def pd_login(self, driver, username, password): ''' Use default configurations in shared_config file to login PD ''' pd_browser_client = driver PD_DebugLog.stepinfo("Login PowerDirector") PD_DebugLog.debug_print("client browser title is " + pd_browser_client.title) assert "PowerDirector" in pd_browser_client.title PD_DebugLog.info_print("Page title: " + pd_browser_client.title) uid_input = pd_browser_client.find_element_by_id("uid") uid_input.send_keys(username) p_input = pd_browser_client.find_element_by_id("pword") p_input.send_keys(password) login_button = pd_browser_client.find_element_by_xpath("/html/body/div/form/div/p[4]/input") login_button.click() expect_welcome_panel = pd_browser_client.find_element_by_id("user_panel") welcome_text = "PowerDirector" try: if welcome_text in expect_welcome_panel.text: PD_DebugLog.debug_print(expect_welcome_panel.text) except: raise Login_Error("Login fails") pd_browser_client.quit() return pd_browser_client
def setUp(self): # 继承父类Basejob,调用环境设置过程 # 设置了日志输出文件接口:PD_DebugLog.xxx # 浏览器对象使用self.driver PD_DebugLog.info_print("Call the parent method setUp") Basejob.setUp(self)
def test_powerdown_vm_normally(self): u'''删除指定的已经存在虚拟机''' # # The id starts from 1. vm_id = 4 vm_name = "AutoTest_VM%02d" % vm_id vm_name = "PD3_Cluster_VM123" host_name = "localhost" ''' Find the virtual machine first, Then, decide if it is running. If yes, shutdown the virtual machine. The third is to delete it. And at the same to watch history or task bar to detect if the deletion is running or finished. ''' # Step 1: Login and pass in with username, password, server and port pd_client_browser = self.pd_login() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) self.pd_client_browser = pd_client_browser # Step 2: Make sure the host resource tab is selected PD_DebugLog.stepinfo("click and select the host resource tab") pd_browser_main_map = Main_Browser_UIMap(pd_client_browser) self.pd_browser_main_map = pd_browser_main_map platform_resource_tab = pd_browser_main_map.get_platform_resource_tab() platform_resource_tab.click() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) # Step 3: Got the directory tree frame and check all the levels # travel around the leaves elements sub_tree = pd_browser_main_map.get_platform_sub_menu_tree() if type(sub_tree) is list: sub_menu_tree_elem = sub_tree[0] else: sub_menu_tree_elem = sub_tree platform_tree = Submenu_Tree(sub_menu_tree_elem) PD_DebugLog.debug_print("The tree id is: " + platform_tree.get_submenu_tree_id()) tree_node = TreeNode(sub_menu_tree_elem) elemts = tree_node.get_all_child_nodes() if type(elemts) is list: fst_lvl_node_elm = elemts[0] else: fst_lvl_node_elm = elemts fst_lvl_node = TreeNode(fst_lvl_node_elm) PD_DebugLog.info_print("First level child node text is :" + fst_lvl_node.get_node_title() ) #platform_tree.travel_around_child_nodes() utils_misc.set_script_timeout(pd_client_browser, 0.2) pd_client_browser.implicitly_wait(6) elem = platform_tree.find_element_by_vmname(vm_name) if elem: elem_node = TreeNode(elem[0]) PD_DebugLog.info_print("Find the elem, the title is " + elem_node.get_node_title()) elem_node.click() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) utils_misc.restore_script_timeout(pd_client_browser) vm_summary_page = VM_Summary_UIMap(pd_client_browser) #task_startup_abouttime = time.time() # The testcase running machine time is not same as the AIX machine under test. vm_summary_page.execute_powerdown_system(True) # Step 4: Check the vm current status, it would turn into "in shutdown progress" check_return = utils_misc.wait_for(vm_summary_page.is_vm_in_powerdown_progress, 10, 0.2, 0.1, "Check if vm goes into shutdown status") self.assert_(check_return, "After execution of shutdown action, vm must go into 'in shutdown progess'") if check_return: # find the task item to get the item information: starttime, name and description # Then to watch when it disappears # The end, check it in the history of task to get the final status, success or fail. # If it failed, get the failure description. # Step 5: to check task status and wait the task finishes # if popup_task is not open, click the button again task_type = u'断电' utils_misc.wait_for(self.shutdown_task_appears, 10, 0, 0.1, "Shutdown vm task should appear in current tasks list") taskstarttime = self.get_task_starttime(task_type, vm_name, host_name) utils_misc.wait_for(self.shutdown_task_disappears, 10, 0, 0.1, "Shutdown vm task should finish and go into the history tasks list") status,fail_desc = self.get_task_status_from_history_task(task_type, vm_name, host_name, taskstarttime) if status == Messages.FAIL_STATUS_STR: self.fail("The task failed: " + fail_desc) else: PD_DebugLog.debug_print("The task finished successfully.") time.sleep(TestSpeedControl.TEST_STEP_INTERVAL)
def setUp(self): ''' Base job case need do setup stuff: 1. Read config from base configuration file tests-shared.cfg <tests-case>.cfg 2. Set the debug and info log files in the result directory 3. Start the PD web browser connection ''' self.shared_config = ConfigParser.ConfigParser() self.shared_config_file = os.path.join(Basejob.TESTCASE_DIR, 'cfg', 'tests-shared.cfg') PD_DebugLog.info_print("The shared_config is " + self.shared_config_file) if self.shared_config_file and os.path.exists(self.shared_config_file): self.shared_config.read(self.shared_config_file) else: raise ConfigFileError('%s not found' % (self.shared_config_file)) if self.need_config: self.config = ConfigParser.ConfigParser() self.config_file = 'cfg\\' + self.__class__.__name__ + '.cfg' logging.debug("The self.config_file is " + self.config_file) self.config_file = os.path.join(Basejob.TESTCASE_DIR, self.config_file) logging.debug("The self.config_file is " + self.config_file) if self.config_file and os.path.exists(self.config_file): self.config.read(self.config_file) else: raise ConfigFileError('%s not found' % (self.config_file)) logging.debug("Set up the log system") logfile_prefix = self._testMethodName logging.debug("Testcase name is " + logfile_prefix) testcasedir = os.path.join(Basejob.RESULT_DIR, logfile_prefix) self.testcasedir = testcasedir if not os.path.isdir(testcasedir): os.mkdir(testcasedir) infolog_file = logfile_prefix + '.info' debuglog_file = logfile_prefix + '.debug' # set log files infolog_file = os.path.join(testcasedir, infolog_file) infolvl_handler = logging.FileHandler(infolog_file, "w") fmt = logging.Formatter('[%(levelname)s:%(asctime)s]:%(message)s') infolvl_handler.setFormatter(fmt) infolvl_handler.setLevel(logging.INFO) logging.root.addHandler(infolvl_handler) debuglog_file = os.path.join(testcasedir, debuglog_file) debuglvl_handler = logging.FileHandler(debuglog_file, "w") fmt = logging.Formatter('[%(levelname)s:%(asctime)s]:%(message)s') debuglvl_handler.setFormatter(fmt) debuglvl_handler.setLevel(logging.DEBUG) logging.root.addHandler(debuglvl_handler) url_addr = self.shared_config.get('DEFAULT', 'url') url_port = self.shared_config.get('DEFAULT', 'port') self.pd_conn = PD_Connection(url_addr, url_port) self.driver = self.pd_client_browser = self.pd_conn.start()
def test_reboot_vm_normally(self): u'''重新启动指定的已经存在虚拟机''' # # The id starts from 1. vm_id = 4 vm_name = "AutoTest_VM%02d" % vm_id vm_name = "PD3_Cluster_VM123" host_name = "localhost" vm_name = "JAVA_VM62" ''' Find the virtual machine first, Then, decide if it is running. If yes, shutdown the virtual machine. The third is to delete it. And at the same to watch history or task bar to detect if the deletion is running or finished. ''' # Step 1: Login and pass in with username, password, server and port pd_client_browser = self.pd_login() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) self.pd_client_browser = pd_client_browser # Step 2: Make sure the host resource tab is selected PD_DebugLog.stepinfo("click and select the host resource tab") pd_browser_main_map = Main_Browser_UIMap(pd_client_browser) self.pd_browser_main_map = pd_browser_main_map platform_resource_tab = pd_browser_main_map.get_platform_resource_tab() platform_resource_tab.click() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) # Step 3: Got the directory tree frame and check all the levels # travel around the leaves elements sub_tree = pd_browser_main_map.get_platform_sub_menu_tree() if type(sub_tree) is list: sub_menu_tree_elem = sub_tree[0] else: sub_menu_tree_elem = sub_tree platform_tree = Submenu_Tree(sub_menu_tree_elem) PD_DebugLog.debug_print("The tree id is: " + platform_tree.get_submenu_tree_id()) tree_node = TreeNode(sub_menu_tree_elem) elemts = tree_node.get_all_child_nodes() if type(elemts) is list: fst_lvl_node_elm = elemts[0] else: fst_lvl_node_elm = elemts fst_lvl_node = TreeNode(fst_lvl_node_elm) PD_DebugLog.info_print("First level child node text is :" + fst_lvl_node.get_node_title()) #platform_tree.travel_around_child_nodes() utils_misc.set_script_timeout(pd_client_browser, 0.2) pd_client_browser.implicitly_wait(6) elem = platform_tree.find_element_by_vmname(vm_name) if elem: elem_node = TreeNode(elem[0]) PD_DebugLog.info_print("Find the elem, the title is " + elem_node.get_node_title()) elem_node.click() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) utils_misc.restore_script_timeout(pd_client_browser) vm_summary_page = VM_Summary_UIMap(pd_client_browser) #task_startup_abouttime = time.time() # The testcase running machine time is not same as the AIX machine under test. vm_summary_page.execute_reboot_system() # Step 4: Check the vm current status, it would turn into "in shutdown progress" check_return = utils_misc.wait_for( vm_summary_page.is_vm_starting, 10, 0.2, 0.1, "Check if vm goes into shutdown status") self.assert_( check_return, "After execution of boot up action, vm must go into 'in starting'") if check_return: # find the task item to get the item information: starttime, name and description # Then to watch when it disappears # The end, check it in the history of task to get the final status, success or fail. # If it failed, get the failure description. # Step 5: to check task status and wait the task finishes # if popup_task is not open, click the button again task_type = u'重启虚拟机' utils_misc.wait_for( self.shutdown_task_appears, 10, 0, 0.1, "Shutdown vm task should appear in current tasks list") taskstarttime = self.get_task_starttime(task_type, vm_name, host_name) utils_misc.wait_for( self.shutdown_task_disappears, 10, 0, 0.1, "Shutdown vm task should finish and go into the history tasks list" ) status, fail_desc = self.get_task_status_from_history_task( task_type, vm_name, host_name, taskstarttime) if status == Messages.FAIL_STATUS_STR: self.fail("The task failed: " + fail_desc) else: PD_DebugLog.debug_print("The task finished successfully.") time.sleep(TestSpeedControl.TEST_STEP_INTERVAL)
def test_ping_vm_normally(self): u'''Ping指定的已经存在虚拟机''' # # The id starts from 1. vm_id = 4 vm_name = "AutoTest_VM%02d" % vm_id vm_name = "PD3_Cluster_VM123" host_name = "localhost" vm_name = "JAVA_VM62" ''' Find the virtual machine first, Then, decide if it is running. If yes, shutdown the virtual machine. The third is to delete it. And at the same to watch history or task bar to detect if the deletion is running or finished. ''' # Step 1: Login and pass in with username, password, server and port pd_client_browser = self.pd_login() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) self.pd_client_browser = pd_client_browser # Step 2: Make sure the host resource tab is selected PD_DebugLog.stepinfo("click and select the host resource tab") pd_browser_main_map = Main_Browser_UIMap(pd_client_browser) self.pd_browser_main_map = pd_browser_main_map platform_resource_tab = pd_browser_main_map.get_platform_resource_tab() platform_resource_tab.click() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) # Step 3: Got the directory tree frame and check all the levels # travel around the leaves elements sub_tree = pd_browser_main_map.get_platform_sub_menu_tree() if type(sub_tree) is list: sub_menu_tree_elem = sub_tree[0] else: sub_menu_tree_elem = sub_tree platform_tree = Submenu_Tree(sub_menu_tree_elem) PD_DebugLog.debug_print("The tree id is: " + platform_tree.get_submenu_tree_id()) tree_node = TreeNode(sub_menu_tree_elem) elemts = tree_node.get_all_child_nodes() if type(elemts) is list: fst_lvl_node_elm = elemts[0] else: fst_lvl_node_elm = elemts fst_lvl_node = TreeNode(fst_lvl_node_elm) PD_DebugLog.info_print("First level child node text is :" + fst_lvl_node.get_node_title()) #platform_tree.travel_around_child_nodes() utils_misc.set_script_timeout(pd_client_browser, 0.2) pd_client_browser.implicitly_wait(6) elem = platform_tree.find_element_by_vmname(vm_name) if elem: elem_node = TreeNode(elem[0]) PD_DebugLog.info_print("Find the elem, the title is " + elem_node.get_node_title()) elem_node.click() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) utils_misc.restore_script_timeout(pd_client_browser) vm_summary_page = VM_Summary_UIMap(pd_client_browser) # in the vm summary page, locate the ip address label # And get the ip address value. target_vm_ipaddr = vm_summary_page.get_vm_ip() if not utils_misc.is_valid_ip(target_vm_ipaddr): self.fail("Get VM IP failed") # Step 4: Check the vm current status, it would turn into "in shutdown progress" ping_output = utils_misc.ping(target_vm_ipaddr) PD_DebugLog.debug_print("Print the ping output : " + ping_output) if utils_misc.get_loss_ratio(ping_output) > 0: self.fail("Ping failed" + ping_output) time.sleep(TestSpeedControl.TEST_STEP_INTERVAL)
from BootVM import BootVM from RebootVM import RebootVM from PingVM import PingVM from RegisterVMIP import RegisterVMIP RESULT_DIR = os.path.join(os.environ["AUTODIR"], "results") if __name__ == "__main__": # logging.basicConfig(format='[%(pathname)s: %(lineno)d: %(levelname)s:%(asctime)s]:%(message)s', # level=logging.DEBUG) logging.basicConfig(format="[%(levelname)s:%(asctime)s]:%(message)s", level=logging.DEBUG) auto_cur_dir = os.path.dirname(sys.argv[0]) PD_DebugLog.info_print("The current dir is: " + auto_cur_dir) os.environ["AUTODIR"] = os.path.abspath(os.path.join(auto_cur_dir, "..")) testsuite = unittest.TestSuite() # testsuite.addTest(ActivateProduction('test_activateproduct')) # testsuite.addTest(ActivateProduction('test_activateproduct_with_wronglicfile')) # testsuite.addTest(ActivateProduction('test_activateproduct_with_correctlicfile')) # testsuite.addTest(RegisterPlatform('test_Register_Platform')) # testsuite.addTest(RegisterPlatform('test_Register_Platform_Check')) # UploadISO 上传镜像 # testsuite.addTest(UploadISO('test_upload_iso')) # RegisterISO 注册镜像 # testsuite.addTest(RegisterIMG('test_register_image'))
def test_register_vm_ip_normally(self): u'''为指定的已经存在虚拟机登记IP地址''' # # The id starts from 1. vm_id = 4 vm_name = "AutoTest_VM%02d" % vm_id vm_name = "PD3_Cluster_VM123" host_name = "localhost" vm_name = "JAVA_VM62" # Step 1: Login and pass in with username, password, server and port pd_client_browser = self.pd_login() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) self.pd_client_browser = pd_client_browser # Step 2: Make sure the host resource tab is selected PD_DebugLog.stepinfo("click and select the host resource tab") pd_browser_main_map = Main_Browser_UIMap(pd_client_browser) self.pd_browser_main_map = pd_browser_main_map platform_resource_tab = pd_browser_main_map.get_platform_resource_tab() platform_resource_tab.click() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) # Step 3: Got the directory tree frame and check all the levels # travel around the leaves elements sub_tree = pd_browser_main_map.get_platform_sub_menu_tree() if type(sub_tree) is list: sub_menu_tree_elem = sub_tree[0] else: sub_menu_tree_elem = sub_tree platform_tree = Submenu_Tree(sub_menu_tree_elem) PD_DebugLog.debug_print("The tree id is: " + platform_tree.get_submenu_tree_id()) tree_node = TreeNode(sub_menu_tree_elem) elemts = tree_node.get_all_child_nodes() if type(elemts) is list: fst_lvl_node_elm = elemts[0] else: fst_lvl_node_elm = elemts fst_lvl_node = TreeNode(fst_lvl_node_elm) PD_DebugLog.info_print("First level child node text is :" + fst_lvl_node.get_node_title() ) #platform_tree.travel_around_child_nodes() utils_misc.set_script_timeout(pd_client_browser, 0.2) pd_client_browser.implicitly_wait(6) elem = platform_tree.find_element_by_vmname(vm_name) if elem: elem_node = TreeNode(elem[0]) PD_DebugLog.info_print("Find the elem, the title is " + elem_node.get_node_title()) elem_node.click() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) utils_misc.restore_script_timeout(pd_client_browser) vm_summary_page = self.vm_summary_page = VM_Summary_UIMap(pd_client_browser) # Step 4: expand the more actions bar vm_summary_page.expand_more_actions_bar() # Step 5: click Register IP button link vm_summary_page.click_register_IP_link() # Step 6: input the ip... value in the register ip form register_vm_ip_form = Register_VM_IP_Frame_UIMap(self.driver) register_vm_ip_form.get_ip_addr_input().send_keys("172.30.126.62") register_vm_ip_form.get_netmask_input().send_keys("255.255.255.0") register_vm_ip_form.get_gateway_input().send_keys("172.30.126.254") register_vm_ip_form.get_dns_input().send_keys("202.106.0.20") register_vm_ip_form.get_seconddns_input().send_keys("202.106.196.115") register_vm_ip_form.get_submit_btn().click() register_vm_ip_form.return_main_page() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) result = utils_misc.wait_for(self.determine_ip_is_set, 20, 1, 1, "The ip is not set successfully.") if not result: self.fail("The ip is not set successfully.") else: PD_DebugLog.info_print("The ip is set done.") # if not utils_misc.is_valid_ip(target_vm_ipaddr): # self.fail("Get VM IP failed") # # # Step 6: Check the vm current status, it would turn into "in shutdown progress" # ping_output = utils_misc.ping(target_vm_ipaddr) # PD_DebugLog.debug_print("Print the ping output : " + ping_output) # # if utils_misc.get_loss_ratio(ping_output) > 0: # self.fail("Ping failed" + ping_output) time.sleep(TestSpeedControl.TEST_STEP_INTERVAL)
def test_register_image(self): u''' 在PDHelper中配置了‘镜像库’地址和共享目录 注册平台 后,注册模板镜像用于安装虚拟机 ''' register_image_config = utils_misc.readconfig(self.__class__.__name__) u'''???平台注册后,有什么标志可以用来检测判断已经成功注册''' # Step 1: 登陆PD Web界面(用户名密码在配置文件tests-shared.cfg) PD_DebugLog.stepinfo(Messages.LOGIN_POWERDIRECTOR) #"Login PowerDirector" pd_client_browser = self.driver pd_client_browser.implicitly_wait(30) pd_client_browser.maximize_window() # :输入用户名,密码 Login and pass in with username, password, server and port self.pd_login() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) # Step 2: 选择镜像库标签 PD_DebugLog.stepinfo(Messages.IMAGE_LIB) PD_DebugLog.stepinfo(Messages.SELECT_CLICK_IMAGELIB_TAB) pd_browser_main_map = Main_Browser_UIMap(pd_client_browser) imagelib_tab = pd_browser_main_map.get_image_library_tab() imagelib_tab.click() # 确认当前页面已经切换到镜像库页面 # 通过检查左侧树形标题/html/body/div[2]/div/div[2]/div[3]/ul/li/span expect_title = u"镜像" PD_DebugLog.info_print(u"期望在左侧树形面板标题获得“镜像”文本") got_title = pd_browser_main_map.get_sub_menu_tree_title( Main_Browser_UIMap.IMAGE) PD_DebugLog.debug_print("expect_title: " + expect_title) PD_DebugLog.debug_print("got_title: " + got_title) assert expect_title == got_title time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) # Step 3: 选择镜像库标签->"注册镜像"链接 pd_imagelib_summary_map = ImageLib_Summary_UIMap(pd_client_browser) pd_imagelib_summary_map.click_register_image_link() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) # Step 4: 在注册镜像对话框中输入镜像对应的目录名 # Step 4: input the image or iso file name under the nfs template # directory. iso_image_file_name = register_image_config.get("images", "rh64_template_img") if not iso_image_file_name: iso_image_file_name = "RedHat_6.4_image" pd_image_register_uimap = Register_Image_Frame_UIMap(pd_client_browser) image_alias_input_elem = pd_image_register_uimap.get_image_alias_input() image_alias_input_elem.send_keys(iso_image_file_name) time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) image_location_input_elem = pd_image_register_uimap.get_image_file_location_input() image_location_input_elem.send_keys(iso_image_file_name) time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) # Step 5: select file type as ISO or IMG # Step 5: 选择文件类型为ISO或IMG file_type_img_radiobtn = pd_image_register_uimap.get_file_type_img_radiobtn() if not file_type_img_radiobtn: raise ElemNotExisted file_type_img_radiobtn.click() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) # Step 6: select the proper OS type # Step 6: 选择合适的操作系统类型 os_type = register_image_config.get("images", "os_type") pd_image_register_uimap.select_ostype_by_value(os_type) time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) os_name = register_image_config.get("images", "os_name") try: pd_image_register_uimap.select_osname_by_value(os_name) except: register_isoimage_fail_file = "register_isoimage_fail_file.png" utils_misc.save_screenshot(self.driver, self.testcasedir, register_isoimage_fail_file) time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) # Step 7: click submit # Step 7: 点击提交按钮 submit_btn = pd_image_register_uimap.get_submit_btn() submit_btn.click() #time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) # Step 8: verify alert is present # Step 8: 确认成功对话框弹出 #time.sleep(3) # 等待时间不能太短 # wait to alert dialog pops up orig_window_handles = self.driver.window_handles time_out = 100 curtime = 0 # True: return alert dialog # False: error message is returned alert_reponse_returned = False error_message_present = False while curtime < time_out: # to wait the response # determine if it gets the success response: alert dialog # or gets the error message. PD_DebugLog.debug_print("In the while loop: %d" % curtime) try: cur_window_handles = self.driver.window_handles PD_DebugLog.debug_print("The original windows number is: %d" % len(orig_window_handles)) PD_DebugLog.debug_print("The current windows number is: %d" % len(cur_window_handles)) if pd_image_register_uimap.is_notify_msg_present(): PD_DebugLog.debug_print("In is_notify_msg_present branch") error_message_present = True PD_DebugLog.debug_print("Found the error message") break if pd_image_register_uimap.is_alert_present(): #if len(orig_window_handles) != len(cur_window_handles): PD_DebugLog.debug_print("In is_alert_present branch") alert_reponse_returned = not alert_reponse_returned PD_DebugLog.debug_print("Found the alert dialog") break if pd_image_register_uimap.is_loading_getvminfo(): PD_DebugLog.debug_print("In is_loading_getvminfo branch") continue finally: time.sleep(0.2) curtime = curtime + 1 self.assertTrue(alert_reponse_returned or error_message_present, "Register ISO could not get the reponse in time.") if alert_reponse_returned or error_message_present: if alert_reponse_returned: expectmsg = register_image_config.get("images", "response_register_img") PD_DebugLog.debug_print(expectmsg) expectmsg = u'注册成功' respmsg = pd_image_register_uimap.close_alert_and_get_its_text() respmsg = unicode(respmsg.strip()) PD_DebugLog.info_print("Step info: " + "Got the response message, " + respmsg ) self.assertEqual(expectmsg, respmsg) else: respmsg = pd_image_register_uimap.get_notify_msg() respmsg = unicode(respmsg.strip()) PD_DebugLog.debug_print("Step info: " + "Got the response message, " + respmsg ) self.assertFalse(error_message_present, respmsg) time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) time.sleep(TestSpeedControl.TEST_STEP_INTERVAL)
def test_register_vm_ip_normally(self): u'''为指定的已经存在虚拟机登记IP地址''' # # The id starts from 1. vm_id = 4 vm_name = "AutoTest_VM%02d" % vm_id vm_name = "PD3_Cluster_VM123" host_name = "localhost" vm_name = "JAVA_VM62" # Step 1: Login and pass in with username, password, server and port pd_client_browser = self.pd_login() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) self.pd_client_browser = pd_client_browser # Step 2: Make sure the host resource tab is selected PD_DebugLog.stepinfo("click and select the host resource tab") pd_browser_main_map = Main_Browser_UIMap(pd_client_browser) self.pd_browser_main_map = pd_browser_main_map platform_resource_tab = pd_browser_main_map.get_platform_resource_tab() platform_resource_tab.click() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) # Step 3: Got the directory tree frame and check all the levels # travel around the leaves elements sub_tree = pd_browser_main_map.get_platform_sub_menu_tree() if type(sub_tree) is list: sub_menu_tree_elem = sub_tree[0] else: sub_menu_tree_elem = sub_tree platform_tree = Submenu_Tree(sub_menu_tree_elem) PD_DebugLog.debug_print("The tree id is: " + platform_tree.get_submenu_tree_id()) tree_node = TreeNode(sub_menu_tree_elem) elemts = tree_node.get_all_child_nodes() if type(elemts) is list: fst_lvl_node_elm = elemts[0] else: fst_lvl_node_elm = elemts fst_lvl_node = TreeNode(fst_lvl_node_elm) PD_DebugLog.info_print("First level child node text is :" + fst_lvl_node.get_node_title()) #platform_tree.travel_around_child_nodes() utils_misc.set_script_timeout(pd_client_browser, 0.2) pd_client_browser.implicitly_wait(6) elem = platform_tree.find_element_by_vmname(vm_name) if elem: elem_node = TreeNode(elem[0]) PD_DebugLog.info_print("Find the elem, the title is " + elem_node.get_node_title()) elem_node.click() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) utils_misc.restore_script_timeout(pd_client_browser) vm_summary_page = self.vm_summary_page = VM_Summary_UIMap( pd_client_browser) # Step 4: expand the more actions bar vm_summary_page.expand_more_actions_bar() # Step 5: click Register IP button link vm_summary_page.click_register_IP_link() # Step 6: input the ip... value in the register ip form register_vm_ip_form = Register_VM_IP_Frame_UIMap(self.driver) register_vm_ip_form.get_ip_addr_input().send_keys("172.30.126.62") register_vm_ip_form.get_netmask_input().send_keys("255.255.255.0") register_vm_ip_form.get_gateway_input().send_keys("172.30.126.254") register_vm_ip_form.get_dns_input().send_keys("202.106.0.20") register_vm_ip_form.get_seconddns_input().send_keys("202.106.196.115") register_vm_ip_form.get_submit_btn().click() register_vm_ip_form.return_main_page() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) result = utils_misc.wait_for(self.determine_ip_is_set, 20, 1, 1, "The ip is not set successfully.") if not result: self.fail("The ip is not set successfully.") else: PD_DebugLog.info_print("The ip is set done.") # if not utils_misc.is_valid_ip(target_vm_ipaddr): # self.fail("Get VM IP failed") # # # Step 6: Check the vm current status, it would turn into "in shutdown progress" # ping_output = utils_misc.ping(target_vm_ipaddr) # PD_DebugLog.debug_print("Print the ping output : " + ping_output) # # if utils_misc.get_loss_ratio(ping_output) > 0: # self.fail("Ping failed" + ping_output) time.sleep(TestSpeedControl.TEST_STEP_INTERVAL)
def test_ping_vm_normally(self): u'''Ping指定的已经存在虚拟机''' # # The id starts from 1. vm_id = 4 vm_name = "AutoTest_VM%02d" % vm_id vm_name = "PD3_Cluster_VM123" host_name = "localhost" vm_name = "JAVA_VM62" ''' Find the virtual machine first, Then, decide if it is running. If yes, shutdown the virtual machine. The third is to delete it. And at the same to watch history or task bar to detect if the deletion is running or finished. ''' # Step 1: Login and pass in with username, password, server and port pd_client_browser = self.pd_login() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) self.pd_client_browser = pd_client_browser # Step 2: Make sure the host resource tab is selected PD_DebugLog.stepinfo("click and select the host resource tab") pd_browser_main_map = Main_Browser_UIMap(pd_client_browser) self.pd_browser_main_map = pd_browser_main_map platform_resource_tab = pd_browser_main_map.get_platform_resource_tab() platform_resource_tab.click() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) # Step 3: Got the directory tree frame and check all the levels # travel around the leaves elements sub_tree = pd_browser_main_map.get_platform_sub_menu_tree() if type(sub_tree) is list: sub_menu_tree_elem = sub_tree[0] else: sub_menu_tree_elem = sub_tree platform_tree = Submenu_Tree(sub_menu_tree_elem) PD_DebugLog.debug_print("The tree id is: " + platform_tree.get_submenu_tree_id()) tree_node = TreeNode(sub_menu_tree_elem) elemts = tree_node.get_all_child_nodes() if type(elemts) is list: fst_lvl_node_elm = elemts[0] else: fst_lvl_node_elm = elemts fst_lvl_node = TreeNode(fst_lvl_node_elm) PD_DebugLog.info_print("First level child node text is :" + fst_lvl_node.get_node_title() ) #platform_tree.travel_around_child_nodes() utils_misc.set_script_timeout(pd_client_browser, 0.2) pd_client_browser.implicitly_wait(6) elem = platform_tree.find_element_by_vmname(vm_name) if elem: elem_node = TreeNode(elem[0]) PD_DebugLog.info_print("Find the elem, the title is " + elem_node.get_node_title()) elem_node.click() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) utils_misc.restore_script_timeout(pd_client_browser) vm_summary_page = VM_Summary_UIMap(pd_client_browser) # in the vm summary page, locate the ip address label # And get the ip address value. target_vm_ipaddr = vm_summary_page.get_vm_ip() if not utils_misc.is_valid_ip(target_vm_ipaddr): self.fail("Get VM IP failed") # Step 4: Check the vm current status, it would turn into "in shutdown progress" ping_output = utils_misc.ping(target_vm_ipaddr) PD_DebugLog.debug_print("Print the ping output : " + ping_output) if utils_misc.get_loss_ratio(ping_output) > 0: self.fail("Ping failed" + ping_output) time.sleep(TestSpeedControl.TEST_STEP_INTERVAL)
from BootVM import BootVM from RebootVM import RebootVM from PingVM import PingVM from RegisterVMIP import RegisterVMIP RESULT_DIR = os.path.join(os.environ["AUTODIR"], 'results') if __name__ == "__main__": #logging.basicConfig(format='[%(pathname)s: %(lineno)d: %(levelname)s:%(asctime)s]:%(message)s', # level=logging.DEBUG) logging.basicConfig(format='[%(levelname)s:%(asctime)s]:%(message)s', level=logging.DEBUG) auto_cur_dir = os.path.dirname(sys.argv[0]) PD_DebugLog.info_print("The current dir is: " + auto_cur_dir) os.environ['AUTODIR'] = os.path.abspath(os.path.join(auto_cur_dir, "..")) testsuite = unittest.TestSuite() #testsuite.addTest(ActivateProduction('test_activateproduct')) #testsuite.addTest(ActivateProduction('test_activateproduct_with_wronglicfile')) #testsuite.addTest(ActivateProduction('test_activateproduct_with_correctlicfile')) #testsuite.addTest(RegisterPlatform('test_Register_Platform')) #testsuite.addTest(RegisterPlatform('test_Register_Platform_Check')) # UploadISO 上传镜像 #testsuite.addTest(UploadISO('test_upload_iso')) # RegisterISO 注册镜像 #testsuite.addTest(RegisterIMG('test_register_image'))
def test_register_image(self): u''' 在PDHelper中配置了‘镜像库’地址和共享目录 注册平台 后,注册模板镜像用于安装虚拟机 ''' register_image_config = utils_misc.readconfig(self.__class__.__name__) u'''???平台注册后,有什么标志可以用来检测判断已经成功注册''' # Step 1: 登陆PD Web界面(用户名密码在配置文件tests-shared.cfg) PD_DebugLog.stepinfo( Messages.LOGIN_POWERDIRECTOR) #"Login PowerDirector" pd_client_browser = self.driver pd_client_browser.implicitly_wait(30) pd_client_browser.maximize_window() # :输入用户名,密码 Login and pass in with username, password, server and port self.pd_login() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) # Step 2: 选择镜像库标签 PD_DebugLog.stepinfo(Messages.IMAGE_LIB) PD_DebugLog.stepinfo(Messages.SELECT_CLICK_IMAGELIB_TAB) pd_browser_main_map = Main_Browser_UIMap(pd_client_browser) imagelib_tab = pd_browser_main_map.get_image_library_tab() imagelib_tab.click() # 确认当前页面已经切换到镜像库页面 # 通过检查左侧树形标题/html/body/div[2]/div/div[2]/div[3]/ul/li/span expect_title = u"镜像" PD_DebugLog.info_print(u"期望在左侧树形面板标题获得“镜像”文本") got_title = pd_browser_main_map.get_sub_menu_tree_title( Main_Browser_UIMap.IMAGE) PD_DebugLog.debug_print("expect_title: " + expect_title) PD_DebugLog.debug_print("got_title: " + got_title) assert expect_title == got_title time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) # Step 3: 选择镜像库标签->"注册镜像"链接 pd_imagelib_summary_map = ImageLib_Summary_UIMap(pd_client_browser) pd_imagelib_summary_map.click_register_image_link() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) # Step 4: 在注册镜像对话框中输入镜像对应的目录名 # Step 4: input the image or iso file name under the nfs template # directory. iso_image_file_name = register_image_config.get( "images", "rh64_template_img") if not iso_image_file_name: iso_image_file_name = "RedHat_6.4_image" pd_image_register_uimap = Register_Image_Frame_UIMap(pd_client_browser) image_alias_input_elem = pd_image_register_uimap.get_image_alias_input( ) image_alias_input_elem.send_keys(iso_image_file_name) time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) image_location_input_elem = pd_image_register_uimap.get_image_file_location_input( ) image_location_input_elem.send_keys(iso_image_file_name) time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) # Step 5: select file type as ISO or IMG # Step 5: 选择文件类型为ISO或IMG file_type_img_radiobtn = pd_image_register_uimap.get_file_type_img_radiobtn( ) if not file_type_img_radiobtn: raise ElemNotExisted file_type_img_radiobtn.click() time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) # Step 6: select the proper OS type # Step 6: 选择合适的操作系统类型 os_type = register_image_config.get("images", "os_type") pd_image_register_uimap.select_ostype_by_value(os_type) time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) os_name = register_image_config.get("images", "os_name") try: pd_image_register_uimap.select_osname_by_value(os_name) except: register_isoimage_fail_file = "register_isoimage_fail_file.png" utils_misc.save_screenshot(self.driver, self.testcasedir, register_isoimage_fail_file) time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) # Step 7: click submit # Step 7: 点击提交按钮 submit_btn = pd_image_register_uimap.get_submit_btn() submit_btn.click() #time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) # Step 8: verify alert is present # Step 8: 确认成功对话框弹出 #time.sleep(3) # 等待时间不能太短 # wait to alert dialog pops up orig_window_handles = self.driver.window_handles time_out = 100 curtime = 0 # True: return alert dialog # False: error message is returned alert_reponse_returned = False error_message_present = False while curtime < time_out: # to wait the response # determine if it gets the success response: alert dialog # or gets the error message. PD_DebugLog.debug_print("In the while loop: %d" % curtime) try: cur_window_handles = self.driver.window_handles PD_DebugLog.debug_print("The original windows number is: %d" % len(orig_window_handles)) PD_DebugLog.debug_print("The current windows number is: %d" % len(cur_window_handles)) if pd_image_register_uimap.is_notify_msg_present(): PD_DebugLog.debug_print("In is_notify_msg_present branch") error_message_present = True PD_DebugLog.debug_print("Found the error message") break if pd_image_register_uimap.is_alert_present(): #if len(orig_window_handles) != len(cur_window_handles): PD_DebugLog.debug_print("In is_alert_present branch") alert_reponse_returned = not alert_reponse_returned PD_DebugLog.debug_print("Found the alert dialog") break if pd_image_register_uimap.is_loading_getvminfo(): PD_DebugLog.debug_print("In is_loading_getvminfo branch") continue finally: time.sleep(0.2) curtime = curtime + 1 self.assertTrue(alert_reponse_returned or error_message_present, "Register ISO could not get the reponse in time.") if alert_reponse_returned or error_message_present: if alert_reponse_returned: expectmsg = register_image_config.get("images", "response_register_img") PD_DebugLog.debug_print(expectmsg) expectmsg = u'注册成功' respmsg = pd_image_register_uimap.close_alert_and_get_its_text( ) respmsg = unicode(respmsg.strip()) PD_DebugLog.info_print("Step info: " + "Got the response message, " + respmsg) self.assertEqual(expectmsg, respmsg) else: respmsg = pd_image_register_uimap.get_notify_msg() respmsg = unicode(respmsg.strip()) PD_DebugLog.debug_print("Step info: " + "Got the response message, " + respmsg) self.assertFalse(error_message_present, respmsg) time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) time.sleep(TestSpeedControl.TEST_STEP_INTERVAL) time.sleep(TestSpeedControl.TEST_STEP_INTERVAL)