55# to you under the Apache License, Version 2.0 (the
66# "License"); you may not use this file except in compliance
77# with the License. You may obtain a copy of the License at
8- #
8+ #
99# http://www.apache.org/licenses/LICENSE-2.0
10- #
10+ #
1111# Unless required by applicable law or agreed to in writing,
1212# software distributed under the License is distributed on an
1313# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1616# under the License.
1717""" BVT tests for Service offerings"""
1818
19- #Import Local Modules
19+ # Import Local Modules
2020from marvin .codes import FAILED
2121from marvin .cloudstackTestCase import cloudstackTestCase
22- from marvin .cloudstackAPI import changeServiceForVirtualMachine ,updateServiceOffering
22+ from marvin .cloudstackAPI import (changeServiceForVirtualMachine ,
23+ updateServiceOffering )
2324from marvin .lib .utils import (isAlmostEqual ,
24- cleanup_resources ,
25- random_gen )
25+ cleanup_resources ,
26+ random_gen )
2627from marvin .lib .base import (ServiceOffering ,
27- Account ,
28- VirtualMachine )
28+ Account ,
29+ VirtualMachine )
2930from marvin .lib .common import (list_service_offering ,
30- list_virtual_machines ,
31- get_domain ,
32- get_zone ,
33- get_template )
31+ list_virtual_machines ,
32+ get_domain ,
33+ get_zone ,
34+ get_template )
3435from nose .plugins .attrib import attr
3536
3637
3738_multiprocess_shared_ = True
3839
3940
4041class TestCreateServiceOffering (cloudstackTestCase ):
42+
4143 def setUp (self ):
4244 self .apiclient = self .testClient .getApiClient ()
4345 self .dbclient = self .testClient .getDbConnection ()
@@ -46,20 +48,29 @@ def setUp(self):
4648
4749 def tearDown (self ):
4850 try :
49- #Clean up, terminate the created templates
51+ # Clean up, terminate the created templates
5052 cleanup_resources (self .apiclient , self .cleanup )
5153
5254 except Exception as e :
5355 raise Exception ("Warning: Exception during cleanup : %s" % e )
5456
5557 return
5658
57- @attr (tags = ["advanced" , "advancedns" , "smoke" , "basic" , "eip" , "sg" ], required_hardware = "false" )
59+ @attr (
60+ tags = [
61+ "advanced" ,
62+ "advancedns" ,
63+ "smoke" ,
64+ "basic" ,
65+ "eip" ,
66+ "sg" ],
67+ required_hardware = "false" )
5868 def test_01_create_service_offering (self ):
5969 """Test to create service offering"""
6070
6171 # Validate the following:
62- # 1. createServiceOfferings should return a valid information for newly created offering
72+ # 1. createServiceOfferings should return a valid information
73+ # for newly created offering
6374 # 2. The Cloud Database contains the valid information
6475
6576 service_offering = ServiceOffering .create (
@@ -68,7 +79,9 @@ def test_01_create_service_offering(self):
6879 )
6980 self .cleanup .append (service_offering )
7081
71- self .debug ("Created service offering with ID: %s" % service_offering .id )
82+ self .debug (
83+ "Created service offering with ID: %s" %
84+ service_offering .id )
7285
7386 list_service_response = list_service_offering (
7487 self .apiclient ,
@@ -115,14 +128,15 @@ def test_01_create_service_offering(self):
115128
116129
117130class TestServiceOfferings (cloudstackTestCase ):
131+
118132 def setUp (self ):
119133 self .apiclient = self .testClient .getApiClient ()
120134 self .dbclient = self .testClient .getDbConnection ()
121135 self .cleanup = []
122136
123137 def tearDown (self ):
124138 try :
125- #Clean up, terminate the created templates
139+ # Clean up, terminate the created templates
126140 cleanup_resources (self .apiclient , self .cleanup )
127141
128142 except Exception as e :
@@ -135,6 +149,7 @@ def setUpClass(cls):
135149 testClient = super (TestServiceOfferings , cls ).getClsTestClient ()
136150 cls .apiclient = testClient .getApiClient ()
137151 cls .services = testClient .getParsedTestDataConfig ()
152+ cls .hypervisor = testClient .getHypervisorInfo ()
138153
139154 domain = get_domain (cls .apiclient )
140155 cls .zone = get_zone (cls .apiclient , testClient .getZoneForTests ())
@@ -149,12 +164,13 @@ def setUpClass(cls):
149164 cls .services ["service_offerings" ]
150165 )
151166 template = get_template (
152- cls .apiclient ,
153- cls .zone .id ,
154- cls .services ["ostype" ]
155- )
167+ cls .apiclient ,
168+ cls .zone .id ,
169+ cls .services ["ostype" ]
170+ )
156171 if template == FAILED :
157- assert False , "get_template() failed to return template with description %s" % cls .services ["ostype" ]
172+ assert False , "get_template() failed to return\
173+ template with description %s" % cls .services ["ostype" ]
158174
159175 # Set Zones and disk offerings
160176 cls .services ["small" ]["zoneid" ] = cls .zone .id
@@ -165,63 +181,73 @@ def setUpClass(cls):
165181
166182 # Create VMs, NAT Rules etc
167183 cls .account = Account .create (
168- cls .apiclient ,
169- cls .services ["account" ],
170- domainid = domain .id
171- )
184+ cls .apiclient ,
185+ cls .services ["account" ],
186+ domainid = domain .id
187+ )
172188
173189 cls .small_offering = ServiceOffering .create (
174- cls .apiclient ,
175- cls .services ["service_offerings" ]["small" ]
176- )
190+ cls .apiclient ,
191+ cls .services ["service_offerings" ]["small" ]
192+ )
177193
178194 cls .medium_offering = ServiceOffering .create (
179- cls .apiclient ,
180- cls .services ["service_offerings" ]["medium" ]
181- )
195+ cls .apiclient ,
196+ cls .services ["service_offerings" ]["medium" ]
197+ )
182198 cls .medium_virtual_machine = VirtualMachine .create (
183- cls .apiclient ,
184- cls .services ["medium" ],
185- accountid = cls .account .name ,
186- domainid = cls .account .domainid ,
187- serviceofferingid = cls .medium_offering .id ,
188- mode = cls .services ["mode" ]
189- )
199+ cls .apiclient ,
200+ cls .services ["medium" ],
201+ accountid = cls .account .name ,
202+ domainid = cls .account .domainid ,
203+ serviceofferingid = cls .medium_offering .id ,
204+ mode = cls .services ["mode" ]
205+ )
190206 cls ._cleanup = [
191- cls .small_offering ,
192- cls .medium_offering ,
193- cls .account
194- ]
207+ cls .small_offering ,
208+ cls .medium_offering ,
209+ cls .account
210+ ]
195211 return
196212
197213 @classmethod
198214 def tearDownClass (cls ):
199215 try :
200- cls .apiclient = super (TestServiceOfferings , cls ).getClsTestClient ().getApiClient ()
201- #Clean up, terminate the created templates
216+ cls .apiclient = super (
217+ TestServiceOfferings ,
218+ cls ).getClsTestClient ().getApiClient ()
219+ # Clean up, terminate the created templates
202220 cleanup_resources (cls .apiclient , cls ._cleanup )
203221
204222 except Exception as e :
205223 raise Exception ("Warning: Exception during cleanup : %s" % e )
206224 return
207225
208- @attr (tags = ["advanced" , "advancedns" , "smoke" , "basic" , "eip" , "sg" ], required_hardware = "false" )
226+ @attr (
227+ tags = [
228+ "advanced" ,
229+ "advancedns" ,
230+ "smoke" ,
231+ "basic" ,
232+ "eip" ,
233+ "sg" ],
234+ required_hardware = "false" )
209235 def test_02_edit_service_offering (self ):
210236 """Test to update existing service offering"""
211237
212238 # Validate the following:
213239 # 1. updateServiceOffering should return
214240 # a valid information for newly created offering
215241
216- #Generate new name & displaytext from random data
242+ # Generate new name & displaytext from random data
217243 random_displaytext = random_gen ()
218244 random_name = random_gen ()
219245
220246 self .debug ("Updating service offering with ID: %s" %
221247 self .service_offering_1 .id )
222248
223249 cmd = updateServiceOffering .updateServiceOfferingCmd ()
224- #Add parameters for API call
250+ # Add parameters for API call
225251 cmd .id = self .service_offering_1 .id
226252 cmd .displaytext = random_displaytext
227253 cmd .name = random_name
@@ -256,7 +282,15 @@ def test_02_edit_service_offering(self):
256282
257283 return
258284
259- @attr (tags = ["advanced" , "advancedns" , "smoke" , "basic" , "eip" , "sg" ], required_hardware = "false" )
285+ @attr (
286+ tags = [
287+ "advanced" ,
288+ "advancedns" ,
289+ "smoke" ,
290+ "basic" ,
291+ "eip" ,
292+ "sg" ],
293+ required_hardware = "false" )
260294 def test_03_delete_service_offering (self ):
261295 """Test to delete service offering"""
262296
@@ -316,30 +350,31 @@ def test_04_change_offering_small(self):
316350 self .debug ("VM state: %s" % vm .state )
317351 else :
318352 raise Exception (
319- "Failed to start VM (ID: %s) after changing service offering" % vm .id )
353+ "Failed to start VM (ID: %s) after changing\
354+ service offering" % vm .id )
320355
321356 try :
322357 ssh = self .medium_virtual_machine .get_ssh_client ()
323358 except Exception as e :
324359 self .fail (
325- "SSH Access failed for %s: %s" % \
360+ "SSH Access failed for %s: %s" %
326361 (self .medium_virtual_machine .ipaddress , e )
327362 )
328363
329364 cpuinfo = ssh .execute ("cat /proc/cpuinfo" )
330365 cpu_cnt = len ([i for i in cpuinfo if "processor" in i ])
331- #'cpu MHz\t\t: 2660.499'
366+ # 'cpu MHz\t\t: 2660.499'
332367 cpu_speed = [i for i in cpuinfo if "cpu MHz" in i ][0 ].split ()[3 ]
333368 meminfo = ssh .execute ("cat /proc/meminfo" )
334- #MemTotal: 1017464 kB
369+ # MemTotal: 1017464 kB
335370 total_mem = [i for i in meminfo if "MemTotal" in i ][0 ].split ()[1 ]
336371
337372 self .debug (
338373 "CPU count: %s, CPU Speed: %s, Mem Info: %s" % (
339374 cpu_cnt ,
340375 cpu_speed ,
341376 total_mem
342- ))
377+ ))
343378 self .assertAlmostEqual (
344379 int (cpu_cnt ),
345380 self .small_offering .cpunumber ,
@@ -350,11 +385,19 @@ def test_04_change_offering_small(self):
350385 self .small_offering .cpuspeed ,
351386 "Check CPU Speed for small offering"
352387 )
388+
389+ range = 20
390+ if self .hypervisor .lower () == "hyperv" :
391+ range = 200
392+ # TODO: Find the memory allocated to VM on hyperv hypervisor using
393+ # powershell commands and use that value to equate instead of
394+ # manipulating range, currently we get the memory count much less
395+ # because of the UI component
353396 self .assertTrue (
354397 isAlmostEqual (int (int (total_mem ) / 1024 ),
355- int (self .small_offering .memory ),
356- range = 20
357- ),
398+ int (self .small_offering .memory ),
399+ range = range
400+ ),
358401 "Check Memory(kb) for small offering"
359402 )
360403 return
0 commit comments