Beispiel #1
0
 def inspect_hosts(self):
     self.logger.info(u"%sInspect hosts for correctness%s\n" %
                      ('+' * 12, '+' * 12))
     endtime = time.time() + 180
     while time.time() < endtime:
         ele_list = find_elements(self.driver, By.CSS_SELECTOR,
                                  ".tiny.glyphicon.success.ok_2")
         if len(ele_list) == 19:
             break
         elif len(ele_list) == 18 and verify_element(
                 self.driver, By.PARTIAL_LINK_TEXT,
                 "echo never > /sys/kernel/mm/transparent_hugepage/defrag"):
             break
     ele_list = find_elements(self.driver, By.CSS_SELECTOR,
                              ".tiny.glyphicon.success.ok_2")
     if len(ele_list) < 19:
         return FuncResult(False, u"Inspect hosts for correctness",
                           caputre(self.driver))
     click_element(self.driver, By.CSS_SELECTOR,
                   ".btn.btn-large.btn-primary")
     time.sleep(1)
     #        ele_text=get_element_text(self.driver,By.CSS_SELECTOR,".Wizard.container>h1")
     ret = u"express-add-services" in self.driver.current_url
     return FuncResult(ret, u"Inspect hosts for correctness",
                       caputre(self.driver))
 def Assign_role(self):
     self.logger.info(u"%sAssign role%s\n" % ('+' * 12, '+' * 12))
     role_name_list = map(
         lambda x: x.text,
         find_elements(self.driver, By.CSS_SELECTOR,
                       ".label-service-kafka+.name"))
     for rolename in self.data.keys():
         if self.data[rolename]:
             rolename_index = get_ele_index(role_name_list, rolename)
             if rolename_index != None:
                 self.logger.info(
                     "%s : $('div:nth-child(%s)>div>.role-type-btn').click()"
                     % (
                         rolename,
                         rolename_index + 1,
                     ))
                 self.driver.execute_script(
                     "$('div:nth-child(%s)>div>.role-type-btn').click()" %
                     (rolename_index + 1, ))
                 role_checkbox_list = find_elements(self.driver,
                                                    By.CSS_SELECTOR,
                                                    "tbody i")
                 role_hostname = map(
                     lambda x: x.text,
                     find_elements(self.driver, By.CSS_SELECTOR,
                                   "tbody>tr>td[data-bind$=\"hostName\"]"))
                 for checkbox in role_checkbox_list:
                     if u" check" in get_element_attribute(
                             checkbox, "class"):
                         checkbox.click()
                         time.sleep(0.5)
                 for hostname in self.data[rolename]:
                     hostname_index = get_ele_index(role_hostname, hostname)
                     if hostname_index != None:
                         role_checkbox_list[hostname_index].click()
                     else:
                         self.logger.error(u"host name is invalid")
                 if not click_element(
                         self.driver, By.CSS_SELECTOR,
                         "form #modalDialog .modal-footer>.btn+.btn"):
                     return FuncResult(
                         False, "kafka install select host:%s" % rolename)
             else:
                 self.logger.error(u"Kafka rolename:%s is invalid")
     click_element(self.driver, By.CSS_SELECTOR,
                   "button[data-bind*=\"onClickContinue\"]")
     time.sleep(3)
     ele_text = get_element_text(self.driver, By.CSS_SELECTOR,
                                 "#reviewStep h2")
     ret = u"Review Changes" in ele_text
     return FuncResult(ret, "kafka assign role")
 def start_service(self):
     self.logger.info(u"%sstart service%s\n" % ('+' * 12, '+' * 12))
     endtime = time.time() + 1200
     fail = 1
     while time.time() < endtime:
         result = get_element_attribute(
             find_elements(
                 self.driver, By.CSS_SELECTOR,
                 "#commandDetailsStep>div>div:first-child>h2:first-child>i:first-child"
             )[0], "class")
         if u"error" in result and fail == 1:
             fail = fail + 1
             click_element(self.driver, By.LINK_TEXT, "Retry")
         elif u"error" in result and fail == 2:
             return FuncResult(False, u"start service",
                               caputre(self.driver))
         elif u"success" in result:
             break
         else:
             time.sleep(5)
     time.sleep(2)
     click_element(self.driver, By.CSS_SELECTOR,
                   "#bottomButtons button[data-bind*=\"onClickContinue\"]")
     time.sleep(1)
     ele_text = get_element_text(self.driver, By.CSS_SELECTOR,
                                 "#finishStep h2")
     ret = u"Congratulations!" in ele_text
     return FuncResult(ret, u"start service", caputre(self.driver))
    def config_service(self):
        self.logger.info(u"%sconfig service%s\n" % ('+' * 12, '+' * 12))
        endTime = time.time() + 60
        while time.time() < endTime:
            if find_elements(self.driver, By.CSS_SELECTOR,
                             "#reviewStep .param-spec-property"):
                break
