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

Add worker field to pool configuration #447

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions services/fuzzing-decision/src/fuzzing_decision/common/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"routes": list,
"scopes": list,
"tasks": int,
"worker": str,
}
)
# fields that must exist in every pool.yml
Expand All @@ -78,6 +79,7 @@
)
PROVIDERS = frozenset(("aws", "gcp", "static"))
ARCHITECTURES = frozenset(("x64", "arm64"))
WORKERS = frozenset(("generic", "docker", "d2g"))


def parse_size(size: str) -> float:
Expand Down Expand Up @@ -240,6 +242,7 @@ class CommonPoolConfiguration(abc.ABC):
routes: list of taskcluster notification routes to enable on the target
scopes: list of taskcluster scopes required by the target
tasks: number of tasks to run (each with `cores_per_task`)
worker: TC worker type
"""

FIELD_TYPES: types.MappingProxyType
Expand Down Expand Up @@ -399,6 +402,12 @@ def __init__(
",".join(PROVIDERS)
)
self.cloud = data["cloud"]
self.worker = None
if data.get("worker") is not None:
assert data["worker"] in WORKERS, "Invalid worker - use {}".format(
",".join(WORKERS)
)
self.worker = data["worker"]

@classmethod
def from_file(
Expand Down Expand Up @@ -613,6 +622,7 @@ def _flatten(self, flattened: Optional[Set[str]]) -> None:
"schedule_start",
"tasks",
"run_as_admin",
"worker",
)
merge_dict_fields = ("artifacts", "macros")
merge_list_fields = ("routes", "scopes")
Expand Down Expand Up @@ -711,6 +721,7 @@ def __init__(
"nested_virtualization",
"platform",
"schedule_start",
"worker",
)
not_allowed = ("preprocess",)
pools = list(self.iterpools())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ def lookup_taskid(cls, namespace: str) -> int:

def add_task_image(task: Dict[str, Any], config: "PoolConfiguration") -> None:
"""Add image or mount to task payload, depending on platform."""
if config.platform in {"macos", "windows"}:
# generic-worker linux still uses docker images, but need to be loaded
# into podman, can't use mounts to do it
# TODO: should still have task dependency for indexed-image
if config.worker == "generic" and config.platform != "linux":
assert isinstance(config.container, dict)
assert config.container["type"] != "docker-image"
task_id: Union[str, int]
Expand All @@ -99,9 +102,11 @@ def add_task_image(task: Dict[str, Any], config: "PoolConfiguration") -> None:
}
)
task["dependencies"].append(task_id)
else:
elif config.worker in {"docker", "d2g"}:
# `container` can be either a string or a dict, so can't template it
task["payload"]["image"] = config.container
else:
raise NotImplementedError(f"{config.worker} / {config.platform} not supported")


def add_capabilities_for_scopes(task: Dict[str, Any]) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def get_worker_config(self, worker: str, platform: str) -> Dict[str, Any]:
assert worker in self.imagesets, f"Missing worker {worker}"
out: Dict[str, Any] = self.imagesets[worker].get("workerConfig", {})

if platform == "linux":
worker_impl = self.imagesets[worker]["workerImplementation"]
LOG.debug("got worker implementation: %s", worker_impl)
if platform == "linux" and worker_impl == "docker-worker":
jschwartzentruber marked this conversation as resolved.
Show resolved Hide resolved
out.setdefault("dockerConfig", {})
out.update(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,7 @@ properties:
tasks:
description: "Number of tasks to run"
type: integer
worker:
description: "Taskcluster worker type"
type: string
pattern: "^d2g|docker|generic$"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

docker-worker:
workerImplementation: docker-worker
aws:
amis:
us-west-1: ami-6789
gcp:
image: path/to/image

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ run_as_admin: false
gpu: false
demand: false
nested_virtualization: false
worker: docker
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ run_as_admin: false
gpu: false
demand: false
nested_virtualization: false
worker: generic
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ run_as_admin: false
gpu: false
demand: false
nested_virtualization: false
worker: generic
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ run_as_admin: false
gpu: false
demand: false
nested_virtualization: false
worker: docker
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ run_as_admin: false
gpu: false
demand: false
nested_virtualization: false
worker: generic
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ run_as_admin: false
gpu: false
demand: false
nested_virtualization: false
worker: docker
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ run_as_admin: false
gpu: false
demand: false
nested_virtualization: false
worker: generic
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ run_as_admin: false
gpu: false
demand: false
nested_virtualization: false
worker: generic
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ run_as_admin: false
gpu: false
demand: false
nested_virtualization: false
worker: generic
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ run_as_admin: false
gpu: false
demand: false
nested_virtualization: false
worker: generic
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ run_as_admin: false
gpu: false
demand: false
nested_virtualization: false
worker: docker
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ run_as_admin: false
gpu: false
demand: false
nested_virtualization: false
worker: generic
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ run_as_admin: false
gpu: false
demand: false
nested_virtualization: false
worker: docker
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ run_as_admin: false
gpu: false
demand: false
nested_virtualization: false
worker: generic
1 change: 1 addition & 0 deletions services/fuzzing-decision/tests/fixtures/pools/pool1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ run_as_admin: false
gpu: false
demand: false
nested_virtualization: false
worker: docker
1 change: 1 addition & 0 deletions services/fuzzing-decision/tests/fixtures/pools/pool4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ run_as_admin: false
gpu: false
demand: false
nested_virtualization: false
worker: generic
1 change: 1 addition & 0 deletions services/fuzzing-decision/tests/fixtures/pools/pool9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ run_as_admin: false
gpu: false
demand: false
nested_virtualization: false
worker: d2g
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ macros: {}
run_as_admin: false
gpu: false
nested_virtualization: false
worker: docker
2 changes: 2 additions & 0 deletions services/fuzzing-decision/tests/test_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def pool_data():
"macros": {},
"run_as_admin": False,
"nested_virtualization": False,
"worker": "generic",
}


Expand Down Expand Up @@ -156,6 +157,7 @@ def test_load_params_4(tmp_path, pool_data):
"preprocess": None,
"macros": {"PREPROC": "1"},
"run_as_admin": False,
"worker": "generic",
}
with (tmp_path / "test-pool.yml").open("w") as test_cfg:
yaml.dump(pool_data, stream=test_cfg)
Expand Down
22 changes: 18 additions & 4 deletions services/fuzzing-decision/tests/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,22 @@ def _get_expected_role(

@pytest.mark.usefixtures("appconfig")
@pytest.mark.parametrize("env", [(None), ({"someKey": "someValue"})])
@pytest.mark.parametrize("platform", ["linux", "windows"])
@pytest.mark.parametrize(
"platform, worker",
[
("linux", "docker"),
("linux", "d2g"),
("windows", "generic"),
],
)
@pytest.mark.parametrize("demand", [True, False])
def test_aws_resources(
env,
mock_clouds,
mock_machines,
platform,
demand,
worker,
):
conf = PoolConfiguration(
"test",
Expand All @@ -181,7 +189,7 @@ def test_aws_resources(
"demand": demand,
"disk_size": "120g",
"gpu": False,
"imageset": "generic-worker-A",
"imageset": "docker-worker" if worker == "docker" else "generic-worker-A",
"macros": {},
"max_run_time": "12h",
"metal": False,
Expand All @@ -195,6 +203,7 @@ def test_aws_resources(
"tasks": 3,
"run_as_admin": False,
"nested_virtualization": False,
"worker": worker,
},
)
resources = list(conf.build_resources(mock_clouds, mock_machines, env=env))
Expand All @@ -207,7 +216,7 @@ def test_aws_resources(
{
"capacityPerInstance": 1,
"launchConfig": {
"ImageId": "ami-1234",
"ImageId": "ami-6789" if worker == "docker" else "ami-1234",
"InstanceType": "a2",
"Placement": {"AvailabilityZone": "us-west-1a"},
"SecurityGroupIds": ["sg-A"],
Expand Down Expand Up @@ -239,7 +248,7 @@ def test_aws_resources(
if not demand:
for config in expected["config"]["launchConfigs"]:
config["launchConfig"]["InstanceMarketOptions"] = {"MarketType": "spot"}
if platform == "linux":
if worker == "docker":
expected["config"]["launchConfigs"][0]["workerConfig"].update(
{
"dockerConfig": {
Expand Down Expand Up @@ -310,6 +319,7 @@ def test_gcp_resources(
"tasks": 3,
"run_as_admin": False,
"nested_virtualization": False,
"worker": "docker",
},
)
resources = list(conf.build_resources(mock_clouds, mock_machines, env=env))
Expand Down Expand Up @@ -530,6 +540,7 @@ def test_tasks(
"tasks": 2,
"run_as_admin": run_as_admin,
"nested_virtualization": False,
"worker": "docker" if platform == "linux" else "generic",
},
)

Expand Down Expand Up @@ -799,6 +810,7 @@ def _flatten(self, _):
assert set(cfg_map.scopes) == set()
assert cfg_map.tasks is None
assert cfg_map.nested_virtualization == expect.nested_virtualization
assert cfg_map.worker == expect.worker

pools = list(cfg_map.iterpools())
assert len(pools) == 1
Expand Down Expand Up @@ -826,6 +838,7 @@ def _flatten(self, _):
assert set(pool.scopes) == set(expect.scopes)
assert pool.tasks == expect.tasks
assert pool.nested_virtualization == expect.nested_virtualization
assert pool.worker == expect.worker


def test_pool_map_admin(mocker):
Expand Down Expand Up @@ -913,6 +926,7 @@ def test_cycle_crons():
"tasks": 2,
"run_as_admin": False,
"nested_virtualization": False,
"worker": "docker",
},
)

Expand Down
Loading