mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
fix snapshots tests
Signed-off-by: Prasanna Santhanam <tsp@apache.org> (cherry picked from commit baf040012430213db557d5ad527b27a954d9a33e)
This commit is contained in:
parent
e55844c364
commit
37b8775203
@ -87,12 +87,6 @@ class Services:
|
||||
"publicport": 22,
|
||||
"protocol": 'TCP',
|
||||
},
|
||||
"mgmt_server": {
|
||||
"ipaddress": '192.168.100.21',
|
||||
"username": "root",
|
||||
"password": "password",
|
||||
"port": 22,
|
||||
},
|
||||
"recurring_snapshot": {
|
||||
"intervaltype": 'HOURLY',
|
||||
# Frequency of snapshots
|
||||
@ -196,6 +190,82 @@ class TestSnapshots(cloudstackTestCase):
|
||||
]
|
||||
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" % (
|
||||
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 = [
|
||||
"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))
|
||||
res = str(snapshots)
|
||||
return res.count(snapshot_id) == 1
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
try:
|
||||
@ -263,12 +333,8 @@ class TestSnapshots(cloudstackTestCase):
|
||||
snapshot.id,
|
||||
"Check resource id in list resources call"
|
||||
)
|
||||
self.debug(
|
||||
"select backup_snap_id, account_id, volume_id from snapshots where uuid = '%s';" \
|
||||
% str(snapshot.id)
|
||||
)
|
||||
qresultset = self.dbclient.execute(
|
||||
"select backup_snap_id, account_id, volume_id from snapshots where uuid = '%s';" \
|
||||
"select id from snapshots where uuid = '%s';" \
|
||||
% str(snapshot.id)
|
||||
)
|
||||
self.assertNotEqual(
|
||||
@ -279,86 +345,13 @@ class TestSnapshots(cloudstackTestCase):
|
||||
|
||||
qresult = qresultset[0]
|
||||
snapshot_uuid = qresult[0] # backup_snap_id = snapshot UUID
|
||||
account_id = qresult[1]
|
||||
volume_id = qresult[2]
|
||||
|
||||
self.assertNotEqual(
|
||||
str(snapshot_uuid),
|
||||
'NULL',
|
||||
"Check if backup_snap_id is not null"
|
||||
)
|
||||
|
||||
# Get the Secondary Storage details from list Hosts
|
||||
hosts = list_hosts(
|
||||
self.apiclient,
|
||||
type='SecondaryStorage',
|
||||
zoneid=self.zone.id
|
||||
)
|
||||
self.assertEqual(
|
||||
isinstance(hosts, list),
|
||||
True,
|
||||
"Check list response returns a valid list"
|
||||
)
|
||||
uuids = []
|
||||
for host in hosts:
|
||||
# hosts[0].name = "nfs://192.168.100.21/export"
|
||||
parse_url = (host.name).split('/')
|
||||
# parse_url = ['nfs:', '', '192.168.100.21', 'export']
|
||||
|
||||
# Split IP address and export path from name
|
||||
sec_storage_ip = parse_url[2]
|
||||
# Sec Storage IP: 192.168.100.21
|
||||
|
||||
export_path = '/'.join(parse_url[3:])
|
||||
# Export path: export
|
||||
|
||||
try:
|
||||
# Login to VM to check snapshot present on sec disk
|
||||
ssh_client = self.virtual_machine_with_disk.get_ssh_client()
|
||||
|
||||
cmds = [
|
||||
"mkdir -p %s" % self.services["paths"]["mount_dir"],
|
||||
"mount %s/%s %s" % (
|
||||
sec_storage_ip,
|
||||
export_path,
|
||||
self.services["paths"]["mount_dir"]
|
||||
),
|
||||
"ls %s/snapshots/%s/%s" % (
|
||||
self.services["paths"]["mount_dir"],
|
||||
account_id,
|
||||
volume_id
|
||||
),
|
||||
]
|
||||
for c in cmds:
|
||||
self.debug(c)
|
||||
result = ssh_client.execute(c)
|
||||
self.debug(result)
|
||||
|
||||
except Exception as e:
|
||||
self.fail("SSH failed for VM with IP: %s" %
|
||||
self.virtual_machine_with_disk.ipaddress)
|
||||
|
||||
uuids.append(result)
|
||||
# Unmount the Sec Storage
|
||||
cmds = [
|
||||
"umount %s" % (self.services["paths"]["mount_dir"]),
|
||||
]
|
||||
try:
|
||||
for c in cmds:
|
||||
self.debug(c)
|
||||
ssh_client.execute(c)
|
||||
|
||||
except Exception as e:
|
||||
self.fail("SSH failed for VM with IP: %s" %
|
||||
self.virtual_machine_with_disk.ipaddress)
|
||||
|
||||
res = str(uuids)
|
||||
# Check snapshot UUID in secondary storage and database
|
||||
self.assertEqual(
|
||||
res.count(snapshot_uuid),
|
||||
1,
|
||||
"Check snapshot UUID in secondary storage and database"
|
||||
)
|
||||
self.assertTrue(self.is_snapshot_on_nfs(snapshot_uuid))
|
||||
return
|
||||
|
||||
@attr(speed = "slow")
|
||||
@ -583,6 +576,7 @@ class TestSnapshots(cloudstackTestCase):
|
||||
#1. Snapshot the Volume
|
||||
#2. Delete the snapshot
|
||||
#3. Verify snapshot is removed by calling List Snapshots API
|
||||
#4. Verify snapshot was removed from image store
|
||||
|
||||
volumes = list_volumes(
|
||||
self.apiclient,
|
||||
@ -613,6 +607,19 @@ class TestSnapshots(cloudstackTestCase):
|
||||
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(self.is_snapshot_on_nfs(snapshotid))
|
||||
return
|
||||
|
||||
@attr(speed = "slow")
|
||||
@ -628,9 +635,7 @@ class TestSnapshots(cloudstackTestCase):
|
||||
# 3. perform the snapshot on the detached volume
|
||||
# 4. listvolumes with VM id shouldn't show the detached volume
|
||||
# 5. listSnapshots should list the snapshot that was created
|
||||
# 6. verify that secondary storage NFS share contains the reqd volume
|
||||
# under /secondary/snapshots/$accountid/$volumeid/$snapshot_uuid
|
||||
# 7. verify backup_snap_id was non null in the `snapshots` table
|
||||
# 6. verify backup_snap_id was non null in the `snapshots` table
|
||||
|
||||
volumes = list_volumes(
|
||||
self.apiclient,
|
||||
@ -724,9 +729,8 @@ class TestSnapshots(cloudstackTestCase):
|
||||
self.fail("SSH failed for VM with IP: %s - %s" %
|
||||
(self.virtual_machine.ipaddress, e))
|
||||
|
||||
# Fetch values from database
|
||||
qresultset = self.dbclient.execute(
|
||||
"select backup_snap_id, account_id, volume_id from snapshots where uuid = '%s';" \
|
||||
"select id from snapshots where uuid = '%s';" \
|
||||
% snapshot.id
|
||||
)
|
||||
self.assertNotEqual(
|
||||
@ -736,93 +740,11 @@ class TestSnapshots(cloudstackTestCase):
|
||||
)
|
||||
|
||||
qresult = qresultset[0]
|
||||
snapshot_uuid = qresult[0] # backup_snap_id = snapshot UUID
|
||||
account_id = qresult[1]
|
||||
volume_id = qresult[2]
|
||||
|
||||
self.assertNotEqual(
|
||||
str(qresult[0]),
|
||||
'NULL',
|
||||
"Check if backup_snap_id is not null"
|
||||
)
|
||||
|
||||
# Get the Secondary Storage details from list Hosts
|
||||
hosts = list_hosts(
|
||||
self.apiclient,
|
||||
type='SecondaryStorage',
|
||||
zoneid=self.zone.id
|
||||
)
|
||||
self.assertEqual(
|
||||
isinstance(hosts, list),
|
||||
True,
|
||||
"Check list response returns a valid list"
|
||||
)
|
||||
uuids = []
|
||||
for host in hosts:
|
||||
# hosts[0].name = "nfs://192.168.100.21/export/test"
|
||||
parse_url = (host.name).split('/')
|
||||
# parse_url = ['nfs:', '', '192.168.100.21', 'export', 'test']
|
||||
|
||||
# Stripping end ':' from storage type
|
||||
storage_type = parse_url[0][:-1]
|
||||
|
||||
# Split IP address and export path from name
|
||||
sec_storage_ip = parse_url[2]
|
||||
# Sec Storage IP: 192.168.100.21
|
||||
|
||||
if sec_storage_ip[-1] != ":":
|
||||
sec_storage_ip = sec_storage_ip + ":"
|
||||
|
||||
export_path = '/'.join(parse_url[3:])
|
||||
# Export path: export/test
|
||||
|
||||
# Sleep to ensure that snapshot is reflected in sec storage
|
||||
time.sleep(self.services["sleep"])
|
||||
try:
|
||||
# Login to Management server to check snapshot present on
|
||||
# sec disk
|
||||
ssh_client = remoteSSHClient(
|
||||
self.services["mgmt_server"]["ipaddress"],
|
||||
self.services["mgmt_server"]["port"],
|
||||
self.services["mgmt_server"]["username"],
|
||||
self.services["mgmt_server"]["password"],
|
||||
)
|
||||
|
||||
cmds = [
|
||||
"mkdir -p %s" % self.services["mount_dir"],
|
||||
"mount -t %s %s/%s %s" % (
|
||||
storage_type,
|
||||
sec_storage_ip,
|
||||
export_path,
|
||||
self.services["mount_dir"]
|
||||
),
|
||||
"ls %s/snapshots/%s/%s" % (
|
||||
self.services["mount_dir"],
|
||||
account_id,
|
||||
volume_id
|
||||
),
|
||||
]
|
||||
|
||||
for c in cmds:
|
||||
result = ssh_client.execute(c)
|
||||
|
||||
uuids.append(result)
|
||||
# Unmount the Sec Storage
|
||||
cmds = [
|
||||
"umount %s" % (self.services["mount_dir"]),
|
||||
]
|
||||
for c in cmds:
|
||||
result = ssh_client.execute(c)
|
||||
except Exception as e:
|
||||
self.fail("SSH failed for management server: %s - %s" %
|
||||
(self.services["mgmt_server"]["ipaddress"], e))
|
||||
|
||||
res = str(uuids)
|
||||
self.assertEqual(
|
||||
res.count(snapshot_uuid),
|
||||
1,
|
||||
"Check snapshot UUID in secondary storage and database"
|
||||
)
|
||||
return
|
||||
|
||||
@attr(speed = "slow")
|
||||
@ -1075,6 +997,80 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase):
|
||||
raise Exception("Warning: Exception during cleanup : %s" % e)
|
||||
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" % (
|
||||
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 = [
|
||||
"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))
|
||||
res = str(snapshots)
|
||||
return res.count(snapshot_id) == 1
|
||||
|
||||
@attr(speed = "slow")
|
||||
@attr(tags = ["advanced", "advancedns"])
|
||||
def test_01_createVM_snapshotTemplate(self):
|
||||
@ -1142,7 +1138,7 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase):
|
||||
% snapshot.id)
|
||||
# Verify backup_snap_id is not NULL
|
||||
qresultset = self.dbclient.execute(
|
||||
"select backup_snap_id, account_id, volume_id from snapshots where uuid = '%s';" \
|
||||
"select id from snapshots where uuid = '%s';" \
|
||||
% snapshot.id
|
||||
)
|
||||
self.assertNotEqual(
|
||||
@ -1152,10 +1148,7 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase):
|
||||
)
|
||||
|
||||
qresult = qresultset[0]
|
||||
|
||||
snapshot_uuid = qresult[0] # backup_snap_id = snapshot UUID
|
||||
account_id = qresult[1]
|
||||
volume_id = qresult[2]
|
||||
snapshot_uuid = qresult[0]
|
||||
|
||||
# Generate template from the snapshot
|
||||
template = Template.create_from_snapshot(
|
||||
@ -1223,89 +1216,7 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase):
|
||||
'Running',
|
||||
"Check list VM response for Running state"
|
||||
)
|
||||
# Get the Secondary Storage details from list Hosts
|
||||
hosts = list_hosts(
|
||||
self.apiclient,
|
||||
type='SecondaryStorage',
|
||||
zoneid=self.zone.id
|
||||
)
|
||||
self.assertEqual(
|
||||
isinstance(hosts, list),
|
||||
True,
|
||||
"Check list response returns a valid list"
|
||||
)
|
||||
uuids = []
|
||||
for host in hosts:
|
||||
# hosts[0].name = "nfs://192.168.100.21/export/test"
|
||||
parse_url = (host.name).split('/')
|
||||
# parse_url = ['nfs:', '', '192.168.100.21', 'export', 'test']
|
||||
|
||||
# Stripping end ':' from storage type
|
||||
storage_type = parse_url[0][:-1]
|
||||
# Split IP address and export path from name
|
||||
sec_storage_ip = parse_url[2]
|
||||
# Sec Storage IP: 192.168.100.21
|
||||
if sec_storage_ip[-1] != ":":
|
||||
sec_storage_ip = sec_storage_ip + ":"
|
||||
|
||||
export_path = '/'.join(parse_url[3:])
|
||||
# Export path: export/test
|
||||
|
||||
# Sleep to ensure that snapshot is reflected in sec storage
|
||||
time.sleep(self.services["sleep"])
|
||||
try:
|
||||
# Login to VM to check snapshot present on sec disk
|
||||
ssh_client = remoteSSHClient(
|
||||
self.services["mgmt_server"]["ipaddress"],
|
||||
self.services["mgmt_server"]["port"],
|
||||
self.services["mgmt_server"]["username"],
|
||||
self.services["mgmt_server"]["password"],
|
||||
)
|
||||
|
||||
cmds = [
|
||||
"mkdir -p %s" % self.services["paths"]["mount_dir"],
|
||||
"mount -t %s %s/%s %s" % (
|
||||
storage_type,
|
||||
sec_storage_ip,
|
||||
export_path,
|
||||
self.services["paths"]["mount_dir"]
|
||||
),
|
||||
"ls %s/snapshots/%s/%s" % (
|
||||
self.services["paths"]["mount_dir"],
|
||||
account_id,
|
||||
volume_id
|
||||
),
|
||||
]
|
||||
for c in cmds:
|
||||
self.debug("command: %s" % c)
|
||||
result = ssh_client.execute(c)
|
||||
self.debug("Result: %s" % result)
|
||||
|
||||
except Exception as e:
|
||||
self.fail("SSH failed for Management server: %s - %s" %
|
||||
(self.services["mgmt_server"]["ipaddress"], e))
|
||||
uuids.append(result)
|
||||
# Unmount the Sec Storage
|
||||
cmds = [
|
||||
"umount %s" % (self.services["mount_dir"]),
|
||||
]
|
||||
try:
|
||||
for c in cmds:
|
||||
self.debug("command: %s" % c)
|
||||
result = ssh_client.execute(c)
|
||||
self.debug("Result: %s" % result)
|
||||
|
||||
except Exception as e:
|
||||
self.fail("SSH failed for Management server: %s - %s" %
|
||||
(self.services["mgmt_server"]["ipaddress"], e))
|
||||
|
||||
res = str(uuids)
|
||||
self.assertEqual(
|
||||
res.count(snapshot_uuid),
|
||||
1,
|
||||
"Check snapshot UUID in secondary storage and database"
|
||||
)
|
||||
|
||||
self.assertTrue(self.is_snapshot_on_nfs(snapshot_uuid))
|
||||
return
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user