[Ceilometer] Improve OSTF for Cinder notifications

- Added more volume and snapshot notifications
- Added extra checks for volume and snapshot statuses
- Added methods for resource deletion

Partially implements: blueprint ceilometer-ostf-notification-tests
Closes-bug: #1442241

Change-Id: Id31be91f64c5cbd88c6afc5d70890b9699dcc11c
This commit is contained in:
vgusev 2015-09-29 15:42:31 +03:00 committed by tatyana-leontovich
parent 2643b03847
commit 191f77515d
4 changed files with 152 additions and 69 deletions

View File

@ -60,8 +60,18 @@ class CeilometerBaseTest(fuel_health.nmanager.PlatformServicesBaseClass):
'router.update']
cls.neutron_floatingip_notifications = ['ip.floating.create',
'ip.floating.update']
cls.volume_notifications = ['volume', 'volume.size']
cls.snapshot_notifications = ['snapshot', 'snapshot.size']
cls.volume_notifications = [
'volume', 'volume.size', 'volume.create.start',
'volume.create.end', 'volume.delete.start',
'volume.delete.end', 'volume.update.start',
'volume.update.end', 'volume.resize.start',
'volume.resize.end', 'volume.attach.start',
'volume.attach.end', 'volume.detach.start',
'volume.detach.end']
cls.snapshot_notifications = [
'snapshot', 'snapshot.size', 'snapshot.create.start',
'snapshot.create.end', 'snapshot.delete.start',
'snapshot.delete.end']
cls.glance_notifications = ['image', 'image.size', 'image.update',
'image.upload', 'image.download',
'image.serve', 'image.delete']
@ -103,11 +113,11 @@ class CeilometerBaseTest(fuel_health.nmanager.PlatformServicesBaseClass):
def create_server(self, name, **kwargs):
server = self._create_server(self.compute_client, name, **kwargs)
self.addCleanup(fuel_health.test.call_until_true,
self.is_resource_deleted, 300, 3,
self.compute_client.servers, server.id)
self.addCleanup(self.compute_client.servers.delete, server.id)
self.addCleanup(
self.delete_resource,
delete_method=lambda: self.compute_client.servers.delete(
server.id),
get_method=lambda: self.compute_client.servers.get(server.id))
return server
def create_alarm(self, **kwargs):
@ -129,8 +139,8 @@ class CeilometerBaseTest(fuel_health.nmanager.PlatformServicesBaseClass):
if not alarm_state_resp == state:
self.fail('State was not setted')
def wait_for_instance_status(self, server, status):
self.status_timeout(self.compute_client.servers, server.id, status)
def wait_for_resource_status(self, resource_client, resource_id, status):
self.status_timeout(resource_client, resource_id, status)
def wait_for_alarm_status(self, alarm_id, status=None):
"""The method is a customization of test.status_timeout()."""
@ -334,11 +344,11 @@ class CeilometerBaseTest(fuel_health.nmanager.PlatformServicesBaseClass):
# Create Sahara cluster
cluster = self.sahara_client.clusters.create(**cluster_json)
self.objects_for_delete.append(
(self.sahara_client.clusters.delete, cluster.id))
self.addCleanup(fuel_health.test.call_until_true,
self.is_resource_deleted, 300, 3,
self.sahara_client.clusters, cluster.id)
self.addCleanup(
self.delete_resource,
delete_method=lambda: self.sahara_client.clusters.delete(
cluster.id),
get_method=lambda: self.sahara_client.clusters.get(cluster.id))
# Wait for change cluster state for metric: cluster.update
def check_status():
@ -364,6 +374,52 @@ class CeilometerBaseTest(fuel_health.nmanager.PlatformServicesBaseClass):
self.glance_client.images.delete(image.id)
return image
def volume_helper(self, instance):
device = '/dev/vdb'
# Create a volume
volume = self.volume_client.volumes.create(
name=rand_name('ost1_test-ceilo-volume'), size=1)
self.addCleanup(
self.delete_resource,
delete_method=lambda: self.volume_client.volumes.delete(volume),
get_method=lambda: self.volume_client.volumes.get(volume.id))
# Wait for "Available" status of the volume
self.wait_for_resource_status(
self.volume_client.volumes, volume.id, 'available')
# Resize the volume
self.volume_client.volumes.extend(volume, 2)
self.wait_for_resource_status(
self.volume_client.volumes, volume.id, 'available')
# Create a volume snapshot
snapshot = self.volume_client.volume_snapshots.create(
volume.id, name=rand_name('ost1_test-'))
self.addCleanup(
self.delete_resource,
delete_method=lambda: self.volume_client.volume_snapshots.delete(
snapshot),
get_method=lambda: self.volume_client.volume_snapshots.get(
snapshot.id))
# Wait for "Available" status of the snapshot
self.wait_for_resource_status(
self.volume_client.volume_snapshots, snapshot.id, 'available')
# Update the volume name
self.volume_client.volumes.update(volume, name="ost1_test-update")
# Attach the volume to the instance
self.volume_client.volumes.attach(volume.id, instance.id, device)
# Detach the volume from the instance
self.volume_client.volumes.detach(volume.id)
# Delete the volume snapshot
self.delete_resource(
delete_method=lambda: self.volume_client.volume_snapshots.delete(
snapshot),
get_method=lambda: self.volume_client.volume_snapshots.get(
snapshot.id))
# Delete the volume
self.delete_resource(
delete_method=lambda: self.volume_client.volumes.delete(volume),
get_method=lambda: self.volume_client.volumes.get(volume.id))
return volume, snapshot
@staticmethod
def cleanup_resources(object_list):
for method, resource in object_list:

