Ejemplo n.º 1
0
 def test_cube_stopvm():
     driver = self.driver
     vm_name = read_conf.vmname
     InstanceID = driver.find_element_by_link_text(vm_name).get_attribute(
         "instanceId")
     driver.find_element_by_css_selector(".vm-row[data-id='%s']" %
                                         InstanceID).click()
     time.sleep(3)
     status = driver.find_element_by_link_text(vm_name).get_attribute(
         "state")
     if status == "STOPPED":
         log.logger.info("VM %s status is %s" % (vm_name, status))
     else:
         #WebDriverWait(driver,180).until(expected_conditions.element_to_be_clickable((By.XPATH,u'//div[@class="function_vm_detail_list"]/a[@title="停止"]'))).click()
         WebDriverWait(driver, 180).until(
             expected_conditions.element_to_be_clickable(
                 (By.XPATH,
                  u'//a[@class="btn btn-function stop"]'))).click()
         time.sleep(5)
         WebDriverWait(driver, 180).until(
             expected_conditions.element_to_be_clickable((
                 By.XPATH,
                 u'//div[@class="ui-dialog-buttonset"]/button[contains(text(),"确定")]'
             ))).click()
         log.logger.info("VM %s is stoping" % vm_name)
         action = u"云主机%s停止" % vm_name
         driver_common.async_info_status(driver, 30, action)
Ejemplo n.º 2
0
def cube_create_snapshot(driver, diskname):
    log.logger.info("Begin case:disk %s create snapshot " % diskname)
    vm_status = driver.find_element_by_xpath(
        './/*[@id="indexTable"]/tbody/tr[@data-name="%s"]/td[6]' %
        diskname).text
    vmname = driver.find_element_by_xpath(
        './/*[@id="indexTable"]/tbody/tr[@data-name="%s"]/td[5]' %
        diskname).text
    if (vm_status != u"停止"):
        log.logger.warning(
            "VM status is %s,can not create snapshot,so stop vm first!" %
            vm_status)
        vm_operation.cube_vmmanage(driver)
        vm_operation.cube_stopvm(driver, vmname)
        cube_diskmanage(driver)

    disk_id = driver.find_element_by_css_selector(
        '#indexTable>tbody>tr[data-name="%s"]' %
        diskname).get_attribute("data-id")
    driver.find_element_by_css_selector('.kiz.c-197[volumeid="%s"]' %
                                        disk_id).click()
    #   driver.find_element_by_xpath("html/body/div[9]/div[3]/div/button[1]").click()
    WebDriverWait(driver, 180).until(
        EC.element_to_be_clickable((
            By.XPATH,
            u'//div[contains(@style,"display: block;")]//div[@class="ui-dialog-buttonset"]/button[contains(text(),"确")]'
        ))).click()
    driver_common.async_info_status(driver, 120, u"云磁盘%s创建快照" % diskname)
    log.logger.info("End case:disk %s create snapshot\n" % diskname)
Ejemplo n.º 3
0
    def test_cube_startvm():
        driver = self.driver
        vm_name = read_conf.vmname
        InstanceID = driver.find_element_by_link_text(vm_name).get_attribute(
            "instanceId")
        driver.find_element_by_css_selector(".vm-row[data-id='%s']" %
                                            InstanceID).click()
        #	WebDriverWait(driver,180).until(expected_conditions.element_to_be_clickable((By.XPATH,u'//table[@id="stretch-table"]/tbody/tr[2]/td'))).click()
        time.sleep(3)

        status = driver.find_element_by_link_text(vm_name).get_attribute(
            "state")

        if status == "RUNNING":
            log.logger.info("VM %s status is %s" % (vm_name, status))
        else:
            WebDriverWait(driver, 180).until(
                expected_conditions.element_to_be_clickable(
                    (By.XPATH,
                     u'//a[@class="btn btn-function start"]'))).click()
            time.sleep(5)
            WebDriverWait(driver, 180).until(
                expected_conditions.element_to_be_clickable((
                    By.XPATH,
                    u'//div[@class="ui-dialog-buttonset"]/button[contains(text(),"确定")]'
                ))).click()
            log.logger.info("VM %s is starting!" % vm_name)
            action = u"云主机%s启动" % vm_name
            driver_common.async_info_status(driver, 30, action)
