def test_all_newest(self): for version in ['1.0.0', '2.0.0', '0.0.1']: plugin_data = self.env.get_default_plugin_metadata( version=version, name='multiversion_plugin') Plugin.create(plugin_data) single_plugin_data = self.env.get_default_plugin_metadata( name='single_plugin') Plugin.create(single_plugin_data) newest_plugins = PluginCollection.all_newest() self.assertEqual(len(newest_plugins), 2) single_plugin = filter( lambda p: p.name == 'single_plugin', newest_plugins) multiversion_plugin = filter( lambda p: p.name == 'multiversion_plugin', newest_plugins) self.assertEqual(len(single_plugin), 1) self.assertEqual(len(multiversion_plugin), 1) self.assertEqual(multiversion_plugin[0].version, '2.0.0')
def setUp(self): super(TestMigrationPluginsClusterAttrs, self).setUp() self.cluster = self.env.create() self.plugins = [ Plugin.create(self.env.get_default_plugin_metadata( name='plugin_name_1')), Plugin.create(self.env.get_default_plugin_metadata( name='plugin_name_2'))]
def setUp(self): super(TestMigrationPluginsClusterAttrs, self).setUp() self.cluster = self.env.create() self.plugins = [ Plugin.create( self.env.get_default_plugin_metadata(name='plugin_name_1')), Plugin.create( self.env.get_default_plugin_metadata(name='plugin_name_2')) ]
def test_get_metadata(self): plugin_metadata = self.env.get_default_plugin_metadata() attributes_metadata = self.env.get_default_plugin_env_config() nic_attributes_metadata = self.env.get_default_plugin_nic_config() bond_attributes_metadata = self.env.get_default_plugin_bond_config() node_attributes_metadata = self.env.get_default_plugin_node_config() roles_metadata = self.env.get_default_plugin_node_roles_config() volumes_metadata = self.env.get_default_plugin_volumes_config() network_roles_metadata = self.env.get_default_network_roles_config() deployment_tasks = self.env.get_default_plugin_deployment_tasks() tasks = self.env.get_default_plugin_tasks() components_metadata = self.env.get_default_components() mocked_metadata = { self._find_path('metadata'): plugin_metadata, self._find_path('environment_config'): attributes_metadata, self._find_path('node_roles'): roles_metadata, self._find_path('volumes'): volumes_metadata, self._find_path('network_roles'): network_roles_metadata, self._find_path('deployment_tasks'): deployment_tasks, self._find_path('tasks'): tasks, self._find_path('components'): components_metadata, self._find_path('nic_config'): nic_attributes_metadata, self._find_path('bond_config'): bond_attributes_metadata, self._find_path('node_config'): node_attributes_metadata } with mock.patch.object(self.plugin_adapter, '_load_config') as load_conf: load_conf.side_effect = lambda key: mocked_metadata[key] Plugin.update(self.plugin, self.plugin_adapter.get_metadata()) for key, val in six.iteritems(plugin_metadata): self.assertEqual(getattr(self.plugin, key), val) self.assertEqual(self.plugin.attributes_metadata, attributes_metadata['attributes']) self.assertEqual(self.plugin.roles_metadata, roles_metadata) self.assertEqual(self.plugin.volumes_metadata, volumes_metadata) self.assertEqual(self.plugin.tasks, tasks) self.assertEqual(self.plugin.components_metadata, components_metadata) self.assertEqual(self.plugin.nic_attributes_metadata, nic_attributes_metadata) self.assertEqual(self.plugin.bond_attributes_metadata, bond_attributes_metadata) self.assertEqual(self.plugin.node_attributes_metadata, bond_attributes_metadata) plugin_tasks = self.env.get_default_plugin_deployment_tasks() self.assertGreater(len(plugin_tasks), 0) for k, v in six.iteritems(plugin_tasks[0]): # this field is updated by plugin adapter if k is 'parameters': v.update({'cwd': '/etc/fuel/plugins/testing_plugin-0.1/'}) self.assertEqual( self.plugin_adapter.get_deployment_tasks()[0][k], v)
def test_get_metadata(self): plugin_metadata = self.env.get_default_plugin_metadata() attributes_metadata = self.env.get_default_plugin_env_config() roles_metadata = self.env.get_default_plugin_node_roles_config() volumes_metadata = self.env.get_default_plugin_volumes_config() network_roles_metadata = self.env.get_default_network_roles_config() deployment_tasks = self.env.get_default_plugin_deployment_tasks() tasks = self.env.get_default_plugin_tasks() components_metadata = self.env.get_default_components() mocked_metadata = { self._find_path('metadata'): plugin_metadata, self._find_path('environment_config'): attributes_metadata, self._find_path('node_roles'): roles_metadata, self._find_path('volumes'): volumes_metadata, self._find_path('network_roles'): network_roles_metadata, self._find_path('deployment_tasks'): deployment_tasks, self._find_path('tasks'): tasks, self._find_path('components'): components_metadata } with mock.patch.object( self.plugin_adapter, '_load_config') as load_conf: load_conf.side_effect = lambda key: mocked_metadata[key] Plugin.update(self.plugin, self.plugin_adapter.get_metadata()) for key, val in six.iteritems(plugin_metadata): self.assertEqual( getattr(self.plugin, key), val) self.assertEqual( self.plugin.attributes_metadata, attributes_metadata['attributes']) self.assertEqual( self.plugin.roles_metadata, roles_metadata) self.assertEqual( self.plugin.volumes_metadata, volumes_metadata) self.assertEqual( self.plugin.tasks, tasks) self.assertEqual( self.plugin.components_metadata, components_metadata) # deployment tasks returning all non-defined fields, so check # should differ from JSON-stored fields plugin_tasks = self.env.get_default_plugin_deployment_tasks() self.assertGreater(len(plugin_tasks), 0) for k, v in six.iteritems(plugin_tasks[0]): # this field is updated by plugin adapter if k is 'parameters': v.update({ 'cwd': '/etc/fuel/plugins/testing_plugin-0.1/' }) self.assertEqual( self.plugin_adapter.get_deployment_tasks()[0][k], v)
def validate(cls, data): if data: parsed = super(PluginSyncValidator, cls).validate(data) cls.validate_schema(parsed, plugin.SYNC_SCHEMA) # Check plugin with given id exists in DB # otherwise raise ObjectNotFound exception for plugin_id in parsed.get('ids'): Plugin.get_by_uid(plugin_id, fail_if_not_found=True) return parsed else: return {}
def test_get_metadata(self): plugin_metadata = self.env.get_default_plugin_metadata() attributes_metadata = self.env.get_default_plugin_env_config() roles_metadata = self.env.get_default_plugin_node_roles_config() volumes_metadata = self.env.get_default_plugin_volumes_config() network_roles_metadata = self.env.get_default_network_roles_config() deployment_tasks = self.env.get_default_plugin_deployment_tasks() tasks = self.env.get_default_plugin_tasks() components_metadata = self.env.get_default_components() plugin_metadata.update({ 'attributes_metadata': attributes_metadata, 'roles_metadata': roles_metadata, 'volumes_metadata': volumes_metadata, 'network_roles_metadata': network_roles_metadata, 'deployment_tasks': deployment_tasks, 'tasks': tasks, 'components_metadata': components_metadata }) with mock.patch.object( self.plugin_adapter, 'loader') as loader: loader.load.return_value = (plugin_metadata, ReportNode()) Plugin.update(self.plugin, self.plugin_adapter.get_metadata()) for key, val in six.iteritems(plugin_metadata): if key not in ('deployment_tasks', 'graphs'): self.assertEqual(getattr(self.plugin, key), val) self.assertEqual( self.plugin.attributes_metadata, attributes_metadata['attributes']) self.assertEqual( self.plugin.roles_metadata, roles_metadata) self.assertEqual( self.plugin.volumes_metadata, volumes_metadata) self.assertEqual( self.plugin.tasks, tasks) self.assertEqual( self.plugin.components_metadata, components_metadata) # deployment tasks returning all non-defined fields, so check # should differ from JSON-stored fields plugin_tasks = self.env.get_default_plugin_deployment_tasks() self.assertGreater(len(plugin_tasks), 0) for k, v in six.iteritems(plugin_tasks[0]): # this field is updated by plugin adapter if k is 'parameters': v.update({ 'cwd': '/etc/fuel/plugins/testing_plugin-0.1/' }) self.assertEqual( self.plugin_adapter.get_deployment_tasks()[0][k], v)
def test_get_metadata(self): plugin_metadata = self.env.get_default_plugin_metadata() plugin_metadata['environment_config'] = \ self.env.get_default_plugin_env_config() plugin_metadata['tasks'] = self.env.get_default_plugin_tasks() with mock.patch.object(self.plugin_adapter, 'loader') as loader: loader.load.return_value = plugin_metadata, ReportNode() Plugin.update(self.plugin, self.plugin_adapter.get_metadata()) for key, val in six.iteritems(plugin_metadata): self.assertEqual(getattr(self.plugin, key), val)
def _create_test_plugins(self): plugin_ids = [] for version in ['1.0.0', '2.0.0', '0.0.1', '3.0.0']: plugin_data = self.env.get_default_plugin_metadata( version=version, name='multiversion_plugin') plugin = Plugin.create(plugin_data) plugin_ids.append(plugin.id) single_plugin_data = self.env.get_default_plugin_metadata( name='single_plugin') plugin = Plugin.create(single_plugin_data) plugin_ids.append(plugin.id) return plugin_ids
def test_get_metadata(self): self.maxDiff = None plugin_metadata = self.env.get_default_plugin_metadata() attributes_metadata = self.env.get_default_plugin_env_config() roles_metadata = self.env.get_default_plugin_node_roles_config() volumes_metadata = self.env.get_default_plugin_volumes_config() network_roles_metadata = self.env.get_default_network_roles_config() deployment_tasks = self.env.get_default_plugin_deployment_tasks() tasks = self.env.get_default_plugin_tasks() mocked_metadata = { self._find_path('metadata'): plugin_metadata, self._find_path('environment_config'): attributes_metadata, self._find_path('node_roles'): roles_metadata, self._find_path('volumes'): volumes_metadata, self._find_path('network_roles'): network_roles_metadata, self._find_path('deployment_tasks'): deployment_tasks, self._find_path('tasks'): tasks, } with mock.patch.object( self.plugin_adapter, '_load_config') as load_conf: load_conf.side_effect = lambda key: mocked_metadata[key] Plugin.update(self.plugin, self.plugin_adapter.get_metadata()) for key, val in six.iteritems(plugin_metadata): self.assertEqual( getattr(self.plugin, key), val) self.assertEqual( self.plugin.attributes_metadata, attributes_metadata['attributes']) self.assertEqual( self.plugin.roles_metadata, roles_metadata) self.assertEqual( self.plugin.volumes_metadata, volumes_metadata) self.assertEqual( self.plugin.tasks, tasks) # deployment tasks returning all non-defined fields, so check # should differ from JSON-stored fields for k, v in six.iteritems(deployment_tasks[0]): # this field is updated by plugin adapter if k is 'parameters': v.update({ 'cwd': '/etc/fuel/plugins/testing_plugin-0.1/' }) self.assertEqual( self.plugin_adapter.get_deployment_tasks()[0][k], v)
def test_get_metadata(self): plugin_metadata = self.env.get_default_plugin_metadata() plugin_metadata['environment_config'] = \ self.env.get_default_plugin_env_config() plugin_metadata['tasks'] = self.env.get_default_plugin_tasks() with mock.patch.object( self.plugin_adapter, 'loader') as loader: loader.load.return_value = plugin_metadata, ReportNode() Plugin.update(self.plugin, self.plugin_adapter.get_metadata()) for key, val in six.iteritems(plugin_metadata): self.assertEqual( getattr(self.plugin, key), val)
def setUp(self): super(TestNailgunReceiver, self).setUp() self.cluster = self.env.create( status=consts.CLUSTER_STATUSES.operational, nodes_kwargs=[{ 'roles': ['controller'], 'status': consts.NODE_STATUSES.ready }]) for i in range(2): meta = self.env.get_default_plugin_metadata( name='name{0}'.format(i), title='title{0}'.format(i), description='description{0}'.format(i)) self.plugin = Plugin.create(meta) self.cluster.plugins.append(self.plugin) ClusterPlugins.set_attributes(self.cluster.id, self.plugin.id, enabled=True) self.task = self.env.create_task(name=consts.TASK_NAMES.deployment, status=consts.TASK_STATUSES.ready, cluster_id=self.cluster.id)
def test_add_nodes_for_cluster_plugin_with_empty_attributes(self): meta = base.reflect_db_metadata() self.env.create_node( cluster_id=self.cluster.id, roles=['compute'] ) plugin = Plugin.create({ 'name': 'plugin_a_with_node_attributes', 'title': 'Test Plugin', 'package_version': '5.0.0', 'version': '1.0.0', 'node_attributes_metadata': {} }) cluster_plugin = ClusterPlugin.create({ 'cluster_id': self.cluster.id, 'plugin_id': plugin.id, 'enabled': False, 'attributes': plugin.node_attributes_metadata }) NodeClusterPlugin.add_nodes_for_cluster_plugin(cluster_plugin) node_cluster_plugins = self.db.execute( meta.tables['node_cluster_plugins'].select() ).fetchall() self.assertEqual(0, len(node_cluster_plugins))
def _create_test_plugins(self): plugin_ids = [] for version in ["1.0.0", "2.0.0", "0.0.1", "3.0.0", "4.0.0", "5.0.0"]: plugin_data = self.env.get_default_plugin_metadata(version=version, name="multiversion_plugin") plugin = Plugin.create(plugin_data) plugin_ids.append(plugin.id) single_plugin_data = self.env.get_default_plugin_metadata(name="single_plugin") plugin = Plugin.create(single_plugin_data) plugin_ids.append(plugin.id) incompatible_plugin_data = self.env.get_default_plugin_metadata(name="incompatible_plugin", releases=[]) plugin = Plugin.create(incompatible_plugin_data) plugin_ids.append(plugin.id) return plugin_ids
def setUp(self): super(TestNailgunReceiver, self).setUp() self.env.create( status=consts.CLUSTER_STATUSES.operational, nodes_kwargs=[ {'roles': ['controller'], 'status': consts.NODE_STATUSES.ready}]) self.cluster = self.env.clusters[0] for i in range(2): meta = self.env.get_default_plugin_metadata( name='name{0}'.format(i), title='title{0}'.format(i), description='description{0}'.format(i)) self.plugin = Plugin.create(meta) self.cluster.plugins.append(self.plugin) ClusterPlugins.set_attributes(self.cluster.id, self.plugin.id, enabled=True) self.task = self.env.create_task( name=consts.TASK_NAMES.deployment, status=consts.TASK_STATUSES.ready, cluster_id=self.cluster.id)
def setUp(self): super(TestClusterCompatiblityValidation, self).setUp() self.plugin = Plugin.create(self.env.get_default_plugin_metadata( releases=[{ 'version': '2014.2-6.0', 'os': 'ubuntu', 'mode': ['ha']}])) self.attr_plugin = attr_plugin.ClusterAttributesPluginV1(self.plugin)
def setUp(self): super(TestClusterCompatibilityValidation, self).setUp() self.plugin = Plugin.create(self.env.get_default_plugin_metadata( releases=[{ 'version': '2014.2-6.0', 'os': 'ubuntu', 'mode': ['ha']}])) self.plugin_adapter = adapters.PluginAdapterV1(self.plugin)
def test_get_metadata(self): plugin_metadata = self.env.get_default_plugin_metadata() attributes_metadata = self.env.get_default_plugin_env_config() roles_metadata = self.env.get_default_plugin_node_roles_config() volumes_metadata = self.env.get_default_plugin_volumes_config() network_roles_metadata = self.env.get_default_network_roles_config() deployment_tasks = self.env.get_default_plugin_deployment_tasks() tasks = self.env.get_default_plugin_tasks() components_metadata = self.env.get_default_components() plugin_metadata.update({ 'attributes_metadata': attributes_metadata, 'roles_metadata': roles_metadata, 'volumes_metadata': volumes_metadata, 'network_roles_metadata': network_roles_metadata, 'deployment_tasks': deployment_tasks, 'tasks': tasks, 'components_metadata': components_metadata }) with mock.patch.object(self.plugin_adapter, 'loader') as loader: loader.load.return_value = (plugin_metadata, ReportNode()) Plugin.update(self.plugin, self.plugin_adapter.get_metadata()) for key, val in six.iteritems(plugin_metadata): if key not in ('deployment_tasks', 'graphs'): self.assertEqual(getattr(self.plugin, key), val) self.assertEqual(self.plugin.attributes_metadata, attributes_metadata['attributes']) self.assertEqual(self.plugin.roles_metadata, roles_metadata) self.assertEqual(self.plugin.volumes_metadata, volumes_metadata) self.assertEqual(self.plugin.tasks, tasks) self.assertEqual(self.plugin.components_metadata, components_metadata) # deployment tasks returning all non-defined fields, so check # should differ from JSON-stored fields plugin_tasks = self.env.get_default_plugin_deployment_tasks() self.assertGreater(len(plugin_tasks), 0) for k, v in six.iteritems(plugin_tasks[0]): # this field is updated by plugin adapter if k is 'parameters': v.update({'cwd': '/etc/fuel/plugins/testing_plugin-0.1/'}) self.assertEqual( self.plugin_adapter.get_deployment_tasks()[0][k], v)
def test_get_metadata(self): plugin_metadata = self.env.get_default_plugin_metadata() attributes_metadata = self.env.get_default_plugin_env_config() tasks = self.env.get_default_plugin_tasks() mocked_metadata = { self._find_path('metadata'): plugin_metadata, self._find_path('environment_config'): attributes_metadata, self._find_path('tasks'): tasks } with mock.patch.object(self.plugin_adapter, '_load_config') as load_conf: load_conf.side_effect = lambda key: mocked_metadata[key] Plugin.update(self.plugin, self.plugin_adapter.get_metadata()) for key, val in six.iteritems(plugin_metadata): self.assertEqual(getattr(self.plugin, key), val)
def setUp(self): super(TestClusterCompatiblityValidation, self).setUp() self.plugin = Plugin.create( self.env.get_default_plugin_metadata(releases=[{ 'version': '2014.2-6.0', 'os': 'ubuntu', 'mode': ['ha'] }])) self.attr_plugin = attr_plugin.ClusterAttributesPluginV1(self.plugin)
def test_get_metadata(self): plugin_metadata = self.env.get_default_plugin_metadata() attributes_metadata = self.env.get_default_plugin_env_config() tasks = self.env.get_default_plugin_tasks() mocked_metadata = { self._find_path('metadata'): plugin_metadata, self._find_path('environment_config'): attributes_metadata, self._find_path('tasks'): tasks } with mock.patch.object( self.plugin_adapter, '_load_config') as load_conf: load_conf.side_effect = lambda key: mocked_metadata[key] Plugin.update(self.plugin, self.plugin_adapter.get_metadata()) for key, val in six.iteritems(plugin_metadata): self.assertEqual( getattr(self.plugin, key), val)
def test_all_newest(self): for version in ['1.0.0', '2.0.0', '0.0.1']: plugin_data = self.env.get_default_plugin_metadata( version=version, name='multiversion_plugin') Plugin.create(plugin_data) single_plugin_data = self.env.get_default_plugin_metadata( name='single_plugin') Plugin.create(single_plugin_data) newest_plugins = PluginCollection.all_newest() self.assertEqual(len(newest_plugins), 2) single_plugin = filter(lambda p: p.name == 'single_plugin', newest_plugins) multiversion_plugin = filter(lambda p: p.name == 'multiversion_plugin', newest_plugins) self.assertEqual(len(single_plugin), 1) self.assertEqual(len(multiversion_plugin), 1) self.assertEqual(multiversion_plugin[0].version, '2.0.0')
def create_plugin(self, api=False, cluster=None, **kwargs): plugin_data = self.get_default_plugin_metadata() plugin_data.update(kwargs) if api: resp = self.app.post( reverse("PluginCollectionHandler"), jsonutils.dumps(plugin_data), headers=self.default_headers, expect_errors=False, ) plugin = Plugin.get_by_uid(resp.json_body["id"]) self.plugins.append(plugin) else: plugin = Plugin.create(plugin_data) self.plugins.append(plugin) # Enable plugin for specific cluster if cluster: cluster.plugins.append(plugin) return plugin
def setUp(self): super(TestPluginBase, self).setUp() self.plugin_metadata = self.env.get_default_plugin_metadata( package_version=self.package_version) self.plugin = Plugin.create(self.plugin_metadata) self.env.create(cluster_kwargs={'mode': 'multinode'}, release_kwargs={ 'version': '2014.2-6.0', 'operating_system': 'Ubuntu' }) self.cluster = self.env.clusters[0] self.attr_plugin = attr_plugin.wrap_plugin(self.plugin) self.env_config = self.env.get_default_plugin_env_config() self.get_config = lambda *args: mock.mock_open(read_data=yaml.dump( self.env_config))() db().flush()
def setUp(self): super(TestPluginBase, self).setUp() self.plugin_metadata = self.env.get_default_plugin_metadata( package_version=self.package_version) self.plugin = Plugin.create(self.plugin_metadata) self.env.create( cluster_kwargs={'mode': 'multinode'}, release_kwargs={ 'version': '2014.2-6.0', 'operating_system': 'Ubuntu'}) self.cluster = self.env.clusters[0] self.attr_plugin = attr_plugin.wrap_plugin(self.plugin) self.env_config = self.env.get_default_plugin_env_config() self.get_config = lambda *args: mock.mock_open( read_data=yaml.dump(self.env_config))() db().flush()
def setUp(self): super(TestPluginBase, self).setUp() self.plugin_metadata = self.env.get_default_plugin_metadata( package_version=self.package_version, roles_metadata={ 'role_x': { 'name': 'Role X', 'description': 'Role X is ...', }, 'role_y': { 'name': 'Role Y', 'description': 'Role Y is ...', 'restrictions': [], 'fault_tolerance': '5%' }, 'role_z': { 'name': 'Role Z', 'description': 'Role Z is ...', 'restrictions': ['settings:some.stuff.value == false'], 'fault_tolerance': '10%' } }) self.plugin = Plugin.create(self.plugin_metadata) self.cluster = self.env.create( cluster_kwargs={'mode': consts.CLUSTER_MODES.multinode}, release_kwargs={ 'version': '2015.1-8.0', 'operating_system': 'Ubuntu', 'modes': [ consts.CLUSTER_MODES.multinode, consts.CLUSTER_MODES.ha_compact ] }) self.plugin_adapter = plugins.wrap_plugin(self.plugin) self.env_config = self.env.get_default_plugin_env_config() self.get_config = lambda *args: mock.mock_open(read_data=yaml.dump( self.env_config))() db().flush()
def setUp(self): super(TestPluginBase, self).setUp() self.plugin_metadata = self.env.get_default_plugin_metadata( package_version=self.package_version, roles_metadata={ 'role_x': { 'name': 'Role X', 'description': 'Role X is ...', }, 'role_y': { 'name': 'Role Y', 'description': 'Role Y is ...', 'restrictions': [], 'fault_tolerance': '5%' }, 'role_z': { 'name': 'Role Z', 'description': 'Role Z is ...', 'restrictions': [ 'settings:some.stuff.value == false' ], 'fault_tolerance': '10%' } } ) self.plugin = Plugin.create(self.plugin_metadata) self.cluster = self.env.create( cluster_kwargs={'mode': consts.CLUSTER_MODES.multinode}, release_kwargs={ 'version': '2015.1-8.0', 'operating_system': 'Ubuntu', 'modes': [consts.CLUSTER_MODES.multinode, consts.CLUSTER_MODES.ha_compact]}) self.plugin_adapter = plugins.wrap_plugin(self.plugin) self.env_config = self.env.get_default_plugin_env_config() self.get_config = lambda *args: mock.mock_open( read_data=yaml.dump(self.env_config))() db().flush()
def setUp(self): super(TestClusterCompatiblityValidation, self).setUp() self.plugin = Plugin.create(self.env.get_default_plugin_metadata()) self.attr_plugin = attr_plugin.ClusterAttributesPlugin(self.plugin)
def test_get_metadata(self): plugin_metadata = self.env.get_default_plugin_metadata() attributes_metadata = self.env.get_default_plugin_env_config() roles_metadata = self.env.get_default_plugin_node_roles_config() tags_metadata = self.env.get_default_plugin_node_tags_config() volumes_metadata = self.env.get_default_plugin_volumes_config() network_roles_metadata = self.env.get_default_network_roles_config() deployment_tasks = self.env.get_default_plugin_deployment_tasks() tasks = self.env.get_default_plugin_tasks() components_metadata = self.env.get_default_components() nic_attributes_metadata = self.env.get_default_plugin_nic_config() bond_attributes_metadata = self.env.get_default_plugin_bond_config() node_attributes_metadata = self.env.get_default_plugin_node_config() plugin_metadata.update({ 'attributes_metadata': attributes_metadata, 'roles_metadata': roles_metadata, 'tags_metadata': tags_metadata, 'volumes_metadata': volumes_metadata, 'network_roles_metadata': network_roles_metadata, 'deployment_tasks': deployment_tasks, 'tasks': tasks, 'components_metadata': components_metadata, 'nic_attributes_metadata': nic_attributes_metadata, 'bond_attributes_metadata': bond_attributes_metadata, 'node_attributes_metadata': node_attributes_metadata, 'graphs': [{ 'type': 'custom', 'name': 'custom', 'tasks': [ {'id': 'task{}'.format(n), 'type': 'puppet'} for n in range(2) ] }] }) with mock.patch.object( self.plugin_adapter, 'loader') as loader: loader.load.return_value = (plugin_metadata, ReportNode()) Plugin.update(self.plugin, self.plugin_adapter.get_metadata()) for key, val in six.iteritems( { k: v for (k, v) in six.iteritems(plugin_metadata) if k not in ('deployment_tasks', 'graphs') } ): self.assertEqual( getattr(self.plugin, key), val) self.assertEqual( self.plugin.attributes_metadata, attributes_metadata['attributes']) self.assertEqual( self.plugin.roles_metadata, roles_metadata) self.assertEqual( self.plugin.tags_metadata, tags_metadata) self.assertEqual( self.plugin.volumes_metadata, volumes_metadata) self.assertEqual( self.plugin.tasks, tasks) self.assertEqual( self.plugin.components_metadata, components_metadata) self.assertEqual( self.plugin.nic_attributes_metadata, nic_attributes_metadata) self.assertEqual( self.plugin.bond_attributes_metadata, bond_attributes_metadata) self.assertEqual( self.plugin.node_attributes_metadata, node_attributes_metadata) # check custom graph dg = DeploymentGraph.get_for_model( self.plugin, graph_type='custom' ) self.assertEqual(dg.name, 'custom') self.assertItemsEqual( DeploymentGraph.get_tasks(dg), [ { 'id': 'task{}'.format(i), 'task_name': 'task{}'.format(i), 'type': 'puppet', 'version': '1.0.0' } for i in range(2) ] ) # deployment tasks returning all non-defined fields, so check # should differ from JSON-stored fields plugin_tasks = self.env.get_default_plugin_deployment_tasks() self.assertGreater(len(plugin_tasks), 0) for k, v in six.iteritems(plugin_tasks[0]): # this field is updated by plugin adapter if k is 'parameters': v.update({ 'cwd': '/etc/fuel/plugins/testing_plugin-0.1/' }) self.assertEqual( self.plugin_adapter.get_deployment_tasks()[0][k], v)
def test_tags_saved_on_plugins_update(self): Plugin.update(self.plugin, {'roles_metadata': self.plugin.roles_metadata}) for role, meta in self.plugin.roles_metadata.items(): self.assertIn('tags', meta)
def test_get_metadata(self): plugin_metadata = self.env.get_default_plugin_metadata() attributes_metadata = self.env.get_default_plugin_env_config() roles_metadata = self.env.get_default_plugin_node_roles_config() tags_metadata = self.env.get_default_plugin_node_tags_config() volumes_metadata = self.env.get_default_plugin_volumes_config() network_roles_metadata = self.env.get_default_network_roles_config() deployment_tasks = self.env.get_default_plugin_deployment_tasks() tasks = self.env.get_default_plugin_tasks() components_metadata = self.env.get_default_components() nic_attributes_metadata = self.env.get_default_plugin_nic_config() bond_attributes_metadata = self.env.get_default_plugin_bond_config() node_attributes_metadata = self.env.get_default_plugin_node_config() plugin_metadata.update({ 'attributes_metadata': attributes_metadata, 'roles_metadata': roles_metadata, 'tags_metadata': tags_metadata, 'volumes_metadata': volumes_metadata, 'network_roles_metadata': network_roles_metadata, 'deployment_tasks': deployment_tasks, 'tasks': tasks, 'components_metadata': components_metadata, 'nic_attributes_metadata': nic_attributes_metadata, 'bond_attributes_metadata': bond_attributes_metadata, 'node_attributes_metadata': node_attributes_metadata, 'graphs': [{ 'type': 'custom', 'name': 'custom', 'tasks': [{ 'id': 'task{}'.format(n), 'type': 'puppet' } for n in range(2)] }] }) with mock.patch.object(self.plugin_adapter, 'loader') as loader: loader.load.return_value = (plugin_metadata, ReportNode()) Plugin.update(self.plugin, self.plugin_adapter.get_metadata()) for key, val in six.iteritems({ k: v for (k, v) in six.iteritems(plugin_metadata) if k not in ('deployment_tasks', 'graphs') }): self.assertEqual(getattr(self.plugin, key), val) self.assertEqual(self.plugin.attributes_metadata, attributes_metadata['attributes']) self.assertEqual(self.plugin.roles_metadata, roles_metadata) self.assertEqual(self.plugin.tags_metadata, tags_metadata) self.assertEqual(self.plugin.volumes_metadata, volumes_metadata) self.assertEqual(self.plugin.tasks, tasks) self.assertEqual(self.plugin.components_metadata, components_metadata) self.assertEqual(self.plugin.nic_attributes_metadata, nic_attributes_metadata) self.assertEqual(self.plugin.bond_attributes_metadata, bond_attributes_metadata) self.assertEqual(self.plugin.node_attributes_metadata, node_attributes_metadata) # check custom graph dg = DeploymentGraph.get_for_model(self.plugin, graph_type='custom') self.assertEqual(dg.name, 'custom') self.assertItemsEqual(DeploymentGraph.get_tasks(dg), [{ 'id': 'task{}'.format(i), 'task_name': 'task{}'.format(i), 'type': 'puppet', 'version': '1.0.0' } for i in range(2)]) # deployment tasks returning all non-defined fields, so check # should differ from JSON-stored fields plugin_tasks = self.env.get_default_plugin_deployment_tasks() self.assertGreater(len(plugin_tasks), 0) for k, v in six.iteritems(plugin_tasks[0]): # this field is updated by plugin adapter if k is 'parameters': v.update({'cwd': '/etc/fuel/plugins/testing_plugin-0.1/'}) self.assertEqual( self.plugin_adapter.get_deployment_tasks()[0][k], v)
def test_graphs_creation(self): metadata_update = { 'name': 'graphs_plugin', 'description': 'testing graphs', 'package_version': '5.0.0', 'graphs': [{ 'type': 'default', 'name': 'default', 'tasks': [{ 'id': 'default', 'type': 'puppet' }] }, { 'type': 'custom', 'name': 'custom', 'tasks': [{ 'id': 'custom', 'type': 'puppet' }] }] } metadata = self.env.get_default_plugin_metadata() metadata.update(metadata_update) plugin = Plugin.create(metadata) def_graph = DeploymentGraph.get_for_model(plugin, graph_type='default') self.assertEqual(def_graph.name, 'default') self.assertEqual(DeploymentGraph.get_tasks(def_graph), [{ 'id': 'default', 'task_name': 'default', 'type': 'puppet', 'version': '1.0.0' }]) custom_graph = DeploymentGraph.get_for_model(plugin, graph_type='custom') self.assertEqual(custom_graph.name, 'custom') self.assertEqual(DeploymentGraph.get_tasks(custom_graph), [{ 'id': 'custom', 'task_name': 'custom', 'type': 'puppet', 'version': '1.0.0' }]) Plugin.update(plugin, metadata) def_graph = DeploymentGraph.get_for_model(plugin, graph_type='default') self.assertEqual(def_graph.name, 'default') self.assertEqual(DeploymentGraph.get_tasks(def_graph), [{ 'id': 'default', 'task_name': 'default', 'type': 'puppet', 'version': '1.0.0' }]) custom_graph = DeploymentGraph.get_for_model(plugin, graph_type='custom') self.assertEqual(custom_graph.name, 'custom') self.assertEqual(DeploymentGraph.get_tasks(custom_graph), [{ 'id': 'custom', 'task_name': 'custom', 'type': 'puppet', 'version': '1.0.0' }])
def test_graphs_creation(self): metadata_update = { 'name': 'graphs_plugin', 'description': 'testing graphs', 'package_version': '5.0.0', 'graphs': [ { 'type': 'default', 'name': 'default', 'tasks': [ {'id': 'default', 'type': 'puppet'} ] }, { 'type': 'custom', 'name': 'custom', 'tasks': [ {'id': 'custom', 'type': 'puppet'} ] } ]} metadata = self.env.get_default_plugin_metadata() metadata.update(metadata_update) plugin = Plugin.create(metadata) def_graph = DeploymentGraph.get_for_model( plugin, graph_type='default' ) self.assertEqual(def_graph.name, 'default') self.assertEqual( DeploymentGraph.get_tasks(def_graph), [ { 'id': 'default', 'task_name': 'default', 'type': 'puppet', 'version': '1.0.0' } ] ) custom_graph = DeploymentGraph.get_for_model( plugin, graph_type='custom' ) self.assertEqual(custom_graph.name, 'custom') self.assertEqual( DeploymentGraph.get_tasks(custom_graph), [ { 'id': 'custom', 'task_name': 'custom', 'type': 'puppet', 'version': '1.0.0' } ] ) Plugin.update(plugin, metadata) def_graph = DeploymentGraph.get_for_model( plugin, graph_type='default' ) self.assertEqual(def_graph.name, 'default') self.assertEqual( DeploymentGraph.get_tasks(def_graph), [ { 'id': 'default', 'task_name': 'default', 'type': 'puppet', 'version': '1.0.0' } ] ) custom_graph = DeploymentGraph.get_for_model( plugin, graph_type='custom' ) self.assertEqual(custom_graph.name, 'custom') self.assertEqual( DeploymentGraph.get_tasks(custom_graph), [ { 'id': 'custom', 'task_name': 'custom', 'type': 'puppet', 'version': '1.0.0' } ] )