Fix multiple gate issues

Change 'multiattach' property support status to HIDDEN

From queens release this is an extra-spec capability of volume type and
the ability to attach a volume to multiple hosts/servers requires that
the volume is of a special type that includes an extra-spec capability
setting of multiattach=<is> True.

Address v1 designate client removal from python-designateclient

designateclient v1 has been removed and we need to stop testing
it with client plugin.

Change-Id: I6fd022ea6cabfb7fadf49152babd215e07f8bec1
This commit is contained in:
Rabi Mishra 2019-09-18 09:51:21 +05:30
parent bb44f779fb
commit 1ab29a42e3
6 changed files with 20 additions and 831 deletions

View File

@ -13,8 +13,12 @@
from designateclient import client
from designateclient import exceptions
from designateclient.v1 import domains
from designateclient.v1 import records
try:
from designateclient.v1 import domains
from designateclient.v1 import records
except ImportError:
pass
from heat.common import exception as heat_exception
from heat.engine.clients import client_plugin
@ -31,7 +35,7 @@ class DesignateClientPlugin(client_plugin.ClientPlugin):
supported_versions = [V1, V2] = ['1', '2']
default_version = V1
default_version = V2
def _create(self, version=default_version):
endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type')

View File

@ -161,8 +161,13 @@ class CinderVolume(vb.BaseVolume, sh.SchedulerHintsMixin):
MULTI_ATTACH: properties.Schema(
properties.Schema.BOOLEAN,
_('Whether allow the volume to be attached more than once.'),
support_status=support.SupportStatus(version='6.0.0'),
default=False
default=False,
support_status=support.SupportStatus(
status=support.HIDDEN,
version='13.0.0',
previous_status=support.SupportStatus(
status=support.SUPPORTED,
version='6.0.0'))
),
}
@ -290,7 +295,7 @@ class CinderVolume(vb.BaseVolume, sh.SchedulerHintsMixin):
arguments['imageRef'] = self.properties[self.IMAGE_REF]
optionals = (self.SNAPSHOT_ID, self.VOLUME_TYPE, self.SOURCE_VOLID,
self.METADATA, self.MULTI_ATTACH)
self.METADATA)
arguments.update((prop, self.properties[prop]) for prop in optionals
if self.properties[prop] is not None)

View File

