| 1 |
# Copyright 2009-present MongoDB, Inc. |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
|
| 15 |
from typing import MutableMapping |
| 16 |
|
| 17 |
from evergreen_config_generator import ConfigObject |
| 18 |
|
| 19 |
from . import Value, ValueSequence |
| 20 |
|
| 21 |
|
| 22 |
class TaskGroup(ConfigObject): |
| 23 |
def __init__(self, name: str): |
| 24 |
self._task_group_name = name |
| 25 |
self.setup_group: ValueSequence | None = None |
| 26 |
self.teardown_group: ValueSequence | None = None |
| 27 |
self.setup_task: str | None = None |
| 28 |
self.teardown_task: str | None = None |
| 29 |
self.max_hosts: int | None = None |
| 30 |
self.timeout: int | None = None |
| 31 |
self.setup_group_can_fail_task: bool | None = None |
| 32 |
self.setup_group_timeout_secs: int | None = None |
| 33 |
self.share_processes: bool | None = None |
| 34 |
self.tasks: ValueSequence | None = None |
| 35 |
|
| 36 |
@property |
| 37 |
def name(self) -> str: |
| 38 |
return self._task_group_name |
| 39 |
|
| 40 |
def to_dict(self) -> Value: |
| 41 |
v = super().to_dict() |
| 42 |
assert isinstance(v, MutableMapping) |
| 43 |
# See possible TaskGroup attributes from the Evergreen wiki: |
| 44 |
# https://github.com/evergreen-ci/evergreen/wiki/Project-Configuration-Files#task-groups |
| 45 |
attrs = [ |
| 46 |
'setup_group', |
| 47 |
'teardown_group', |
| 48 |
'setup_task', |
| 49 |
'teardown_task', |
| 50 |
'max_hosts', |
| 51 |
'timeout', |
| 52 |
'setup_group_can_fail_task', |
| 53 |
'setup_group_timeout_secs', |
| 54 |
'share_processes', |
| 55 |
'tasks', |
| 56 |
] |
| 57 |
|
| 58 |
for i in attrs: |
| 59 |
if getattr(self, i, None): |
| 60 |
v[i] = getattr(self, i) |
| 61 |
return v |