Skip to content

Commit 81d489d

Browse files
author
Prasanna Santhanam
committed
CLOUDSTACK-4452: Cleaning up the is_snapshot_on_nfs utility
- Pass in config and determine the mgmtsvr credentials - remove the dir_paths param which is not reqd. - pass all entities as uuids and convert to ids within the method Signed-off-by: Prasanna Santhanam <tsp@apache.org> (cherry picked from commit 02e7630)
1 parent 35ee383 commit 81d489d

4 files changed

Lines changed: 50 additions & 129 deletions

File tree

‎test/integration/component/test_snapshot_gc.py‎

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
from marvin.integration.lib.utils import *
2222
from marvin.integration.lib.base import *
2323
from marvin.integration.lib.common import *
24-
from marvin.remoteSSHClient import remoteSSHClient
2524
from marvin.integration.lib.utils import is_snapshot_on_nfs
26-
import os
2725

2826

2927
class Services:
@@ -289,27 +287,8 @@ def test_02_accountSnapshotClean(self):
289287
"Check snapshot id in list resources call"
290288
)
291289

292-
qresultset = self.dbclient.execute(
293-
"select id from snapshots where uuid = '%s';" \
294-
% self.snapshot.id
295-
)
296-
self.assertEqual(
297-
isinstance(qresultset, list),
298-
True,
299-
"Invalid db query response for snapshot %s" % self.snapshot.id
300-
)
301-
self.assertNotEqual(
302-
len(qresultset),
303-
0,
304-
"No such snapshot %s found in the cloudstack db" % self.snapshot.id
305-
)
306-
307-
qresult = qresultset[0]
308-
snapshot_id = qresult[0]
309-
310-
self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config.mgtSvr,
311-
self.services["paths"], self.zone.id, snapshot_id),
312-
"Snapshot was not found on NFS")
290+
self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, self.snapshot.id),
291+
"Snapshot was not found on NFS")
313292

314293
self.debug("Deleting account: %s" % self.account.name)
315294
# Delete account
@@ -327,7 +306,6 @@ def test_02_accountSnapshotClean(self):
327306
"List accounts should return empty list after account deletion"
328307
)
329308

330-
self.assertFalse(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config.mgtSvr,
331-
self.services["paths"], self.zone.id, snapshot_id),
332-
"Snapshot was still found no NFS after account gc")
309+
self.assertFalse(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, self.snapshot.id),
310+
"Snapshot was still found on NFS after account gc")
333311
return

‎test/integration/component/test_snapshot_limits.py‎

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -289,25 +289,5 @@ def test_04_snapshot_limit(self):
289289
snapshot = snapshots[0]
290290
# Sleep to ensure that snapshot is reflected in sec storage
291291
time.sleep(self.services["sleep"])
292-
293-
# Fetch values from database
294-
qresultset = self.dbclient.execute(
295-
"select id from snapshots where uuid = '%s';" \
296-
% snapshot.id
297-
)
298-
self.assertEqual(
299-
isinstance(qresultset, list),
300-
True,
301-
"Invalid db query response for snapshot %s" % snapshot.id
302-
)
303-
self.assertNotEqual(
304-
len(qresultset),
305-
0,
306-
"No such snapshot %s found in the cloudstack db" % snapshot.id
307-
)
308-
309-
qresult = qresultset[0]
310-
snapshot_id = qresult[0]
311-
self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config.mgtSvr,
312-
self.services["paths"], self.zone.id, snapshot_id))
292+
self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, snapshot.id))
313293
return

‎test/integration/component/test_snapshots.py‎

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
from marvin.integration.lib.utils import *
2424
from marvin.integration.lib.base import *
2525
from marvin.integration.lib.common import *
26-
from marvin.remoteSSHClient import remoteSSHClient
2726
from marvin.integration.lib.utils import is_snapshot_on_nfs
28-
import os
2927

3028