@ -11,36 +11,14 @@
# License for the specific language governing permissions and limitations
# under the License.
from designateclient import exceptions as designate_exceptions
from designateclient import v1 as designate_client
from designateclient import client as designate_client
import mock
import six
from heat.common import exception as heat_exception
from heat.engine.clients.os import designate as client
from heat.tests import common
class DesignateDomainConstraintTest(common.HeatTestCase):
def test_expected_exceptions(self):
self.assertEqual((heat_exception.EntityNotFound,),
client.DesignateDomainConstraint.expected_exceptions,
"DesignateDomainConstraint expected exceptions error")
def test_constrain(self):
constrain = client.DesignateDomainConstraint()
client_mock = mock.MagicMock()
client_plugin_mock = mock.MagicMock()
client_plugin_mock.get_domain_id.return_value = None
client_mock.client_plugin.return_value = client_plugin_mock
self.assertIsNone(constrain.validate_with_client(client_mock,
'domain_1'))
client_plugin_mock.get_domain_id.assert_called_once_with('domain_1')
class DesignateClientPluginTest(common.HeatTestCase):
@mock.patch.object(designate_client, 'Client')
@ -56,267 +34,8 @@ class DesignateClientPluginTest(common.HeatTestCase):
# Make sure proper client is created with expected args
client_designate.assert_called_once_with(
endpoint_type='publicURL', service_type='dns',
session=session, region_name='region1'
)
class DesignateClientPluginDomainTest(common.HeatTestCase):
sample_uuid = '477e8273-60a7-4c41-b683-fdb0bc7cd152'
sample_name = 'test-domain.com'
def _get_mock_domain(self):
domain = mock.MagicMock()
domain.id = self.sample_uuid
domain.name = self.sample_name
return domain
def setUp(self):
super(DesignateClientPluginDomainTest, self).setUp()
self._client = mock.MagicMock()
self.client_plugin = client.DesignateClientPlugin(
context=mock.MagicMock()
)
@mock.patch.object(client.DesignateClientPlugin, 'client')
def test_get_domain_id(self, client_designate):
self._client.domains.get.return_value = self._get_mock_domain()
client_designate.return_value = self._client
self.assertEqual(self.sample_uuid,
self.client_plugin.get_domain_id(self.sample_uuid))
self._client.domains.get.assert_called_once_with(
self.sample_uuid)
@mock.patch.object(client.DesignateClientPlugin, 'client')
def test_get_domain_id_not_found(self, client_designate):
self._client.domains.get.side_effect = (designate_exceptions
.NotFound)
client_designate.return_value = self._client
ex = self.assertRaises(heat_exception.EntityNotFound,
self.client_plugin.get_domain_id,
self.sample_uuid)
msg = ("The Designate Domain (%(name)s) could not be found." %
{'name': self.sample_uuid})
self.assertEqual(msg, six.text_type(ex))
self._client.domains.get.assert_called_once_with(
self.sample_uuid)
@mock.patch.object(client.DesignateClientPlugin, 'client')
def test_get_domain_id_by_name(self, client_designate):
self._client.domains.get.side_effect = (designate_exceptions
.NotFound)
self._client.domains.list.return_value = [self._get_mock_domain()]
client_designate.return_value = self._client
self.assertEqual(self.sample_uuid,
self.client_plugin.get_domain_id(self.sample_name))
self._client.domains.get.assert_called_once_with(
self.sample_name)
self._client.domains.list.assert_called_once_with()
@mock.patch.object(client.DesignateClientPlugin, 'client')
def test_get_domain_id_by_name_not_found(self, client_designate):
self._client.domains.get.side_effect = (designate_exceptions
.NotFound)
self._client.domains.list.return_value = []
client_designate.return_value = self._client
ex = self.assertRaises(heat_exception.EntityNotFound,
self.client_plugin.get_domain_id,
self.sample_name)
msg = ("The Designate Domain (%(name)s) could not be found." %
{'name': self.sample_name})
self.assertEqual(msg, six.text_type(ex))
self._client.domains.get.assert_called_once_with(
self.sample_name)
self._client.domains.list.assert_called_once_with()
@mock.patch.object(client.DesignateClientPlugin, 'client')
@mock.patch('designateclient.v1.domains.Domain')
def test_domain_create(self, mock_domain, client_designate):
self._client.domains.create.return_value = None
client_designate.return_value = self._client
domain = dict(
name='test-domain.com',
description='updated description',
ttl=4200,
email='xyz@test-domain.com'
)
mock_sample_domain = mock.Mock()
mock_domain.return_value = mock_sample_domain
self.client_plugin.domain_create(**domain)
# Make sure domain entity is created with right arguments
mock_domain.assert_called_once_with(**domain)
self._client.domains.create.assert_called_once_with(
mock_sample_domain)
@mock.patch.object(client.DesignateClientPlugin, 'client')
def test_domain_update(self, client_designate):
self._client.domains.update.return_value = None
mock_domain = self._get_mock_domain()
self._client.domains.get.return_value = mock_domain
client_designate.return_value = self._client
domain = dict(
id='sample-id',
description='updated description',
ttl=4200,
email='xyz@test-domain.com'
)
self.client_plugin.domain_update(**domain)
self._client.domains.get.assert_called_once_with(
mock_domain.id)
for key in domain.keys():
setattr(mock_domain, key, domain[key])
self._client.domains.update.assert_called_once_with(
mock_domain)
class DesignateClientPluginRecordTest(common.HeatTestCase):
sample_uuid = '477e8273-60a7-4c41-b683-fdb0bc7cd152'
sample_domain_id = '477e8273-60a7-4c41-b683-fdb0bc7cd153'
def _get_mock_record(self):
record = mock.MagicMock()
record.id = self.sample_uuid
record.domain_id = self.sample_domain_id
return record
def setUp(self):
super(DesignateClientPluginRecordTest, self).setUp()
self._client = mock.MagicMock()
self.client_plugin = client.DesignateClientPlugin(
context=mock.MagicMock()
)
self.client_plugin.get_domain_id = mock.Mock(
return_value=self.sample_domain_id)
@mock.patch.object(client.DesignateClientPlugin, 'client')
@mock.patch('designateclient.v1.records.Record')
def test_record_create(self, mock_record, client_designate):
self._client.records.create.return_value = None
client_designate.return_value = self._client
record = dict(
name='test-record.com',
description='updated description',
ttl=4200,
type='',
priority=1,
data='1.1.1.1',
domain=self.sample_domain_id
)
mock_sample_record = mock.Mock()
mock_record.return_value = mock_sample_record
self.client_plugin.record_create(**record)
# Make sure record entity is created with right arguments
domain_id = record.pop('domain')
mock_record.assert_called_once_with(**record)
self._client.records.create.assert_called_once_with(
domain_id,
mock_sample_record)
@mock.patch.object(client.DesignateClientPlugin, 'client')
@mock.patch('designateclient.v1.records.Record')
def test_record_update(self, mock_record, client_designate):
self._client.records.update.return_value = None
mock_record = self._get_mock_record()
self._client.records.get.return_value = mock_record
client_designate.return_value = self._client
record = dict(
id=self.sample_uuid,
name='test-record.com',
description='updated description',
ttl=4200,
type='',
priority=1,
data='1.1.1.1',
domain=self.sample_domain_id
)
self.client_plugin.record_update(**record)
self._client.records.get.assert_called_once_with(
self.sample_domain_id,
self.sample_uuid)
for key in record.keys():
setattr(mock_record, key, record[key])
self._client.records.update.assert_called_once_with(
self.sample_domain_id,
mock_record)
@mock.patch.object(client.DesignateClientPlugin, 'client')
@mock.patch('designateclient.v1.records.Record')
def test_record_delete(self, mock_record, client_designate):
self._client.records.delete.return_value = None
client_designate.return_value = self._client
record = dict(
id=self.sample_uuid,
domain=self.sample_domain_id
)
self.client_plugin.record_delete(**record)
self._client.records.delete.assert_called_once_with(
self.sample_domain_id,
self.sample_uuid)
@mock.patch.object(client.DesignateClientPlugin, 'client')
@mock.patch('designateclient.v1.records.Record')
def test_record_delete_domain_not_found(self, mock_record,
client_designate):
self._client.records.delete.return_value = None
self.client_plugin.get_domain_id.side_effect = (
heat_exception.EntityNotFound)
client_designate.return_value = self._client
record = dict(
id=self.sample_uuid,
domain=self.sample_domain_id
)
self.client_plugin.record_delete(**record)
self.assertFalse(self._client.records.delete.called)
@mock.patch.object(client.DesignateClientPlugin, 'client')
@mock.patch('designateclient.v1.records.Record')
def test_record_show(self, mock_record, client_designate):
self._client.records.get.return_value = None
client_designate.return_value = self._client
record = dict(
id=self.sample_uuid,
domain=self.sample_domain_id
)
self.client_plugin.record_show(**record)
self._client.records.get.assert_called_once_with(
self.sample_domain_id,
self.sample_uuid)
session=session, region_name='region1',
version='2')
class DesignateZoneConstraintTest(common.HeatTestCase):

