From bd1588ac19be31bac473b6ec1bae900d795074c2 Mon Sep 17 00:00:00 2001 From: Graham Hayes Date: Mon, 15 Oct 2018 16:47:37 +0100 Subject: [PATCH] Add Designate support Change-Id: Ia4aab5f6ccc6405eba20750b505ebdf32a6ab82d Signed-off-by: Graham Hayes --- ospurge/resources/designate.py | 29 +++++++++++++++ ospurge/resources/designate.pyi | 28 +++++++++++++++ ospurge/tests/resources/test_designate.py | 44 +++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 ospurge/resources/designate.py create mode 100644 ospurge/resources/designate.pyi create mode 100644 ospurge/tests/resources/test_designate.py diff --git a/ospurge/resources/designate.py b/ospurge/resources/designate.py new file mode 100644 index 0000000..2ce41b6 --- /dev/null +++ b/ospurge/resources/designate.py @@ -0,0 +1,29 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +from ospurge.resources import base + + +class Zones(base.ServiceResource): + ORDER = 10 + + def list(self): + if not self.cloud.has_service('dns'): + return [] + return self.cloud.list_zones() + + def delete(self, resource): + self.cloud.delete_zone(resource['id']) + + @staticmethod + def to_str(resource): + return "Designate Zone (id='{}', name='{}')".format( + resource['id'], resource['name']) diff --git a/ospurge/resources/designate.pyi b/ospurge/resources/designate.pyi new file mode 100644 index 0000000..1b40fbe --- /dev/null +++ b/ospurge/resources/designate.pyi @@ -0,0 +1,28 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +from typing import Any +from typing import Dict +from typing import Iterable + +from ospurge.resources import base + + +class Zones(base.ServiceResource): + def list(self) -> Iterable: + ... + + def delete(self, resource: Dict[str, Any]) -> None: + ... + + @staticmethod + def to_str(resource: Dict[str, Any]) -> str: + ... diff --git a/ospurge/tests/resources/test_designate.py b/ospurge/tests/resources/test_designate.py new file mode 100644 index 0000000..72b15b1 --- /dev/null +++ b/ospurge/tests/resources/test_designate.py @@ -0,0 +1,44 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +import unittest + +import shade + +from ospurge.resources import designate +from ospurge.tests import mock + + +class TestZones(unittest.TestCase): + def setUp(self): + self.cloud = mock.Mock(spec_set=shade.openstackcloud.OpenStackCloud) + self.creds_manager = mock.Mock(cloud=self.cloud) + + def test_list_without_service(self): + self.cloud.has_service.return_value = False + self.assertEqual(designate.Zones(self.creds_manager).list(), []) + self.cloud.list_zones.assert_not_called() + + def test_list_with_service(self): + self.cloud.has_service.return_value = True + self.assertIs(self.cloud.list_zones.return_value, + designate.Zones(self.creds_manager).list()) + self.cloud.list_zones.assert_called_once_with() + + def test_delete(self): + zone = mock.MagicMock() + self.assertIsNone(designate.Zones(self.creds_manager).delete(zone)) + self.cloud.delete_zone.assert_called_once_with(zone['id']) + + def test_to_string(self): + stack = mock.MagicMock() + self.assertIn("Designate Zone", + designate.Zones(self.creds_manager).to_str(stack))