manila resources observe reality implementation

Add override parse_live_resource_data method implementation for
manila resources' plugins.

implements bp get-reality-for-resources

Change-Id: I32b5906ab2f28dd480792707e555f854fef64063
This commit is contained in:
Peter Razumovsky 2016-02-02 21:16:20 +03:00
parent 7930886f07
commit f4e8bfcf4b
6 changed files with 140 additions and 6 deletions

View File

@ -338,6 +338,18 @@ class ManilaShare(resource.Resource):
access_level=rule.get(self.ACCESS_LEVEL)
)
def parse_live_resource_data(self, resource_properties, resource_data):
result = super(ManilaShare, self).parse_live_resource_data(
resource_properties, resource_data)
rules = self.client().shares.access_list(self.resource_id)
result[self.ACCESS_RULES] = []
for rule in rules:
result[self.ACCESS_RULES].append(
{(k, v) for (k, v) in six.iteritems(rule)
if k in self._ACCESS_RULE_PROPERTIES})
return result
def resource_mapping():
return {'OS::Manila::Share': ManilaShare}

View File

@ -237,6 +237,19 @@ class ManilaShareNetwork(resource.Resource):
nova_net_id=prop_diff.get(self.NOVA_NETWORK),
description=prop_diff.get(self.DESCRIPTION))
def parse_live_resource_data(self, resource_properties, resource_data):
result = super(ManilaShareNetwork, self).parse_live_resource_data(
resource_properties, resource_data)
sec_list = self.client().security_services.list(
search_opts={'share_network_id': self.resource_id})
result.update({
self.NOVA_NETWORK: resource_data.get('nova_net_id'),
self.NEUTRON_NETWORK: resource_data.get('neutron_net_id'),
self.NEUTRON_SUBNET: resource_data.get('neutron_subnet_id'),
self.SECURITY_SERVICES: [service.id for service in sec_list]}
)
return result
def resource_mapping():
return {'OS::Manila::ShareNetwork': ManilaShareNetwork}

View File

@ -96,6 +96,12 @@ class ManilaShareType(resource.Resource):
share_type.unset_keys(extra_specs_old)
share_type.set_keys(prop_diff.get(self.EXTRA_SPECS))
def parse_live_resource_data(self, resource_properties, resource_data):
extra_specs = resource_data.pop(self.EXTRA_SPECS)
extra_specs.pop(self.SNAPSHOT_SUPPORT)
extra_specs.pop(self.DRIVER_HANDLES_SHARE_SERVERS)
return {self.EXTRA_SPECS: extra_specs}
def resource_mapping():
return {

View File

@ -76,14 +76,12 @@ class ManilaShareTest(common.HeatTestCase):
self.stack = utils.parse_stack(tmp, stack_name=stack_name)
res_def = self.stack.t.resource_definitions(self.stack)["test_share"]
share = mshare.ManilaShare("test_share", res_def, self.stack)
self.patchobject(share, 'data_set')
# replace clients and plugins with mocks
mock_client = mock.MagicMock()
client = mock.MagicMock(return_value=mock_client)
share.client = client
mock_plugin = mock.MagicMock()
client_plugin = mock.MagicMock(return_value=mock_plugin)
share.client_plugin = client_plugin
return share
@ -233,3 +231,51 @@ class ManilaShareTest(common.HeatTestCase):
exception.StackValidationFailed,
".* \"domain\" is not an allowed value \[ip, user, cert, cephx\]",
stack.validate)
def test_get_live_state(self):
share = self._create_share("share")
value = mock.MagicMock()
value.to_dict.return_value = {
'status': 'available',
'size': 1,
'description': None,
'share_proto': 'NFS',
'name': 'testshare',
'share_type': 'default',
'availability_zone': 'nova',
'created_at': '2016-02-04T10:20:52.000000',
'export_location': 'dummy',
'share_network_id': '5f0a3c90-36ef-4e92-8142-06afd6be2881',
'export_locations': ['dummy'],
'share_server_id': 'fcb9d90d-76e6-466f-a0cb-23e254ccc16c',
'host': 'ubuntu@generic1#GENERIC1',
'volume_type': 'default',
'snapshot_id': None,
'is_public': False,
'project_id': '221b4f51e9bd4f659845f657a3051a46',
'id': '3a68e59d-11c1-4da4-a102-03fc9448613e',
'metadata': {}}
share.client().shares.get.return_value = value
share.client().shares.access_list.return_value = [
{'access_to': '0.0.0.0', 'access_type': 'ip', 'access_level': 'r'}]
share.data = mock.MagicMock(return_value={'share_type': 'default'})
reality = share.get_live_state(share.properties)
expected = {
'description': None,
'name': 'testshare',
'is_public': False,
'metadata': {},
'access_rules': [{'access_to': '0.0.0.0',
'access_type': 'ip',
'access_level': 'r'}]}
self.assertEqual(set(expected.keys()), set(reality.keys()))
exp_rules = expected.pop('access_rules')
real_rules = reality.pop('access_rules')
self.assertEqual([set(rule.items()) for rule in exp_rules],
real_rules)
for key in expected:
self.assertEqual(expected[key], reality[key])

