diff --git a/openstack/cloud/_compute.py b/openstack/cloud/_compute.py index 958c07822..5b09d90a1 100644 --- a/openstack/cloud/_compute.py +++ b/openstack/cloud/_compute.py @@ -1633,6 +1633,16 @@ class ComputeCloudMixin(_normalize.Normalizer): :raises: OpenStackCloudException on operation error. """ + if ( + isinstance(name_or_id, six.string_types + (six.binary_type,)) + and not name_or_id.isdigit() + ): + aggregate = self.get_aggregate(name_or_id) + if not aggregate: + self.log.debug( + "Aggregate %s not found for deleting", name_or_id) + return False + name_or_id = aggregate.id try: self.compute.delete_aggregate(name_or_id, ignore_missing=False) return True diff --git a/openstack/tests/functional/cloud/test_aggregate.py b/openstack/tests/functional/cloud/test_aggregate.py index 0f06e3a8c..d7bcc0fd4 100644 --- a/openstack/tests/functional/cloud/test_aggregate.py +++ b/openstack/tests/functional/cloud/test_aggregate.py @@ -50,9 +50,11 @@ class TestAggregate(base.BaseFunctionalTest): ) self.assertNotIn('key', aggregate['metadata']) - self.operator_cloud.delete_aggregate(aggregate_name) + # Validate that we can delete by name + self.assertTrue( + self.operator_cloud.delete_aggregate(aggregate_name)) def cleanup(self, aggregate_name): aggregate = self.operator_cloud.get_aggregate(aggregate_name) if aggregate: - self.operator_cloud.delete_aggregate(aggregate_name) + self.operator_cloud.delete_aggregate(aggregate['id']) diff --git a/openstack/tests/unit/cloud/test_aggregate.py b/openstack/tests/unit/cloud/test_aggregate.py index f6718c2aa..45975bbc1 100644 --- a/openstack/tests/unit/cloud/test_aggregate.py +++ b/openstack/tests/unit/cloud/test_aggregate.py @@ -78,6 +78,24 @@ class TestAggregate(base.TestCase): self.assert_calls() + def test_delete_aggregate_by_name(self): + self.register_uris([ + dict( + method='GET', + uri=self.get_mock_url( + 'compute', 'public', append=['os-aggregates'] + ), + json={'aggregates': [self.fake_aggregate]}, + ), + dict(method='DELETE', + uri=self.get_mock_url( + 'compute', 'public', append=['os-aggregates', '1'])), + ]) + + self.assertTrue(self.cloud.delete_aggregate(self.aggregate_name)) + + self.assert_calls() + def test_update_aggregate_set_az(self): self.register_uris([ dict(method='GET',