Skip to content

Commit 876f14c

Browse files
authored
check generic-worker interactive tasks. raise on docker-worker interactive tasks. (#452)
* check generic-worker interactive tasks. raise on docker-worker interactive tasks. * address review comment * 34.0.0
1 parent 0d9e029 commit 876f14c

File tree

5 files changed

+93
-24
lines changed

5 files changed

+93
-24
lines changed

HISTORY.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ Change Log
44
All notable changes to this project will be documented in this file.
55
This project adheres to `Semantic Versioning <http://semver.org/>`__.
66

7+
[34.0.0] - 2020-04-17
8+
---------------------
9+
10+
Added
11+
~~~~~
12+
- added ``check_interactive_generic_worker``
13+
14+
Changed
15+
~~~~~~~
16+
- ``check_interactive_docker_worker`` now raises ``CoTError`` on errors, rather
17+
than returning the list of error messages
18+
- ``check_interactive_docker_worker`` now also runs against the chain task, if it's
19+
docker-worker
20+
721
[33.1.1] - 2020-04-09
822
---------------------
923

src/scriptworker/cot/verify.py

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ def get_valid_worker_impls():
365365
validation functions.
366366
367367
"""
368-
# TODO support taskcluster worker
369368
return immutabledict({"docker-worker": verify_docker_worker_task, "generic-worker": verify_generic_worker_task, "scriptworker": verify_scriptworker_task})
370369

371370

@@ -436,8 +435,8 @@ def check_interactive_docker_worker(link):
436435
Args:
437436
link (LinkOfTrust): the task link we're checking.
438437
439-
Returns:
440-
list: the list of error errors. Success is an empty list.
438+
Raises:
439+
CoTError: on interactive.
441440
442441
"""
443442
errors = []
@@ -449,7 +448,34 @@ def check_interactive_docker_worker(link):
449448
errors.append("{} is interactive: task.payload.env.TASKCLUSTER_INTERACTIVE!".format(link.name))
450449
except KeyError:
451450
errors.append("check_interactive_docker_worker: {} task definition is malformed!".format(link.name))
452-
return errors
451+
raise_on_errors(errors)
452+
453+
454+
# check_interactive_generic_worker {{{1
455+
def check_interactive_generic_worker(link):
456+
"""Given a task, make sure the task was not defined as interactive.
457+
458+
* ``task.payload.rdpInfo`` must be absent or False.
459+
* ``task.payload.scopes`` must not contain a scope starting with ``generic-worker:allow-rdp:``
460+
461+
Args:
462+
link (LinkOfTrust): the task link we're checking.
463+
464+
Raises:
465+
CoTError: on interactive.
466+
467+
"""
468+
errors = []
469+
log.info("Checking for {} {} interactive generic-worker".format(link.name, link.task_id))
470+
try:
471+
if link.task["payload"].get("rdpInfo"):
472+
errors.append("{} is interactive: task.payload.rdpInfo!".format(link.name))
473+
for scope in link.task["scopes"]:
474+
if scope.startswith("generic-worker:allow-rdp:"):
475+
errors.append("{} is interactive: {}!".format(link.name, scope))
476+
except KeyError:
477+
errors.append("check_interactive_generic_worker: {} task definition is malformed!".format(link.name))
478+
raise_on_errors(errors)
453479

454480

455481
# verify_docker_image_sha {{{1
@@ -1679,12 +1705,11 @@ async def verify_docker_worker_task(chain, link):
16791705
CoTError: on failure.
16801706
16811707
"""
1708+
check_interactive_docker_worker(link)
16821709
if chain != link:
1683-
# These two checks will die on `link.cot` if `link` is a ChainOfTrust
1684-
# object (e.g., the task we're running `verify_cot` against is a
1685-
# docker-worker task). So only run these tests if they are not the chain
1686-
# object.
1687-
check_interactive_docker_worker(link)
1710+
# This check will die on `link.cot` if `link` is a ChainOfTrust object
1711+
# (e.g., the task we're running `verify_cot` against is a docker-worker
1712+
# task). So only run this test if the link is not the chain object.
16881713
verify_docker_image_sha(chain, link)
16891714

16901715

@@ -1700,7 +1725,9 @@ async def verify_generic_worker_task(chain, link):
17001725
CoTError: on failure.
17011726
17021727
"""
1703-
pass
1728+
check_interactive_generic_worker(link)
1729+
# XXX once generic-worker supports docker, verify the docker image sha
1730+
# if applicable.
17041731

17051732

17061733
# verify_scriptworker_task {{{1

src/scriptworker/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def get_version_string(version: Union[ShortVerType, LongVerType]) -> str:
5454

5555
# 1}}}
5656
# Semantic versioning 2.0.0 http://semver.org/
57-
__version__ = (33, 1, 1)
57+
__version__ = (34, 0, 0)
5858
__version_string__ = get_version_string(__version__)
5959

6060

tests/test_cot_verify.py

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -464,23 +464,44 @@ def test_guess_task_type():
464464

465465
# check_interactive_docker_worker {{{1
466466
@pytest.mark.parametrize(
467-
"task,has_errors",
467+
"task,raises",
468468
(
469469
({"payload": {"features": {}, "env": {}}}, False),
470470
({"payload": {"features": {"interactive": True}, "env": {}}}, True),
471471
({"payload": {"features": {}, "env": {"TASKCLUSTER_INTERACTIVE": "x"}}}, True),
472472
({}, True),
473473
),
474474
)
475-
def test_check_interactive_docker_worker(task, has_errors):
475+
def test_check_interactive_docker_worker(task, raises):
476476
link = MagicMock()
477477
link.name = "foo"
478478
link.task = task
479-
result = cotverify.check_interactive_docker_worker(link)
480-
if has_errors:
481-
assert len(result) >= 1
479+
if raises:
480+
with pytest.raises(CoTError):
481+
cotverify.check_interactive_docker_worker(link)
482+
else:
483+
cotverify.check_interactive_docker_worker(link)
484+
485+
486+
# check_interactive_generic_worker {{{1
487+
@pytest.mark.parametrize(
488+
"task,raises",
489+
(
490+
({"payload": {}, "scopes": []}, False),
491+
({"payload": {"rdpInfo": {"foo": "bar"}}, "scopes": []}, True),
492+
({"payload": {}, "scopes": ["foo", "generic-worker:allow-rdp:foo:bar"]}, True),
493+
({}, True),
494+
),
495+
)
496+
def test_check_interactive_generic_worker(task, raises):
497+
link = MagicMock()
498+
link.name = "foo"
499+
link.task = task
500+
if raises:
501+
with pytest.raises(CoTError):
502+
cotverify.check_interactive_generic_worker(link)
482503
else:
483-
assert result == []
504+
cotverify.check_interactive_generic_worker(link)
484505

485506

486507
# verify_docker_image_sha {{{1
@@ -1892,17 +1913,24 @@ async def test_verify_docker_worker_task(mocker):
18921913
mocker.patch.object(cotverify, "check_interactive_docker_worker", new=check.method1)
18931914
mocker.patch.object(cotverify, "verify_docker_image_sha", new=check.method2)
18941915
await cotverify.verify_docker_worker_task(chain, chain)
1895-
check.method1.assert_not_called()
1916+
check.method1.assert_called_once_with(chain)
18961917
check.method2.assert_not_called()
18971918
await cotverify.verify_docker_worker_task(chain, link)
1898-
check.method1.assert_called_once_with(link)
1919+
check.method1.assert_called_with(link)
18991920
check.method2.assert_called_once_with(chain, link)
19001921

19011922

19021923
# verify_generic_worker_task {{{1
19031924
@pytest.mark.asyncio
19041925
async def test_verify_generic_worker_task(mocker):
1905-
await cotverify.verify_generic_worker_task(MagicMock(), MagicMock())
1926+
chain = MagicMock()
1927+
link = MagicMock()
1928+
check = MagicMock()
1929+
mocker.patch.object(cotverify, "check_interactive_generic_worker", new=check.method1)
1930+
await cotverify.verify_generic_worker_task(chain, chain)
1931+
check.method1.assert_called_once_with(chain)
1932+
await cotverify.verify_generic_worker_task(chain, link)
1933+
check.method1.assert_called_with(link)
19061934

19071935

19081936
# verify_worker_impls {{{1

version.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"version":[
3-
33,
4-
1,
5-
1
3+
34,
4+
0,
5+
0
66
],
7-
"version_string":"33.1.1"
7+
"version_string":"34.0.0"
88
}

0 commit comments

Comments
 (0)