Ejemplo n.º 4
0
def cube_delete_disk(driver, diskname):
    log.logger.info("Begin case:delete disk %s " % diskname)
    WebDriverWait(driver, 60).until(
        EC.element_to_be_clickable((By.CSS_SELECTOR, '.ycpglHT'))).click()
    time.sleep(3)
    vmname = WebDriverWait(driver, 90).until(
        EC.visibility_of_element_located(
            (By.XPATH,
             u'.//*[@id="indexTable"]/tbody/tr[@data-name="%s"]/td[5]' %
             diskname))).text
    if (vmname is not None and vmname != ""):
        log.logger.warn(
            "disk is mount on %s ,can not delete, so unmount the disk first" %
            vmname)
        cube_unmount_vm(driver, diskname)
    WebDriverWait(driver, 60).until(
        EC.element_to_be_clickable(
            (By.XPATH,
             u'//tr[@data-name="%s"]//a[text()="删除"]' % diskname))).click()
    WebDriverWait(driver, 180).until(
        EC.element_to_be_clickable((
            By.XPATH,
            u'//div[contains(@style,"display: block;")]//div[@class="ui-dialog-buttonset"]/button[contains(text(),"确定")]'
        ))).click()
    WebDriverWait(driver, 180).until(
        EC.element_to_be_clickable((
            By.XPATH,
            u'//div[contains(@style,"display: block;")]//div[@class="ui-dialog-buttonset"]/button[contains(text(),"确定")]'
        ))).click()
    driver_common.async_info_status(driver, 120, u"云磁盘%s删除" % diskname)
    log.logger.info("End case: delete disk %s\n" % diskname)
Ejemplo n.º 5
0
def cube_startvm(driver, vm_name):
    log.logger.info("Begin case: start vm %s" % vm_name)
    InstanceID = WebDriverWait(driver, 120).until(
        expected_conditions.visibility_of_element_located(
            (By.LINK_TEXT, vm_name))).get_attribute("instanceId")
    #InstanceID=driver.find_element_by_link_text(vm_name).get_attribute("instanceId")
    WebDriverWait(driver, 120).until(
        expected_conditions.element_to_be_clickable(
            (By.CSS_SELECTOR, ".vm-row[data-id='%s']" % InstanceID))).click()
    #driver.find_element_by_css_selector(".vm-row[data-id='%s']" % InstanceID).click()
    status = WebDriverWait(driver, 120).until(
        expected_conditions.visibility_of_element_located(
            (By.LINK_TEXT, vm_name))).get_attribute("state")
    #status=driver.find_element_by_link_text(vm_name).get_attribute("state")

    if status == "RUNNING":
        log.logger.info("VM %s status is %s" % (vm_name, status))
    else:
        WebDriverWait(driver, 180).until(
            expected_conditions.element_to_be_clickable(
                (By.XPATH, u'//a[@class="btn btn-function start"]'))).click()
        time.sleep(2)
        WebDriverWait(driver, 180).until(
            expected_conditions.element_to_be_clickable((
                By.XPATH,
                u'//div[contains(@style,"display: block;")]//div[@class="ui-dialog-buttonset"]/button[contains(text(),"确定")]'
            ))).click()
        log.logger.info("VM %s is starting!" % vm_name)
        action = u"云主机%s启动" % vm_name
        driver_common.async_info_status(driver, 30, action)
    log.logger.info("End case: start vm %s\n" % vm_name)
Ejemplo n.º 6
0
def cube_create_disk(driver):
    t = time.strftime("%m%d%H%M%S", time.localtime())
    diskname = "data" + t
    log.logger.info("Begin case: create disk %s" % diskname)
    time.sleep(1)
    WebDriverWait(driver,
                  60).until(EC.element_to_be_clickable(
                      (By.ID, "createVolume"))).click()
    time.sleep(3)
    WebDriverWait(driver,
                  180).until(EC.element_to_be_clickable(
                      (By.ID, "displayName"))).clear()
    WebDriverWait(driver,
                  180).until(EC.element_to_be_clickable(
                      (By.ID, "displayName"))).send_keys(diskname)
    WebDriverWait(driver,
                  180).until(EC.element_to_be_clickable(
                      (By.ID, "submit_but"))).click()
    WebDriverWait(driver, 180).until(
        EC.element_to_be_clickable((
            By.XPATH,
            u'//div[contains(@style,"display: block;")]//div[@class="ui-dialog-buttonset"]/button[contains(text(),"确定")]'
        ))).click()
    rs = driver_common.async_info_status(driver, 120, u"云磁盘%s创建" % diskname)
    log.logger.info("End case: create disk %s\n" % diskname)
    if (u"成功" in rs):
        return diskname
