From 23e055a8d3736f5de7a9f88efb4ca83c0a9ba756 Mon Sep 17 00:00:00 2001 From: Alexander Chadin Date: Tue, 5 Jul 2016 10:47:58 +0300 Subject: [PATCH] Add support for watcher osclient and watcher related types This patch set registers Watcher as Service for Rally and adds Watcher Goal and Strategy Types with related unit tests. Also it adds *.DS_Store type to gitignore and python-watcherclient to the requirements.txt to support Watcher in future. Change-Id: I0ed4154bdb497d76b768c0eace74940f8811a8e8 --- .gitignore | 3 ++ rally/consts.py | 3 ++ rally/plugins/openstack/cleanup/resources.py | 21 ++++++++++++ requirements.txt | 1 + tests/ci/osresources.py | 20 +++++++++++ tests/unit/fakes.py | 33 +++++++++++++++++++ .../openstack/cleanup/test_resources.py | 27 +++++++++++++++ 7 files changed, 108 insertions(+) diff --git a/.gitignore b/.gitignore index d311e9b9..3a8cb664 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,6 @@ doc/source/_build/ .idea .pydevproject *.swp + +# Mac Desktop Service Store +*.DS_Store diff --git a/rally/consts.py b/rally/consts.py index 3b15251d..dab791f2 100644 --- a/rally/consts.py +++ b/rally/consts.py @@ -113,6 +113,7 @@ class _Service(utils.ImmutableMixin, utils.EnumMixin): IRONIC = "ironic" GNOCCHI = "gnocchi" MAGNUM = "magnum" + WATCHER = "watcher" class _ServiceType(utils.ImmutableMixin, utils.EnumMixin): @@ -141,6 +142,7 @@ class _ServiceType(utils.ImmutableMixin, utils.EnumMixin): BARE_METAL = "baremetal" METRIC = "metric" CONTAINER_INFRA = "container-infra" + INFRA_OPTIM = "infra-optim" def __init__(self): self.__names = { @@ -167,6 +169,7 @@ class _ServiceType(utils.ImmutableMixin, utils.EnumMixin): self.BARE_METAL: _Service.IRONIC, self.METRIC: _Service.GNOCCHI, self.CONTAINER_INFRA: _Service.MAGNUM, + self.INFRA_OPTIM: _Service.WATCHER, } def __getitem__(self, service_type): diff --git a/rally/plugins/openstack/cleanup/resources.py b/rally/plugins/openstack/cleanup/resources.py index 5161370a..37fca765 100644 --- a/rally/plugins/openstack/cleanup/resources.py +++ b/rally/plugins/openstack/cleanup/resources.py @@ -720,6 +720,27 @@ class FuelEnvironment(base.ResourceManager): futils.FuelScenario)] +# WATCHER + +@base.resource("watcher", "audit_template", order=1500, + admin_required=True, tenant_resource=True) +class WatcherTemplate(SynchronizedDeletion, base.ResourceManager): + + def id(self): + return self.raw_resource.uuid + + def is_deleted(self): + from watcherclient.common.apiclient import exceptions + try: + self._manager().get(self.id()) + return False + except exceptions.NotFound: + return True + + def list(self): + return self._manager().list(limit=0) + + # KEYSTONE _keystone_order = get_order(9000) diff --git a/requirements.txt b/requirements.txt index 2c35c73e..997fe78b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -32,6 +32,7 @@ python-saharaclient>=0.13.0 # Apache-2.0 python-troveclient>=2.2.0 # Apache-2.0 python-zaqarclient>=1.0.0 # Apache-2.0 python-swiftclient>=2.2.0 # Apache-2.0 +python-watcherclient>=0.23.0 # Apache-2.0 python-subunit>=0.0.18 # Apache-2.0/BSD requests>=2.10.0 # Apache-2.0 SQLAlchemy<1.1.0,>=1.0.10 # MIT diff --git a/tests/ci/osresources.py b/tests/ci/osresources.py index 898ae8bf..14c6be74 100755 --- a/tests/ci/osresources.py +++ b/tests/ci/osresources.py @@ -208,6 +208,26 @@ class Cinder(ResourceManager): search_opts={"all_tenants": True}) +class Watcher(ResourceManager): + + REQUIRED_SERVICE = consts.Service.WATCHER + + def list_audits(self): + return self.client.audit.list() + + def list_audit_templates(self): + return self.client.audit_template.list() + + def list_goals(self): + return self.client.goal.list() + + def list_action_plans(self): + return self.client.action_plan.list() + + def list_actions(self): + return self.client.action.list() + + class CloudResources(object): """List and compare cloud resources. diff --git a/tests/unit/fakes.py b/tests/unit/fakes.py index c273e900..8e6949f8 100644 --- a/tests/unit/fakes.py +++ b/tests/unit/fakes.py @@ -127,6 +127,14 @@ class FakeImage(FakeResource): self.update = mock.MagicMock() +class FakeStrategy(FakeResource): + pass + + +class FakeGoal(FakeResource): + pass + + class FakeMurano(FakeResource): pass @@ -425,6 +433,18 @@ class FakeImageManager(FakeManager): self.resources_order.remove(resource) +class FakeStrategyManager(FakeManager): + + def create(self): + return FakeStrategy(self) + + +class FakeGoalManager(FakeManager): + + def create(self): + return FakeGoal(self) + + class FakePackageManager(FakeManager): def create(self, package_descr, package_arch, package_class=FakeMurano): @@ -1493,6 +1513,13 @@ class FakeMagnumClient(object): pass +class FakeWatcherClient(object): + + def __init__(self): + self.strategy = FakeStrategyManager() + self.goal = FakeGoalManager() + + class FakeClients(object): def __init__(self, credential_=None): @@ -1513,6 +1540,7 @@ class FakeClients(object): self._monasca = None self._ec2 = None self._senlin = None + self._watcher = None self._credential = credential_ or objects.Credential( "http://fake.example.org:5000/v2.0/", "fake_username", @@ -1607,6 +1635,11 @@ class FakeClients(object): self._senlin = FakeSenlinClient() return self._senlin + def watcher(self): + if not self._watcher: + self._watcher = FakeWatcherClient() + return self._watcher + class FakeRunner(object): diff --git a/tests/unit/plugins/openstack/cleanup/test_resources.py b/tests/unit/plugins/openstack/cleanup/test_resources.py index 15d15c49..ad509ae9 100644 --- a/tests/unit/plugins/openstack/cleanup/test_resources.py +++ b/tests/unit/plugins/openstack/cleanup/test_resources.py @@ -18,6 +18,7 @@ import ddt import mock from neutronclient.common import exceptions as neutron_exceptions from novaclient import exceptions as nova_exc +from watcherclient.common.apiclient import exceptions as watcher_exceptions from rally.common import utils from rally.plugins.openstack.cleanup import resources @@ -753,3 +754,29 @@ class FuelEnvironmentTestCase(test.TestCase): fres = resources.FuelEnvironment() self.assertEqual(envs[:-1], fres.list()) + + +class WatcherTemplateTestCase(test.TestCase): + + def test_id(self): + watcher = resources.WatcherTemplate() + watcher.raw_resource = mock.MagicMock(uuid=100) + self.assertEqual(100, watcher.id()) + + @mock.patch("%s.WatcherTemplate._manager" % BASE) + def test_is_deleted(self, mock__manager): + mock__manager.return_value.get.return_value = None + watcher = resources.WatcherTemplate() + watcher.id = mock.Mock() + self.assertFalse(watcher.is_deleted()) + mock__manager.side_effect = [watcher_exceptions.NotFound()] + self.assertTrue(watcher.is_deleted()) + + def test_list(self): + watcher = resources.WatcherTemplate() + watcher._manager = mock.MagicMock() + + watcher.list() + + self.assertEqual("audit_template", watcher._resource) + watcher._manager().list.assert_called_once_with(limit=0)