Add Designate support

Change-Id: Ia4aab5f6ccc6405eba20750b505ebdf32a6ab82d
Signed-off-by: Graham Hayes <gr@ham.ie>
This commit is contained in:
Graham Hayes 2018-10-15 16:47:37 +01:00
parent add202ff6a
commit bd1588ac19
No known key found for this signature in database
GPG Key ID: 1B263DC59F4AEFD5
3 changed files with 101 additions and 0 deletions

View File

@ -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'])

View File

@ -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:
...

View File

@ -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))