|
34 | 34 | ) |
35 | 35 |
|
36 | 36 | from marvin.codes import (PASS, |
37 | | - ZONETAG1) |
| 37 | + ZONETAG1, |
| 38 | + CLUSTERTAG1) |
38 | 39 |
|
39 | 40 |
|
40 | 41 | class TestAttachDataDisk(cloudstackTestCase): |
@@ -207,3 +208,188 @@ def test_01_attach_datadisk_to_vm_on_zwps(self): |
207 | 208 | "Check: Data if Disk is attached to VM") |
208 | 209 |
|
209 | 210 | return |
| 211 | + |
| 212 | + |
| 213 | +class TestAttachDataDiskOnCWPS(cloudstackTestCase): |
| 214 | + |
| 215 | + @classmethod |
| 216 | + def setUpClass(cls): |
| 217 | + testClient = super(TestAttachDataDiskOnCWPS, cls).getClsTestClient() |
| 218 | + cls.apiclient = testClient.getApiClient() |
| 219 | + cls.testdata = testClient.getParsedTestDataConfig() |
| 220 | + cls.hypervisor = cls.testClient.getHypervisorInfo() |
| 221 | + |
| 222 | + # Get Zone, Domain and templates |
| 223 | + cls.domain = get_domain(cls.apiclient) |
| 224 | + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) |
| 225 | + cls._cleanup = [] |
| 226 | + cls.template = get_template( |
| 227 | + cls.apiclient, |
| 228 | + cls.zone.id, |
| 229 | + cls.testdata["ostype"]) |
| 230 | + cls.skiptest = False |
| 231 | + |
| 232 | + try: |
| 233 | + cls.pools = StoragePool.list( |
| 234 | + cls.apiclient, |
| 235 | + zoneid=cls.zone.id, |
| 236 | + scope="CLUSTER") |
| 237 | + except Exception as e: |
| 238 | + cls.skiptest = True |
| 239 | + return |
| 240 | + try: |
| 241 | + |
| 242 | + # Create an account |
| 243 | + cls.account = Account.create( |
| 244 | + cls.apiclient, |
| 245 | + cls.testdata["account"], |
| 246 | + domainid=cls.domain.id |
| 247 | + ) |
| 248 | + cls._cleanup.append(cls.account) |
| 249 | + |
| 250 | + # Create user api client of the account |
| 251 | + cls.userapiclient = testClient.getUserApiClient( |
| 252 | + UserName=cls.account.name, |
| 253 | + DomainName=cls.account.domain |
| 254 | + ) |
| 255 | + # Create Service offering |
| 256 | + cls.service_offering = ServiceOffering.create( |
| 257 | + cls.apiclient, |
| 258 | + cls.testdata["service_offering"], |
| 259 | + ) |
| 260 | + cls._cleanup.append(cls.service_offering) |
| 261 | + |
| 262 | + # Create Disk offering |
| 263 | + cls.disk_offering = DiskOffering.create( |
| 264 | + cls.apiclient, |
| 265 | + cls.testdata["disk_offering"], |
| 266 | + custom=True, |
| 267 | + tags=CLUSTERTAG1, |
| 268 | + ) |
| 269 | + |
| 270 | + cls._cleanup.append(cls.disk_offering) |
| 271 | + |
| 272 | + except Exception as e: |
| 273 | + cls.tearDownClass() |
| 274 | + raise e |
| 275 | + return |
| 276 | + |
| 277 | + @classmethod |
| 278 | + def tearDownClass(cls): |
| 279 | + try: |
| 280 | + cleanup_resources(cls.apiclient, cls._cleanup) |
| 281 | + except Exception as e: |
| 282 | + raise Exception("Warning: Exception during cleanup : %s" % e) |
| 283 | + |
| 284 | + def setUp(self): |
| 285 | + self.apiclient = self.testClient.getApiClient() |
| 286 | + self.dbclient = self.testClient.getDbConnection() |
| 287 | + self.cleanup = [] |
| 288 | + |
| 289 | + def tearDown(self): |
| 290 | + try: |
| 291 | + for storagePool in self.pools: |
| 292 | + StoragePool.update(self.apiclient, id=storagePool.id, tags="") |
| 293 | + |
| 294 | + if hasattr(self, "data_volume_created"): |
| 295 | + data_volumes_list = Volume.list( |
| 296 | + self.userapiclient, |
| 297 | + id=self.data_volume_created.id, |
| 298 | + virtualmachineid=self.vm.id |
| 299 | + ) |
| 300 | + if data_volumes_list: |
| 301 | + self.vm.detach_volume( |
| 302 | + self.userapiclient, |
| 303 | + data_volumes_list[0] |
| 304 | + ) |
| 305 | + |
| 306 | + status = validateList(data_volumes_list) |
| 307 | + self.assertEqual( |
| 308 | + status[0], |
| 309 | + PASS, |
| 310 | + "DATA Volume List Validation Failed") |
| 311 | + |
| 312 | + cleanup_resources(self.apiclient, self.cleanup) |
| 313 | + except Exception as e: |
| 314 | + raise Exception("Warning: Exception during cleanup : %s" % e) |
| 315 | + return |
| 316 | + |
| 317 | + @attr(tags=["basic", "advanced"], required_hardware="true") |
| 318 | + def test_01_attach_datadisk_to_vm_on_zwps(self): |
| 319 | + """ Attach Data Disk on CWPS To VM |
| 320 | + 1. Check if zwps storage pool exists. |
| 321 | + 2. Adding tag to zone wide primary storage |
| 322 | + 3. Launch a VM |
| 323 | + 4. Attach data disk to vm. |
| 324 | + 5. Verify disk is attached and in correct storage pool. |
| 325 | + """ |
| 326 | + |
| 327 | + # Step 1 |
| 328 | + if len(list(self.pools)) < 1: |
| 329 | + self.skipTest("There must be at least one zone wide \ |
| 330 | + storage pools available in the setup") |
| 331 | + |
| 332 | + # Step 2 |
| 333 | + # Adding tags to Storage Pools |
| 334 | + StoragePool.update( |
| 335 | + self.apiclient, |
| 336 | + id=self.pools[0].id, |
| 337 | + tags=[CLUSTERTAG1]) |
| 338 | + |
| 339 | + # Launch VM |
| 340 | + self.vm = VirtualMachine.create( |
| 341 | + self.apiclient, |
| 342 | + self.testdata["small"], |
| 343 | + templateid=self.template.id, |
| 344 | + accountid=self.account.name, |
| 345 | + domainid=self.account.domainid, |
| 346 | + serviceofferingid=self.service_offering_zone1.id, |
| 347 | + zoneid=self.zone.id |
| 348 | + ) |
| 349 | + |
| 350 | + self.testdata["volume"]["zoneid"] = self.zone.id |
| 351 | + self.testdata["volume"]["customdisksize"] = 1 |
| 352 | + self.data_volume_created = Volume.create_custom_disk( |
| 353 | + self.userapiclient, |
| 354 | + self.testdata["volume"], |
| 355 | + account=self.account.name, |
| 356 | + domainid=self.account.domainid, |
| 357 | + diskofferingid=self.disk_offering.id, |
| 358 | + ) |
| 359 | + |
| 360 | + self.cleanup.append(self.data_volume_created) |
| 361 | + |
| 362 | + # Step 4 |
| 363 | + self.vm.attach_volume( |
| 364 | + self.userapiclient, |
| 365 | + self.data_volume_created |
| 366 | + ) |
| 367 | + |
| 368 | + data_volumes_list = Volume.list( |
| 369 | + self.userapiclient, |
| 370 | + virtualmachineid=self.vm.id, |
| 371 | + type="DATA", |
| 372 | + listall=True |
| 373 | + ) |
| 374 | + |
| 375 | + self.debug("list volumes using vm id %s" % dir(data_volumes_list[0])) |
| 376 | + |
| 377 | + data_volumes_list = Volume.list(self.apiclient, |
| 378 | + id=self.data_volume_created.id, |
| 379 | + listall=True) |
| 380 | + data_volume = data_volumes_list[0] |
| 381 | + status = validateList(data_volume) |
| 382 | + # Step 5 |
| 383 | + self.assertEqual( |
| 384 | + status[0], |
| 385 | + PASS, |
| 386 | + "Check: volume list is valid") |
| 387 | + |
| 388 | + self.assertEqual( |
| 389 | + data_volume.state, |
| 390 | + "Ready", |
| 391 | + "Check: Data volume is attached to VM") |
| 392 | + |
| 393 | + if data_volume.storage != self.pools[0].name: |
| 394 | + self.fail("check if volume is created in correct storage pool") |
| 395 | + return |
0 commit comments