Ejemplo n.º 7
0
def cube_create_snapshot(driver, diskname):
    log.logger.info("Begin case:disk %s create snapshot " % diskname)
    vm_status = WebDriverWait(driver, 90).until(
        EC.visibility_of_element_located(
            (By.XPATH,
             u'.//*[@id="indexTable"]/tbody/tr[@data-name="%s"]/td[6]' %
             diskname))).text
    vmname = WebDriverWait(driver, 90).until(
        EC.visibility_of_element_located(
            (By.XPATH,
             u'.//*[@id="indexTable"]/tbody/tr[@data-name="%s"]/td[5]' %
             diskname))).text
    storage = WebDriverWait(driver, 90).until(
        EC.visibility_of_element_located(
            (By.XPATH,
             u'.//*[@id="indexTable"]/tbody/tr[@data-name="%s"]/td[3]' %
             diskname))).text
    if (storage is None or storage == ""):
        log.logger.warn("云磁盘未挂载过,不能创建快照!")
        return
    if (vm_status == u"运行"):
        log.logger.warning(
            "VM status is %s,can not create snapshot,so stop vm first!" %
            vm_status)
        vm_operation.cube_vmmanage(driver)
        vm_operation.cube_stopvm(driver, vmname)
        cube_diskmanage(driver)
    vm_status = WebDriverWait(driver, 60).until(
        EC.visibility_of_element_located(
            (By.XPATH,
             u'.//*[@id="indexTable"]/tbody/tr[@data-name="%s"]/td[6]' %
             diskname))).text
    if (vm_status == u"停止" or (vmname is None or vmname == "")):
        disk_id = WebDriverWait(driver, 90).until(
            EC.visibility_of_element_located(
                (By.CSS_SELECTOR, u'#indexTable>tbody>tr[data-name="%s"]' %
                 diskname))).get_attribute("data-id")
        time.sleep(2)
        WebDriverWait(driver, 180).until(
            EC.element_to_be_clickable(
                (By.CSS_SELECTOR,
                 '.kiz.c-197[volumeid="%s"]' % disk_id))).click()
        WebDriverWait(driver, 180).until(
            EC.element_to_be_clickable((
                By.XPATH,
                u'//div[contains(@style,"display: block;")]//div[@class="ui-dialog-buttonset"]/button[contains(text(),"确")]'
            ))).click()
        rs = driver_common.async_info_status(driver, 120,
                                             u"云磁盘%s创建快照" % diskname)
        if (u"成功" in rs):
            WebDriverWait(driver, 90).until(
                EC.element_to_be_clickable((By.LINK_TEXT, u"快照管理"))).click()
            snapshotname = WebDriverWait(driver, 10).until(
                EC.element_to_be_clickable(
                    (By.XPATH, u'//tr[contains(@data-name, "%s")]' %
                     diskname))).get_attribute("data-name")
            log.logger.info("snapshot name : %s" % snapshotname)
            log.logger.info("End case:disk %s create snapshot \n" % diskname)
            return snapshotname
    log.logger.info("End case:disk %s create snapshot \n" % diskname)
Ejemplo n.º 8
0
def cube_deletevm(driver, vm_name):
    log.logger.info("Begin case: delete vm %s" % vm_name)
    InstanceID = WebDriverWait(driver, 120).until(
        expected_conditions.visibility_of_element_located(
            (By.LINK_TEXT, vm_name))).get_attribute("instanceId")
    WebDriverWait(driver, 120).until(
        expected_conditions.element_to_be_clickable(
            (By.CSS_SELECTOR, ".vm-row[data-id='%s']" % InstanceID))).click()
    WebDriverWait(driver, 180).until(
        expected_conditions.element_to_be_clickable(
            (By.XPATH, u'//a[@class="btn btn-function delete"]'))).click()
    time.sleep(2)
    WebDriverWait(driver, 180).until(
        expected_conditions.element_to_be_clickable((
            By.XPATH,
            u'//div[contains(@style,"display: block;")]//div[@class="ui-dialog-buttonset"]/button[contains(text(),"确定")]'
        ))).click()
    action = u"云主机%s删除" % vm_name
    driver_common.async_info_status(driver, 180, action)
    log.logger.info("End case: delete vm %s\n" % vm_name)
