mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-4452 - Fixed method is_snapshot_on_nfs and moved it to utils
Signed-off-by: Prasanna Santhanam <tsp@apache.org> (cherry picked from commit 35ee38385ce0c54b3a16c3270db66d3eb3a56d04)
This commit is contained in:
parent
f724c91296
commit
684573939f
@ -22,6 +22,7 @@ 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.remoteSSHClient import remoteSSHClient
|
||||||
|
from marvin.integration.lib.utils import is_snapshot_on_nfs
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
@ -210,82 +211,6 @@ class TestAccountSnapshotClean(cloudstackTestCase):
|
|||||||
raise Exception("Warning: Exception during cleanup : %s" % e)
|
raise Exception("Warning: Exception during cleanup : %s" % e)
|
||||||
return
|
return
|
||||||
|
|
||||||
def is_snapshot_on_nfs(self, snapshot_id):
|
|
||||||
"""
|
|
||||||
Checks whether a snapshot with id (not UUID) `snapshot_id` is present on the nfs storage
|
|
||||||
|
|
||||||
@param snapshot_id: id of the snapshot (not uuid)
|
|
||||||
@return: True if snapshot is found, False otherwise
|
|
||||||
"""
|
|
||||||
secondaryStores = ImageStore.list(self.apiclient, zoneid=self.zone.id)
|
|
||||||
self.assertTrue(isinstance(secondaryStores, list), "Not a valid response for listImageStores")
|
|
||||||
self.assertNotEqual(len(secondaryStores), 0, "No image stores found in zone %s" % self.zone.id)
|
|
||||||
secondaryStore = secondaryStores[0]
|
|
||||||
if str(secondaryStore.providername).lower() != "nfs":
|
|
||||||
self.skipTest("TODO: %s test works only against nfs secondary storage" % self._testMethodName)
|
|
||||||
|
|
||||||
qresultset = self.dbclient.execute(
|
|
||||||
"select install_path from snapshot_store_ref where snapshot_id='%s' and store_role='Image';" % 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
|
|
||||||
)
|
|
||||||
snapshotPath = qresultset[0][0]
|
|
||||||
nfsurl = secondaryStore.url
|
|
||||||
# parse_url = ['nfs:', '', '192.168.100.21', 'export', 'test']
|
|
||||||
from urllib2 import urlparse
|
|
||||||
parse_url = urlparse.urlsplit(nfsurl, scheme='nfs')
|
|
||||||
host, path = parse_url.netloc, parse_url.path
|
|
||||||
# Sleep to ensure that snapshot is reflected in sec storage
|
|
||||||
time.sleep(self.services["sleep"])
|
|
||||||
snapshots = []
|
|
||||||
try:
|
|
||||||
# Login to Secondary storage VM to check snapshot present on sec disk
|
|
||||||
ssh_client = remoteSSHClient(
|
|
||||||
self.config.mgtSvr[0].mgtSvrIp,
|
|
||||||
22,
|
|
||||||
self.config.mgtSvr[0].user,
|
|
||||||
self.config.mgtSvr[0].passwd,
|
|
||||||
)
|
|
||||||
|
|
||||||
cmds = [
|
|
||||||
"mkdir -p %s" % self.services["paths"]["mount_dir"],
|
|
||||||
"mount -t %s %s%s %s" % (
|
|
||||||
'nfs',
|
|
||||||
host,
|
|
||||||
path,
|
|
||||||
self.services["paths"]["mount_dir"]
|
|
||||||
),
|
|
||||||
"ls %s" % (
|
|
||||||
os.path.join(self.services["paths"]["mount_dir"], snapshotPath)
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
||||||
for c in cmds:
|
|
||||||
self.debug("command: %s" % c)
|
|
||||||
result = ssh_client.execute(c)
|
|
||||||
self.debug("Result: %s" % result)
|
|
||||||
|
|
||||||
snapshots.extend(result)
|
|
||||||
# Unmount the Sec Storage
|
|
||||||
cmds = [
|
|
||||||
"cd",
|
|
||||||
"umount %s" % (self.services["paths"]["mount_dir"]),
|
|
||||||
]
|
|
||||||
for c in cmds:
|
|
||||||
ssh_client.execute(c)
|
|
||||||
except Exception as e:
|
|
||||||
self.fail("SSH failed for management server: %s - %s" %
|
|
||||||
(self.config.mgtSvr[0].mgtSvrIp, e))
|
|
||||||
return snapshots.count(snapshot_id) == 1
|
|
||||||
|
|
||||||
@attr(speed = "slow")
|
@attr(speed = "slow")
|
||||||
@attr(tags = ["advanced", "advancedns", "basic", "sg"])
|
@attr(tags = ["advanced", "advancedns", "basic", "sg"])
|
||||||
def test_02_accountSnapshotClean(self):
|
def test_02_accountSnapshotClean(self):
|
||||||
@ -382,7 +307,9 @@ class TestAccountSnapshotClean(cloudstackTestCase):
|
|||||||
qresult = qresultset[0]
|
qresult = qresultset[0]
|
||||||
snapshot_id = qresult[0]
|
snapshot_id = qresult[0]
|
||||||
|
|
||||||
self.assertTrue(self.is_snapshot_on_nfs(snapshot_id), "Snapshot was not found no NFS")
|
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
|
||||||
@ -400,5 +327,7 @@ class TestAccountSnapshotClean(cloudstackTestCase):
|
|||||||
"List accounts should return empty list after account deletion"
|
"List accounts should return empty list after account deletion"
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertFalse(self.is_snapshot_on_nfs(snapshot_id), "Snapshot was still found no NFS after account gc")
|
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")
|
||||||
return
|
return
|
||||||
|
|||||||
@ -22,6 +22,7 @@ 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.remoteSSHClient import remoteSSHClient
|
||||||
|
from marvin.integration.lib.utils import is_snapshot_on_nfs
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
@ -198,82 +199,6 @@ class TestSnapshotLimit(cloudstackTestCase):
|
|||||||
raise Exception("Warning: Exception during cleanup : %s" % e)
|
raise Exception("Warning: Exception during cleanup : %s" % e)
|
||||||
return
|
return
|
||||||
|
|
||||||
def is_snapshot_on_nfs(self, snapshot_id):
|
|
||||||
"""
|
|
||||||
Checks whether a snapshot with id (not UUID) `snapshot_id` is present on the nfs storage
|
|
||||||
|
|
||||||
@param snapshot_id: id of the snapshot (not uuid)
|
|
||||||
@return: True if snapshot is found, False otherwise
|
|
||||||
"""
|
|
||||||
secondaryStores = ImageStore.list(self.apiclient, zoneid=self.zone.id)
|
|
||||||
self.assertTrue(isinstance(secondaryStores, list), "Not a valid response for listImageStores")
|
|
||||||
self.assertNotEqual(len(secondaryStores), 0, "No image stores found in zone %s" % self.zone.id)
|
|
||||||
secondaryStore = secondaryStores[0]
|
|
||||||
if str(secondaryStore.providername).lower() != "nfs":
|
|
||||||
self.skipTest("TODO: %s test works only against nfs secondary storage" % self._testMethodName)
|
|
||||||
|
|
||||||
qresultset = self.dbclient.execute(
|
|
||||||
"select install_path from snapshot_store_ref where snapshot_id='%s' and store_role='Image';" % 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
|
|
||||||
)
|
|
||||||
snapshotPath = qresultset[0][0]
|
|
||||||
nfsurl = secondaryStore.url
|
|
||||||
# parse_url = ['nfs:', '', '192.168.100.21', 'export', 'test']
|
|
||||||
from urllib2 import urlparse
|
|
||||||
parse_url = urlparse.urlsplit(nfsurl, scheme='nfs')
|
|
||||||
host, path = parse_url.netloc, parse_url.path
|
|
||||||
# Sleep to ensure that snapshot is reflected in sec storage
|
|
||||||
time.sleep(self.services["sleep"])
|
|
||||||
snapshots = []
|
|
||||||
try:
|
|
||||||
# Login to Secondary storage VM to check snapshot present on sec disk
|
|
||||||
ssh_client = remoteSSHClient(
|
|
||||||
self.config.mgtSvr[0].mgtSvrIp,
|
|
||||||
22,
|
|
||||||
self.config.mgtSvr[0].user,
|
|
||||||
self.config.mgtSvr[0].passwd,
|
|
||||||
)
|
|
||||||
|
|
||||||
cmds = [
|
|
||||||
"mkdir -p %s" % self.services["paths"]["mount_dir"],
|
|
||||||
"mount -t %s %s%s %s" % (
|
|
||||||
'nfs',
|
|
||||||
host,
|
|
||||||
path,
|
|
||||||
self.services["paths"]["mount_dir"]
|
|
||||||
),
|
|
||||||
"ls %s" % (
|
|
||||||
os.path.join(self.services["paths"]["mount_dir"], snapshotPath)
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
||||||
for c in cmds:
|
|
||||||
self.debug("command: %s" % c)
|
|
||||||
result = ssh_client.execute(c)
|
|
||||||
self.debug("Result: %s" % result)
|
|
||||||
|
|
||||||
snapshots.extend(result)
|
|
||||||
# Unmount the Sec Storage
|
|
||||||
cmds = [
|
|
||||||
"cd",
|
|
||||||
"umount %s" % (self.services["paths"]["mount_dir"]),
|
|
||||||
]
|
|
||||||
for c in cmds:
|
|
||||||
ssh_client.execute(c)
|
|
||||||
except Exception as e:
|
|
||||||
self.fail("SSH failed for management server: %s - %s" %
|
|
||||||
(self.config.mgtSvr[0].mgtSvrIp, e))
|
|
||||||
return snapshots.count(snapshot_id) == 1
|
|
||||||
|
|
||||||
@attr(speed = "slow")
|
@attr(speed = "slow")
|
||||||
@attr(tags = ["advanced", "advancedns"])
|
@attr(tags = ["advanced", "advancedns"])
|
||||||
def test_04_snapshot_limit(self):
|
def test_04_snapshot_limit(self):
|
||||||
@ -383,5 +308,6 @@ class TestSnapshotLimit(cloudstackTestCase):
|
|||||||
|
|
||||||
qresult = qresultset[0]
|
qresult = qresultset[0]
|
||||||
snapshot_id = qresult[0]
|
snapshot_id = qresult[0]
|
||||||
self.is_snapshot_on_nfs(snapshot_id)
|
self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config.mgtSvr,
|
||||||
|
self.services["paths"], self.zone.id, snapshot_id))
|
||||||
return
|
return
|
||||||
|
|||||||
@ -24,6 +24,7 @@ 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.remoteSSHClient import remoteSSHClient
|
||||||
|
from marvin.integration.lib.utils import is_snapshot_on_nfs
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
@ -174,16 +175,7 @@ class TestSnapshots(cloudstackTestCase):
|
|||||||
serviceofferingid=cls.service_offering.id,
|
serviceofferingid=cls.service_offering.id,
|
||||||
mode=cls.services["mode"]
|
mode=cls.services["mode"]
|
||||||
)
|
)
|
||||||
cls.virtual_machine_without_disk = \
|
|
||||||
VirtualMachine.create(
|
|
||||||
cls.api_client,
|
|
||||||
cls.services["server_without_disk"],
|
|
||||||
templateid=cls.template.id,
|
|
||||||
accountid=cls.account.name,
|
|
||||||
domainid=cls.account.domainid,
|
|
||||||
serviceofferingid=cls.service_offering.id,
|
|
||||||
mode=cls.services["mode"]
|
|
||||||
)
|
|
||||||
cls._cleanup = [
|
cls._cleanup = [
|
||||||
cls.service_offering,
|
cls.service_offering,
|
||||||
cls.disk_offering,
|
cls.disk_offering,
|
||||||
@ -191,82 +183,6 @@ class TestSnapshots(cloudstackTestCase):
|
|||||||
]
|
]
|
||||||
return
|
return
|
||||||
|
|
||||||
def is_snapshot_on_nfs(self, snapshot_id):
|
|
||||||
"""
|
|
||||||
Checks whether a snapshot with id (not UUID) `snapshot_id` is present on the nfs storage
|
|
||||||
|
|
||||||
@param snapshot_id: id of the snapshot (not uuid)
|
|
||||||
@return: True if snapshot is found, False otherwise
|
|
||||||
"""
|
|
||||||
secondaryStores = ImageStore.list(self.apiclient, zoneid=self.zone.id)
|
|
||||||
self.assertTrue(isinstance(secondaryStores, list), "Not a valid response for listImageStores")
|
|
||||||
self.assertNotEqual(len(secondaryStores), 0, "No image stores found in zone %s" % self.zone.id)
|
|
||||||
secondaryStore = secondaryStores[0]
|
|
||||||
if str(secondaryStore.providername).lower() != "nfs":
|
|
||||||
self.skipTest("TODO: %s test works only against nfs secondary storage" % self._testMethodName)
|
|
||||||
|
|
||||||
qresultset = self.dbclient.execute(
|
|
||||||
"select install_path from snapshot_store_ref where snapshot_id='%s' and store_role='Image';" % 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
|
|
||||||
)
|
|
||||||
snapshotPath = qresultset[0][0]
|
|
||||||
nfsurl = secondaryStore.url
|
|
||||||
# parse_url = ['nfs:', '', '192.168.100.21', 'export', 'test']
|
|
||||||
from urllib2 import urlparse
|
|
||||||
parse_url = urlparse.urlsplit(nfsurl, scheme='nfs')
|
|
||||||
host, path = parse_url.netloc, parse_url.path
|
|
||||||
# Sleep to ensure that snapshot is reflected in sec storage
|
|
||||||
time.sleep(self.services["sleep"])
|
|
||||||
snapshots = []
|
|
||||||
try:
|
|
||||||
# Login to Secondary storage VM to check snapshot present on sec disk
|
|
||||||
ssh_client = remoteSSHClient(
|
|
||||||
self.config.mgtSvr[0].mgtSvrIp,
|
|
||||||
22,
|
|
||||||
self.config.mgtSvr[0].user,
|
|
||||||
self.config.mgtSvr[0].passwd,
|
|
||||||
)
|
|
||||||
|
|
||||||
cmds = [
|
|
||||||
"mkdir -p %s" % self.services["paths"]["mount_dir"],
|
|
||||||
"mount -t %s %s%s %s" % (
|
|
||||||
'nfs',
|
|
||||||
host,
|
|
||||||
path,
|
|
||||||
self.services["paths"]["mount_dir"]
|
|
||||||
),
|
|
||||||
"ls %s" % (
|
|
||||||
os.path.join(self.services["paths"]["mount_dir"], snapshotPath)
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
||||||
for c in cmds:
|
|
||||||
self.debug("command: %s" % c)
|
|
||||||
result = ssh_client.execute(c)
|
|
||||||
self.debug("Result: %s" % result)
|
|
||||||
|
|
||||||
snapshots.extend(result)
|
|
||||||
# Unmount the Sec Storage
|
|
||||||
cmds = [
|
|
||||||
"cd",
|
|
||||||
"umount %s" % (self.services["paths"]["mount_dir"]),
|
|
||||||
]
|
|
||||||
for c in cmds:
|
|
||||||
ssh_client.execute(c)
|
|
||||||
except Exception as e:
|
|
||||||
self.fail("SSH failed for management server: %s - %s" %
|
|
||||||
(self.config.mgtSvr[0].mgtSvrIp, e))
|
|
||||||
return snapshots.count(snapshot_id) == 1
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
try:
|
try:
|
||||||
@ -352,7 +268,8 @@ class TestSnapshots(cloudstackTestCase):
|
|||||||
'NULL',
|
'NULL',
|
||||||
"Check if backup_snap_id is not null"
|
"Check if backup_snap_id is not null"
|
||||||
)
|
)
|
||||||
self.assertTrue(self.is_snapshot_on_nfs(snapshot_uuid))
|
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")
|
||||||
@ -620,7 +537,8 @@ class TestSnapshots(cloudstackTestCase):
|
|||||||
|
|
||||||
qresult = qresultset[0]
|
qresult = qresultset[0]
|
||||||
snapshotid = qresult[0]
|
snapshotid = qresult[0]
|
||||||
self.assertFalse(self.is_snapshot_on_nfs(snapshotid))
|
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")
|
||||||
@ -771,7 +689,7 @@ class TestSnapshots(cloudstackTestCase):
|
|||||||
cmds = [
|
cmds = [
|
||||||
"mkdir -p %s" % self.services["paths"]["mount_dir"],
|
"mkdir -p %s" % self.services["paths"]["mount_dir"],
|
||||||
"mount %s1 %s" % (
|
"mount %s1 %s" % (
|
||||||
self.services["rootdisk"],
|
self.services["volume"]["diskdevice"],
|
||||||
self.services["paths"]["mount_dir"]
|
self.services["paths"]["mount_dir"]
|
||||||
),
|
),
|
||||||
"mkdir -p %s/%s/{%s,%s} " % (
|
"mkdir -p %s/%s/{%s,%s} " % (
|
||||||
@ -885,7 +803,7 @@ class TestSnapshots(cloudstackTestCase):
|
|||||||
cmds = [
|
cmds = [
|
||||||
"mkdir -p %s" % self.services["paths"]["mount_dir"],
|
"mkdir -p %s" % self.services["paths"]["mount_dir"],
|
||||||
"mount %s1 %s" % (
|
"mount %s1 %s" % (
|
||||||
self.services["rootdisk"],
|
self.services["volume"]["diskdevice"],
|
||||||
self.services["paths"]["mount_dir"]
|
self.services["paths"]["mount_dir"]
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
@ -998,80 +916,6 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase):
|
|||||||
raise Exception("Warning: Exception during cleanup : %s" % e)
|
raise Exception("Warning: Exception during cleanup : %s" % e)
|
||||||
return
|
return
|
||||||
|
|
||||||
def is_snapshot_on_nfs(self, snapshot_id):
|
|
||||||
"""
|
|
||||||
Checks whether a snapshot with id (not UUID) `snapshot_id` is present on the nfs storage
|
|
||||||
|
|
||||||
@param snapshot_id: id of the snapshot (not uuid)
|
|
||||||
@return: True if snapshot is found, False otherwise
|
|
||||||
"""
|
|
||||||
secondaryStores = ImageStore.list(self.apiclient, zoneid=self.zone.id)
|
|
||||||
self.assertTrue(isinstance(secondaryStores, list), "Not a valid response for listImageStores")
|
|
||||||
self.assertNotEqual(len(secondaryStores), 0, "No image stores found in zone %s" % self.zone.id)
|
|
||||||
secondaryStore = secondaryStores[0]
|
|
||||||
if str(secondaryStore.providername).lower() != "nfs":
|
|
||||||
self.skipTest("TODO: %s test works only against nfs secondary storage" % self._testMethodName)
|
|
||||||
|
|
||||||
qresultset = self.dbclient.execute(
|
|
||||||
"select install_path from snapshot_store_ref where snapshot_id='%s' and store_role='Image';" % 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
|
|
||||||
)
|
|
||||||
snapshotPath = qresultset[0][0]
|
|
||||||
nfsurl = secondaryStore.url
|
|
||||||
# parse_url = ['nfs:', '', '192.168.100.21', 'export', 'test']
|
|
||||||
from urllib2 import urlparse
|
|
||||||
parse_url = urlparse.urlsplit(nfsurl, scheme='nfs')
|
|
||||||
host, path = parse_url.netloc, parse_url.path
|
|
||||||
snapshots = []
|
|
||||||
try:
|
|
||||||
# Login to Secondary storage VM to check snapshot present on sec disk
|
|
||||||
ssh_client = remoteSSHClient(
|
|
||||||
self.config.mgtSvr[0].mgtSvrIp,
|
|
||||||
22,
|
|
||||||
self.config.mgtSvr[0].user,
|
|
||||||
self.config.mgtSvr[0].passwd,
|
|
||||||
)
|
|
||||||
|
|
||||||
cmds = [
|
|
||||||
"mkdir -p %s" % self.services["paths"]["mount_dir"],
|
|
||||||
"mount -t %s %s%s %s" % (
|
|
||||||
'nfs',
|
|
||||||
host,
|
|
||||||
path,
|
|
||||||
self.services["paths"]["mount_dir"]
|
|
||||||
),
|
|
||||||
"ls %s" % (
|
|
||||||
os.path.join(self.services["paths"]["mount_dir"], snapshotPath)
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
||||||
for c in cmds:
|
|
||||||
self.debug("command: %s" % c)
|
|
||||||
result = ssh_client.execute(c)
|
|
||||||
self.debug("Result: %s" % result)
|
|
||||||
|
|
||||||
snapshots.extend(result)
|
|
||||||
# Unmount the Sec Storage
|
|
||||||
cmds = [
|
|
||||||
"cd",
|
|
||||||
"umount %s" % (self.services["paths"]["mount_dir"]),
|
|
||||||
]
|
|
||||||
for c in cmds:
|
|
||||||
ssh_client.execute(c)
|
|
||||||
except Exception as e:
|
|
||||||
self.fail("SSH failed for management server: %s - %s" %
|
|
||||||
(self.services["mgmt_server"]["ipaddress"], e))
|
|
||||||
return snapshots.count(snapshot_id) == 1
|
|
||||||
|
|
||||||
@attr(speed = "slow")
|
@attr(speed = "slow")
|
||||||
@attr(tags = ["advanced", "advancedns"])
|
@attr(tags = ["advanced", "advancedns"])
|
||||||
def test_01_createVM_snapshotTemplate(self):
|
def test_01_createVM_snapshotTemplate(self):
|
||||||
@ -1217,7 +1061,8 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase):
|
|||||||
'Running',
|
'Running',
|
||||||
"Check list VM response for Running state"
|
"Check list VM response for Running state"
|
||||||
)
|
)
|
||||||
self.assertTrue(self.is_snapshot_on_nfs(snapshot_uuid))
|
self.assertTrue(is_snapshot_on_nfs(self.apiclient, self.dbclient, self.config.mgtSvr,
|
||||||
|
self.services["paths"], self.zone.id, snapshot_uuid))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -218,4 +218,80 @@ def xsplit(txt, seps):
|
|||||||
default_sep = seps[0]
|
default_sep = seps[0]
|
||||||
for sep in seps[1:]: # we skip seps[0] because that's the default separator
|
for sep in seps[1:]: # we skip seps[0] because that's the default separator
|
||||||
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,
|
||||||
|
dir_paths, zone_id, snapshot_id):
|
||||||
|
"""
|
||||||
|
Checks whether a snapshot with id (not UUID) `snapshot_id` is present on the nfs storage
|
||||||
|
|
||||||
|
@param snapshot_id: id of the snapshot (not uuid)
|
||||||
|
@return: True if snapshot is found, False otherwise
|
||||||
|
"""
|
||||||
|
|
||||||
|
from base import ImageStore
|
||||||
|
|
||||||
|
secondaryStores = ImageStore.list(api_client, zoneid=zone_id)
|
||||||
|
|
||||||
|
assert isinstance(secondaryStores, list), "Not a valid response for listImageStores"
|
||||||
|
assert len(secondaryStores) != 0, "No image stores found in zone %s" % zone_id
|
||||||
|
|
||||||
|
secondaryStore = secondaryStores[0]
|
||||||
|
|
||||||
|
if str(secondaryStore.providername).lower() != "nfs":
|
||||||
|
raise Exception("Test works only against nfs secondary storage")
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
assert len(qresultset) != 0, "No such snapshot %s found in the cloudstack db" % snapshot_id
|
||||||
|
|
||||||
|
snapshotPath = qresultset[0][0]
|
||||||
|
|
||||||
|
nfsurl = secondaryStore.url
|
||||||
|
# parse_url = ['nfs:', '', '192.168.100.21', 'export', 'test']
|
||||||
|
from urllib2 import urlparse
|
||||||
|
parse_url = urlparse.urlsplit(nfsurl, scheme='nfs')
|
||||||
|
host, path = parse_url.netloc, parse_url.path
|
||||||
|
snapshots = []
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Login to Secondary storage VM to check snapshot present on sec disk
|
||||||
|
ssh_client = remoteSSHClient(
|
||||||
|
config_mgtSvr[0].mgtSvrIp,
|
||||||
|
22,
|
||||||
|
config_mgtSvr[0].user,
|
||||||
|
config_mgtSvr[0].passwd,
|
||||||
|
)
|
||||||
|
import os
|
||||||
|
|
||||||
|
cmds = [
|
||||||
|
"mkdir -p %s" % dir_paths["mount_dir"],
|
||||||
|
"mount -t %s %s%s %s" % (
|
||||||
|
'nfs',
|
||||||
|
host,
|
||||||
|
path,
|
||||||
|
dir_paths["mount_dir"]
|
||||||
|
),
|
||||||
|
"test -f %s && echo 'snapshot exists'" % (
|
||||||
|
os.path.join(dir_paths["mount_dir"], snapshotPath)
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
for c in cmds:
|
||||||
|
result = ssh_client.execute(c)
|
||||||
|
|
||||||
|
# Unmount the Sec Storage
|
||||||
|
cmds = [
|
||||||
|
"cd",
|
||||||
|
"umount %s" % (dir_paths["mount_dir"]),
|
||||||
|
]
|
||||||
|
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))
|
||||||
|
return 'snapshot exists' in result
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user