blob: dd6d855425e78e73fa985969707d2b6c1f2ff1c7 [file] [log] [blame]
Chris Dent7d3d08d2014-08-21 13:52:47 +01001#
2# Copyright 2014 Red Hat
3#
4# Author: Chris Dent <chdent@redhat.com>
5# All Rights Reserved.
6#
7# Licensed under the Apache License, Version 2.0 (the "License"); you may
8# not use this file except in compliance with the License. You may obtain
9# a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16# License for the specific language governing permissions and limitations
17# under the License.
18
19
20from tempest import config
21from tempest.openstack.common import log as logging
22from tempest.scenario import manager
23from tempest import test
24
25CONF = config.CONF
26
27LOG = logging.getLogger(__name__)
28
29# Loop for up to 120 seconds waiting on notifications
30# NOTE(chdent): The choice of 120 seconds is fairly
31# arbitrary: Long enough to give the notifications the
32# chance to travel across a highly latent bus but not
33# so long as to allow excessive latency to never be visible.
34# TODO(chdent): Ideally this value would come from configuration.
35NOTIFICATIONS_WAIT = 120
36NOTIFICATIONS_SLEEP = 1
37
38
39class TestSwiftTelemetry(manager.SwiftScenarioTest):
40 """
41 Test that swift uses the ceilometer middleware.
42 * create container.
43 * upload a file to the created container.
44 * retrieve the file from the created container.
45 * wait for notifications from ceilometer.
46 """
47
48 @classmethod
49 def resource_setup(cls):
50 if not CONF.service_available.ceilometer:
51 skip_msg = ("%s skipped as ceilometer is not available" %
52 cls.__name__)
53 raise cls.skipException(skip_msg)
Matthew Treinish9981e162014-11-20 17:26:28 -050054 elif CONF.telemetry.too_slow_to_test:
55 skip_msg = "Ceilometer feature for fast work mysql is disabled"
56 raise cls.skipException(skip_msg)
Chris Dent7d3d08d2014-08-21 13:52:47 +010057 super(TestSwiftTelemetry, cls).resource_setup()
58 cls.telemetry_client = cls.manager.telemetry_client
59
60 def _confirm_notifications(self, container_name, obj_name):
61 """
62 Loop seeking for appropriate notifications about the containers
63 and objects sent to swift.
64 """
65
66 def _check_samples():
67 """
68 Return True only if we have notifications about some
69 containers and some objects and the notifications are about
70 the expected containers and objects.
71 Otherwise returning False will case _check_samples to be
72 called again.
73 """
David Kranz20d06f42015-02-09 14:54:15 -050074 results = self.telemetry_client.list_samples(
Chris Dent7d3d08d2014-08-21 13:52:47 +010075 'storage.api.request')
76 LOG.debug('got samples %s', results)
77
78 # Extract container info from samples.
gordon chungdc1f53a2015-02-13 09:54:13 -050079 containers, objects = [], []
80 for sample in results:
81 meta = sample['resource_metadata']
82 if meta.get('container') and meta['container'] != 'None':
83 containers.append(meta['container'])
84 elif (meta.get('target') and
85 meta['target']['metadata']['container'] != 'None'):
86 containers.append(meta['target']['metadata']['container'])
Chris Dent7d3d08d2014-08-21 13:52:47 +010087
gordon chungdc1f53a2015-02-13 09:54:13 -050088 if meta.get('object') and meta['object'] != 'None':
89 objects.append(meta['object'])
90 elif (meta.get('target') and
91 meta['target']['metadata']['object'] != 'None'):
92 objects.append(meta['target']['metadata']['object'])
93
94 return (container_name in containers and obj_name in objects)
Chris Dent7d3d08d2014-08-21 13:52:47 +010095
96 self.assertTrue(test.call_until_true(_check_samples,
97 NOTIFICATIONS_WAIT,
98 NOTIFICATIONS_SLEEP),
99 'Correct notifications were not received after '
100 '%s seconds.' % NOTIFICATIONS_WAIT)
101
102 @test.services('object_storage', 'telemetry')
103 def test_swift_middleware_notifies(self):
104 container_name = self.create_container()
105 obj_name, _ = self.upload_object_to_container(container_name)
106 self._confirm_notifications(container_name, obj_name)