Ejemplo n.º 9
0
    def test_login(self):
        driver = self.driver
        driver.get(self.base_url + "/")
        driver.find_element_by_id("userName").clear()
        driver.find_element_by_id("userName").send_keys(
            read_conf.login_username)
        driver.find_element_by_id("password").clear()
        driver.find_element_by_id("password").send_keys(
            read_conf.login_password)
        driver.find_element_by_id("msg1").click()

        WebDriverWait(driver, 180).until(
            expected_conditions.element_to_be_clickable(
                (By.XPATH,
                 u'//div[@class="desk"]//span[contains(text(),"PowerCube")]'
                 ))).click()
        time.sleep(2)

        WebDriverWait(driver, 180).until(
            expected_conditions.element_to_be_clickable(
                (By.CSS_SELECTOR, '.ha-max'))).click()
        time.sleep(2)

        driver.switch_to_frame("ifr_appId_1")
        WebDriverWait(driver, 180).until(
            expected_conditions.element_to_be_clickable((
                By.XPATH,
                u'//div[@id="mCSB_1_container"]/li/span[contains(text(),"资源管理")]'
            ))).click()
        time.sleep(2)

        WebDriverWait(driver, 180).until(
            expected_conditions.element_to_be_clickable(
                (By.XPATH,
                 u'//div[@id="mCSB_1_container"]/ul/li/a[@class="yzjglHT"]'
                 ))).click()
        time.sleep(2)

        vm_name = "testtest"
        InstanceID = driver.find_element_by_link_text(vm_name).get_attribute(
            "instanceId")
        driver.find_element_by_css_selector(".vm-row[data-id='%s']" %
                                            InstanceID).click()
        #	WebDriverWait(driver,180).until(expected_conditions.element_to_be_clickable((By.XPATH,u'//table[@id="stretch-table"]/tbody/tr[2]/td'))).click()
        time.sleep(2)

        status = driver.find_element_by_link_text(vm_name).get_attribute(
            "state")
        print status
        if status == "RUNNING":
            #WebDriverWait(driver,180).until(expected_conditions.element_to_be_clickable((By.XPATH,u'//div[@class="function_vm_detail_list"]/a[@title="停止"]'))).click()
            WebDriverWait(driver, 180).until(
                expected_conditions.element_to_be_clickable(
                    (By.XPATH,
                     u'//a[@class="btn btn-function stop"]'))).click()
            WebDriverWait(driver, 180).until(
                expected_conditions.element_to_be_clickable((
                    By.XPATH,
                    u'//div[@class="ui-dialog-buttonset"]/button[contains(text(),"确定")]'
                ))).click()
            print "stoping"
            action = u"云主机%s停止" % vm_name
            driver_common.async_info_status(driver, 30, action)
        else:
            #		driver.find_element_by_css_selector(".vm-row[data-id='%s']" % InstanceID).click()
            #		driver.find_element_by_link_text("启动").click()
            #		WebDriverWait(driver,180).until(expected_conditions.element_to_be_clickable((By.XPATH,u'//div[@class=mCSB_container"]//div[@class="function_vm_detail_list"]/a[@title="启动"]'))).click()
            ##		WebDriverWait(driver,180).until(expected_conditions.element_to_be_clickable((By.CSS_SELECTOR,'.btn.btn-function.start'))).click()
            WebDriverWait(driver, 180).until(
                expected_conditions.element_to_be_clickable(
                    (By.XPATH,
                     u'//a[@class="btn btn-function start"]'))).click()
            time.sleep(3)
            WebDriverWait(driver, 180).until(
                expected_conditions.element_to_be_clickable((
                    By.XPATH,
                    u'//div[@class="ui-dialog-buttonset"]/button[contains(text(),"确定")]'
                ))).click()
            print "starting"
            action = u"云主机%s启动" % vm_name
            driver_common.async_info_status(driver, 30, action)

