コード例 #1
0
class LinuxResource(object):
    def __init__(self, driver):
        self.driver = driver
        self.frameElem = frameElement(driver)
        self.resource = Resource(driver)
        self.account = Accountmgr(driver)

    u'''添加和编辑Linux资源
	   Parameters:
	      - data:excel中的一行数据
	'''

    def add_edit_linux_resource(self, data):
        self.frameElem.from_frame_to_otherFrame("mainFrame")
        #资源名称
        self.resource.set_resource_name(data[3])
        #资源ip
        self.resource.set_resource_ip(data[4])
        #归属部门
        if data[5] != 'no':
            self.resource.set_depart(data[5])
        self.resource.select_all_agreement()
        #从IP
        if data[6] != 'no':
            self.resource.set_resource_fortIps(data[6])
        #系统版本
        if data[7] != 'no':
            self.resource.set_sys_version(data[7])
        #密码策略
        if data[8] != 'no':
            self.resource.select_pwd_strategy(data[8])
        #改密驱动名称
        if data[9] != 'no':
            self.resource.set_changePwd_driver(data[9])

        #管理员帐号
        if data[10] != 'no':
            self.resource.click_account_sync()
            self.resource.set_admin_account(data[10])
        #管理员口令
        if data[11] != 'no':
            self.resource.set_admin_pwd(data[11])
        #口令确认
        if data[12] != 'no':
            self.resource.set_confirm_pwd(data[12])
            self.resource.click_up_super()
            #提权账号口令
            self.resource.set_super_pwd(data[13])
            #确认口令
            self.resource.set_super_confirm_pwd(data[14])
        self.resource.resoure_save_button()

    u'''校验Linux资源
	   Parameters:
	      - datarow:excel数据位于第几行
	      - data:excel中的一行数据
	'''

    def check_linux_resource(self, datarow, data):
        self.frameElem.from_frame_to_otherFrame("mainFrame")
        #资源名称
        self.resource.set_resource_name(data[2])
        #资源ip
        self.resource.set_resource_ip(data[3])
        #协议类型
        if data[4] != 'no':
            self.resource.select_agreement(data[4])
        #协议类型 端口
        if datarow == 7:
            self.resource.set_port(data[4], data[5])
        if datarow == 8:
            self.resource.clear_port("Ssh1")
        if datarow == 9:
            self.resource.set_port("Ssh1", data[5])
        if datarow == 12:
            self.resource.click_account_sync()
            self.resource.click_up_super()
        if datarow == 13:
            #提权账号口令
            if data[6] != 'no':
                self.resource.set_super_pwd(data[6])
            #确认口令
            if data[7] != 'no':
                self.resource.set_super_confirm_pwd(data[7])
            self.resource.set_super_prompt()
        self.resource.resoure_save_button()

    u'''添加资源账号
	   Parameters:
	      - editacttname:编辑的资源账号名称
	      - value:选择编辑方式的value值
	      - addactname:填写的资源账号名称
	      - pwd:账号口令
	      - cmfpwd:确认口令
	'''

    def add_edit_resource_account(self,
                                  editacttname='no',
                                  value='no',
                                  addactname='no',
                                  pwd='no',
                                  cmfpwd='no'):
        self.account.click_account_add_edit_button(editacttname)
        if value != 'no':
            self.account.select_edit_way(value)
        if addactname != 'no':
            self.account.set_account_name(addactname)
        if pwd != 'no':
            self.account.set_account_pwd(pwd)
        if cmfpwd != 'no':
            self.account.set_account_confirm_pwd(cmfpwd)
        self.account.set_authorize()
        self.account.click_save_account()

    u'''校验资源账号
	   Parameters:
	      - value:选择编辑方式的value值
	      - addactname:填写的资源账号名称
	      - pwd:账号口令
	      - cmfpwd:确认口令
	'''

    def check_resource_account(self,
                               value='no',
                               addactname='no',
                               pwd='no',
                               cmfpwd='no'):
        if addactname == 'no':
            self.account.clear_account_name()
        if pwd == 'no':
            self.account.clear_account_pwd()
        if cmfpwd == 'no':
            self.account.clear_account_confirm_pwd()
        if value != 'no':
            self.account.select_edit_way(value)
        if addactname != 'no':
            self.account.set_account_name(addactname)
        if pwd != 'no':
            self.account.set_account_pwd(pwd)
        if cmfpwd != 'no':
            self.account.set_account_confirm_pwd(cmfpwd)
        self.account.set_authorize()
        self.account.click_save_account()
