def d_test_save_as_test_case_with_ports(self, stc): plLogger = PLLogger.GetLogger('methodology') plLogger.LogInfo("begin") # TODO: Fix this once the test case work is finished if True: plLogger.LogWarn("Fix me after test cases have been repaired.") return ctor = CScriptableCreator() meth_name = "TestMeth_SaveAsTestCase" stc_sys = CStcSystem.Instance() meth_man_pkg = "spirent.methodology.manager" # Defaults port_loc = "//10.14.16.20/2/1" mac_addr = "00:01:94:00:00:01" enable_vlan = False vlan_id = 100 ipv4_addr = "192.85.1.3" plLogger.LogInfo("Create a test package") test_name, name_dict = TestSaveTestCase.make_fake_test_pkg(mac_addr, enable_vlan, vlan_id, ipv4_addr, port_loc, meth_name) # Build a port_map for validation (flip the name_dict) port_map = {} port_map[name_dict[port_loc]] = port_loc plLogger.LogInfo("Import the methodology " + test_name) # Import the test methodology (make available) cmd = ctor.CreateCommand(meth_man_pkg + ".ImportTestCommand") cmd.Set("fileName", test_name + ".stm") cmd.Execute() cmd.MarkDelete() plLogger.LogInfo("Verify that the TXML file exists after import") # Check the TXML file exists install_dir = os.path.join(stc_sys.GetApplicationCommonDataPath(), mgr_const.MM_TEST_METH_DIR) test_meth_dir = os.path.join(install_dir, meth_name) assert os.path.exists(test_meth_dir) test_case_dir = os.path.join(test_meth_dir, mgr_const.MM_TEST_CASE_SUBDIR) assert os.path.exists(test_case_dir) file_list = os.listdir(test_case_dir) assert len(file_list) == 1 meta_file = file_list[0] assert meta_file == mgr_const.MM_META_FILE_NAME plLogger.LogInfo("Verify the TXML file contents haven't changed") # Check TXML defaults TestSaveTestCase.check_txml_values(meta_file, meta_man.TEST_INSTANCE_ORIGINAL, mac_addr, enable_vlan, vlan_id, ipv4_addr, port_map, meth_name) new_port_loc = "//10.14.16.27/2/1" new_mac = "00:01:95:CC:CC:0s" new_enable_vlan = "true" new_vlan = "541" new_ip = "182.0.0.1" # New port_map (for validation) new_port_map = {} new_port_map[name_dict[port_loc]] = new_port_loc # Create JSON string with new defaults json_input = "{\"ports\" : {\"" + name_dict[port_loc] + "\" : \"" + \ new_port_loc + "\"},\"params\" : {\"" + \ name_dict["MacAddr"] + "\" : \"" + new_mac + "\"," + \ " \"" + name_dict["EnableVlan"] + "\" : \"" + new_enable_vlan + "\"," + \ " \"" + name_dict["VlanId"] + "\" : \"" + new_vlan + "\"," + \ " \"" + name_dict["Ipv4Addr"] + "\" : \"" + new_ip + "\" }}" plLogger.LogInfo("Execute SaveTestCaseCommand with json_input: \n" + json_input) # Create a new "instance" of the testcase new_test_case = "MyNewTestCase" cmd = ctor.CreateCommand(meth_man_pkg + ".SaveTestCaseCommand") cmd.Set("TestMethodologyName", test_name) cmd.Set("InputJson", json_input) cmd.Set("TestCaseName", new_test_case) cmd.Execute() # Get the TXML file path new_txml_file_path = cmd.Get("TxmlFileName") new_txml_file = os.path.split(new_txml_file_path)[-1] cmd.MarkDelete() # Check the TXML file exists install_dir = os.path.join(stc_sys.GetApplicationCommonDataPath(), mgr_const.MM_TEST_METH_DIR) test_meth_dir = os.path.join(install_dir, meth_name) assert os.path.exists(test_meth_dir) test_case_dir = os.path.join(test_meth_dir, mgr_const.MM_TEST_CASE_SUBDIR) assert os.path.exists(test_case_dir) file_list = os.listdir(test_case_dir) assert len(file_list) > 1 assert new_txml_file in file_list assert mgr_const.MM_META_FILE_NAME in file_list plLogger.LogInfo("Check the new saved file") TestSaveTestCase.check_txml_values(new_txml_file, new_test_case, new_mac, new_enable_vlan, new_vlan, new_ip, new_port_map, meth_name) plLogger.LogInfo("Verify the original hasn't changed") TestSaveTestCase.check_txml_values(mgr_const.MM_META_FILE_NAME, meta_man.TEST_INSTANCE_ORIGINAL, mac_addr, enable_vlan, vlan_id, ipv4_addr, port_map, meth_name) # Clean up anything that might be left from a previous run meth_handle = UnitTestUtils.get_methodology_handle(meth_name) UnitTestUtils.cleanup_methodology(meth_handle) plLogger.LogInfo("end")
def d_test_save_test_case(self, stc): plLogger = PLLogger.GetLogger('methodology') plLogger.LogInfo("begin") # TODO: Fix this once the test case work is finished if True: plLogger.LogWarn("Fix me after test cases have been repaired.") return ctor = CScriptableCreator() meth_name = "TestMeth_SaveTestCase" stc_sys = CStcSystem.Instance() meth_man_pkg = "spirent.methodology.manager" # Defaults mac_addr = "00:01:94:00:00:01" enable_vlan = False vlan_id = 100 ipv4_addr = "192.85.1.3" plLogger.LogInfo("Create and export the test") test_name, name_dict = TestSaveTestCase.make_fake_test_pkg(mac_addr, enable_vlan, vlan_id, ipv4_addr, "", meth_name) plLogger.LogInfo("name_dict: " + str(name_dict)) plLogger.LogInfo("test_name: " + test_name) new_mac = "00:01:95:CC:CC:05" new_enable_vlan = "true" new_vlan = "541" new_ip = "182.0.0.1" # Create JSON string with new defaults json_input = "{ \"ports\" : {}, \"params\" : {\"" + name_dict["MacAddr"] + "\" : \"" + \ new_mac + "\"," + \ " \"" + name_dict["EnableVlan"] + "\" : \"" + new_enable_vlan + "\"," + \ " \"" + name_dict["VlanId"] + "\" : \"" + new_vlan + "\"," + \ " \"" + name_dict["Ipv4Addr"] + "\" : \"" + new_ip + "\" } }" plLogger.LogInfo("Execute save test with json_input: \n" + json_input) # Change the defaults in "original" TXML by setting TestCaseName to "" cmd = ctor.CreateCommand(meth_man_pkg + ".SaveTestCaseCommand") cmd.Set("TestMethodologyName", test_name) cmd.Set("InputJson", json_input) cmd.Set("TestCaseName", "") cmd.Execute() cmd.MarkDelete() # Check the TXML file exists install_dir = os.path.join(stc_sys.GetApplicationCommonDataPath(), mgr_const.MM_TEST_METH_DIR) test_meth_dir = os.path.join(install_dir, meth_name) assert os.path.exists(test_meth_dir) test_case_dir = os.path.join(test_meth_dir, mgr_const.MM_TEST_CASE_SUBDIR) assert os.path.exists(test_case_dir) file_list = os.listdir(test_case_dir) assert len(file_list) == 1 meta_file = file_list[0] assert meta_file == mgr_const.MM_META_FILE_NAME # Check TXML defaults plLogger.LogInfo("check original txml has new values") TestSaveTestCase.check_txml_values(meta_file, meta_man.TEST_INSTANCE_ORIGINAL, new_mac, new_enable_vlan, new_vlan, new_ip, None, meth_name) # Clean up anything that might be left meth_handle = UnitTestUtils.get_methodology_handle(meth_name) UnitTestUtils.cleanup_methodology(meth_handle) plLogger.LogInfo("end")