Skip to content

Commit b6a06b4

Browse files
Priti Sarapsanjeev
authored andcommitted
CLOUDSTACK-8686: Data disk attach failed for clusters with only zone wide primary -Attaching the uploaded/allocated volume to a VM on zwps
This closes #631
1 parent 2ae2aac commit b6a06b4

File tree

1 file changed

+209
-0
lines changed

1 file changed

+209
-0
lines changed
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
""" Test case for Data Disk Attach to VM on ZWPS Test Path
18+
"""
19+
20+
from nose.plugins.attrib import attr
21+
from marvin.cloudstackTestCase import cloudstackTestCase
22+
from marvin.lib.utils import (cleanup_resources,
23+
validateList)
24+
from marvin.lib.base import (Account,
25+
ServiceOffering,
26+
DiskOffering,
27+
Volume,
28+
VirtualMachine,
29+
StoragePool
30+
)
31+
from marvin.lib.common import (get_domain,
32+
get_zone,
33+
get_template
34+
)
35+
36+
from marvin.codes import (PASS,
37+
ZONETAG1)
38+
39+
40+
class TestAttachDataDisk(cloudstackTestCase):
41+
42+
@classmethod
43+
def setUpClass(cls):
44+
testClient = super(TestAttachDataDisk, cls).getClsTestClient()
45+
cls.apiclient = testClient.getApiClient()
46+
cls.testdata = testClient.getParsedTestDataConfig()
47+
cls.hypervisor = cls.testClient.getHypervisorInfo()
48+
49+
# Get Zone, Domain and templates
50+
cls.domain = get_domain(cls.apiclient)
51+
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
52+
cls._cleanup = []
53+
cls.template = get_template(
54+
cls.apiclient,
55+
cls.zone.id,
56+
cls.testdata["ostype"])
57+
cls.skiptest = False
58+
59+
try:
60+
cls.pools = StoragePool.list(cls.apiclient, zoneid=cls.zone.id)
61+
except Exception as e:
62+
cls.skiptest = True
63+
return
64+
try:
65+
66+
# Create an account
67+
cls.account = Account.create(
68+
cls.apiclient,
69+
cls.testdata["account"],
70+
domainid=cls.domain.id
71+
)
72+
cls._cleanup.append(cls.account)
73+
74+
# Create user api client of the account
75+
cls.userapiclient = testClient.getUserApiClient(
76+
UserName=cls.account.name,
77+
DomainName=cls.account.domain
78+
)
79+
# Create Service offering
80+
cls.service_offering_zone1 = ServiceOffering.create(
81+
cls.apiclient,
82+
cls.testdata["service_offering"],
83+
tags=ZONETAG1
84+
)
85+
cls._cleanup.append(cls.service_offering_zone1)
86+
87+
# Create Disk offering
88+
cls.disk_offering = DiskOffering.create(
89+
cls.apiclient,
90+
cls.testdata["disk_offering"]
91+
)
92+
93+
cls._cleanup.append(cls.disk_offering)
94+
95+
except Exception as e:
96+
cls.tearDownClass()
97+
raise e
98+
return
99+
100+
@classmethod
101+
def tearDownClass(cls):
102+
try:
103+
cleanup_resources(cls.apiclient, cls._cleanup)
104+
except Exception as e:
105+
raise Exception("Warning: Exception during cleanup : %s" % e)
106+
107+
def setUp(self):
108+
self.apiclient = self.testClient.getApiClient()
109+
self.dbclient = self.testClient.getDbConnection()
110+
self.cleanup = []
111+
112+
def tearDown(self):
113+
try:
114+
for storagePool in self.pools:
115+
StoragePool.update(self.apiclient, id=storagePool.id, tags="")
116+
117+
if hasattr(self, "data_volume_created"):
118+
data_volumes_list = Volume.list(
119+
self.userapiclient,
120+
id=self.data_volume_created.id,
121+
virtualmachineid=self.vm.id
122+
)
123+
if data_volumes_list:
124+
self.vm.detach_volume(
125+
self.userapiclient,
126+
data_volumes_list[0]
127+
)
128+
129+
status = validateList(data_volumes_list)
130+
self.assertEqual(
131+
status[0],
132+
PASS,
133+
"DATA Volume List Validation Failed")
134+
135+
cleanup_resources(self.apiclient, self.cleanup)
136+
except Exception as e:
137+
raise Exception("Warning: Exception during cleanup : %s" % e)
138+
return
139+
140+
@attr(tags=["basic", "advanced"], required_hardware="true")
141+
def test_01_attach_datadisk_to_vm_on_zwps(self):
142+
""" Attach Data Disk To VM on ZWPS
143+
1. Check if zwps storage pool exists.
144+
2. Adding tag to zone wide primary storage
145+
3. Launch a VM on ZWPS
146+
4. Attach data disk to vm which is on zwps.
147+
5. Verify disk is attached.
148+
"""
149+
150+
# Step 1
151+
if len(list(storagePool for storagePool in self.pools
152+
if storagePool.scope == "ZONE")) < 1:
153+
self.skipTest("There must be at least one zone wide \
154+
storage pools available in the setup")
155+
156+
# Adding tags to Storage Pools
157+
zone_no = 1
158+
for storagePool in self.pools:
159+
if storagePool.scope == "ZONE":
160+
StoragePool.update(
161+
self.apiclient,
162+
id=storagePool.id,
163+
tags=[ZONETAG1[:-1] + repr(zone_no)])
164+
zone_no += 1
165+
166+
self.vm = VirtualMachine.create(
167+
self.apiclient,
168+
self.testdata["small"],
169+
templateid=self.template.id,
170+
accountid=self.account.name,
171+
domainid=self.account.domainid,
172+
serviceofferingid=self.service_offering_zone1.id,
173+
zoneid=self.zone.id
174+
)
175+
176+
self.data_volume_created = Volume.create(
177+
self.userapiclient,
178+
self.testdata["volume"],
179+
zoneid=self.zone.id,
180+
account=self.account.name,
181+
domainid=self.account.domainid,
182+
diskofferingid=self.disk_offering.id
183+
)
184+
185+
self.cleanup.append(self.data_volume_created)
186+
187+
# Step 2
188+
self.vm.attach_volume(
189+
self.userapiclient,
190+
self.data_volume_created
191+
)
192+
193+
data_volumes_list = Volume.list(
194+
self.userapiclient,
195+
id=self.data_volume_created.id,
196+
virtualmachineid=self.vm.id
197+
)
198+
199+
data_volume = data_volumes_list[0]
200+
201+
status = validateList(data_volume)
202+
203+
# Step 3
204+
self.assertEqual(
205+
status[0],
206+
PASS,
207+
"Check: Data if Disk is attached to VM")
208+
209+
return

0 commit comments

Comments
 (0)