コード例 #2
0
ファイル: databaseElement.py プロジェクト: xuanzhaoyue/xuan
class DatabaseResource(object):
    #数据库名称
    DATABASE_NAME = "fortDatabaseName"
    #服务名
    SERVICE_NAME = "fortDatabaseServerName"
    #全选应用发布
    SELECT_ALL_APP = "add_app_release"
    #应用发布添加到右侧
    ADD_APP = "add"
    #服务名
    SERVICE_NAME = "fortDatabaseServerName"
    #BS账号属性
    ACCOUNT_ATTRIBUTE = "fortBsAccountAttribute"
    #BS表单名称
    FORM_NAME = "fortBsFormName"
    #口令属性
    PWD_ATTRIBUTE = "fortBsPasswordAttribute"
    #表单提交方式
    SUBMIT_METHOD = "fortBsFormSubmitMethod"
    #登录URL
    LOGIN_URL = "fortBsLoginUrl"
    #连接端口
    CONNECT_PORT = "fortDatabasePort"
    #选择归属操作系统
    SELECT_SYSTEM = "system_data_select_system"
    #归属资源IP
    SYSTEM_IP = "fortResourceIp"
    #归属资源检索
    SYSTEM_QUERY = "quick_query"
    #全选按钮
    SYSTEM_CHECK_ALL = "resource_check_all"
    #确认按钮
    SYSTEM_OK_BUTTON = "okButton"
    #取消按钮
    SYSTEM_QUIT_BUTTON = "cancelButton"

    def __init__(self, driver):
        self.driver = driver
        self.getElem = getElement(driver)
        self.selectElem = selectElement(driver)
        self.frameElem = frameElement(driver)
        self.log = log()
        self.resource = Resource(driver)
        self.account = Accountmgr(driver)
        self.cnEn = cnEncode()

    u'''添加和编辑database资源
		Parameters:
			- data:excel中的一行数据
	'''

    def add_edit_database_resource(self, data):
        self.frameElem.from_frame_to_otherFrame("mainFrame")
        #资源名称
        self.resource.set_resource_name(data[3])
        #归属部门
        if data[4] != "":
            self.resource.set_depart(data[4])
        #资源ip
        if data[5] != "":
            self.resource.set_resource_ip(data[5])
        #库名
        if data[6] != "":
            self.set_database_name(data[6])
        #服务名
        if data[7] != "":
            self.set_service_name(data[7])
        #密码策略
        if data[8] != "":
            self.resource.select_pwd_strategy(data[8])
        #账号属性
        if data[9] != "":
            self.set_account_attribute(data[9])
            self.set_form_name(data[10])
            self.set_pwd_attribute(data[11])
            self.set_submit_method(data[12])
            self.set_login_url(data[13])
        #选择客户端
        if data[14] != "":
            self.select_protocol(data[14])
        #选择应用发布
        if data[15] != "":
            self.select_application(data[15])
        #依附操作系统IP
        if data[16] != "":
            self.click_select_button()
            self.set_system_ip(data[16])
            self.click_query_button()
            self.click_check_all_button()
            self.click_confirm_button()
        #管理员帐号
        if data[17] != "":
            self.resource.click_account_sync()
            self.resource.set_admin_account(data[17])
            #管理员口令
            self.resource.set_admin_pwd(data[18])
            #口令确认
            self.resource.set_confirm_pwd(data[19])
        time.sleep(1)
        self.resource.click_save_button()

    u'''填写资源名称'''

    def set_resource_name(self, resourceName):
        reName = self.cnEn.is_float(resourceName)
        self.frameElem.from_frame_to_otherFrame("mainFrame")
        name = self.getElem.find_element_with_wait_EC('id', 'fortResourceName')
        name.clear()
        name.send_keys(reName)

    u'''填写资源IP'''

    def set_resource_ip(self, resourceIp):
        reIp = self.cnEn.is_float(resourceIp)
        ip = self.getElem.find_element_with_wait_EC('id', 'fortResourceIp')
        ip.clear()
        ip.send_keys(reIp)
        self.getElem.find_element_wait_and_click_EC("id", "spanid")
        self.getElem.find_element_with_wait_EC("classname", "ip_succ")
        time.sleep(3)
        #self.driver.implicitly_wait(5)

    u'''填写database库名
		parameter:
			- databaseName:数据库库名
	'''

    def set_database_name(self, databaseName):
        try:
            reName = self.cnEn.is_float(databaseName)
            self.frameElem.from_frame_to_otherFrame("mainFrame")
            name = self.getElem.find_element_with_wait_EC(
                'id', self.DATABASE_NAME)
            name.clear()
            name.send_keys(reName)
        except Exception as e:
            print "DatabaseName is error :" + str(e)

    u'''填写database服务名
		parameter:
			- serviceName:数据库库名
	'''

    def set_service_name(self, serviceName):
        reName = self.cnEn.is_float(serviceName)
        try:
            self.frameElem.from_frame_to_otherFrame("mainFrame")
            serviceName = self.getElem.find_element_with_wait_EC(
                'id', self.SERVICE_NAME)
            serviceName.clear()
            serviceName.send_keys(reName)
        except Exception as e:
            print "ServiceName is error :" + str(e)

    u'''点击添加到应用发布到右侧'''

    def add_application(self):
        self.getElem.find_element_wait_and_click_EC('id', self.ADD_APP)

    u'''选择客户端'''

    def select_protocol(self, proName):
        reName = self.cnEn.is_float(proName)
        parent_xpath = "//table[@id='trees']/tbody/tr[7]/td[2]"
        parent_elem = self.getElem.find_element_with_wait_EC(
            'xpath', parent_xpath)
        elems = parent_elem.find_elements_by_tag_name("span")
        for index in range(len(elems)):
            if elems[index].text == reName:
                protocol_xpath = parent_xpath + "/" + "span[" + str(
                    index + 1) + "]/input[1]"
                protocol_elem = self.getElem.find_element_with_wait_EC(
                    'xpath', protocol_xpath)
                if not protocol_elem.is_selected():
                    protocol_elem.click()

    u'''选择应用发布
		parameter:
			- appStr:应用发布
	'''

    def select_application(self, appStr):
        reappStr = self.cnEn.is_float(appStr)
        appList = reappStr.split(',')
        appSelect = self.getElem.find_element_with_wait_EC(
            'id', self.SELECT_ALL_APP)
        try:
            if appStr != "":
                for appName in appList:
                    self.selectElem.select_element_by_visible_text(
                        appSelect, appName)
                    self.add_application()

        except Exception as e:
            print "Domian select error:" + str(e)