3129
class Services:
@@ -250,26 +248,7 @@ def test_02_snapshot_data_disk(self):
250248
snapshot.id,
251249
"Check resource id in list resources call"
252250
)
253-
qresultset = self.dbclient.execute(
254-
"select id from snapshots where uuid = '%s';" \
255-
% str(snapshot.id)
256-
)
257-
self.assertNotEqual(
258-
len(qresultset),
259-
0,
260-
"Check DB Query result set"
261-
)
262-
263-
qresult = qresultset[0]
264-
snapshot_uuid = qresult[0] # backup_snap_id = snapshot UUID
265-
266-
self.assertNotEqual(
267-
str(snapshot_uuid),
268-
'NULL',
269-
"Check if backup_snap_id is not null"
270-
)
271-
self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config.mgtSvr,
272-
self.services["paths"], self.zone.id, snapshot_uuid))
251+
self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, snapshot.id))
273252
return
274253

275254
@attr(speed = "slow")
@@ -514,31 +493,16 @@ def test_04_delete_snapshot(self):
514493
domainid=self.account.domainid
515494
)
516495
snapshot.delete(self.apiclient)
517-
518496
snapshots = list_snapshots(
519497
self.apiclient,
520498
id=snapshot.id
521499
)
522-
523500
self.assertEqual(
524501
snapshots,
525502
None,
526503
"Check if result exists in list item call"
527504
)
528-
qresultset = self.dbclient.execute(
529-
"select id from snapshots where uuid = '%s';" \
530-
% str(snapshot.id)
531-
)
532-
self.assertNotEqual(
533-
len(qresultset),
534-
0,
535-
"Check DB Query result set"
536-
)
537-
538-
qresult = qresultset[0]
539-
snapshotid = qresult[0]
540-
self.assertFalse(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config.mgtSvr,
541-
self.services["paths"], self.zone.id, snapshotid))
505+
self.assertFalse(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, snapshot.id))
542506
return
543507

544508
@attr(speed = "slow")
@@ -981,19 +945,7 @@ def test_01_createVM_snapshotTemplate(self):
981945
)
982946
self.debug("select backup_snap_id, account_id, volume_id from snapshots where uuid = '%s';" \
983947
% snapshot.id)
984-
# Verify backup_snap_id is not NULL
985-
qresultset = self.dbclient.execute(
986-
"select id from snapshots where uuid = '%s';" \
987-
% snapshot.id
988-
)
989-
self.assertNotEqual(
990-
len(qresultset),
991-
0,
992-
"Check DB Query result set"
993-
)
994-
995-
qresult = qresultset[0]
996-
snapshot_uuid = qresult[0]
948+
snapshot_uuid = snapshot.id
997949

998950
# Generate template from the snapshot
999951
template = Template.create_from_snapshot(
@@ -1061,8 +1013,7 @@ def test_01_createVM_snapshotTemplate(self):
10611013
'Running',
10621014
"Check list VM response for Running state"
10631015
)
1064-
self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config.mgtSvr,
1065-
self.services["paths"], self.zone.id, snapshot_uuid))
1016+
self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, snapshot_uuid))
10661017
return
10671018

10681019

