From 8a650b1414cc7ac3eea2c2798f5d174b226de5f9 Mon Sep 17 00:00:00 2001 From: Chi Song <27178119+squirrelsc@users.noreply.github.com> Date: Mon, 19 Oct 2020 20:24:55 +0800 Subject: [PATCH] Change to clearer default environment names update UTs --- lisa/environment.py | 6 +- lisa/tests/test_environment.py | 4 +- lisa/tests/test_lisarunner.py | 106 +++++++++++++++++++++++---------- lisa/tests/test_platform.py | 26 ++++---- 4 files changed, 92 insertions(+), 50 deletions(-) diff --git a/lisa/environment.py b/lisa/environment.py index e42424349..ec6df3842 100644 --- a/lisa/environment.py +++ b/lisa/environment.py @@ -212,7 +212,9 @@ class Environments(EnvironmentsDict): nodes_requirement=requirement.nodes, ) return self.from_runbook( - runbook=runbook, name=f"req_{len(self.keys())}", is_original_runbook=False + runbook=runbook, + name=f"generated_{len(self.keys())}", + is_original_runbook=False, ) def from_runbook( @@ -250,7 +252,7 @@ def load_environments( for environment_runbook in environments_runbook: env = environments.from_runbook( runbook=environment_runbook, - name=f"runbook_{len(environments)}", + name=f"customized_{len(environments)}", is_original_runbook=True, ) assert env, "created from runbook shouldn't be None" diff --git a/lisa/tests/test_environment.py b/lisa/tests/test_environment.py index a10f882e0..722440e32 100644 --- a/lisa/tests/test_environment.py +++ b/lisa/tests/test_environment.py @@ -86,7 +86,7 @@ class EnvironmentTestCase(TestCase): runbook = generate_runbook(local=True, requirement=True) envs = load_environments(runbook) self.assertEqual(2, len(envs)) - env = envs.get("runbook_0") + env = envs.get("customized_0") assert env for node in env.nodes.list(): # mock initializing @@ -100,7 +100,7 @@ class EnvironmentTestCase(TestCase): self.assertEqual(search_space.IntRange(min=1), env_cap.nodes[0].disk_count) # test pure node_requirement - env = envs.get("runbook_1") + env = envs.get("customized_1") assert env env_cap = env.capability self.assertEqual(2, len(env_cap.nodes)) diff --git a/lisa/tests/test_lisarunner.py b/lisa/tests/test_lisarunner.py index 75b4c745a..818213845 100644 --- a/lisa/tests/test_lisarunner.py +++ b/lisa/tests/test_lisarunner.py @@ -63,7 +63,7 @@ class LisaRunnerTestCase(TestCase): ) # 3 cases create 3 envs self.assertListEqual( - ["req_0", "req_1", "req_2"], + ["generated_0", "generated_1", "generated_2"], [x for x in envs], ) self.verify_test_results( @@ -79,7 +79,7 @@ class LisaRunnerTestCase(TestCase): env_runbook = generate_env_runbook(remote=True) envs = load_environments(env_runbook) self.assertListEqual( - ["runbook_0"], + ["customized_0"], [x for x in envs], ) @@ -91,9 +91,9 @@ class LisaRunnerTestCase(TestCase): platform_type=constants.PLATFORM_MOCK, ) - # 3 cases created only two req, as simple req meets on runbook_0 + # 3 cases created only two req, as simple req meets on customized_0 self.assertListEqual( - ["runbook_0", "req_1", "req_2"], + ["customized_0", "generated_1", "generated_2"], [x for x in envs], ) self.assertListEqual( @@ -108,7 +108,7 @@ class LisaRunnerTestCase(TestCase): env_runbook = generate_env_runbook(remote=True) envs = load_environments(env_runbook) self.assertListEqual( - ["runbook_0"], + ["customized_0"], [x for x in envs], ) runner = generate_lisarunner(env_runbook) @@ -122,7 +122,7 @@ class LisaRunnerTestCase(TestCase): ) # every case need a new environment, so created 3 self.assertListEqual( - ["runbook_0", "req_1", "req_2", "req_3"], + ["customized_0", "generated_1", "generated_2", "generated_3"], [x for x in envs], ) self.verify_test_results( @@ -215,12 +215,12 @@ class LisaRunnerTestCase(TestCase): runner = generate_lisarunner(env_runbook) asyncio.run(runner.start()) self.verify_env_results( - expected_prepared=["runbook_0", "req_1", "req_2"], - expected_deployed_envs=["runbook_0", "req_1"], - expected_deleted_envs=["runbook_0", "req_1"], + expected_prepared=["customized_0", "generated_1", "generated_2"], + expected_deployed_envs=["customized_0", "generated_1"], + expected_deleted_envs=["customized_0", "generated_1"], ) self.verify_test_results( - expected_envs=["req_1", "runbook_0", "runbook_0"], + expected_envs=["generated_1", "customized_0", "customized_0"], expected_status=[TestStatus.PASSED, TestStatus.PASSED, TestStatus.PASSED], expected_message=["", "", ""], test_results=runner._latest_test_results, @@ -234,12 +234,17 @@ class LisaRunnerTestCase(TestCase): runner = generate_lisarunner(env_runbook) asyncio.run(runner.start()) self.verify_env_results( - expected_prepared=["runbook_0", "req_1", "req_2", "req_3"], - expected_deployed_envs=["runbook_0"], - expected_deleted_envs=["runbook_0"], + expected_prepared=[ + "customized_0", + "generated_1", + "generated_2", + "generated_3", + ], + expected_deployed_envs=["customized_0"], + expected_deleted_envs=["customized_0"], ) self.verify_test_results( - expected_envs=["runbook_0", "runbook_0", "runbook_0"], + expected_envs=["customized_0", "customized_0", "customized_0"], expected_status=[TestStatus.PASSED, TestStatus.PASSED, TestStatus.PASSED], expected_message=["", "", ""], test_results=runner._latest_test_results, @@ -253,31 +258,41 @@ class LisaRunnerTestCase(TestCase): runner = generate_lisarunner(env_runbook, case_use_new_env=True) asyncio.run(runner.start()) self.verify_env_results( - expected_prepared=["runbook_0", "req_1", "req_2", "req_3"], - expected_deployed_envs=["runbook_0", "req_1", "req_3"], - expected_deleted_envs=["runbook_0", "req_1", "req_3"], + expected_prepared=[ + "customized_0", + "generated_1", + "generated_2", + "generated_3", + ], + expected_deployed_envs=["customized_0", "generated_1", "generated_3"], + expected_deleted_envs=["customized_0", "generated_1", "generated_3"], ) self.verify_test_results( - expected_envs=["runbook_0", "req_1", "req_3"], + expected_envs=["customized_0", "generated_1", "generated_3"], expected_status=[TestStatus.PASSED, TestStatus.PASSED, TestStatus.PASSED], expected_message=["", "", ""], test_results=runner._latest_test_results, ) def test_no_needed_env(self) -> None: - # two 1 node env predefined, but only runbook_0 go to deploy - # no cases assigned to runbook_1, as fit cases run on runbook_0 already + # two 1 node env predefined, but only customized_0 go to deploy + # no cases assigned to customized_1, as fit cases run on customized_0 already generate_cases_metadata() env_runbook = generate_env_runbook(local=True, remote=True) runner = generate_lisarunner(env_runbook) asyncio.run(runner.start()) self.verify_env_results( - expected_prepared=["runbook_0", "runbook_1", "req_2", "req_3"], - expected_deployed_envs=["runbook_0", "req_2"], - expected_deleted_envs=["runbook_0", "req_2"], + expected_prepared=[ + "customized_0", + "customized_1", + "generated_2", + "generated_3", + ], + expected_deployed_envs=["customized_0", "generated_2"], + expected_deleted_envs=["customized_0", "generated_2"], ) self.verify_test_results( - expected_envs=["req_2", "runbook_0", "runbook_0"], + expected_envs=["generated_2", "customized_0", "customized_0"], expected_status=[TestStatus.PASSED, TestStatus.PASSED, TestStatus.PASSED], expected_message=["", "", ""], test_results=runner._latest_test_results, @@ -294,7 +309,12 @@ class LisaRunnerTestCase(TestCase): asyncio.run(runner.start()) self.verify_env_results( - expected_prepared=["runbook_0", "req_1", "req_2", "req_3"], + expected_prepared=[ + "customized_0", + "generated_1", + "generated_2", + "generated_3", + ], expected_deployed_envs=[], expected_deleted_envs=[], ) @@ -322,13 +342,18 @@ class LisaRunnerTestCase(TestCase): runner = generate_lisarunner(env_runbook) asyncio.run(runner.start()) self.verify_env_results( - expected_prepared=["runbook_0", "req_1", "req_2", "req_3"], - expected_deployed_envs=["runbook_0"], - expected_deleted_envs=["runbook_0"], + expected_prepared=[ + "customized_0", + "generated_1", + "generated_2", + "generated_3", + ], + expected_deployed_envs=["customized_0"], + expected_deleted_envs=["customized_0"], ) before_suite_failed = "before_suite: failed" self.verify_test_results( - expected_envs=["runbook_0", "runbook_0", "runbook_0"], + expected_envs=["customized_0", "customized_0", "customized_0"], expected_status=[ TestStatus.SKIPPED, TestStatus.SKIPPED, @@ -346,7 +371,12 @@ class LisaRunnerTestCase(TestCase): runner = generate_lisarunner(env_runbook) asyncio.run(runner.start()) self.verify_env_results( - expected_prepared=["runbook_0", "req_1", "req_2", "req_3"], + expected_prepared=[ + "customized_0", + "generated_1", + "generated_2", + "generated_3", + ], expected_deployed_envs=[], expected_deleted_envs=[], ) @@ -371,8 +401,18 @@ class LisaRunnerTestCase(TestCase): runner = generate_lisarunner(env_runbook) asyncio.run(runner.start()) self.verify_env_results( - expected_prepared=["runbook_0", "req_1", "req_2", "req_3"], - expected_deployed_envs=["runbook_0", "req_1", "req_2", "req_3"], + expected_prepared=[ + "customized_0", + "generated_1", + "generated_2", + "generated_3", + ], + expected_deployed_envs=[ + "customized_0", + "generated_1", + "generated_2", + "generated_3", + ], expected_deleted_envs=[], ) no_avaiable_env = "no available environment" @@ -395,7 +435,7 @@ class LisaRunnerTestCase(TestCase): asyncio.run(runner.start()) # still prepare predefined, but not deploy self.verify_env_results( - expected_prepared=["runbook_0"], + expected_prepared=["customized_0"], expected_deployed_envs=[], expected_deleted_envs=[], ) diff --git a/lisa/tests/test_platform.py b/lisa/tests/test_platform.py index cb8d59b83..f931e04f6 100644 --- a/lisa/tests/test_platform.py +++ b/lisa/tests/test_platform.py @@ -135,25 +135,25 @@ class PlatformTestCase(TestCase): envs = generate_environments() # verify init as expected - self.assertListEqual(["runbook_0", "runbook_1"], [x for x in envs]) + self.assertListEqual(["customized_0", "customized_1"], [x for x in envs]) self.assertListEqual([True, True], [x.is_predefined for x in envs.values()]) # verify stable sort - envs["runbook_1"].is_predefined = False + envs["customized_1"].is_predefined = False prepared_environments = platform.prepare_environments(envs) self.assertListEqual( - ["runbook_0", "runbook_1"], [x.name for x in prepared_environments] + ["customized_0", "customized_1"], [x.name for x in prepared_environments] ) self.assertListEqual( [True, False], [x.is_predefined for x in prepared_environments] ) # verify reverse sort - envs["runbook_0"].is_predefined = False - envs["runbook_1"].is_predefined = True + envs["customized_0"].is_predefined = False + envs["customized_1"].is_predefined = True prepared_environments = platform.prepare_environments(envs) self.assertListEqual( - ["runbook_1", "runbook_0"], + ["customized_1", "customized_0"], [x.name for x in prepared_environments], ) self.assertListEqual( @@ -165,22 +165,22 @@ class PlatformTestCase(TestCase): envs = generate_environments() platform.set_test_config() - self.assertListEqual(["runbook_0", "runbook_1"], [x for x in envs]) + self.assertListEqual(["customized_0", "customized_1"], [x for x in envs]) self.assertListEqual([0, 0], [x.cost for x in envs.values()]) - envs["runbook_0"].cost = 1 - envs["runbook_1"].cost = 2 + envs["customized_0"].cost = 1 + envs["customized_1"].cost = 2 prepared_environments = platform.prepare_environments(envs) self.assertListEqual( - ["runbook_0", "runbook_1"], [x.name for x in prepared_environments] + ["customized_0", "customized_1"], [x.name for x in prepared_environments] ) self.assertListEqual([1, 2], [x.cost for x in prepared_environments]) - envs["runbook_0"].cost = 2 - envs["runbook_1"].cost = 1 + envs["customized_0"].cost = 2 + envs["customized_1"].cost = 1 prepared_environments = platform.prepare_environments(envs) self.assertListEqual( - ["runbook_1", "runbook_0"], [x.name for x in prepared_environments] + ["customized_1", "customized_0"], [x.name for x in prepared_environments] ) self.assertListEqual([1, 2], [x.cost for x in prepared_environments])