#---------------------------------BS属性--------------------------------------

    u'''填写BS账号属性
		parameter:
			- accountAtt:账号属性
	'''
    def set_account_attribute(self, accountAtt):
        reName = self.cnEn.is_float(accountAtt)
        try:
            accountArrbt = self.getElem.find_element_with_wait_EC(
                'id', self.ACCOUNT_ATTRIBUTE)
            accountArrbt.clear()
            accountArrbt.send_keys(reName)
        except Exception as e:
            print "Set BS Account Attribute is error :" + str(e)

    u'''填写BS表单名称
		parameter:
			- formName:表单名称
	'''

    def set_form_name(self, formName):
        reName = self.cnEn.is_float(formName)
        try:
            accountArrbt = self.getElem.find_element_with_wait_EC(
                'id', self.FORM_NAME)
            accountArrbt.clear()
            accountArrbt.send_keys(reName)
        except Exception as e:
            print "Set BS form name is error :" + str(e)

    u'''填写BS口令属性
		parameter:
			- pwdAtt:口令属性
	'''

    def set_pwd_attribute(self, pwdAtt):
        reATtt = self.cnEn.is_float(pwdAtt)
        try:
            pwdArrbt = self.getElem.find_element_with_wait_EC(
                'id', self.PWD_ATTRIBUTE)
            pwdArrbt.clear()
            pwdArrbt.send_keys(reATtt)
        except Exception as e:
            print "Set BS Pwd Attribute is error :" + str(e)

    u'''填写BS表单提交方式
		parameter:
			- submitMethod:提交方式
	'''

    def set_submit_method(self, submitMethod):
        reMethod = self.cnEn.is_float(submitMethod)
        try:
            smtMethod = self.getElem.find_element_with_wait_EC(
                'id', self.SUBMIT_METHOD)
            smtMethod.clear()
            smtMethod.send_keys(reMethod)
        except Exception as e:
            print "Set BS submit method error :" + str(e)

    u'''填写BS登录URL
		parameter:
			- loginUrl:登录url
	'''

    def set_login_url(self, loginUrl):
        reUrl = self.cnEn.is_float(loginUrl)
        try:
            url = self.getElem.find_element_with_wait_EC('id', self.LOGIN_URL)
            url.clear()
            url.send_keys(reUrl)
        except Exception as e:
            print "Set BS login url error :" + str(e)

#--------------------------------依附操作系统----------------------------------

    u'''点击选择'''
    def click_select_button(self):

        self.getElem.find_element_wait_and_click_EC('id', self.SELECT_SYSTEM)

    u'''检索的依附操作系统IP'''

    def set_system_ip(self, systemIp):
        self.frameElem.from_frame_to_otherFrame("artIframe")
        reIp = self.cnEn.is_float(systemIp)
        try:
            system_ip = self.getElem.find_element_with_wait_EC(
                'id', self.SYSTEM_IP)
            system_ip.clear()
            system_ip.send_keys(reIp)
        except Exception as e:
            print "Set system ip error :" + str(e)

    u'''点击检索按钮'''

    def click_query_button(self):
        self.getElem.find_element_wait_and_click_EC('id', self.SYSTEM_QUERY)

    u'''点击全选按钮'''

    def click_check_all_button(self):
        self.getElem.find_element_wait_and_click_EC('id',
                                                    self.SYSTEM_CHECK_ALL)

    u'''点击确认按钮'''

    def click_confirm_button(self):
        self.frameElem.switch_to_content()
        self.getElem.find_element_wait_and_click_EC('id',
                                                    self.SYSTEM_OK_BUTTON)

    u'''点击取消按钮'''

    def click_quit_button(self):
        self.frameElem.switch_to_content()
        self.getElem.find_element_wait_and_click_EC('id',
                                                    self.SYSTEM_QUIT_BUTTON)

    u'''判断是否是有ip可用性校验'''

    def is_pop_up(self):
        xpath = "html/body/div[1]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[2]/td[2]/div"
        flag = self.getElem.find_element_wait_and_compare_text(
            "xpath", xpath, [0, "ip可用性校验失败!"])
        if flag:
            self.cmf.click_login_msg_button()
#--------------------------windows资源-----------------------------------------

    u'''填写windows域名
	   parameter:
	       - domainname:windows域名
	'''
    def set_domain_name(self, domainname):
        try:
            doname = self.cnEn.is_float(domainname)
            self.frameElem.from_frame_to_otherFrame("mainFrame")
            self.getElem.find_element_wait_and_clear_EC('id', "fortDomainName")
            self.getElem.find_element_wait_and_sendkeys(
                'id', "fortDomainName", doname)
        except Exception as e:
            print "domainname is error :" + str(e)

    u'''填写主机名称
	   parameter:
	       - hostname:主机名称
	'''

    def set_host_name(self, hostname):
        try:
            host = self.cnEn.is_float(hostname)
            self.frameElem.from_frame_to_otherFrame("mainFrame")
            self.getElem.find_element_wait_and_clear_EC(
                'id', "window_host_name")
            self.getElem.find_element_wait_and_sendkeys(
                'id', "window_host_name", host)
        except Exception as e:
            print "window_host_name is error :" + str(e)
