Add 'bind' option in plugin components

Plugin should have possibility to bind cluster attributes.

Change-Id: I02466818150df827a9131f814da90f3a6e850ab1
Closes-Bug: #1523981
This commit is contained in:
Andriy Popovych 2015-12-16 00:25:59 +02:00 committed by Andriy Popovych
parent e7fa62d6a2
commit f1fe48241a
5 changed files with 59 additions and 11 deletions

View File

@ -229,7 +229,7 @@ class Cluster(NailgunObject):
release = Release.get_by_uid(release_id)
cluster_attributes = {}
for component in release.components_metadata:
for component in Release.get_all_components(release):
if component['name'] in components:
for bind_item in component.get('bind', []):
if isinstance(bind_item, six.string_types):

View File

@ -112,6 +112,10 @@ class PluginAdapterBase(object):
return set()
return set([rel['version'] for rel in self.plugin.releases])
@property
def name(self):
return self.plugin.name
@property
def full_name(self):
return u'{0}-{1}'.format(self.plugin.name, self.plugin.version)

View File

@ -330,18 +330,20 @@ class PluginManager(object):
for plugin_adapter in map(
wrap_plugin, PluginCollection.get_by_release(release)):
plugin_name = plugin_adapter.name
for component in plugin_adapter.components_metadata:
name = component['name']
if name in seen_components:
if seen_components.get(name, plugin_name) != plugin_name:
raise errors.AlreadyExists(
'Plugin {0} is overlapping with {1} by introducing '
'the same component with name "{2}"'
.format(plugin_adapter.full_name,
.format(plugin_adapter.name,
seen_components[name],
name))
seen_components[name] = plugin_adapter.full_name
components.append(component)
if name not in seen_components:
seen_components[name] = plugin_adapter.name
components.append(component)
return components

View File

@ -166,7 +166,7 @@ class TestPluginManager(base.BaseIntegrationTest):
PluginManager.sync_plugins_metadata([self.env.plugins[0].id])
self.assertEqual(sync_mock.call_count, 1)
def test_get_components_metadata(self):
def test_get_components(self):
self.env.create_plugin(
name='plugin_with_components',
package_version='4.0.0',
@ -178,6 +178,27 @@ class TestPluginManager(base.BaseIntegrationTest):
self.assertEqual(
components_metadata, self.env.get_default_components())
def test_get_components_for_same_plugins_with_different_verions(self):
self.env.create_plugin(
name='plugin_with_components_to_test_verions',
package_version='4.0.0',
fuel_version=['8.0'],
components_metadata=self.env.get_default_components())
self.env.create_plugin(
name='plugin_with_components_to_test_verions',
version='1.0.0',
package_version='4.0.0',
fuel_version=['8.0'],
components_metadata=self.env.get_default_components())
# PluginManager should return only one component for same plugin
# but different versions
components_metadata = PluginManager.get_components_metadata(
self.release)
self.assertEqual(
components_metadata, self.env.get_default_components())
def test_raise_exception_when_plugin_overlap_release_component(self):
release = self.env.create_release(
version='2015.1-8.1',
@ -197,7 +218,7 @@ class TestPluginManager(base.BaseIntegrationTest):
components_metadata=self.env.get_default_components())
expected_message = (
'Plugin plugin_with_components-0.1.0 is overlapping with release '
'Plugin plugin_with_components is overlapping with release '
'by introducing the same component with name '
'"hypervisor:test_hypervisor"')
@ -219,8 +240,8 @@ class TestPluginManager(base.BaseIntegrationTest):
components_metadata=self.env.get_default_components())
expected_message = (
'Plugin plugin_with_components_2-0.1.0 is overlapping with '
'plugin_with_components_1-0.1.0 by introducing the same component '
'Plugin plugin_with_components_2 is overlapping with '
'plugin_with_components_1 by introducing the same component '
'with name "hypervisor:test_hypervisor"')
with self.assertRaisesRegexp(errors.AlreadyExists,

View File

@ -1344,7 +1344,20 @@ class TestClusterObject(BaseTestCase):
'additional_components': {'sahara': {'value': False}}
}
release = self.env.create_release(components_metadata=components)
release = self.env.create_release(
version='2015.1-8.0',
operating_system=consts.RELEASE_OS.ubuntu,
modes=[consts.CLUSTER_MODES.ha_compact],
components_metadata=components)
self.env.create_plugin(
name='plugin_with_test_network_for_neutron',
package_version='4.0.0',
fuel_version=['8.0'],
components_metadata=self.env.get_default_components(
name='network:neutron:test_network',
bind=[['cluster:net_segment_type', 'tun']]))
tests_data = [{
'selected_components': ['network:neutron:tun',
'hypervisor:libvirt:kvm',
@ -1361,6 +1374,14 @@ class TestClusterObject(BaseTestCase):
'net_provider': consts.CLUSTER_NET_PROVIDERS.nova_network,
'segmentation_type': None
}
}, {
'selected_components': ['network:neutron:test_network',
'hypervisor:libvirt:kvm',
'additional_service:sahara'],
'expected_values': {
'net_provider': consts.CLUSTER_NET_PROVIDERS.neutron,
'segmentation_type': consts.NEUTRON_SEGMENT_TYPES.tun
}
}]
for i, test_data in enumerate(tests_data):
with mock.patch('objects.Cluster.get_default_editable_attributes',
@ -1629,7 +1650,7 @@ class TestRelease(BaseTestCase):
def test_get_all_components(self):
release = self.env.create_release(
version='2015.1-8.0',
operating_system='Ubuntu',
operating_system=consts.RELEASE_OS.ubuntu,
modes=[consts.CLUSTER_MODES.ha_compact],
components_metadata=self.env.get_default_components(
name='hypervisor:test_component_1'))