#        time.sleep(1)
#         shell_command("mysql -uadmin -paaaaaa --execute 'use cm;update CONFIGS set VALUE=1024 where ATTR=\"broker_max_heap_size\";update CONFIGS_AUD set VALUE=1024 where ATTR=\"broker_max_heap_size\";'")
#        shell_command("sshpass -p aaaaaa ssh [email protected] -o StrictHostKeyChecking=no sh /home/mysql_kafka_config.sh")
        time.sleep(3)
        click_element(self.driver, By.CSS_SELECTOR,
                      "#bottomButtons button[data-bind*=\"onClickContinue\"]")
        for _ in range(5):
            c_url = self.driver.current_url
            self.logger.info(c_url)
            if u"commandDetailsStep" in c_url:
                break
            else:
                time.sleep(2)
#         ele_text=get_element_text(self.driver,By.CSS_SELECTOR,"#commandDetailsStep>div>div:first-child>h2:first-child .muted")
        c_url = self.driver.current_url
        self.logger.info(c_url)
        ret = u"commandDetailsStep" in c_url
        return FuncResult(ret, u"config service", caputre(self.driver))
Beispiel #5
0
    def select_service(self):
        self.logger.info(u"%sselect service%s\n" % ('+' * 12, '+' * 12))
        click_element(self.driver, By.CSS_SELECTOR, "#package_CUSTOM")
        #        self.driver.execute_script("$(window).scrollTop(550,0)")
        #        service_input_ele_list=find_elements(self.driver,By.CSS_SELECTOR, "#serviceSelector tbody input")
        service_name_list = map(
            lambda x: x.text,
            find_elements(self.driver, By.CSS_SELECTOR,
                          "#serviceSelector tbody td:nth-child(2)>label"))
        install_service = self.data["install_service"]
        for service in install_service:
            service_index = get_ele_index(service_name_list, service)
            if service_index != None:
                #                 if u"YARN" in service or u"ZooKeeper" in service:
                #                    self.driver.execute_script("$(window).scrollTop(650,0)")
                self.logger.info(
                    "%s $('#serviceSelector tbody>tr:nth-child(%s) input').click()"
                    % (service, 1 + service_index))
                self.driver.execute_script(
                    "$('#serviceSelector tbody>tr:nth-child(%s) input').click()"
                    % (1 + service_index))
                #                service_input_ele_list[service_index].click()
                time.sleep(1)
            else:
                self.logger.error(u"service name [%s] is invalid" % service)
#        click_element(self.driver,By.CSS_SELECTOR,"input[name*=Navigator]")
        click_element(self.driver, By.CSS_SELECTOR,
                      ".btn.btn-large.btn-primary")
        ele_text = get_element_text(self.driver, By.CSS_SELECTOR,
                                    "#roleAssignmentsStep>div>h2")
        ret = u'Customize Role Assignments' in ele_text
        return FuncResult(ret, u"select service", caputre(self.driver))
