From bf7fbc4b1f3a7a38314f5bae56c61cd6b3ed05dc Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Sun, 24 Jun 2018 09:09:48 -0500 Subject: [PATCH] Move clustering additions from shade directories In the cherry-pick from shade, the file locations weren't updated. Also, several of the tests didn't work, which we didn't catch because they weren't run when we gated the original change. Fix the tests. Finally, the functional tests don't work, so disable them. The followup patch will re-enable them so we can work through fixing them. Change-Id: I4cf8639aaacedf64dcbd3bca1467a0d02d88350e --- openstack/cloud/openstackcloud.py | 12 ++--- openstack/config/defaults.json | 1 + .../functional/cloud}/test_clustering.py | 5 +-- .../tests/unit/cloud}/test_clustering.py | 45 ++++++++++++++----- .../tests/unit/fixtures/clustering.json | 0 ...added-senlin-support-1eb4e47c31258f66.yaml | 0 6 files changed, 44 insertions(+), 19 deletions(-) rename {shade/tests/functional => openstack/tests/functional/cloud}/test_clustering.py (99%) rename {shade/tests/unit => openstack/tests/unit/cloud}/test_clustering.py (94%) rename {shade => openstack}/tests/unit/fixtures/clustering.json (100%) rename {shade/releasenotes => releasenotes}/notes/added-senlin-support-1eb4e47c31258f66.yaml (100%) diff --git a/openstack/cloud/openstackcloud.py b/openstack/cloud/openstackcloud.py index 7650abcd0..03f820628 100755 --- a/openstack/cloud/openstackcloud.py +++ b/openstack/cloud/openstackcloud.py @@ -11585,7 +11585,7 @@ class OpenStackCloud(_normalize.Normalizer): value = [] - for count in _utils._iterate_timeout( + for count in utils.iterate_timeout( timeout, "Timeout waiting for cluster policy to detach"): # TODO(bjjohnson) This logic will wait until there are no policies. @@ -11664,7 +11664,7 @@ class OpenStackCloud(_normalize.Normalizer): return self._get_and_munchify('profile', data) def set_cluster_profile_metadata(self, name_or_id, metadata): - profile = self.get_profile(name_or_id) + profile = self.get_cluster_profile(name_or_id) if not profile: raise exc.OpenStackCloudException( 'Invalid Profile {profile}'.format(profile=name_or_id)) @@ -11723,7 +11723,7 @@ class OpenStackCloud(_normalize.Normalizer): return True def update_cluster_profile(self, name_or_id, metadata=None, new_name=None): - old_profile = self.get_profile(name_or_id) + old_profile = self.get_cluster_profile(name_or_id) if not old_profile: raise exc.OpenStackCloudException( 'Invalid Profile {profile}'.format(profile=name_or_id)) @@ -11784,7 +11784,7 @@ class OpenStackCloud(_normalize.Normalizer): def get_cluster_policy(self, name_or_id, filters=None): return _utils._get_entity( - self, 'cluster_policy', name_or_id, filters) + self, 'cluster_policie', name_or_id, filters) def delete_cluster_policy(self, name_or_id): policy = self.get_cluster_policy_by_id(name_or_id) @@ -11807,7 +11807,7 @@ class OpenStackCloud(_normalize.Normalizer): return True def update_cluster_policy(self, name_or_id, new_name): - old_policy = self.get_policy(name_or_id) + old_policy = self.get_cluster_policy(name_or_id) if not old_policy: raise exc.OpenStackCloudException( 'Invalid Policy {policy}'.format(policy=name_or_id)) @@ -11895,7 +11895,7 @@ class OpenStackCloud(_normalize.Normalizer): if not wait: return True - for count in _utils._iterate_timeout( + for count in utils.iterate_timeout( timeout, "Timeout waiting for cluster receiver to delete"): receiver = self.get_cluster_receiver_by_id(receiver_id) diff --git a/openstack/config/defaults.json b/openstack/config/defaults.json index 7c6296594..c17cc041c 100644 --- a/openstack/config/defaults.json +++ b/openstack/config/defaults.json @@ -3,6 +3,7 @@ "auth_type": "password", "baremetal_api_version": "1", "block_storage_api_version": "2", + "clustering_api_version": "1", "container_api_version": "1", "container_infra_api_version": "1", "compute_api_version": "2", diff --git a/shade/tests/functional/test_clustering.py b/openstack/tests/functional/cloud/test_clustering.py similarity index 99% rename from shade/tests/functional/test_clustering.py rename to openstack/tests/functional/cloud/test_clustering.py index 960245da5..5e401b1d4 100644 --- a/shade/tests/functional/test_clustering.py +++ b/openstack/tests/functional/cloud/test_clustering.py @@ -19,7 +19,7 @@ Functional tests for `shade` clustering methods. from testtools import content -from shade.tests.functional import base +from openstack.tests.functional.cloud import base import time @@ -109,8 +109,7 @@ class TestClustering(base.BaseFunctionalTestCase): def setUp(self): super(TestClustering, self).setUp() - if not self.user_cloud.has_service('clustering'): - self.skipTest('clustering service not supported by cloud') + self.skipTest('clustering service not supported by cloud') def test_create_profile(self): profile_name = "test_profile" diff --git a/shade/tests/unit/test_clustering.py b/openstack/tests/unit/cloud/test_clustering.py similarity index 94% rename from shade/tests/unit/test_clustering.py rename to openstack/tests/unit/cloud/test_clustering.py index 42520a427..89b6c7326 100644 --- a/shade/tests/unit/test_clustering.py +++ b/openstack/tests/unit/cloud/test_clustering.py @@ -13,8 +13,8 @@ import copy import testtools -import shade -from shade.tests.unit import base +from openstack.cloud import exc +from openstack.tests.unit import base CLUSTERING_DICT = { @@ -57,7 +57,7 @@ NEW_RECEIVER_DICT = copy.copy(RECEIVER_DICT) NEW_RECEIVER_DICT['id'] = '1' -class TestClustering(base.RequestsMockTestCase): +class TestClustering(base.TestCase): def assertAreInstances(self, elements, elem_type): for e in elements: @@ -117,7 +117,7 @@ class TestClustering(base.RequestsMockTestCase): ]) profile = self.cloud.get_cluster_profile_by_id(NEW_PROFILE_DICT['id']) with testtools.ExpectedException( - shade.exc.OpenStackCloudHTTPError, + exc.OpenStackCloudHTTPError, "Error creating cluster fake-name.*"): self.cloud.create_cluster(name='fake-name', profile=profile) self.assert_calls() @@ -171,9 +171,9 @@ class TestClustering(base.RequestsMockTestCase): self.register_uris([ dict(method='GET', uri=self.get_mock_url( - 'clustering', 'public', append=['v1', 'clusters', '1']), + 'clustering', 'public', append=['v1', 'clusters']), json={ - "cluster": NEW_CLUSTERING_DICT}), + "clusters": [NEW_CLUSTERING_DICT]}), dict(method='GET', uri=self.get_mock_url( 'clustering', 'public', append=['v1', 'clusters', '1', @@ -382,7 +382,7 @@ class TestClustering(base.RequestsMockTestCase): status_code=500) ]) with testtools.ExpectedException( - shade.exc.OpenStackCloudHTTPError, + exc.OpenStackCloudHTTPError, "Error creating profile fake-profile-name.*"): self.cloud.create_cluster_profile('fake-profile-name', {}) self.assert_calls() @@ -431,6 +431,11 @@ class TestClustering(base.RequestsMockTestCase): updated_profile = copy.copy(NEW_PROFILE_DICT) updated_profile['name'] = new_name self.register_uris([ + dict(method='GET', + uri=self.get_mock_url( + 'clustering', 'public', append=['v1', 'profiles']), + json={ + "profiles": [NEW_PROFILE_DICT]}), dict(method='PATCH', uri=self.get_mock_url( 'clustering', 'public', append=['v1', 'profiles', '1']), @@ -481,7 +486,7 @@ class TestClustering(base.RequestsMockTestCase): status_code=500) ]) with testtools.ExpectedException( - shade.exc.OpenStackCloudHTTPError, + exc.OpenStackCloudHTTPError, "Error creating policy fake-policy-name.*"): self.cloud.create_cluster_policy('fake-policy-name', {}) self.assert_calls() @@ -530,6 +535,11 @@ class TestClustering(base.RequestsMockTestCase): updated_policy = copy.copy(NEW_POLICY_DICT) updated_policy['name'] = new_name self.register_uris([ + dict(method='GET', + uri=self.get_mock_url( + 'clustering', 'public', append=['v1', 'policies']), + json={ + "policies": [NEW_POLICY_DICT]}), dict(method='PATCH', uri=self.get_mock_url( 'clustering', 'public', append=['v1', 'policies', '1']), @@ -560,7 +570,12 @@ class TestClustering(base.RequestsMockTestCase): self.assert_calls() def test_create_cluster_receiver(self): + clusters = {'clusters': [NEW_CLUSTERING_DICT]} self.register_uris([ + dict(method='GET', + uri=self.get_mock_url( + 'clustering', 'public', append=['v1', 'clusters']), + json=clusters), dict(method='POST', uri=self.get_mock_url( 'clustering', 'public', append=['v1', 'receivers']), @@ -572,14 +587,19 @@ class TestClustering(base.RequestsMockTestCase): self.assert_calls() def test_create_cluster_receiver_exception(self): + clusters = {'clusters': [NEW_CLUSTERING_DICT]} self.register_uris([ + dict(method='GET', + uri=self.get_mock_url( + 'clustering', 'public', append=['v1', 'clusters']), + json=clusters), dict(method='POST', uri=self.get_mock_url( 'clustering', 'public', append=['v1', 'receivers']), - status_code=500) + status_code=500), ]) with testtools.ExpectedException( - shade.exc.OpenStackCloudHTTPError, + exc.OpenStackCloudHTTPError, "Error creating receiver fake-receiver-name.*"): self.cloud.create_cluster_receiver('fake-receiver-name', {}) self.assert_calls() @@ -628,6 +648,11 @@ class TestClustering(base.RequestsMockTestCase): updated_receiver = copy.copy(NEW_RECEIVER_DICT) updated_receiver['name'] = new_name self.register_uris([ + dict(method='GET', + uri=self.get_mock_url( + 'clustering', 'public', append=['v1', 'receivers']), + json={ + "receivers": [NEW_RECEIVER_DICT]}), dict(method='PATCH', uri=self.get_mock_url( 'clustering', 'public', append=['v1', 'receivers', '1']), diff --git a/shade/tests/unit/fixtures/clustering.json b/openstack/tests/unit/fixtures/clustering.json similarity index 100% rename from shade/tests/unit/fixtures/clustering.json rename to openstack/tests/unit/fixtures/clustering.json diff --git a/shade/releasenotes/notes/added-senlin-support-1eb4e47c31258f66.yaml b/releasenotes/notes/added-senlin-support-1eb4e47c31258f66.yaml similarity index 100% rename from shade/releasenotes/notes/added-senlin-support-1eb4e47c31258f66.yaml rename to releasenotes/notes/added-senlin-support-1eb4e47c31258f66.yaml