You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ts...@apache.org on 2013/08/26 10:49:10 UTC
[2/2] git commit: updated refs/heads/master to 02e7630
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 <ts...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/02e7630f
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/02e7630f
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/02e7630f
Branch: refs/heads/master
Commit: 02e7630f1cf218b1436a71a42623a7bf790d98e7
Parents: 6845739
Author: Prasanna Santhanam <ts...@apache.org>
Authored: Mon Aug 26 11:10:06 2013 +0530
Committer: Prasanna Santhanam <ts...@apache.org>
Committed: Mon Aug 26 11:10:06 2013 +0530
----------------------------------------------------------------------
test/integration/component/test_snapshot_gc.py | 30 ++-------
.../component/test_snapshot_limits.py | 22 +-----
test/integration/component/test_snapshots.py | 57 ++--------------
tools/marvin/marvin/integration/lib/utils.py | 70 ++++++++++++--------
4 files changed, 50 insertions(+), 129 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/02e7630f/test/integration/component/test_snapshot_gc.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_snapshot_gc.py b/test/integration/component/test_snapshot_gc.py
index ea40273..aec9761 100644
--- a/test/integration/component/test_snapshot_gc.py
+++ b/test/integration/component/test_snapshot_gc.py
@@ -21,9 +21,7 @@ from marvin.cloudstackAPI import *
from marvin.integration.lib.utils import *
from marvin.integration.lib.base import *
from marvin.integration.lib.common import *
-from marvin.remoteSSHClient import remoteSSHClient
from marvin.integration.lib.utils import is_snapshot_on_nfs
-import os
class Services:
@@ -289,27 +287,8 @@ class TestAccountSnapshotClean(cloudstackTestCase):
"Check snapshot id in list resources call"
)
- qresultset = self.dbclient.execute(
- "select id from snapshots where uuid = '%s';" \
- % self.snapshot.id
- )
- self.assertEqual(
- isinstance(qresultset, list),
- True,
- "Invalid db query response for snapshot %s" % self.snapshot.id
- )
- self.assertNotEqual(
- len(qresultset),
- 0,
- "No such snapshot %s found in the cloudstack db" % self.snapshot.id
- )
-
- qresult = qresultset[0]
- snapshot_id = qresult[0]
-
- self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config.mgtSvr,
- self.services["paths"], self.zone.id, snapshot_id),
- "Snapshot was not found on NFS")
+ self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, self.snapshot.id),
+ "Snapshot was not found on NFS")
self.debug("Deleting account: %s" % self.account.name)
# Delete account
@@ -327,7 +306,6 @@ class TestAccountSnapshotClean(cloudstackTestCase):
"List accounts should return empty list after account deletion"
)
- self.assertFalse(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config.mgtSvr,
- self.services["paths"], self.zone.id, snapshot_id),
- "Snapshot was still found no NFS after account gc")
+ self.assertFalse(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, self.snapshot.id),
+ "Snapshot was still found on NFS after account gc")
return
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/02e7630f/test/integration/component/test_snapshot_limits.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_snapshot_limits.py b/test/integration/component/test_snapshot_limits.py
index 3845c96..2af77c3 100644
--- a/test/integration/component/test_snapshot_limits.py
+++ b/test/integration/component/test_snapshot_limits.py
@@ -289,25 +289,5 @@ class TestSnapshotLimit(cloudstackTestCase):
snapshot = snapshots[0]
# Sleep to ensure that snapshot is reflected in sec storage
time.sleep(self.services["sleep"])
-
- # Fetch values from database
- qresultset = self.dbclient.execute(
- "select id from snapshots where uuid = '%s';" \
- % snapshot.id
- )
- self.assertEqual(
- isinstance(qresultset, list),
- True,
- "Invalid db query response for snapshot %s" % snapshot.id
- )
- self.assertNotEqual(
- len(qresultset),
- 0,
- "No such snapshot %s found in the cloudstack db" % snapshot.id
- )
-
- qresult = qresultset[0]
- snapshot_id = qresult[0]
- self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config.mgtSvr,
- self.services["paths"], self.zone.id, snapshot_id))
+ self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, snapshot.id))
return
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/02e7630f/test/integration/component/test_snapshots.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_snapshots.py b/test/integration/component/test_snapshots.py
index d3da505..1c2537c 100644
--- a/test/integration/component/test_snapshots.py
+++ b/test/integration/component/test_snapshots.py
@@ -23,9 +23,7 @@ from marvin.cloudstackAPI import *
from marvin.integration.lib.utils import *
from marvin.integration.lib.base import *
from marvin.integration.lib.common import *
-from marvin.remoteSSHClient import remoteSSHClient
from marvin.integration.lib.utils import is_snapshot_on_nfs
-import os
class Services:
@@ -250,26 +248,7 @@ class TestSnapshots(cloudstackTestCase):
snapshot.id,
"Check resource id in list resources call"
)
- qresultset = self.dbclient.execute(
- "select id from snapshots where uuid = '%s';" \
- % str(snapshot.id)
- )
- self.assertNotEqual(
- len(qresultset),
- 0,
- "Check DB Query result set"
- )
-
- qresult = qresultset[0]
- snapshot_uuid = qresult[0] # backup_snap_id = snapshot UUID
-
- self.assertNotEqual(
- str(snapshot_uuid),
- 'NULL',
- "Check if backup_snap_id is not null"
- )
- self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config.mgtSvr,
- self.services["paths"], self.zone.id, snapshot_uuid))
+ self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, snapshot.id))
return
@attr(speed = "slow")
@@ -514,31 +493,16 @@ class TestSnapshots(cloudstackTestCase):
domainid=self.account.domainid
)
snapshot.delete(self.apiclient)
-
snapshots = list_snapshots(
self.apiclient,
id=snapshot.id
)
-
self.assertEqual(
snapshots,
None,
"Check if result exists in list item call"
)
- qresultset = self.dbclient.execute(
- "select id from snapshots where uuid = '%s';" \
- % str(snapshot.id)
- )
- self.assertNotEqual(
- len(qresultset),
- 0,
- "Check DB Query result set"
- )
-
- qresult = qresultset[0]
- snapshotid = qresult[0]
- self.assertFalse(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config.mgtSvr,
- self.services["paths"], self.zone.id, snapshotid))
+ self.assertFalse(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, snapshot.id))
return
@attr(speed = "slow")
@@ -981,19 +945,7 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase):
)
self.debug("select backup_snap_id, account_id, volume_id from snapshots where uuid = '%s';" \
% snapshot.id)
- # Verify backup_snap_id is not NULL
- qresultset = self.dbclient.execute(
- "select id from snapshots where uuid = '%s';" \
- % snapshot.id
- )
- self.assertNotEqual(
- len(qresultset),
- 0,
- "Check DB Query result set"
- )
-
- qresult = qresultset[0]
- snapshot_uuid = qresult[0]
+ snapshot_uuid = snapshot.id
# Generate template from the snapshot
template = Template.create_from_snapshot(
@@ -1061,8 +1013,7 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase):
'Running',
"Check list VM response for Running state"
)
- self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config.mgtSvr,
- self.services["paths"], self.zone.id, snapshot_uuid))
+ self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, snapshot_uuid))
return
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/02e7630f/tools/marvin/marvin/integration/lib/utils.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/integration/lib/utils.py b/tools/marvin/marvin/integration/lib/utils.py
index e65044b..1512d52 100644
--- a/tools/marvin/marvin/integration/lib/utils.py
+++ b/tools/marvin/marvin/integration/lib/utils.py
@@ -18,15 +18,16 @@
"""
import marvin
+import os
import time
-from marvin.remoteSSHClient import remoteSSHClient
-from marvin.cloudstackAPI import *
import logging
import string
import random
import imaplib
import email
import datetime
+from marvin.cloudstackAPI import *
+from marvin.remoteSSHClient import remoteSSHClient
def restart_mgmt_server(server):
@@ -220,34 +221,46 @@ def xsplit(txt, seps):
txt = txt.replace(sep, default_sep)
return [i.strip() for i in txt.split(default_sep)]
-def is_snapshot_on_nfs(api_client, db_client, config_mgtSvr,
- dir_paths, zone_id, snapshot_id):
+def is_snapshot_on_nfs(apiclient, dbconn, config, zoneid, snapshotid):
"""
- Checks whether a snapshot with id (not UUID) `snapshot_id` is present on the nfs storage
+ Checks whether a snapshot with id (not UUID) `snapshotid` is present on the nfs storage
- @param snapshot_id: id of the snapshot (not uuid)
+ @param apiclient: api client connection
+ @param @dbconn: connection to the cloudstack db
+ @param config: marvin configuration file
+ @param zoneid: uuid of the zone on which the secondary nfs storage pool is mounted
+ @param snapshotid: uuid of the snapshot
@return: True if snapshot is found, False otherwise
"""
- from base import ImageStore
-
- secondaryStores = ImageStore.list(api_client, zoneid=zone_id)
+ from base import ImageStore, Snapshot
+ secondaryStores = ImageStore.list(apiclient, zoneid=zoneid)
assert isinstance(secondaryStores, list), "Not a valid response for listImageStores"
- assert len(secondaryStores) != 0, "No image stores found in zone %s" % zone_id
+ assert len(secondaryStores) != 0, "No image stores found in zone %s" % zoneid
secondaryStore = secondaryStores[0]
if str(secondaryStore.providername).lower() != "nfs":
- raise Exception("Test works only against nfs secondary storage")
+ raise Exception(
+ "is_snapshot_on_nfs works only against nfs secondary storage. found %s" % str(secondaryStore.providername))
+
+ qresultset = dbconn.execute(
+ "select id from snapshots where uuid = '%s';" \
+ % str(snapshotid)
+ )
+ if len(qresultset) == 0:
+ raise Exception(
+ "No snapshot found in cloudstack with id %s" % snapshotid)
- qresultset = db_client.execute(
- "select install_path from snapshot_store_ref where snapshot_id='%s' and store_role='Image';" % snapshot_id
- )
- assert isinstance(qresultset, list), "Invalid db query response for snapshot %s" % snapshot_id
+ snapshotid = qresultset[0][0]
+ qresultset = dbconn.execute(
+ "select install_path from snapshot_store_ref where snapshot_id='%s' and store_role='Image';" % snapshotid
+ )
- assert len(qresultset) != 0, "No such snapshot %s found in the cloudstack db" % snapshot_id
+ assert isinstance(qresultset, list), "Invalid db query response for snapshot %s" % snapshotid
+ assert len(qresultset) != 0, "No such snapshot %s found in the cloudstack db" % snapshotid
snapshotPath = qresultset[0][0]
@@ -256,28 +269,27 @@ def is_snapshot_on_nfs(api_client, db_client, config_mgtSvr,
from urllib2 import urlparse
parse_url = urlparse.urlsplit(nfsurl, scheme='nfs')
host, path = parse_url.netloc, parse_url.path
- snapshots = []
+
+ if not config.mgtSvr:
+ raise Exception("Your marvin configuration does not contain mgmt server credentials")
+ host, user, passwd = config.mgtSvr[0].mgtSvrIp, config.mgtSvr[0].user, config.mgtSvr[0].passwd
try:
- # Login to Secondary storage VM to check snapshot present on sec disk
ssh_client = remoteSSHClient(
- config_mgtSvr[0].mgtSvrIp,
+ host,
22,
- config_mgtSvr[0].user,
- config_mgtSvr[0].passwd,
+ user,
+ passwd,
)
- import os
-
cmds = [
- "mkdir -p %s" % dir_paths["mount_dir"],
- "mount -t %s %s%s %s" % (
+ "mkdir -p %s /mnt/tmp",
+ "mount -t %s %s%s /mnt/tmp" % (
'nfs',
host,
path,
- dir_paths["mount_dir"]
),
"test -f %s && echo 'snapshot exists'" % (
- os.path.join(dir_paths["mount_dir"], snapshotPath)
+ os.path.join("/mnt/tmp", snapshotPath)
),
]
@@ -287,11 +299,11 @@ def is_snapshot_on_nfs(api_client, db_client, config_mgtSvr,
# Unmount the Sec Storage
cmds = [
"cd",
- "umount %s" % (dir_paths["mount_dir"]),
+ "umount /mnt/tmp",
]
for c in cmds:
ssh_client.execute(c)
except Exception as e:
raise Exception("SSH failed for management server: %s - %s" %
- (config_mgtSvr[0].mgtSvrIp, e))
+ (config[0].mgtSvrIp, e))
return 'snapshot exists' in result