Beispiel #6
0
 def install_parcels(self):
     self.logger.info(u"%sInstalling Selected Parcels%s\n" %
                      ('+' * 12, '+' * 12))
     install_schedule_ele = find_elements(
         self.driver, By.CSS_SELECTOR,
         ".parcel-header>div[data-bind$=\"Activation\"]>div>div")
     unpack_schedule_ele = find_elements(
         self.driver, By.CSS_SELECTOR,
         "div[data-bind*=\"unpackedPercent\"]")[0]
     destribute_schedule_ele = find_elements(
         self.driver, By.CSS_SELECTOR,
         "div[data-bind*=\"distributionProgress\"]")[0]
     endtime = time.time() + 1200
     while time.time() < endtime:
         unpack_schedule = get_element_attribute(unpack_schedule_ele,
                                                 "style")
         destribute_schedule = get_element_attribute(
             destribute_schedule_ele, "style")
         self.logger.info(u"Distribute schedule:%s || unpack schedule:%s " %
                          (destribute_schedule, unpack_schedule))
         install_schedule_list = map(
             get_element_attribute, install_schedule_ele,
             ["style" for _ in install_schedule_ele])
         if len(set(install_schedule_list)
                ) == 1 and u"width: 100%;" in install_schedule_list:
             break
         else:
             time.sleep(3)
     time.sleep(3)
     next_button_attr = get_element_attribute(
         find_elements(self.driver, By.CSS_SELECTOR,
                       ".btn.btn-large.btn-primary")[0], "disabled")
     if next_button_attr == 0:
         return FuncResult(False, u"Installing Selected Parcels",
                           caputre(self.driver))
     else:
         click_element(self.driver, By.CSS_SELECTOR,
                       ".btn.btn-large.btn-primary")
     time.sleep(1)
     ele_text = get_element_text(self.driver, By.CSS_SELECTOR,
                                 "#hostInspectorStep>div>h2")
     ret = u"Inspect hosts for correctness" in ele_text
     return FuncResult(ret, u"Installing Selected Parcels",
                       caputre(self.driver))
 def verify_install_result(self, ele_select, endtime, para):
     status = ''
     while time.time() < endtime:
         status = get_element_attribute(
             find_elements(self.driver, By.CSS_SELECTOR, ele_select)[0],
             "class")
         if para == status:
             break
         else:
             time.sleep(3)
     return status
Beispiel #8
0
 def select_hosts(self):
     self.logger.info(u"%sselect hosts%s\n" % ('+' * 12, '+' * 12))
     click_element(self.driver, By.CSS_SELECTOR,
                   "#newOrExistingHostsTabs>li+li>a")
     host_buttons = find_elements(self.driver, By.CSS_SELECTOR,
                                  "tr>td>input")
     host_name_list = map(
         lambda x: x.text,
         find_elements(self.driver, By.CSS_SELECTOR,
                       "#HostsTable tr>td:nth-child(2) a"))
     for name in self.data["host_name"]:
         index_s = get_ele_index(host_name_list, name)
         if index_s != None:
             host_buttons[index_s].click()
         else:
             self.logger.warning(u"host name [%] is wrong!" % name)
     time.sleep(1)
     click_element(self.driver, By.CSS_SELECTOR, "#continueExistingButton")
     ele_text = get_element_text(
         self.driver, By.CSS_SELECTOR,
         "#repositorySelectionStep>.wizard-step>h2")
     ret = ele_text == u"Select Repository"
     return FuncResult(ret, u"select hosts", caputre(self.driver))
Beispiel #9
0
    def config_service(self):
        self.logger.info(u"%sconfig service%s\n" % ('+' * 12, '+' * 12))
        endTime = time.time() + 120
        while time.time() < endTime:
            if find_elements(self.driver, By.CSS_SELECTOR,
                             "#reviewStep .param-spec-property"):
                break
        time.sleep(1)
        click_element(self.driver, By.CSS_SELECTOR,
                      "#bottomButtons button[data-bind*=\"onClickContinue\"]")
        for _ in range(5):
            c_url = self.driver.current_url
            self.logger.info(c_url)
            if u"commandDetailsStep" in c_url:
                break
            else:
                time.sleep(2)
