Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temp queue download #434

Merged
merged 6 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/scriptworker/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ def get_artifact_url(context, task_id, path):

"""
if path.startswith("public/"):
url = context.queue.buildUrl("getLatestArtifact", task_id, path)
url = context.temp_queue.buildUrl("getLatestArtifact", task_id, path)
else:
url = context.queue.buildSignedUrl(
url = context.temp_queue.buildSignedUrl(
"getLatestArtifact",
task_id,
path,
Expand Down
23 changes: 21 additions & 2 deletions src/scriptworker/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Context(object):
queue = None
session = None
task = None
temp_queue = None
_temp_queue = None
running_tasks = None
_credentials = None
_claim_task = None # This assumes a single task per worker.
Expand Down Expand Up @@ -169,7 +169,10 @@ def temp_credentials(self):
@temp_credentials.setter
def temp_credentials(self, credentials):
self._temp_credentials = credentials
self.temp_queue = self.create_queue(self.temp_credentials)
if credentials is not None:
self.temp_queue = self.create_queue(self.temp_credentials)
else:
self.temp_queue = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, when would we reach this else case ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


def write_json(self, path, contents, message):
"""Write json to disk.
Expand Down Expand Up @@ -215,6 +218,22 @@ def event_loop(self):
def event_loop(self, event_loop):
self._event_loop = event_loop

@property
def temp_queue(self):
"""dict: The queue for the current task.

These will have different sets of scopes than the worker queue.

"""
if self._temp_queue:
return self._temp_queue
else:
return self.queue

@temp_queue.setter
def temp_queue(self, queue):
self._temp_queue = queue

async def populate_projects(self, force=False):
"""Download the ``projects.yml`` file and populate ``self.projects``.

Expand Down
8 changes: 4 additions & 4 deletions tests/test_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ def buildSignedUrl(*args, **kwargs):
return expected

context = mock.MagicMock()
context.queue = mock.MagicMock()
context.queue.options = {"baseUrl": "https://netloc/"}
context.queue.buildUrl = buildUrl
context.queue.buildSignedUrl = buildSignedUrl
context.temp_queue = mock.MagicMock()
context.temp_queue.options = {"baseUrl": "https://netloc/"}
context.temp_queue.buildUrl = buildUrl
context.temp_queue.buildSignedUrl = buildSignedUrl
assert get_artifact_url(context, "x", path) == expected


Expand Down
6 changes: 6 additions & 0 deletions tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ def test_temp_queue(rw_context, mocker):
assert taskcluster.aio.Queue.called_once_with(
options={"rootUrl": rw_context.config["taskcluster_root_url"], "credentials": rw_context.temp_credentials}, session=rw_context.session
)
assert rw_context._temp_queue is not None
rw_context.temp_queue = None
fake_queue = mocker.MagicMock()
rw_context.queue = fake_queue
assert rw_context._temp_queue is None
assert rw_context.temp_queue is fake_queue


@pytest.mark.asyncio
Expand Down
6 changes: 3 additions & 3 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ async def get_temp_creds_context(config_override=None):
yield context


async def create_task(context, task_id, task_group_id):
payload = integration_create_task_payload(context.config, task_group_id)
async def create_task(context, task_id, task_group_id, **kwargs):
payload = integration_create_task_payload(context.config, task_group_id, **kwargs)
return await context.queue.createTask(task_id, payload)


Expand Down Expand Up @@ -327,7 +327,7 @@ async def test_private_artifacts(context_function):
task_group_id = task_id = slugid.nice()
override = {"task_script": ("bash", "-c", ">&2 echo")}
async with context_function(override) as context:
result = await create_task(context, task_id, task_group_id)
result = await create_task(context, task_id, task_group_id, scopes=["queue:get-artifact:SampleArtifacts/_/X.txt"])
assert result["status"]["state"] == "pending"
path = os.path.join(context.config["artifact_dir"], "SampleArtifacts/_/X.txt")
utils.makedirs(os.path.dirname(path))
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ depends =
[testenv:report]
skip_install = true
commands = coverage report -m
depends = py37
depends = py38
parallel_show_output = true

[testenv:coveralls]
Expand Down