Eliminate Master/Slave terminology from Designate Zone resource
Change-Id: If136f5e270db5df1f871dc9473afb178e242bc18
This commit is contained in:
parent
9f931119ba
commit
a3eeefb6d7
@ -18,6 +18,7 @@ from heat.engine import constraints
|
||||
from heat.engine import properties
|
||||
from heat.engine import resource
|
||||
from heat.engine import support
|
||||
from heat.engine import translation
|
||||
|
||||
|
||||
class DesignateZone(resource.Resource):
|
||||
@ -31,9 +32,9 @@ class DesignateZone(resource.Resource):
|
||||
version='8.0.0')
|
||||
|
||||
PROPERTIES = (
|
||||
NAME, TTL, DESCRIPTION, EMAIL, TYPE, MASTERS
|
||||
NAME, TTL, DESCRIPTION, EMAIL, TYPE, PRIMARIES, MASTERS
|
||||
) = (
|
||||
'name', 'ttl', 'description', 'email', 'type', 'masters'
|
||||
'name', 'ttl', 'description', 'email', 'type', 'primaries', 'masters'
|
||||
)
|
||||
|
||||
ATTRIBUTES = (
|
||||
@ -80,17 +81,28 @@ class DesignateZone(resource.Resource):
|
||||
TYPE: properties.Schema(
|
||||
properties.Schema.STRING,
|
||||
_('Type of zone. PRIMARY is controlled by Designate, SECONDARY '
|
||||
'zones are slaved from another DNS Server.'),
|
||||
'zones are transferred from another DNS Server.'),
|
||||
default=PRIMARY,
|
||||
constraints=[constraints.AllowedValues(
|
||||
allowed=TYPES)]
|
||||
),
|
||||
MASTERS: properties.Schema(
|
||||
properties.Schema.LIST,
|
||||
_('The servers to slave from to get DNS information and is '
|
||||
'mandatory for zone type SECONDARY, otherwise ignored.'),
|
||||
_('The primary servers to transfer DNS zone information from. '
|
||||
'Mandatory for zone type SECONDARY, otherwise ignored.'),
|
||||
update_allowed=True,
|
||||
support_status=support.SupportStatus(
|
||||
status=support.DEPRECATED,
|
||||
version='15.0.0',
|
||||
message=_('Use ``primaries`` instead.')
|
||||
)
|
||||
),
|
||||
PRIMARIES: properties.Schema(
|
||||
properties.Schema.LIST,
|
||||
_('The primary servers to transfer DNS zone information from. '
|
||||
'Mandatory for zone type SECONDARY, otherwise ignored.'),
|
||||
update_allowed=True
|
||||
)
|
||||
),
|
||||
}
|
||||
|
||||
attributes_schema = {
|
||||
@ -120,6 +132,17 @@ class DesignateZone(resource.Resource):
|
||||
raise_invalid_exception(self.PRIMARY, self.EMAIL)
|
||||
raise_invalid_exception(self.SECONDARY, self.MASTERS)
|
||||
|
||||
def translation_rules(self, props):
|
||||
return [
|
||||
# Translate to "masters" as that is what the Designate API uses,
|
||||
# even though we have deprecated that name for the property
|
||||
# in favour of "primaries".
|
||||
translation.TranslationRule(props,
|
||||
translation.TranslationRule.REPLACE,
|
||||
translation_path=[self.MASTERS],
|
||||
value_name=self.PRIMARIES)
|
||||
]
|
||||
|
||||
def handle_create(self):
|
||||
args = dict((k, v) for k, v in self.properties.items() if v)
|
||||
args['type_'] = args.pop(self.TYPE)
|
||||
|
@ -211,3 +211,94 @@ class DesignateZoneTest(common.HeatTestCase):
|
||||
self.test_client.zones.get.assert_called_once_with(
|
||||
self.test_resource.resource_id
|
||||
)
|
||||
|
||||
|
||||
class DesignateSecondaryZoneTest(common.HeatTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(DesignateSecondaryZoneTest, self).setUp()
|
||||
|
||||
self.ctx = utils.dummy_context()
|
||||
|
||||
self.primaries = ['::1']
|
||||
|
||||
def _get_mock_resource(self):
|
||||
value = {}
|
||||
value['id'] = '477e8273-60a7-4c41-b683-fdb0bc7cd152'
|
||||
value['serial'] = '1434596972'
|
||||
|
||||
return value
|
||||
|
||||
def test_masters(self):
|
||||
self.do_test({
|
||||
'heat_template_version': '2015-04-30',
|
||||
'resources': {
|
||||
'test_resource': {
|
||||
'type': 'OS::Designate::Zone',
|
||||
'properties': {
|
||||
'name': 'test-zone.com',
|
||||
'description': 'Test zone',
|
||||
'ttl': 3600,
|
||||
'email': 'abc@test-zone.com',
|
||||
'type': 'SECONDARY',
|
||||
'masters': self.primaries,
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
def test_primaries(self):
|
||||
self.do_test({
|
||||
'heat_template_version': '2015-04-30',
|
||||
'resources': {
|
||||
'test_resource': {
|
||||
'type': 'OS::Designate::Zone',
|
||||
'properties': {
|
||||
'name': 'test-zone.com',
|
||||
'description': 'Test zone',
|
||||
'ttl': 3600,
|
||||
'email': 'abc@test-zone.com',
|
||||
'type': 'SECONDARY',
|
||||
'primaries': self.primaries,
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
def do_test(self, sample_template):
|
||||
self.stack = stack.Stack(
|
||||
self.ctx, 'test_stack',
|
||||
template.Template(sample_template)
|
||||
)
|
||||
|
||||
self.test_resource = self.stack['test_resource']
|
||||
|
||||
# Mock client plugin
|
||||
self.test_client_plugin = mock.MagicMock()
|
||||
self.test_resource.client_plugin = mock.MagicMock(
|
||||
return_value=self.test_client_plugin)
|
||||
|
||||
# Mock client
|
||||
self.test_client = mock.MagicMock()
|
||||
self.test_resource.client = mock.MagicMock(
|
||||
return_value=self.test_client)
|
||||
|
||||
mock_zone_create = self.test_client.zones.create
|
||||
mock_resource = self._get_mock_resource()
|
||||
mock_zone_create.return_value = mock_resource
|
||||
|
||||
self.test_resource.data_set = mock.Mock()
|
||||
self.test_resource.handle_create()
|
||||
|
||||
args = dict(
|
||||
name='test-zone.com',
|
||||
description='Test zone',
|
||||
ttl=3600,
|
||||
email='abc@test-zone.com',
|
||||
type_='SECONDARY',
|
||||
masters=self.primaries
|
||||
)
|
||||
|
||||
mock_zone_create.assert_called_once_with(**args)
|
||||
# validate physical resource id
|
||||
self.assertEqual(mock_resource['id'], self.test_resource.resource_id)
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
deprecations:
|
||||
- |
|
||||
The ``OS::Designate::Zone`` resource type's ``masters`` property is now
|
||||
known as ``primaries``. Existing templates will continue to work.
|
Loading…
Reference in New Issue
Block a user