#         ele_text=get_element_text(self.driver,By.CSS_SELECTOR,"#commandDetailsStep>div>div:first-child>h2:first-child .muted")
        c_url = self.driver.current_url
        self.logger.info(c_url)
        ret = u"commandDetailsStep" in c_url
        return FuncResult(ret, u"config service", caputre(self.driver))
 def Kafka_deploy(self):
     self.logger.info(u"%sKafka install parcel%s\n" % ('+' * 12, '+' * 12))
     cur_url = self.driver.current_url
     install_url = cur_url.split(":7180")[0] + ":7180/cmf/parcel/status"
     self.driver.get(install_url)
     time.sleep(2)
     #        self.driver.execute_script("$('tbody .name>span>span').attr(\"style\",\"\")")
     parcel_name_list = map(
         lambda x: x.text,
         find_elements(self.driver, By.CSS_SELECTOR,
                       "tbody .name>span>span"))
     parcel_version_list = map(
         lambda x: x.text,
         find_elements(self.driver, By.CSS_SELECTOR,
                       "tbody .version>span>span"))
     Kafka_name_index = [
         i for i, x in enumerate(parcel_name_list) if x == u"KAFKA"
     ]
     Kafka_version_index = [
         i for i, x in enumerate(parcel_version_list)
         if x == u"2.1.1-1.2.1.1.p0.18"
     ]
     kafka_index = [
         i for i in Kafka_version_index if i in Kafka_name_index
     ][0]
     kafka_status = get_element_text(
         self.driver, By.CSS_SELECTOR,
         "tbody>tr:nth-child(%s)>.version+td>div" % (kafka_index * 2 + 1, ))
     if u"Downloaded" in kafka_status:
         click_element(
             self.driver, By.CSS_SELECTOR,
             "tbody>tr:nth-child(%s)>.actions button[title*=\"Distribute\"]"
             % (kafka_index * 2 + 1, ))
         status = self.verify_install_result(
             "tbody>tr:nth-child(%s)>td:nth-child(3)>div" %
             (kafka_index * 2 + 1, ),
             time.time() + 300, u'distributed clickable')
         if u'distributed clickable' != status:
             return FuncResult(False, u"Kafka install parcel distribute",
                               caputre(self.driver))
         click_element(
             self.driver, By.CSS_SELECTOR,
             "tbody>tr:nth-child(%s)>.actions button[title*=\"Activate\"]" %
             (kafka_index * 2 + 1, ))
         if verify_element(
                 self.driver, By.CSS_SELECTOR,
                 "#parcelRestartInfoDialog button[data-bind$=\"onClickActivateOnly\"]",
                 5):
             click_element(
                 self.driver, By.CSS_SELECTOR,
                 "#parcelRestartInfoDialog button[data-bind$=\"onClickActivateOnly\"]"
             )
         else:
             return FuncResult(False, u"Kafka install parcel Activate",
                               caputre(self.driver))
         status = self.verify_install_result(
             "tbody>tr:nth-child(%s)>td:nth-child(3)>div" %
             (kafka_index * 2 + 1, ),
             time.time() + 300, u'activated clickable')
         if u'activated clickable' != status:
             return FuncResult(False, u"Kafka install parcel Activate",
                               caputre(self.driver))
     elif u"Distributed" in kafka_status and u"Activated" not in kafka_status:
         click_element(
             self.driver, By.CSS_SELECTOR,
             "tbody>tr:nth-child(%s)>.actions button[title*=\"Activate\"]" %
             (kafka_index * 2 + 1, ))
         if verify_element(
                 self.driver, By.CSS_SELECTOR,
                 "#parcelRestartInfoDialog button[data-bind$=\"onClickActivateOnly\"]",
                 5):
             click_element(
                 self.driver, By.CSS_SELECTOR,
                 "#parcelRestartInfoDialog button[data-bind$=\"onClickActivateOnly\"]"
             )
         else:
             return FuncResult(False, u"Kafka install parcel Activate",
                               caputre(self.driver))
         status = self.verify_install_result(
             "tbody>tr:nth-child(%s)>td:nth-child(3)>div" %
             (kafka_index * 2 + 1, ),
             time.time() + 300, u'activated clickable')
         if u'activated clickable' != status:
             return FuncResult(False, u"Kafka install parcel Activate",
                               caputre(self.driver))
     elif u"Distributed, Activated" in kafka_status:
         pass
     return FuncResult(True, u"Kafka install parcel", caputre(self.driver))