#restart
        status = driver.find_element_by_link_text(vm_name).get_attribute(
            "state")
        print status
        if status == "STOPPED":
            WebDriverWait(driver, 180).until(
                expected_conditions.element_to_be_clickable(
                    (By.XPATH,
                     u'//a[@class="btn btn-function start"]'))).click()
            time.sleep(3)
            WebDriverWait(driver, 180).until(
                expected_conditions.element_to_be_clickable((
                    By.XPATH,
                    u'//div[@class="ui-dialog-buttonset"]/button[contains(text(),"确定")]'
                ))).click()
            print "for restart,starting vm"
            action = u"云主机%s启动" % vm_name
            driver_common.async_info_status(driver, 30, action)

#get status again
        status = driver.find_element_by_link_text(vm_name).get_attribute(
            "state")
        print status
        if status == "RUNNING":
            WebDriverWait(driver, 180).until(
                expected_conditions.element_to_be_clickable(
                    (By.XPATH,
                     u'//a[@class="btn btn-function restart"]'))).click()
            time.sleep(3)
            WebDriverWait(driver, 180).until(
                expected_conditions.element_to_be_clickable((
                    By.XPATH,
                    u'//div[@class="ui-dialog-buttonset"]/button[contains(text(),"确定")]'
                ))).click()
            print "restarting"
            action = u"云主机%s重启" % vm_name
            driver_common.async_info_status(driver, 30, action)

#SecurityKey
        status = driver.find_element_by_link_text(vm_name).get_attribute(
            "state")
        print status
        if status == "RUNNING":
            WebDriverWait(driver, 180).until(
                expected_conditions.element_to_be_clickable(
                    (By.XPATH,
                     u'//a[@class="btn btn-function securityKey"]'))).click()
            time.sleep(3)
            WebDriverWait(driver, 180).until(
                expected_conditions.element_to_be_clickable((
                    By.XPATH,
                    u'//div[@class="ui-dialog-buttonset"]/button[contains(text(),"确定")]'
                ))).click()
            print "查看密钥"
            time.sleep(3)
        if status == "STOPPED":
            WebDriverWait(driver, 180).until(
                expected_conditions.element_to_be_clickable(
                    (By.XPATH,
                     u'//a[@class="btn btn-function securityKey"]'))).click()
            time.sleep(3)
            WebDriverWait(driver, 180).until(
                expected_conditions.element_to_be_clickable((
                    By.XPATH,
                    u'//div[@class="ui-dialog-buttonset"]/button[contains(text(),"重置")]'
                ))).click()
            print "重置密钥"
            time.sleep(5)
Ejemplo n.º 10
0
    time.sleep(3)
    #driver.find_element_by_css_selector("#buyVm_confirm").click()
    WebDriverWait(driver, 180).until(
        EC.element_to_be_clickable(
            (By.CSS_SELECTOR, "#buyVm_confirm"))).click()

    time.sleep(3)
    #driver.find_element_by_xpath("//*[text()='创建云主机任务启动成功!']/following-sibling::*//button").click()
    WebDriverWait(driver, 180).until(
        EC.element_to_be_clickable((
            By.XPATH,
            u'//div[contains(@style,"display: block;")]//div[@class="ui-dialog-buttonset"]/button[contains(text(),"确定")]'
        ))).click()

    action = u"云主机%s创建" % vm_name
    if u"成功" not in driver_common.async_info_status(driver, 480, action):
        log.logger.warn("End case: create vm name: %s Failed!\n" % vm_name)
        return False

    InstanceID = WebDriverWait(driver, 90).until(
        EC.visibility_of_element_located(
            (By.LINK_TEXT, vm_name))).get_attribute("instanceId")
    WebDriverWait(driver, 90).until(
        EC.element_to_be_clickable(
            (By.CSS_SELECTOR, ".vm-row[data-id='%s']" % InstanceID))).click()
    wait_time = 0
    while (wait_time) < 300:
        status = WebDriverWait(driver, 90).until(
            EC.visibility_of_element_located(
                (By.LINK_TEXT, vm_name))).get_attribute("state")
        if status == "RUNNING":