View File

@ -65,7 +65,6 @@ resources:
availability_zone: nova
size: 1
name: test_name
multiattach: True
attachment:
type: OS::Cinder::VolumeAttachment
properties:
@ -144,8 +143,7 @@ class CinderVolumeTest(vt_base.VolumeTestCase):
description='test_description',
name='test_name',
metadata={'key': 'value'},
volume_type='lvm',
multiattach=False)
volume_type='lvm')
self.assertEqual(2, self.cinder_fc.volumes.get.call_count)
def test_cinder_create_from_image(self):
@ -176,7 +174,6 @@ class CinderVolumeTest(vt_base.VolumeTestCase):
description='ImageVolumeDescription',
name='ImageVolume',
imageRef=image_id,
multiattach=False,
metadata={})
self.assertEqual(2, self.cinder_fc.volumes.get.call_count)
@ -208,7 +205,6 @@ class CinderVolumeTest(vt_base.VolumeTestCase):
size=1, availability_zone='nova',
description='ImageVolumeDescription',
name='ImageVolume',
multiattach=False,
metadata={})
self.cinder_fc.volumes.get.assert_called_once_with(fv.id)
@ -232,7 +228,6 @@ class CinderVolumeTest(vt_base.VolumeTestCase):
size=1, availability_zone='nova',
description=None,
name=vol_name,
multiattach=False,
metadata={}
)
self.assertEqual(2, self.cinder_fc.volumes.get.call_count)
@ -246,7 +241,7 @@ class CinderVolumeTest(vt_base.VolumeTestCase):
description='desc', volume_type='lvm',
metadata={'key': 'value'}, source_volid=None,
bootable=False, created_at='2013-02-25T02:40:21.000000',
encrypted=False, attachments=[], multiattach=False)
encrypted=False, attachments=[])
self._mock_create_volume(vt_base.FakeVolume('creating'),
self.stack_name,
@ -273,7 +268,6 @@ class CinderVolumeTest(vt_base.VolumeTestCase):
self.assertEqual(u'False', rsrc.FnGetAtt('encrypted'))
self.assertEqual(u'[]', rsrc.FnGetAtt('attachments'))
self.assertEqual([], rsrc.FnGetAtt('attachments_list'))
self.assertEqual('False', rsrc.FnGetAtt('multiattach'))
error = self.assertRaises(exception.InvalidTemplateAttribute,
rsrc.FnGetAtt, 'unknown')
self.assertEqual(
@ -577,7 +571,6 @@ class CinderVolumeTest(vt_base.VolumeTestCase):
size=1, availability_zone='nova',
description='test_description',
name='test_name',
multiattach=False,
metadata={u'key': u'value'})
self.cinder_fc.volumes.get.assert_called_with(fv.id)
@ -617,7 +610,6 @@ class CinderVolumeTest(vt_base.VolumeTestCase):
size=2, availability_zone='nova',
description=None,
name=vol_name,
multiattach=False,
metadata={}
)
self.cinder_fc.volumes.extend.assert_called_once_with(fv.id, 3)
@ -720,7 +712,6 @@ class CinderVolumeTest(vt_base.VolumeTestCase):
size=1, availability_zone=None,
description='test_description',
name='test_name',
multiattach=False,
metadata={}
)
self.cinder_fc.backups.create.assert_called_once_with(fv.id,
@ -763,7 +754,6 @@ class CinderVolumeTest(vt_base.VolumeTestCase):
size=1, availability_zone=None,
description='test_description',
name='test_name',
multiattach=False,
metadata={}
)
self.cinder_fc.backups.create.assert_called_once_with(
@ -857,7 +847,6 @@ class CinderVolumeTest(vt_base.VolumeTestCase):
size=2, availability_zone='nova',
description=None,
name=vol2_name,
multiattach=False,
metadata={}
)
self.fc.volumes.get_server_volume.assert_called_with(
@ -938,29 +927,10 @@ class CinderVolumeTest(vt_base.VolumeTestCase):
size=1, name='test_name', description=None,
availability_zone='nova',
scheduler_hints={'hint1': 'good_advice'},
multiattach=False,
metadata={}
)
self.assertEqual(2, self.cinder_fc.volumes.get.call_count)
def test_cinder_create_with_multiattach(self):
fv = vt_base.FakeVolume('creating')
self.cinder_fc.volumes.create.return_value = fv
fv_ready = vt_base.FakeVolume('available', id=fv.id)
self.cinder_fc.volumes.get.side_effect = [fv, fv_ready]
self.stack_name = 'test_cvolume_multiattach_stack'
stack = utils.parse_stack(self.t, stack_name=self.stack_name)
self.create_volume(self.t, stack, 'volume4')
self.cinder_fc.volumes.create.assert_called_once_with(
size=1, name='test_name', description=None,
availability_zone='nova',
multiattach=True,
metadata={})
self.assertEqual(2, self.cinder_fc.volumes.get.call_count)
def test_cinder_create_with_stack_scheduler_hints(self):
fv = vt_base.FakeVolume('creating')
sh.cfg.CONF.set_override('stack_scheduler_hints', True)
@ -989,7 +959,6 @@ class CinderVolumeTest(vt_base.VolumeTestCase):
size=1, name='test_name', description='test_description',
availability_zone=None,
metadata={},
multiattach=False,
scheduler_hints={shm.HEAT_ROOT_STACK_ID: stack.root_stack_id(),
shm.HEAT_STACK_ID: stack.id,
shm.HEAT_STACK_NAME: stack.name,
@ -1171,7 +1140,6 @@ class CinderVolumeTest(vt_base.VolumeTestCase):
size=1, availability_zone=None,
description='test_description',
name='test_name',
multiattach=False,
metadata={}
)
self.cinder_fc.backups.create.assert_called_once_with(
@ -1244,7 +1212,6 @@ class CinderVolumeTest(vt_base.VolumeTestCase):
'volume_image_metadata': {'image_id': '1234',
'image_name': 'test'},
'description': None,
'multiattach': False,
'source_volid': None,
'name': 'test-volume-jbdbgdsy3vyg',
'volume_type': 'lvmdriver-1'

View File

@ -1,216 +0,0 @@
#
# 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 mock
from designateclient import exceptions as designate_exception
from designateclient.v1 import domains
from heat.engine.resources.openstack.designate import domain
from heat.engine import stack
from heat.engine import template
from heat.tests import common
from heat.tests import utils
sample_template = {
'heat_template_version': '2015-04-30',
'resources': {
'test_resource': {
'type': 'OS::Designate::Domain',
'properties': {
'name': 'test-domain.com',
'description': 'Test domain',
'ttl': 3600,
'email': 'abc@test-domain.com'
}
}
}
}
class DesignateDomainTest(common.HeatTestCase):
def setUp(self):
super(DesignateDomainTest, self).setUp()
self.ctx = utils.dummy_context()
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)
def _get_mock_resource(self):
value = mock.MagicMock()
value.id = '477e8273-60a7-4c41-b683-fdb0bc7cd152'
value.serial = '1434596972'
return value
def test_resource_handle_create(self):
mock_domain_create = self.test_client_plugin.domain_create
mock_resource = self._get_mock_resource()
mock_domain_create.return_value = mock_resource
# validate the properties
self.assertEqual(
'test-domain.com',
self.test_resource.properties.get(domain.DesignateDomain.NAME))
self.assertEqual(
'Test domain',
self.test_resource.properties.get(
domain.DesignateDomain.DESCRIPTION))
self.assertEqual(
3600,
self.test_resource.properties.get(domain.DesignateDomain.TTL))
self.assertEqual(
'abc@test-domain.com',
self.test_resource.properties.get(domain.DesignateDomain.EMAIL))
self.test_resource.data_set = mock.Mock()
self.test_resource.handle_create()
args = dict(
name='test-domain.com',
description='Test domain',
ttl=3600,
email='abc@test-domain.com'
)
mock_domain_create.assert_called_once_with(**args)
# validate physical resource id
self.assertEqual(mock_resource.id, self.test_resource.resource_id)
def test_resource_handle_update(self):
mock_domain_update = self.test_client_plugin.domain_update
self.test_resource.resource_id = '477e8273-60a7-4c41-b683-fdb0bc7cd151'
prop_diff = {domain.DesignateDomain.EMAIL: 'xyz@test-domain.com',
domain.DesignateDomain.DESCRIPTION: 'updated description',
domain.DesignateDomain.TTL: 4200}
self.test_resource.handle_update(json_snippet=None,
tmpl_diff=None,
prop_diff=prop_diff)
args = dict(
id=self.test_resource.resource_id,
description='updated description',
ttl=4200,
email='xyz@test-domain.com'
)
mock_domain_update.assert_called_once_with(**args)
def test_resource_handle_delete(self):
mock_domain_delete = self.test_client.domains.delete
self.test_resource.resource_id = '477e8273-60a7-4c41-b683-fdb0bc7cd151'
mock_domain_delete.return_value = None
self.assertEqual('477e8273-60a7-4c41-b683-fdb0bc7cd151',
self.test_resource.handle_delete())
mock_domain_delete.assert_called_once_with(
self.test_resource.resource_id
)
def test_resource_handle_delete_resource_id_is_none(self):
self.test_resource.resource_id = None
self.assertIsNone(self.test_resource.handle_delete())
def test_resource_handle_delete_not_found(self):
mock_domain_delete = self.test_client.domains.delete
mock_domain_delete.side_effect = designate_exception.NotFound
self.assertIsNone(self.test_resource.handle_delete())
def test_resolve_attributes(self):
mock_domain = self._get_mock_resource()
self.test_resource.resource_id = mock_domain.id
self.test_client.domains.get.return_value = mock_domain
self.assertEqual(mock_domain.serial,
self.test_resource._resolve_attribute(
domain.DesignateDomain.SERIAL
))
self.test_client.domains.get.assert_called_once_with(
self.test_resource.resource_id
)
def test_resource_show_resource(self):
args = dict(
name='test',
description='updated description',
ttl=4200,
email='xyz@test-domain.com'
)
rsc = domains.Domain(args)
mock_notification_get = self.test_client.domains.get
mock_notification_get.return_value = rsc
self.assertEqual(args,
self.test_resource._show_resource(),
'Failed to show resource')
def test_no_ttl(self):
mock_domain_create = self.test_client_plugin.domain_create
mock_resource = self._get_mock_resource()
mock_domain_create.return_value = mock_resource
self.test_resource.properties.data['ttl'] = None
self.test_resource.handle_create()
mock_domain_create.assert_called_once_with(
name='test-domain.com', description='Test domain',
email='abc@test-domain.com')
def test_domain_get_live_state(self):
return_domain = {
'name': 'test-domain.com',
'description': 'Test domain',
'ttl': 3600,
'email': 'abc@test-domain.com'
}
self.test_client.domains.get.return_value = return_domain
self.test_resource.resource_id = '1234'
reality = self.test_resource.get_live_state(
self.test_resource.properties)
self.assertEqual(return_domain, reality)
def test_domain_get_live_state_ttl_equals_zero(self):
return_domain = {
'name': 'test-domain.com',
'description': 'Test domain',
'ttl': 0,
'email': 'abc@test-domain.com'
}
self.test_client.domains.get.return_value = return_domain
self.test_resource.resource_id = '1234'
reality = self.test_resource.get_live_state(
self.test_resource.properties)
self.assertEqual(return_domain, reality)