コード例 #3
0
class WindowsResource(object):
    def __init__(self, driver):
        self.driver = driver
        self.getElem = getElement(driver)
        self.selectElem = selectElement(driver)
        self.frameElem = frameElement(driver)
        self.resource = Resource(driver)
        self.cnEn = cnEncode()

    u'''添加和编辑windows资源
	   Parameters:
	      - data:excel中的一行数据
	'''

    def add_edit_windows_resource(self, data):
        self.frameElem.from_frame_to_otherFrame("mainFrame")
        #资源名称
        if data[3] != 'no':
            self.resource.set_resource_name(data[3])
        #资源ip
        if data[5] != 'no':
            self.resource.set_resource_ip(data[5])
        #从IP
        if data[6] != 'no':
            self.resource.set_resource_fortIps(data[6])
        #归属部门
        if data[4] != 'no':
            self.resource.set_depart(data[4])
        #密码策略
        if data[7] != 'no':
            self.resource.select_pwd_strategy(data[7])
        #选择所要运维协议
        self.resource.select_all_agreement()
        #windows域名
        if data[8] != 'no':
            self.set_domain_name(data[8])
        #账号分类
        if data[9] != 'no':
            self.resource.click_account_sync()
            self.select_account_type(data[9])
        #归属域控主机
        if data[10] != 'no':
            self.select_attach_domian(data[10])
        #主机名称
        if data[11] != 'no':
            self.set_host_name(data[11])
        #管理员帐号
        if data[12] != 'no':
            if data[9] == 'no':
                self.resource.click_account_sync()
            self.resource.set_admin_account(data[12])
        #管理员帐号
        if data[16] != 'no':
            self.resource.click_account_sync()
            self.select_account_protocol(data[16])
            self.set_port(data[17])
            if data[16] == "Ldap":
                self.set_ldap_account(data[18])
            else:
                self.set_ssh_account(data[18])
        #管理员口令
        if data[13] != 'no':
            self.resource.set_admin_pwd(data[13])
        #口令确认
        if data[14] != 'no':
            self.resource.set_confirm_pwd(data[14])
        #BaseDN
        if data[15] != 'no':
            self.set_base_dn(data[15])
        self.resource.click_save_button()

    u'''校验windows资源
	   Parameters:
	      - datarow:excel数据位于第几行
	      - data:excel中的一行数据
	'''

    def check_windows_resource(self, datarow, data):
        self.frameElem.from_frame_to_otherFrame("mainFrame")
        #资源名称
        self.resource.set_resource_name(data[2])
        #资源ip
        self.resource.set_resource_ip(data[3])
        #协议类型
        if data[4] != 'no':
            self.resource.select_agreement(data[4])
        #协议类型 端口
        if datarow == 7:
            self.resource.set_port(data[4], data[5])
        if datarow == 8:
            self.resource.clear_port("Vnc")
        if datarow == 9:
            self.resource.set_port("Vnc", data[5])
        if datarow == 12:
            self.resource.click_account_sync()
            self.select_account_type(data[6])
        if datarow == 13:
            self.select_attach_domian(data[7])
        self.resource.click_save_button()

    u'''填写windows域名
	   parameter:
	       - domainname:windows域名
	'''

    def set_domain_name(self, domainname):
        try:
            doname = self.cnEn.is_float(domainname)
            self.frameElem.from_frame_to_otherFrame("mainFrame")
            self.getElem.find_element_wait_and_clear('id', "fortDomainName")
            self.getElem.find_element_wait_and_sendkeys(
                'id', "fortDomainName", doname)
        except Exception as e:
            print "domainname is error :" + str(e)

    u'''选择账号分类
	   Parameters:
	      - value:value属性
	'''

    def select_account_type(self, value):
        type = self.cnEn.is_float(value)
        self.frameElem.from_frame_to_otherFrame("mainFrame")
        selectelem = self.getElem.find_element_with_wait_EC(
            "id", "selectDisplay")
        self.selectElem.select_element_by_value(selectelem, type)

    u'''选择归属域控主机
	   parameter:
	       - text:归属域控主机的名称
	'''

    def select_attach_domian(self, text):
        try:
            domiantext = self.cnEn.is_float(text)
            self.frameElem.from_frame_to_otherFrame("mainFrame")
            selectelem = self.getElem.find_element_with_wait_EC(
                'id', "window_select_dc")
            self.selectElem.select_element_by_visible_text(
                selectelem, domiantext)
        except Exception as e:
            print "Domian select error:" + str(e)

    u'''填写主机名称
	   parameter:
	       - hostname:主机名称
	'''

    def set_host_name(self, hostname):
        try:
            host = self.cnEn.is_float(hostname)
            self.frameElem.from_frame_to_otherFrame("mainFrame")
            self.getElem.find_element_wait_and_clear('id', "window_host_name")
            self.getElem.find_element_wait_and_sendkeys(
                'id', "window_host_name", host)
        except Exception as e:
            print "window_host_name is error :" + str(e)

    u'''填写Base DN
	   parameter:
	       - basedn:Base DN名称
	'''

    def set_base_dn(self, basedn):
        try:
            base = self.cnEn.is_float(basedn)
            self.frameElem.from_frame_to_otherFrame("mainFrame")
            self.getElem.find_element_wait_and_clear('id', "fortBaseDn")
            self.getElem.find_element_wait_and_sendkeys(
                'id', "fortBaseDn", base)
        except Exception as e:
            print "fortBaseDn is error :" + str(e)

    u'''填写连接端口
	   parameter:
	       - portname:连接端口名称
	'''

    def set_port(self, portname):
        try:
            port = self.cnEn.is_float(portname)
            self.frameElem.from_frame_to_otherFrame("mainFrame")
            self.getElem.find_element_wait_and_clear('id',
                                                     "fortConnectionPort")
            self.getElem.find_element_wait_and_sendkeys(
                'id', "fortConnectionPort", port)
        except Exception as e:
            print "port is error :" + str(e)

    u'''填写ldap账号
	   parameter:
	       - actname:管理员账号
	'''

    def set_ldap_account(self, actname):
        try:
            act = self.cnEn.is_float(actname)
            self.frameElem.from_frame_to_otherFrame("mainFrame")
            self.getElem.find_element_wait_and_clear('id',
                                                     "fortAdminAccount_ldap")
            self.getElem.find_element_wait_and_sendkeys(
                'id', "fortAdminAccount_ldap", act)
        except Exception as e:
            print "name is error :" + str(e)

    u'''填写ssh账号
	   parameter:
	       - actname:管理员账号
	'''

    def set_ssh_account(self, actname):
        try:
            act = self.cnEn.is_float(actname)
            self.frameElem.from_frame_to_otherFrame("mainFrame")
            self.getElem.find_element_wait_and_clear('id',
                                                     "fortAdminAccount_ssh")
            self.getElem.find_element_wait_and_sendkeys(
                'id', "fortAdminAccount_ssh", act)
        except Exception as e:
            print "name is error :" + str(e)

    u'''选择账号同步连接协议
	   parameter:
	       - proname:同步
	'''

    def select_account_protocol(self, proname):
        try:
            pro = self.cnEn.is_float(proname)
            self.frameElem.from_frame_to_otherFrame("mainFrame")
            selem = self.getElem.find_element_with_wait_EC(
                'id', "fortConnectionProtocol")
            self.selectElem.select_element_by_visible_text(selem, pro)
        except Exception as e:
            print " protocol is error :" + str(e)

    u'''是否勾选获取所有账号'''

    def check_all_account(self):
        try:
            self.frameElem.from_frame_to_otherFrame("mainFrame")
            self.getElem.find_element_wait_and_click_EC(
                'id', "get_all_accounts")
        except Exception as e:
            print " Check failure :" + str(e)