Beispiel #11
0
 def Database_setup(self):
     self.logger.info(u"%sDatabase setup%s\n" % ('+' * 12, '+' * 12))
     service_name_list = map(
         lambda x: x.text,
         find_elements(self.driver, By.CSS_SELECTOR,
                       ".db-test-connection-view tbody h2"))
     #        db_hostname_input_ele_list=find_elements(self.driver,By.CSS_SELECTOR,".db-test-connection-view table[class*=\"body\"] .host")
     db_name_input_ele_list = find_elements(
         self.driver, By.CSS_SELECTOR,
         ".db-test-connection-view table[class*=\"body\"] .name")
     db_username_input_ele_list = find_elements(
         self.driver, By.CSS_SELECTOR,
         ".db-test-connection-view table[class*=\"body\"] .username")
     db_passwd_input_ele_list = find_elements(
         self.driver, By.CSS_SELECTOR,
         ".db-test-connection-view table[class*=\"body\"] .password")
     self.driver.execute_script(
         "$('.db-test-connection-view table[class*=\"body\"] .host').val(\"%s\")"
         % (self.data["Database_setup"]["mysql_hostname"], ))
     for service_name in self.data["Database_setup"].keys():
         if u"mysql_hostname" not in service_name:
             service_name_index = get_ele_index(service_name_list,
                                                service_name)
             if service_name_index != None:
                 db_name_input_ele_list[service_name_index].clear()
                 db_name_input_ele_list[service_name_index].send_keys(
                     self.data["Database_setup"][service_name]
                     ["Database Name"])
                 db_username_input_ele_list[service_name_index].clear()
                 db_username_input_ele_list[service_name_index].send_keys(
                     self.data["Database_setup"][service_name]["Username"])
                 db_passwd_input_ele_list[service_name_index].clear()
                 db_passwd_input_ele_list[service_name_index].send_keys(
                     self.data["Database_setup"][service_name]["Password"])
             else:
                 self.logger.error(u"service name [] is invalid" %
                                   (service_name, ))
     time.sleep(1)
     #         click_element(self.driver,By.CSS_SELECTOR,".db-test-connection-view label>input[data-bind*=\"showPassword\"]")
     #         click_element(self.driver, By.CSS_SELECTOR, ".db-test-connection-view button[data-bind*=\"testConnection\"]")
     self.logger.info(
         "$('.db-test-connection-view label>input[data-bind*=\"showPassword\"]').click()"
     )
     self.driver.execute_script(
         "$('.db-test-connection-view label>input[data-bind*=\"showPassword\"]').click()"
     )
     self.logger.info(
         "$('.db-test-connection-view button[data-bind*=\"testConnection\"]').click()"
     )
     self.driver.execute_script(
         "$('button[data-bind*=\"testConnection\"]').click()")
     endtime = time.time() + 30
     while time.time() < endtime:
         result_ele = find_elements(self.driver, By.CSS_SELECTOR,
                                    ".bold.message>i")
         test_conn_result = map(get_element_attribute, result_ele,
                                ["class" for _ in result_ele])
         if len(set(test_conn_result))==1 and \
            True not in ["error" in result for result  in test_conn_result] and \
            True in ["success" in result for result  in test_conn_result]:
             break
         elif True in ["error" in result for result in test_conn_result]:
             return FuncResult(False, u"Database setup",
                               caputre(self.driver))
         else:
             time.sleep(3)
     click_element(self.driver, By.CSS_SELECTOR,
                   "#bottomButtons button[data-bind*=\"onClickContinue\"]")
     time.sleep(3)
     ele_text = get_element_text(self.driver, By.CSS_SELECTOR,
                                 "#reviewStep h2")
     ret = u"Review Changes" in ele_text
     return FuncResult(ret, u"Database setup", caputre(self.driver))
