Chris Dent | 7d3d08d | 2014-08-21 13:52:47 +0100 | [diff] [blame] | 1 | # Copyright 2014 Red Hat |
| 2 | # |
Chris Dent | 7d3d08d | 2014-08-21 13:52:47 +0100 | [diff] [blame] | 3 | # 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 Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 17 | from oslo_log import log as logging |
Chris Dent | 7d3d08d | 2014-08-21 13:52:47 +0100 | [diff] [blame] | 18 | |
| 19 | from tempest import config |
Chris Dent | 7d3d08d | 2014-08-21 13:52:47 +0100 | [diff] [blame] | 20 | from tempest.scenario import manager |
| 21 | from tempest import test |
| 22 | |
| 23 | CONF = config.CONF |
| 24 | |
| 25 | LOG = 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. |
| 33 | NOTIFICATIONS_WAIT = 120 |
| 34 | NOTIFICATIONS_SLEEP = 1 |
| 35 | |
| 36 | |
| 37 | class 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 Hugenbruch | 5e2d2a2 | 2015-02-25 21:35:45 +0000 | [diff] [blame] | 47 | def skip_checks(cls): |
| 48 | super(TestSwiftTelemetry, cls).skip_checks() |
Chris Dent | 7d3d08d | 2014-08-21 13:52:47 +0100 | [diff] [blame] | 49 | 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 Treinish | 9981e16 | 2014-11-20 17:26:28 -0500 | [diff] [blame] | 53 | 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 Hugenbruch | 5e2d2a2 | 2015-02-25 21:35:45 +0000 | [diff] [blame] | 56 | |
| 57 | @classmethod |
| 58 | def setup_clients(cls): |
| 59 | super(TestSwiftTelemetry, cls).setup_clients() |
Matthew Treinish | 8f26829 | 2015-02-24 20:01:36 -0500 | [diff] [blame] | 60 | cls.telemetry_client = cls.os_operator.telemetry_client |
Chris Dent | 7d3d08d | 2014-08-21 13:52:47 +0100 | [diff] [blame] | 61 | |
| 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 Kranz | 20d06f4 | 2015-02-09 14:54:15 -0500 | [diff] [blame] | 76 | results = self.telemetry_client.list_samples( |
Chris Dent | 7d3d08d | 2014-08-21 13:52:47 +0100 | [diff] [blame] | 77 | 'storage.api.request') |
| 78 | LOG.debug('got samples %s', results) |
| 79 | |
| 80 | # Extract container info from samples. |
gordon chung | dc1f53a | 2015-02-13 09:54:13 -0500 | [diff] [blame] | 81 | 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 chung | 396cb38 | 2015-02-25 11:43:32 -0500 | [diff] [blame] | 86 | elif (meta.get('target.metadata:container') and |
| 87 | meta['target.metadata:container'] != 'None'): |
| 88 | containers.append(meta['target.metadata:container']) |
Chris Dent | 7d3d08d | 2014-08-21 13:52:47 +0100 | [diff] [blame] | 89 | |
gordon chung | dc1f53a | 2015-02-13 09:54:13 -0500 | [diff] [blame] | 90 | if meta.get('object') and meta['object'] != 'None': |
| 91 | objects.append(meta['object']) |
gordon chung | 396cb38 | 2015-02-25 11:43:32 -0500 | [diff] [blame] | 92 | elif (meta.get('target.metadata:object') and |
| 93 | meta['target.metadata:object'] != 'None'): |
| 94 | objects.append(meta['target.metadata:object']) |
gordon chung | dc1f53a | 2015-02-13 09:54:13 -0500 | [diff] [blame] | 95 | |
| 96 | return (container_name in containers and obj_name in objects) |
Chris Dent | 7d3d08d | 2014-08-21 13:52:47 +0100 | [diff] [blame] | 97 | |
| 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 Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 104 | @test.idempotent_id('6d6b88e5-3e38-41bc-b34a-79f713a6cb84') |
Chris Dent | 7d3d08d | 2014-08-21 13:52:47 +0100 | [diff] [blame] | 105 | @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) |