コード例 #4
0
ファイル: test_linux_ment.py プロジェクト: isomper/testIsomp
class LinuxResource(object):

	def __init__(self, driver):
		self.driver = driver
		self.frameElem = frameElement(driver)
		self.resource = Resource(driver)
		self.account = Accountmgr(driver)

	u'''添加和编辑Linux资源
	   Parameters:
	      - data:excel中的一行数据
	'''
	def add_edit_linux_resource(self, data):
		self.frameElem.from_frame_to_otherFrame("mainFrame")
		#资源名称
		self.resource.set_resource_name(data[3])
		#资源ip
		self.resource.set_resource_ip(data[4])
		#归属部门
		if data[5] != 'no':
			self.resource.set_depart(data[5])
		self.resource.select_all_agreement()
		#从IP
		if data[6] != 'no':
			self.resource.set_resource_fortIps(data[6])
		#系统版本
		if data[7] != 'no':
			self.resource.set_sys_version(data[7])
		#密码策略
		if data[8] != 'no':
			self.resource.select_pwd_strategy(data[8])
		#改密驱动名称
		if data[9] != 'no':
			self.resource.set_changePwd_driver(data[9])

		#管理员帐号
		if data[10] != 'no':
			self.resource.click_account_sync()
			self.resource.set_admin_account(data[10])
		#管理员口令
		if data[11] != 'no':
			self.resource.set_admin_pwd(data[11])
		#口令确认
		if data[12] != 'no':
			self.resource.set_confirm_pwd(data[12])
			self.resource.click_up_super()
			#提权账号口令
			self.resource.set_super_pwd(data[13])
			#确认口令
			self.resource.set_super_confirm_pwd(data[14])
		self.resource.click_save_button()

	u'''校验Linux资源
	   Parameters:
	      - datarow:excel数据位于第几行
	      - data:excel中的一行数据
	'''
	def check_linux_resource(self, datarow, data):
		self.frameElem.from_frame_to_otherFrame("mainFrame")
		#资源名称
		self.resource.set_resource_name(data[2])
		#资源ip
		self.resource.set_resource_ip(data[3])
		#协议类型
		if data[4] != 'no':
			self.resource.select_agreement(data[4])
		#协议类型 端口
		if datarow == 7:
			self.resource.set_port(data[4], data[5])
		if datarow == 8:
			self.resource.clear_port("Ssh1")
		if datarow == 9:
			self.resource.set_port("Ssh1", data[5])
		if datarow == 12:
			self.resource.click_account_sync()
			self.resource.click_up_super()
		if datarow == 13:
			#提权账号口令
			if data[6] != 'no':
				self.resource.set_super_pwd(data[6])
			#确认口令
			if data[7] != 'no':
				self.resource.set_super_confirm_pwd(data[7])
			self.resource.set_super_prompt()
		self.resource.click_save_button()

	u'''添加资源账号
	   Parameters:
	      - editacttname:编辑的资源账号名称
	      - value:选择编辑方式的value值
	      - addactname:填写的资源账号名称
	      - pwd:账号口令
	      - cmfpwd:确认口令
	'''
	def add_edit_resource_account(self, editacttname='no', value='no', addactname='no', pwd='no', cmfpwd='no'):
		self.account.click_account_add_edit_button(editacttname)
		if value != 'no':
			self.account.select_edit_way(value)
		if addactname != 'no':
			self.account.set_account_name(addactname)
		if pwd != 'no':
			self.account.set_account_pwd(pwd)
		if cmfpwd != 'no':
			self.account.set_account_confirm_pwd(cmfpwd)
		self.account.set_authorize()
		self.account.click_save_account()

	u'''校验资源账号
	   Parameters:
	      - value:选择编辑方式的value值
	      - addactname:填写的资源账号名称
	      - pwd:账号口令
	      - cmfpwd:确认口令
	'''
	def check_resource_account(self, value='no', addactname='no', pwd='no', cmfpwd='no'):
		if addactname == 'no':
			self.account.clear_account_name()
		if pwd == 'no':
			self.account.clear_account_pwd()
		if cmfpwd == 'no':
			self.account.clear_account_confirm_pwd()
		if value != 'no':
			self.account.select_edit_way(value)
		if addactname != 'no':
			self.account.set_account_name(addactname)
		if pwd != 'no':
			self.account.set_account_pwd(pwd)
		if cmfpwd != 'no':
			self.account.set_account_confirm_pwd(cmfpwd)
		self.account.set_authorize()
		self.account.click_save_account()