Beispiel #12
0
    def add_role(self):
        self.logger.info(u"%sdploy role%s\n" % ('+' * 12, '+' * 12))
        self.logger.info(self.data)
        if self.data["host_role_default"] == "no":
            service_name_list = map(
                lambda x: x.text,
                find_elements(self.driver, By.CSS_SELECTOR, ".row h3 span"))
            for service_name in self.data["host_role"].keys():
                self.logger.info(service_name)
                service_name_index = get_ele_index(service_name_list,
                                                   service_name)
                service_role_name_list = map(
                    lambda x: x.text,
                    find_elements(
                        self.driver, By.CSS_SELECTOR,
                        ".row:nth-child(%s) .name" %
                        (4 + 2 * service_name_index, )))
                #                self.logger.info(service_role_name_list)
                #                service_role_ele_list=find_elements(self.driver, By.CSS_SELECTOR,".row:nth-child(%s) div>a")
                for role_name in self.data["host_role"][service_name].keys():
                    time.sleep(1)
                    self.logger.info(role_name)
                    role_index = get_ele_index(service_role_name_list,
                                               role_name)
                    if self.data["host_role"][service_name][
                            role_name] and role_index != None:
                        if verify_element(
                                self.driver, By.CSS_SELECTOR,
                                ".row:nth-child(%s)>.span3:nth-child(%s)>div+div>a+ul"
                                %
                            (4 + 2 * service_name_index, 1 + role_index)):
                            self.logger.info(
                                "$('.row:nth-child(%s)>.span3:nth-child(%s)>div+div>a+ul>li>a[data-bind*=\"Custom\"]').click()"
                                % (4 + 2 * service_name_index, 1 + role_index))
                            self.driver.execute_script(
                                "$('.row:nth-child(%s)>.span3:nth-child(%s)>div+div>a+ul>li>a[data-bind*=\"Custom\"]').click()"
                                % (4 + 2 * service_name_index, 1 + role_index))
                        else:
                            self.logger.info(
                                "$('.row:nth-child(%s)>.span3:nth-child(%s)>div+div>a').click()"
                                % (4 + 2 * service_name_index, 1 + role_index))
                            self.driver.execute_script(
                                "$('.row:nth-child(%s)>.span3:nth-child(%s)>div+div>a').click()"
                                % (4 + 2 * service_name_index, 1 + role_index))
                        role_checkbox_list = find_elements(
                            self.driver, By.CSS_SELECTOR, "tbody i")
                        role_hostname = map(
                            lambda x: x.text,
                            find_elements(
                                self.driver, By.CSS_SELECTOR,
                                "tbody>tr>td[data-bind$=\"hostName\"]"))
                        for checkbox in role_checkbox_list:
                            if u" check" in get_element_attribute(
                                    checkbox, "class"):
                                checkbox.click()
                                time.sleep(0.5)
                        for hostname in self.data["host_role"][service_name][
                                role_name]:
                            self.logger.info(hostname)
                            hostname_index = get_ele_index(
                                role_hostname, hostname)
                            if hostname_index != None:
                                role_checkbox_list[hostname_index].click()
                            else:
                                self.logger.error(u"host name is invalid")
                        if not click_element(
                                self.driver, By.CSS_SELECTOR,
                                "form #modalDialog .modal-footer>.btn+.btn"):
                            click_element(
                                self.driver, By.CSS_SELECTOR,
                                "form #modalDialog .modal-footer>.dismissButton"
                            )
#                         ok_button=find_elements(self.driver,By.CSS_SELECTOR,"form #modalDialog .modal-footer>.btn-primary")[0]
#                         if get_element_attribute(ok_button,"disabled")==0:
#                             ok_button.click()
#                         else:
#                             click_element(self.driver,By.CSS_SELECTOR, "form #modalDialog .modal-footer>.btn+.btn")
        elif self.data["host_role_default"] == "yes":
            pass
        click_element(self.driver, By.CSS_SELECTOR,
                      "button[data-bind*=\"onClickContinue\"]")
        ele_text = get_element_text(self.driver, By.CSS_SELECTOR,
                                    ".db-test-connection-view>h2")
        ret = ele_text == u"Database Setup"
        return FuncResult(ret, u"dploy role", caputre(self.driver))