Chris Dent | 7d3d08d | 2014-08-21 13:52:47 +0100 | [diff] [blame] | 1 | # |
| 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 | |
| 20 | from tempest import config |
| 21 | from tempest.openstack.common import log as logging |
| 22 | from tempest.scenario import manager |
| 23 | from tempest import test |
| 24 | |
| 25 | CONF = config.CONF |
| 26 | |
| 27 | LOG = 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. |
| 35 | NOTIFICATIONS_WAIT = 120 |
| 36 | NOTIFICATIONS_SLEEP = 1 |
| 37 | |
| 38 | |
| 39 | class 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 Treinish | 9981e16 | 2014-11-20 17:26:28 -0500 | [diff] [blame] | 54 | 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 Dent | 7d3d08d | 2014-08-21 13:52:47 +0100 | [diff] [blame] | 57 | 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 | """ |
| 74 | _, results = self.telemetry_client.list_samples( |
| 75 | 'storage.api.request') |
| 76 | LOG.debug('got samples %s', results) |
| 77 | |
| 78 | # Extract container info from samples. |
| 79 | containers = [sample['resource_metadata']['container'] |
| 80 | for sample in results |
| 81 | if sample['resource_metadata']['container'] |
| 82 | != 'None'] |
| 83 | # Extract object info from samples. |
| 84 | objects = [sample['resource_metadata']['object'] |
| 85 | for sample in results |
| 86 | if sample['resource_metadata']['object'] != 'None'] |
| 87 | |
| 88 | return (containers |
| 89 | and objects |
| 90 | and container_name in containers |
| 91 | and obj_name in objects) |
| 92 | |
| 93 | self.assertTrue(test.call_until_true(_check_samples, |
| 94 | NOTIFICATIONS_WAIT, |
| 95 | NOTIFICATIONS_SLEEP), |
| 96 | 'Correct notifications were not received after ' |
| 97 | '%s seconds.' % NOTIFICATIONS_WAIT) |
| 98 | |
| 99 | @test.services('object_storage', 'telemetry') |
| 100 | def test_swift_middleware_notifies(self): |
| 101 | container_name = self.create_container() |
| 102 | obj_name, _ = self.upload_object_to_container(container_name) |
| 103 | self._confirm_notifications(container_name, obj_name) |