зеркало из https://github.com/microsoft/lisa.git
Reformat due to updated Black package
This commit is contained in:
Родитель
300121735a
Коммит
57dc0339d7
|
@ -64,7 +64,8 @@ class EnvironmentSpace(search_space.RequirementMixin):
|
|||
for index, current_req in enumerate(self.nodes):
|
||||
current_cap = capability.nodes[index]
|
||||
result.merge(
|
||||
search_space.check(current_req, current_cap), str(index),
|
||||
search_space.check(current_req, current_cap),
|
||||
str(index),
|
||||
)
|
||||
if not result.result:
|
||||
break
|
||||
|
@ -224,7 +225,8 @@ class Environments(EnvironmentsDict):
|
|||
|
||||
def from_requirement(self, requirement: EnvironmentSpace) -> Optional[Environment]:
|
||||
runbook = schema.Environment(
|
||||
topology=requirement.topology, nodes_requirement=requirement.nodes,
|
||||
topology=requirement.topology,
|
||||
nodes_requirement=requirement.nodes,
|
||||
)
|
||||
return self.from_runbook(
|
||||
runbook=runbook, name=f"req_{len(self.keys())}", is_original_runbook=False
|
||||
|
@ -251,7 +253,9 @@ class Environments(EnvironmentsDict):
|
|||
return env
|
||||
|
||||
|
||||
def load_environments(root_runbook: Optional[schema.EnvironmentRoot],) -> Environments:
|
||||
def load_environments(
|
||||
root_runbook: Optional[schema.EnvironmentRoot],
|
||||
) -> Environments:
|
||||
if root_runbook:
|
||||
environments = Environments(
|
||||
warn_as_error=root_runbook.warn_as_error,
|
||||
|
|
|
@ -192,7 +192,11 @@ class Tool(ABC, InitializableMixin):
|
|||
else:
|
||||
command = self.command
|
||||
return self.node.execute_async(
|
||||
command, shell, no_error_log=no_error_log, cwd=cwd, no_info_log=no_info_log,
|
||||
command,
|
||||
shell,
|
||||
no_error_log=no_error_log,
|
||||
cwd=cwd,
|
||||
no_info_log=no_info_log,
|
||||
)
|
||||
|
||||
def run(
|
||||
|
@ -348,8 +352,8 @@ class CustomScript(Tool):
|
|||
|
||||
class CustomScriptBuilder:
|
||||
"""
|
||||
With CustomScriptBuilder, provides variables is enough to use like a tool
|
||||
It needs some special handling in tool.py, but not much.
|
||||
With CustomScriptBuilder, provides variables is enough to use like a tool
|
||||
It needs some special handling in tool.py, but not much.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
|
|
14
lisa/node.py
14
lisa/node.py
|
@ -87,7 +87,11 @@ class Node(ContextMixin, InitializableMixin):
|
|||
)
|
||||
|
||||
self._connection_info = ConnectionInfo(
|
||||
public_address, public_port, username, password, private_key_file,
|
||||
public_address,
|
||||
public_port,
|
||||
username,
|
||||
password,
|
||||
private_key_file,
|
||||
)
|
||||
self.shell = SshShell(self._connection_info)
|
||||
self.internal_address = address
|
||||
|
@ -259,7 +263,9 @@ class Nodes(NodesDict):
|
|||
node.close()
|
||||
|
||||
def from_local(
|
||||
self, node_runbook: schema.LocalNode, logger_name: str = "node",
|
||||
self,
|
||||
node_runbook: schema.LocalNode,
|
||||
logger_name: str = "node",
|
||||
) -> Node:
|
||||
assert isinstance(
|
||||
node_runbook, schema.LocalNode
|
||||
|
@ -276,7 +282,9 @@ class Nodes(NodesDict):
|
|||
return node
|
||||
|
||||
def from_remote(
|
||||
self, node_runbook: schema.RemoteNode, logger_name: str = "node",
|
||||
self,
|
||||
node_runbook: schema.RemoteNode,
|
||||
logger_name: str = "node",
|
||||
) -> Optional[Node]:
|
||||
assert isinstance(
|
||||
node_runbook, schema.RemoteNode
|
||||
|
|
|
@ -179,7 +179,8 @@ class Parent:
|
|||
|
||||
path: str = field(default="", metadata=metadata(required=True))
|
||||
strategy: List[Strategy] = field(
|
||||
default_factory=list, metadata=metadata(required=True),
|
||||
default_factory=list,
|
||||
metadata=metadata(required=True),
|
||||
)
|
||||
|
||||
|
||||
|
@ -251,7 +252,8 @@ class Variable:
|
|||
@dataclass
|
||||
class ArtifactLocation:
|
||||
type: str = field(
|
||||
default="", metadata=metadata(required=True, validate=validate.OneOf([])),
|
||||
default="",
|
||||
metadata=metadata(required=True, validate=validate.OneOf([])),
|
||||
)
|
||||
path: str = field(default="", metadata=metadata(required=True))
|
||||
|
||||
|
@ -265,7 +267,8 @@ class Artifact:
|
|||
# name is optional. artifacts can be referred by name or index.
|
||||
name: str = ""
|
||||
type: str = field(
|
||||
default="", metadata=metadata(required=True, validate=validate.OneOf([])),
|
||||
default="",
|
||||
metadata=metadata(required=True, validate=validate.OneOf([])),
|
||||
)
|
||||
locations: List[ArtifactLocation] = field(default_factory=list)
|
||||
|
||||
|
@ -279,7 +282,8 @@ class Notifier:
|
|||
"""
|
||||
|
||||
type: str = field(
|
||||
default="", metadata=metadata(required=True, validate=validate.OneOf([])),
|
||||
default="",
|
||||
metadata=metadata(required=True, validate=validate.OneOf([])),
|
||||
)
|
||||
|
||||
|
||||
|
@ -345,12 +349,14 @@ class NodeSpace(search_space.RequirementMixin, ExtendableSchemaMixin):
|
|||
# all features on requirement should be included.
|
||||
# all features on capability can be included.
|
||||
features: Optional[search_space.SetSpace[Feature]] = field(
|
||||
default=None, metadata=metadata(data_key="features", allow_none=True),
|
||||
default=None,
|
||||
metadata=metadata(data_key="features", allow_none=True),
|
||||
)
|
||||
# set by requirements
|
||||
# capability's is ignored
|
||||
excluded_features: Optional[search_space.SetSpace[Feature]] = field(
|
||||
default=None, metadata=metadata(data_key="excludedFeatures", allow_none=True),
|
||||
default=None,
|
||||
metadata=metadata(data_key="excludedFeatures", allow_none=True),
|
||||
)
|
||||
|
||||
def __post_init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
|
@ -454,7 +460,8 @@ class NodeSpace(search_space.RequirementMixin, ExtendableSchemaMixin):
|
|||
"gpu_count",
|
||||
)
|
||||
result.merge(
|
||||
search_space.check(self.features, capability.features), "features",
|
||||
search_space.check(self.features, capability.features),
|
||||
"features",
|
||||
)
|
||||
if self.excluded_features:
|
||||
result.merge(
|
||||
|
@ -650,7 +657,8 @@ class Environment:
|
|||
metadata=metadata(validate=validate.OneOf([constants.ENVIRONMENTS_SUBNET])),
|
||||
)
|
||||
nodes_raw: Optional[List[Any]] = field(
|
||||
default=None, metadata=metadata(data_key=constants.NODES),
|
||||
default=None,
|
||||
metadata=metadata(data_key=constants.NODES),
|
||||
)
|
||||
nodes_requirement: Optional[List[NodeSpace]] = None
|
||||
|
||||
|
@ -703,7 +711,8 @@ class EnvironmentRoot:
|
|||
@dataclass
|
||||
class Platform(ExtendableSchemaMixin):
|
||||
type: str = field(
|
||||
default=constants.PLATFORM_READY, metadata=metadata(required=True),
|
||||
default=constants.PLATFORM_READY,
|
||||
metadata=metadata(required=True),
|
||||
)
|
||||
|
||||
admin_username: str = "lisatest"
|
||||
|
|
|
@ -211,7 +211,9 @@ class SetSpace(RequirementMixin, Set[T]):
|
|||
is_allow_set: bool = False
|
||||
|
||||
def __init__(
|
||||
self, is_allow_set: Optional[bool] = None, items: Optional[Iterable[T]] = None,
|
||||
self,
|
||||
is_allow_set: Optional[bool] = None,
|
||||
items: Optional[Iterable[T]] = None,
|
||||
) -> None:
|
||||
if items:
|
||||
self.update(items)
|
||||
|
|
|
@ -141,7 +141,8 @@ class AzurePlatformSchema:
|
|||
subscription_id: str = field(
|
||||
default="",
|
||||
metadata=schema.metadata(
|
||||
data_key="subscriptionId", validate=validate.Regexp(constants.GUID_REGEXP),
|
||||
data_key="subscriptionId",
|
||||
validate=validate.Regexp(constants.GUID_REGEXP),
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -665,7 +666,9 @@ class AzurePlatform(Platform):
|
|||
parameters = {k: {"value": v} for k, v in parameters.items()}
|
||||
log.debug(f"parameters: {parameters}")
|
||||
deployment_properties = DeploymentProperties(
|
||||
mode=DeploymentMode.incremental, template=template, parameters=parameters,
|
||||
mode=DeploymentMode.incremental,
|
||||
template=template,
|
||||
parameters=parameters,
|
||||
)
|
||||
|
||||
return {
|
||||
|
|
|
@ -294,7 +294,10 @@ class AzurePrepareTestCase(TestCase):
|
|||
)
|
||||
return result
|
||||
|
||||
def load_environment(self, node_req_count: int = 2,) -> Environment:
|
||||
def load_environment(
|
||||
self,
|
||||
node_req_count: int = 2,
|
||||
) -> Environment:
|
||||
environment = Environment(is_predefined=True, warn_as_error=False)
|
||||
environment.runbook = schema.Environment()
|
||||
if node_req_count > 0:
|
||||
|
@ -342,10 +345,12 @@ class AzurePrepareTestCase(TestCase):
|
|||
]
|
||||
|
||||
self.assertListEqual(
|
||||
expected_locations, [x.location for x in nodes_runbook],
|
||||
expected_locations,
|
||||
[x.location for x in nodes_runbook],
|
||||
)
|
||||
self.assertListEqual(
|
||||
expected_vm_sizes, [x.vm_size for x in nodes_runbook],
|
||||
expected_vm_sizes,
|
||||
[x.vm_size for x in nodes_runbook],
|
||||
)
|
||||
|
||||
# all cap values must be covered to specified int value, not space
|
||||
|
|
|
@ -182,7 +182,9 @@ class LisaRunner(Action):
|
|||
assert cases
|
||||
suite_metadata = cases[0].runtime_data.metadata.suite
|
||||
test_suite: TestSuite = suite_metadata.test_class(
|
||||
environment, cases, suite_metadata,
|
||||
environment,
|
||||
cases,
|
||||
suite_metadata,
|
||||
)
|
||||
for case in cases:
|
||||
case.assigned_env = environment.name
|
||||
|
|
|
@ -52,7 +52,8 @@ class LisaRunnerTestCase(TestCase):
|
|||
env_runbook = generate_env_runbook(is_single_env=False)
|
||||
envs = load_environments(env_runbook)
|
||||
self.assertListEqual(
|
||||
[], [x for x in envs],
|
||||
[],
|
||||
[x for x in envs],
|
||||
)
|
||||
runner = generate_lisarunner(None)
|
||||
test_results = generate_cases_result()
|
||||
|
@ -63,7 +64,8 @@ class LisaRunnerTestCase(TestCase):
|
|||
)
|
||||
# 3 cases create 3 envs
|
||||
self.assertListEqual(
|
||||
["req_0", "req_1", "req_2"], [x for x in envs],
|
||||
["req_0", "req_1", "req_2"],
|
||||
[x for x in envs],
|
||||
)
|
||||
self.verify_test_results(
|
||||
expected_envs=["", "", ""],
|
||||
|
@ -78,7 +80,8 @@ class LisaRunnerTestCase(TestCase):
|
|||
env_runbook = generate_env_runbook(remote=True)
|
||||
envs = load_environments(env_runbook)
|
||||
self.assertListEqual(
|
||||
["runbook_0"], [x for x in envs],
|
||||
["runbook_0"],
|
||||
[x for x in envs],
|
||||
)
|
||||
|
||||
runner = generate_lisarunner(env_runbook)
|
||||
|
@ -91,7 +94,8 @@ class LisaRunnerTestCase(TestCase):
|
|||
|
||||
# 3 cases created only two req, as simple req meets on runbook_0
|
||||
self.assertListEqual(
|
||||
["runbook_0", "req_1", "req_2"], [x for x in envs],
|
||||
["runbook_0", "req_1", "req_2"],
|
||||
[x for x in envs],
|
||||
)
|
||||
self.assertListEqual(
|
||||
[TestStatus.NOTRUN, TestStatus.NOTRUN, TestStatus.NOTRUN],
|
||||
|
@ -105,7 +109,8 @@ class LisaRunnerTestCase(TestCase):
|
|||
env_runbook = generate_env_runbook(remote=True)
|
||||
envs = load_environments(env_runbook)
|
||||
self.assertListEqual(
|
||||
["runbook_0"], [x for x in envs],
|
||||
["runbook_0"],
|
||||
[x for x in envs],
|
||||
)
|
||||
runner = generate_lisarunner(env_runbook)
|
||||
test_results = generate_cases_result()
|
||||
|
@ -118,7 +123,8 @@ class LisaRunnerTestCase(TestCase):
|
|||
)
|
||||
# every case need a new environment, so created 3
|
||||
self.assertListEqual(
|
||||
["runbook_0", "req_1", "req_2", "req_3"], [x for x in envs],
|
||||
["runbook_0", "req_1", "req_2", "req_3"],
|
||||
[x for x in envs],
|
||||
)
|
||||
self.verify_test_results(
|
||||
expected_envs=["", "", ""],
|
||||
|
@ -134,7 +140,8 @@ class LisaRunnerTestCase(TestCase):
|
|||
env_runbook.allow_create = False
|
||||
envs = load_environments(env_runbook)
|
||||
self.assertListEqual(
|
||||
[], [x for x in envs],
|
||||
[],
|
||||
[x for x in envs],
|
||||
)
|
||||
runner = generate_lisarunner(None)
|
||||
test_results = generate_cases_result()
|
||||
|
@ -144,7 +151,8 @@ class LisaRunnerTestCase(TestCase):
|
|||
platform_type=constants.PLATFORM_MOCK,
|
||||
)
|
||||
self.assertListEqual(
|
||||
[], [x for x in envs],
|
||||
[],
|
||||
[x for x in envs],
|
||||
)
|
||||
|
||||
not_allow_new_message = (
|
||||
|
@ -173,7 +181,8 @@ class LisaRunnerTestCase(TestCase):
|
|||
env_runbook = generate_env_runbook(is_single_env=False)
|
||||
envs = load_environments(env_runbook)
|
||||
self.assertListEqual(
|
||||
[], [x for x in envs],
|
||||
[],
|
||||
[x for x in envs],
|
||||
)
|
||||
runner = generate_lisarunner(None)
|
||||
test_results = generate_cases_result()
|
||||
|
@ -413,10 +422,12 @@ class LisaRunnerTestCase(TestCase):
|
|||
test_results: List[TestResult],
|
||||
) -> None:
|
||||
self.assertListEqual(
|
||||
expected_envs, [x.assigned_env for x in test_results],
|
||||
expected_envs,
|
||||
[x.assigned_env for x in test_results],
|
||||
)
|
||||
self.assertListEqual(
|
||||
expected_status, [x.status for x in test_results],
|
||||
expected_status,
|
||||
[x.status for x in test_results],
|
||||
)
|
||||
# compare it's begin with
|
||||
actual_messages = [
|
||||
|
@ -424,7 +435,8 @@ class LisaRunnerTestCase(TestCase):
|
|||
for index, expected in enumerate(expected_message)
|
||||
]
|
||||
self.assertListEqual(
|
||||
expected_message, actual_messages,
|
||||
expected_message,
|
||||
actual_messages,
|
||||
)
|
||||
|
||||
def verify_env_results(
|
||||
|
@ -434,11 +446,14 @@ class LisaRunnerTestCase(TestCase):
|
|||
expected_deleted_envs: List[str],
|
||||
) -> None:
|
||||
self.assertListEqual(
|
||||
expected_prepared, [x for x in prepared_envs],
|
||||
expected_prepared,
|
||||
[x for x in prepared_envs],
|
||||
)
|
||||
self.assertListEqual(
|
||||
expected_deployed_envs, [x for x in deployed_envs],
|
||||
expected_deployed_envs,
|
||||
[x for x in deployed_envs],
|
||||
)
|
||||
self.assertListEqual(
|
||||
expected_deleted_envs, [x for x in deleted_envs],
|
||||
expected_deleted_envs,
|
||||
[x for x in deleted_envs],
|
||||
)
|
||||
|
|
|
@ -33,7 +33,8 @@ class UtTestCaseRequirement(TestCaseRequirement, RequirementMixin):
|
|||
), f"actual: {type(capability)}"
|
||||
result = ResultReason()
|
||||
result.merge(
|
||||
check(self.environment, capability.environment), name="environment",
|
||||
check(self.environment, capability.environment),
|
||||
name="environment",
|
||||
)
|
||||
|
||||
return result
|
||||
|
@ -126,7 +127,9 @@ class RequirementTestCase(SearchSpaceTestCase):
|
|||
n10 = n10.generate_min_capability(n10)
|
||||
|
||||
partial_testcase_schema = partial(
|
||||
TestCaseSchema, platform_type=None, operating_system=None,
|
||||
TestCaseSchema,
|
||||
platform_type=None,
|
||||
operating_system=None,
|
||||
)
|
||||
s11 = partial_testcase_schema(environment=EnvironmentSpace())
|
||||
s11.environment.nodes = [n1]
|
||||
|
|
|
@ -140,7 +140,8 @@ class PlatformTestCase(TestCase):
|
|||
envs["runbook_1"].is_predefined = True
|
||||
prepared_environments = platform.prepare_environments(envs)
|
||||
self.assertListEqual(
|
||||
["runbook_1", "runbook_0"], [x.name for x in prepared_environments],
|
||||
["runbook_1", "runbook_0"],
|
||||
[x.name for x in prepared_environments],
|
||||
)
|
||||
self.assertListEqual(
|
||||
[True, False], [x.is_predefined for x in prepared_environments]
|
||||
|
|
|
@ -249,7 +249,10 @@ class SearchSpaceTestCase(unittest.TestCase):
|
|||
)
|
||||
|
||||
def _assert_check(
|
||||
self, expected_meet: bool, result: ResultReason, extra_msg: str = "",
|
||||
self,
|
||||
expected_meet: bool,
|
||||
result: ResultReason,
|
||||
extra_msg: str = "",
|
||||
) -> None:
|
||||
msg = f"expected result: {expected_meet}, actual: {result.result}"
|
||||
if extra_msg:
|
||||
|
|
|
@ -45,7 +45,9 @@ class SecretTestCase(TestCase):
|
|||
|
||||
def test_fallback(self) -> None:
|
||||
add_secret(
|
||||
"test1", mask=re.compile(r"^doesn't match$"), sub=r"*****",
|
||||
"test1",
|
||||
mask=re.compile(r"^doesn't match$"),
|
||||
sub=r"*****",
|
||||
)
|
||||
result = mask("my test1 test2 not")
|
||||
self.assertEqual(result, "my ***** test2 not")
|
||||
|
|
|
@ -89,7 +89,11 @@ def cleanup_cases_metadata() -> None:
|
|||
|
||||
def generate_cases_metadata() -> List[TestCaseMetadata]:
|
||||
ut_cases = [
|
||||
TestCaseMetadata("ut1", 0, requirement=simple_requirement(min_count=2),),
|
||||
TestCaseMetadata(
|
||||
"ut1",
|
||||
0,
|
||||
requirement=simple_requirement(min_count=2),
|
||||
),
|
||||
TestCaseMetadata("ut2", 1),
|
||||
TestCaseMetadata("ut3", 2),
|
||||
]
|
||||
|
@ -364,5 +368,6 @@ class TestSuiteTestCase(TestCase):
|
|||
assert result.check_results
|
||||
self.assertTrue(result.check_results.result)
|
||||
self.assertListEqual(
|
||||
[], result.check_results.reasons,
|
||||
[],
|
||||
result.check_results.reasons,
|
||||
)
|
||||
|
|
|
@ -69,7 +69,9 @@ class VariableTestCase(TestCase):
|
|||
|
||||
def test_in_secret_file(self) -> None:
|
||||
self._test_files(
|
||||
"variable_secret.yml", False, {},
|
||||
"variable_secret.yml",
|
||||
False,
|
||||
{},
|
||||
)
|
||||
|
||||
def test_in_runbook_format_file(self) -> None:
|
||||
|
|
|
@ -30,7 +30,10 @@ class ExecutableResult:
|
|||
|
||||
class Process:
|
||||
def __init__(
|
||||
self, id_: str, shell: Shell, parent_logger: Optional[Logger] = None,
|
||||
self,
|
||||
id_: str,
|
||||
shell: Shell,
|
||||
parent_logger: Optional[Logger] = None,
|
||||
) -> None:
|
||||
# the shell can be LocalShell or SshShell
|
||||
self._shell = shell
|
||||
|
@ -49,7 +52,7 @@ class Process:
|
|||
no_info_log: bool = False,
|
||||
) -> None:
|
||||
"""
|
||||
command include all parameters also.
|
||||
command include all parameters also.
|
||||
"""
|
||||
stdout_level = logging.INFO
|
||||
stderr_level = logging.ERROR
|
||||
|
|
|
@ -76,7 +76,9 @@ def load_from_runbook(runbook_data: Any, current_variables: Dict[str, Any]) -> N
|
|||
|
||||
|
||||
def load_from_file(
|
||||
file_name: str, current_variables: Dict[str, Any], is_secret: bool = False,
|
||||
file_name: str,
|
||||
current_variables: Dict[str, Any],
|
||||
is_secret: bool = False,
|
||||
) -> None:
|
||||
if is_secret:
|
||||
secret.add_secret(file_name)
|
||||
|
|
Загрузка…
Ссылка в новой задаче