View File

@ -293,3 +293,39 @@ class ManilaShareNetworkTest(common.HeatTestCase):
self.assertEqual('3', net.FnGetAtt('cidr'))
self.assertEqual('5', net.FnGetAtt('ip_version'))
self.assertEqual('6', net.FnGetAtt('network_type'))
def test_get_live_state(self):
net = self._create_network('share_network', self.rsrc_defn,
self.stack)
value = mock.MagicMock()
value.to_dict.return_value = {
'name': 'test',
'segmentation_id': '123',
'created_at': '2016-02-02T18:40:24.000000',
'neutron_subnet_id': None,
'updated_at': None,
'network_type': None,
'neutron_net_id': '4321',
'ip_version': None,
'nova_net_id': None,
'cidr': None,
'project_id': '221b4f51e9bd4f659845f657a3051a46',
'id': '4000d1c7-1017-4ea2-a4a1-951d8b63857a',
'description': None}
self.client.share_networks.get.return_value = value
self.client.security_services.list.return_value = [mock.Mock(id='6'),
mock.Mock(id='7')]
reality = net.get_live_state(net.properties)
expected = {
'name': 'test',
'neutron_subnet': None,
'neutron_network': '4321',
'nova_network': None,
'description': None,
'security_services': ['6', '7']
}
self.assertEqual(expected, reality)

View File

@ -55,9 +55,6 @@ class ManilaShareTypeTest(common.HeatTestCase):
mock_client = mock.MagicMock()
client = mock.MagicMock(return_value=mock_client)
share_type.client = client
mock_plugin = mock.MagicMock()
client_plugin = mock.MagicMock(return_value=mock_plugin)
share_type.client_plugin = client_plugin
return share_type
@ -89,3 +86,27 @@ class ManilaShareTypeTest(common.HeatTestCase):
fake_share_type.unset_keys.assert_called_once_with({"test": "test"})
fake_share_type.set_keys.assert_called_with(
updated_props[mshare_type.ManilaShareType.EXTRA_SPECS])
def test_get_live_state(self):
share_type = self._init_share("stack_share_type_update")
value = mock.MagicMock()
value.to_dict.return_value = {
'os-share-type-access:is_public': True,
'required_extra_specs': {},
'extra_specs': {'test': 'test',
'snapshot_support': 'True',
'driver_handles_share_servers': 'True'},
'id': 'cc76cb22-75fe-4e6e-b618-7c345b2444e3',
'name': 'test'}
share_type.client().share_types.get.return_value = value
reality = share_type.get_live_state(share_type.properties)
expected = {
'extra_specs': {'test': 'test'}
}
self.assertEqual(set(expected.keys()), set(reality.keys()))
for key in expected:
self.assertEqual(expected[key], reality[key])