1818#Test from the Marvin - Testing in Python wiki
1919
2020#All tests inherit from cloudstackTestCase
21- from marvin .cloudstackTestCase import cloudstackTestCase
21+ from marvin .cloudstackTestCase import cloudstackTestCase , unittest
2222
2323#Import Integration Libraries
2424
2929from marvin .lib .utils import cleanup_resources
3030
3131#common - commonly used methods for all tests are listed here
32- from marvin .lib .common import get_zone , get_domain , get_template
32+ from marvin .lib .common import get_zone , get_domain , get_template , list_hosts
3333
34- from marvin .codes import FAILED
34+ from marvin .sshClient import SshClient
3535
36- from nose .plugins .attrib import attr
37-
38-
39- class Services :
40- """Test VM Life Cycle Services
41- """
42-
43- def __init__ (self ):
44- self .services = {
45- "disk_offering" :{
46- "displaytext" : "Small" ,
47- "name" : "Small" ,
48- "disksize" : 1
49- },
50- "account" : {
51- "email" : "test@test.com" ,
52- "firstname" : "Test" ,
53- "lastname" : "User" ,
54- "username" : "test" ,
55- # Random characters are appended in create account to
56- # ensure unique username generated each time
57- "password" : "password" ,
58- },
59- "vgpu260q" : # Create a virtual machine instance with vgpu type as 260q
60- {
61- "displayname" : "testserver" ,
62- "username" : "root" , # VM creds for SSH
63- "password" : "password" ,
64- "ssh_port" : 22 ,
65- "hypervisor" : 'XenServer' ,
66- "privateport" : 22 ,
67- "publicport" : 22 ,
68- "protocol" : 'TCP' ,
69- },
70- "vgpu140q" : # Create a virtual machine instance with vgpu type as 140q
71- {
72- "displayname" : "testserver" ,
73- "username" : "root" ,
74- "password" : "password" ,
75- "ssh_port" : 22 ,
76- "hypervisor" : 'XenServer' ,
77- "privateport" : 22 ,
78- "publicport" : 22 ,
79- "protocol" : 'TCP' ,
80- },
81- "service_offerings" :
82- {
83- "vgpu260qwin" :
84- {
85- "name" : "Windows Instance with vGPU260Q" ,
86- "displaytext" : "Windows Instance with vGPU260Q" ,
87- "cpunumber" : 2 ,
88- "cpuspeed" : 1600 , # in MHz
89- "memory" : 3072 , # In MBs
90- },
91- "vgpu140qwin" :
92- {
93- # Small service offering ID to for change VM
94- # service offering from medium to small
95- "name" : "Windows Instance with vGPU140Q" ,
96- "displaytext" : "Windows Instance with vGPU140Q" ,
97- "cpunumber" : 2 ,
98- "cpuspeed" : 1600 ,
99- "memory" : 3072 ,
100- }
101- },
102- "diskdevice" : ['/dev/vdc' , '/dev/vdb' , '/dev/hdb' , '/dev/hdc' , '/dev/xvdd' , '/dev/cdrom' , '/dev/sr0' , '/dev/cdrom1' ],
103- # Disk device where ISO is attached to instance
104- "mount_dir" : "/mnt/tmp" ,
105- "sleep" : 60 ,
106- "timeout" : 10 ,
107- #Migrate VM to hostid
108- "ostype" : 'Windows 7 (32-bit)' ,
109- # CentOS 5.3 (64-bit)
110- }
36+ from marvin .codes import FAILED , XEN_SERVER
11137
38+ from nose .plugins .attrib import attr
11239
11340class TestDeployvGPUenabledVM (cloudstackTestCase ):
114- """Test deploy a vGPU enabled VM into a user account
11541 """
42+ Test deploy a vGPU enabled VM into a user account
43+ """
44+ @classmethod
45+ def setUpClass (cls ):
46+ testClient = super (TestDeployvGPUenabledVM , cls ).getClsTestClient ()
47+ #Need to add check whether zone containing the xen hypervisor or not as well
48+ hypervisor = testClient .getHypervisorInfo ()
49+ if hypervisor .lower () != XEN_SERVER .lower ():
50+ raise unittest .skipTest ("GPU feature is supported only on XenServer" )
51+
11652
11753 def setUp (self ):
118- self .services = Services (). services
54+ self .testdata = self . testClient . getParsedTestDataConfig ()[ "vgpu" ]
11955 self .apiclient = self .testClient .getApiClient ()
12056
12157 # Get Zone, Domain and Default Built-in template
12258 self .domain = get_domain (self .apiclient )
12359 self .zone = get_zone (self .apiclient , self .testClient .getZoneForTests ())
124- self .services ["mode" ] = self .zone .networktype
60+ self .testdata ["mode" ] = self .zone .networktype
12561 # Before running this test, register a windows template with ostype as 'Windows 7 (32-bit)'
126- self .services ["ostype" ] = 'Windows 7 (32-bit)'
127- self .template = get_template (self .apiclient , self .zone .id , self .services ["ostype" ])
62+ self .template = get_template (self .apiclient , self .zone .id , self .testdata ["ostype" ])
12863
12964 if self .template == FAILED :
130- assert False , "get_template() failed to return template with description %s" % self .services ["ostype" ]
65+ assert False , "get_template() failed to return template with description %s" % self .testdata ["ostype" ]
13166 #create a user account
13267 self .account = Account .create (
13368 self .apiclient ,
134- self .services ["account" ],
69+ self .testdata ["account" ],
13570 domainid = self .domain .id
13671 )
13772
138- self .services ["vgpu260q" ]["zoneid" ] = self .zone .id
139- self .services ["vgpu260q" ]["template" ] = self .template .id
73+ self .testdata ["vgpu260q" ]["zoneid" ] = self .zone .id
74+ self .testdata ["vgpu260q" ]["template" ] = self .template .id
14075
141- self .services ["vgpu140q" ]["zoneid" ] = self .zone .id
142- self .services ["vgpu140q" ]["template" ] = self .template .id
76+ self .testdata ["vgpu140q" ]["zoneid" ] = self .zone .id
77+ self .testdata ["vgpu140q" ]["template" ] = self .template .id
14378 #create a service offering
14479 self .service_offering = ServiceOffering .create (
14580 self .apiclient ,
146- self .services ["service_offerings" ]["vgpu260qwin" ],
81+ self .testdata ["service_offerings" ]["vgpu260qwin" ],
14782 serviceofferingdetails = {'pciDevice' : 'VGPU' }
14883 )
14984 #build cleanup list
@@ -152,7 +87,7 @@ def setUp(self):
15287 self .account
15388 ]
15489
155- @attr (tags = ['advanced' , 'simulator' , ' basic' , 'vgpu' , 'provisioning' ] )
90+ @attr (tags = ['advanced' , 'basic' , 'vgpu' ], required_hardware = "true" , BugId = "CLOUDSTACK-6876" )
15691 def test_deploy_vgpu_enabled_vm (self ):
15792 """Test Deploy Virtual Machine
15893
@@ -163,11 +98,11 @@ def test_deploy_vgpu_enabled_vm(self):
16398 """
16499 self .virtual_machine = VirtualMachine .create (
165100 self .apiclient ,
166- self .services ["vgpu260q" ],
101+ self .testdata ["vgpu260q" ],
167102 accountid = self .account .name ,
168103 domainid = self .account .domainid ,
169104 serviceofferingid = self .service_offering .id ,
170- mode = self .services ['mode' ]
105+ mode = self .testdata ['mode' ]
171106 )
172107
173108 list_vms = VirtualMachine .list (self .apiclient , id = self .virtual_machine .id )
@@ -204,13 +139,13 @@ def test_deploy_vgpu_enabled_vm(self):
204139 "Running" ,
205140 msg = "VM is not in Running state"
206141 )
207- list_hosts = list_hosts (
142+ hosts = list_hosts (
208143 self .apiclient ,
209144 id = vm .hostid
210145 )
211- hostip = list_hosts [0 ].ipaddress
146+ hostip = hosts [0 ].ipaddress
212147 try :
213- sshClient = SshClient (host = hostip , port = 22 , user = 'root' ,passwd = self .services ["host_password" ])
148+ sshClient = SshClient (host = hostip , port = 22 , user = 'root' ,passwd = self .testdata ["host_password" ])
214149 res = sshClient .execute ("xe vgpu-list vm-name-label=%s params=type-uuid %s" % (
215150 vm .instancename
216151 ))
@@ -230,4 +165,4 @@ def tearDown(self):
230165 try :
231166 cleanup_resources (self .apiclient , self .cleanup )
232167 except Exception as e :
233- self .debug ("Warning! Exception in tearDown: %s" % e )
168+ self .debug ("Warning! Exception in tearDown: %s" % e )
0 commit comments