‎tools/marvin/marvin/integration/lib/utils.py‎

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818
"""
1919

2020
import marvin
21+
import os
2122
import time
22-
from marvin.remoteSSHClient import remoteSSHClient
23-
from marvin.cloudstackAPI import *
2423
import logging
2524
import string
2625
import random
2726
import imaplib
2827
import email
2928
import datetime
29+
from marvin.cloudstackAPI import *
30+
from marvin.remoteSSHClient import remoteSSHClient
3031

3132

3233
def restart_mgmt_server(server):
@@ -220,34 +221,46 @@ def xsplit(txt, seps):
220221
txt = txt.replace(sep, default_sep)
221222
return [i.strip() for i in txt.split(default_sep)]
222223

223-
def is_snapshot_on_nfs(api_client, db_client, config_mgtSvr,
224-
dir_paths, zone_id, snapshot_id):
224+
def is_snapshot_on_nfs(apiclient, dbconn, config, zoneid, snapshotid):
225225
"""
226-
Checks whether a snapshot with id (not UUID) `snapshot_id` is present on the nfs storage
226+
Checks whether a snapshot with id (not UUID) `snapshotid` is present on the nfs storage
227227
228-
@param snapshot_id: id of the snapshot (not uuid)
228+
@param apiclient: api client connection
229+
@param @dbconn: connection to the cloudstack db
230+
@param config: marvin configuration file
231+
@param zoneid: uuid of the zone on which the secondary nfs storage pool is mounted
232+
@param snapshotid: uuid of the snapshot
229233
@return: True if snapshot is found, False otherwise
230234
"""
231235

232-
from base import ImageStore
233-
234-
secondaryStores = ImageStore.list(api_client, zoneid=zone_id)
236+
from base import ImageStore, Snapshot
237+
secondaryStores = ImageStore.list(apiclient, zoneid=zoneid)
235238

236239
assert isinstance(secondaryStores, list), "Not a valid response for listImageStores"
237-
assert len(secondaryStores) != 0, "No image stores found in zone %s" % zone_id
240+
assert len(secondaryStores) != 0, "No image stores found in zone %s" % zoneid
238241

239242
secondaryStore = secondaryStores[0]
240243

241244
if str(secondaryStore.providername).lower() != "nfs":
242-
raise Exception("Test works only against nfs secondary storage")
245+
raise Exception(
246+
"is_snapshot_on_nfs works only against nfs secondary storage. found %s" % str(secondaryStore.providername))
247+
248+
qresultset = dbconn.execute(
249+
"select id from snapshots where uuid = '%s';" \
250+
% str(snapshotid)
251+
)
252+
if len(qresultset) == 0:
253+
raise Exception(
254+
"No snapshot found in cloudstack with id %s" % snapshotid)
243255

244-
qresultset = db_client.execute(
245-
"select install_path from snapshot_store_ref where snapshot_id='%s' and store_role='Image';" % snapshot_id
246-
)
247256

248-
assert isinstance(qresultset, list), "Invalid db query response for snapshot %s" % snapshot_id
257+
snapshotid = qresultset[0][0]
258+
qresultset = dbconn.execute(
259+
"select install_path from snapshot_store_ref where snapshot_id='%s' and store_role='Image';" % snapshotid
260+
)
249261

250-
assert len(qresultset) != 0, "No such snapshot %s found in the cloudstack db" % snapshot_id
262+
assert isinstance(qresultset, list), "Invalid db query response for snapshot %s" % snapshotid
263+
assert len(qresultset) != 0, "No such snapshot %s found in the cloudstack db" % snapshotid
251264

252265
snapshotPath = qresultset[0][0]
253266

@@ -256,28 +269,27 @@ def is_snapshot_on_nfs(api_client, db_client, config_mgtSvr,
256269
from urllib2 import urlparse
257270
parse_url = urlparse.urlsplit(nfsurl, scheme='nfs')
258271
host, path = parse_url.netloc, parse_url.path
259-
snapshots = []
272+
273+
if not config.mgtSvr:
274+
raise Exception("Your marvin configuration does not contain mgmt server credentials")
275+
host, user, passwd = config.mgtSvr[0].mgtSvrIp, config.mgtSvr[0].user, config.mgtSvr[0].passwd
260276

261277
try:
262-
# Login to Secondary storage VM to check snapshot present on sec disk
263278
ssh_client = remoteSSHClient(
264-
config_mgtSvr[0].mgtSvrIp,
279+
host,
265280
22,
266-
config_mgtSvr[0].user,
267-
config_mgtSvr[0].passwd,
281+
user,
282+
passwd,
268283
)
269-
import os
270-
271284
cmds = [
272-
"mkdir -p %s" % dir_paths["mount_dir"],
273-
"mount -t %s %s%s %s" % (
285+
"mkdir -p %s /mnt/tmp",
286+
"mount -t %s %s%s /mnt/tmp" % (
274287
'nfs',
275288
host,
276289
path,
277-
dir_paths["mount_dir"]
278290
),
279291
"test -f %s && echo 'snapshot exists'" % (
280-
os.path.join(dir_paths["mount_dir"], snapshotPath)
292+
os.path.join("/mnt/tmp", snapshotPath)
281293
),
282294
]
283295

@@ -287,11 +299,11 @@ def is_snapshot_on_nfs(api_client, db_client, config_mgtSvr,
287299
# Unmount the Sec Storage
288300
cmds = [
289301
"cd",
290-
"umount %s" % (dir_paths["mount_dir"]),
302+
"umount /mnt/tmp",
291303
]
292304
for c in cmds:
293305
ssh_client.execute(c)
294306
except Exception as e:
295307
raise Exception("SSH failed for management server: %s - %s" %
296-
(config_mgtSvr[0].mgtSvrIp, e))
308+
(config[0].mgtSvrIp, e))
297309
return 'snapshot exists' in result

0 commit comments

Comments
 (0)