コード例 #5
0
ファイル: databaseElement.py プロジェクト: isomper/testIsomp
class DatabaseResource(object):
	#数据库名称
	DATABASE_NAME = "fortDatabaseName"
	#服务名
	SERVICE_NAME = "fortDatabaseServerName"
	#全选应用发布
	SELECT_ALL_APP = "add_app_release"
	#应用发布添加到右侧
	ADD_APP = "add"
	#服务名
	SERVICE_NAME = "fortDatabaseServerName"
	#BS账号属性
	ACCOUNT_ATTRIBUTE = "fortBsAccountAttribute"
	#BS表单名称
	FORM_NAME = "fortBsFormName"
	#口令属性
	PWD_ATTRIBUTE = "fortBsPasswordAttribute"
	#表单提交方式
	SUBMIT_METHOD = "fortBsFormSubmitMethod"
	#登录URL
	LOGIN_URL = "fortBsLoginUrl"
	#连接端口
	CONNECT_PORT = "fortDatabasePort"
	#选择归属操作系统
	SELECT_SYSTEM = "system_data_select_system"
	#归属资源IP
	SYSTEM_IP = "fortResourceIp"
	#归属资源检索
	SYSTEM_QUERY = "quick_query"
	#全选按钮
	SYSTEM_CHECK_ALL= "resource_check_all"
	#确认按钮
	SYSTEM_OK_BUTTON = "okButton"
	#取消按钮
	SYSTEM_QUIT_BUTTON = "cancelButton"
	

	def __init__(self, driver):
		self.driver = driver
		self.getElem = getElement(driver)
		self.selectElem = selectElement(driver)
		self.frameElem = frameElement(driver)
		self.log = log()
		self.resource = Resource(driver)
		self.account = Accountmgr(driver)
		self.cnEn = cnEncode()

	u'''添加和编辑database资源
		Parameters:
			- data:excel中的一行数据
	'''
	def add_edit_database_resource(self, data):
		self.frameElem.from_frame_to_otherFrame("mainFrame")
		#资源名称
		self.resource.set_resource_name(data[3])
		#归属部门
		if data[4] != "":
			self.resource.set_depart(data[4])
		#资源ip
		if data[5] != "":
			self.resource.set_resource_ip(data[5])			
		#库名
		if data[6] != "":
			self.set_database_name(data[6])
		#服务名
		if data[7] != "":
			self.set_service_name(data[7])
		#密码策略
		if data[8] != "":
			self.resource.select_pwd_strategy(data[8])
		#账号属性
		if data[9] != "":
			self.set_account_attribute(data[9])
			self.set_form_name(data[10])
			self.set_pwd_attribute(data[11])
			self.set_submit_method(data[12])
			self.set_login_url(data[13])
		#选择客户端
		if data[14] != "":
			self.select_protocol(data[14])
		#选择应用发布
		if data[15] != "":
			self.select_application(data[15])
		#依附操作系统IP
		if data[16] != "":
			self.click_select_button()
			self.set_system_ip(data[16])
			self.click_query_button()
			self.click_check_all_button()
			self.click_confirm_button()
		#管理员帐号
		if data[17] != "":
			self.resource.click_account_sync()
			self.resource.set_admin_account(data[17])
			#管理员口令
			self.resource.set_admin_pwd(data[18])
			#口令确认
			self.resource.set_confirm_pwd(data[19])
		time.sleep(1)
		self.resource.click_save_button()

	u'''填写资源名称'''
	def set_resource_name(self,resourceName):
		reName = self.cnEn.is_float(resourceName)
		self.frameElem.from_frame_to_otherFrame("mainFrame")
		name = self.getElem.find_element_with_wait_EC('id','fortResourceName')
		name.clear()
		name.send_keys(reName)
	
	u'''填写资源IP'''
	def set_resource_ip(self,resourceIp):
		reIp = self.cnEn.is_float(resourceIp)
		ip = self.getElem.find_element_with_wait_EC('id','fortResourceIp')
		ip.clear()
		ip.send_keys(reIp)
		self.getElem.find_element_wait_and_click_EC("id", "spanid")
		self.getElem.find_element_with_wait_EC("classname", "ip_succ")
		time.sleep(3)
		#self.driver.implicitly_wait(5)
		
	u'''填写database库名
		parameter:
			- databaseName:数据库库名
	'''
	def set_database_name(self, databaseName):
		try:
			reName = self.cnEn.is_float(databaseName)
			self.frameElem.from_frame_to_otherFrame("mainFrame")
			name = self.getElem.find_element_with_wait_EC('id', self.DATABASE_NAME)
			name.clear()
			name.send_keys(reName)
		except Exception as e:
			print "DatabaseName is error :" + str(e)
	
	u'''填写database服务名
		parameter:
			- serviceName:数据库库名
	'''
	def set_service_name(self, serviceName):
		reName = self.cnEn.is_float(serviceName)
		try:
			self.frameElem.from_frame_to_otherFrame("mainFrame")
			serviceName = self.getElem.find_element_with_wait_EC('id', self.SERVICE_NAME)
			serviceName.clear()
			serviceName.send_keys(reName)
		except Exception as e:
			print "ServiceName is error :" + str(e)
	
	
	u'''点击添加到应用发布到右侧'''
	def add_application(self):
		self.getElem.find_element_wait_and_click_EC('id',self.ADD_APP)
	
	u'''选择客户端'''
	def select_protocol(self,proName):
		reName = self.cnEn.is_float(proName)
		parent_xpath = "//table[@id='trees']/tbody/tr[7]/td[2]"
		parent_elem = self.getElem.find_element_with_wait_EC('xpath',parent_xpath)
		elems = parent_elem.find_elements_by_tag_name("span")
		for index in range(len(elems)):
			if elems[index].text == reName:
				protocol_xpath = parent_xpath + "/" + "span[" + str(index+1) + "]/input[1]"
				protocol_elem = self.getElem.find_element_with_wait_EC('xpath',protocol_xpath)
				if not protocol_elem.is_selected():
					protocol_elem.click()

	u'''选择应用发布
		parameter:
			- appStr:应用发布
	'''
	def select_application(self, appStr):
		reappStr = self.cnEn.is_float(appStr)
		appList = reappStr.split(',')
		appSelect = self.getElem.find_element_with_wait_EC('id',self.SELECT_ALL_APP)
		try:
			if appStr != "":
				for appName in appList:
					self.selectElem.select_element_by_visible_text(appSelect, appName)
					self.add_application()

		except Exception as e:
			print "Domian select error:" + str(e)

