forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_storage_motion.py
More file actions
305 lines (273 loc) · 11.8 KB
/
test_storage_motion.py
File metadata and controls
305 lines (273 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
""" P1 tests for Storage motion
"""
#Import Local Modules
import marvin
from marvin.cloudstackTestCase import *
from marvin.cloudstackAPI import *
from marvin.lib.utils import *
from marvin.lib.base import *
from marvin.lib.common import *
from nose.plugins.attrib import attr
#Import System modules
import time
_multiprocess_shared_ = True
class Services:
"""Test VM Life Cycle Services
"""
def __init__(self):
self.services = {
"disk_offering":{
"displaytext": "Small",
"name": "Small",
"disksize": 1
},
"account": {
"email": "test@test.com",
"firstname": "Test",
"lastname": "User",
"username": "test",
# Random characters are appended in create account to
# ensure unique username generated each time
"password": "password",
},
"small":
# Create a small virtual machine instance with disk offering
{
"displayname": "testserver",
"username": "root", # VM creds for SSH
"password": "password",
"ssh_port": 22,
"hypervisor": 'XenServer',
"privateport": 22,
"publicport": 22,
"protocol": 'TCP',
},
"service_offerings":
{
"small":
{
# Small service offering ID to for change VM
# service offering from medium to small
"name": "Small Instance",
"displaytext": "Small Instance",
"cpunumber": 1,
"cpuspeed": 100,
"memory": 256,
}
},
"template": {
"displaytext": "Cent OS Template",
"name": "Cent OS Template",
"passwordenabled": True,
},
"sleep": 60,
"timeout": 10,
#Migrate VM to hostid
"ostype": 'CentOS 5.3 (64-bit)',
# CentOS 5.3 (64-bit)
}
class TestStorageMotion(cloudstackTestCase):
@classmethod
def setUpClass(cls):
cls.testClient = super(TestStorageMotion, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient()
cls.services = Services().services
# Get Zone, Domain and templates
domain = get_domain(cls.api_client)
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
cls.services['mode'] = cls.zone.networktype
template = get_template(
cls.api_client,
cls.zone.id,
cls.services["ostype"]
)
# Set Zones and disk offerings
cls.services["small"]["zoneid"] = cls.zone.id
cls.services["small"]["template"] = template.id
# Create VMs, NAT Rules etc
cls.account = Account.create(
cls.api_client,
cls.services["account"],
domainid=domain.id
)
cls.small_offering = ServiceOffering.create(
cls.api_client,
cls.services["service_offerings"]["small"]
)
#create a virtual machine
cls.virtual_machine = VirtualMachine.create(
cls.api_client,
cls.services["small"],
accountid=cls.account.name,
domainid=cls.account.domainid,
serviceofferingid=cls.small_offering.id,
mode=cls.services["mode"]
)
cls._cleanup = [
cls.small_offering,
cls.account
]
@classmethod
def tearDownClass(cls):
cls.api_client = super(TestStorageMotion, cls).getClsTestClient().getApiClient()
cleanup_resources(cls.api_client, cls._cleanup)
return
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.dbclient = self.testClient.getDbConnection()
self.cleanup = []
def tearDown(self):
#Clean up, terminate the created ISOs
cleanup_resources(self.apiclient, self.cleanup)
return
@attr(tags=["advanced", "basic", "multicluster", "storagemotion", "xenserver"], required_hardware="true")
def test_01_migrate_vm_with_volume(self):
"""Test migrate virtual machine with its volumes
"""
# Validate the following
# 1. List hosts for migration of a vm. Pick a host that
# requires storage motion too.
# 2. Migrate vm to a host.
# 3. listVM command should return this VM.State of this VM
# should be "Running" and the host should be the host
# to which the VM was migrated to in a different cluster
hosts = Host.listForMigration(
self.apiclient,
virtualmachineid=self.virtual_machine.id
)
self.assertEqual(
isinstance(hosts, list),
True,
"Check the number of hosts in the zone"
)
# Migrate to a host that requires storage motion
hosts[:] = [host for host in hosts if host.requiresStorageMotion]
if hosts is None or len(hosts) == 0:
self.skipTest("No valid hosts for storage motion. Skipping")
host = hosts[0]
self.debug("Migrating VM-ID: %s to Host: %s" % (
self.virtual_machine.id,
host.id
))
cmd = migrateVirtualMachineWithVolume.migrateVirtualMachineWithVolumeCmd()
cmd.hostid = host.id
cmd.virtualmachineid = self.virtual_machine.id
self.apiclient.migrateVirtualMachineWithVolume(cmd)
list_vm_response = list_virtual_machines(
self.apiclient,
id=self.virtual_machine.id
)
self.assertEqual(
isinstance(list_vm_response, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
list_vm_response,
None,
"Check virtual machine is listVirtualMachines"
)
vm_response = list_vm_response[0]
self.assertEqual(
vm_response.id,
self.virtual_machine.id,
"Check virtual machine ID of migrated VM"
)
self.assertEqual(
vm_response.hostid,
host.id,
"Check destination hostID of migrated VM"
)
self.assertEqual(
vm_response.state,
'Running',
"Check the state of VM"
)
return
@attr(tags=["advanced", "basic", "multipool", "storagemotion", "xenserver"], required_hardware="false")
def test_02_migrate_volume(self):
"""Test migrate volume of a running vm
"""
# Validate the following
# 1. List all the volumes of a vm. For each volume do step 2 to 4.
# 2. List storage pools for migrating volume of a vm. Multiple
# storage pools should be present in the cluster.
# 3. Migrate volume of the vm to another pool.
# 4. Check volume is present in the new pool and is in Ready state.
list_volumes_response = list_volumes(
self.apiclient,
virtualmachineid=self.virtual_machine.id,
listall=True
)
self.assertEqual(
isinstance(list_volumes_response, list),
True,
"Check list volumes response for valid list"
)
self.assertNotEqual(
list_volumes_response,
None,
"Check if volume exists in ListVolumes"
)
for volume in list_volumes_response:
pools = StoragePool.listForMigration(
self.apiclient,
id=volume.id
)
if not pools:
self.skipTest("No suitable storage pools found for volume migration. Skipping")
self.assert_(isinstance(pools, list), "invalid pool response from listStoragePoolsForMigration: %s" %pools)
self.assert_(len(pools) > 0, "no valid storage pools found for migration")
pool = pools[0]
self.debug("Migrating Volume-ID: %s to Pool: %s" % (
volume.id,
pool.id
))
Volume.migrate(
self.apiclient,
volumeid=volume.id,
storageid=pool.id,
livemigrate='true'
)
migrated_volume_response = list_volumes(
self.apiclient,
id=volume.id
)
self.assertEqual(
isinstance(migrated_volume_response, list),
True,
"Check list volumes response for valid list"
)
self.assertNotEqual(
migrated_volume_response,
None,
"Check if volume exists in ListVolumes"
)
migrated_volume = migrated_volume_response[0]
self.assertEqual(
migrated_volume.state,
'Ready',
"Check migrated volume is in Ready state"
)
self.assertEqual(
migrated_volume.storage,
pool.name,
"Check volume is on migrated pool"
)
return