diff --git a/test/integration/component/test_deploy_vgpu_vm.py b/test/integration/component/test_deploy_vgpu_vm.py index 0284eab1f9a..15ad2d94391 100644 --- a/test/integration/component/test_deploy_vgpu_vm.py +++ b/test/integration/component/test_deploy_vgpu_vm.py @@ -15,323 +15,375 @@ # specific language governing permissions and limitations # under the License. -#Test from the Marvin - Testing in Python wiki +# Test from the Marvin - Testing in Python wiki -#All tests inherit from cloudstackTestCase +# All tests inherit from cloudstackTestCase from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.cloudstackAPI import changeServiceForVirtualMachine,updateServiceOffering,listConfigurations,startVirtualMachine +from marvin.cloudstackAPI import changeServiceForVirtualMachine, startVirtualMachine -#Import Integration Libraries +# Import Integration Libraries -#base - contains all resources as entities and defines create, delete, list operations on them -from marvin.lib.base import Account, VirtualMachine, ServiceOffering , Template , Host, VmSnapshot +# base - contains all resources as entities and defines create, delete, +# list operations on them +from marvin.lib.base import Account, VirtualMachine, ServiceOffering, Template, Host, VmSnapshot -#utils - utility classes for common cleanup, external library wrappers etc -from marvin.lib.utils import cleanup_resources,random_gen +# utils - utility classes for common cleanup, external library wrappers etc +from marvin.lib.utils import cleanup_resources -#common - commonly used methods for all tests are listed here -from marvin.lib.common import get_zone, get_domain, get_template, list_hosts ,list_service_offering, get_windows_template, get_pod, list_clusters, list_virtual_machines +# common - commonly used methods for all tests are listed here +from marvin.lib.common import get_zone, get_domain, list_hosts, list_service_offering, get_windows_template, get_pod, list_clusters, list_virtual_machines from marvin.sshClient import SshClient -from marvin.codes import FAILED, XEN_SERVER +from marvin.codes import FAILED from nose.plugins.attrib import attr import time + class TestvGPUWindowsVm(cloudstackTestCase): + """ Testing vGPU VM with All vGPU service offerings """ @classmethod def setUpClass(cls): - testClient = super(TestvGPUWindowsVm, cls).getClsTestClient() + cls.testClient = super(TestvGPUWindowsVm, cls).getClsTestClient() cls.testdata = cls.testClient.getParsedTestDataConfig() cls.apiclient = cls.testClient.getApiClient() cls._cleanup = [] cls.cleanup = [] hosts = list_hosts( - cls.apiclient, - hypervisor="XenServer" - ) + cls.apiclient, + hypervisor="XenServer" + ) if hosts is None: - raise unittest.SkipTest("There are no XenServers available. GPU feature is supported only on XenServer.Check listhosts response") + raise unittest.SkipTest( + "There are no XenServers available. GPU feature is supported only on XenServer.Check listhosts response") else: - cls.k140qgpuhosts=0 - cls.k120qgpuhosts=0 - cls.k100gpuhosts=0 - cls.k260qgpuhosts=0 - cls.k240qgpuhosts=0 - cls.k220qgpuhosts=0 - cls.k200gpuhosts=0 - cls.k1passthroughgpuhosts=0 - cls.k2passthroughgpuhosts=0 - cls.nongpuhosts=[] - cls.k2hosts=0 - cls.k1hosts=0 - cls.k100_vgpu_service_offering=[] - cls.k200_vgpu_service_offering=[] - cls.nonvgpu_service_offering=[] - cls.vm_k1_card=[] - cls.vm_k2_card=[] - cls.vm2_k2_card=[] - cls.nonvgpu=[] - cls.vmlifecycletest=0 - cls.vmsnapwomemory=0 - cls.vmsnapwithmemory=0 + cls.k140qgpuhosts = 0 + cls.k120qgpuhosts = 0 + cls.k100gpuhosts = 0 + cls.k260qgpuhosts = 0 + cls.k240qgpuhosts = 0 + cls.k220qgpuhosts = 0 + cls.k200gpuhosts = 0 + cls.k1passthroughgpuhosts = 0 + cls.k2passthroughgpuhosts = 0 + cls.nongpuhosts = [] + cls.k2hosts = 0 + cls.k1hosts = 0 + cls.k100_vgpu_service_offering = [] + cls.k200_vgpu_service_offering = [] + cls.nonvgpu_service_offering = [] + cls.vm_k1_card = [] + cls.vm_k2_card = [] + cls.vm2_k2_card = [] + cls.nonvgpu = [] + cls.vmlifecycletest = 0 + cls.vmsnapwomemory = 0 + cls.vmsnapwithmemory = 0 - for ghost in hosts : - if ghost.hypervisorversion >= "6.2.0": + for ghost in hosts: + if ghost.hypervisorversion >= "6.2.0": - sshClient = SshClient(host=ghost.ipaddress, port=22, user='root',passwd=cls.testdata["host_password"]) + sshClient = SshClient( + host=ghost.ipaddress, + port=cls.testdata['configurableData']['host']["publicport"], + user=cls.testdata['configurableData']['host']["username"], + passwd=cls.testdata['configurabledata']['host']["password"]) if ghost.hypervisorversion == "6.2.0": - res = len(sshClient.execute("xe patch-list uuid=0850b186-4d47-11e3-a720-001b2151a503")) - if res == 0: - continue - k1card= len(sshClient.execute("lspci | grep \"GRID K1\"")) - k2card= len(sshClient.execute("lspci | grep \"GRID K2\"")) - cls.debug("k1 card and k2 card details are :%s %s "%(k1card,k2card)) - if (k2card==0) and (k1card==0): - cls.nongpuhosts.append(ghost.ipaddress) - if k2card !=0: - cls.k2hosts=cls.k2hosts+1 - k260q = len(sshClient.execute("xe vgpu-type-list model-name=\"GRID K260Q\"")) - k240q = len(sshClient.execute("xe vgpu-type-list model-name=\"GRID K240Q\"")) - k220q = len(sshClient.execute("xe vgpu-type-list model-name=\"GRID K220Q\"")) - k200 = len(sshClient.execute("xe vgpu-type-list model-name=\"GRID K200\"")) - k2passthrough = len(sshClient.execute("xe vgpu-type-list model-name='passthrough'")) - if ((k260q==0) and (k240q==0) and (k220q==0) and (k200==0) and (k2passthrough== 0)): - continue - else: - if k260q != 0 : - cls.k260qgpuhosts=cls.k260qgpuhosts+1 - if k240q != 0 : - cls.k240qgpuhosts=cls.k240qgpuhosts+1 - if k220q != 0 : - cls.k220qgpuhosts=cls.k220qgpuhosts+1 - if k200 != 0 : - cls.k200gpuhosts=cls.k200gpuhosts+1 - if k2passthrough != 0: - cls.k2passthroughgpuhosts=cls.k2passthroughgpuhosts+1 + res = len( + sshClient.execute("xe patch-list uuid=0850b186-4d47-11e3-a720-001b2151a503")) + if res == 0: + continue + k1card = len(sshClient.execute("lspci | grep \"GRID K1\"")) + k2card = len(sshClient.execute("lspci | grep \"GRID K2\"")) + cls.debug( + "k1 card and k2 card details are :%s %s " % + (k1card, k2card)) + if (k2card == 0) and (k1card == 0): + cls.nongpuhosts.append(ghost.ipaddress) + if k2card != 0: + cls.k2hosts = cls.k2hosts + 1 + k260q = len( + sshClient.execute("xe vgpu-type-list model-name=\"GRID K260Q\"")) + k240q = len( + sshClient.execute("xe vgpu-type-list model-name=\"GRID K240Q\"")) + k220q = len( + sshClient.execute("xe vgpu-type-list model-name=\"GRID K220Q\"")) + k200 = len( + sshClient.execute("xe vgpu-type-list model-name=\"GRID K200\"")) + k2passthrough = len( + sshClient.execute("xe vgpu-type-list model-name='passthrough'")) + if ((k260q == 0) and (k240q == 0) and (k220q == 0) + and (k200 == 0) and (k2passthrough == 0)): + continue + else: + if k260q != 0: + cls.k260qgpuhosts = cls.k260qgpuhosts + 1 + if k240q != 0: + cls.k240qgpuhosts = cls.k240qgpuhosts + 1 + if k220q != 0: + cls.k220qgpuhosts = cls.k220qgpuhosts + 1 + if k200 != 0: + cls.k200gpuhosts = cls.k200gpuhosts + 1 + if k2passthrough != 0: + cls.k2passthroughgpuhosts = cls.k2passthroughgpuhosts + \ + 1 if k1card != 0: - cls.k1hosts=cls.k1hosts+1 - k100 = len(sshClient.execute("xe vgpu-type-list model-name=\"GRID K100\"")) - k120q = len(sshClient.execute("xe vgpu-type-list model-name=\"GRID K120Q\"")) - k140q = len(sshClient.execute("xe vgpu-type-list model-name=\"GRID K140Q\"")) - k1passthrough = len(sshClient.execute("xe vgpu-type-list model-name='passthrough'")) - if ((k100 == 0) and (k120q == 0) and (k140q == 0) and (k1passthrough == 0)): - continue - else: - if k140q != 0 : - cls.k140qgpuhosts=cls.k140qgpuhosts+1 - if k120q != 0 : - cls.k120qgpuhosts=cls.k120qgpuhosts+1 - if k100 != 0 : - cls.k100gpuhosts=cls.k100gpuhosts+1 - if k1passthrough != 0 : - cls.k1passthroughgpuhosts=cls.k1passthroughgpuhosts+1 + cls.k1hosts = cls.k1hosts + 1 + k100 = len( + sshClient.execute("xe vgpu-type-list model-name=\"GRID K100\"")) + k120q = len( + sshClient.execute("xe vgpu-type-list model-name=\"GRID K120Q\"")) + k140q = len( + sshClient.execute("xe vgpu-type-list model-name=\"GRID K140Q\"")) + k1passthrough = len( + sshClient.execute("xe vgpu-type-list model-name='passthrough'")) + if ((k100 == 0) and (k120q == 0) and ( + k140q == 0) and (k1passthrough == 0)): + continue + else: + if k140q != 0: + cls.k140qgpuhosts = cls.k140qgpuhosts + 1 + if k120q != 0: + cls.k120qgpuhosts = cls.k120qgpuhosts + 1 + if k100 != 0: + cls.k100gpuhosts = cls.k100gpuhosts + 1 + if k1passthrough != 0: + cls.k1passthroughgpuhosts = cls.k1passthroughgpuhosts + \ + 1 if (cls.k2hosts == 0) and (cls.k1hosts == 0): - raise unittest.SkipTest("No XenServer available with GPU Drivers installed") + raise unittest.SkipTest( + "No XenServer available with GPU Drivers installed") cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) cls.domain = get_domain(cls.apiclient) cls.pod = get_pod(cls.apiclient, cls.zone.id) cls.account = Account.create( - cls.apiclient, - cls.testdata["account"], - domainid=cls.domain.id - ) + cls.apiclient, + cls.testdata["account"], + domainid=cls.domain.id + ) - cls.template = get_windows_template(cls.apiclient, cls.zone.id ,ostype_desc="Windows 8 (64-bit)") + cls.template = get_windows_template( + cls.apiclient, + cls.zone.id, + ostype_desc="Windows 8 (64-bit)") #cls.template = get_windows_template(cls.apiclient, cls.zone.id ,ostype_desc="Windows Server 2012 (64-bit)") - if cls.template == FAILED: - if "http://pleaseupdateURL/dummy.vhd" in cls.testdata["vgpu"] ["templateregister1"]["url"]: - raise unittest.SkipTest("Check Test Data file if it has the valid template URL") + if cls.template == FAILED: + if "http://pleaseupdateURL/dummy.vhd" in cls.testdata[ + "vgpu"]["templateregister1"]["url"]: + raise unittest.SkipTest( + "Check Test Data file if it has the valid template URL") cls.template = Template.register( - cls.apiclient, - cls.testdata["vgpu"] ["templateregister1"], - hypervisor = "XenServer", - zoneid=cls.zone.id, - domainid=cls.account.domainid, - account=cls.account.name - ) + cls.apiclient, + cls.testdata["vgpu"]["templateregister1"], + hypervisor="XenServer", + zoneid=cls.zone.id, + domainid=cls.account.domainid, + account=cls.account.name + ) timeout = cls.testdata["vgpu"]["timeout"] while True: - time.sleep(cls.testdata["vgpu"]["sleep"]) - list_template_response = Template.list( - cls.apiclient, - templatefilter=\ - cls.testdata["templatefilter"], - id=cls.template.id - ) - if (isinstance(list_template_response, list)) is not True: - raise unittest.SkipTest("Check list template api response returns a valid list") + time.sleep(cls.testdata["vgpu"]["sleep"]) + list_template_response = Template.list( + cls.apiclient, + templatefilter=cls.testdata["templatefilter"], + id=cls.template.id + ) + if (isinstance(list_template_response, list)) is not True: + raise unittest.SkipTest( + "Check list template api response returns a valid list") - if len(list_template_response) is None : - raise unittest.SkipTest("Check template registered is in List Templates") + if len(list_template_response) is None: + raise unittest.SkipTest( + "Check template registered is in List Templates") - template_response = list_template_response[0] - if template_response.isready == True: - break + template_response = list_template_response[0] + if template_response.isready: + break - if timeout == 0: - raise unittest.SkipTest("Failed to download template(ID: %s). " % template_response.id) - - timeout = timeout - 1 + if timeout == 0: + raise unittest.SkipTest( + "Failed to download template(ID: %s). " % + template_response.id) + timeout = timeout - 1 cls._cleanup = [ - cls.account, - #cls.k100_vgpu_service_offering, - #cls.k200_vgpu_service_offering - ] + cls.account, + # cls.k100_vgpu_service_offering, + # cls.k200_vgpu_service_offering + ] - @attr(tags = ['advanced', 'basic', 'vgpu'], required_hardware="true") + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def setUp(self): self.testdata = self.testClient.getParsedTestDataConfig() self.apiclient = self.testClient.getApiClient() self.cleanup = [] return - - def check_host_vgpu_capacity(self,gpucard,gtype): + def check_host_vgpu_capacity(self, gpucard, gtype): gputhosts = list_hosts( - self.apiclient, - hypervisor="XenServer" - ) - vgpucapacity=0 + self.apiclient, + hypervisor="XenServer" + ) + vgpucapacity = 0 for ghost in gputhosts: if ghost.gpugroup is not None: - for gp in ghost.gpugroup: - if gp.gpugroupname == gpucard: - for gptype in gp.vgpu: - if gptype.vgputype == gtype: - vgpucapacity=vgpucapacity+gptype.remainingcapacity + for gp in ghost.gpugroup: + if gp.gpugroupname == gpucard: + for gptype in gp.vgpu: + if gptype.vgputype == gtype: + vgpucapacity = vgpucapacity + \ + gptype.remainingcapacity return(vgpucapacity) + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") + def vgpu_serviceoffering_creation(self, gtype, nvidiamodel): + if gtype == "nonvgpuoffering" and nvidiamodel == "None": + self.service_offering = ServiceOffering.create( + self.apiclient, + self.testdata["vgpu"]["service_offerings"][gtype] + ) + self.debug( + "service offering details are:%s" % + self.service_offering) + list_service_response = ServiceOffering.list( + self.apiclient, + id=self.service_offering.id + ) - @attr(tags = ['advanced', 'basic', 'vgpu'], required_hardware="true") - def vgpu_serviceoffering_creation(self,gtype,nvidiamodel): - if gtype=="nonvgpuoffering" and nvidiamodel=="None": - self.service_offering = ServiceOffering.create( - self.apiclient, - self.testdata["vgpu"]["service_offerings"][gtype] - ) - self.debug("service offering details are:%s"%self.service_offering) - list_service_response = ServiceOffering.list( - self.apiclient, - id=self.service_offering.id - ) + if list_service_response is None: + raise unittest.SkipTest( + "Check Service Offering list for %s service offering" % + (gtype)) - if list_service_response is None: - raise unittest.SkipTest("Check Service Offering list for %s service offering" %(gtype)) - - self.assertEqual( - list_service_response[0].displaytext, - self.testdata["vgpu"]["service_offerings"][gtype]["displaytext"], - "Check server display text in createServiceOfferings" - ) - self.assertEqual( - list_service_response[0].name, - self.testdata["vgpu"]["service_offerings"][gtype]["name"], - "Check name in createServiceOffering" - ) + self.assertEqual( + list_service_response[0].displaytext, + self.testdata["vgpu"]["service_offerings"][gtype]["displaytext"], + "Check server display text in createServiceOfferings") + self.assertEqual( + list_service_response[0].name, + self.testdata["vgpu"]["service_offerings"][gtype]["name"], + "Check name in createServiceOffering" + ) else: - self.testdata["vgpu"]["service_offerings"][gtype]["serviceofferingdetails"] = [{'pciDevice': nvidiamodel}, - {'vgpuType':gtype}] - self.service_offering = ServiceOffering.create( - self.apiclient, - self.testdata["vgpu"]["service_offerings"][gtype] - ) - list_service_response = ServiceOffering.list( - self.apiclient, - id=self.service_offering.id - ) + self.testdata["vgpu"]["service_offerings"][gtype]["serviceofferingdetails"] = [ + {'pciDevice': nvidiamodel}, {'vgpuType': gtype}] + self.service_offering = ServiceOffering.create( + self.apiclient, + self.testdata["vgpu"]["service_offerings"][gtype] + ) + list_service_response = ServiceOffering.list( + self.apiclient, + id=self.service_offering.id + ) - if list_service_response is None: - raise unittest.SkipTest("Check Service Offering list for %s service offering" %(gtype)) + if list_service_response is None: + raise unittest.SkipTest( + "Check Service Offering list for %s service offering" % + (gtype)) - self.assertEqual( - list_service_response[0].serviceofferingdetails.vgpuType, - gtype, - "Failed To Create Service Offering . Check vGPU Service Offering list" - ) - self.assertEqual( - list_service_response[0].displaytext, - self.testdata["vgpu"]["service_offerings"][gtype]["displaytext"], - "Check server displaytext in createServiceOfferings" - ) - self.assertEqual( - list_service_response[0].name, - self.testdata["vgpu"]["service_offerings"][gtype]["name"], - "Check name in createServiceOffering" - ) + self.assertEqual( + list_service_response[0].serviceofferingdetails.vgpuType, + gtype, + "Failed To Create Service Offering . Check vGPU Service Offering list") + self.assertEqual( + list_service_response[0].displaytext, + self.testdata["vgpu"]["service_offerings"][gtype]["displaytext"], + "Check server displaytext in createServiceOfferings") + self.assertEqual( + list_service_response[0].name, + self.testdata["vgpu"]["service_offerings"][gtype]["name"], + "Check name in createServiceOffering" + ) return(self.service_offering) - - @attr(tags = ['advanced', 'basic', 'vgpu'], required_hardware="true") - def check_for_vGPU_resource(self,hostid,vminstancename,serviceofferingid,vgputype): + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") + def check_for_vGPU_resource( + self, + hostid, + vminstancename, + serviceofferingid, + vgputype): """ Validate the VM for VGPU resources """ """Create SSH Client for Host Connection """ vgpu_host = list_hosts( - self.apiclient, - id=hostid - ) - ssh_client = SshClient(host=vgpu_host[0].ipaddress, port=22, user='root',passwd=self.testdata["host_password"]) + self.apiclient, + id=hostid + ) + ssh_client = SshClient( + host=vgpu_host[0].ipaddress, + port=self.testdata['configurabledata']['host']["publicport"], + user=self.testdata['configurabledata']['host']["username"], + passwd=self.testdata['configurabledata']['host']["password"]) """ Get vGPU type model """ - vgpu_type_model = ssh_client.execute("xe vgpu-list vm-name-label=" + vminstancename + " params=type-model-name --minimal") - self.debug("vgpu type model is %s and value is %s and length is %s"%(vgpu_type_model,vgpu_type_model[0],len(vgpu_type_model[0]))) + vgpu_type_model = ssh_client.execute( + "xe vgpu-list vm-name-label=" + + vminstancename + + " params=type-model-name --minimal") + self.debug( + "vgpu type model is %s and value is %s and length is %s" % + (vgpu_type_model, vgpu_type_model[0], len( + vgpu_type_model[0]))) if vgputype is None: - if len(vgpu_type_model[0])==0: + if len(vgpu_type_model[0]) == 0: self.debug("This is non GPU instance") return else: - self.fail("Non vGPU VM has GPU cards @ host:%s"%vminstancename) + self.fail( + "Non vGPU VM has GPU cards @ host:%s" % + vminstancename) self.assertNotEqual( - len(vgpu_type_model), - 0, - "The VM is NOT deployed with vGPU cards" - ) + len(vgpu_type_model), + 0, + "The VM is NOT deployed with vGPU cards" + ) """ List service offering from which VM is deployed """ list_service_offering_response = ServiceOffering.list( - self.apiclient, - id=serviceofferingid - ) + self.apiclient, + id=serviceofferingid + ) """ Check whether the vgputype in the service offering is same as the one obtained by listing the vgpu type model """ - self.debug("VM vGPU type is: %s and vGPU type on XenServer is : %s"%(list_service_offering_response[0].serviceofferingdetails.vgpuType,vgpu_type_model[0])) + self.debug( + "VM vGPU type is: %s and vGPU type on XenServer is : %s" % + (list_service_offering_response[0].serviceofferingdetails.vgpuType, + vgpu_type_model[0])) self.assertEqual( - list_service_offering_response[0].serviceofferingdetails.vgpuType, - vgpu_type_model[0], - "VM does not have the correct GPU resources, verified on the host" - ) + list_service_offering_response[0].serviceofferingdetails.vgpuType, + vgpu_type_model[0], + "VM does not have the correct GPU resources, verified on the host" + ) """ Check whether the VM is deployed with the card which was mentioned in the service offering """ self.assertEqual( - vgputype, - list_service_offering_response[0].serviceofferingdetails.vgpuType, - "The VM is NOT deployed with correct cards, verified from CS" - ) + vgputype, + list_service_offering_response[0].serviceofferingdetails.vgpuType, + "The VM is NOT deployed with correct cards, verified from CS" + ) return - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - - def deploy_vGPU_windows_vm(self,vgpuofferingid,vgput): + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") + def deploy_vGPU_windows_vm(self, vgpuofferingid, vgput): """ Validate vGPU K1 windows instances """ @@ -343,12 +395,14 @@ class TestvGPUWindowsVm(cloudstackTestCase): domainid=self.account.domainid, serviceofferingid=vgpuofferingid, templateid=self.template.id - ) + ) time.sleep(self.testdata["vgpu"]["sleep"]) - list_vms = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id) + list_vms = VirtualMachine.list( + self.apiclient, + id=self.virtual_machine.id) self.debug( - "Verify listVirtualMachines response for virtual machine: %s"\ + "Verify listVirtualMachines response for virtual machine: %s" % self.virtual_machine.id ) @@ -380,15 +434,15 @@ class TestvGPUWindowsVm(cloudstackTestCase): msg="VM is not in Running state" ) if vgput != "nonvgpuoffering": - self.assertEqual( - vm.vgpu, - vgput, - msg="Failed to deploy VM with vGPU card" - ) + self.assertEqual( + vm.vgpu, + vgput, + msg="Failed to deploy VM with vGPU card" + ) return - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - def delete_vgpu_service_offering(self,serviceoffering): + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") + def delete_vgpu_service_offering(self, serviceoffering): """ delete vGPU Service Offering """ @@ -397,41 +451,44 @@ class TestvGPUWindowsVm(cloudstackTestCase): list_service_response = list_service_offering( self.apiclient, id=serviceoffering.id - ) + ) self.assertEqual( list_service_response, None, "Check if service offering exists in listServiceOfferings" - ) + ) return - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - def check_for_vm(self,vgpucard,vgpuofferingid,vmid): + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") + def check_for_vm(self, vgpucard, vgpuofferingid, vmid): list_vm_response = list_virtual_machines( - self.apiclient, - id=vmid - ) + self.apiclient, + id=vmid + ) if isinstance(list_vm_response, list): - vm = list_vm_response[0] - if vm.state == 'Running': - self.debug("VM state: %s" % vm.state) + vm = list_vm_response[0] + if vm.state == 'Running': + self.debug("VM state: %s" % vm.state) + else: + self.fail("Failed to start VM (ID: %s)" % vm.id) + if vm.serviceofferingid == vgpuofferingid: + self.debug( + "VM service offering id : %s" % + vm.serviceofferingid) + else: + self.fail("Service Offering is not matching " % vm.id) + if vgpucard != "nonvgpuoffering": + if vm.vgpu == vgpucard: + self.debug("VM vGPU card is : %s" % vm.vgpu) else: - self.fail("Failed to start VM (ID: %s)" % vm.id) - if vm.serviceofferingid == vgpuofferingid: - self.debug("VM service offering id : %s" % vm.serviceofferingid) - else: - self.fail("Service Offering is not matching " % vm.id) - if vgpucard !="nonvgpuoffering": - if vm.vgpu == vgpucard: - self.debug("VM vGPU card is : %s" % vm.vgpu) - else: - self.fail("Failed to start VM (ID: %s) with %s vGPU card " % (vm.id,vgpucard)) + self.fail( + "Failed to start VM (ID: %s) with %s vGPU card " % + (vm.id, vgpucard)) return(list_vm_response[0]) - - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def destroy_vm(self): """Destroy Virtual Machine """ @@ -439,29 +496,29 @@ class TestvGPUWindowsVm(cloudstackTestCase): self.virtual_machine.delete(self.apiclient) list_vm_response = VirtualMachine.list( - self.apiclient, - id=self.virtual_machine.id - ) + self.apiclient, + id=self.virtual_machine.id + ) self.assertEqual( - isinstance(list_vm_response, list), - True, - "Check list response returns a valid list" - ) + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) self.assertNotEqual( - len(list_vm_response), - 0, - "Check VM avaliable in List Virtual Machines" - ) + len(list_vm_response), + 0, + "Check VM avaliable in List Virtual Machines" + ) self.assertEqual( - list_vm_response[0].state, - "Destroyed", - "Check virtual machine is in destroyed state" - ) + list_vm_response[0].state, + "Destroyed", + "Check virtual machine is in destroyed state" + ) return - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def stop_vm(self): """Stop Virtual Machine """ @@ -472,7 +529,7 @@ class TestvGPUWindowsVm(cloudstackTestCase): self.fail("Failed to stop VM: %s" % e) return - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def start_vm(self): """Start Virtual Machine """ @@ -481,45 +538,61 @@ class TestvGPUWindowsVm(cloudstackTestCase): self.virtual_machine.start(self.apiclient) list_vm_response = VirtualMachine.list( - self.apiclient, - id=self.virtual_machine.id - ) + self.apiclient, + id=self.virtual_machine.id + ) self.assertEqual( - isinstance(list_vm_response, list), - True, - "Check list response returns a valid list" - ) + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) self.assertNotEqual( - len(list_vm_response), - 0, - "Check VM available in List Virtual Machines" - ) + len(list_vm_response), + 0, + "Check VM available in List Virtual Machines" + ) self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % self.virtual_machine.id - ) + "Verify listVirtualMachines response for virtual machine: %s" + % self.virtual_machine.id + ) self.assertEqual( - list_vm_response[0].state, - "Running", - "Check virtual machine is in running state" - ) + list_vm_response[0].state, + "Running", + "Check virtual machine is in running state" + ) return - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - def serviceoffering_upgrade(self,sourcetype,sourcemodel,desttype,destmodel): + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") + def serviceoffering_upgrade( + self, + sourcetype, + sourcemodel, + desttype, + destmodel): - self.sourcevgpuoffering=self.vgpu_serviceoffering_creation(sourcetype,sourcemodel) - self.deploy_vGPU_windows_vm(self.sourcevgpuoffering.id,sourcetype) + self.sourcevgpuoffering = self.vgpu_serviceoffering_creation( + sourcetype, + sourcemodel) + self.deploy_vGPU_windows_vm(self.sourcevgpuoffering.id, sourcetype) time.sleep(self.testdata["vgpu"]["sleep"]) - vm=self.check_for_vm(sourcetype,self.sourcevgpuoffering.id,self.virtual_machine.id) - self.check_for_vGPU_resource(vm.hostid,vm.instancename,vm.serviceofferingid,vm.vgpu) + vm = self.check_for_vm( + sourcetype, + self.sourcevgpuoffering.id, + self.virtual_machine.id) + self.check_for_vGPU_resource( + vm.hostid, + vm.instancename, + vm.serviceofferingid, + vm.vgpu) self.stop_vm() - self.destvgpuoffering=self.vgpu_serviceoffering_creation(desttype,destmodel) + self.destvgpuoffering = self.vgpu_serviceoffering_creation( + desttype, + destmodel) cmd = changeServiceForVirtualMachine.changeServiceForVirtualMachineCmd() cmd.id = vm.id cmd.serviceofferingid = self.destvgpuoffering.id @@ -529,28 +602,47 @@ class TestvGPUWindowsVm(cloudstackTestCase): self.start_vm() time.sleep(self.testdata["vgpu"]["sleep"]) - # Ensure that VM is in running state - vm=self.check_for_vm(desttype,self.destvgpuoffering.id,vm.id) - self.check_for_vGPU_resource(vm.hostid,vm.instancename,vm.serviceofferingid,vm.vgpu) + # Ensure that VM is in running state + vm = self.check_for_vm(desttype, self.destvgpuoffering.id, vm.id) + self.check_for_vGPU_resource( + vm.hostid, + vm.instancename, + vm.serviceofferingid, + vm.vgpu) self.delete_vgpu_service_offering(self.destvgpuoffering) self.delete_vgpu_service_offering(self.sourcevgpuoffering) self.destroy_vm() return + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") + def vm_snapshot_serviceoffering_upgrade( + self, + sourcetype, + sourcemodel, + desttype, + destmodel): - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - def vm_snapshot_serviceoffering_upgrade(self,sourcetype,sourcemodel,desttype,destmodel): - - self.sourcevgpuoffering=self.vgpu_serviceoffering_creation(sourcetype,sourcemodel) - self.deploy_vGPU_windows_vm(self.sourcevgpuoffering.id,sourcetype) + self.sourcevgpuoffering = self.vgpu_serviceoffering_creation( + sourcetype, + sourcemodel) + self.deploy_vGPU_windows_vm(self.sourcevgpuoffering.id, sourcetype) time.sleep(self.testdata["vgpu"]["sleep"]) - vm=self.check_for_vm(sourcetype,self.sourcevgpuoffering.id,self.virtual_machine.id) - self.check_for_vGPU_resource(vm.hostid,vm.instancename,vm.serviceofferingid,vm.vgpu) + vm = self.check_for_vm( + sourcetype, + self.sourcevgpuoffering.id, + self.virtual_machine.id) + self.check_for_vGPU_resource( + vm.hostid, + vm.instancename, + vm.serviceofferingid, + vm.vgpu) self.stop_vm() - self.destvgpuoffering=self.vgpu_serviceoffering_creation(desttype,destmodel) + self.destvgpuoffering = self.vgpu_serviceoffering_creation( + desttype, + destmodel) cmd = changeServiceForVirtualMachine.changeServiceForVirtualMachineCmd() cmd.id = vm.id cmd.serviceofferingid = self.destvgpuoffering.id @@ -560,66 +652,84 @@ class TestvGPUWindowsVm(cloudstackTestCase): self.start_vm() time.sleep(self.testdata["vgpu"]["sleep"]) - # Ensure that VM is in running state - vm=self.check_for_vm(desttype,self.destvgpuoffering.id,vm.id) - self.check_for_vGPU_resource(vm.hostid,vm.instancename,vm.serviceofferingid,vm.vgpu) + # Ensure that VM is in running state + vm = self.check_for_vm(desttype, self.destvgpuoffering.id, vm.id) + self.check_for_vGPU_resource( + vm.hostid, + vm.instancename, + vm.serviceofferingid, + vm.vgpu) self.delete_vgpu_service_offering(self.destvgpuoffering) self.delete_vgpu_service_offering(self.sourcevgpuoffering) self.destroy_vm() return - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - def deploy_vm(self,type,model): + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") + def deploy_vm(self, type, model): - self.vgpuoffering=self.vgpu_serviceoffering_creation(type,model) + self.vgpuoffering = self.vgpu_serviceoffering_creation(type, model) if self.vgpuoffering is not None: - self.deploy_vGPU_windows_vm(self.vgpuoffering.id,type) - time.sleep(self.testdata["vgpu"]["sleep"]) - vm=self.check_for_vm(type,self.vgpuoffering.id,self.virtual_machine.id) - self.check_for_vGPU_resource(vm.hostid,vm.instancename,vm.serviceofferingid,vm.vgpu) - self.destroy_vm() - self.delete_vgpu_service_offering(self.vgpuoffering) + self.deploy_vGPU_windows_vm(self.vgpuoffering.id, type) + time.sleep(self.testdata["vgpu"]["sleep"]) + vm = self.check_for_vm( + type, + self.vgpuoffering.id, + self.virtual_machine.id) + self.check_for_vGPU_resource( + vm.hostid, + vm.instancename, + vm.serviceofferingid, + vm.vgpu) + self.destroy_vm() + self.delete_vgpu_service_offering(self.vgpuoffering) return + def new_template_register(self, guestostype): - def new_template_register(self,guestostype): + template1 = get_windows_template( + self.apiclient, + self.zone.id, + ostype_desc=guestostype) - template1 = get_windows_template(self.apiclient, self.zone.id ,ostype_desc=guestostype) - - if template1 == FAILED: - if "http://pleaseupdateURL/dummy.vhd" in cls.testdata["vgpu"] [guestostype]["url"]: - raise unittest.SkipTest("Check Test Data file if it has the valid template URL") + if template1 == FAILED: + if "http://pleaseupdateURL/dummy.vhd" in self.testdata[ + "vgpu"][guestostype]["url"]: + raise unittest.SkipTest( + "Check Test Data file if it has the valid template URL") template1 = Template.register( - self.apiclient, - self.testdata["vgpu"] [guestostype], - hypervisor = "XenServer", - zoneid=cls.zone.id, - domainid=cls.account.domainid, - account=cls.account.name - ) + self.apiclient, + self.testdata["vgpu"][guestostype], + hypervisor="XenServer", + zoneid=self.zone.id, + domainid=self.account.domainid, + account=self.account.name + ) timeout = self.testdata["vgpu"]["timeout"] while True: - time.sleep(self.testdata["vgpu"]["sleep"]) - list_template_response = Template.list( - self.apiclient, - templatefilter=\ - self.testdata["templatefilter"], - id=template1.id - ) - if (isinstance(list_template_response, list)) is not True: - raise unittest.SkipTest("Check list template api response returns a valid list") + time.sleep(self.testdata["vgpu"]["sleep"]) + list_template_response = Template.list( + self.apiclient, + templatefilter=self.testdata["templatefilter"], + id=template1.id + ) + if (isinstance(list_template_response, list)) is not True: + raise unittest.SkipTest( + "Check list template api response returns a valid list") - if len(list_template_response) is None : - raise unittest.SkipTest("Check template registered is in List Templates") + if len(list_template_response) is None: + raise unittest.SkipTest( + "Check template registered is in List Templates") - template_response = list_template_response[0] - if template_response.isready == True: - break - if timeout == 0: - raise unittest.SkipTest("Failed to download template(ID: %s)" % template_response.id) + template_response = list_template_response[0] + if template_response.isready: + break + if timeout == 0: + raise unittest.SkipTest( + "Failed to download template(ID: %s)" % + template_response.id) - timeout = timeout - 1 + timeout = timeout - 1 return(template1.id) def deploy_vm_lifecycle(self): @@ -632,49 +742,50 @@ class TestvGPUWindowsVm(cloudstackTestCase): gtype = "GRID K140Q" elif(self.k120qgpuhosts != 0): gtype = "GRID K120Q" - elif(self.k100gpuhosts !=0): + elif(self.k100gpuhosts != 0): gtype = "GRID K100" else: gtype = "passthrough" - self.testdata["vgpu"]["service_offerings"][gtype]["serviceofferingdetails"] = [{'pciDevice':'Group of NVIDIA Corporation GK107GL [GRID K1] GPUs'}, - {'vgpuType':gtype}] + self.testdata["vgpu"]["service_offerings"][gtype]["serviceofferingdetails"] = [ + {'pciDevice': 'Group of NVIDIA Corporation GK107GL [GRID K1] GPUs'}, {'vgpuType': gtype}] try: - self.__class__.k100_vgpu_service_offering = ServiceOffering.create( - self.apiclient, - self.testdata["vgpu"]["service_offerings"][gtype] - ) + self.__class__.k100_vgpu_service_offering = ServiceOffering.create( + self.apiclient, + self.testdata["vgpu"]["service_offerings"][gtype] + ) except Exception as e: - self.fail("Failed to create the service offering, %s" % e) + self.fail("Failed to create the service offering, %s" % e) if(self.k2hosts != 0): if(self.k240qgpuhosts != 0): gtype = "GRID K240Q" - elif(cls.k220qgpuhosts != 0): + elif(self.k220qgpuhosts != 0): gtype = "GRID K220Q" - elif(self.k200gpuhosts !=0): + elif(self.k200gpuhosts != 0): gtype = "GRID K200" else: gtype = "passthrough" - self.testdata["vgpu"]["service_offerings"][gtype]["serviceofferingdetails"] = [{'pciDevice': 'Group of NVIDIA Corporation GK104GL [GRID K2] GPUs'}, - {'vgpuType':gtype}] + self.testdata["vgpu"]["service_offerings"][gtype]["serviceofferingdetails"] = [ + {'pciDevice': 'Group of NVIDIA Corporation GK104GL [GRID K2] GPUs'}, {'vgpuType': gtype}] try: - self.__class__.k200_vgpu_service_offering = ServiceOffering.create( - self.apiclient, - self.testdata["vgpu"]["service_offerings"][gtype] - ) + self.__class__.k200_vgpu_service_offering = ServiceOffering.create( + self.apiclient, + self.testdata["vgpu"]["service_offerings"][gtype] + ) except Exception as e: - self.fail("Failed to create the service offering, %s" % e) + self.fail("Failed to create the service offering, %s" % e) - win8templateid=self.new_template_register("Windows 8 (64-bit)") - win2012templateid=self.new_template_register("Windows Server 2012 (64-bit)") - win7templateid=self.new_template_register("Windows 7 (64-bit)") + win8templateid = self.new_template_register("Windows 8 (64-bit)") + win2012templateid = self.new_template_register( + "Windows Server 2012 (64-bit)") + win7templateid = self.new_template_register("Windows 7 (64-bit)") self.__class__.nonvgpu_service_offering = ServiceOffering.create( - self.apiclient, - self.testdata["vgpu"]["service_offerings"]["nonvgpuoffering"] - ) + self.apiclient, + self.testdata["vgpu"]["service_offerings"]["nonvgpuoffering"] + ) """ Create Virtual Machines for Both K1 and K2 cards to be used for VM life cycle tests @@ -682,34 +793,34 @@ class TestvGPUWindowsVm(cloudstackTestCase): if(self.k1hosts != 0): self.__class__.vm_k1_card = VirtualMachine.create( - self.apiclient, - self.testdata["virtual_machine"], - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - serviceofferingid=self.k100_vgpu_service_offering.id, - templateid=win8templateid + self.apiclient, + self.testdata["virtual_machine"], + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + serviceofferingid=self.k100_vgpu_service_offering.id, + templateid=win8templateid ) - if(self.k2hosts !=0): + if(self.k2hosts != 0): self.__class__.vm_k2_card = VirtualMachine.create( - self.apiclient, - self.testdata["virtual_machine"], - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - serviceofferingid=self.k200_vgpu_service_offering.id, - templateid=win2012templateid + self.apiclient, + self.testdata["virtual_machine"], + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + serviceofferingid=self.k200_vgpu_service_offering.id, + templateid=win2012templateid ) - if(self.k2hosts !=0): + if(self.k2hosts != 0): self.__class__.vm2_k2_card = VirtualMachine.create( - self.apiclient, - self.testdata["virtual_machine"], - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - serviceofferingid=self.k200_vgpu_service_offering.id, - templateid=win7templateid + self.apiclient, + self.testdata["virtual_machine"], + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + serviceofferingid=self.k200_vgpu_service_offering.id, + templateid=win7templateid ) self.__class__.nonvgpu = VirtualMachine.create( @@ -720,174 +831,191 @@ class TestvGPUWindowsVm(cloudstackTestCase): domainid=self.account.domainid, serviceofferingid=self.__class__.nonvgpu_service_offering.id, templateid=win7templateid - ) + ) return - - def check_gpu_resources_released_vm(self,gpuhostid,vm_vgpu_type,rcapacity): + def check_gpu_resources_released_vm( + self, + gpuhostid, + vm_vgpu_type, + rcapacity): hhosts = list_hosts( - self.apiclient, - hypervisor="XenServer", - id=gpuhostid - ) + self.apiclient, + hypervisor="XenServer", + id=gpuhostid + ) self.assertEqual( - isinstance(hhosts, list), - True, - "Check list hosts response returns a valid list" - ) + isinstance(hhosts, list), + True, + "Check list hosts response returns a valid list" + ) self.assertNotEqual( - len(hhosts), - 0, - "Check Host details are available in List Hosts" - ) + len(hhosts), + 0, + "Check Host details are available in List Hosts" + ) for ggroup in hhosts: - if ggroup.ipaddress not in self.nongpuhosts: - for gp in ggroup.gpugroup: - #if gp.gpugroupname == "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs": - for gptype in gp.vgpu: - if gptype.vgputype==vm_vgpu_type: - self.debug("Latest remainingcapacity is %s and before remainingcapacity is %s"%(gptype.remainingcapacity,rcapacity)) - if gptype.remainingcapacity != rcapacity+1: - self.fail("Host capacity is not updated .GPU resources should be released when VM is stopped/Destroyed ") + if ggroup.ipaddress not in self.nongpuhosts: + for gp in ggroup.gpugroup: + # if gp.gpugroupname == "Group of NVIDIA Corporation + # GK104GL [GRID K2] GPUs": + for gptype in gp.vgpu: + if gptype.vgputype == vm_vgpu_type: + self.debug( + "Latest remainingcapacity is %s and before remainingcapacity is %s" % + (gptype.remainingcapacity, rcapacity)) + if gptype.remainingcapacity != rcapacity + 1: + self.fail( + "Host capacity is not updated .GPU resources should be released when VM is stopped/Destroyed ") return - def check_vm_state(self,vmid): + def check_vm_state(self, vmid): list_vm_response = list_virtual_machines( - self.apiclient, - id=vmid - ) + self.apiclient, + id=vmid + ) if list_vm_response is None: return("Expunge") return(list_vm_response[0].state) - def check_host_vgpu_remaining_capacity(self,gpuhostid,gtype): + def check_host_vgpu_remaining_capacity(self, gpuhostid, gtype): gputhosts = list_hosts( - self.apiclient, - hypervisor="XenServer", - id=gpuhostid - ) - vgpucapacity=0 + self.apiclient, + hypervisor="XenServer", + id=gpuhostid + ) + vgpucapacity = 0 for ghost in gputhosts: if ghost.gpugroup is not None: - for gp in ghost.gpugroup: - #if gp.gpugroupname == gpucard: - for gptype in gp.vgpu: - if gptype.vgputype == gtype: - vgpucapacity=vgpucapacity+gptype.remainingcapacity + for gp in ghost.gpugroup: + # if gp.gpugroupname == gpucard: + for gptype in gp.vgpu: + if gptype.vgputype == gtype: + vgpucapacity = vgpucapacity + \ + gptype.remainingcapacity return(vgpucapacity) - def verify_vm(self,vm_gpu_card): + def verify_vm(self, vm_gpu_card): if(vm_gpu_card): - vm_gpu_card.getState( - self.apiclient, - "Running") - time.sleep(self.testdata["vgpu"]["sleep"]*3) - self.check_for_vGPU_resource(vm_gpu_card.hostid,vm_gpu_card.instancename,vm_gpu_card.serviceofferingid,vm_gpu_card.vgpu) + vm_gpu_card.getState( + self.apiclient, + "Running") + time.sleep(self.testdata["vgpu"]["sleep"] * 3) + self.check_for_vGPU_resource( + vm_gpu_card.hostid, + vm_gpu_card.instancename, + vm_gpu_card.serviceofferingid, + vm_gpu_card.vgpu) - def stop_life_cycle_vm (self,vm_gpu_card): + def stop_life_cycle_vm(self, vm_gpu_card): if(vm_gpu_card): - vm_gpu_card.stop(self.apiclient) - time.sleep(self.testdata["vgpu"]["sleep"]) - vm_gpu_card.getState( - self.apiclient, - "Stopped") + vm_gpu_card.stop(self.apiclient) + time.sleep(self.testdata["vgpu"]["sleep"]) + vm_gpu_card.getState( + self.apiclient, + "Stopped") - def start_life_cycle_vm(self,vm_gpu_card): + def start_life_cycle_vm(self, vm_gpu_card): if(vm_gpu_card): - vm_gpu_card.start(self.apiclient) - time.sleep(self.testdata["vgpu"]["sleep"]) - vm_gpu_card.getState( - self.apiclient, - "Running") + vm_gpu_card.start(self.apiclient) + time.sleep(self.testdata["vgpu"]["sleep"]) + vm_gpu_card.getState( + self.apiclient, + "Running") - - def restore_life_cycle_vm(self,vm_gpu_card): + def restore_life_cycle_vm(self, vm_gpu_card): if(vm_gpu_card): - vm_gpu_card.restore(self.apiclient) - time.sleep(self.testdata["vgpu"]["sleep"]) + vm_gpu_card.restore(self.apiclient) + time.sleep(self.testdata["vgpu"]["sleep"]) - def reboot_life_cycle_vm(self,vm_gpu_card): + def reboot_life_cycle_vm(self, vm_gpu_card): if(vm_gpu_card): - vm_gpu_card.reboot(self.apiclient) - time.sleep(self.testdata["vgpu"]["sleep"]) + vm_gpu_card.reboot(self.apiclient) + time.sleep(self.testdata["vgpu"]["sleep"]) - def delete_vm_life_cycle_vm(self,vm_gpu_card): + def delete_vm_life_cycle_vm(self, vm_gpu_card): if(vm_gpu_card): - vm_gpu_card.delete(self.apiclient) - time.sleep(self.testdata["vgpu"]["sleep"]) - vm_gpu_card.getState( - self.apiclient, - "Destroyed") + vm_gpu_card.delete(self.apiclient) + time.sleep(self.testdata["vgpu"]["sleep"]) + vm_gpu_card.getState( + self.apiclient, + "Destroyed") - def recover_vm_life_cycle_vm(self,vm_gpu_card): + def recover_vm_life_cycle_vm(self, vm_gpu_card): if(vm_gpu_card): - vm_gpu_card.recover(self.apiclient) - vm_gpu_card.getState( - self.apiclient, - "Stopped") + vm_gpu_card.recover(self.apiclient) + vm_gpu_card.getState( + self.apiclient, + "Stopped") - - def recovervm(self,vm_gpu_card): - if self.check_vm_state(vm_gpu_card.id)=="Expunge": + def recovervm(self, vm_gpu_card): + if self.check_vm_state(vm_gpu_card.id) == "Expunge": raise unittest.SkipTest("VM is already deleted hence skipping") self.recover_vm_life_cycle_vm(vm_gpu_card) self.start_life_cycle_vm(vm_gpu_card) self.verify_vm(vm_gpu_card) return - - def startvm(self,vm_gpu_card): + def startvm(self, vm_gpu_card): self.start_life_cycle_vm(vm_gpu_card) self.verify_vm(vm_gpu_card) return - def stopvm(self,vm_gpu_card): + def stopvm(self, vm_gpu_card): - rcapacity=self.check_host_vgpu_remaining_capacity(vm_gpu_card.hostid,vm_gpu_card.vgpu) + rcapacity = self.check_host_vgpu_remaining_capacity( + vm_gpu_card.hostid, + vm_gpu_card.vgpu) self.stop_life_cycle_vm(vm_gpu_card) - time.sleep(self.testdata["vgpu"]["sleep"]*3) - self.check_gpu_resources_released_vm(vm_gpu_card.hostid,vm_gpu_card.vgpu,rcapacity) + time.sleep(self.testdata["vgpu"]["sleep"] * 3) + self.check_gpu_resources_released_vm( + vm_gpu_card.hostid, + vm_gpu_card.vgpu, + rcapacity) return - def deletevm(self,vm_gpu_card): + def deletevm(self, vm_gpu_card): - rcapacity=self.check_host_vgpu_remaining_capacity(vm_gpu_card.hostid,vm_gpu_card.vgpu) - hostid=vm_gpu_card.hostid - vgputype=vm_gpu_card.vgpu + rcapacity = self.check_host_vgpu_remaining_capacity( + vm_gpu_card.hostid, + vm_gpu_card.vgpu) + hostid = vm_gpu_card.hostid + vgputype = vm_gpu_card.vgpu self.delete_vm_life_cycle_vm(vm_gpu_card) - time.sleep(self.testdata["vgpu"]["sleep"]*3) - self.check_gpu_resources_released_vm(hostid,vgputype,rcapacity) + time.sleep(self.testdata["vgpu"]["sleep"] * 3) + self.check_gpu_resources_released_vm(hostid, vgputype, rcapacity) return - def restorevm(self,vm_gpu_card): + def restorevm(self, vm_gpu_card): self.restore_life_cycle_vm(vm_gpu_card) self.verify_vm(vm_gpu_card) return - - - - def create_vm_snapshot(self,vmcard): + def create_vm_snapshot(self, vmcard): self.debug("Check if deployed VMs are in running state?") if(vmcard): - vmcard.getState( - self.apiclient, - "Running") + vmcard.getState( + self.apiclient, + "Running") - if hasattr(vmcard,"vgpu"): - self.check_for_vGPU_resource(vmcard.hostid,vmcard.instancename,vmcard.serviceofferingid,vmcard.vgpu) + if hasattr(vmcard, "vgpu"): + self.check_for_vGPU_resource( + vmcard.hostid, + vmcard.instancename, + vmcard.serviceofferingid, + vmcard.vgpu) - vm_snapshot = VmSnapshot.create( + VmSnapshot.create( self.apiclient, vmcard.id, "false", @@ -895,7 +1023,10 @@ class TestvGPUWindowsVm(cloudstackTestCase): "Display Text" ) - list_snapshot_response = VmSnapshot.list(self.apiclient, virtualmachineid=vmcard.id, listall=True) + list_snapshot_response = VmSnapshot.list( + self.apiclient, + virtualmachineid=vmcard.id, + listall=True) self.assertEqual( isinstance(list_snapshot_response, list), @@ -915,37 +1046,51 @@ class TestvGPUWindowsVm(cloudstackTestCase): ) vgpu_host = list_hosts( - self.apiclient, - id=vmcard.hostid - ) - ssh_client = SshClient(host=vgpu_host[0].ipaddress, port=22, user='root',passwd=self.testdata["host_password"]) + self.apiclient, + id=vmcard.hostid + ) + ssh_client = SshClient( + host=vgpu_host[0].ipaddress, + port=self.testdata['configurabledata']['host']["publicport"], + user=self.testdata['configurabledata']['host']["username"], + passwd=self.testdata['configurabledata']['host']["password"]) """ Get vGPU type model """ - vgpu_snapshot = ssh_client.execute("xe snapshot-list name-label=" + list_snapshot_response[0].name + " --minimal") + vgpu_snapshot = ssh_client.execute( + "xe snapshot-list name-label=" + + list_snapshot_response[0].name + + " --minimal") #vgpu_snapshot = ssh_client.execute("xe snapshot-param-get param-name=name-label uuid="+vgpu_snapshot_uuid[0]+ " params=type-model-name --minimal") # self.debug("vgpu type model is %s and value is %s and length is %s"%(vgpu_type_model,vgpu_type_model[0],len(vgpu_type_model[0]))) self.assertNotEqual( - len(vgpu_snapshot[0]), - 0, - "VM Snapshot is not created" - ) - self.__class__.vmsnapwomemory=1 + len(vgpu_snapshot[0]), + 0, + "VM Snapshot is not created" + ) + self.__class__.vmsnapwomemory = 1 return - def revert_vm_snapshot(self,vmcard): + def revert_vm_snapshot(self, vmcard): self.debug("Check if deployed VMs are in running state?") - #if(vmcard): - # vmcard.getState( - # self.apiclient, - # "Running") - if hasattr(vmcard,"vgpu"): - self.check_for_vGPU_resource(vmcard.hostid,vmcard.instancename,vmcard.serviceofferingid,vmcard.vgpu) + # if(vmcard): + # vmcard.getState( + # self.apiclient, + # "Running") + if hasattr(vmcard, "vgpu"): + self.check_for_vGPU_resource( + vmcard.hostid, + vmcard.instancename, + vmcard.serviceofferingid, + vmcard.vgpu) - list_snapshot_response = VmSnapshot.list(self.apiclient, virtualmachineid=vmcard.id, listall=True) + list_snapshot_response = VmSnapshot.list( + self.apiclient, + virtualmachineid=vmcard.id, + listall=True) self.assertEqual( isinstance(list_snapshot_response, list), @@ -964,13 +1109,15 @@ class TestvGPUWindowsVm(cloudstackTestCase): "Check the snapshot of vm is ready!" ) - VmSnapshot.revertToSnapshot(self.apiclient, list_snapshot_response[0].id) + VmSnapshot.revertToSnapshot( + self.apiclient, + list_snapshot_response[0].id) time.sleep(self.testdata["vgpu"]["sleep"]) list_vm_response = list_virtual_machines( self.apiclient, id=vmcard.id ) - vm=list_vm_response[0] + vm = list_vm_response[0] self.assertEqual( list_vm_response[0].state, "Stopped", @@ -986,22 +1133,28 @@ class TestvGPUWindowsVm(cloudstackTestCase): self.apiclient, id=vm.id ) - vm=list_vm_response[0] + vm = list_vm_response[0] if vm is None: self.fail("Failed to list VM details after Vm Snapshot") self.assertEqual( - vm.state, + vm.state, "Running", "Check the state of vm is Running" ) - if hasattr(vmcard,"vgpu"): - self.check_for_vGPU_resource(vmcard.hostid,vmcard.instancename,vmcard.serviceofferingid,vmcard.vgpu) + if hasattr(vmcard, "vgpu"): + self.check_for_vGPU_resource( + vmcard.hostid, + vmcard.instancename, + vmcard.serviceofferingid, + vmcard.vgpu) + def delete_vm_snapshot(self, vmcard): - def delete_vm_snapshot(self,vmcard): - - list_snapshot_response = VmSnapshot.list(self.apiclient, virtualmachineid=vmcard.id, listall=True) + list_snapshot_response = VmSnapshot.list( + self.apiclient, + virtualmachineid=vmcard.id, + listall=True) self.assertEqual( isinstance(list_snapshot_response, list), @@ -1013,13 +1166,20 @@ class TestvGPUWindowsVm(cloudstackTestCase): None, "Check if snapshot exists in ListSnapshot" ) - Tobedeletedsnapname=list_snapshot_response[0].name - VmSnapshot.deleteVMSnapshot(self.apiclient, list_snapshot_response[0].id) + Tobedeletedsnapname = list_snapshot_response[0].name + VmSnapshot.deleteVMSnapshot( + self.apiclient, + list_snapshot_response[0].id) time.sleep(self.testdata["vgpu"]["sleep"]) - list_snapshot_response = VmSnapshot.list(self.apiclient, virtualmachineid=vmcard.id, listall=True) - self.debug("List Snapshot response after snapshot deletion %s"%list_snapshot_response) + list_snapshot_response = VmSnapshot.list( + self.apiclient, + virtualmachineid=vmcard.id, + listall=True) + self.debug( + "List Snapshot response after snapshot deletion %s" % + list_snapshot_response) self.assertEqual( list_snapshot_response, None, @@ -1027,35 +1187,47 @@ class TestvGPUWindowsVm(cloudstackTestCase): ) vgpu_host = list_hosts( - self.apiclient, - id=vmcard.hostid - ) - ssh_client = SshClient(host=vgpu_host[0].ipaddress, port=22, user='root',passwd=self.testdata["host_password"]) + self.apiclient, + id=vmcard.hostid + ) + ssh_client = SshClient( + host=vgpu_host[0].ipaddress, + port=self.testdata['configurabledata']['host']["publicport"], + user=self.testdata['configurabledata']['host']["username"], + passwd=self.testdata['configurabledata']['host']["password"]) - vgpu_snapshot = ssh_client.execute("xe snapshot-list name-label=" +Tobedeletedsnapname + " --minimal") + vgpu_snapshot = ssh_client.execute( + "xe snapshot-list name-label=" + + Tobedeletedsnapname + + " --minimal") #vgpu_snapshot = ssh_client.execute("xe snapshot-param-get param-name=name-label uuid="+vgpu_snapshot_uuid[0]+ " params=type-model-name --minimal") # self.debug("vgpu type model is %s and value is %s and length is %s"%(vgpu_type_model,vgpu_type_model[0],len(vgpu_type_model[0]))) - self.debug("List Snapshot response after snapshot deletion is %s %s"%(vgpu_snapshot,vgpu_snapshot[0])) + self.debug( + "List Snapshot response after snapshot deletion is %s %s" % + (vgpu_snapshot, vgpu_snapshot[0])) self.assertEqual( - len(vgpu_snapshot[0]), - 0, - "check if VM Snapshot is not deleted" - ) + len(vgpu_snapshot[0]), + 0, + "check if VM Snapshot is not deleted" + ) return - - def create_vm_snapshot_with_memory(self,vmcard): + def create_vm_snapshot_with_memory(self, vmcard): self.debug("Check if deployed VMs are in running state?") if(vmcard): - vmcard.getState( - self.apiclient, - "Running") - self.check_for_vGPU_resource(vmcard.hostid,vmcard.instancename,vmcard.serviceofferingid,vmcard.vgpu) + vmcard.getState( + self.apiclient, + "Running") + self.check_for_vGPU_resource( + vmcard.hostid, + vmcard.instancename, + vmcard.serviceofferingid, + vmcard.vgpu) - vm_snapshot = VmSnapshot.create( + VmSnapshot.create( self.apiclient, vmcard.id, "true", @@ -1065,7 +1237,10 @@ class TestvGPUWindowsVm(cloudstackTestCase): time.sleep(self.testdata["vgpu"]["sleep"] * 3) - list_snapshot_response = VmSnapshot.list(self.apiclient, virtualmachineid=vmcard.id, listall=True) + list_snapshot_response = VmSnapshot.list( + self.apiclient, + virtualmachineid=vmcard.id, + listall=True) self.assertEqual( isinstance(list_snapshot_response, list), @@ -1085,35 +1260,48 @@ class TestvGPUWindowsVm(cloudstackTestCase): ) vgpu_host = list_hosts( - self.apiclient, - id=vmcard.hostid - ) - ssh_client = SshClient(host=vgpu_host[0].ipaddress, port=22, user='root',passwd=self.testdata["host_password"]) + self.apiclient, + id=vmcard.hostid + ) + ssh_client = SshClient( + host=vgpu_host[0].ipaddress, + port=self.testdata['configurabledata']['host']["publicport"], + user=self.testdata['configurabledata']['host']["username"], + passwd=self.testdata['configurabledata']['host']["password"]) - vgpu_snapshot = ssh_client.execute("xe snapshot-list name-label=" + list_snapshot_response[0].name + " --minimal") + vgpu_snapshot = ssh_client.execute( + "xe snapshot-list name-label=" + + list_snapshot_response[0].name + + " --minimal") #vgpu_snapshot = ssh_client.execute("xe snapshot-param-get param-name=name-label uuid="+vgpu_snapshot_uuid[0]+ " params=type-model-name --minimal") # self.debug("vgpu type model is %s and value is %s and length is %s"%(vgpu_type_model,vgpu_type_model[0],len(vgpu_type_model[0]))) self.assertNotEqual( - len(vgpu_snapshot[0]), - 0, - "VM Snapshot is not created" - ) - self.__class__.vmsnapwithmemory=1 + len(vgpu_snapshot[0]), + 0, + "VM Snapshot is not created" + ) + self.__class__.vmsnapwithmemory = 1 return - def revert_vm_snapshot_with_memory(self,vmcard): + def revert_vm_snapshot_with_memory(self, vmcard): self.debug("Check if deployed VMs are in running state?") if(vmcard): - vmcard.getState( - self.apiclient, - "Running") - self.check_for_vGPU_resource(vmcard.hostid,vmcard.instancename,vmcard.serviceofferingid,vmcard.vgpu) + vmcard.getState( + self.apiclient, + "Running") + self.check_for_vGPU_resource( + vmcard.hostid, + vmcard.instancename, + vmcard.serviceofferingid, + vmcard.vgpu) - - list_snapshot_response = VmSnapshot.list(self.apiclient, virtualmachineid=vmcard.id, listall=True) + list_snapshot_response = VmSnapshot.list( + self.apiclient, + virtualmachineid=vmcard.id, + listall=True) self.assertEqual( isinstance(list_snapshot_response, list), @@ -1132,40 +1320,51 @@ class TestvGPUWindowsVm(cloudstackTestCase): "Check the snapshot of vm is ready!" ) - VmSnapshot.revertToSnapshot(self.apiclient, list_snapshot_response[0].id) + VmSnapshot.revertToSnapshot( + self.apiclient, + list_snapshot_response[0].id) list_vm_response = list_virtual_machines( self.apiclient, id=vmcard.id ) - vm=list_vm_response[0] + vm = list_vm_response[0] if vm is None: self.fail("Failed to list VM details after Vm Snapshot") self.assertEqual( - vm.state, + vm.state, "Running", "Check the state of vm is Running" ) - self.check_for_vGPU_resource(vmcard.hostid,vmcard.instancename,vmcard.serviceofferingid,vmcard.vgpu) - + self.check_for_vGPU_resource( + vmcard.hostid, + vmcard.instancename, + vmcard.serviceofferingid, + vmcard.vgpu) return - - def rebootvm(self,vm_vgpu_card): + def rebootvm(self, vm_vgpu_card): self.reboot_life_cycle_vm(vm_vgpu_card) self.verify_vm(vm_vgpu_card) return - @attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true") - def vm_snapshot_vgpu(self,vmcard,sourcetype,sourcemodel,desttype,destmodel): + def vm_snapshot_vgpu( + self, + vmcard, + sourcetype, + sourcemodel, + desttype, + destmodel): self.create_vm_snapshot(vmcard) self.start_life_cycle_vm(vmcard) - self.destvgpuoffering=self.vgpu_serviceoffering_creation(desttype,destmodel) + self.destvgpuoffering = self.vgpu_serviceoffering_creation( + desttype, + destmodel) self.stop_life_cycle_vm(vmcard) cmd = changeServiceForVirtualMachine.changeServiceForVirtualMachineCmd() cmd.id = vmcard.id @@ -1175,317 +1374,366 @@ class TestvGPUWindowsVm(cloudstackTestCase): self.debug("Starting VM - ID: %s" % vmcard.id) self.start_life_cycle_vm(vmcard) time.sleep(self.testdata["vgpu"]["sleep"]) - vm=self.check_for_vm(desttype,self.destvgpuoffering.id,vmcard.id) - # Ensure that VM is in running state - if destmodel!="None": - self.check_for_vGPU_resource(vm.hostid,vm.instancename,vm.serviceofferingid,vm.vgpu) + vm = self.check_for_vm(desttype, self.destvgpuoffering.id, vmcard.id) + # Ensure that VM is in running state + if destmodel != "None": + self.check_for_vGPU_resource( + vm.hostid, + vm.instancename, + vm.serviceofferingid, + vm.vgpu) self.revert_vm_snapshot(vm) self.delete_vm_snapshot(vm) - - def test_01_list_vgpu_host_details(self): """ list vGPU host details """ hhosts = list_hosts( - self.apiclient, - hypervisor="XenServer", - ) + self.apiclient, + hypervisor="XenServer", + ) self.assertEqual( - isinstance(hhosts, list), - True, - "Check list hosts response returns a valid list" - ) + isinstance(hhosts, list), + True, + "Check list hosts response returns a valid list" + ) self.assertNotEqual( - len(hhosts), - 0, - "Check Host details are available in List Hosts" - ) - k260q=0 - k240q=0 - k220q=0 - k200=0 - k2pass=0 + len(hhosts), + 0, + "Check Host details are available in List Hosts" + ) + k260q = 0 + k240q = 0 + k220q = 0 + k200 = 0 + k2pass = 0 - k140q=0 - k120q=0 - k100=0 - k1pass=0 + k140q = 0 + k120q = 0 + k100 = 0 + k1pass = 0 for ggroup in hhosts: if ggroup.ipaddress not in self.nongpuhosts: - for gp in ggroup.gpugroup: - if gp.gpugroupname == "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs": - for gptype in gp.vgpu: - if gptype.vgputype == "GRID K260Q": - k260q=k260q+1 - if gptype.vgputype == "GRID K220Q": - k220q=k220q+1 - if gptype.vgputype == "GRID K240Q": - k240q=k240q+1 - if gptype.vgputype == "GRID K200": - k200=k200+1 - if gptype.vgputype != "passthrough": - k2pass=k2pass+1 - if gp.gpugroupname == "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs": - for gptype in gp.vgpu: - if gptype.vgputype == "GRID K140Q": - k140q=k140q+1 - if gptype.vgputype == "GRID K120Q": - k120q=k120q+1 - if gptype.vgputype == "GRID K100": - k100=k100+1 - if gptype.vgputype == "passthrough": - k1pass=k1pass+1 + for gp in ggroup.gpugroup: + if gp.gpugroupname == "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs": + for gptype in gp.vgpu: + if gptype.vgputype == "GRID K260Q": + k260q = k260q + 1 + if gptype.vgputype == "GRID K220Q": + k220q = k220q + 1 + if gptype.vgputype == "GRID K240Q": + k240q = k240q + 1 + if gptype.vgputype == "GRID K200": + k200 = k200 + 1 + if gptype.vgputype != "passthrough": + k2pass = k2pass + 1 + if gp.gpugroupname == "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs": + for gptype in gp.vgpu: + if gptype.vgputype == "GRID K140Q": + k140q = k140q + 1 + if gptype.vgputype == "GRID K120Q": + k120q = k120q + 1 + if gptype.vgputype == "GRID K100": + k100 = k100 + 1 + if gptype.vgputype == "passthrough": + k1pass = k1pass + 1 else: - self.debug("This is nongpuhost:%s"%(ggroup.ipaddress)) - if self.k260qgpuhosts>0: - if not k260q: - self.fail("list host details with K260Q vgpu are not correct") - if self.k240qgpuhosts>0: - if not k240q: - self.fail("list host details with K240Q vgpu are not correct") - if self.k220qgpuhosts>0: - if not k220q: - self.fail("list host details with K220Q vgpu are not correct") - if self.k200gpuhosts>0: - if not k200: - self.fail("list host details with K200 vgpu are not correct") - if self.k2passthroughgpuhosts>0: + self.debug("This is nongpuhost:%s" % (ggroup.ipaddress)) + if self.k260qgpuhosts > 0: + if not k260q: + self.fail("list host details with K260Q vgpu are not correct") + if self.k240qgpuhosts > 0: + if not k240q: + self.fail("list host details with K240Q vgpu are not correct") + if self.k220qgpuhosts > 0: + if not k220q: + self.fail("list host details with K220Q vgpu are not correct") + if self.k200gpuhosts > 0: + if not k200: + self.fail("list host details with K200 vgpu are not correct") + if self.k2passthroughgpuhosts > 0: if not k2pass: - self.fail("list host details with K2 passthrough vgpu are not correct") - if self.k140qgpuhosts>0: - if not k140q: - self.fail("list host details with K140Q vgpu are not correct") - if self.k120qgpuhosts>0: - if not k120q: - self.fail("list host details with K120Q vgpu are not correct") - if self.k100gpuhosts>0: - if not k100: - self.fail("list host details with K100 vgpu are not correct") - if self.k1passthroughgpuhosts>0: - if not k1pass: - self.fail("list host details with K1 Passthrough vgpu are not correct") - - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") + self.fail( + "list host details with K2 passthrough vgpu are not correct") + if self.k140qgpuhosts > 0: + if not k140q: + self.fail("list host details with K140Q vgpu are not correct") + if self.k120qgpuhosts > 0: + if not k120q: + self.fail("list host details with K120Q vgpu are not correct") + if self.k100gpuhosts > 0: + if not k100: + self.fail("list host details with K100 vgpu are not correct") + if self.k1passthroughgpuhosts > 0: + if not k1pass: + self.fail( + "list host details with K1 Passthrough vgpu are not correct") + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def test_02_create_deploy_windows_vm_with_k100_vgpu_service_offering(self): """Test to create and deploy vm with K100 vGPU service offering""" - k100capacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK107GL [GRID K1] GPUs","GRID K100") + k100capacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs", + "GRID K100") if (self.k100gpuhosts == 0) or (k100capacity == 0): - raise unittest.SkipTest("No XenServer available with K100 vGPU Drivers installed") + raise unittest.SkipTest( + "No XenServer available with K100 vGPU Drivers installed") - self.deploy_vm("GRID K100","Group of NVIDIA Corporation GK107GL [GRID K1] GPUs") + self.deploy_vm( + "GRID K100", + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs") - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - - def test_03_create_deploy_windows_vm_with_k120q_vgpu_service_offering(self): + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") + def test_03_create_deploy_windows_vm_with_k120q_vgpu_service_offering( + self): """Test to create and deploy vm with K120Q vGPU service offering""" - k120qcapacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK107GL [GRID K1] GPUs","GRID K120Q") + k120qcapacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs", + "GRID K120Q") - if (self.k120qgpuhosts == 0) or (k120qcapacity==0): - raise unittest.SkipTest("No XenServer available with K120Q vGPU Drivers installed") + if (self.k120qgpuhosts == 0) or (k120qcapacity == 0): + raise unittest.SkipTest( + "No XenServer available with K120Q vGPU Drivers installed") - self.deploy_vm("GRID K120Q","Group of NVIDIA Corporation GK107GL [GRID K1] GPUs") + self.deploy_vm( + "GRID K120Q", + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs") - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - - def test_04_create_deploy_windows_vm_with_k140q_vgpu_service_offering(self): + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") + def test_04_create_deploy_windows_vm_with_k140q_vgpu_service_offering( + self): """Test to create and deploy vm with K140Q vGPU service offering""" - k140qcapacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK107GL [GRID K1] GPUs","GRID K140Q") + k140qcapacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs", + "GRID K140Q") - if (self.k140qgpuhosts == 0) or (k140qcapacity ==0): - raise unittest.SkipTest("No XenServer available with K140Q vGPU Drivers installed") + if (self.k140qgpuhosts == 0) or (k140qcapacity == 0): + raise unittest.SkipTest( + "No XenServer available with K140Q vGPU Drivers installed") - self.deploy_vm("GRID K140Q","Group of NVIDIA Corporation GK107GL [GRID K1] GPUs") + self.deploy_vm( + "GRID K140Q", + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs") - - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - - def test_05_create_deploy_windows_vm_with_k1_passthrough_vgpu_service_offering(self): + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") + def test_05_create_deploy_windows_vm_with_k1_passthrough_vgpu_service_offering( + self): """Test to create and deploy vm with K1 passthrough vGPU service offering""" - k1passcapacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK107GL [GRID K1] GPUs","passthrough") + k1passcapacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs", + "passthrough") - if (self.k1passthroughgpuhosts == 0) or (k1passcapacity==0): - raise unittest.SkipTest("No XenServer available with K1 passthrough installed") + if (self.k1passthroughgpuhosts == 0) or (k1passcapacity == 0): + raise unittest.SkipTest( + "No XenServer available with K1 passthrough installed") - self.deploy_vm("passthrough","Group of NVIDIA Corporation GK107GL [GRID K1] GPUs") + self.deploy_vm( + "passthrough", + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs") - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - - def test_06_create_deploy_windows_vm_with_k2_passthrough_vgpu_service_offering(self): + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") + def test_06_create_deploy_windows_vm_with_k2_passthrough_vgpu_service_offering( + self): """Test to create and deploy vm with K2 pasthrough vGPU service offering""" - k2passcapacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK104GL [GRID K2] GPUs","passthrough") + k2passcapacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs", + "passthrough") - if (self.k2passthroughgpuhosts == 0) or (k2passcapacity==0): - raise unittest.SkipTest("No XenServer available with K2 passthrough installed") + if (self.k2passthroughgpuhosts == 0) or (k2passcapacity == 0): + raise unittest.SkipTest( + "No XenServer available with K2 passthrough installed") - self.deploy_vm("passthrough","Group of NVIDIA Corporation GK104GL [GRID K2] GPUs") + self.deploy_vm( + "passthrough", + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs") - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - - def test_07_create_deploy_windows_vm_with_k260q_vgpu_service_offering(self): + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") + def test_07_create_deploy_windows_vm_with_k260q_vgpu_service_offering( + self): """Test to create and deploy vm with K260Q vGPU service offering""" - k260qcapacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK104GL [GRID K2] GPUs","GRID K260Q") + k260qcapacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs", + "GRID K260Q") if (self.k260qgpuhosts == 0) or (k260qcapacity == 0): - raise unittest.SkipTest("No XenServer available with K260Q vGPU Drivers installed") + raise unittest.SkipTest( + "No XenServer available with K260Q vGPU Drivers installed") - self.deploy_vm("GRID K260Q","Group of NVIDIA Corporation GK104GL [GRID K2] GPUs") + self.deploy_vm( + "GRID K260Q", + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs") - - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - - def test_08_create_deploy_windows_vm_with_k240q_vgpu_service_offering(self): + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") + def test_08_create_deploy_windows_vm_with_k240q_vgpu_service_offering( + self): """ Test to create and deploy vm with K240Q vGPU service offering """ - k240qcapacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK104GL [GRID K2] GPUs","GRID K240Q") + k240qcapacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs", + "GRID K240Q") - if (self.k240qgpuhosts == 0) or (k240qcapacity==0): - raise unittest.SkipTest("No XenServer available with K240Q vGPU Drivers installed") + if (self.k240qgpuhosts == 0) or (k240qcapacity == 0): + raise unittest.SkipTest( + "No XenServer available with K240Q vGPU Drivers installed") - self.deploy_vm("GRID K240Q","Group of NVIDIA Corporation GK104GL [GRID K2] GPUs") + self.deploy_vm( + "GRID K240Q", + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs") - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - - def test_09_create_deploy_windows_vm_with_k220q_vgpu_service_offering(self): + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") + def test_09_create_deploy_windows_vm_with_k220q_vgpu_service_offering( + self): """ Test to create and deploy vm with K220Q vGPU service offering """ - k220qcapacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK104GL [GRID K2] GPUs","GRID K220Q") + k220qcapacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs", + "GRID K220Q") - if (self.k220qgpuhosts == 0) or (k220qcapacity==0): - raise unittest.SkipTest("No XenServer available with K220Q vGPU Drivers installed") + if (self.k220qgpuhosts == 0) or (k220qcapacity == 0): + raise unittest.SkipTest( + "No XenServer available with K220Q vGPU Drivers installed") - self.deploy_vm("GRID K220Q","Group of NVIDIA Corporation GK104GL [GRID K2] GPUs") - - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") + self.deploy_vm( + "GRID K220Q", + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs") + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def test_10_create_deploy_windows_vm_with_k200_vgpu_service_offering(self): """ Test to create and deploy vm with K200 vGPU service offering """ - k200capacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK104GL [GRID K2] GPUs","GRID K200") + k200capacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs", + "GRID K200") - if (self.k200gpuhosts == 0) or (k200capacity==0): - raise unittest.SkipTest("No XenServer available with K200 vGPU Drivers installed") + if (self.k200gpuhosts == 0) or (k200capacity == 0): + raise unittest.SkipTest( + "No XenServer available with K200 vGPU Drivers installed") - self.deploy_vm("GRID K200","Group of NVIDIA Corporation GK104GL [GRID K2] GPUs") - - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") + self.deploy_vm( + "GRID K200", + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs") + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def test_11_add_nonvgpu_host_to_vgpucluster(self): """ Test to add non vGPU host to an existing cluster """ - countx=0 - #hostuuids=[] - huuids=[] + countx = 0 + # hostuuids=[] + huuids = [] lhosts = list_hosts( - self.apiclient, - hypervisor="XenServer" - ) + self.apiclient, + hypervisor="XenServer" + ) - sshClient1 = SshClient(host=lhosts[0].ipaddress, port=22, user='root',passwd=self.testdata["host_password"]) - totalxenhosts=len(sshClient1.execute("xe host-list | grep uuid")) + sshClient1 = SshClient( + host=lhosts[0].ipaddress, + port=self.testdata['configurabledata']['host']["publicport"], + user=self.testdata['configurabledata']['host']["username"], + passwd=self.testdata['configurabledata']['host']["password"]) + totalxenhosts = len(sshClient1.execute("xe host-list | grep uuid")) for hostlist in lhosts: - countx=countx+1 + countx = countx + 1 - if totalxenhosts<=countx: - raise unittest.SkipTest("No additional Host is available in the XS pool to add host") + if totalxenhosts <= countx: + raise unittest.SkipTest( + "No additional Host is available in the XS pool to add host") huuids.append(sshClient1.execute("xe host-list --minimal")) - self.debug("host uuids are:%s"%huuids) - hostuuids=huuids[0][0].split(',') - addhost="FAIL" + self.debug("host uuids are:%s" % huuids) + hostuuids = huuids[0][0].split(',') + addhost = "FAIL" for hid in hostuuids: - self.debug("host id: %s"%(hid)) - haddress=sshClient1.execute("xe host-param-get param-name=address --minimal uuid="+hid) - self.debug("host address is %s"%(haddress[0])) - if haddress[0]==self.testdata["vgpu"]["nongpu_host_ip"]: - addhost="PASS" - break + self.debug("host id: %s" % (hid)) + haddress = sshClient1.execute( + "xe host-param-get param-name=address --minimal uuid=" + + hid) + self.debug("host address is %s" % (haddress[0])) + if haddress[0] == self.testdata["vgpu"]["nongpu_host_ip"]: + addhost = "PASS" + break - if addhost!="PASS": - raise unittest.SkipTest("XS Pool new host ip is not matching with test data host ip. Skipping the test.Please update test data file with hostip added to XS pool") + if addhost != "PASS": + raise unittest.SkipTest( + "XS Pool new host ip is not matching with test data host ip. Skipping the test.Please update test data file with hostip added to XS pool") list_cluster_response = list_clusters( - self.apiclient, - hypervisor="XenServer", - allocationstate="Enabled" - ) + self.apiclient, + hypervisor="XenServer", + allocationstate="Enabled" + ) self.assertEqual( - isinstance(list_cluster_response, list), - True, - "Check list clusters response returns a valid list" - ) + isinstance(list_cluster_response, list), + True, + "Check list clusters response returns a valid list" + ) self.assertNotEqual( - len(list_cluster_response), - 0, - "Check list clusters response" - ) + len(list_cluster_response), + 0, + "Check list clusters response" + ) cluster_response = list_cluster_response[0] self.assertEqual( - cluster_response.allocationstate, - 'Enabled', - "Check whether allocation state of cluster is enabled" - ) - self.debug("Cluster response is:%s"%(cluster_response)) + cluster_response.allocationstate, + 'Enabled', + "Check whether allocation state of cluster is enabled" + ) + self.debug("Cluster response is:%s" % (cluster_response)) self.assertEqual( - cluster_response.hypervisortype, - "XenServer", - "Check hypervisor type is XenServer or not" - ) + cluster_response.hypervisortype, + "XenServer", + "Check hypervisor type is XenServer or not" + ) nongpuhost = Host.create( - self.apiclient, - cluster_response, - self.testdata["vgpu"]["hosts"]["nonvgpuxenserver"], - zoneid=self.zone.id, - podid=self.pod.id, - hypervisor="XenServer" - ) + self.apiclient, + cluster_response, + self.testdata["vgpu"]["hosts"]["nonvgpuxenserver"], + zoneid=self.zone.id, + podid=self.pod.id, + hypervisor="XenServer" + ) if nongpuhost == FAILED: - self.fail("Host Creation Failed") + self.fail("Host Creation Failed") self.debug( - "Created host (ID: %s) in cluster ID %s" %( - nongpuhost.id, - cluster_response.id - )) + "Created host (ID: %s) in cluster ID %s" % ( + nongpuhost.id, + cluster_response.id + )) listhosts = list_hosts( - self.apiclient, - hypervisor="XenServer", - id=nongpuhost.id - ) + self.apiclient, + hypervisor="XenServer", + id=nongpuhost.id + ) self.assertEqual( - isinstance(listhosts, list), - True, - "Check list hosts response returns a valid list" - ) + isinstance(listhosts, list), + True, + "Check list hosts response returns a valid list" + ) self.assertNotEqual( - len(listhosts), - 0, - "Check Host details are available in List Hosts" - ) + len(listhosts), + 0, + "Check Host details are available in List Hosts" + ) for ggroup in listhosts: if ggroup.gpugroup is not None: - self.fail("This is not a non vGPU host") - #Cleanup Host + self.fail("This is not a non vGPU host") + # Cleanup Host self.cleanup.append(nongpuhost) - - - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def test_12_validate_deployed_vGPU_windows_vm(self): """ Test deploy virtual machine """ @@ -1494,7 +1742,6 @@ class TestvGPUWindowsVm(cloudstackTestCase): self.debug("Check if deployed VMs are in running state?") - if self.__class__.vm_k1_card is not None: self.verify_vm(self.__class__.vm_k1_card) @@ -1504,17 +1751,16 @@ class TestvGPUWindowsVm(cloudstackTestCase): if self.__class__.vm2_k2_card is not None: self.verify_vm(self.__class__.vm2_k2_card) - - self.__class__.vmlifecycletest=1 + self.__class__.vmlifecycletest = 1 return - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def test_13_stop_vGPU_windows_vm(self): """ Test stop virtual machine """ - if self.__class__.vmlifecycletest==0: - raise unittest.SkipTest("VM Life Cycle Deploy VM test failed hence skipping") - + if self.__class__.vmlifecycletest == 0: + raise unittest.SkipTest( + "VM Life Cycle Deploy VM test failed hence skipping") if self.__class__.vm_k1_card: self.stopvm(self.__class__.vm_k1_card) @@ -1525,16 +1771,15 @@ class TestvGPUWindowsVm(cloudstackTestCase): if self.__class__.vm2_k2_card: self.stopvm(self.__class__.vm2_k2_card) - return - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def test_14_start_vGPU_windows_vm(self): """ Test start virtual machine """ - if self.__class__.vmlifecycletest==0: - raise unittest.SkipTest("VM Life Cycle Deploy VM test failed hence skipping") - + if self.__class__.vmlifecycletest == 0: + raise unittest.SkipTest( + "VM Life Cycle Deploy VM test failed hence skipping") if self.__class__.vm_k1_card: self.startvm(self.__class__.vm_k1_card) @@ -1547,14 +1792,14 @@ class TestvGPUWindowsVm(cloudstackTestCase): return - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def test_15_restore_vGPU_windows_vm(self): """Test restore Virtual Machine """ - if self.__class__.vmlifecycletest==0: - raise unittest.SkipTest("VM Life Cycle Deploy VM test failed hence skipping") - + if self.__class__.vmlifecycletest == 0: + raise unittest.SkipTest( + "VM Life Cycle Deploy VM test failed hence skipping") if self.__class__.vm_k1_card: self.restorevm(self.__class__.vm_k1_card) @@ -1563,17 +1808,16 @@ class TestvGPUWindowsVm(cloudstackTestCase): if self.__class__.vm2_k2_card: self.restorevm(self.__class__.vm2_k2_card) - return - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def test_16_reboot_vGPU_windows_vm(self): """ Test reboot virtual machine """ - if self.__class__.vmlifecycletest==0: - raise unittest.SkipTest("VM Life Cycle Deploy VM test failed hence skipping") - + if self.__class__.vmlifecycletest == 0: + raise unittest.SkipTest( + "VM Life Cycle Deploy VM test failed hence skipping") if self.__class__.vm_k1_card: self.rebootvm(self.__class__.vm_k1_card) @@ -1589,8 +1833,9 @@ class TestvGPUWindowsVm(cloudstackTestCase): """Test to create VM snapshots """ - if self.__class__.vmlifecycletest==0: - raise unittest.SkipTest("VM Life Cycle Deploy VM test failed hence skipping") + if self.__class__.vmlifecycletest == 0: + raise unittest.SkipTest( + "VM Life Cycle Deploy VM test failed hence skipping") if not (self.__class__.vm_k1_card): raise unittest.SkipTest(" No VM available.Hence skipping") @@ -1606,11 +1851,13 @@ class TestvGPUWindowsVm(cloudstackTestCase): """Test to revert VM snapshots """ - if self.__class__.vmlifecycletest==0: - raise unittest.SkipTest("VM Life Cycle Deploy VM test failed hence skipping") + if self.__class__.vmlifecycletest == 0: + raise unittest.SkipTest( + "VM Life Cycle Deploy VM test failed hence skipping") - if self.__class__.vmsnapwomemory==0: - raise unittest.SkipTest("VM Snapshot creation test failed hence skipping") + if self.__class__.vmsnapwomemory == 0: + raise unittest.SkipTest( + "VM Snapshot creation test failed hence skipping") if not self.__class__.vm_k1_card: raise unittest.SkipTest("No VM available.Hence skipping") @@ -1619,17 +1866,18 @@ class TestvGPUWindowsVm(cloudstackTestCase): return - @attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true") def test_19_delete_k1_vm_snapshot_wo_memory(self): """Test to delete vm snapshots """ - if self.__class__.vmlifecycletest==0: - raise unittest.SkipTest("VM Life Cycle Deploy VM test failed hence skipping") + if self.__class__.vmlifecycletest == 0: + raise unittest.SkipTest( + "VM Life Cycle Deploy VM test failed hence skipping") - if self.__class__.vmsnapwomemory==0: - raise unittest.SkipTest("VM Snapshot creation test failed hence skipping") + if self.__class__.vmsnapwomemory == 0: + raise unittest.SkipTest( + "VM Snapshot creation test failed hence skipping") if not (self.__class__.vm_k1_card): raise unittest.SkipTest("No VM available.Hence skipping") @@ -1638,14 +1886,14 @@ class TestvGPUWindowsVm(cloudstackTestCase): return - @attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true") def test_20_create_k2_vm_snapshot_with_memory(self): """Test to create VM snapshots """ - if self.__class__.vmlifecycletest==0: - raise unittest.SkipTest("VM Life Cycle Deploy VM test failed hence skipping") + if self.__class__.vmlifecycletest == 0: + raise unittest.SkipTest( + "VM Life Cycle Deploy VM test failed hence skipping") if not (self.__class__.vm_k2_card): raise unittest.SkipTest("No VM available.Hence skipping") @@ -1659,40 +1907,37 @@ class TestvGPUWindowsVm(cloudstackTestCase): """Test to revert VM snapshots """ + if self.__class__.vmlifecycletest == 0: + raise unittest.SkipTest( + "VM Life Cycle Deploy VM test failed hence skipping") - if self.__class__.vmlifecycletest==0: - raise unittest.SkipTest("VM Life Cycle Deploy VM test failed hence skipping") - - - if self.__class__.vmsnapwithmemory==0: - raise unittest.SkipTest("VM Snapshot creation with memory test failed hence skipping") - + if self.__class__.vmsnapwithmemory == 0: + raise unittest.SkipTest( + "VM Snapshot creation with memory test failed hence skipping") if not (self.__class__.vm_k2_card): raise unittest.SkipTest("No VM available.Hence skipping") - self.revert_vm_snapshot_with_memory(self.__class__.vm_k2_card) return - @attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true") def test_22_delete_k2_vm_snapshot_with_memory(self): """Test to delete vm snapshots """ + if self.__class__.vmlifecycletest == 0: + raise unittest.SkipTest( + "VM Life Cycle Deploy VM test failed hence skipping") - if self.__class__.vmlifecycletest==0: - raise unittest.SkipTest("VM Life Cycle Deploy VM test failed hence skipping") - - if self.__class__.vmsnapwithmemory==0: - raise unittest.SkipTest("VM Snapshot creation with memory test failed hence skipping") + if self.__class__.vmsnapwithmemory == 0: + raise unittest.SkipTest( + "VM Snapshot creation with memory test failed hence skipping") if not(self.__class__.vm_k2_card): raise unittest.SkipTest("No VM available.Hence skipping") - self.delete_vm_snapshot(self.__class__.vm_k2_card) return @@ -1702,73 +1947,96 @@ class TestvGPUWindowsVm(cloudstackTestCase): """Test to verify VM snapshot from vGPU to non vgpu to vGPU snap """ - if self.__class__.vmlifecycletest==0: - raise unittest.SkipTest("VM Life Cycle Deploy VM test failed hence skipping") + if self.__class__.vmlifecycletest == 0: + raise unittest.SkipTest( + "VM Life Cycle Deploy VM test failed hence skipping") - k1qcapacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK107GL [GRID K1] GPUs",self.__class__.vm_k1_card.vgpu) + k1qcapacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs", + self.__class__.vm_k1_card.vgpu) - if (k1qcapacity==0): - raise unittest.SkipTest("No XenServer available with K1 vGPU Drivers installed. Skipping ") + if (k1qcapacity == 0): + raise unittest.SkipTest( + "No XenServer available with K1 vGPU Drivers installed. Skipping ") if not(self.__class__.vm_k1_card): raise unittest.SkipTest("No VM available.Hence skipping") - self.vm_snapshot_vgpu(self.__class__.vm_k1_card,self.__class__.vm_k1_card.vgpu,"Group of NVIDIA Corporation GK107GL [GRID K1] GPUs","nonvgpuoffering","None") + self.vm_snapshot_vgpu( + self.__class__.vm_k1_card, + self.__class__.vm_k1_card.vgpu, + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs", + "nonvgpuoffering", + "None") return - - @attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true") def test_24_vm_snapshot_without_memory_from_nonvgpu_k1vgpu_nonvgpu(self): """Test to verify VM snapshot from non vGPU snap to vGPU snap to non vGPU snap """ - if self.__class__.vmlifecycletest==0: - raise unittest.SkipTest("VM Life Cycle Deploy VM test failed hence skipping") + if self.__class__.vmlifecycletest == 0: + raise unittest.SkipTest( + "VM Life Cycle Deploy VM test failed hence skipping") - k1qcapacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK107GL [GRID K1] GPUs",self.__class__.vm_k1_card.vgpu) + k1qcapacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs", + self.__class__.vm_k1_card.vgpu) - if (k1qcapacity==0): - raise unittest.SkipTest("No XenServer available with vGPU Drivers installed. Skipping ") + if (k1qcapacity == 0): + raise unittest.SkipTest( + "No XenServer available with vGPU Drivers installed. Skipping ") if not(self.__class__.vm_k1_card): raise unittest.SkipTest("No VM available.Hence skipping") - self.vm_snapshot_vgpu(self.__class__.nonvgpu,"nonvgpuoffering","None",self.__class__.vm_k1_card.vgpu,"Group of NVIDIA Corporation GK107GL [GRID K1] GPUs") + self.vm_snapshot_vgpu( + self.__class__.nonvgpu, + "nonvgpuoffering", + "None", + self.__class__.vm_k1_card.vgpu, + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs") return - @attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true") def test_25_vm_snapshot_without_memory_from_k2vgpu_k1vgpu_k2vgpu(self): """Test to verify VM snapshot from K2 vGPU snap to K1 vGPU snap to K2 vGPU snap """ - if self.__class__.vmlifecycletest==0: - raise unittest.SkipTest("VM Life Cycle Deploy VM test failed hence skipping") + if self.__class__.vmlifecycletest == 0: + raise unittest.SkipTest( + "VM Life Cycle Deploy VM test failed hence skipping") - k1qcapacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK107GL [GRID K1] GPUs",self.__class__.vm_k1_card.vgpu) + k1qcapacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs", + self.__class__.vm_k1_card.vgpu) if (k1qcapacity == 0): - raise unittest.SkipTest("No XenServer available with vGPU Drivers installed. Skipping ") + raise unittest.SkipTest( + "No XenServer available with vGPU Drivers installed. Skipping ") if not(self.__class__.vm_k2_card): raise unittest.SkipTest("No VM available.Hence skipping") - - self.vm_snapshot_vgpu(self.__class__.vm_k2_card,self.__class__.vm_k2_card.vgpu,"Group of NVIDIA Corporation GK104GL [GRID K2] GPUs",self.__class__.vm_k1_card.vgpu,"Group of NVIDIA Corporation GK107GL [GRID K1] GPUs") + self.vm_snapshot_vgpu( + self.__class__.vm_k2_card, + self.__class__.vm_k2_card.vgpu, + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs", + self.__class__.vm_k1_card.vgpu, + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs") return - - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def test_26_destroy_vGPU_windows_vm(self): """Test destroy Virtual Machine """ - if self.__class__.vmlifecycletest==0: - raise unittest.SkipTest("VM Life Cycle Deploy VM test failed hence skipping") + if self.__class__.vmlifecycletest == 0: + raise unittest.SkipTest( + "VM Life Cycle Deploy VM test failed hence skipping") if self.__class__.vm_k2_card: self.deletevm(self.__class__.vm_k2_card) @@ -1788,13 +2056,14 @@ class TestvGPUWindowsVm(cloudstackTestCase): return - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def test_27_recover_vGPU_windows_vm(self): """Test recover Virtual Machine """ - if self.__class__.vmlifecycletest==0: - raise unittest.SkipTest("VM Life Cycle Deploy VM test failed hence skipping") + if self.__class__.vmlifecycletest == 0: + raise unittest.SkipTest( + "VM Life Cycle Deploy VM test failed hence skipping") if self.__class__.vm_k2_card is not None: self.recovervm(self.__class__.vm_k2_card) @@ -1811,143 +2080,200 @@ class TestvGPUWindowsVm(cloudstackTestCase): """Test destroy Virtual Machine """ - if self.__class__.vmlifecycletest==0: - raise unittest.SkipTest("VM Life Cycle Deploy VM test failed hence skipping") + if self.__class__.vmlifecycletest == 0: + raise unittest.SkipTest( + "VM Life Cycle Deploy VM test failed hence skipping") if self.__class__.vm_k1_card: - if self.check_vm_state(self.__class__.vm_k1_card.id)=="Expunge": + if self.check_vm_state(self.__class__.vm_k1_card.id) == "Expunge": raise unittest.SkipTest("VM is already deleted hence skipping") self.deletevm(self.__class__.vm_k1_card) if self.__class__.vm_k2_card: - if self.check_vm_state(self.__class__.vm_k2_card.id)=="Expunge": + if self.check_vm_state(self.__class__.vm_k2_card.id) == "Expunge": raise unittest.SkipTest("VM is already deleted hence skipping") self.deletevm(self.__class__.vm_k2_card) if self.__class__.vm2_k2_card: - if self.check_vm_state(self.__class__.vm2_k2_card.id)=="Expunge": + if self.check_vm_state(self.__class__.vm2_k2_card.id) == "Expunge": raise unittest.SkipTest("VM is already deleted hence skipping") self.deletevm(self.__class__.vm2_k2_card) return - - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def test_29_nonvgpuvm_k2vgpuvm_offline(self): """Test to change service from non vgpu to vgpu K200""" - k200capacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK104GL [GRID K2] GPUs","GRID K200") - if (self.k200gpuhosts == 0) or (k200capacity==0): - raise unittest.SkipTest("No XenServer available with K200 vGPU Drivers installed. Skipping non gpu to K200 Offering Upgrade") + k200capacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs", + "GRID K200") + if (self.k200gpuhosts == 0) or (k200capacity == 0): + raise unittest.SkipTest( + "No XenServer available with K200 vGPU Drivers installed. Skipping non gpu to K200 Offering Upgrade") - self.serviceoffering_upgrade("nonvgpuoffering","None","GRID K200","Group of NVIDIA Corporation GK104GL [GRID K2] GPUs") + self.serviceoffering_upgrade( + "nonvgpuoffering", + "None", + "GRID K200", + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs") return - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def test_30_K2_vgpuvm_vgpuvm_offline(self): """Test to change service from vgpu K200 to vgpu K240Q""" - k240qcapacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK104GL [GRID K2] GPUs","GRID K240Q") - k200capacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK104GL [GRID K2] GPUs","GRID K200") - if (self.k240qgpuhosts == 0) or (self.k200gpuhosts == 0) or (k240qcapacity==0) or (k200capacity==0): - raise unittest.SkipTest("No XenServer available with K240Q,K200Q vGPU Drivers installed. Skipping K200 to K240Q Offering Upgrade") + k240qcapacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs", + "GRID K240Q") + k200capacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs", + "GRID K200") + if (self.k240qgpuhosts == 0) or (self.k200gpuhosts == 0) or ( + k240qcapacity == 0) or (k200capacity == 0): + raise unittest.SkipTest( + "No XenServer available with K240Q,K200Q vGPU Drivers installed. Skipping K200 to K240Q Offering Upgrade") - self.serviceoffering_upgrade("GRID K200","Group of NVIDIA Corporation GK104GL [GRID K2] GPUs","GRID K240Q","Group of NVIDIA Corporation GK104GL [GRID K2] GPUs") + self.serviceoffering_upgrade( + "GRID K200", + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs", + "GRID K240Q", + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs") return - - - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def test_31_K1_vgpuvm_vgpuvm_offline(self): """Test to change service from K1 vgpu K120Q to K1 vgpu K140Q""" - k140qcapacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK107GL [GRID K1] GPUs","GRID K140Q") - k120qcapacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK107GL [GRID K1] GPUs","GRID K120Q") + k140qcapacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs", + "GRID K140Q") + k120qcapacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs", + "GRID K120Q") - if (self.k140qgpuhosts == 0) or (self.k120qgpuhosts == 0) or (k140qcapacity==0) or (k120qcapacity==0): - raise unittest.SkipTest("No XenServer available with K140Q,K120Q vGPU Drivers installed. Skipping K200 to K240Q Offering Upgrade") + if (self.k140qgpuhosts == 0) or (self.k120qgpuhosts == 0) or ( + k140qcapacity == 0) or (k120qcapacity == 0): + raise unittest.SkipTest( + "No XenServer available with K140Q,K120Q vGPU Drivers installed. Skipping K200 to K240Q Offering Upgrade") - self.serviceoffering_upgrade("GRID K120Q","Group of NVIDIA Corporation GK107GL [GRID K1] GPUs","GRID K140Q","Group of NVIDIA Corporation GK107GL [GRID K1] GPUs") + self.serviceoffering_upgrade( + "GRID K120Q", + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs", + "GRID K140Q", + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs") return - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def test_32_nonvgpuvm_k1vgpuvm_offline(self): """Test to change service from non vgpu to vgpu K100""" - k100capacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK107GL [GRID K1] GPUs","GRID K100") + k100capacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs", + "GRID K100") if (self.k100gpuhosts == 0) or (k100capacity == 0): - raise unittest.SkipTest("No XenServer available with K100 vGPU Drivers installed. Skipping non gpu to K100 Offering Upgrade") - self.serviceoffering_upgrade("nonvgpuoffering","None","GRID K100","Group of NVIDIA Corporation GK107GL [GRID K1] GPUs") + raise unittest.SkipTest( + "No XenServer available with K100 vGPU Drivers installed. Skipping non gpu to K100 Offering Upgrade") + self.serviceoffering_upgrade( + "nonvgpuoffering", + "None", + "GRID K100", + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs") return - - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def test_33_K2_vgpuvm_nonvgpuvm_offline(self): """Test to change service from non vgpu to vgpu K240Q""" - k240qcapacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK104GL [GRID K2] GPUs","GRID K240Q") - if (self.k240qgpuhosts == 0) or (k240qcapacity==0): - raise unittest.SkipTest("No XenServer available with K240Q vGPU Drivers installed. Skipping K2 vgpu 240Q to nonvgpu Offering Upgrade") + k240qcapacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs", + "GRID K240Q") + if (self.k240qgpuhosts == 0) or (k240qcapacity == 0): + raise unittest.SkipTest( + "No XenServer available with K240Q vGPU Drivers installed. Skipping K2 vgpu 240Q to nonvgpu Offering Upgrade") - self.serviceoffering_upgrade("GRID K240Q","Group of NVIDIA Corporation GK104GL [GRID K2] GPUs","nonvgpuoffering","None") + self.serviceoffering_upgrade( + "GRID K240Q", + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs", + "nonvgpuoffering", + "None") return - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def test_34_K1_vgpuvm_nonvgpuvm_offline(self): """Test to change service from non vgpu to vgpu K140Q""" - k140qcapacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK107GL [GRID K1] GPUs","GRID K140Q") + k140qcapacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs", + "GRID K140Q") - if (self.k140qgpuhosts == 0) or (k140qcapacity==0): - raise unittest.SkipTest("No XenServer available with K140Q vGPU Drivers installed. Skipping K1 vgpu 140Q to nonvgpu Offering Upgrade") + if (self.k140qgpuhosts == 0) or (k140qcapacity == 0): + raise unittest.SkipTest( + "No XenServer available with K140Q vGPU Drivers installed. Skipping K1 vgpu 140Q to nonvgpu Offering Upgrade") - self.serviceoffering_upgrade("GRID K140Q","Group of NVIDIA Corporation GK107GL [GRID K1] GPUs","nonvgpuoffering","None") + self.serviceoffering_upgrade( + "GRID K140Q", + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs", + "nonvgpuoffering", + "None") return - - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def test_35_K140Q_vgpuvm_K240Q_vgpuvm_offline(self): """Test to change service from K1 vgpu K140Q to K2 vgpu K240Q""" - k140qcapacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK107GL [GRID K1] GPUs","GRID K140Q") - k240qcapacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK104GL [GRID K2] GPUs","GRID K240Q") + k140qcapacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs", + "GRID K140Q") + k240qcapacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs", + "GRID K240Q") - if (self.k140qgpuhosts == 0) or (self.k240qgpuhosts == 0) or (k140qcapacity == 0) or (k240qcapacity==0): - raise unittest.SkipTest("No XenServer available with K140Q,K240Q vGPU Drivers installed. Skipping K140Q to K240Q Offering Upgrade") + if (self.k140qgpuhosts == 0) or (self.k240qgpuhosts == 0) or ( + k140qcapacity == 0) or (k240qcapacity == 0): + raise unittest.SkipTest( + "No XenServer available with K140Q,K240Q vGPU Drivers installed. Skipping K140Q to K240Q Offering Upgrade") - self.serviceoffering_upgrade("GRID K140Q","Group of NVIDIA Corporation GK107GL [GRID K1] GPUs","GRID K240Q","Group of NVIDIA Corporation GK104GL [GRID K2] GPUs") + self.serviceoffering_upgrade( + "GRID K140Q", + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs", + "GRID K240Q", + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs") return - @attr(tags = ['advanced', 'basic' , 'vgpu'], required_hardware="true") - + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def test_36_K240Q_vgpuvm_K140Q_vgpuvm_offline(self): """Test to change service from K2 vgpu K240Q to K1 vgpu K140Q""" - k140qcapacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK107GL [GRID K1] GPUs","GRID K140Q") - k240qcapacity=self.check_host_vgpu_capacity("Group of NVIDIA Corporation GK104GL [GRID K2] GPUs","GRID K240Q") + k140qcapacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs", + "GRID K140Q") + k240qcapacity = self.check_host_vgpu_capacity( + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs", + "GRID K240Q") - if (self.k140qgpuhosts == 0) or (self.k240qgpuhosts == 0) or (k140qcapacity == 0) or (k240qcapacity==0): - raise unittest.SkipTest("No XenServer available with K140Q,K240Q vGPU Drivers installed. Skipping K140Q to K240Q Offering Upgrade") + if (self.k140qgpuhosts == 0) or (self.k240qgpuhosts == 0) or ( + k140qcapacity == 0) or (k240qcapacity == 0): + raise unittest.SkipTest( + "No XenServer available with K140Q,K240Q vGPU Drivers installed. Skipping K140Q to K240Q Offering Upgrade") - self.serviceoffering_upgrade("GRID K240Q","Group of NVIDIA Corporation GK104GL [GRID K2] GPUs","GRID K140Q","Group of NVIDIA Corporation GK107GL [GRID K1] GPUs") + self.serviceoffering_upgrade( + "GRID K240Q", + "Group of NVIDIA Corporation GK104GL [GRID K2] GPUs", + "GRID K140Q", + "Group of NVIDIA Corporation GK107GL [GRID K1] GPUs") return - @classmethod def tearDownClass(self): try: - self.apiclient = super(TestvGPUWindowsVm, self).getClsTestClient().getApiClient() + self.apiclient = super( + TestvGPUWindowsVm, + self).getClsTestClient().getApiClient() cleanup_resources(self.apiclient, self._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -1958,7 +2284,3 @@ class TestvGPUWindowsVm(cloudstackTestCase): cleanup_resources(self.apiclient, self.cleanup) except Exception as e: self.debug("Warning! Exception in tearDown: %s" % e) - - - - diff --git a/test/integration/component/test_persistent_networks.py b/test/integration/component/test_persistent_networks.py index 4b1bc7aada5..ae184245118 100644 --- a/test/integration/component/test_persistent_networks.py +++ b/test/integration/component/test_persistent_networks.py @@ -97,7 +97,8 @@ class TestPersistentNetworks(cloudstackTestCase): cls.isolated_network_offering_netscaler = cls.createNetworkOffering( "nw_off_isolated_netscaler") - cls.services["configurableData"]["netscaler"]["lbdevicededicated"] = False + cls.services["configurableData"]["netscaler"]["lbdevicededicated"] =\ + False # Configure Netscaler device # If configuration succeeds, set ns_configured to True so that @@ -172,9 +173,9 @@ class TestPersistentNetworks(cloudstackTestCase): try: sshClient = SshClient( host=sourceip, - port=22, - user='root', - passwd=self.services["host_password"]) + port=self.services['configurableData']['host']["publicport"], + user=self.services['configurableData']['host']["username"], + passwd=self.services['configurableData']['host']["password"]) res = sshClient.execute("ping -c 1 %s" % ( router.linklocalip )) @@ -1502,7 +1503,8 @@ class TestAssignVirtualMachine(cloudstackTestCase): cls.persistent_network_offering_netscaler = cls.createNetworkOffering( "nw_off_isolated_persistent_netscaler") - cls.services["configurableData"]["netscaler"]["lbdevicededicated"] = False + cls.services["configurableData"]["netscaler"]["lbdevicededicated"] =\ + False # Configure Netscaler device # If configuration succeeds, set ns_configured to True so that @@ -1968,7 +1970,8 @@ class TestRestartPersistentNetwork(cloudstackTestCase): cls.api_client, state="enabled") - cls.services["configurableData"]["netscaler"]["lbdevicededicated"] = False + cls.services["configurableData"]["netscaler"]["lbdevicededicated"] =\ + False # Configure Netscaler device # If configuration succeeds, set ns_configured to True so that @@ -2039,9 +2042,9 @@ class TestRestartPersistentNetwork(cloudstackTestCase): try: sshClient = SshClient( host=sourceip, - port=22, - user='root', - passwd=self.services["host_password"]) + port=self.services['configurableData']['host']["publicport"], + user=self.services['configurableData']['host']["username"], + passwd=self.services['configurableData']['host']["password"]) res = sshClient.execute("ping -c 1 %s" % ( router.linklocalip )) diff --git a/test/integration/smoke/test_deploy_vgpu_enabled_vm.py b/test/integration/smoke/test_deploy_vgpu_enabled_vm.py index f13ac9270e0..7cf46ea2c5b 100644 --- a/test/integration/smoke/test_deploy_vgpu_enabled_vm.py +++ b/test/integration/smoke/test_deploy_vgpu_enabled_vm.py @@ -15,29 +15,32 @@ # specific language governing permissions and limitations # under the License. -#Test from the Marvin - Testing in Python wiki +# Test from the Marvin - Testing in Python wiki -#All tests inherit from cloudstackTestCase +# All tests inherit from cloudstackTestCase from marvin.cloudstackTestCase import cloudstackTestCase, unittest -#Import Integration Libraries +# Import Integration Libraries -#base - contains all resources as entities and defines create, delete, list operations on them +# base - contains all resources as entities and defines create, delete, +# list operations on them from marvin.lib.base import Account, VirtualMachine, ServiceOffering -#utils - utility classes for common cleanup, external library wrappers etc +# utils - utility classes for common cleanup, external library wrappers etc from marvin.lib.utils import cleanup_resources -#common - commonly used methods for all tests are listed here +# common - commonly used methods for all tests are listed here from marvin.lib.common import get_zone, get_domain, get_template, list_hosts from marvin.sshClient import SshClient -from marvin.codes import FAILED, XEN_SERVER +from marvin.codes import FAILED from nose.plugins.attrib import attr + class TestDeployvGPUenabledVM(cloudstackTestCase): + """ Test deploy a vGPU enabled VM into a user account """ @@ -46,41 +49,51 @@ class TestDeployvGPUenabledVM(cloudstackTestCase): testClient = super(TestDeployvGPUenabledVM, self).getClsTestClient() self.apiclient = testClient.getApiClient() self.testdata = self.testClient.getParsedTestDataConfig() - #Need to add check whether zone containing the xen hypervisor or not as well + # Need to add check whether zone containing the xen hypervisor or not + # as well hosts = list_hosts( - self.apiclient, - hypervisor="XenServer" - ) + self.apiclient, + hypervisor="XenServer" + ) if hosts is None: - raise unittest.SkipTest("There are no XenServers available. GPU feature is supported only on XenServer.Check listhosts response") - else: - gpuhosts=0 - for ghost in hosts : - if ghost.hypervisorversion >= "6.2.0": - sshClient = SshClient(host=ghost.ipaddress, port=22, user='root',passwd=self.testdata["host_password"]) - if ghost.hypervisorversion == "6.2.0": - res = sshClient.execute("xe patch-list uuid=0850b186-4d47-11e3-a720-001b2151a503") - if len(res) == 0: - continue - res = sshClient.execute("xe vgpu-type-list model-name=\"GRID K120Q\"") - if len(res) != 0 : - gpuhosts=gpuhosts+1 - else: - continue + raise unittest.SkipTest( + "There are no XenServers available. GPU feature is supported only on XenServer.Check listhosts response") + else: + gpuhosts = 0 + for ghost in hosts: + if ghost.hypervisorversion >= "6.2.0": + sshClient = SshClient( + host=ghost.ipaddress, + port=self.testdata['configurableData']['host']["publicport"], + user=self.testdata['configurableData']['host']["username"], + passwd=self.testdata['configurableData']['host']["password"]) + if ghost.hypervisorversion == "6.2.0": + res = sshClient.execute( + "xe patch-list uuid=0850b186-4d47-11e3-a720-001b2151a503") + if len(res) == 0: + continue + res = sshClient.execute( + "xe vgpu-type-list model-name=\"GRID K120Q\"") + if len(res) != 0: + gpuhosts = gpuhosts + 1 + else: + continue if gpuhosts == 0: - raise unittest.SkipTest("No XenServer available with GPU Drivers installed") + raise unittest.SkipTest( + "No XenServer available with GPU Drivers installed") self.domain = get_domain(self.apiclient) self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) - #Creating Account + # Creating Account self.account = Account.create( self.apiclient, self.testdata["account"], domainid=self.domain.id - ) + ) self._cleanup = [ - self.account - ] + self.account + ] + def setUp(self): self.testdata = self.testClient.getParsedTestDataConfig()["vgpu"] self.apiclient = self.testClient.getApiClient() @@ -89,12 +102,17 @@ class TestDeployvGPUenabledVM(cloudstackTestCase): self.domain = get_domain(self.apiclient) self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) self.testdata["mode"] = self.zone.networktype - # Before running this test, register a windows template with ostype as 'Windows 7 (32-bit)' - self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"]) + # Before running this test, register a windows template with ostype as + # 'Windows 7 (32-bit)' + self.template = get_template( + self.apiclient, + self.zone.id, + self.testdata["ostype"]) if self.template == FAILED: - assert False, "get_template() failed to return template with description %s" % self.testdata["ostype"] - #create a user account + assert False, "get_template() failed to return template with description %s" % self.testdata[ + "ostype"] + # create a user account self.account = Account.create( self.apiclient, self.testdata["account"], @@ -106,20 +124,22 @@ class TestDeployvGPUenabledVM(cloudstackTestCase): self.testdata["vgpu140q"]["zoneid"] = self.zone.id self.testdata["vgpu140q"]["template"] = self.template.id - self.testdata["service_offerings"]["vgpu260qwin"]["serviceofferingdetails"] = [{'pciDevice': 'Group of NVIDIA Corporation GK107GL [GRID K1] GPUs'}, - {'vgpuType':'GRID K120Q'}] - #create a service offering + self.testdata["service_offerings"]["vgpu260qwin"]["serviceofferingdetails"] = [ + { + 'pciDevice': 'Group of NVIDIA Corporation GK107GL [GRID K1] GPUs'}, { + 'vgpuType': 'GRID K120Q'}] + # create a service offering self.service_offering = ServiceOffering.create( - self.apiclient, - self.testdata["service_offerings"]["vgpu260qwin"], + self.apiclient, + self.testdata["service_offerings"]["vgpu260qwin"], ) - #build cleanup list + # build cleanup list self.cleanup = [ self.service_offering, self.account ] - @attr(tags = ['advanced', 'basic', 'vgpu'], required_hardware="true") + @attr(tags=['advanced', 'basic', 'vgpu'], required_hardware="true") def test_deploy_vgpu_enabled_vm(self): """Test Deploy Virtual Machine @@ -137,10 +157,12 @@ class TestDeployvGPUenabledVM(cloudstackTestCase): mode=self.testdata['mode'] ) - list_vms = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id) + list_vms = VirtualMachine.list( + self.apiclient, + id=self.virtual_machine.id) self.debug( - "Verify listVirtualMachines response for virtual machine: %s"\ + "Verify listVirtualMachines response for virtual machine: %s" % self.virtual_machine.id ) @@ -172,26 +194,30 @@ class TestDeployvGPUenabledVM(cloudstackTestCase): msg="VM is not in Running state" ) hosts = list_hosts( - self.apiclient, - id=vm.hostid - ) + self.apiclient, + id=vm.hostid + ) hostip = hosts[0].ipaddress try: - sshClient = SshClient(host=hostip, port=22, user='root',passwd=self.testdata["host_password"]) - res = sshClient.execute("xe vgpu-list vm-name-label=%s params=type-uuid %s" % ( - vm.instancename - )) + sshClient = SshClient( + host=hostip, + port=self.testdata['configurableData']['host']["publicport"], + user=self.testdata['configurableData']['host']["username"], + passwd=self.testdata['configurableData']['host']["password"]) + res = sshClient.execute( + "xe vgpu-list vm-name-label=%s params=type-uuid %s" % + (vm.instancename)) self.debug("SSH result: %s" % res) except Exception as e: - self.fail("SSH Access failed for %s: %s" % \ + self.fail("SSH Access failed for %s: %s" % (hostip, e) ) result = str(res) self.assertEqual( - result.count("type-uuid"), - 1, - "VM is vGPU enabled." - ) + result.count("type-uuid"), + 1, + "VM is vGPU enabled." + ) def tearDown(self): try: