def verifyyoption(c): # only letters, blank space and underscore are accepted # other chars are verified # no more than 48 char # leading spaces and tailing spaces are removed in the alias # length subsys alias = 48 chars # length controller alias = 48 chars # length array,ld alias =32 cahrs result1 = "" result2 = "" FailFlag = False ipv4, ipv6 = getnetinfo(c) if "Enabled" in ipv6["ProtocolFamily"]: result1 = SendCmd(c, "net -a disable -f ipv6 -y") else: SendCmd(c, "net -a enable -f ipv6") result2 = SendCmd(c, "net -a disable -f ipv6 -y") SendCmd(c, "net -a enable -f ipv6") result3 = SendCmd(c, "net -a mod -f ipv6 -y -s \"primaryip=2017::12\"") if not ("" in result1 and "" in result2 and "" in result3): FailFlag = True tolog(Failprompt + "sending cmd with -y option.") if FailFlag: tolog('Modify subsys alias fail') tolog(Fail) else: tolog('Modify subsys alias pass') tolog(Pass)
def verifyMaintenancemode(c): # net -m # net -a mod -m -c 1 -f ipv6 -s "primaryip=2001::1" # net -a mod -m -c 1 -s "primaryip=10.84.2.145,wol=enable" # net -a enable -m -c 1 -f ipv6 # net -m FailFlag = False origMresult = SendCmd(c, "net -m") ipv4, ipv6 = getnetMinfo(c) if ipv6['IP'] == "2001::1": ip = "2001::2" else: ip = "2001::1" cmd = "net -a mod -m -c 1 -f ipv6 -s \"primaryip=" + ip + "\"" result = SendCmd(c, cmd) if "Error" in result: FailFlag = True newMresult = SendCmd(c, "net -m") if ip not in newMresult: FailFlag = True tolog(Failprompt + "changing to maintenance ip addresd " + ip) if FailFlag: tolog('Verify modifing maintenance mode ip address failed') tolog(Fail) else: tolog('Verify modifing maintenance mode ip address passed') tolog(Pass)
def SendCmd(c, cmdstr): data = '' if cmdstr.endswith('\n'): c.send(cmdstr) else: c.send(cmdstr + '\n') # time.sleep(1) while not c.exit_status_ready(): if c.recv_ready(): # removig the following chars to avoid # <Fault -32700: 'parse error. not well formed'> when # updating to testlink data += c.recv(2000) if data.endswith('@cli> '): break # time.sleep(2) # removig the following chars to avoid # <Fault -32700: 'parse error. not well formed'> when # updating to testlink while c.recv_ready(): data += c.recv(2000) if data.endswith('@cli> '): break # data += c.recv(9999) data = data.replace("\x1b[D \x1b[D", "") tolog(data) return data
def getSubsysVinfo(c): result = "" tolog("Get Subsystem model name:") result = SendCmd(c, "subsys -v") modelNameValue = (result.split("\\n")[1]).replace( "Vendor: Promise Technology,Inc. Model: ", "") return modelNameValue
def get_ftp(): # test data response = [ 'enable', 'encrypt_type', 'port', 'passive_start', 'passive_end', 'charset', 'dw_rate', 'up_rate' ] tolog('Expect: \r\n' + str(response) + '\r\n') result = server.webapi('get', 'protocol/ftp') if isinstance(result, str): result_assert.FailFlag = True tolog('Fail: ' + result + '\r\n') else: check = json.loads(result["text"])[0] tolog('Actual: \r\n' + str(check.keys()).replace('u', '') + '\r\n') if len(response) != len(check.keys()): result_assert.FailFlag = True tolog('Fail: please check out response parameters count\r\n') else: for key in check.keys(): if key not in response: result_assert.FailFlag = True tolog('Fail: ' + key + ' is not in response\r\n') result_assert.result_assert()
def result_assert(self): if self.FailFlag: tolog(Fail) self.FailFlag = False else: tolog(Pass)
def get_protocol_running_status(): # test data response = ['name', 'status'] tolog('Expect: \r\n' + str(response) + '\r\n') result = server.webapi('get', 'protocol/status') if isinstance(result, str): result_assert.FailFlag = True tolog('Fail: ' + result + '\r\n') else: check = json.loads(result["text"])[0] tolog('Actual: \r\n' + str(check.keys()).replace('u', '') + '\r\n') if len(response) != len(check.keys()): result_assert.FailFlag = True tolog('Fail: please check out response parameters count\r\n') else: for key in check.keys(): if key not in response: result_assert.FailFlag = True tolog('Fail: ' + key + ' is not in response\r\n') result_assert.result_assert()
def userverify(c,userinfo): FailFlag = False briefoutput=(SendCmd(c,"user"),SendCmd(c,"user -a list"),SendCmd(c,"user -a list -u "+userinfo["username"])) for op in briefoutput: for key,value in userinfo.items(): if value[:10] not in op: tolog("%s created unsucessfully beause %s is not in the list" % userinfo["username"] % value[:10]) FailFlag = True break verboseoutput=(SendCmd(c,"user -v"),SendCmd(c,"user -v -a list"),SendCmd(c,"user -v -u "+userinfo["username"])) for op in verboseoutput: for key,value in userinfo.items(): if value not in op: tolog("%s created unsucessfully beause %s is not in the list" % userinfo["username"] % value) FailFlag = True break if FailFlag: tolog(Fail) else: tolog("User is created successully.") tolog(Pass)
def get_protocol_status_on_storage(): # precondition precondition() # test data response = ['ftp', 'nfs', 'smb', 'tm_enable', 'allow_ip'] tolog('Expect: \r\n' + str(response) + '\r\n') result = server.webapi('get', 'protocol/storage/nasshare_0') if isinstance(result, str): result_assert.FailFlag = True tolog('Fail: ' + result + '\r\n') else: check = json.loads(result["text"])[0] tolog('Actual: \r\n' + str(check.keys()).replace('u', '') + '\r\n') if len(response) != len(check.keys()): result_assert.FailFlag = True tolog('Fail: please check out response parameters count\r\n') else: for key in check.keys(): if key not in response: result_assert.FailFlag = True tolog('Fail: ' + key + ' is not in response\r\n') result_assert.result_assert()
def click_action(self, locator, path, location='', response_time=3): try: self.driver.find_element(locator, path).click() time.sleep(response_time) except: tolog('to click ' + location + ' is failed\r\n')
def bvt_verifyChapList(c): FailFlag = False tolog("<b>Verify chap -a list</b>") c, ssh = ssh_conn() chapId = findChapId(c) if len(chapId) != 0: result = SendCmd(c, 'chap -a list') if "Error (" in result or 'ChapId:' not in result or 'Name:' not in result: FailFlag = True tolog('\n<font color="red">Fail: chap -a list</font>') tolog('<b>Verify chap -a list -i chap id</b>') for i in chapId: result = SendCmd(c, 'chap -a list -i ' + i) if 'ChapId:' not in result or 'Name:' not in result or i not in result: FailFlag = True tolog('\n<font color="red">Fail: chap -a list -i ' + i + '</font>') else: result = SendCmd(c, 'chap -a list') if 'CHAP record not found' not in result: FailFlag = True tolog('\n<font color="red">Fail: chap -a list</font>') # c.close() # ssh.close() time.sleep(3) return FailFlag
def response_test(self, url_parameters, cases_file, sheet_name): # Open cases file # data = xlrd.open_workbook('/home/work/zach/clitest/' + data_file_name) data = xlrd.open_workbook(cases_file) table = data.sheet_by_name(sheet_name) # data for verification parameters = [table.cell(0, i).value for i in range(table.ncols)] tolog('Expected: ' + str(parameters) + '\n') result = server.webapi('get', url_parameters) # Verify expected results and actual results if str(result['response']) != '<Response [200]>': self.flag = True tolog('Fail: ' + str(result['text'])) else: response_info = json.loads(result['text']) get_r = str(response_info).replace('},', '\n').replace( '[', '\n').replace(']', '').replace('{', '').replace('}', '') tolog('Actual: ' + get_r + '\n') if self.flag: tolog(Fail) else: tolog(Pass)
def get_ds_group(): # test id = 'users' response = ['id', 'gid', 'description', 'group_member'] tolog('Expect: \r\n' + str(response) + '\r\n') result = server.webapi('get', 'dsgroup/' + id) if isinstance(result, str): result_assert.FailFlag = True tolog('Fail: ' + result + '\r\n') else: check = json.loads(result["text"])[0] tolog('Actual: \r\n' + str(check.keys()).replace('u', '') + '\r\n') if len(response) != len(check.keys()): result_assert.FailFlag = True tolog('Fail: please check out response parameters count\r\n') for p in check.keys(): if p not in response: result_assert.FailFlag = True tolog('Fail: please check out response parameter: ' + p + '\r\n') result_assert.result_assert()
def SendCmdRestart(c, cmdstr): data = '' if cmdstr.endswith('\n'): c.send(cmdstr) else: c.send(cmdstr + '\n') # time.sleep(1) while not c.exit_status_ready(): #while a[1].get_transport().is_active(): a = check_ping() if a == 0: if c.recv_ready(): # removig the following chars to avoid # <Fault -32700: 'parse error. not well formed'> when # updating to testlink data += c.recv(2000) # add code for password in user # print data # data=data.replace("[32D[32C[0m[?12l[?25h","").replace("[?1l[6n[?2004h[?25l[?7l[0m[0m[J[0m","") #print data while data.endswith('?25h'): # print data c.send("Local#123" + "\n") data += c.recv(2000) if data.endswith('@cli> '): break if data.endswith('@cli> '): break else: tolog("Network connection lost.") break # time.sleep(2) # removig the following chars to avoid # <Fault -32700: 'parse error. not well formed'> when # updating to testlink while c.recv_ready(): data += c.recv(2000) if data.endswith('@cli> '): break # if data.endswith('?25h'): # c.send("Local#123"+"\n") # data += c.recv(9999) data = data.replace("\x1b[D \x1b[D", "") data = data.replace( "[?1l[6n[?2004h[?25l[?7l[0m[0m[J[0m", "" ).replace("[32D[32C[0m[?12l[?25h", "").replace( "[?7h[0m[?12l[?25h[?2004l[?1l[6n[?2004h[?25l[?7l[0m[0m[J[0m", "") tolog(data) return data
def test_iscsi_portal_view(self): ValError = [] Failflag = False portal_dict = {} self.driver = loginFirefox() self.verificationErrors = [] self.accept_next_alert = True driver = self.driver driver.find_element_by_link_text("Device").click() time.sleep(2) driver.find_element_by_link_text("iSCSI Management").click() time.sleep(1) driver.find_element_by_link_text("Portal").click() time.sleep(2) if "No iSCSI Portal detected." in driver.find_element_by_xpath("//table/tbody").text: tolog("No iSCSI Portal entry was detected") tolog(Pass) else: temp = driver.find_element_by_xpath("//table/tbody").text.split("\n") for p in temp: portal_dict[str(p).split()[0]] = str(p).split()[2:6] if portal_dict: tolog("Portal list is: "+ str(portal_dict)) ValError.append("pass") else: ValError.append("fail") for val in ValError: if val == "fail": Failflag = True if Failflag: tolog(Fail) else: tolog(Pass) return portal_dict
def fill_action(self, locator, path, value, location=''): try: self.driver.find_element(locator, path).clear() self.driver.find_element(locator, path).send_keys(value) time.sleep(1) except: tolog('to fill out ' + location + ' is failed\r\n')
def Iscsisetnode(id): Failflag = False tolog("Set iscsinode info by api") urlpara = str(id) bodypara={"alias":"test","header_digest":1,"data_digest":1,"bi_chap_auth":0,"uni_chap_auth":0,"assn_portal_ids":"1,2"} res = server.webapiurlbody("put", "iscsinode", urlparameter=urlpara,body=bodypara) Iscsinodegetbyidinfo(id)
def Bgascheduleinfo(): Failflag = False tolog("Verify Bgaschedule list info by api") bgascheduleres=server.webapi("get","bgaschedule") bgascheduleview = json.loads(bgascheduleres["text"]) for bgaschedule in bgascheduleview: tolog(str(bgaschedule)) return Failflag
def add_group_and_users_by_must_parameters(): # precondition server.webapi('post', 'dsgroup/editcancel') tolog('Expect: add group "by_must_parameters" and add 10 user\r\n') step1 = server.webapi('post', 'dsgroup/editbegin', { "page": 1, "page_size": 20 }) if isinstance(step1, str): result_assert.FailFlag = True tolog("Fail: " + step1 + '\r\n') else: # test data token = json.loads(step1["text"])[0]["token"] get_page_data = json.loads(step1["text"])[0]["page_data"] page_data = [[1, uid["uid"]] for uid in get_page_data[1:]] step2 = server.webapi('post', 'dsgroup/editnext', { "token": token, "page_data": page_data, "page": 1, "page_size": 20 }) if isinstance(step2, str): result_assert.FailFlag = True tolog("Fail: " + step2 + '\r\n') else: step3 = server.webapi('post', 'dsgroup/editsave', { "id": 'by_must_parameters', "token": token, "page_data": page_data }) if isinstance(step3, str): result_assert.FailFlag = True tolog("Fail: " + step3 + '\r\n') else: check = server.webapi('get', 'dsgroup/by_must_parameters') checkResult = json.loads(check["text"])[0] tolog('Actual: ' + json.dumps(checkResult) + '\r\n') result_assert.result_assert()
def createobj(obj,setting): Failflag=False createres = server.webapiurlbody("post", obj, body=setting) if createres["text"] != "": tolog("Creating %s with %s failed" % (obj,str(setting))) Failflag = True else: tolog("Creating %s with %s successfully" % (obj, str(setting))) return Failflag
def invalid_group_name(): # test data name = ['', 't' * 31, 1] for n in name: # precondition: cancel edit server.webapi('post', 'dsgroup/editcancel') tolog('Expect: that will hint error when group name is ' + str(n) + '\r\n') step1 = server.webapi('post', 'dsgroup/editbegin', { "page": 1, "page_size": 20 }) if isinstance(step1, str): result_assert.FailFlag = True tolog("Fail: " + step1 + '\r\n') else: # test data token = json.loads(step1["text"])[0]["token"] get_page_data = json.loads(step1["text"])[0]["page_data"] page_data = [[0, uid["uid"]] for uid in get_page_data] step2 = server.webapi('post', 'dsgroup/editnext', { "page": 1, "page_size": 20, "token": token, "page_data": page_data }) if isinstance(step2, str): result_assert.FailFlag = True tolog("Fail: " + step2 + '\r\n') else: step3 = server.webapi('post', 'dsgroup/editsave', { "id": n, "token": token, "page_data": page_data }) if isinstance(step3, dict): result_assert.FailFlag = True tolog("Fail: group name can be specified " + str(n) + '\r\n') else: tolog('Actual: ' + step3 + '\r\n') result_assert.result_assert()
def deleteobj(obj,objid): Failflag = False urlpara=str(objid)+"?force=1" res = server.webapiurlbody("delete", obj, urlparameter=urlpara) if res["text"] != "": tolog("Deleting %s %s failed" % (obj,str(objid))) Failflag = True else: tolog("Deleting %s %s successfully" % (obj, str(objid))) return Failflag
def VerifyWords(driver, wordlist): ValidationError = False # time.sleep(1) for each in wordlist: time.sleep(0.5) if re.search(each, driver.find_element_by_css_selector("BODY").text): tolog(each + ' is verified.') else: tolog(each + ' is not verified.') ValidationError = True return ValidationError
def Batteryrecondition(batteryid): Failflag = False tolog("Verify battery recondition by api") urlpara = str(batteryid) batteryreconditionres = server.webapiurl("post", "batteryrecondition", urlpara) if batteryreconditionres["text"] != "": Failflag = True tolog("Failed on recondiction battery %s,error is %s" % (urlpara, batteryreconditionres["text"])) return Failflag
def test_iscsi_portal_mod(self): ValError = [] Failflag = False self.driver = loginFirefox() self.verificationErrors = [] self.accept_next_alert = True driver = self.driver driver.find_element_by_link_text("Device").click() time.sleep(2) driver.find_element_by_link_text("iSCSI Management").click() time.sleep(2) driver.find_element_by_link_text("Portal").click() time.sleep(2) if "No iSCSI Portal detected." in driver.find_element_by_xpath("//table/tbody").text: ValError.append("pass") tolog("No iSCSI Portal detected") else: if driver.find_element_by_xpath("//table/tbody/tr[2]/td[1]/input").is_enabled(): driver.find_element_by_xpath("//table/tbody/tr[2]/td[1]/input").click() time.sleep(0.5) driver.find_element_by_xpath("//button[@title='Modify iSCSI Portal Settings']").click() time.sleep(2) TCP_Port_number = random.randint(0, 65535) driver.find_element_by_name("tcpportnumber").clear() time.sleep(0.5) driver.find_element_by_name("tcpportnumber").send_keys(TCP_Port_number) time.sleep(0.5) IP_Type = random.choice(["IPv4", "IPv6"]) Select(driver.find_element_by_name("ip_type")).select_by_visible_text(IP_Type) time.sleep(1) if not driver.find_element_by_xpath("//form/div[7]/div[1]/label/input").is_selected(): driver.find_element_by_xpath("//form/div[7]/div[1]/label/input").click() time.sleep(0.5) driver.find_element_by_xpath("//button[@type='submit']").click() time.sleep(1) for k in range(20): if "iSCSI portal settings were changed successfully." in driver.find_element_by_xpath( "//body/div/div/div[5]/div/div").text: ValError.append("pass") tolog("iSCSI portal settings were changed successfully.") break if "Failed to change iSCSI portal settings" in driver.find_element_by_xpath("//body/div/div/div[5]/div/div").text: ValError.append("fail") tolog(driver.find_element_by_xpath("//body/div/div/div[5]/div/div/span").text) break for val in ValError: if val == "fail": Failflag = True if Failflag: tolog(Fail) else: tolog(Pass)
def VerifyTurnonBuzzerDisabled(c): checkResult = '' result = tuple() SendCmd(c, 'buzz -a disable') tolog("Turn on buzzer: ") result = SendCmd(c, 'buzz -a on') verifyBuzzerInfo(c) if 'Error' in result and 'Buzzer is disabled' in result: tolog('Check turn on buzzer when it is disabled pass') tolog(Pass) else: tolog('Check turn on buzzer when it is disabled fail') tolog(Fail)
def modify_ds_group(): # test data id = 'a' setting = {"desc": 'this is the test for group description'} tolog('Expect: ' + json.dumps(setting) + '\r\n') result = server.webapi('put', 'dsgroup/' + id, setting) if isinstance(result, str): result_assert.FailFlag = True tolog('Fail: ' + result + '\r\n') else: check = server.webapi('get', 'dsgroup/' + id) checkResult = json.loads(check["text"])[0] if setting["desc"] not in checkResult["description"]: result_assert.FailFlag = True tolog('Fail: please check description of group' + id + '\r\n') else: tolog('Actual: ' + json.dumps(checkResult) + '\r\n') result_assert.result_assert()
def test_iscsi_logged_in_device_view(self): ValError = [] Failflag = False portal_dict = {} self.driver = loginFirefox() self.verificationErrors = [] self.accept_next_alert = True driver = self.driver driver.find_element_by_link_text("Device").click() time.sleep(2) driver.find_element_by_link_text("iSCSI Management").click() time.sleep(1) driver.find_element_by_xpath("//ul/li[9]/ul/li[8]/a").click() time.sleep(2) if "No iSCSI Initiator detected." in driver.find_element_by_xpath( "//table/tbody").text: tolog("No logged in device was detected") ValError.append("pass") else: temp = driver.find_element_by_xpath("//table/tbody").text.split( "\n") for i in temp: if i != "": tolog(i) ValError.append("pass") else: ValError.append("fail") for err in ValError: if err == "fail": Failflag = True break if Failflag: tolog(Fail) else: tolog(Pass)
def test_iscsi_isns_view(self): ValError = [] Failflag = False self.driver = loginFirefox() self.verificationErrors = [] self.accept_next_alert = True driver = self.driver driver.find_element_by_link_text("Device").click() time.sleep(3) driver.find_element_by_link_text("iSCSI Management").click() time.sleep(2) driver.find_element_by_link_text("iSNS").click() time.sleep(2) tolog("Start to List iSCSI iSNS entrys") for line in driver.find_element_by_xpath("//table/tbody").text.split( "\n"): if line == "": ValError.append("fail") else: tolog(line) ValError.append("pass") for val in ValError: if val == "fail": Failflag = True if Failflag: tolog(Fail) else: tolog(Pass)
def test_iscsi_chap_del(self): ValError = [] Failflag = False self.driver = loginFirefox() self.verificationErrors = [] self.accept_next_alert = True driver = self.driver driver.find_element_by_link_text("Device").click() time.sleep(3) driver.find_element_by_link_text("iSCSI Management").click() time.sleep(2) driver.find_element_by_xpath("//li[9]/ul/li[7]/a").click() time.sleep(2) tolog("Start to delete ALL iSCSI CHAP entrys") if "No iSCSI CHAP detected" in driver.find_element_by_xpath( "//table/tbody").text: chap_count = 0 ValError.append("pass") else: chap_count = len( driver.find_element_by_xpath("//table/tbody").text.split("\n")) while chap_count > 0: driver.find_element_by_xpath("//b").click() time.sleep(1) driver.find_element_by_link_text("Delete").click() time.sleep(1) driver.find_element_by_name("name").clear() time.sleep(1) driver.find_element_by_name("name").send_keys("confirm") time.sleep(1) driver.find_element_by_xpath( "//button[@type='submit']").click() chap_count -= 1 time.sleep(3) if "No iSCSI CHAP detected" in str( driver.find_element_by_xpath("//table/tbody").text.split( "\n")): tolog("All iSCSI CHAP entrys were deleted!") ValError.append("pass") else: Failflag = True tolog("Failed to delete All iSCSI CHAP entry!") ValError.append("fail") for val in ValError: if val == "fail": Failflag = True if Failflag: tolog(Fail) else: tolog(Pass)