View File

@ -1061,7 +1061,7 @@ class PlatformServicesBaseClass(NovaNetworkScenarioTest):
'not found.'.format(tag_plugin, tag_version))
# Method for checking whether or not resource is deleted.
def is_resource_deleted(self, resource_client, resource_id):
def is_resource_deleted(self, get_method):
"""This method checks whether or not the resource is deleted.
The API request is wrapped in the try/except block to correctly handle
@ -1070,17 +1070,43 @@ class PlatformServicesBaseClass(NovaNetworkScenarioTest):
"""
try:
resource_client.get(resource_id)
get_method()
except Exception as exc:
exc_msg = exc.message.lower()
if ('not found' in exc_msg) or ('could not be found' in exc_msg):
LOG.debug('Resource "{0}" is deleted.'.format(resource_id))
return True
self.fail(exc.message)
return False
# Methods for deleting resources.
def delete_resource(self, delete_method, get_method=None, timeout=300,
sleep=5):
"""This method deletes the resource by its ID and checks whether
the resource is really deleted or not.
"""
try:
delete_method()
except Exception as exc:
LOG.warn(exc.message)
return
if get_method:
self._wait_for_deletion(get_method, timeout, sleep)
def _wait_for_deletion(self, get_method, timeout, sleep):
"""This method waits for the resource deletion."""
start = time.time()
while time.time() - start < timeout:
if self.is_resource_deleted(get_method):
return
time.sleep(sleep)
self.fail('Request timed out. '
'Timed out while waiting for one of the test resources '
'to delete within {0} seconds.'.format(timeout))
class SanityChecksTest(OfficialClientTest):
"""Base class for openstack sanity tests."""

View File

@ -92,8 +92,13 @@ class SaharaTestsManager(nmanager.PlatformServicesBaseClass):
del node_group['floating_ip_pool']
cl_template = self.sahara_client.cluster_templates.create(
name, plugin, hadoop_version, node_groups=node_groups, **kwargs)
self.addCleanup(self.delete_resource,
self.sahara_client.cluster_templates, cl_template.id)
self.addCleanup(
self.delete_resource,
delete_method=lambda: self.sahara_client.cluster_templates.delete(
cl_template.id),
get_method=lambda: self.sahara_client.cluster_templates.get(
cl_template.id),
timeout=self.delete_timeout, sleep=self.request_timeout)
LOG.debug('Cluster template "{0}" has been created.'.format(name))
return cl_template.id
@ -112,8 +117,12 @@ class SaharaTestsManager(nmanager.PlatformServicesBaseClass):
cluster = self.sahara_client.clusters.create(
name, plugin, hadoop_version, default_image_id=default_image_id,
user_keypair_id=key_pair_name, node_groups=node_groups, **kwargs)
self.addCleanup(self.delete_resource,
self.sahara_client.clusters, cluster.id)
self.addCleanup(
self.delete_resource,
delete_method=lambda: self.sahara_client.clusters.delete(
cluster.id),
get_method=lambda: self.sahara_client.clusters.get(cluster.id),
timeout=self.delete_timeout, sleep=self.request_timeout)
LOG.debug('Cluster "{0}" has been created.'.format(name))
return cluster.id
@ -216,29 +225,3 @@ class SaharaTestsManager(nmanager.PlatformServicesBaseClass):
self._run_ssh_cmd(cmd + node_ip + ' ls -a')
LOG.debug('Node {0} is accessible via SSH.'.format(node_ip))
LOG.debug('All cluster nodes are accessible via SSH.')
# Methods for deleting resources.
def delete_resource(self, resource_client, resource_id):
"""This method deletes the resource by its ID and checks whether
the resource is really deleted or not.
"""
LOG.debug('Deleting resource "{0}"...'.format(resource_id))
if self.is_resource_deleted(resource_client, resource_id):
return
resource_client.delete(resource_id)
self._wait_for_deletion(resource_client, resource_id)
LOG.debug('Resource "{0}" has been deleted.'.format(resource_id))
def _wait_for_deletion(self, resource_client, resource_id):
"""This method waits for the resource deletion."""
start = time.time()
while time.time() - start < self.delete_timeout:
if self.is_resource_deleted(resource_client, resource_id):
return
time.sleep(self.request_timeout)
self.fail('Request timed out. '
'Timed out while waiting for one of the test resources '
'to delete within {0} seconds.'.format(self.delete_timeout))