View File

@ -1,290 +0,0 @@
#
# 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 designateclient import exceptions as designate_exception
from designateclient.v1 import records
import mock
from heat.engine.resources.openstack.designate import record
from heat.engine import stack
from heat.engine import template
from heat.tests import common
from heat.tests import utils
sample_template = {
'heat_template_version': '2015-04-30',
'resources': {
'test_resource': {
'type': 'OS::Designate::Record',
'properties': {
'name': 'test-record.com',
'description': 'Test record',
'ttl': 3600,
'type': 'MX',
'priority': 1,
'data': '1.1.1.1',
'domain': '1234567'
}
}
}
}
class DesignateRecordTest(common.HeatTestCase):
def setUp(self):
super(DesignateRecordTest, self).setUp()
self.ctx = utils.dummy_context()
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)
def _get_mock_resource(self):
value = mock.MagicMock()
value.id = '477e8273-60a7-4c41-b683-fdb0bc7cd152'
return value
def test_resource_validate_properties(self):
mock_record_create = self.test_client_plugin.record_create
mock_resource = self._get_mock_resource()
mock_record_create.return_value = mock_resource
# validate the properties
self.assertEqual(
'test-record.com',
self.test_resource.properties.get(record.DesignateRecord.NAME))
self.assertEqual(
'Test record',
self.test_resource.properties.get(
record.DesignateRecord.DESCRIPTION))
self.assertEqual(
3600,
self.test_resource.properties.get(record.DesignateRecord.TTL))
self.assertEqual(
'MX',
self.test_resource.properties.get(record.DesignateRecord.TYPE))
self.assertEqual(
1,
self.test_resource.properties.get(record.DesignateRecord.PRIORITY))
self.assertEqual(
'1.1.1.1',
self.test_resource.properties.get(record.DesignateRecord.DATA))
self.assertEqual(
'1234567',
self.test_resource.properties.get(
record.DesignateRecord.DOMAIN))
def test_resource_handle_create_non_mx_or_srv(self):
mock_record_create = self.test_client_plugin.record_create
mock_resource = self._get_mock_resource()
mock_record_create.return_value = mock_resource
for type in (set(self.test_resource._ALLOWED_TYPES) -
set([self.test_resource.MX,
self.test_resource.SRV])):
self.test_resource.properties = args = dict(
name='test-record.com',
description='Test record',
ttl=3600,
type=type,
priority=1,
data='1.1.1.1',
domain='1234567'
)
self.test_resource.handle_create()
# Make sure priority is set to None for non mx or srv records
args['priority'] = None
mock_record_create.assert_called_with(
**args
)
# validate physical resource id
self.assertEqual(mock_resource.id, self.test_resource.resource_id)
def test_resource_handle_create_mx_or_srv(self):
mock_record_create = self.test_client_plugin.record_create
mock_resource = self._get_mock_resource()
mock_record_create.return_value = mock_resource
for type in [self.test_resource.MX, self.test_resource.SRV]:
self.test_resource.properties = args = dict(
name='test-record.com',
description='Test record',
ttl=3600,
type=type,
priority=1,
data='1.1.1.1',
domain='1234567'
)
self.test_resource.handle_create()
mock_record_create.assert_called_with(
**args
)
# validate physical resource id
self.assertEqual(mock_resource.id, self.test_resource.resource_id)
def test_resource_handle_update_non_mx_or_srv(self):
mock_record_update = self.test_client_plugin.record_update
self.test_resource.resource_id = '477e8273-60a7-4c41-b683-fdb0bc7cd151'
for type in (set(self.test_resource._ALLOWED_TYPES) -
set([self.test_resource.MX,
self.test_resource.SRV])):
prop_diff = args = {
record.DesignateRecord.DESCRIPTION: 'updated description',
record.DesignateRecord.TTL: 4200,
record.DesignateRecord.TYPE: type,
record.DesignateRecord.DATA: '2.2.2.2',
record.DesignateRecord.PRIORITY: 1}
self.test_resource.handle_update(json_snippet=None,
tmpl_diff=None,
prop_diff=prop_diff)
# priority is not considered for records other than mx or srv
args.update(dict(
id=self.test_resource.resource_id,
priority=None,
domain='1234567',
))
mock_record_update.assert_called_with(**args)
def test_resource_handle_update_mx_or_srv(self):
mock_record_update = self.test_client_plugin.record_update
self.test_resource.resource_id = '477e8273-60a7-4c41-b683-fdb0bc7cd151'
for type in [self.test_resource.MX, self.test_resource.SRV]:
prop_diff = args = {
record.DesignateRecord.DESCRIPTION: 'updated description',
record.DesignateRecord.TTL: 4200,
record.DesignateRecord.TYPE: type,
record.DesignateRecord.DATA: '2.2.2.2',
record.DesignateRecord.PRIORITY: 1}
self.test_resource.handle_update(json_snippet=None,
tmpl_diff=None,
prop_diff=prop_diff)
args.update(dict(
id=self.test_resource.resource_id,
domain='1234567',
))
mock_record_update.assert_called_with(**args)
def test_resource_handle_delete(self):
mock_record_delete = self.test_client_plugin.record_delete
self.test_resource.resource_id = '477e8273-60a7-4c41-b683-fdb0bc7cd151'
mock_record_delete.return_value = None
self.assertIsNone(self.test_resource.handle_delete())
mock_record_delete.assert_called_once_with(
domain='1234567',
id=self.test_resource.resource_id
)
def test_resource_handle_delete_resource_id_is_none(self):
self.test_resource.resource_id = None
self.assertIsNone(self.test_resource.handle_delete())
def test_resource_handle_delete_not_found(self):
mock_record_delete = self.test_client_plugin.record_delete
mock_record_delete.side_effect = designate_exception.NotFound
self.assertIsNone(self.test_resource.handle_delete())
def test_resource_show_resource(self):
args = dict(
name='test-record.com',
description='Test record',
ttl=3600,
type='A',
priority=1,
data='1.1.1.1'
)
rsc = records.Record(args)
mock_notification_get = self.test_client_plugin.record_show
mock_notification_get.return_value = rsc
self.assertEqual(args,
self.test_resource._show_resource(),
'Failed to show resource')
def test_resource_get_live_state(self):
tmpl = {
'heat_template_version': '2015-04-30',
'resources': {
'test_resource': {
'type': 'OS::Designate::Record',
'properties': {
'name': 'test-record.com',
'description': 'Test record',
'ttl': 3600,
'type': 'MX',
'priority': 1,
'data': '1.1.1.1',
'domain': 'example.com.'
}
}
}
}
s = stack.Stack(
self.ctx, 'test_stack',
template.Template(tmpl)
)
test_resource = s['test_resource']
test_resource.resource_id = '1234'
test_resource.client_plugin().get_domain_id = mock.MagicMock()
test_resource.client_plugin().get_domain_id.return_value = '1234567'
test_resource.client().records = mock.MagicMock()
test_resource.client().records.get.return_value = {
'type': 'MX',
'data': '1.1.1.1',
'ttl': 3600,
'description': 'test',
'domain_id': '1234567',
'name': 'www.example.com.',
'priority': 0
}
reality = test_resource.get_live_state(test_resource.properties)
expected = {
'type': 'MX',
'data': '1.1.1.1',
'ttl': 3600,
'description': 'test',
'priority': 0
}
self.assertEqual(expected, reality)