def extBGAset(): Failflag=False origsetting=dict() origsetting=BGAinfo() tolog(str(origsetting)) body={"rebuild_rate":"Medium","rc_rate":"High"} server.webapi("post","bga",body) modifiedsetting=BGAinfo() tolog(str(modifiedsetting)) if modifiedsetting["rebuild_rate"]==body["rebuild_rate"] and modifiedsetting["rc_rate"]==body["rc_rate"]: tolog("BGA setting updated sucessfully.") else: tolog("BGA setting updated failed.") Failflag=True return Failflag
def ReadCacheinfo(): res=server.webapi("get","rcache") view = json.loads(res["text"]) return view
def WriteCacheinfo(): res=server.webapi("get","wcache") view = json.loads(res["text"]) return view
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 BGAinfo(): Failflag = False bgares=server.webapi("get","bga") bgaview = json.loads(bgares["text"]) bgasetting=dict() for bga in bgaview: bgasetting["rebuild_rate"]=bga["rebuild_rate"] bgasetting["rc_rate"]=bga["rc_rate"] return bgasetting
def Buzzerinfo(): Failflag = False tolog("Verify buzzer info by api") buzzerres = server.webapi("get", "buzzer") buzzerview = json.loads(buzzerres["text"]) for buzzer in buzzerview: if buzzer: tolog(str(buzzer)) else: Failflag = True return buzzer, Failflag
def Batteryinfo(): Failflag = False batteryres = server.webapi("get", "battery") batteryview = json.loads(batteryres["text"]) for battery in batteryview: if battery['id'] != "": tolog("Verify the battery info by api") tolog(str(battery)) Failflag = Batteryrecondition(battery['id']) else: Failflag = True if Failflag: tolog(Fail) else: tolog(Pass)
def BuzzerDisable(): Failflag = False tolog("Verify buzzer enable by api") body = {"enable": 0} res = server.webapi("post", "buzzer", body) #resview = json.loads(res["text"]) buzzer, Failflag = Buzzerinfo() if buzzer["enabled"] == 0: tolog("Buzzer enable sucessfully.") else: Failflag = True tolog("Buzzer enable failed.") if Failflag: tolog(Fail) else: tolog(Pass)
def Phydrvgetinfo(): Failflag=False tolog("Get Phydrv info by api") res = server.webapi("get", "phydrv") # pdlist = list() cleanrestext = json.loads(res["text"]) # for eachpd in cleanrestext: # # if eachpd["op_status"] == "OK" and eachpd["cfg_status"] == "Unconfigured" and eachpd["type"] == "SAS HDD": # pdlist.append(eachpd["id"]) # if "200" not in str(res["response"]): Failflag=True tolog(str(cleanrestext)) if Failflag: tolog(Fail) else: tolog(Pass)
def CloneCreateListModifyDelete(sourceid): Failflag = False name = random_key(10) volumelistview = server.webapiurlbody("get", "volume") volumeview = json.loads(volumelistview["text"]) # create snapshot for each volume type=random.choice({"volume","filesystem"}) # do not support filesysrtem # as to 2017-5-15 type="volume" parameters=dict() parameters = { "name": name, "source_id": sourceid,"type":type} volumecreateres = server.webapiurlbody("post", "snapshot", body=parameters) if volumecreateres["text"] != "": tolog("Creating snapshot %s failed" % name) Failflag = True else: tolog("Creating snapshot %s successfully" % name) snapshotlistview = server.webapi("get", "snapshot") # server.webapiurl("delete", "pool", "0?force=0") snapshotview = json.loads(snapshotlistview["text"]) volumeid = "" for snapshot in snapshotview: if snapshot["name"] == name: snapshotid = str(snapshot["id"]) if snapshot["type"] != type or snapshot["source_id"] != sourceid: tolog("Verifying the created snapshot %s failed" % name) Failflag = True else: tolog("Verifying the created snapshot %s sucessfully by api view." % name) if snapshot["status"]=="Exported": tolog("Verifying snapshot unexport") urlpara=snapshotid+"/unexport" unexportres=server.webapiurlbody("post","snapshot",urlparameter=urlpara) #unexportres = json.loads(unexportres["text"]) if unexportres["text"]!="": tolog("Verifying snapshot unexport failed.") Failflag=True else: tolog("Verifying volume unexport successfully.") elif snapshot["status"]=="Un-exported": tolog("Verifying snapshot export") urlpara = snapshotid + "/export" exportres = server.webapiurlbody("post", "snapshot", urlparameter=urlpara) # unexportres = json.loads(unexportres["text"]) if exportres["text"] != "": tolog("Verifying snapshot export failed.") Failflag = True if snapshot["status"]=="Un-exported": tolog("Verifying snapshot export") urlpara=volumeid+"/export" unexportres=server.webapiurlbody("post","snapshot",urlparameter=urlpara) #unexportres = json.loads(unexportres["text"]) if unexportres["text"]!="": tolog("Verifying snapshot export failed.") Failflag=True else: tolog("Verifying snapshot export successfully.") elif snapshot["status"]=="Exported": tolog("Verifying snapshot unexport") urlpara = snapshotid + "/unexport" exportres = server.webapiurlbody("post", "snapshot", urlparameter=urlpara) # unexportres = json.loads(unexportres["text"]) if exportres["text"] != "": tolog("Verifying snapshot unexport failed.") Failflag = True if snapshot["status"]=="Exported": tolog("Verifying snapshot unexport") urlpara=snapshotid+"/unexport" unexportres=server.webapiurlbody("post","snapshot",urlparameter=urlpara) #unexportres = json.loads(unexportres["text"]) if unexportres["text"]!="": tolog("Verifying snapshot unexport failed.") Failflag=True else: tolog("Verifying volume unexport successfully.") elif snapshot["status"]=="Un-exported": tolog("Verifying snapshot export") urlpara = snapshotid + "/export" exportres = server.webapiurlbody("post", "snapshot", urlparameter=urlpara) # unexportres = json.loads(unexportres["text"]) if exportres["text"] != "": tolog("Verifying snapshot export failed.") Failflag = True if snapshot["status"]=="Un-exported": tolog("Verifying snapshot export") urlpara=volumeid+"/export" unexportres=server.webapiurlbody("post","snapshot",urlparameter=urlpara) #unexportres = json.loads(unexportres["text"]) if unexportres["text"]!="": tolog("Verifying snapshot export failed.") Failflag=True else: tolog("Verifying snapshot export successfully.") elif snapshot["status"]=="Exported": tolog("Verifying snapshot unexport") urlpara = snapshotid + "/unexport" exportres = server.webapiurlbody("post", "snapshot", urlparameter=urlpara) # unexportres = json.loads(unexportres["text"]) if exportres["text"] != "": tolog("Verifying snapshot unexport failed.") Failflag = True newname = {"name": random_key(20)} tolog("Verifying modify the snapshot name from %s to %sby api view." %(name,newname)) urlpara =snapshotid renameres = server.webapiurlbody("put", "snapshot", urlparameter=urlpara) if renameres["text"] != "": Failflag = True tolog("snapshot rename failed by api") else: # To be added 2017-5-15 # Body Parameters # # Body paramemters urlpara=snapshotid renameres=server.webapiurlbody("get","snapshot",urlparameter=urlpara) renameres=json.loads(renameres) if renameres["name"]!=newname: Failflag = True tolog("snapshot rename failed by api") else: tolog("snapshot rename successfully by api") tolog("Verifying snapshot delete.") urlparameter = snapshotid + "?force=1" deleteres = server.webapiurlbody("delete", "snapshot", urlparameter=urlparameter) if deleteres["text"] != "": Failflag = True tolog("snapshot delete failed by api delete.") else: tolog("snapshot delete sucessfully by api delete.") if Failflag: tolog(Fail) else: tolog(Pass)
def Dateinfo(): res = server.webapi("get", "date") view = json.loads(res["text"]) return view