mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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>
This commit is contained in:
parent
684573939f
commit
02e7630f1c
@ -21,9 +21,7 @@ from marvin.cloudstackAPI import *
|
|||||||
from marvin.integration.lib.utils import *
|
from marvin.integration.lib.utils import *
|
||||||
from marvin.integration.lib.base import *
|
from marvin.integration.lib.base import *
|
||||||
from marvin.integration.lib.common import *
|
from marvin.integration.lib.common import *
|
||||||
from marvin.remoteSSHClient import remoteSSHClient
|
|
||||||
from marvin.integration.lib.utils import is_snapshot_on_nfs
|
from marvin.integration.lib.utils import is_snapshot_on_nfs
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
class Services:
|
class Services:
|
||||||
@ -289,27 +287,8 @@ class TestAccountSnapshotClean(cloudstackTestCase):
|
|||||||
"Check snapshot id in list resources call"
|
"Check snapshot id in list resources call"
|
||||||
)
|
)
|
||||||
|
|
||||||
qresultset = self.dbclient.execute(
|
self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, self.snapshot.id),
|
||||||
"select id from snapshots where uuid = '%s';" \
|
"Snapshot was not found on NFS")
|
||||||
% 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.debug("Deleting account: %s" % self.account.name)
|
self.debug("Deleting account: %s" % self.account.name)
|
||||||
# Delete account
|
# Delete account
|
||||||
@ -327,7 +306,6 @@ class TestAccountSnapshotClean(cloudstackTestCase):
|
|||||||
"List accounts should return empty list after account deletion"
|
"List accounts should return empty list after account deletion"
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertFalse(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config.mgtSvr,
|
self.assertFalse(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, self.snapshot.id),
|
||||||
self.services["paths"], self.zone.id, snapshot_id),
|
"Snapshot was still found on NFS after account gc")
|
||||||
"Snapshot was still found no NFS after account gc")
|
|
||||||
return
|
return
|
||||||
|
|||||||
@ -289,25 +289,5 @@ class TestSnapshotLimit(cloudstackTestCase):
|
|||||||
snapshot = snapshots[0]
|
snapshot = snapshots[0]
|
||||||
# Sleep to ensure that snapshot is reflected in sec storage
|
# Sleep to ensure that snapshot is reflected in sec storage
|
||||||
time.sleep(self.services["sleep"])
|
time.sleep(self.services["sleep"])
|
||||||
|
self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, snapshot.id))
|
||||||
# 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))
|
|
||||||
return
|
return
|
||||||
|
|||||||
@ -23,9 +23,7 @@ from marvin.cloudstackAPI import *
|
|||||||
from marvin.integration.lib.utils import *
|
from marvin.integration.lib.utils import *
|
||||||
from marvin.integration.lib.base import *
|
from marvin.integration.lib.base import *
|
||||||
from marvin.integration.lib.common import *
|
from marvin.integration.lib.common import *
|
||||||
from marvin.remoteSSHClient import remoteSSHClient
|
|
||||||
from marvin.integration.lib.utils import is_snapshot_on_nfs
|
from marvin.integration.lib.utils import is_snapshot_on_nfs
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
class Services:
|
class Services:
|
||||||
@ -250,26 +248,7 @@ class TestSnapshots(cloudstackTestCase):
|
|||||||
snapshot.id,
|
snapshot.id,
|
||||||
"Check resource id in list resources call"
|
"Check resource id in list resources call"
|
||||||
)
|
)
|
||||||
qresultset = self.dbclient.execute(
|
self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, snapshot.id))
|
||||||
"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))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@attr(speed = "slow")
|
@attr(speed = "slow")
|
||||||
@ -514,31 +493,16 @@ class TestSnapshots(cloudstackTestCase):
|
|||||||
domainid=self.account.domainid
|
domainid=self.account.domainid
|
||||||
)
|
)
|
||||||
snapshot.delete(self.apiclient)
|
snapshot.delete(self.apiclient)
|
||||||
|
|
||||||
snapshots = list_snapshots(
|
snapshots = list_snapshots(
|
||||||
self.apiclient,
|
self.apiclient,
|
||||||
id=snapshot.id
|
id=snapshot.id
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
snapshots,
|
snapshots,
|
||||||
None,
|
None,
|
||||||
"Check if result exists in list item call"
|
"Check if result exists in list item call"
|
||||||
)
|
)
|
||||||
qresultset = self.dbclient.execute(
|
self.assertFalse(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, snapshot.id))
|
||||||
"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))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@attr(speed = "slow")
|
@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';" \
|
self.debug("select backup_snap_id, account_id, volume_id from snapshots where uuid = '%s';" \
|
||||||
% snapshot.id)
|
% snapshot.id)
|
||||||
# Verify backup_snap_id is not NULL
|
snapshot_uuid = snapshot.id
|
||||||
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]
|
|
||||||
|
|
||||||
# Generate template from the snapshot
|
# Generate template from the snapshot
|
||||||
template = Template.create_from_snapshot(
|
template = Template.create_from_snapshot(
|
||||||
@ -1061,8 +1013,7 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase):
|
|||||||
'Running',
|
'Running',
|
||||||
"Check list VM response for Running state"
|
"Check list VM response for Running state"
|
||||||
)
|
)
|
||||||
self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config.mgtSvr,
|
self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config, self.zone.id, snapshot_uuid))
|
||||||
self.services["paths"], self.zone.id, snapshot_uuid))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -18,15 +18,16 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import marvin
|
import marvin
|
||||||
|
import os
|
||||||
import time
|
import time
|
||||||
from marvin.remoteSSHClient import remoteSSHClient
|
|
||||||
from marvin.cloudstackAPI import *
|
|
||||||
import logging
|
import logging
|
||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
import imaplib
|
import imaplib
|
||||||
import email
|
import email
|
||||||
import datetime
|
import datetime
|
||||||
|
from marvin.cloudstackAPI import *
|
||||||
|
from marvin.remoteSSHClient import remoteSSHClient
|
||||||
|
|
||||||
|
|
||||||
def restart_mgmt_server(server):
|
def restart_mgmt_server(server):
|
||||||
@ -220,34 +221,46 @@ def xsplit(txt, seps):
|
|||||||
txt = txt.replace(sep, default_sep)
|
txt = txt.replace(sep, default_sep)
|
||||||
return [i.strip() for i in txt.split(default_sep)]
|
return [i.strip() for i in txt.split(default_sep)]
|
||||||
|
|
||||||
def is_snapshot_on_nfs(api_client, db_client, config_mgtSvr,
|
def is_snapshot_on_nfs(apiclient, dbconn, config, zoneid, snapshotid):
|
||||||
dir_paths, zone_id, snapshot_id):
|
|
||||||
"""
|
"""
|
||||||
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
|
@return: True if snapshot is found, False otherwise
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from base import ImageStore
|
from base import ImageStore, Snapshot
|
||||||
|
secondaryStores = ImageStore.list(apiclient, zoneid=zoneid)
|
||||||
secondaryStores = ImageStore.list(api_client, zoneid=zone_id)
|
|
||||||
|
|
||||||
assert isinstance(secondaryStores, list), "Not a valid response for listImageStores"
|
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]
|
secondaryStore = secondaryStores[0]
|
||||||
|
|
||||||
if str(secondaryStore.providername).lower() != "nfs":
|
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 = db_client.execute(
|
qresultset = dbconn.execute(
|
||||||
"select install_path from snapshot_store_ref where snapshot_id='%s' and store_role='Image';" % snapshot_id
|
"select id from snapshots where uuid = '%s';" \
|
||||||
|
% str(snapshotid)
|
||||||
|
)
|
||||||
|
if len(qresultset) == 0:
|
||||||
|
raise Exception(
|
||||||
|
"No snapshot found in cloudstack with id %s" % snapshotid)
|
||||||
|
|
||||||
|
|
||||||
|
snapshotid = qresultset[0][0]
|
||||||
|
qresultset = dbconn.execute(
|
||||||
|
"select install_path from snapshot_store_ref where snapshot_id='%s' and store_role='Image';" % snapshotid
|
||||||
)
|
)
|
||||||
|
|
||||||
assert isinstance(qresultset, list), "Invalid db query response for snapshot %s" % 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
|
||||||
assert len(qresultset) != 0, "No such snapshot %s found in the cloudstack db" % snapshot_id
|
|
||||||
|
|
||||||
snapshotPath = qresultset[0][0]
|
snapshotPath = qresultset[0][0]
|
||||||
|
|
||||||
@ -256,28 +269,27 @@ def is_snapshot_on_nfs(api_client, db_client, config_mgtSvr,
|
|||||||
from urllib2 import urlparse
|
from urllib2 import urlparse
|
||||||
parse_url = urlparse.urlsplit(nfsurl, scheme='nfs')
|
parse_url = urlparse.urlsplit(nfsurl, scheme='nfs')
|
||||||
host, path = parse_url.netloc, parse_url.path
|
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:
|
try:
|
||||||
# Login to Secondary storage VM to check snapshot present on sec disk
|
|
||||||
ssh_client = remoteSSHClient(
|
ssh_client = remoteSSHClient(
|
||||||
config_mgtSvr[0].mgtSvrIp,
|
host,
|
||||||
22,
|
22,
|
||||||
config_mgtSvr[0].user,
|
user,
|
||||||
config_mgtSvr[0].passwd,
|
passwd,
|
||||||
)
|
)
|
||||||
import os
|
|
||||||
|
|
||||||
cmds = [
|
cmds = [
|
||||||
"mkdir -p %s" % dir_paths["mount_dir"],
|
"mkdir -p %s /mnt/tmp",
|
||||||
"mount -t %s %s%s %s" % (
|
"mount -t %s %s%s /mnt/tmp" % (
|
||||||
'nfs',
|
'nfs',
|
||||||
host,
|
host,
|
||||||
path,
|
path,
|
||||||
dir_paths["mount_dir"]
|
|
||||||
),
|
),
|
||||||
"test -f %s && echo 'snapshot exists'" % (
|
"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
|
# Unmount the Sec Storage
|
||||||
cmds = [
|
cmds = [
|
||||||
"cd",
|
"cd",
|
||||||
"umount %s" % (dir_paths["mount_dir"]),
|
"umount /mnt/tmp",
|
||||||
]
|
]
|
||||||
for c in cmds:
|
for c in cmds:
|
||||||
ssh_client.execute(c)
|
ssh_client.execute(c)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception("SSH failed for management server: %s - %s" %
|
raise Exception("SSH failed for management server: %s - %s" %
|
||||||
(config_mgtSvr[0].mgtSvrIp, e))
|
(config[0].mgtSvrIp, e))
|
||||||
return 'snapshot exists' in result
|
return 'snapshot exists' in result
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user