#---------------------------------BS属性--------------------------------------
	
	u'''填写BS账号属性
		parameter:
			- accountAtt:账号属性
	'''
	def set_account_attribute(self, accountAtt):
		reName = self.cnEn.is_float(accountAtt)
		try:
			accountArrbt = self.getElem.find_element_with_wait_EC('id', self.ACCOUNT_ATTRIBUTE)
			accountArrbt.clear()
			accountArrbt.send_keys(reName)
		except Exception as e:
			print "Set BS Account Attribute is error :" + str(e)
	
	u'''填写BS表单名称
		parameter:
			- formName:表单名称
	'''
	def set_form_name(self, formName):
		reName = self.cnEn.is_float(formName)
		try:
			accountArrbt = self.getElem.find_element_with_wait_EC('id', self.FORM_NAME)
			accountArrbt.clear()
			accountArrbt.send_keys(reName)
		except Exception as e:
			print "Set BS form name is error :" + str(e)
	
	u'''填写BS口令属性
		parameter:
			- pwdAtt:口令属性
	'''
	def set_pwd_attribute(self, pwdAtt):
		reATtt = self.cnEn.is_float(pwdAtt)
		try:
			pwdArrbt = self.getElem.find_element_with_wait_EC('id', self.PWD_ATTRIBUTE)
			pwdArrbt.clear()
			pwdArrbt.send_keys(reATtt)
		except Exception as e:
			print "Set BS Pwd Attribute is error :" + str(e)
	
	u'''填写BS表单提交方式
		parameter:
			- submitMethod:提交方式
	'''
	def set_submit_method(self, submitMethod):
		reMethod = self.cnEn.is_float(submitMethod)
		try:
			smtMethod = self.getElem.find_element_with_wait_EC('id', self.SUBMIT_METHOD)
			smtMethod.clear()
			smtMethod.send_keys(reMethod)
		except Exception as e:
			print "Set BS submit method error :" + str(e)
	
	u'''填写BS登录URL
		parameter:
			- loginUrl:登录url
	'''
	def set_login_url(self, loginUrl):
		reUrl = self.cnEn.is_float(loginUrl)
		try:
			url = self.getElem.find_element_with_wait_EC('id', self.LOGIN_URL)
			url.clear()
			url.send_keys(reUrl)
		except Exception as e:
			print "Set BS login url error :" + str(e)

#--------------------------------依附操作系统----------------------------------
	
	u'''点击选择'''
	def click_select_button(self):
		
		self.getElem.find_element_wait_and_click_EC('id',self.SELECT_SYSTEM)
	
	u'''检索的依附操作系统IP'''
	def set_system_ip(self,systemIp):
		self.frameElem.from_frame_to_otherFrame("artIframe")
		reIp = self.cnEn.is_float(systemIp)
		try:
			system_ip = self.getElem.find_element_with_wait_EC('id', self.SYSTEM_IP)
			system_ip.clear()
			system_ip.send_keys(reIp)
		except Exception as e:
			print "Set system ip error :" + str(e)
	
	u'''点击检索按钮'''
	def click_query_button(self):
		self.getElem.find_element_wait_and_click_EC('id',self.SYSTEM_QUERY)
	
	u'''点击全选按钮'''
	def click_check_all_button(self):
		self.getElem.find_element_wait_and_click_EC('id',self.SYSTEM_CHECK_ALL)
	
	u'''点击确认按钮'''
	def click_confirm_button(self):
		self.frameElem.switch_to_content()
		self.getElem.find_element_wait_and_click_EC('id',self.SYSTEM_OK_BUTTON)
	
	u'''点击取消按钮'''
	def click_quit_button(self):
		self.frameElem.switch_to_content()
		self.getElem.find_element_wait_and_click_EC('id',self.SYSTEM_QUIT_BUTTON)
	
	u'''判断是否是有ip可用性校验'''
	def is_pop_up(self):
		xpath = "html/body/div[1]/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[2]/td[2]/div"
		flag = self.getElem.find_element_wait_and_compare_text("xpath", xpath, [0, "ip可用性校验失败!"])
		if flag:
			self.cmf.click_login_msg_button()
#--------------------------windows资源-----------------------------------------
	u'''填写windows域名
	   parameter:
	       - domainname:windows域名
	'''
	def set_domain_name(self, domainname):
		try:
			doname = self.cnEn.is_float(domainname)
			self.frameElem.from_frame_to_otherFrame("mainFrame")
			self.getElem.find_element_wait_and_clear_EC('id', "fortDomainName")
			self.getElem.find_element_wait_and_sendkeys('id', "fortDomainName", doname)
		except Exception as e:
			print "domainname is error :" + str(e)
	
	u'''填写主机名称
	   parameter:
	       - hostname:主机名称
	'''
	def set_host_name(self, hostname):
		try:
			host = self.cnEn.is_float(hostname)
			self.frameElem.from_frame_to_otherFrame("mainFrame")
			self.getElem.find_element_wait_and_clear_EC('id', "window_host_name")
			self.getElem.find_element_wait_and_sendkeys('id', "window_host_name", host)
		except Exception as e:
			print "window_host_name is error :" + str(e)
