blob: 302ccbec4b0eed7d1b17efacf87cc797dcfb3a7e [file] [log] [blame]
Chris Dent7d3d08d2014-08-21 13:52:47 +01001# Copyright 2014 Red Hat
2#
Chris Dent7d3d08d2014-08-21 13:52:47 +01003# All Rights Reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
Doug Hellmann583ce2c2015-03-11 14:55:46 +000017from oslo_log import log as logging
Chris Dent7d3d08d2014-08-21 13:52:47 +010018
19from tempest import config
Chris Dent7d3d08d2014-08-21 13:52:47 +010020from tempest.scenario import manager
21from tempest import test
22
23CONF = config.CONF
24
25LOG = logging.getLogger(__name__)
26
27# Loop for up to 120 seconds waiting on notifications
28# NOTE(chdent): The choice of 120 seconds is fairly
29# arbitrary: Long enough to give the notifications the
30# chance to travel across a highly latent bus but not
31# so long as to allow excessive latency to never be visible.
32# TODO(chdent): Ideally this value would come from configuration.
33NOTIFICATIONS_WAIT = 120
34NOTIFICATIONS_SLEEP = 1
35
36
37class TestSwiftTelemetry(manager.SwiftScenarioTest):
38 """
39 Test that swift uses the ceilometer middleware.
40 * create container.
41 * upload a file to the created container.
42 * retrieve the file from the created container.
43 * wait for notifications from ceilometer.
44 """
45
46 @classmethod
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000047 def skip_checks(cls):
48 super(TestSwiftTelemetry, cls).skip_checks()
Chris Dent7d3d08d2014-08-21 13:52:47 +010049 if not CONF.service_available.ceilometer:
50 skip_msg = ("%s skipped as ceilometer is not available" %
51 cls.__name__)
52 raise cls.skipException(skip_msg)
Matthew Treinish9981e162014-11-20 17:26:28 -050053 elif CONF.telemetry.too_slow_to_test:
54 skip_msg = "Ceilometer feature for fast work mysql is disabled"
55 raise cls.skipException(skip_msg)
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000056
57 @classmethod
58 def setup_clients(cls):
59 super(TestSwiftTelemetry, cls).setup_clients()
Matthew Treinish8f268292015-02-24 20:01:36 -050060 cls.telemetry_client = cls.os_operator.telemetry_client
Chris Dent7d3d08d2014-08-21 13:52:47 +010061
62 def _confirm_notifications(self, container_name, obj_name):
63 """
64 Loop seeking for appropriate notifications about the containers
65 and objects sent to swift.
66 """
67
68 def _check_samples():
69 """
70 Return True only if we have notifications about some
71 containers and some objects and the notifications are about
72 the expected containers and objects.
73 Otherwise returning False will case _check_samples to be
74 called again.
75 """
David Kranz20d06f42015-02-09 14:54:15 -050076 results = self.telemetry_client.list_samples(
Chris Dent7d3d08d2014-08-21 13:52:47 +010077 'storage.api.request')
78 LOG.debug('got samples %s', results)
79
80 # Extract container info from samples.
gordon chungdc1f53a2015-02-13 09:54:13 -050081 containers, objects = [], []
82 for sample in results:
83 meta = sample['resource_metadata']
84 if meta.get('container') and meta['container'] != 'None':
85 containers.append(meta['container'])
gordon chung396cb382015-02-25 11:43:32 -050086 elif (meta.get('target.metadata:container') and
87 meta['target.metadata:container'] != 'None'):
88 containers.append(meta['target.metadata:container'])
Chris Dent7d3d08d2014-08-21 13:52:47 +010089
gordon chungdc1f53a2015-02-13 09:54:13 -050090 if meta.get('object') and meta['object'] != 'None':
91 objects.append(meta['object'])
gordon chung396cb382015-02-25 11:43:32 -050092 elif (meta.get('target.metadata:object') and
93 meta['target.metadata:object'] != 'None'):
94 objects.append(meta['target.metadata:object'])
gordon chungdc1f53a2015-02-13 09:54:13 -050095
96 return (container_name in containers and obj_name in objects)
Chris Dent7d3d08d2014-08-21 13:52:47 +010097
98 self.assertTrue(test.call_until_true(_check_samples,
99 NOTIFICATIONS_WAIT,
100 NOTIFICATIONS_SLEEP),
101 'Correct notifications were not received after '
102 '%s seconds.' % NOTIFICATIONS_WAIT)
103
Chris Hoge7579c1a2015-02-26 14:12:15 -0800104 @test.idempotent_id('6d6b88e5-3e38-41bc-b34a-79f713a6cb84')
Chris Dent7d3d08d2014-08-21 13:52:47 +0100105 @test.services('object_storage', 'telemetry')
106 def test_swift_middleware_notifies(self):
107 container_name = self.create_container()
108 obj_name, _ = self.upload_object_to_container(container_name)
109 self._confirm_notifications(container_name, obj_name)