def test_push_updates_behaviour_configuration_if_exists(self): pkg_sim = self.simlab.simulate_pkg_type_with_behaviour() pkg = Pkg(pkg_sim.path) push_options = PushOptions() lm_sim = self.simlab.simulate_lm() lm_sim.add_project({ 'id': 'type::with_behaviour::1.0', 'name': 'type::with_behaviour::1.0' }) lm_sim.add_assembly_configuration({ 'id': 'existing', 'projectId': 'type::with_behaviour::1.0', 'name': 'simple' }) lm_session = lm_sim.as_mocked_session() env_sessions = EnvironmentSessions(lm_session) result = pkg.push(env_sessions, push_options) self.assertIsInstance(result, PkgContent) lm_session.behaviour_driver.create_assembly_configuration.assert_not_called( ) lm_session.behaviour_driver.update_assembly_configuration.assert_called_once_with( { "id": "existing", "name": "simple", "projectId": "type::with_behaviour::1.0", "description": "a simple assembly config", "properties": { "a": "123" }, "createdAt": "2019-01-01T01:00:00.613Z", "lastModifiedAt": "2019-01-02T01:00:00.613Z", "descriptorName": "type::with_behaviour::1.0" })
def test_push(self): pkg_sim = self.simlab.simulate_pkg_assembly_contains_brent_2dot1_basic( ) pkg = Pkg(pkg_sim.path) push_options = PushOptions() lm_sim = self.simlab.simulate_lm() lm_sim.add_rm({'name': 'brent', 'url': 'http://brent:8443'}) lm_session = lm_sim.as_mocked_session() env_sessions = EnvironmentSessions(lm_session) result = pkg.push(env_sessions, push_options) self.assertIsInstance(result, PkgContent) res_pkg_path = os.path.join(result.tree.root_path, PROJECT_CONTAINS_DIR, project_lab.SUBPROJECT_NAME_BRENT_BASIC, 'sub_basic-contains_basic.zip') lm_session.descriptor_driver.delete_descriptor.assert_called_once_with( 'resource::sub_basic-contains_basic::1.0') lm_session.resource_pkg_driver.delete_package.assert_called_once_with( 'resource::sub_basic-contains_basic::1.0') lm_session.resource_pkg_driver.onboard_package.assert_called_once_with( res_pkg_path) lm_session.onboard_rm_driver.get_rm_by_name.assert_called_once_with( 'brent') lm_session.onboard_rm_driver.update_rm.assert_called_once_with({ 'name': 'brent', 'url': 'http://brent:8443' })
def test_runs_test_scenarios(self): pkg_sim = self.simlab.simulate_pkg_assembly_contains_assembly_with_behaviour() pkg = Pkg(pkg_sim.path) push_options = PushOptions() test_options = TestOptions() lm_sim = self.simlab.simulate_lm() lm_session = lm_sim.as_mocked_session() env_sessions = EnvironmentSessions(lm_session) result = pkg.push(env_sessions, push_options).test(env_sessions, test_options) self.assertIsInstance(result, PkgTestReport) self.assertEqual(result.name, 'contains_with_behaviour') self.assertEqual(result.full_name, 'contains_with_behaviour') self.assertIsInstance(result.suite_report, TestSuiteExecutionReport) self.assertEqual(len(result.suite_report.entries), 0) self.assertEqual(len(result.sub_reports), 1) sub_report = result.sub_reports[0] self.assertEqual(sub_report.name, 'sub_with_behaviour') self.assertEqual(sub_report.full_name, 'sub_with_behaviour-contains_with_behaviour') self.assertEqual(len(sub_report.suite_report.entries), 1) self.assertEqual(sub_report.suite_report.entries[0].test_name, 'test') self.assertEqual(sub_report.suite_report.entries[0].result, TEST_STATUS_PASSED) self.assertIsNone(sub_report.suite_report.entries[0].detail) scenarios_on_project = lm_sim.get_scenarios_on_project('assembly::sub_with_behaviour-contains_with_behaviour::1.0') expected_scenario = next((x for x in scenarios_on_project if x['name'] == 'test'), None) lm_session.behaviour_driver.execute_scenario.assert_called_once_with(expected_scenario['id']) scenario_executions = lm_sim.get_executions_on_scenario(expected_scenario['id']) self.assertEqual(len(scenario_executions), 1) lm_session.behaviour_driver.get_execution.assert_called_with(scenario_executions[0]['id'])
def test_runs_multi_tests(self): pkg_sim = self.simlab.simulate_pkg_assembly_with_behaviour_multi_tests() pkg = Pkg(pkg_sim.path) push_options = PushOptions() test_options = TestOptions() lm_sim = self.simlab.simulate_lm() lm_session = lm_sim.as_mocked_session() env_sessions = EnvironmentSessions(lm_session) result = pkg.push(env_sessions, push_options).test(env_sessions, test_options) self.assertEqual(len(result.suite_report.entries), 3) test1_entry = None test2_entry = None test3_entry = None for entry in result.suite_report.entries: if entry.test_name == 'test': test1_entry = entry elif entry.test_name == 'test2': test2_entry = entry elif entry.test_name == 'test3': test3_entry = entry self.assertEqual(test1_entry.test_name, 'test') self.assertEqual(test1_entry.result, TEST_STATUS_PASSED) self.assertIsNone(test1_entry.detail) self.assertEqual(test2_entry.test_name, 'test2') self.assertEqual(test2_entry.result, TEST_STATUS_PASSED) self.assertIsNone(test2_entry.detail) self.assertEqual(test3_entry.test_name, 'test3') self.assertEqual(test3_entry.result, TEST_STATUS_PASSED) self.assertIsNone(test3_entry.detail) scenarios_on_project = lm_sim.get_scenarios_on_project('assembly::with_behaviour_multi_tests::1.0') expected_calls = [] for scenario in scenarios_on_project: if scenario['name'] != 'runtime': expected_calls.append(call(scenario['id'])) lm_session.behaviour_driver.execute_scenario.assert_has_calls(expected_calls)
def test_reports_test_failure(self): pkg_sim = self.simlab.simulate_pkg_assembly_with_behaviour_multi_tests() pkg = Pkg(pkg_sim.path) push_options = PushOptions() test_options = TestOptions() lm_sim = self.simlab.simulate_lm() lm_sim.execution_listener.add_step_failure_trigger('assembly::with_behaviour_multi_tests::1.0', 'test2', 1, 0, 'Mocked Error') lm_session = lm_sim.as_mocked_session() env_sessions = EnvironmentSessions(lm_session) result = pkg.push(env_sessions, push_options).test(env_sessions, test_options) self.assertEqual(len(result.suite_report.entries), 3) test1_entry = None test2_entry = None test3_entry = None for entry in result.suite_report.entries: if entry.test_name == 'test': test1_entry = entry elif entry.test_name == 'test2': test2_entry = entry elif entry.test_name == 'test3': test3_entry = entry self.assertEqual(test1_entry.test_name, 'test') self.assertEqual(test1_entry.result, TEST_STATUS_PASSED) self.assertIsNone(test1_entry.detail) self.assertEqual(test2_entry.test_name, 'test2') self.assertEqual(test2_entry.result, TEST_STATUS_FAILED) self.assertEqual(test2_entry.detail, 'test2 failed: Mocked Error') self.assertEqual(test3_entry.test_name, 'test3') self.assertEqual(test3_entry.result, TEST_STATUS_PASSED) self.assertIsNone(test3_entry.detail)
def test_push_creates_behaviour_configuration(self): pkg_sim = self.simlab.simulate_pkg_assembly_contains_assembly_with_behaviour( ) pkg = Pkg(pkg_sim.path) push_options = PushOptions() lm_sim = self.simlab.simulate_lm() lm_session = lm_sim.as_mocked_session() env_sessions = EnvironmentSessions(lm_session) result = pkg.push(env_sessions, push_options) self.assertIsInstance(result, PkgContent) lm_session.behaviour_driver.create_assembly_configuration.assert_called_once_with( { "name": "simple", "projectId": "assembly::sub_with_behaviour-contains_with_behaviour::1.0", "description": "a simple assembly config", "properties": { "a": "123" }, "createdAt": "2019-01-01T01:00:00.613Z", "lastModifiedAt": "2019-01-02T01:00:00.613Z", "descriptorName": "assembly::sub_with_behaviour-contains_with_behaviour::1.0" })
def test_push(self): pkg_sim = self.simlab.simulate_pkg_assembly_contains_arm_basic() pkg = Pkg(pkg_sim.path) push_options = PushOptions() arm_sim = self.simlab.simulate_arm() arm_session = arm_sim.as_mocked_session() lm_sim = self.simlab.simulate_lm() lm_sim.add_rm({ 'name': arm_session.env.name, 'url': arm_session.env.address }) lm_session = lm_sim.as_mocked_session() env_sessions = EnvironmentSessions(lm_session, arm_session) result = pkg.push(env_sessions, push_options) self.assertIsInstance(result, PkgContent) csar_path = os.path.join(result.tree.root_path, PROJECT_CONTAINS_DIR, project_lab.SUBPROJECT_NAME_ARM_BASIC, 'sub_basic-contains_basic.csar') arm_session.arm_driver.onboard_type.assert_called_once_with( 'sub_basic-contains_basic', '1.0', csar_path) lm_session.onboard_rm_driver.get_rm_by_name.assert_called_once_with( arm_session.env.name) lm_session.onboard_rm_driver.update_rm.assert_called_once_with({ 'name': arm_session.env.name, 'url': arm_session.env.address })
def test_push(self): pkg_sim = self.simlab.simulate_pkg_brent_basic() pkg = Pkg(pkg_sim.path) push_options = PushOptions() lm_sim = self.simlab.simulate_lm() lm_sim.add_rm({'name': 'brent', 'url': 'http://brent:8443'}) lm_session = lm_sim.as_mocked_session() env_sessions = EnvironmentSessions(lm_session) result = pkg.push(env_sessions, push_options) self.assertIsInstance(result, PkgContent) res_pkg_path = os.path.join(result.tree.root_path, 'basic.zip') lm_session.descriptor_driver.delete_descriptor.assert_called_once_with( 'resource::basic::1.0') lm_session.resource_pkg_driver.delete_package.assert_called_once_with( 'resource::basic::1.0') lm_session.resource_pkg_driver.onboard_package.assert_called_once_with( res_pkg_path) lm_session.onboard_rm_driver.get_rm_by_name.assert_called_once_with( 'brent') lm_session.onboard_rm_driver.update_rm.assert_called_once_with({ 'name': 'brent', 'url': 'http://brent:8443' })
def test_inspect(self): pkg_sim = self.simlab.simulate_pkg_assembly_basic() pkg = Pkg(pkg_sim.path) inspection_report = pkg.inspect() self.assertEqual(inspection_report.name, 'basic') self.assertEqual(inspection_report.version, '1.0') self.assertEqual(len(inspection_report.includes), 1) first_include = inspection_report.includes[0] self.assertEqual(first_include.name, 'basic') self.assertEqual(first_include.descriptor_name, 'assembly::basic::1.0') self.assertIsNone(first_include.resource_manager)
def test_push_creates_descriptor(self): pkg_sim = self.simlab.simulate_pkg_type_basic() pkg = Pkg(pkg_sim.path) push_options = PushOptions() lm_sim = self.simlab.simulate_lm() lm_session = lm_sim.as_mocked_session() env_sessions = EnvironmentSessions(lm_session) result = pkg.push(env_sessions, push_options) self.assertIsInstance(result, PkgContent) lm_session.descriptor_driver.get_descriptor.assert_called_once_with( 'type::basic::1.0') lm_session.descriptor_driver.create_descriptor.assert_called_once_with( 'name: type::basic::1.0\ndescription: descriptor for basic\n')
def test_extract(self): pkg_sim = self.simlab.simulate_pkg_assembly_basic() pkg = Pkg(pkg_sim.path) tmp_dir = tempfile.mkdtemp() try: pkg.extract(tmp_dir) self.assertTrue( os.path.exists(os.path.join(tmp_dir, PKG_META_YML_FILE))) self.assertTrue( os.path.exists(os.path.join(tmp_dir, ASSEMBLY_DESCRIPTOR_DIR))) finally: if os.path.exists(tmp_dir): shutil.rmtree(tmp_dir)
def test_push_creates_descriptor_template(self): pkg_sim = self.simlab.simulate_pkg_assembly_with_template() pkg = Pkg(pkg_sim.path) push_options = PushOptions() lm_sim = self.simlab.simulate_lm() lm_session = lm_sim.as_mocked_session() env_sessions = EnvironmentSessions(lm_session) result = pkg.push(env_sessions, push_options) self.assertIsInstance(result, PkgContent) lm_session.descriptor_template_driver.get_descriptor_template.assert_called_once_with( 'assembly-template::with_template::1.0') lm_session.descriptor_template_driver.create_descriptor_template.assert_called_once_with( WITH_TEMPLATE_ASSEMBLY_TEMPLATE_DESCRIPTOR_YAML)
def test_push_creates_behaviour_scenarios(self): pkg_sim = self.simlab.simulate_pkg_type_with_behaviour() pkg = Pkg(pkg_sim.path) push_options = PushOptions() lm_sim = self.simlab.simulate_lm() lm_sim.add_project({ 'id': 'type::with_behaviour::1.0', 'name': 'type::with_behaviour::1.0' }) lm_sim.add_assembly_configuration({ 'id': 'existing', 'projectId': 'type::with_behaviour::1.0', 'name': 'simple' }) lm_session = lm_sim.as_mocked_session() env_sessions = EnvironmentSessions(lm_session) result = pkg.push(env_sessions, push_options) self.assertIsInstance(result, PkgContent) lm_session.behaviour_driver.create_scenario.assert_has_calls([ call({ "name": "test", "projectId": "type::with_behaviour::1.0", "description": "a test scenario", "stages": [{ "name": "Stage One", "steps": [{ "stepDefinitionName": "Utilities::SleepForTime", "properties": { "sleepTime": "20", "timeUnit": "seconds" } }] }], "assemblyActors": [{ "instanceName": "simple", "assemblyConfigurationId": "existing", "initialState": "Active", "uninstallOnExit": True, "provided": False }], "createdAt": "2019-01-01T01:00:00.613Z", "lastModifiedAt": "2019-01-02T01:00:00.613Z" }) ])
def test_runs_with_no_tests(self): pkg_sim = self.simlab.simulate_pkg_assembly_basic() pkg = Pkg(pkg_sim.path) push_options = PushOptions() test_options = TestOptions() lm_sim = self.simlab.simulate_lm() lm_session = lm_sim.as_mocked_session() env_sessions = EnvironmentSessions(lm_session) result = pkg.push(env_sessions, push_options).test(env_sessions, test_options) self.assertIsInstance(result, PkgTestReport) self.assertEqual(result.name, 'basic') self.assertEqual(result.full_name, 'basic') self.assertIsInstance(result.suite_report, TestSuiteExecutionReport) self.assertEqual(len(result.suite_report.entries), 0)
def test_inspect_with_subcontent(self): pkg_sim = self.simlab.simulate_pkg_assembly_contains_brent_basic() pkg = Pkg(pkg_sim.path) inspection_report = pkg.inspect() self.assertEqual(inspection_report.name, 'contains_basic') self.assertEqual(inspection_report.version, '1.0') self.assertEqual(len(inspection_report.includes), 2) first_include = inspection_report.includes[0] self.assertEqual(first_include.name, 'contains_basic') self.assertEqual(first_include.descriptor_name, 'assembly::contains_basic::1.0') self.assertIsNone(first_include.resource_manager) second_include = inspection_report.includes[1] self.assertEqual(second_include.name, 'sub_basic-contains_basic') self.assertEqual(second_include.descriptor_name, 'resource::sub_basic-contains_basic::1.0') self.assertEqual(second_include.resource_manager, 'brent')
def test_push_updates_descriptors_if_exists(self): pkg_sim = self.simlab.simulate_pkg_assembly_basic() pkg = Pkg(pkg_sim.path) push_options = PushOptions() lm_sim = self.simlab.simulate_lm() lm_sim.add_descriptor( 'name: assembly::basic::1.0\ndescription: pre-update basic_assembly\n' ) lm_session = lm_sim.as_mocked_session() env_sessions = EnvironmentSessions(lm_session) result = pkg.push(env_sessions, push_options) self.assertIsInstance(result, PkgContent) lm_session.descriptor_driver.get_descriptor.assert_called_once_with( 'assembly::basic::1.0') lm_session.descriptor_driver.create_descriptor.assert_not_called() lm_session.descriptor_driver.update_descriptor.assert_called_once_with( 'assembly::basic::1.0', 'name: assembly::basic::1.0\ndescription: basic_assembly\n')
def test_open_pkg_with_deprecated_content_directory(self): pkg_sim = self.simlab.simulate_pkg_assembly_deprecated_content_basic() pkg = Pkg(pkg_sim.path) tmp_dir = tempfile.mkdtemp() try: content = pkg.open(tmp_dir) self.assertIsInstance(content, PkgContent) # Pkg opened in content directory self.assertEqual(content.tree.root_path, os.path.join(tmp_dir, PKG_DEPRECATED_CONTENT_DIR)) # Pkg meta file still reachable self.assertTrue( os.path.exists( os.path.join(content.tree.root_path, PKG_META_YML_FILE))) self.assertTrue( os.path.exists( os.path.join(content.tree.root_path, ASSEMBLY_DESCRIPTOR_DIR))) finally: if os.path.exists(tmp_dir): shutil.rmtree(tmp_dir)
def test_extract_pkg_with_deprecated_content_directory(self): pkg_sim = self.simlab.simulate_pkg_assembly_deprecated_content_basic() pkg = Pkg(pkg_sim.path) tmp_dir = tempfile.mkdtemp() try: pkg.extract(tmp_dir) self.assertTrue( os.path.exists(os.path.join(tmp_dir, PKG_META_YML_FILE))) # Content nested under a "content" directory self.assertTrue( os.path.exists( os.path.join(tmp_dir, PKG_DEPRECATED_CONTENT_DIR))) self.assertFalse( os.path.exists(os.path.join(tmp_dir, ASSEMBLY_DESCRIPTOR_DIR))) self.assertTrue( os.path.exists( os.path.join(tmp_dir, PKG_DEPRECATED_CONTENT_DIR, ASSEMBLY_DESCRIPTOR_DIR))) finally: if os.path.exists(tmp_dir): shutil.rmtree(tmp_dir)
def test_push_creates_descriptor(self): pkg_sim = self.simlab.simulate_pkg_assembly_contains_assembly_basic() pkg = Pkg(pkg_sim.path) push_options = PushOptions() lm_sim = self.simlab.simulate_lm() lm_session = lm_sim.as_mocked_session() env_sessions = EnvironmentSessions(lm_session) result = pkg.push(env_sessions, push_options) self.assertIsInstance(result, PkgContent) lm_session.descriptor_driver.get_descriptor.assert_has_calls([ call('assembly::sub_basic-contains_basic::1.0'), call('assembly::contains_basic::1.0') ]) lm_session.descriptor_driver.create_descriptor.assert_has_calls([ call( 'name: assembly::sub_basic-contains_basic::1.0\ndescription: descriptor\n' ), call( 'name: assembly::contains_basic::1.0\ndescription: basic_assembly\n' ) ])
def test_push(self): pkg_sim = self.simlab.simulate_pkg_assembly_old_style() pkg = Pkg(pkg_sim.path) push_options = PushOptions() arm_sim = self.simlab.simulate_arm() arm_session = arm_sim.as_mocked_session() lm_sim = self.simlab.simulate_lm() lm_sim.add_rm({ 'name': arm_session.env.name, 'url': arm_session.env.address }) lm_session = lm_sim.as_mocked_session() env_sessions = EnvironmentSessions(lm_session, arm_session) result = pkg.push(env_sessions, push_options) self.assertIsInstance(result, PkgContent) csar_a_path = os.path.join(result.tree.root_path, PROJECT_CONTAINS_DIR, 'vnfcA', 'vnfcA.csar') csar_b_path = os.path.join(result.tree.root_path, PROJECT_CONTAINS_DIR, 'vnfcB', 'vnfcB.csar') arm_session.arm_driver.onboard_type.assert_has_calls([ call('vnfcA', '1.0', csar_a_path), call('vnfcB', '2.0', csar_b_path) ])