コード例 #6
0
class WindowsResource(object):

	def __init__(self, driver):
		self.driver = driver
		self.getElem = getElement(driver)
		self.selectElem = selectElement(driver)
		self.frameElem = frameElement(driver)
		self.resource = Resource(driver)
		self.cnEn = cnEncode()

	u'''添加和编辑windows资源
	   Parameters:
	      - data:excel中的一行数据
	'''
	def add_edit_windows_resource(self, data):
		self.frameElem.from_frame_to_otherFrame("mainFrame")
		#资源名称
		if data[3] != 'no':
			self.resource.set_resource_name(data[3])
		#资源ip
		if data[5] != 'no':
			self.resource.set_resource_ip(data[5])
		#从IP
		if data[6] != 'no':
			self.resource.set_resource_fortIps(data[6])
		#归属部门
		if data[4] != 'no':
			self.resource.set_depart(data[4])
		#密码策略
		if data[7] != 'no':
			self.resource.select_pwd_strategy(data[7])
		#选择所要运维协议
		self.resource.select_all_agreement()
		#windows域名
		if data[8] != 'no':
			self.set_domain_name(data[8])
		#账号分类
		if data[9] != 'no':
			self.resource.click_account_sync()
			self.select_account_type(data[9])
		#归属域控主机
		if data[10] != 'no':
			self.select_attach_domian(data[10])
		#主机名称
		if data[11] != 'no':
			self.set_host_name(data[11])
		#管理员帐号
		if data[12] != 'no':
			if data[9] == 'no':
				self.resource.click_account_sync()
			self.resource.set_admin_account(data[12])
		#管理员帐号
		if data[16] != 'no':
			self.resource.click_account_sync()
			self.select_account_protocol(data[16])
			self.set_port(data[17])
			if data[16] == "Ldap":
				self.set_ldap_account(data[18])
			else:
				self.set_ssh_account(data[18])
		#管理员口令
		if data[13] != 'no':
			self.resource.set_admin_pwd(data[13])
		#口令确认
		if data[14] != 'no':
			self.resource.set_confirm_pwd(data[14])
		#BaseDN
		if data[15] != 'no':
			self.set_base_dn(data[15])
		self.resource.click_save_button()

	u'''校验windows资源
	   Parameters:
	      - datarow:excel数据位于第几行
	      - data:excel中的一行数据
	'''
	def check_windows_resource(self, datarow, data):
		self.frameElem.from_frame_to_otherFrame("mainFrame")
		#资源名称
		self.resource.set_resource_name(data[2])
		#资源ip
		self.resource.set_resource_ip(data[3])
		#协议类型
		if data[4] != 'no':
			self.resource.select_agreement(data[4])
		#协议类型 端口
		if datarow == 7:
			self.resource.set_port(data[4], data[5])
		if datarow == 8:
			self.resource.clear_port("Vnc")
		if datarow == 9:
			self.resource.set_port("Vnc", data[5])
		if datarow == 12:
			self.resource.click_account_sync()
			self.select_account_type(data[6])
		if datarow == 13:
			self.select_attach_domian(data[7])
		self.resource.click_save_button()

	u'''填写windows域名
	   parameter:
	       - domainname:windows域名
	'''
	def set_domain_name(self, domainname):
		try:
			doname = self.cnEn.is_float(domainname)
			self.frameElem.from_frame_to_otherFrame("mainFrame")
			self.getElem.find_element_wait_and_clear('id', "fortDomainName")
			self.getElem.find_element_wait_and_sendkeys('id', "fortDomainName", doname)
		except Exception as e:
			print "domainname is error :" + str(e)

	u'''选择账号分类
	   Parameters:
	      - value:value属性
	'''
	def select_account_type(self, value):
		type = self.cnEn.is_float(value)
		self.frameElem.from_frame_to_otherFrame("mainFrame")
		selectelem = self.getElem.find_element_with_wait_EC("id", "selectDisplay")
		self.selectElem.select_element_by_value(selectelem, type)

	u'''选择归属域控主机
	   parameter:
	       - text:归属域控主机的名称
	'''
	def select_attach_domian(self, text):
		try:
			domiantext = self.cnEn.is_float(text)
			self.frameElem.from_frame_to_otherFrame("mainFrame")
			selectelem = self.getElem.find_element_with_wait_EC('id', "window_select_dc")
			self.selectElem.select_element_by_visible_text(selectelem, domiantext)
		except Exception as e:
			print "Domian select error:" + str(e)

	u'''填写主机名称
	   parameter:
	       - hostname:主机名称
	'''
	def set_host_name(self, hostname):
		try:
			host = self.cnEn.is_float(hostname)
			self.frameElem.from_frame_to_otherFrame("mainFrame")
			self.getElem.find_element_wait_and_clear('id', "window_host_name")
			self.getElem.find_element_wait_and_sendkeys('id', "window_host_name", host)
		except Exception as e:
			print "window_host_name is error :" + str(e)

	u'''填写Base DN
	   parameter:
	       - basedn:Base DN名称
	'''
	def set_base_dn(self, basedn):
		try:
			base = self.cnEn.is_float(basedn)
			self.frameElem.from_frame_to_otherFrame("mainFrame")
			self.getElem.find_element_wait_and_clear('id', "fortBaseDn")
			self.getElem.find_element_wait_and_sendkeys('id', "fortBaseDn", base)
		except Exception as e:
			print "fortBaseDn is error :" + str(e)

	u'''填写连接端口
	   parameter:
	       - portname:连接端口名称
	'''
	def set_port(self, portname):
		try:
			port = self.cnEn.is_float(portname)
			self.frameElem.from_frame_to_otherFrame("mainFrame")
			self.getElem.find_element_wait_and_clear('id', "fortConnectionPort")
			self.getElem.find_element_wait_and_sendkeys('id', "fortConnectionPort", port)
		except Exception as e:
			print "port is error :" + str(e)

	u'''填写ldap账号
	   parameter:
	       - actname:管理员账号
	'''
	def set_ldap_account(self, actname):
		try:
			act = self.cnEn.is_float(actname)
			self.frameElem.from_frame_to_otherFrame("mainFrame")
			self.getElem.find_element_wait_and_clear('id', "fortAdminAccount_ldap")
			self.getElem.find_element_wait_and_sendkeys('id', "fortAdminAccount_ldap", act)
		except Exception as e:
			print "name is error :" + str(e)

	u'''填写ssh账号
	   parameter:
	       - actname:管理员账号
	'''
	def set_ssh_account(self, actname):
		try:
			act = self.cnEn.is_float(actname)
			self.frameElem.from_frame_to_otherFrame("mainFrame")
			self.getElem.find_element_wait_and_clear('id', "fortAdminAccount_ssh")
			self.getElem.find_element_wait_and_sendkeys('id', "fortAdminAccount_ssh", act)
		except Exception as e:
			print "name is error :" + str(e)

	u'''选择账号同步连接协议
	   parameter:
	       - proname:同步
	'''
	def select_account_protocol(self, proname):
		try:
			pro = self.cnEn.is_float(proname)
			self.frameElem.from_frame_to_otherFrame("mainFrame")
			selem = self.getElem.find_element_with_wait_EC('id', "fortConnectionProtocol")
			self.selectElem.select_element_by_visible_text(selem, pro)
		except Exception as e:
			print " protocol is error :" + str(e)

	u'''是否勾选获取所有账号'''
	def check_all_account(self):
		try:
			self.frameElem.from_frame_to_otherFrame("mainFrame")
			self.getElem.find_element_wait_and_click_EC('id', "get_all_accounts")
		except Exception as e:
			print " Check failure :" + str(e)