View File

@ -134,8 +134,9 @@ class CeilometerApiPlatformTests(ceilometermanager.CeilometerBaseTest):
fail_msg = 'Failed while waiting for "ACTIVE" status of instance.'
msg = 'waiting for "ACTIVE" status of instance'
self.verify(200, self.wait_for_instance_status, 2,
fail_msg, msg, instance, 'ACTIVE')
self.verify(200, self.wait_for_resource_status, 2,
fail_msg, msg, self.compute_client.servers,
instance.id, 'ACTIVE')
fail_msg = 'Failed to get notifications.'
msg = 'getting notifications'
@ -238,12 +239,14 @@ class CeilometerApiPlatformTests(ceilometermanager.CeilometerBaseTest):
Target component: Ceilometer
Scenario:
1. Create a volume.
2. Get volume notifications.
3. Create a volume snapshot.
1. Create an instance.
2. Wait for 'ACTIVE' status of the instance.
3. Create a volume and volume snapshot.
4. Get volume snapshot notifications.
5. Get volume notifications.
6. Delete the instance.
Duration: 10 s.
Duration: 150 s.
Deployment tags: Ceilometer
"""
@ -251,30 +254,45 @@ class CeilometerApiPlatformTests(ceilometermanager.CeilometerBaseTest):
and not self.config.volume.ceph_exist):
self.skipTest('There are no storage nodes for volumes.')
fail_msg = 'Failed to create volume.'
msg = 'creating volume'
volume = self.verify(60, self._create_volume, 1,
fail_msg, msg, self.volume_client, 'available')
self.check_image_exists()
private_net_id, _ = self.create_network_resources()
query = [{'field': 'resource', 'op': 'eq', 'value': volume.id}]
fail_msg = 'Failed to get volume notifications.'
msg = 'getting volume notifications'
self.verify(600, self.wait_metrics, 2,
fail_msg, msg, self.volume_notifications, query)
fail_msg = 'Failed to create instance.'
msg = 'creating instance'
name = rand_name('ostf-ceilo-instance-')
vcenter = self.config.compute.use_vcenter
image_name = 'TestVM-VMDK' if vcenter else None
instance = self.verify(300, self.create_server, 1, fail_msg, msg, name,
net_id=private_net_id, img_name=image_name)
fail_msg = 'Failed to create volume snapshot.'
msg = 'creating volume snapshot'
snapshot = self.verify(60, self._create_snapshot, 3,
fail_msg, msg, self.volume_client,
volume.id, 'available')
fail_msg = 'Failed while waiting for "ACTIVE" status of instance.'
msg = 'waiting for "ACTIVE" status of instance'
self.verify(200, self.wait_for_resource_status, 2,
fail_msg, msg, self.compute_client.servers,
instance.id, 'ACTIVE')
fail_msg = 'Failed to create volume and volume snapshot.'
msg = 'creating volume and volume snapshot'
volume, snapshot = self.verify(300, self.volume_helper, 3,
fail_msg, msg, instance)
query = [{'field': 'resource', 'op': 'eq', 'value': snapshot.id}]
fail_msg = 'Failed to get volume snapshot notifications.'
msg = 'getting volume snapshot notifications'
self.verify(600, self.wait_metrics, 4,
self.verify(300, self.wait_metrics, 4,
fail_msg, msg,
self.snapshot_notifications, query)
query = [{'field': 'resource', 'op': 'eq', 'value': volume.id}]
fail_msg = 'Failed to get volume notifications.'
msg = 'getting volume notifications'
self.verify(300, self.wait_metrics, 5,
fail_msg, msg, self.volume_notifications, query)
fail_msg = 'Failed to delete the server.'
msg = 'deleting server'
self.verify(30, self._delete_server, 6, fail_msg, msg, instance)
def test_check_glance_notifications(self):
"""Ceilometer test to check notifications from Glance
Target component: Ceilometer