2020import marvin
2121from marvin .cloudstackTestCase import *
2222from marvin .cloudstackAPI import *
23- from marvin .remoteSSHClient import remoteSSHClient
2423from marvin .integration .lib .utils import *
2524from marvin .integration .lib .base import *
2625from marvin .integration .lib .common import *
2726from nose .plugins .attrib import attr
28- #Import System modules
29- import time
3027
3128_multiprocess_shared_ = True
29+
3230class Services :
3331 """Test VM Life Cycle Services
3432 """
3533
3634 def __init__ (self ):
3735 self .services = {
3836
39- "account" : {
40- "email" : "test@test.com" ,
41- "firstname" : "Test" ,
42- "lastname" : "User" ,
43- "username" : "test" ,
44- # Random characters are appended in create account to
45- # ensure unique username generated each time
46- "password" : "password" ,
47- },
48- "small" :
49- # Create a small virtual machine instance with disk offering
37+ "account" : {
38+ "email" : "test@test.com" ,
39+ "firstname" : "Test" ,
40+ "lastname" : "User" ,
41+ "username" : "test" ,
42+ # Random characters are appended in create account to
43+ # ensure unique username generated each time
44+ "password" : "password" ,
45+ },
46+ "small" :
47+ # Create a small virtual machine instance with disk offering
5048 {
5149 "displayname" : "testserver" ,
5250 "username" : "root" , # VM creds for SSH
@@ -57,43 +55,43 @@ def __init__(self):
5755 "publicport" : 22 ,
5856 "protocol" : 'TCP' ,
5957 },
60- "service_offerings" :
58+ "service_offerings" :
6159 {
62- "small" :
63- {
64- # Small service offering ID to for change VM
65- # service offering from medium to small
66- "name" : "SmallInstance" ,
67- "displaytext" : "SmallInstance" ,
68- "cpunumber" : 1 ,
69- "cpuspeed" : 100 ,
70- "memory" : 256 ,
71- },
72- "big" :
73- {
74- # Big service offering ID to for change VM
75- "name" : "BigInstance" ,
76- "displaytext" : "BigInstance" ,
77- "cpunumber" : 1 ,
78- "cpuspeed" : 100 ,
79- "memory" : 512 ,
80- }
81- },
82- #Change this
83- "template" : {
84- "displaytext" : "xs" ,
85- "name" : "xs" ,
86- "passwordenabled" : False ,
60+ "small" :
61+ {
62+ # Small service offering ID to for change VM
63+ # service offering from medium to small
64+ "name" : "SmallInstance" ,
65+ "displaytext" : "SmallInstance" ,
66+ "cpunumber" : 1 ,
67+ "cpuspeed" : 100 ,
68+ "memory" : 256 ,
69+ },
70+ "big" :
71+ {
72+ # Big service offering ID to for change VM
73+ "name" : "BigInstance" ,
74+ "displaytext" : "BigInstance" ,
75+ "cpunumber" : 1 ,
76+ "cpuspeed" : 100 ,
77+ "memory" : 512 ,
78+ }
8779 },
80+ #Change this
81+ "template" : {
82+ "displaytext" : "xs" ,
83+ "name" : "xs" ,
84+ "passwordenabled" : False ,
85+ },
8886 "sleep" : 60 ,
8987 "timeout" : 10 ,
9088 #Migrate VM to hostid
9189 "ostype" : 'CentOS 5.3 (64-bit)' ,
9290 # CentOS 5.3 (64-bit)
9391 }
9492
95- class TestScaleVm (cloudstackTestCase ):
9693
94+ class TestScaleVm (cloudstackTestCase ):
9795 @classmethod
9896 def setUpClass (cls ):
9997 cls .api_client = super (TestScaleVm , cls ).getClsTestClient ().getApiClient ()
@@ -105,45 +103,44 @@ def setUpClass(cls):
105103 cls .services ['mode' ] = zone .networktype
106104
107105 template = get_template (
108- cls .api_client ,
109- zone .id ,
110- cls .services ["ostype" ]
111- )
106+ cls .api_client ,
107+ zone .id ,
108+ cls .services ["ostype" ]
109+ )
112110 # Set Zones and disk offerings ??
113111 cls .services ["small" ]["zoneid" ] = zone .id
114112 cls .services ["small" ]["template" ] = template .id
115113
116114 # Create account, service offerings, vm.
117115 cls .account = Account .create (
118- cls .api_client ,
119- cls .services ["account" ],
120- domainid = domain .id
121- )
116+ cls .api_client ,
117+ cls .services ["account" ],
118+ domainid = domain .id
119+ )
122120
123121 cls .small_offering = ServiceOffering .create (
124- cls .api_client ,
125- cls .services ["service_offerings" ]["small" ]
126- )
127-
122+ cls .api_client ,
123+ cls .services ["service_offerings" ]["small" ]
124+ )
125+
128126 cls .big_offering = ServiceOffering .create (
129- cls .api_client ,
130- cls .services ["service_offerings" ]["big" ]
131- )
127+ cls .api_client ,
128+ cls .services ["service_offerings" ]["big" ]
129+ )
132130
133131 #create a virtual machine
134132 cls .virtual_machine = VirtualMachine .create (
135- cls .api_client ,
136- cls .services ["small" ],
137- accountid = cls .account .name ,
138- domainid = cls .account .domainid ,
139- serviceofferingid = cls .small_offering .id ,
140- mode = cls .services ["mode" ]
141- )
142- #how does it work ??
133+ cls .api_client ,
134+ cls .services ["small" ],
135+ accountid = cls .account .name ,
136+ domainid = cls .account .domainid ,
137+ serviceofferingid = cls .small_offering .id ,
138+ mode = cls .services ["mode" ]
139+ )
143140 cls ._cleanup = [
144- cls .small_offering ,
145- # cls.account
146- ]
141+ cls .small_offering ,
142+ cls .account
143+ ]
147144
148145 @classmethod
149146 def tearDownClass (cls ):
@@ -161,65 +158,69 @@ def tearDown(self):
161158 cleanup_resources (self .apiclient , self .cleanup )
162159 return
163160
164- @attr (tags = ["xenserver" , "advanced" , "basic" ])
161+ @attr (hypervisor = "xenserver" )
162+ @attr (tags = ["advanced" , "basic" ])
165163 def test_01_scale_vm (self ):
166164 """Test scale virtual machine
167165 """
168166 # Validate the following
169167 # Scale up the vm and see if it scales to the new svc offering and is finally in running state
170-
171-
172-
168+
173169 self .debug ("Scaling VM-ID: %s to service offering: %s and state %s" % (
174- self .virtual_machine .id ,
175- self .big_offering .id ,
176- self .virtual_machine .state
177- ))
178-
170+ self .virtual_machine .id ,
171+ self .big_offering .id ,
172+ self .virtual_machine .state
173+ ))
174+
179175 cmd = scaleVirtualMachine .scaleVirtualMachineCmd ()
180176 cmd .serviceofferingid = self .big_offering .id
181177 cmd .id = self .virtual_machine .id
182- self .apiclient .scaleVirtualMachine (cmd )
178+ self .apiclient .scaleVirtualMachine (cmd )
183179
184- list_vm_response = list_virtual_machines (
185- self .apiclient ,
186- id = self .virtual_machine .id
187- )
180+ list_vm_response = VirtualMachine . list (
181+ self .apiclient ,
182+ id = self .virtual_machine .id
183+ )
188184 self .assertEqual (
189- isinstance (list_vm_response , list ),
190- True ,
191- "Check list response returns a valid list"
192- )
185+ isinstance (list_vm_response , list ),
186+ True ,
187+ "Check list response returns a valid list"
188+ )
193189
194190 self .assertNotEqual (
195- list_vm_response ,
196- None ,
197- "Check virtual machine is listVirtualMachines"
198- )
191+ list_vm_response ,
192+ None ,
193+ "Check virtual machine is listVirtualMachines"
194+ )
199195
200196 vm_response = list_vm_response [0 ]
201-
202197 self .assertEqual (
203- vm_response .id ,
204- self .virtual_machine .id ,
205- "Check virtual machine ID of scaled VM"
206- )
198+ vm_response .id ,
199+ self .virtual_machine .id ,
200+ "Check virtual machine ID of scaled VM"
201+ )
202+
203+ # VirtualMachine should be updated to tell cloudstack it has PV tools
204+ # available and successfully scaled. We will only mock that behaviour
205+ # here but it is not expected in production since the VM scaling is not
206+ # guaranteed until tools are installed, vm rebooted
207+ self .virtual_machine .update (self .apiclient , isdynamicallyscalable = 'true' )
207208
208209 self .debug ("Scaling VM-ID: %s from service offering: %s to new service offering %s and the response says %s" % (
209- self .virtual_machine .id ,
210- self .virtual_machine .serviceofferingid ,
211- self .big_offering .id ,
212- vm_response .serviceofferingid
213- ))
210+ self .virtual_machine .id ,
211+ self .virtual_machine .serviceofferingid ,
212+ self .big_offering .id ,
213+ vm_response .serviceofferingid
214+ ))
214215 self .assertEqual (
215- vm_response .serviceofferingid ,
216- self .big_offering .id ,
217- "Check service offering of the VM"
218- )
216+ vm_response .serviceofferingid ,
217+ self .big_offering .id ,
218+ "Check service offering of the VM"
219+ )
219220
220221 self .assertEqual (
221- vm_response .state ,
222- 'Running' ,
223- "Check the state of VM"
224- )
222+ vm_response .state ,
223+ 'Running' ,
224+ "Check the state of VM"
225+ )
225226 return
0 commit comments