Skip to content

Commit f45548b

Browse files
manasaveloorisanjeev
authored andcommitted
Added a test to verify that listSnapshots response returns zone id
Made changes based on Comments This closes #632
1 parent bccd344 commit f45548b

File tree

1 file changed

+77
-63
lines changed

1 file changed

+77
-63
lines changed

test/integration/smoke/test_snapshots.py

Lines changed: 77 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
list_snapshots)
3232
from marvin.lib.decoratorGenerators import skipTestIf
3333

34+
3435
class TestSnapshotRootDisk(cloudstackTestCase):
3536

3637
@classmethod
@@ -52,12 +53,13 @@ def setUpClass(cls):
5253
cls._cleanup = []
5354
if not cls.hypervisorNotSupported:
5455
template = get_template(
55-
cls.apiclient,
56-
cls.zone.id,
57-
cls.services["ostype"]
58-
)
56+
cls.apiclient,
57+
cls.zone.id,
58+
cls.services["ostype"]
59+
)
5960
if template == FAILED:
60-
assert False, "get_template() failed to return template with description %s" % cls.services["ostype"]
61+
assert False, "get_template() failed to return template with description %s" % cls.services[
62+
"ostype"]
6163

6264
cls.services["domainid"] = cls.domain.id
6365
cls.services["server_without_disk"]["zoneid"] = cls.zone.id
@@ -66,32 +68,33 @@ def setUpClass(cls):
6668

6769
# Create VMs, NAT Rules etc
6870
cls.account = Account.create(
69-
cls.apiclient,
70-
cls.services["account"],
71-
domainid=cls.domain.id
72-
)
71+
cls.apiclient,
72+
cls.services["account"],
73+
domainid=cls.domain.id
74+
)
7375
cls._cleanup.append(cls.account)
7476
cls.service_offering = ServiceOffering.create(
75-
cls.apiclient,
76-
cls.services["service_offerings"]
77-
)
77+
cls.apiclient,
78+
cls.services["service_offerings"]
79+
)
7880
cls._cleanup.append(cls.service_offering)
7981
cls.virtual_machine = cls.virtual_machine_with_disk = \
80-
VirtualMachine.create(
81-
cls.apiclient,
82-
cls.services["server_without_disk"],
83-
templateid=template.id,
84-
accountid=cls.account.name,
85-
domainid=cls.account.domainid,
86-
serviceofferingid=cls.service_offering.id,
87-
mode=cls.services["mode"]
88-
)
82+
VirtualMachine.create(
83+
cls.apiclient,
84+
cls.services["server_without_disk"],
85+
templateid=template.id,
86+
accountid=cls.account.name,
87+
domainid=cls.account.domainid,
88+
zoneid=cls.zone.id,
89+
serviceofferingid=cls.service_offering.id,
90+
mode=cls.services["mode"]
91+
)
8992
return
9093

9194
@classmethod
9295
def tearDownClass(cls):
9396
try:
94-
#Cleanup resources used
97+
# Cleanup resources used
9598
cleanup_resources(cls.apiclient, cls._cleanup)
9699
except Exception as e:
97100
raise Exception("Warning: Exception during cleanup : %s" % e)
@@ -105,14 +108,14 @@ def setUp(self):
105108

106109
def tearDown(self):
107110
try:
108-
#Clean up, terminate the created instance, volumes and snapshots
111+
# Clean up, terminate the created instance, volumes and snapshots
109112
cleanup_resources(self.apiclient, self.cleanup)
110113
except Exception as e:
111114
raise Exception("Warning: Exception during cleanup : %s" % e)
112115
return
113116

114117
@skipTestIf("hypervisorNotSupported")
115-
@attr(tags = ["advanced", "advancedns", "smoke"], required_hardware="true")
118+
@attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true")
116119
def test_01_snapshot_root_disk(self):
117120
"""Test Snapshot Root Disk
118121
"""
@@ -123,65 +126,76 @@ def test_01_snapshot_root_disk(self):
123126
# the reqd volume under
124127
# /secondary/snapshots//$account_id/$volumeid/$snapshot_uuid
125128
# 3. verify backup_snap_id was non null in the `snapshots` table
129+
# 4. Verify that zoneid is returned in listSnapshots API response
126130

127131
volumes = list_volumes(
128-
self.apiclient,
129-
virtualmachineid=self.virtual_machine_with_disk.id,
130-
type='ROOT',
131-
listall=True
132-
)
132+
self.apiclient,
133+
virtualmachineid=self.virtual_machine_with_disk.id,
134+
type='ROOT',
135+
listall=True
136+
)
133137

134138
snapshot = Snapshot.create(
135-
self.apiclient,
136-
volumes[0].id,
137-
account=self.account.name,
138-
domainid=self.account.domainid
139-
)
139+
self.apiclient,
140+
volumes[0].id,
141+
account=self.account.name,
142+
domainid=self.account.domainid
143+
)
140144
self.debug("Snapshot created: ID - %s" % snapshot.id)
141145

142146
snapshots = list_snapshots(
143-
self.apiclient,
144-
id=snapshot.id
145-
)
147+
self.apiclient,
148+
id=snapshot.id
149+
)
146150
self.assertEqual(
147-
isinstance(snapshots, list),
148-
True,
149-
"Check list response returns a valid list"
150-
)
151+
isinstance(snapshots, list),
152+
True,
153+
"Check list response returns a valid list"
154+
)
151155

152156
self.assertNotEqual(
153-
snapshots,
154-
None,
155-
"Check if result exists in list item call"
156-
)
157+
snapshots,
158+
None,
159+
"Check if result exists in list item call"
160+
)
157161
self.assertEqual(
158-
snapshots[0].id,
159-
snapshot.id,
160-
"Check resource id in list resources call"
161-
)
162+
snapshots[0].id,
163+
snapshot.id,
164+
"Check resource id in list resources call"
165+
)
166+
167+
self.assertIsNotNone(snapshots[0].zoneid,
168+
"Zone id is not none in listSnapshots")
169+
self.assertEqual(
170+
snapshots[0].zoneid,
171+
self.zone.id,
172+
"Check zone id in the list snapshots"
173+
)
174+
162175
self.debug(
163-
"select backup_snap_id, account_id, volume_id from snapshots where uuid = '%s';" \
176+
"select backup_snap_id, account_id, volume_id from snapshots where uuid = '%s';"
164177
% str(snapshot.id)
165-
)
178+
)
166179
qresultset = self.dbclient.execute(
167-
"select backup_snap_id, account_id, volume_id from snapshots where uuid = '%s';" \
168-
% str(snapshot.id)
169-
)
180+
"select backup_snap_id, account_id, volume_id from snapshots where uuid = '%s';"
181+
% str(snapshot.id)
182+
)
170183
self.assertNotEqual(
171-
len(qresultset),
172-
0,
173-
"Check DB Query result set"
174-
)
184+
len(qresultset),
185+
0,
186+
"Check DB Query result set"
187+
)
175188

176189
qresult = qresultset[0]
177190

178191
snapshot_uuid = qresult[0] # backup_snap_id = snapshot UUID
179192

180193
self.assertNotEqual(
181-
str(snapshot_uuid),
182-
'NULL',
183-
"Check if backup_snap_id is not null"
184-
)
194+
str(snapshot_uuid),
195+
'NULL',
196+
"Check if backup_snap_id is not null"
197+
)
185198

186-
self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, snapshot.id))
199+
self.assertTrue(is_snapshot_on_nfs(
200+
self.apiclient, self.dbclient, self.config, self.zone.id, snapshot.id))
187201
return

0 commit comments

Comments
 (0)