diff --git a/tools/marvin/marvin/cloudstackConnection.py b/tools/marvin/marvin/cloudstackConnection.py index d006002ae0f..caa8609e14a 100644 --- a/tools/marvin/marvin/cloudstackConnection.py +++ b/tools/marvin/marvin/cloudstackConnection.py @@ -149,7 +149,7 @@ class CSConnection(object): [str.lower(r[0]), str.lower( urllib.quote_plus(str(r[1])) - ).replace("+", "%20")] + ).replace("+", "%20")] ) for r in params] ) signature = base64.encodestring(hmac.new( diff --git a/tools/marvin/marvin/codegenerator.py b/tools/marvin/marvin/codegenerator.py index 1e02ddfb379..e5015c6dfd7 100644 --- a/tools/marvin/marvin/codegenerator.py +++ b/tools/marvin/marvin/codegenerator.py @@ -343,7 +343,7 @@ class CodeGenerator(object): paramProperty.desc = response['description'] if 'type' in response: if response['type'] in ['list', 'map', 'set']: - # Here list becomes a subproperty + # Here list becomes a subproperty if 'response' in response: for innerResponse in response['response']: subProperty =\ @@ -359,9 +359,9 @@ class CodeGenerator(object): jsonOut = apiStream.readlines() assert len(jsonOut) > 0 apiDict = json.loads(jsonOut[0]) - if not 'listapisresponse' in apiDict: + if 'listapisresponse' not in apiDict: raise Exception("API discovery plugin response failed") - if not 'count' in apiDict['listapisresponse']: + if 'count' not in apiDict['listapisresponse']: raise Exception("Malformed api response") apilist = apiDict['listapisresponse']['api'] @@ -397,7 +397,8 @@ class CodeGenerator(object): csCmd.request.append(paramProperty) for response in cmd['response']: - # FIXME: ExtractImage related APIs return empty dicts in response + # FIXME: ExtractImage related APIs return empty dicts in + # response if len(response) > 0: paramProperty = self.constructResponseFromJSON(response) csCmd.response.append(paramProperty) @@ -412,11 +413,11 @@ class CodeGenerator(object): @return: The classes in cloudstackAPI/ formed from api discovery json """ if endpointUrl.find('response=json') >= 0: - apiStream = urllib2.urlopen(endpointUrl) - cmds = self.loadCmdFromJSON(apiStream) - for cmd in cmds: - self.generate(cmd) - self.finalize() + apiStream = urllib2.urlopen(endpointUrl) + cmds = self.loadCmdFromJSON(apiStream) + for cmd in cmds: + self.generate(cmd) + self.finalize() def getText(elements): diff --git a/tools/marvin/marvin/codes.py b/tools/marvin/marvin/codes.py index 28e907cbcd8..660193a1b4c 100644 --- a/tools/marvin/marvin/codes.py +++ b/tools/marvin/marvin/codes.py @@ -74,5 +74,5 @@ ADMIN = 1 DOMAIN_ADMIN = 2 USER = 0 XEN_SERVER = "XenServer" -ADMIN_ACCOUNT='ADMIN_ACCOUNT' -USER_ACCOUNT='USER_ACCOUNT' +ADMIN_ACCOUNT = 'ADMIN_ACCOUNT' +USER_ACCOUNT = 'USER_ACCOUNT' diff --git a/tools/marvin/marvin/configGenerator.py b/tools/marvin/marvin/configGenerator.py index 68ec24eb2bc..2a67bc13828 100644 --- a/tools/marvin/marvin/configGenerator.py +++ b/tools/marvin/marvin/configGenerator.py @@ -47,17 +47,20 @@ class dbServer(object): class configuration(object): + def __init__(self): self.name = None self.value = None class logger(object): + def __init__(self): self.LogFolderPath = None class cloudstackConfiguration(object): + def __init__(self): self.zones = [] self.mgtSvr = [] @@ -68,6 +71,7 @@ class cloudstackConfiguration(object): class zone(object): + def __init__(self): self.dns1 = None self.internaldns1 = None @@ -845,8 +849,8 @@ def descSetupInAdvancedsgMode(): memory = 8 * 1024 * 1024 * 1024 localstorage = 1 * 1024 * 1024 * 1024 * 1024 # h.url = "http://sim/%d%d%d%d/cpucore=1&cpuspeed=8000&\ - # memory=%d&localstorage=%d" % (l, i, j, k, memory, - # localstorage) + # memory=%d&localstorage=%d" % (l, i, j, k, memory, + # localstorage) h.url = "http://sim/%d%d%d%d" % (l, i, j, k) c.hosts.append(h) @@ -855,8 +859,6 @@ def descSetupInAdvancedsgMode(): primary = primaryStorage() primary.name = "primary" + \ str(l) + str(i) + str(j) + str(m) - # primary.url = "nfs://localhost/path%s/size=%d" % \ - #(str(l) + str(i) + str(j) + str(m), size) primary.url = "nfs://localhost/path%s" % \ (str(l) + str(i) + str(j) + str(m)) c.primaryStorages.append(primary) diff --git a/tools/marvin/marvin/deployAndRun.py b/tools/marvin/marvin/deployAndRun.py index d3b6b8606b0..9f392e5e5a3 100644 --- a/tools/marvin/marvin/deployAndRun.py +++ b/tools/marvin/marvin/deployAndRun.py @@ -97,8 +97,8 @@ def startMarvin(cfg_file, load_flag): print "\nMarvin Initialization Failed" exit(1) except Exception as e: - print "\n Exception occurred while starting Marvin %s" % str(e) - exit(1) + print "\n Exception occurred while starting Marvin %s" % str(e) + exit(1) def runTCs(num_iter, inp1, inp2): diff --git a/tools/marvin/marvin/lib/__init__.py b/tools/marvin/marvin/lib/__init__.py index 978b68af62a..13a83393a91 100644 --- a/tools/marvin/marvin/lib/__init__.py +++ b/tools/marvin/marvin/lib/__init__.py @@ -5,9 +5,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/tools/marvin/marvin/lib/base.py b/tools/marvin/marvin/lib/base.py index d75309877f4..c68b551cdb6 100644 --- a/tools/marvin/marvin/lib/base.py +++ b/tools/marvin/marvin/lib/base.py @@ -20,11 +20,10 @@ """ import marvin -from utils import is_server_ssh_ready, random_gen from marvin.cloudstackAPI import * from marvin.codes import FAILED, PASS from marvin.cloudstackException import GetDetailExceptionInfo -from marvin.lib.utils import validateList +from marvin.lib.utils import validateList, is_server_ssh_ready, random_gen # Import System modules import time import hashlib @@ -32,7 +31,9 @@ import base64 class Domain: + """ Domain Life Cycle """ + def __init__(self, items): self.__dict__.update(items) @@ -84,7 +85,9 @@ class Domain: class Account: + """ Account Life Cycle """ + def __init__(self, items): self.__dict__.update(items) @@ -102,16 +105,16 @@ class Account: cmd.password = services["password"] - username = "-".join([services["username"], random_gen(id=apiclient.id)]) + username = "-".join([services["username"], + random_gen(id=apiclient.id)]) # Trim username to 99 characters to prevent failure cmd.username = username[:99] if len(username) > 99 else username if "accountUUID" in services: - cmd.accountid = "-".join([services["accountUUID"],random_gen()]) + cmd.accountid = "-".join([services["accountUUID"], random_gen()]) if "userUUID" in services: - cmd.userid = "-".join([services["userUUID"],random_gen()]) - + cmd.userid = "-".join([services["userUUID"], random_gen()]) if domainid: cmd.domainid = domainid @@ -143,7 +146,9 @@ class Account: class User: + """ User Life Cycle """ + def __init__(self, items): self.__dict__.update(items) @@ -159,7 +164,7 @@ class User: cmd.lastname = services["lastname"] if "userUUID" in services: - cmd.userid = "-".join([services["userUUID"],random_gen()]) + cmd.userid = "-".join([services["userUUID"], random_gen()]) cmd.password = services["password"] cmd.username = "-".join([services["username"], random_gen()]) @@ -220,6 +225,7 @@ class User: class VirtualMachine: + """Manage virtual machine lifecycle""" def __init__(self, items, services): @@ -243,7 +249,8 @@ class VirtualMachine: @classmethod def ssh_access_group(cls, apiclient, cmd): """ - Programs the security group with SSH access before deploying virtualmachine + Programs the security group with SSH + access before deploying virtualmachine @return: """ zone_list = Zone.list( @@ -252,7 +259,7 @@ class VirtualMachine: domainid=cmd.domainid if cmd.domainid else None ) zone = zone_list[0] - #check if security groups settings is enabled for the zone + # check if security groups settings is enabled for the zone if zone.securitygroupsenabled: list_security_groups = SecurityGroup.list( apiclient, @@ -274,9 +281,11 @@ class VirtualMachine: "endport": 22, "cidrlist": "0.0.0.0/0" } - #Authorize security group for above ingress rule - basic_mode_security_group.authorize(apiclient, sec_grp_services, account=cmd.account, - domainid=cmd.domainid) + # Authorize security group for above ingress rule + basic_mode_security_group.authorize(apiclient, + sec_grp_services, + account=cmd.account, + domainid=cmd.domainid) else: basic_mode_security_group = list_security_groups[0] @@ -286,7 +295,8 @@ class VirtualMachine: cmd.securitygroupids = [basic_mode_security_group.id] @classmethod - def access_ssh_over_nat(cls, apiclient, services, virtual_machine, allow_egress=False): + def access_ssh_over_nat( + cls, apiclient, services, virtual_machine, allow_egress=False): """ Program NAT and PF rules to open up ssh access to deployed guest @return: @@ -324,11 +334,13 @@ class VirtualMachine: @classmethod def create(cls, apiclient, services, templateid=None, accountid=None, - domainid=None, zoneid=None, networkids=None, serviceofferingid=None, - securitygroupids=None, projectid=None, startvm=None, - diskofferingid=None, affinitygroupnames=None, affinitygroupids=None, group=None, - hostid=None, keypair=None, ipaddress=None, mode='default', method='GET',hypervisor=None, - customcpunumber=None, customcpuspeed=None, custommemory=None, rootdisksize=None): + domainid=None, zoneid=None, networkids=None, + serviceofferingid=None, securitygroupids=None, + projectid=None, startvm=None, diskofferingid=None, + affinitygroupnames=None, affinitygroupids=None, group=None, + hostid=None, keypair=None, ipaddress=None, mode='default', + method='GET', hypervisor=None, customcpunumber=None, + customcpuspeed=None, custommemory=None, rootdisksize=None): """Create the instance""" cmd = deployVirtualMachine.deployVirtualMachineCmd() @@ -397,12 +409,12 @@ class VirtualMachine: cmd.securitygroupids = [str(sg_id) for sg_id in securitygroupids] if "affinitygroupnames" in services: - cmd.affinitygroupnames = services["affinitygroupnames"] + cmd.affinitygroupnames = services["affinitygroupnames"] elif affinitygroupnames: - cmd.affinitygroupnames = affinitygroupnames + cmd.affinitygroupnames = affinitygroupnames if affinitygroupids: - cmd.affinitygroupids = affinitygroupids + cmd.affinitygroupids = affinitygroupids if projectid: cmd.projectid = projectid @@ -433,25 +445,31 @@ class VirtualMachine: if group: cmd.group = group - #program default access to ssh + # program default access to ssh if mode.lower() == 'basic': cls.ssh_access_group(apiclient, cmd) virtual_machine = apiclient.deployVirtualMachine(cmd, method=method) virtual_machine.ssh_ip = virtual_machine.nic[0].ipaddress - if startvm == False: + if startvm is False: virtual_machine.public_ip = virtual_machine.nic[0].ipaddress return VirtualMachine(virtual_machine.__dict__, services) - #program ssh access over NAT via PF + # program ssh access over NAT via PF if mode.lower() == 'advanced': - cls.access_ssh_over_nat(apiclient, services, virtual_machine, allow_egress=allow_egress) + cls.access_ssh_over_nat( + apiclient, + services, + virtual_machine, + allow_egress=allow_egress) elif mode.lower() == 'basic': if virtual_machine.publicip is not None: - vm_ssh_ip = virtual_machine.publicip #EIP/ELB (netscaler) enabled zone + # EIP/ELB (netscaler) enabled zone + vm_ssh_ip = virtual_machine.publicip else: - vm_ssh_ip = virtual_machine.nic[0].ipaddress #regular basic zone with security group + # regular basic zone with security group + vm_ssh_ip = virtual_machine.nic[0].ipaddress virtual_machine.ssh_ip = vm_ssh_ip virtual_machine.public_ip = vm_ssh_ip @@ -491,12 +509,14 @@ class VirtualMachine: cmd.templateid = templateid return apiclient.restoreVirtualMachine(cmd) - def get_ssh_client(self, ipaddress=None, reconnect=False, port=None, keyPairFileLocation=None): + def get_ssh_client( + self, ipaddress=None, reconnect=False, port=None, + keyPairFileLocation=None): """Get SSH object of VM""" # If NAT Rules are not created while VM deployment in Advanced mode # then, IP address must be passed - if ipaddress != None: + if ipaddress is not None: self.ssh_ip = ipaddress if port: self.ssh_port = port @@ -506,19 +526,19 @@ class VirtualMachine: if reconnect: self.ssh_client = is_server_ssh_ready( - self.ssh_ip, - self.ssh_port, - self.username, - self.password, - keyPairFileLocation=keyPairFileLocation - ) + self.ssh_ip, + self.ssh_port, + self.username, + self.password, + keyPairFileLocation=keyPairFileLocation + ) self.ssh_client = self.ssh_client or is_server_ssh_ready( - self.ssh_ip, - self.ssh_port, - self.username, - self.password, - keyPairFileLocation=keyPairFileLocation - ) + self.ssh_ip, + self.ssh_port, + self.username, + self.password, + keyPairFileLocation=keyPairFileLocation + ) return self.ssh_client def resetSshKey(self, apiclient, **kwargs): @@ -584,7 +604,8 @@ class VirtualMachine: def update_default_nic(self, apiclient, nicId): """Set a NIC to be the default network adapter for a VM""" - cmd = updateDefaultNicForVirtualMachine.updateDefaultNicForVirtualMachineCmd() + cmd = updateDefaultNicForVirtualMachine.\ + updateDefaultNicForVirtualMachineCmd() cmd.nicid = nicId cmd.virtualmachineid = self.id return apiclient.updateDefaultNicForVirtualMachine(cmd) @@ -601,7 +622,7 @@ class VirtualMachine: cmd = detachIso.detachIsoCmd() cmd.virtualmachineid = self.id return apiclient.detachIso(cmd) - + def scale_virtualmachine(self, apiclient, serviceOfferingId): """ Scale up of service offering for the Instance""" cmd = scaleVirtualMachine.scaleVirtualMachineCmd() @@ -611,7 +632,8 @@ class VirtualMachine: def change_service_offering(self, apiclient, serviceOfferingId): """Change service offering of the instance""" - cmd = changeServiceForVirtualMachine.changeServiceForVirtualMachineCmd() + cmd = changeServiceForVirtualMachine.\ + changeServiceForVirtualMachineCmd() cmd.id = self.id cmd.serviceofferingid = serviceOfferingId return apiclient.changeServiceForVirtualMachine(cmd) @@ -627,7 +649,8 @@ class VirtualMachine: def resetPassword(self, apiclient): """Resets VM password if VM created using password enabled template""" - cmd = resetPasswordForVirtualMachine.resetPasswordForVirtualMachineCmd() + cmd = resetPasswordForVirtualMachine.\ + resetPasswordForVirtualMachineCmd() cmd.id = self.id try: response = apiclient.resetPasswordForVirtualMachine(cmd) @@ -639,15 +662,15 @@ class VirtualMachine: def assign_virtual_machine(self, apiclient, account, domainid): """Move a user VM to another user under same domain.""" - cmd = assignVirtualMachine.assignVirtualMachineCmd() + cmd = assignVirtualMachine.assignVirtualMachineCmd() cmd.virtualmachineid = self.id - cmd.account = account - cmd.domainid = domainid + cmd.account = account + cmd.domainid = domainid try: response = apiclient.assignVirtualMachine(cmd) return response except Exception as e: - raise Exception("assignVirtualMachine failed - %s" %e) + raise Exception("assignVirtualMachine failed - %s" % e) def update_affinity_group(self, apiclient, affinitygroupids=None, affinitygroupnames=None): @@ -664,12 +687,12 @@ class VirtualMachine: return apiclient.updateVMAffinityGroup(cmd) def scale(self, apiclient, serviceOfferingId, - customcpunumber=None, customcpuspeed=None, custommemory=None): + customcpunumber=None, customcpuspeed=None, custommemory=None): """Change service offering of the instance""" cmd = scaleVirtualMachine.scaleVirtualMachineCmd() cmd.id = self.id cmd.serviceofferingid = serviceOfferingId - cmd.details = [{"cpuNumber": "","cpuSpeed":"","memory":""}] + cmd.details = [{"cpuNumber": "", "cpuSpeed": "", "memory": ""}] if customcpunumber: cmd.details[0]["cpuNumber"] = customcpunumber if customcpuspeed: @@ -680,8 +703,10 @@ class VirtualMachine: class Volume: + """Manage Volume Life cycle """ + def __init__(self, items): self.__dict__.update(items) @@ -718,7 +743,7 @@ class Volume: @classmethod def create_custom_disk(cls, apiclient, services, account=None, - domainid=None, diskofferingid=None): + domainid=None, diskofferingid=None): """Create Volume from Custom disk offering""" cmd = createVolume.createVolumeCmd() cmd.name = services["diskname"] @@ -784,7 +809,8 @@ class Volume: return(apiclient.resizeVolume(cmd)) @classmethod - def upload(cls, apiclient, services, zoneid=None, account=None, domainid=None, url=None): + def upload(cls, apiclient, services, zoneid=None, + account=None, domainid=None, url=None): """Uploads the volume to specified account""" cmd = uploadVolume.uploadVolumeCmd() @@ -809,10 +835,10 @@ class Volume: while True: volume_response = Volume.list( - apiclient, - id=self.id, - zoneid=self.zoneid, - ) + apiclient, + id=self.id, + zoneid=self.zoneid, + ) if isinstance(volume_response, list): volume = volume_response[0] @@ -827,7 +853,7 @@ class Volume: elif 'Installing' not in volume.state: raise Exception( "Error in uploading volume: status - %s" % - volume.state) + volume.state) elif timeout == 0: break @@ -839,7 +865,7 @@ class Volume: @classmethod def extract(cls, apiclient, volume_id, zoneid, mode): """Extracts the volume""" - + cmd = extractVolume.extractVolumeCmd() cmd.id = volume_id cmd.zoneid = zoneid @@ -853,15 +879,18 @@ class Volume: [setattr(cmd, k, v) for k, v in kwargs.items()] return(apiclient.migrateVolume(cmd)) + class Snapshot: + """Manage Snapshot Lifecycle """ + def __init__(self, items): self.__dict__.update(items) @classmethod def create(cls, apiclient, volume_id, account=None, - domainid=None, projectid=None): + domainid=None, projectid=None): """Create Snapshot""" cmd = createSnapshot.createSnapshotCmd() cmd.volumeid = volume_id @@ -889,6 +918,7 @@ class Snapshot: class Template: + """Manage template life cycle""" def __init__(self, items): @@ -913,16 +943,20 @@ class Template: if not isinstance(ostypes, list): raise Exception( "Unable to find Ostype id with desc: %s" % - services["ostype"]) + services["ostype"]) cmd.ostypeid = ostypes[0].id else: raise Exception( - "Unable to find Ostype is required for creating template") + "Unable to find Ostype is required for creating template") - cmd.isfeatured = services["isfeatured"] if "isfeatured" in services else False - cmd.ispublic = services["ispublic"] if "ispublic" in services else False - cmd.isextractable = services["isextractable"] if "isextractable" in services else False - cmd.passwordenabled = services["passwordenabled"] if "passwordenabled" in services else False + cmd.isfeatured = services[ + "isfeatured"] if "isfeatured" in services else False + cmd.ispublic = services[ + "ispublic"] if "ispublic" in services else False + cmd.isextractable = services[ + "isextractable"] if "isextractable" in services else False + cmd.passwordenabled = services[ + "passwordenabled"] if "passwordenabled" in services else False if volumeid: cmd.volumeid = volumeid @@ -939,7 +973,7 @@ class Template: @classmethod def register(cls, apiclient, services, zoneid=None, - account=None, domainid=None, hypervisor=None): + account=None, domainid=None, hypervisor=None): """Create template from URL""" # Create template from Virtual machine and Volume ID @@ -947,7 +981,7 @@ class Template: cmd.displaytext = services["displaytext"] cmd.name = "-".join([services["name"], random_gen()]) cmd.format = services["format"] - cmd.hypervisor = hypervisor + cmd.hypervisor = hypervisor if "ostypeid" in services: cmd.ostypeid = services["ostypeid"] @@ -960,11 +994,11 @@ class Template: if not isinstance(ostypes, list): raise Exception( "Unable to find Ostype id with desc: %s" % - services["ostype"]) + services["ostype"]) cmd.ostypeid = ostypes[0].id else: raise Exception( - "Unable to find Ostype is required for registering template") + "Unable to find Ostype is required for registering template") cmd.url = services["url"] @@ -973,10 +1007,14 @@ class Template: else: cmd.zoneid = services["zoneid"] - cmd.isfeatured = services["isfeatured"] if "isfeatured" in services else False - cmd.ispublic = services["ispublic"] if "ispublic" in services else False - cmd.isextractable = services["isextractable"] if "isextractable" in services else False - cmd.passwordenabled = services["passwordenabled"] if "passwordenabled" in services else False + cmd.isfeatured = services[ + "isfeatured"] if "isfeatured" in services else False + cmd.ispublic = services[ + "ispublic"] if "ispublic" in services else False + cmd.isextractable = services[ + "isextractable"] if "isextractable" in services else False + cmd.passwordenabled = services[ + "passwordenabled"] if "passwordenabled" in services else False if account: cmd.account = account @@ -1003,15 +1041,15 @@ class Template: @classmethod def create_from_snapshot(cls, apiclient, snapshot, services, - random_name=True): + random_name=True): """Create Template from snapshot""" # Create template from Virtual machine and Snapshot ID cmd = createTemplate.createTemplateCmd() cmd.displaytext = services["displaytext"] cmd.name = "-".join([ - services["name"], - random_gen() - ]) if random_name else services["name"] + services["name"], + random_gen() + ]) if random_name else services["name"] if "ostypeid" in services: cmd.ostypeid = services["ostypeid"] @@ -1024,11 +1062,11 @@ class Template: if not isinstance(ostypes, list): raise Exception( "Unable to find Ostype id with desc: %s" % - services["ostype"]) + services["ostype"]) cmd.ostypeid = ostypes[0].id else: raise Exception( - "Unable to find Ostype is required for creating template") + "Unable to find Ostype is required for creating template") cmd.snapshotid = snapshot.id return Template(apiclient.createTemplate(cmd).__dict__) @@ -1047,11 +1085,11 @@ class Template: while True: template_response = Template.list( - apiclient, - id=self.id, - zoneid=self.zoneid, - templatefilter='self' - ) + apiclient, + id=self.id, + zoneid=self.zoneid, + templatefilter='self' + ) if isinstance(template_response, list): template = template_response[0] @@ -1068,7 +1106,7 @@ class Template: elif 'Installing' not in template.status: raise Exception( "Error in downloading template: status - %s" % - template.status) + template.status) elif timeout == 0: break @@ -1115,6 +1153,7 @@ class Template: class Iso: + """Manage ISO life cycle""" def __init__(self, items): @@ -1122,7 +1161,7 @@ class Iso: @classmethod def create(cls, apiclient, services, account=None, domainid=None, - projectid=None): + projectid=None): """Create an ISO""" # Create ISO from URL cmd = registerIso.registerIsoCmd() @@ -1139,11 +1178,11 @@ class Iso: if not isinstance(ostypes, list): raise Exception( "Unable to find Ostype id with desc: %s" % - services["ostype"]) + services["ostype"]) cmd.ostypeid = ostypes[0].id else: raise Exception( - "Unable to find Ostype is required for creating ISO") + "Unable to find Ostype is required for creating ISO") cmd.url = services["url"] cmd.zoneid = services["zoneid"] @@ -1193,10 +1232,10 @@ class Iso: if response.status == 'Successfully Installed': return elif 'Downloaded' not in response.status and \ - 'Installing' not in response.status: + 'Installing' not in response.status: raise Exception( "Error In Downloading ISO: ISO Status - %s" % - response.status) + response.status) elif timeout == 0: raise Exception("ISO download Timeout Exception") @@ -1244,14 +1283,16 @@ class Iso: class PublicIPAddress: + """Manage Public IP Addresses""" def __init__(self, items): self.__dict__.update(items) @classmethod - def create(cls, apiclient, accountid=None, zoneid=None, domainid=None, services=None, - networkid=None, projectid=None, vpcid=None, isportable=False): + def create(cls, apiclient, accountid=None, zoneid=None, domainid=None, + services=None, networkid=None, projectid=None, vpcid=None, + isportable=False): """Associate Public IP address""" cmd = associateIpAddress.associateIpAddressCmd() @@ -1300,6 +1341,7 @@ class PublicIPAddress: class NATRule: + """Manage port forwarding rule""" def __init__(self, items): @@ -1360,13 +1402,15 @@ class NATRule: class StaticNATRule: + """Manage Static NAT rule""" def __init__(self, items): self.__dict__.update(items) @classmethod - def create(cls, apiclient, services, ipaddressid=None, networkid=None, vpcid=None): + def create(cls, apiclient, services, ipaddressid=None, + networkid=None, vpcid=None): """Creates static ip forwarding rule""" cmd = createFirewallRule.createFirewallRuleCmd() @@ -1408,7 +1452,7 @@ class StaticNATRule: @classmethod def enable(cls, apiclient, ipaddressid, virtualmachineid, networkid=None, - vmguestip=None): + vmguestip=None): """Enables Static NAT rule""" cmd = enableStaticNat.enableStaticNatCmd() @@ -1433,6 +1477,7 @@ class StaticNATRule: class EgressFireWallRule: + """Manage Egress Firewall rule""" def __init__(self, items): @@ -1452,7 +1497,8 @@ class EgressFireWallRule: if endport: cmd.endport = endport - return EgressFireWallRule(apiclient.createEgressFirewallRule(cmd).__dict__) + return EgressFireWallRule( + apiclient.createEgressFirewallRule(cmd).__dict__) def delete(self, apiclient): """Delete Egress Firewall rule""" @@ -1470,8 +1516,8 @@ class EgressFireWallRule: return(apiclient.listEgressFirewallRules(cmd)) - class FireWallRule: + """Manage Firewall rule""" def __init__(self, items): @@ -1516,6 +1562,7 @@ class FireWallRule: class ServiceOffering: + """Manage service offerings cycle""" def __init__(self, items): @@ -1549,7 +1596,8 @@ class ServiceOffering: cmd.deploymentplanner = services["deploymentplanner"] if "serviceofferingdetails" in services: - cmd.serviceofferingdetails.append({services['serviceofferingdetails']}) + cmd.serviceofferingdetails.append( + {services['serviceofferingdetails']}) if "isvolatile" in services: cmd.isvolatile = services["isvolatile"] @@ -1581,6 +1629,7 @@ class ServiceOffering: class DiskOffering: + """Manage disk offerings cycle""" def __init__(self, items): @@ -1622,6 +1671,7 @@ class DiskOffering: class NetworkOffering: + """Manage network offerings cycle""" def __init__(self, items): @@ -1646,18 +1696,19 @@ class NetworkOffering: if "serviceProviderList" in services: for service, provider in services["serviceProviderList"].items(): cmd.serviceproviderlist.append({ - 'service': service, - 'provider': provider - }) + 'service': service, + 'provider': provider + }) if "serviceCapabilityList" in services: cmd.servicecapabilitylist = [] - for service, capability in services["serviceCapabilityList"].items(): + for service, capability in services["serviceCapabilityList"].\ + items(): for ctype, value in capability.items(): cmd.servicecapabilitylist.append({ - 'service': service, - 'capabilitytype': ctype, - 'capabilityvalue': value - }) + 'service': service, + 'capabilitytype': ctype, + 'capabilityvalue': value + }) if "specifyVlan" in services: cmd.specifyVlan = services["specifyVlan"] if "specifyIpRanges" in services: @@ -1698,6 +1749,7 @@ class NetworkOffering: class SnapshotPolicy: + """Manage snapshot policies""" def __init__(self, items): @@ -1729,7 +1781,9 @@ class SnapshotPolicy: [setattr(cmd, k, v) for k, v in kwargs.items()] return(apiclient.listSnapshotPolicies(cmd)) + class Hypervisor: + """Manage Hypervisor""" def __init__(self, items): @@ -1745,6 +1799,7 @@ class Hypervisor: class LoadBalancerRule: + """Manage Load Balancer rule""" def __init__(self, items): @@ -1810,7 +1865,8 @@ class LoadBalancerRule: apiclient.removeFromLoadBalancerRule(cmd) return - def update(self, apiclient, algorithm=None, description=None, name=None, **kwargs): + def update(self, apiclient, algorithm=None, + description=None, name=None, **kwargs): """Updates the load balancing rule""" cmd = updateLoadBalancerRule.updateLoadBalancerRuleCmd() cmd.id = self.id @@ -1824,7 +1880,8 @@ class LoadBalancerRule: [setattr(cmd, k, v) for k, v in kwargs.items()] return apiclient.updateLoadBalancerRule(cmd) - def createSticky(self, apiclient, methodname, name, description=None, param=None): + def createSticky( + self, apiclient, methodname, name, description=None, param=None): """Creates a sticky policy for the LB rule""" cmd = createLBStickinessPolicy.createLBStickinessPolicyCmd() @@ -1865,13 +1922,15 @@ class LoadBalancerRule: class Cluster: + """Manage Cluster life cycle""" def __init__(self, items): self.__dict__.update(items) @classmethod - def create(cls, apiclient, services, zoneid=None, podid=None, hypervisor=None): + def create(cls, apiclient, services, zoneid=None, podid=None, + hypervisor=None): """Create Cluster""" cmd = addCluster.addClusterCmd() cmd.clustertype = services["clustertype"] @@ -1915,13 +1974,15 @@ class Cluster: class Host: + """Manage Host life cycle""" def __init__(self, items): self.__dict__.update(items) @classmethod - def create(cls, apiclient, cluster, services, zoneid=None, podid=None, hypervisor=None): + def create(cls, apiclient, cluster, services, + zoneid=None, podid=None, hypervisor=None): """ 1. Creates the host based upon the information provided. 2. Verifies the output of the adding host and its state post addition @@ -1967,12 +2028,14 @@ class Host: while retries: lh_resp = apiclient.listHosts(host[0].id) ret = validateList(lh_resp) - if (ret[0] == PASS) and (str(ret[1].state).lower() == 'up'): + if (ret[0] == PASS) and \ + (str(ret[1].state).lower() == 'up'): return Host(host[0].__dict__) retries += -1 return FAILED - except Exception, e: - print "Exception Occurred Under Host.create : %s" % GetDetailExceptionInfo(e) + except Exception as e: + print "Exception Occurred Under Host.create : %s" % \ + GetDetailExceptionInfo(e) return FAILED def delete(self, apiclient): @@ -2044,6 +2107,7 @@ class Host: class StoragePool: + """Manage Storage pools (Primary Storage)""" def __init__(self, items): @@ -2051,7 +2115,7 @@ class StoragePool: @classmethod def create(cls, apiclient, services, clusterid=None, - zoneid=None, podid=None): + zoneid=None, podid=None): """Create Storage pool (Primary Storage)""" cmd = createStoragePool.createStoragePoolCmd() @@ -2111,7 +2175,9 @@ class StoragePool: [setattr(cmd, k, v) for k, v in kwargs.items()] return(apiclient.findStoragePoolsForMigration(cmd)) + class Network: + """Manage Network pools""" def __init__(self, items): @@ -2203,6 +2269,7 @@ class Network: class NetworkACL: + """Manage Network ACL lifecycle""" def __init__(self, items): @@ -2210,7 +2277,8 @@ class NetworkACL: @classmethod def create(cls, apiclient, services, networkid=None, protocol=None, - number=None, aclid=None, action='Allow', traffictype=None, cidrlist=[]): + number=None, aclid=None, action='Allow', + traffictype=None, cidrlist=[]): """Create network ACL rules(Ingress/Egress)""" cmd = createNetworkACL.createNetworkACLCmd() @@ -2277,13 +2345,15 @@ class NetworkACL: class NetworkACLList: + """Manage Network ACL lists lifecycle""" def __init__(self, items): self.__dict__.update(items) @classmethod - def create(cls, apiclient, services, name=None, description=None, vpcid=None): + def create( + cls, apiclient, services, name=None, description=None, vpcid=None): """Create network ACL container list""" cmd = createNetworkACLList.createNetworkACLListCmd() @@ -2321,6 +2391,7 @@ class NetworkACLList: class Vpn: + """Manage VPN life cycle""" def __init__(self, items): @@ -2328,7 +2399,7 @@ class Vpn: @classmethod def create(cls, apiclient, publicipid, account=None, domainid=None, - projectid=None, networkid=None, vpcid=None): + projectid=None, networkid=None, vpcid=None): """Create VPN for Public IP address""" cmd = createRemoteAccessVpn.createRemoteAccessVpnCmd() cmd.publicipid = publicipid @@ -2361,6 +2432,7 @@ class Vpn: class VpnUser: + """Manage VPN user""" def __init__(self, items): @@ -2405,6 +2477,7 @@ class VpnUser: class Zone: + """Manage Zone""" def __init__(self, items): @@ -2455,6 +2528,7 @@ class Zone: class Pod: + """Manage Pod""" def __init__(self, items): @@ -2490,6 +2564,7 @@ class Pod: class PublicIpRange: + """Manage VlanIpRange""" def __init__(self, items): @@ -2528,7 +2603,8 @@ class PublicIpRange: return(apiclient.listVlanIpRanges(cmd)) @classmethod - def dedicate(cls, apiclient, id, account=None, domainid=None, projectid=None): + def dedicate( + cls, apiclient, id, account=None, domainid=None, projectid=None): """Dedicate VLAN IP range""" cmd = dedicatePublicIpRange.dedicatePublicIpRangeCmd() @@ -2547,6 +2623,7 @@ class PublicIpRange: class PortablePublicIpRange: + """Manage portable public Ip Range""" def __init__(self, items): @@ -2566,7 +2643,8 @@ class PortablePublicIpRange: if "vlan" in services: cmd.vlan = services["vlan"] - return PortablePublicIpRange(apiclient.createPortableIpRange(cmd).__dict__) + return PortablePublicIpRange( + apiclient.createPortableIpRange(cmd).__dict__) def delete(self, apiclient): """Delete portable IpRange""" @@ -2583,7 +2661,9 @@ class PortablePublicIpRange: [setattr(cmd, k, v) for k, v in kwargs.items()] return(apiclient.listPortableIpRanges(cmd)) + class SecondaryStagingStore: + """Manage Staging Store""" def __init__(self, items): @@ -2603,7 +2683,8 @@ class SecondaryStagingStore: if "scope" in services: cmd.scope = services["scope"] - return SecondaryStagingStore(apiclient.createSecondaryStagingStore(cmd).__dict__) + return SecondaryStagingStore( + apiclient.createSecondaryStagingStore(cmd).__dict__) def delete(self, apiclient): """Delete Staging Storage""" @@ -2619,6 +2700,7 @@ class SecondaryStagingStore: class ImageStore: + """Manage image stores""" def __init__(self, items): @@ -2654,6 +2736,7 @@ class ImageStore: class PhysicalNetwork: + """Manage physical network storage""" def __init__(self, items): @@ -2694,7 +2777,8 @@ class PhysicalNetwork: return apiclient.addTrafficType(cmd) @classmethod - def dedicate(cls, apiclient, vlanrange, physicalnetworkid, account=None, domainid=None, projectid=None): + def dedicate(cls, apiclient, vlanrange, physicalnetworkid, + account=None, domainid=None, projectid=None): """Dedicate guest vlan range""" cmd = dedicateGuestVlanRange.dedicateGuestVlanRangeCmd() @@ -2708,7 +2792,8 @@ class PhysicalNetwork: def release(self, apiclient): """Release guest vlan range""" - cmd = releaseDedicatedGuestVlanRange.releaseDedicatedGuestVlanRangeCmd() + cmd = releaseDedicatedGuestVlanRange.\ + releaseDedicatedGuestVlanRangeCmd() cmd.id = self.id return apiclient.releaseDedicatedGuestVlanRange(cmd) @@ -2726,10 +2811,12 @@ class PhysicalNetwork: cmd = listPhysicalNetworks.listPhysicalNetworksCmd() [setattr(cmd, k, v) for k, v in kwargs.items()] - return map(lambda pn : PhysicalNetwork(pn.__dict__), apiclient.listPhysicalNetworks(cmd)) + return map(lambda pn: PhysicalNetwork( + pn.__dict__), apiclient.listPhysicalNetworks(cmd)) class SecurityGroup: + """Manage Security Groups""" def __init__(self, items): @@ -2821,9 +2908,9 @@ class SecurityGroup: cmd.usersecuritygrouplist = [] for account, group in user_secgrp_list.items(): cmd.usersecuritygrouplist.append({ - 'account': account, - 'group': group - }) + 'account': account, + 'group': group + }) return (apiclient.authorizeSecurityGroupEgress(cmd).__dict__) @@ -2844,6 +2931,7 @@ class SecurityGroup: class VpnCustomerGateway: + """Manage VPN Customer Gateway""" def __init__(self, items): @@ -2851,7 +2939,7 @@ class VpnCustomerGateway: @classmethod def create(cls, apiclient, services, name, gateway, cidrlist, - account=None, domainid=None): + account=None, domainid=None): """Create VPN Customer Gateway""" cmd = createVpnCustomerGateway.createVpnCustomerGatewayCmd() cmd.name = name @@ -2873,7 +2961,8 @@ class VpnCustomerGateway: cmd.account = account if domainid: cmd.domainid = domainid - return VpnCustomerGateway(apiclient.createVpnCustomerGateway(cmd).__dict__) + return VpnCustomerGateway( + apiclient.createVpnCustomerGateway(cmd).__dict__) def update(self, apiclient, services, name, gateway, cidrlist): """Updates VPN Customer Gateway""" @@ -2914,6 +3003,7 @@ class VpnCustomerGateway: class Project: + """Manage Project life cycle""" def __init__(self, items): @@ -2999,6 +3089,7 @@ class Project: class ProjectInvitation: + """Manage project invitations""" def __init__(self, items): @@ -3035,6 +3126,7 @@ class ProjectInvitation: class Configurations: + """Manage Configuration""" @classmethod @@ -3056,13 +3148,15 @@ class Configurations: class NetScaler: + """Manage external netscaler device""" def __init__(self, items): self.__dict__.update(items) @classmethod - def add(cls, apiclient, services, physicalnetworkid, username=None, password=None): + def add(cls, apiclient, services, physicalnetworkid, + username=None, password=None): """Add external netscaler device to cloudstack""" cmd = addNetscalerLoadBalancer.addNetscalerLoadBalancerCmd() @@ -3082,11 +3176,14 @@ class NetScaler: # Generate the URL url = 'https://' + str(services["ipaddress"]) + '?' url = url + 'publicinterface=' + str(services["publicinterface"]) + '&' - url = url + 'privateinterface=' + str(services["privateinterface"]) + '&' + url = url + 'privateinterface=' + \ + str(services["privateinterface"]) + '&' url = url + 'numretries=' + str(services["numretries"]) + '&' - if not services["lbdevicededicated"] and "lbdevicecapacity" in services: - url = url + 'lbdevicecapacity=' + str(services["lbdevicecapacity"]) + '&' + if not services["lbdevicededicated"] and \ + "lbdevicecapacity" in services: + url = url + 'lbdevicecapacity=' + \ + str(services["lbdevicecapacity"]) + '&' url = url + 'lbdevicededicated=' + str(services["lbdevicededicated"]) @@ -3104,7 +3201,8 @@ class NetScaler: def configure(self, apiclient, **kwargs): """List already registered netscaler devices""" - cmd = configureNetscalerLoadBalancer.configureNetscalerLoadBalancerCmd() + cmd = configureNetscalerLoadBalancer.\ + configureNetscalerLoadBalancerCmd() cmd.lbdeviceid = self.lbdeviceid [setattr(cmd, k, v) for k, v in kwargs.items()] return(apiclient.configureNetscalerLoadBalancer(cmd)) @@ -3119,6 +3217,7 @@ class NetScaler: class NetworkServiceProvider: + """Manage network serivce providers for CloudStack""" def __init__(self, items): @@ -3132,7 +3231,8 @@ class NetworkServiceProvider: cmd.name = name cmd.physicalnetworkid = physicalnetworkid cmd.servicelist = servicelist - return NetworkServiceProvider(apiclient.addNetworkServiceProvider(cmd).__dict__) + return NetworkServiceProvider( + apiclient.addNetworkServiceProvider(cmd).__dict__) def delete(self, apiclient): """Deletes network service provider""" @@ -3168,6 +3268,7 @@ class NetworkServiceProvider: class Router: + """Manage router life cycle""" def __init__(self, items): @@ -3221,6 +3322,7 @@ class Router: class Tag: + """Manage tags""" def __init__(self, items): @@ -3236,9 +3338,9 @@ class Tag: cmd.tags = [] for key, value in tags.items(): cmd.tags.append({ - 'key': key, - 'value': value - }) + 'key': key, + 'value': value + }) return Tag(apiclient.createTags(cmd).__dict__) def delete(self, apiclient, resourceIds, resourceType, tags): @@ -3250,9 +3352,9 @@ class Tag: cmd.tags = [] for key, value in tags.items(): cmd.tags.append({ - 'key': key, - 'value': value - }) + 'key': key, + 'value': value + }) apiclient.deleteTags(cmd) @classmethod @@ -3265,6 +3367,7 @@ class Tag: class VpcOffering: + """Manage VPC offerings""" def __init__(self, items): @@ -3281,18 +3384,19 @@ class VpcOffering: if "serviceProviderList" in services: for service, provider in services["serviceProviderList"].items(): cmd.serviceproviderlist.append({ - 'service': service, - 'provider': provider - }) + 'service': service, + 'provider': provider + }) if "serviceCapabilityList" in services: cmd.servicecapabilitylist = [] - for service, capability in services["serviceCapabilityList"].items(): + for service, capability in \ + services["serviceCapabilityList"].items(): for ctype, value in capability.items(): cmd.servicecapabilitylist.append({ - 'service': service, - 'capabilitytype': ctype, - 'capabilityvalue': value - }) + 'service': service, + 'capabilitytype': ctype, + 'capabilityvalue': value + }) return VpcOffering(apiclient.createVPCOffering(cmd).__dict__) def update(self, apiclient, name=None, displaytext=None, state=None): @@ -3325,6 +3429,7 @@ class VpcOffering: class VPC: + """Manage Virtual Private Connection""" def __init__(self, items): @@ -3332,7 +3437,8 @@ class VPC: @classmethod def create(cls, apiclient, services, vpcofferingid, - zoneid, networkDomain=None, account=None, domainid=None, **kwargs): + zoneid, networkDomain=None, account=None, + domainid=None, **kwargs): """Creates the virtual private connection (VPC)""" cmd = createVPC.createVPCCmd() @@ -3386,6 +3492,7 @@ class VPC: class PrivateGateway: + """Manage private gateway lifecycle""" def __init__(self, items): @@ -3393,7 +3500,7 @@ class PrivateGateway: @classmethod def create(cls, apiclient, gateway, ipaddress, netmask, vlan, vpcid, - physicalnetworkid=None): + physicalnetworkid=None): """Create private gateway""" cmd = createPrivateGateway.createPrivateGatewayCmd() @@ -3424,6 +3531,7 @@ class PrivateGateway: class AffinityGroup: + def __init__(self, items): self.__dict__.update(items) @@ -3453,8 +3561,11 @@ class AffinityGroup: [setattr(cmd, k, v) for k, v in kwargs.items()] return apiclient.listAffinityGroups(cmd) + class StaticRoute: + """Manage static route lifecycle""" + def __init__(self, items): self.__dict__.update(items) @@ -3484,11 +3595,14 @@ class StaticRoute: class VNMC: + """Manage VNMC lifecycle""" + def __init__(self, items): self.__dict__.update(items) - def create(cls, apiclient, hostname, username, password, physicalnetworkid): + def create(cls, apiclient, hostname, username, password, + physicalnetworkid): """Registers VNMC appliance""" cmd = addCiscoVnmcResource.addCiscoVnmcResourceCmd() @@ -3515,6 +3629,7 @@ class VNMC: class SSHKeyPair: + """Manage SSH Key pairs""" def __init__(self, items, services): @@ -3522,7 +3637,7 @@ class SSHKeyPair: @classmethod def create(cls, apiclient, name=None, account=None, - domainid=None, projectid=None): + domainid=None, projectid=None): """Creates SSH keypair""" cmd = createSSHKeyPair.createSSHKeyPairCmd() cmd.name = name @@ -3557,6 +3672,7 @@ class SSHKeyPair: class Capacities: + """Manage Capacities""" @classmethod @@ -3569,6 +3685,7 @@ class Capacities: class Alert: + """Manage alerts""" @classmethod @@ -3581,6 +3698,7 @@ class Alert: class InstanceGroup: + """Manage VM instance groups""" def __init__(self, items): @@ -3654,7 +3772,8 @@ class InstanceGroup: def changeServiceOffering(self, apiclient, serviceOfferingId): """Change service offering of the vm tier""" - cmd = changeServiceForVirtualMachine.changeServiceForVirtualMachineCmd() + cmd = changeServiceForVirtualMachine.\ + changeServiceForVirtualMachineCmd() cmd.group = self.id cmd.serviceofferingid = serviceOfferingId return apiclient.changeServiceForVirtualMachine(cmd) @@ -3667,8 +3786,10 @@ class InstanceGroup: class ASA1000V: + """Manage ASA 1000v lifecycle""" - def create(cls, apiclient, hostname, insideportprofile, clusterid, physicalnetworkid): + def create(cls, apiclient, hostname, insideportprofile, + clusterid, physicalnetworkid): """Registers ASA 1000v appliance""" cmd = addCiscoAsa1000vResource.addCiscoAsa1000vResourceCmd() @@ -3693,12 +3814,17 @@ class ASA1000V: [setattr(cmd, k, v) for k, v in kwargs.items()] return(apiclient.listCiscoAsa1000vResources(cmd)) + class VmSnapshot: + """Manage VM Snapshot life cycle""" + def __init__(self, items): self.__dict__.update(items) + @classmethod - def create(cls,apiclient,vmid,snapshotmemory="false",name=None,description=None): + def create(cls, apiclient, vmid, snapshotmemory="false", + name=None, description=None): cmd = createVMSnapshot.createVMSnapshotCmd() cmd.virtualmachineid = vmid @@ -3709,29 +3835,32 @@ class VmSnapshot: if description: cmd.description = description return VmSnapshot(apiclient.createVMSnapshot(cmd).__dict__) - + @classmethod def list(cls, apiclient, **kwargs): cmd = listVMSnapshot.listVMSnapshotCmd() [setattr(cmd, k, v) for k, v in kwargs.items()] return(apiclient.listVMSnapshot(cmd)) - + @classmethod - def revertToSnapshot(cls, apiclient,vmsnapshotid): + def revertToSnapshot(cls, apiclient, vmsnapshotid): cmd = revertToVMSnapshot.revertToVMSnapshotCmd() cmd.vmsnapshotid = vmsnapshotid - + return apiclient.revertToVMSnapshot(cmd) - + @classmethod - def deleteVMSnapshot(cls,apiclient,vmsnapshotid): + def deleteVMSnapshot(cls, apiclient, vmsnapshotid): cmd = deleteVMSnapshot.deleteVMSnapshotCmd() cmd.vmsnapshotid = vmsnapshotid - + return apiclient.deleteVMSnapshot(cmd) + class Region: + """ Regions related Api """ + def __init__(self, items): self.__dict__.update(items) @@ -3773,14 +3902,16 @@ class Region: class ApplicationLoadBalancer: + """Manage Application Load Balancers in VPC""" def __init__(self, items): self.__dict__.update(items) @classmethod - def create(cls, apiclient, services, name=None, sourceport=None, instanceport=22, - algorithm="roundrobin", scheme="internal", sourcenetworkid=None, networkid=None): + def create(cls, apiclient, services, name=None, sourceport=None, + instanceport=22, algorithm="roundrobin", scheme="internal", + sourcenetworkid=None, networkid=None): """Create Application Load Balancer""" cmd = createLoadBalancer.createLoadBalancerCmd() @@ -3851,7 +3982,9 @@ class ApplicationLoadBalancer: [setattr(cmd, k, v) for k, v in kwargs.items()] return(apiclient.listLoadBalancerRules(cmd)) + class Resources: + """Manage resource limits""" def __init__(self, items, services): @@ -3880,9 +4013,12 @@ class Resources: cmd = updateResourceCount.updateResourceCountCmd() [setattr(cmd, k, v) for k, v in kwargs.items()] return(apiclient.updateResourceCount(cmd)) - + + class NIC: + """NIC related API""" + def __init__(self, items): self.__dict__.update(items) @@ -3896,7 +4032,7 @@ class NIC: return(apiclient.addIpToNic(cmd)) @classmethod - def removeIp(cls,apiclient,ipaddressid): + def removeIp(cls, apiclient, ipaddressid): """Remove secondary Ip from NIC""" cmd = removeIpFromNic.removeIpFromNicCmd() cmd.id = ipaddressid @@ -3909,8 +4045,10 @@ class NIC: cmd = listNics.listNicsCmd() [setattr(cmd, k, v) for k, v in kwargs.items()] return(apiclient.listNics(cmd)) - + + class IAMGroup: + def __init__(self, items): self.__dict__.update(items) @@ -3937,15 +4075,15 @@ class IAMGroup: def list(cls, apiclient, **kwargs): cmd = listIAMGroups.listIAMGroupsCmd() [setattr(cmd, k, v) for k, v in kwargs.items()] - return apiclient.listIAMGroupsCmd(cmd) - + return apiclient.listIAMGroupsCmd(cmd) + def addAccount(self, apiclient, accts): """Add accounts to iam group""" cmd = addAccountToIAMGroup.addAccountToIAMGroupCmd() cmd.id = self.id cmd.accounts = [str(acct.id) for acct in accts] apiclient.addAccountToIAMGroup(cmd) - return + return def removeAccount(self, apiclient, accts): """ Remove accounts from iam group""" @@ -3953,25 +4091,27 @@ class IAMGroup: cmd.id = self.id cmd.accounts = [str(acct.id) for acct in accts] apiclient.removeAccountFromIAMGroup(cmd) - return - + return + def attachPolicy(self, apiclient, policies): """Add policies to iam group""" cmd = attachIAMPolicyToIAMGroup.attachIAMPolicyToIAMGroupCmd() cmd.id = self.id cmd.policies = [str(policy.id) for policy in policies] apiclient.attachIAMPolicyToIAMGroup(cmd) - return - + return + def detachPolicy(self, apiclient, policies): """Remove policies from iam group""" cmd = removeIAMPolicyFromIAMGroup.removeIAMPolicyFromIAMGroupCmd() cmd.id = self.id cmd.policies = [str(policy.id) for policy in policies] apiclient.removeIAMPolicyFromIAMGroup(cmd) - return - + return + + class IAMPolicy: + def __init__(self, items): self.__dict__.update(items) @@ -3998,7 +4138,7 @@ class IAMPolicy: def list(cls, apiclient, **kwargs): cmd = listIAMPolicies.listIAMPoliciesCmd() [setattr(cmd, k, v) for k, v in kwargs.items()] - return apiclient.listIAMPoliciesCmd(cmd) + return apiclient.listIAMPoliciesCmd(cmd) def addPermission(self, apiclient, permission): """Add permission to iam policy""" @@ -4009,27 +4149,28 @@ class IAMPolicy: cmd.scope = permission['scope'] cmd.scopeid = permission['scopeid'] apiclient.addIAMPermissionToIAMPolicy(cmd) - return + return def removePermission(self, apiclient, permission): """Remove permission from iam policy""" - cmd = removeIAMPermissionFromIAMPolicy.removeIAMPermissionFromIAMPolicyCmd() + cmd = removeIAMPermissionFromIAMPolicy.\ + removeIAMPermissionFromIAMPolicyCmd() cmd.id = self.id cmd.action = permission['action'] cmd.entitytype = permission['entitytype'] cmd.scope = permission['scope'] cmd.scopeid = permission['scopeid'] apiclient.removeIAMPermissionFromIAMPolicy(cmd) - return - + return + def attachAccount(self, apiclient, accts): """Attach iam policy to accounts""" cmd = attachIAMPolicyToAccount.attachIAMPolicyToAccountCmd() cmd.id = self.id cmd.accounts = [str(acct.id) for acct in accts] apiclient.attachIAMPolicyToAccount(cmd) - return - + return + def detachAccount(self, apiclient, accts): """Detach iam policy from accounts""" cmd = removeIAMPolicyFromAccount.removeIAMPolicyFromAccountCmd() @@ -4038,15 +4179,20 @@ class IAMPolicy: apiclient.removeIAMPolicyFromAccount(cmd) return + class SimulatorMock: + """Manage simulator mock lifecycle""" + def __init__(self, items): self.__dict__.update(items) - + @classmethod - def create(cls, apiclient, command, zoneid=None, podid=None, clusterid=None, hostid=None, value="result:fail", count=None, jsonresponse=None): + def create(cls, apiclient, command, zoneid=None, podid=None, + clusterid=None, hostid=None, value="result:fail", + count=None, jsonresponse=None): """Creates simulator mock""" - + cmd = configureSimulator.configureSimulatorCmd() cmd.zoneid = zoneid cmd.podid = podid @@ -4062,17 +4208,17 @@ class SimulatorMock: return SimulatorMock(simulatormock.__dict__) except Exception as e: raise e - + def delete(self, apiclient): """Removes simulator mock""" - + cmd = cleanupSimulatorMock.cleanupSimulatorMockCmd() cmd.id = self.id return apiclient.cleanupSimulatorMock(cmd) - + def query(self, apiclient): """Queries simulator mock""" - + cmd = querySimulatorMock.querySimulatorMockCmd() cmd.id = self.id try: @@ -4081,5 +4227,3 @@ class SimulatorMock: return SimulatorMock(simulatormock.__dict__) except Exception as e: raise e - - diff --git a/tools/marvin/marvin/lib/common.py b/tools/marvin/marvin/lib/common.py index 8868d2d51ea..0a82f9335d9 100644 --- a/tools/marvin/marvin/lib/common.py +++ b/tools/marvin/marvin/lib/common.py @@ -59,8 +59,6 @@ from marvin.cloudstackAPI import (listConfigurations, listVPCOfferings) - - from marvin.sshClient import SshClient from marvin.codes import (PASS, ISOLATED_NETWORK, VPC_NETWORK, BASIC_ZONE, FAIL, NAT_RULE, STATIC_NAT_RULE) @@ -76,7 +74,8 @@ import time def is_config_suitable(apiclient, name, value): """ - Ensure if the deployment has the expected `value` for the global setting `name' + Ensure if the deployment has the expected + `value` for the global setting `name' @return: true if value is set, else false """ configs = Configurations.list(apiclient, name=name) @@ -151,7 +150,8 @@ def add_netscaler(apiclient, zoneid, NSservice): def get_region(apiclient, region_id=None, region_name=None): ''' @name : get_region - @Desc : Returns the Region Information for a given region id or region name + @Desc : Returns the Region Information for a given + region id or region name @Input : region_name: Name of the Region region_id : Id of the region @Output : 1. Region Information for the passed inputs else first Region @@ -237,10 +237,12 @@ def get_pod(apiclient, zone_id=None, pod_id=None, pod_name=None): if validateList(cmd_out)[0] != PASS: return FAILED return cmd_out[0] + + def get_template( - apiclient, zone_id=None, ostype_desc=None, template_filter="featured", template_type='BUILTIN', - template_id=None, template_name=None, account=None, domain_id=None, project_id=None, - hypervisor=None): + apiclient, zone_id=None, ostype_desc=None, template_filter="featured", + template_type='BUILTIN', template_id=None, template_name=None, + account=None, domain_id=None, project_id=None, hypervisor=None): ''' @Name : get_template @Desc : Retrieves the template Information based upon inputs provided @@ -759,20 +761,24 @@ def update_resource_count(apiclient, domainid, accountid=None, ) return + def findSuitableHostForMigration(apiclient, vmid): """Returns a suitable host for VM migration""" suitableHost = None try: hosts = Host.listForMigration(apiclient, virtualmachineid=vmid, - ) + ) except Exception as e: - raise Exception("Exception while getting hosts list suitable for migration: %s" % e) + raise Exception( + "Exception while getting hosts list suitable for migration: %s" % + e) suitablehosts = [] if isinstance(hosts, list) and len(hosts) > 0: - suitablehosts = [host for host in hosts if (str(host.resourcestate).lower() == "enabled"\ - and str(host.state).lower() == "up")] - if len(suitablehosts)>0: + suitablehosts = [host for host in hosts + if (str(host.resourcestate).lower() == "enabled" + and str(host.state).lower() == "up")] + if len(suitablehosts) > 0: suitableHost = suitablehosts[0] return suitableHost @@ -798,10 +804,10 @@ def get_resource_type(resource_id): return lookup[resource_id] - def get_free_vlan(apiclient, zoneid): """ - Find an unallocated VLAN outside the range allocated to the physical network. + Find an unallocated VLAN outside the range + allocated to the physical network. @note: This does not guarantee that the VLAN is available for use in the deployment's network gear @@ -813,7 +819,8 @@ def get_free_vlan(apiclient, zoneid): ) assert isinstance(list_physical_networks_response, list) assert len( - list_physical_networks_response) > 0, "No physical networks found in zone %s" % zoneid + list_physical_networks_response) > 0,\ + "No physical networks found in zone %s" % zoneid physical_network = list_physical_networks_response[0] @@ -836,7 +843,8 @@ def get_free_vlan(apiclient, zoneid): assert len(vlans) > 0 assert int(vlans[0]) < int( - vlans[-1]), "VLAN range %s was improperly split" % physical_network.vlan + vlans[-1]), "VLAN range %s was improperly split"\ + % physical_network.vlan # Assuming random function will give different integer each time retriesCount = 20 @@ -864,7 +872,8 @@ def get_free_vlan(apiclient, zoneid): def setNonContiguousVlanIds(apiclient, zoneid): """ - Form the non contiguous ranges based on currently assigned range in physical network + Form the non contiguous ranges based on currently + assigned range in physical network """ NonContigVlanIdsAcquired = False @@ -875,7 +884,8 @@ def setNonContiguousVlanIds(apiclient, zoneid): ) assert isinstance(list_physical_networks_response, list) assert len( - list_physical_networks_response) > 0, "No physical networks found in zone %s" % zoneid + list_physical_networks_response) > 0, \ + "No physical networks found in zone %s" % zoneid for physical_network in list_physical_networks_response: @@ -883,26 +893,30 @@ def setNonContiguousVlanIds(apiclient, zoneid): assert len(vlans) > 0 assert int(vlans[0]) < int( - vlans[-1]), "VLAN range %s was improperly split" % physical_network.vlan + vlans[-1]), "VLAN range %s was improperly split"\ + % physical_network.vlan - # Keep some gap between existing vlan and the new vlans which we are going to add + # Keep some gap between existing vlan and the new vlans + # which we are going to add # So that they are non contiguous non_contig_end_vlan_id = int(vlans[-1]) + 6 non_contig_start_vlan_id = int(vlans[0]) - 6 - # Form ranges which are consecutive to existing ranges but not immediately contiguous - # There should be gap in between existing range and new non contiguous - # ranage - - # If you can't add range after existing range, because it's crossing 4095, then - # select VLAN ids before the existing range such that they are greater than 0, and + # Form ranges which are consecutive to existing ranges but + # not immediately contiguous + # There should be gap in between existing range + # and new non contiguous range + # If you can't add range after existing range, + # because it's crossing 4095, then select VLAN ids before + # the existing range such that they are greater than 0, and # then add this non contiguoud range vlan = {"partial_range": ["", ""], "full_range": ""} if non_contig_end_vlan_id < 4095: vlan["partial_range"][0] = str( - non_contig_end_vlan_id - 4) + '-' + str(non_contig_end_vlan_id - 3) + non_contig_end_vlan_id - 4) + '-' + str(non_contig_end_vlan_id + - 3) vlan["partial_range"][1] = str( non_contig_end_vlan_id - 1) + '-' + str(non_contig_end_vlan_id) vlan["full_range"] = str( @@ -910,12 +924,15 @@ def setNonContiguousVlanIds(apiclient, zoneid): NonContigVlanIdsAcquired = True elif non_contig_start_vlan_id > 0: - vlan["partial_range"][0] = str( - non_contig_start_vlan_id) + '-' + str(non_contig_start_vlan_id + 1) - vlan["partial_range"][1] = str( - non_contig_start_vlan_id + 3) + '-' + str(non_contig_start_vlan_id + 4) - vlan["full_range"] = str( - non_contig_start_vlan_id) + '-' + str(non_contig_start_vlan_id + 4) + vlan["partial_range"][0] = \ + str(non_contig_start_vlan_id) \ + + '-' + str(non_contig_start_vlan_id + 1) + vlan["partial_range"][1] = \ + str(non_contig_start_vlan_id + 3) \ + + '-' + str(non_contig_start_vlan_id + 4) + vlan["full_range"] = \ + str(non_contig_start_vlan_id) \ + + '-' + str(non_contig_start_vlan_id + 4) NonContigVlanIdsAcquired = True else: @@ -930,7 +947,8 @@ def setNonContiguousVlanIds(apiclient, zoneid): else: break - # If even through looping from all existing physical networks, failed to get relevant non + # If even through looping from all existing physical networks, + # failed to get relevant non # contiguous vlan ids, then fail the test case if not NonContigVlanIdsAcquired: @@ -938,84 +956,111 @@ def setNonContiguousVlanIds(apiclient, zoneid): return physical_network, vlan + def is_public_ip_in_correct_state(apiclient, ipaddressid, state): """ Check if the given IP is in the correct state (given) and return True/False accordingly""" retriesCount = 10 while True: portableips = PublicIPAddress.list(apiclient, id=ipaddressid) - assert validateList(portableips)[0] == PASS, "IPs list validation failed" + assert validateList( + portableips)[0] == PASS, "IPs list validation failed" if str(portableips[0].state).lower() == state: break elif retriesCount == 0: - return False + return False else: retriesCount -= 1 time.sleep(60) continue return True -def setSharedNetworkParams(networkServices, range=20): - """Fill up the services dictionary for shared network using random subnet""" - # @range: range decides the endip. Pass the range as "x" if you want the difference between the startip +def setSharedNetworkParams(networkServices, range=20): + """Fill up the services dictionary for shared network + using random subnet + """ + + # @range: range decides the endip. Pass the range as "x" + # if you want the difference between the startip # and endip as "x" # Set the subnet number of shared networks randomly prior to execution # of each test case to avoid overlapping of ip addresses - shared_network_subnet_number = random.randrange(1,254) + shared_network_subnet_number = random.randrange(1, 254) - networkServices["gateway"] = "172.16."+str(shared_network_subnet_number)+".1" - networkServices["startip"] = "172.16."+str(shared_network_subnet_number)+".2" - networkServices["endip"] = "172.16."+str(shared_network_subnet_number)+"."+str(range+1) + networkServices["gateway"] = "172.16." + \ + str(shared_network_subnet_number) + ".1" + networkServices["startip"] = "172.16." + \ + str(shared_network_subnet_number) + ".2" + networkServices["endip"] = "172.16." + \ + str(shared_network_subnet_number) + "." + str(range + 1) networkServices["netmask"] = "255.255.255.0" return networkServices + def createEnabledNetworkOffering(apiclient, networkServices): """Create and enable network offering according to the type @output: List, containing [ Result,Network Offering,Reason ] - Ist Argument('Result') : FAIL : If exception or assertion error occurs + Ist Argument('Result') : FAIL : If exception or assertion + error occurs PASS : If network offering is created and enabled successfully IInd Argument(Net Off) : Enabled network offering In case of exception or - assertion error, it will be None + assertion error, it will be + None IIIrd Argument(Reason) : Reason for failure, default to None """ try: resultSet = [FAIL, None, None] # Create network offering - network_offering = NetworkOffering.create(apiclient, networkServices, conservemode=False) + network_offering = NetworkOffering.create( + apiclient, + networkServices, + conservemode=False) # Update network offering state from disabled to enabled. - NetworkOffering.update(network_offering, apiclient, id=network_offering.id, + NetworkOffering.update(network_offering, + apiclient, id=network_offering.id, state="enabled") except Exception as e: resultSet[2] = e return resultSet return [PASS, network_offering, None] + def shouldTestBeSkipped(networkType, zoneType): """Decide which test to skip, according to type of network and zone type""" - # If network type is isolated or vpc and zone type is basic, then test should be skipped + # If network type is isolated or vpc and zone type is basic, then test + # should be skipped skipIt = False - if ((networkType.lower() == str(ISOLATED_NETWORK).lower() or networkType.lower() == str(VPC_NETWORK).lower()) - and (zoneType.lower() == BASIC_ZONE)): + if (networkType.lower() == str(ISOLATED_NETWORK).lower() or + networkType.lower() == str(VPC_NETWORK).lower()) and\ + (zoneType.lower() == BASIC_ZONE): skipIt = True return skipIt + def verifyNetworkState(apiclient, networkid, state): """List networks and check if the network state matches the given state""" try: networks = Network.list(apiclient, id=networkid) except Exception as e: - raise Exception("Failed while fetching network list with error: %s" % e) - assert validateList(networks)[0] == PASS, "Networks list validation failed, list is %s" % networks - assert str(networks[0].state).lower() == state, "network state should be %s, it is %s" % (state, networks[0].state) + raise Exception( + "Failed while fetching network list with error: %s" % + e) + assert validateList( + networks)[0] == PASS, "Networks list validation failed, list is %s"\ + % networks + assert str(networks[0].state).lower( + ) == state, "network state should be %s, it is %s" \ + % (state, networks[0].state) return + def verifyComputeOfferingCreation(apiclient, computeofferingid): """List Compute offerings by ID and verify that the offering exists""" @@ -1025,11 +1070,12 @@ def verifyComputeOfferingCreation(apiclient, computeofferingid): try: serviceOfferings = apiclient.listServiceOfferings(cmd) except Exception: - return FAIL + return FAIL if not (isinstance(serviceOfferings, list) and len(serviceOfferings) > 0): - return FAIL + return FAIL return PASS + def createNetworkRulesForVM(apiclient, virtualmachine, ruletype, account, networkruledata): """Acquire IP, create Firewall and NAT/StaticNAT rule @@ -1037,26 +1083,28 @@ def createNetworkRulesForVM(apiclient, virtualmachine, ruletype, try: public_ip = PublicIPAddress.create( - apiclient,accountid=account.name, - zoneid=virtualmachine.zoneid,domainid=account.domainid, - networkid=virtualmachine.nic[0].networkid) + apiclient, accountid=account.name, + zoneid=virtualmachine.zoneid, domainid=account.domainid, + networkid=virtualmachine.nic[0].networkid) FireWallRule.create( - apiclient,ipaddressid=public_ip.ipaddress.id, + apiclient, ipaddressid=public_ip.ipaddress.id, protocol='TCP', cidrlist=[networkruledata["fwrule"]["cidr"]], startport=networkruledata["fwrule"]["startport"], endport=networkruledata["fwrule"]["endport"] - ) + ) if ruletype == NAT_RULE: # Create NAT rule NATRule.create(apiclient, virtualmachine, - networkruledata["natrule"],ipaddressid=public_ip.ipaddress.id, - networkid=virtualmachine.nic[0].networkid) + networkruledata[ + "natrule"], ipaddressid=public_ip.ipaddress.id, + networkid=virtualmachine.nic[0].networkid) elif ruletype == STATIC_NAT_RULE: # Enable Static NAT for VM - StaticNATRule.enable(apiclient,public_ip.ipaddress.id, - virtualmachine.id, networkid=virtualmachine.nic[0].networkid) + StaticNATRule.enable(apiclient, public_ip.ipaddress.id, + virtualmachine.id, + networkid=virtualmachine.nic[0].networkid) except Exception as e: [FAIL, e] return [PASS, public_ip] diff --git a/tools/marvin/marvin/lib/utils.py b/tools/marvin/marvin/lib/utils.py index cb5dcfbd810..5178f5dec82 100644 --- a/tools/marvin/marvin/lib/utils.py +++ b/tools/marvin/marvin/lib/utils.py @@ -33,13 +33,14 @@ from platform import system from marvin.cloudstackException import GetDetailExceptionInfo from marvin.sshClient import SshClient from marvin.codes import ( - SUCCESS, - FAIL, - PASS, - MATCH_NOT_FOUND, - INVALID_INPUT, - EMPTY_LIST, - FAILED) + SUCCESS, + FAIL, + PASS, + MATCH_NOT_FOUND, + INVALID_INPUT, + EMPTY_LIST, + FAILED) + def restart_mgmt_server(server): """Restarts the management server""" @@ -121,7 +122,9 @@ def cleanup_resources(api_client, resources): obj.delete(api_client) -def is_server_ssh_ready(ipaddress, port, username, password, retries=20, retryinterv=30, timeout=10.0, keyPairFileLocation=None): +def is_server_ssh_ready(ipaddress, port, username, password, + retries=20, retryinterv=30, + timeout=10.0, keyPairFileLocation=None): ''' @Name: is_server_ssh_ready @Input: timeout: tcp connection timeout flag, @@ -141,8 +144,10 @@ def is_server_ssh_ready(ipaddress, port, username, password, retries=20, retryin retries=retries, delay=retryinterv, timeout=timeout) - except Exception, e: - raise Exception("SSH connection has Failed. Waited %ss. Error is %s" % (retries * retryinterv, str(e))) + except Exception as e: + raise Exception( + "SSH connection has Failed. Waited %ss. Error is %s" % + (retries * retryinterv, str(e))) else: return ssh @@ -171,6 +176,7 @@ def fetch_api_client(config_file='datacenterCfg'): ) ) + def get_host_credentials(config, hostip): """Get login information for a host `hostip` (ipv4) from marvin's `config` @@ -186,26 +192,35 @@ def get_host_credentials(config, hostip): try: if socket.getfqdn(hostip) == socket.getfqdn(hostname): return host.username, host.password - except socket.error, e: - raise Exception("Unresolvable host %s error is %s" % (hostip, e)) - raise KeyError("Please provide the marvin configuration file with credentials to your hosts") + except socket.error as e: + raise Exception( + "Unresolvable host %s error is %s" % + (hostip, e)) + raise KeyError( + "Please provide the marvin configuration file " + "with credentials to your hosts") -def get_process_status(hostip, port, username, password, linklocalip, process, hypervisor=None): +def get_process_status( + hostip, port, username, password, + linklocalip, process, hypervisor=None): """Double hop and returns a process status""" - #SSH to the machine + # SSH to the machine ssh = SshClient(hostip, port, username, password) if (str(hypervisor).lower() == 'vmware' - or str(hypervisor).lower() == 'hyperv'): - ssh_command = "ssh -i /var/cloudstack/management/.ssh/id_rsa -ostricthostkeychecking=no " + or str(hypervisor).lower() == 'hyperv'): + ssh_command =\ + "ssh -i /var/cloudstack/management/" \ + ".ssh/id_rsa -ostricthostkeychecking=no " else: - ssh_command = "ssh -i ~/.ssh/id_rsa.cloud -ostricthostkeychecking=no " + ssh_command = "ssh -i ~/.ssh/id_rsa.cloud " \ + "-ostricthostkeychecking=no " ssh_command = ssh_command +\ - "-oUserKnownHostsFile=/dev/null -p 3922 %s %s" % ( - linklocalip, - process) + "-oUserKnownHostsFile=/dev/null -p 3922 %s %s" % ( + linklocalip, + process) # Double hop into router timeout = 5 @@ -242,12 +257,13 @@ def xsplit(txt, seps): @return: list of split units """ default_sep = seps[0] - for sep in seps[1:]: # we skip seps[0] because that's the default separator + # we skip seps[0] because that's the default separator + for sep in seps[1:]: txt = txt.replace(sep, default_sep) return [i.strip() for i in txt.split(default_sep)] -def get_hypervisor_type(apiclient): +def get_hypervisor_type(apiclient): """Return the hypervisor type of the hosts in setup""" cmd = listHosts.listHostsCmd() @@ -255,62 +271,79 @@ def get_hypervisor_type(apiclient): cmd.listall = True hosts = apiclient.listHosts(cmd) hosts_list_validation_result = validateList(hosts) - assert hosts_list_validation_result[0] == PASS, "host list validation failed" + assert hosts_list_validation_result[ + 0] == PASS, "host list validation failed" return hosts_list_validation_result[1].hypervisor + def is_snapshot_on_nfs(apiclient, dbconn, config, zoneid, snapshotid): """ - Checks whether a snapshot with id (not UUID) `snapshotid` is present on the nfs storage + Checks whether a snapshot with id + (not UUID) `snapshotid` is present on the nfs storage @param apiclient: api client connection @param @dbconn: connection to the cloudstack db @param config: marvin configuration file - @param zoneid: uuid of the zone on which the secondary nfs storage pool is mounted + @param zoneid: uuid of the zone on which the + secondary nfs storage pool is mounted @param snapshotid: uuid of the snapshot @return: True if snapshot is found, False otherwise """ # snapshot extension to be appended to the snapshot path obtained from db snapshot_extensions = {"vmware": ".ovf", - "kvm": "", - "xenserver": ".vhd", - "simulator":""} + "kvm": "", + "xenserver": ".vhd", + "simulator": ""} qresultset = dbconn.execute( - "select id from snapshots where uuid = '%s';" \ - % str(snapshotid) - ) + "select id from snapshots where uuid = '%s';" + % str(snapshotid) + ) if len(qresultset) == 0: raise Exception( "No snapshot found in cloudstack with id %s" % snapshotid) - snapshotid = qresultset[0][0] qresultset = dbconn.execute( - "select install_path,store_id from snapshot_store_ref where snapshot_id='%s' and store_role='Image';" % snapshotid + "select install_path,store_id from snapshot_store_ref" + " where snapshot_id='%s' and " + "store_role='Image';" % snapshotid ) - assert isinstance(qresultset, list), "Invalid db query response for snapshot %s" % snapshotid + assert isinstance( + qresultset, list), "Invalid db query " \ + "response for snapshot " \ + "%s" % snapshotid if len(qresultset) == 0: - #Snapshot does not exist + # Snapshot does not exist return False from base import ImageStore - #pass store_id to get the exact storage pool where snapshot is stored - secondaryStores = ImageStore.list(apiclient, zoneid=zoneid, id=int(qresultset[0][1])) + # pass store_id to get the exact storage pool where snapshot is stored + secondaryStores = ImageStore.list( + apiclient, + zoneid=zoneid, + id=int( + qresultset[0][1])) - assert isinstance(secondaryStores, list), "Not a valid response for listImageStores" - assert len(secondaryStores) != 0, "No image stores found in zone %s" % zoneid + assert isinstance( + secondaryStores, list), "Not a valid response for listImageStores" + assert len( + secondaryStores) != 0, "No image stores found in zone %s" % zoneid secondaryStore = secondaryStores[0] if str(secondaryStore.providername).lower() != "nfs": raise Exception( - "is_snapshot_on_nfs works only against nfs secondary storage. found %s" % str(secondaryStore.providername)) + "is_snapshot_on_nfs works only " + "against nfs secondary storage." + " found %s" % str(secondaryStore.providername)) hypervisor = get_hypervisor_type(apiclient) # append snapshot extension based on hypervisor, to the snapshot path - snapshotPath = str(qresultset[0][0]) + snapshot_extensions[str(hypervisor).lower()] + snapshotPath = str(qresultset[0][0]) + \ + snapshot_extensions[str(hypervisor).lower()] nfsurl = secondaryStore.url from urllib2 import urlparse @@ -318,8 +351,11 @@ def is_snapshot_on_nfs(apiclient, dbconn, config, zoneid, snapshotid): host, path = parse_url.netloc, parse_url.path if not config.mgtSvr: - raise Exception("Your marvin configuration does not contain mgmt server credentials") - mgtSvr, user, passwd = config.mgtSvr[0].mgtSvrIp, config.mgtSvr[0].user, config.mgtSvr[0].passwd + raise Exception( + "Your marvin configuration does " + "not contain mgmt server credentials") + mgtSvr, user, passwd = config.mgtSvr[ + 0].mgtSvrIp, config.mgtSvr[0].user, config.mgtSvr[0].passwd try: ssh_client = SshClient( @@ -329,32 +365,33 @@ def is_snapshot_on_nfs(apiclient, dbconn, config, zoneid, snapshotid): passwd ) cmds = [ - "mkdir -p %s /mnt/tmp", - "mount -t %s %s%s /mnt/tmp" % ( - 'nfs', - host, - path, - ), - "test -f %s && echo 'snapshot exists'" % ( - os.path.join("/mnt/tmp", snapshotPath) - ), - ] + "mkdir -p %s /mnt/tmp", + "mount -t %s %s%s /mnt/tmp" % ( + 'nfs', + host, + path, + ), + "test -f %s && echo 'snapshot exists'" % ( + os.path.join("/mnt/tmp", snapshotPath) + ), + ] for c in cmds: result = ssh_client.execute(c) # Unmount the Sec Storage cmds = [ - "cd", - "umount /mnt/tmp", - ] + "cd", + "umount /mnt/tmp", + ] for c in cmds: ssh_client.execute(c) except Exception as e: raise Exception("SSH failed for management server: %s - %s" % - (config.mgtSvr[0].mgtSvrIp, e)) + (config.mgtSvr[0].mgtSvrIp, e)) return 'snapshot exists' in result + def validateList(inp): """ @name: validateList @@ -388,7 +425,8 @@ def validateList(inp): return ret return [PASS, inp[0], None] -def verifyElementInList(inp, toverify, responsevar=None, pos=0): + +def verifyElementInList(inp, toverify, responsevar=None, pos=0): ''' @name: verifyElementInList @Description: @@ -400,9 +438,9 @@ def verifyElementInList(inp, toverify, responsevar=None, pos=0): at a given pos @Input: I : Input to be verified whether its a list or not - II : Element to verify whether it exists in the list - III : variable name in response object to verify - default to None, if None, we will verify for the complete + II : Element to verify whether it exists in the list + III : variable name in response object to verify + default to None, if None, we will verify for the complete first element EX: state of response object object IV : Position in the list at which the input element to verify default to 0 @@ -425,25 +463,29 @@ def verifyElementInList(inp, toverify, responsevar=None, pos=0): return [FAIL, out[2]] if len(inp) > pos: if responsevar is None: - if inp[pos] == toverify: - return [PASS, None] + if inp[pos] == toverify: + return [PASS, None] else: - if responsevar in inp[pos].__dict__ and getattr(inp[pos], responsevar) == toverify: - return [PASS, None] - else: - return [FAIL, MATCH_NOT_FOUND] + if responsevar in inp[pos].\ + __dict__ and getattr(inp[pos], responsevar) == toverify: + return [PASS, None] + else: + return [FAIL, MATCH_NOT_FOUND] else: return [FAIL, MATCH_NOT_FOUND] + def checkVolumeSize(ssh_handle=None, volume_name="/dev/sda", cmd_inp="/sbin/fdisk -l | grep Disk", size_to_verify=0): ''' @Name : getDiskUsage - @Desc : provides facility to verify the volume size against the size to verify + @Desc : provides facility to verify the + volume size against the size to verify @Input: 1. ssh_handle : machine against which to execute the disk size cmd - 2. volume_name : The name of the volume against which to verify the size + 2. volume_name : The name of the volume + against which to verify the size 3. cmd_inp : Input command used to veify the size 4. size_to_verify: size against which to compare. @Output: Returns FAILED in case of an issue, else SUCCESS @@ -465,14 +507,14 @@ def checkVolumeSize(ssh_handle=None, if volume_name in line: parts = line.split() if str(parts[-2]) == str(size_to_verify): - return [SUCCESS,str(parts[-2])] - return [FAILED,"Volume Not Found"] - except Exception, e: + return [SUCCESS, str(parts[-2])] + return [FAILED, "Volume Not Found"] + except Exception as e: print "\n Exception Occurred under getDiskUsage: " \ - "%s" %GetDetailExceptionInfo(e) - return [FAILED,GetDetailExceptionInfo(e)] + "%s" % GetDetailExceptionInfo(e) + return [FAILED, GetDetailExceptionInfo(e)] + - def verifyRouterState(apiclient, routerid, allowedstates): """List the router and verify that its state is in allowed states @output: List, containing [Result, Reason] @@ -492,7 +534,7 @@ def verifyRouterState(apiclient, routerid, allowedstates): if listvalidationresult[0] == FAIL: return [FAIL, listvalidationresult[2]] if routers[0].redundantstate not in allowedstates: - return [FAIL, "Redundant state of the router should be in %s but is %s" % - (allowedstates, routers[0].redundantstate)] + return [FAIL, "Redundant state of the" + " router should be in %s but is %s" % + (allowedstates, routers[0].redundantstate)] return [PASS, None] - \ No newline at end of file diff --git a/tools/marvin/marvin/marvinInit.py b/tools/marvin/marvin/marvinInit.py index c35fec6adc1..de580ceb964 100644 --- a/tools/marvin/marvin/marvinInit.py +++ b/tools/marvin/marvin/marvinInit.py @@ -134,11 +134,11 @@ class MarvinInit: ''' try: if ((self.__parseConfig() != FAILED) and - (self.__setHypervisorAndZoneInfo())and - (self.__setTestDataPath() != FAILED) and - (self.__initLogging() != FAILED) and - (self.__createTestClient() != FAILED) and - (self.__deployDC() != FAILED)): + (self.__setHypervisorAndZoneInfo())and + (self.__setTestDataPath() != FAILED) and + (self.__initLogging() != FAILED) and + (self.__createTestClient() != FAILED) and + (self.__deployDC() != FAILED)): return SUCCESS return FAILED except Exception as e: @@ -187,7 +187,8 @@ class MarvinInit: try: mgt_details = self.__parsedConfig.mgtSvr[0] dbsvr_details = self.__parsedConfig.dbSvr - self.__testClient = CSTestClient(mgt_details, dbsvr_details, + self.__testClient = CSTestClient(mgt_details, + dbsvr_details, logger=self.__tcRunLogger, test_data_filepath= self.__testDataFilePath, diff --git a/tools/marvin/marvin/marvinPlugin.py b/tools/marvin/marvin/marvinPlugin.py index 4200a657e71..c817cd69535 100644 --- a/tools/marvin/marvin/marvinPlugin.py +++ b/tools/marvin/marvin/marvinPlugin.py @@ -302,6 +302,6 @@ class MarvinPlugin(Plugin): cmd = "mv " + src + " " + dst os.system(cmd) print "===final results are now copied to: %s===" % str(dst) - except Exception, e: + except Exception as e: print "=== Exception occurred under finalize :%s ===" % \ str(GetDetailExceptionInfo(e)) diff --git a/tools/marvin/marvin/sshClient.py b/tools/marvin/marvin/sshClient.py index 611c8b5312c..76f3b6dd597 100644 --- a/tools/marvin/marvin/sshClient.py +++ b/tools/marvin/marvin/sshClient.py @@ -204,9 +204,9 @@ class SshClient(object): self.close() def close(self): - if self.ssh is not None: - self.ssh.close() - self.ssh = None + if self.ssh is not None: + self.ssh.close() + self.ssh = None if __name__ == "__main__":