deployment_tasks attribute removed from plugins adapter

plugins adapter has legacy .deployment_tasks attribute
that was replaced with get_deployment_tasks() method

Change-Id: I69cd2e93d42dfe235bd0e96dfc98f3286622a444
Partial-Bug: #1567504
This commit is contained in:
Ilya Kutukov 2016-04-12 18:25:34 +03:00
parent 05be83199a
commit 32053bedb0
5 changed files with 51 additions and 35 deletions

View File

@ -144,11 +144,20 @@ class PluginsPreDeploymentHooksSerializer(BasePluginDeploymentHooksSerializer):
plugins = PluginManager.get_enabled_plugins(self.cluster)
return self.deployment_tasks(plugins)
def _get_node_uids_for_plugin_tasks(self, plugin):
def _get_node_uids_for_plugin_tasks(self, plugin_adapter):
"""Get node uids for plugin tasks.
:param plugin_adapter: Plugin adapter
:type plugin_adapter: plugins.adapters.PluginAdapterBase
:returns: node UIDs
:rtype: list[basestring]
"""
# TODO(aroma): remove concatenation of tasks when unified way of
# processing will be introduced for deployment tasks and existing
# plugin tasks
tasks_to_process = plugin.tasks + plugin.deployment_tasks
# TODO(ikutukov): add deployment graph type support for plugins
tasks_to_process = \
plugin_adapter.tasks + plugin_adapter.get_deployment_tasks()
roles = set()
for task in tasks_to_process:

View File

@ -136,23 +136,6 @@ class PluginAdapterBase(object):
deployment_tasks.append(task)
return deployment_tasks
# fixme(ikutukov): this getter only for default graph type, drop in future
@property
def deployment_tasks(self):
return self.get_deployment_tasks()
# it will better to replace to getters and setters
@deployment_tasks.setter
def deployment_tasks(self, value):
if value:
deployment_graph_instance = DeploymentGraph.get_for_model(
self.plugin)
if deployment_graph_instance:
DeploymentGraph.update(deployment_graph_instance,
{'tasks': value})
else:
DeploymentGraph.create_for_model({'tasks': value}, self.plugin)
def get_tasks(self):
if self._tasks is None:
if self.plugin.tasks:
@ -344,10 +327,17 @@ class PluginAdapterV3(PluginAdapterV2):
self.db_cfg_mapping['roles_metadata'] = 'node_roles.yaml'
self.db_cfg_mapping['volumes_metadata'] = 'volumes.yaml'
def get_metadata(self):
# FIXME (ikutukov): rework to getters and setters to be able to
# change deployment graph type
self.deployment_tasks = self._load_config('deployment_tasks.yaml')
def get_metadata(self, graph_type=None):
dg = DeploymentGraph.get_for_model(self.plugin, graph_type)
if dg:
DeploymentGraph.update(
dg,
{'tasks': self._load_config('deployment_tasks.yaml')})
else:
DeploymentGraph.create_for_model(
{'tasks': self._load_config('deployment_tasks.yaml')},
self.plugin,
graph_type)
return super(PluginAdapterV3, self).get_metadata()

View File

@ -1320,7 +1320,7 @@ class TestClusterObject(BaseTestCase):
default_tasks_count = len(objects.Release.get_deployment_tasks(
cluster.release))
plugin_tasks_count = len(plugins.adapters.wrap_plugin(
cluster.plugins[0]).deployment_tasks)
cluster.plugins[0]).get_deployment_tasks())
self.assertEqual(
len(cluster_deployment_tasks),

View File

@ -24,6 +24,7 @@ from nailgun.db import db
from nailgun.errors import errors
from nailgun.expression import Expression
from nailgun.objects import ClusterPlugins
from nailgun.objects import DeploymentGraph
from nailgun.objects import Plugin
from nailgun.plugins import adapters
from nailgun.settings import settings
@ -163,20 +164,29 @@ class TestPluginBase(base.BaseTestCase):
getattr(self.plugin, key), val)
def test_get_deployment_tasks(self):
self.plugin_adapter.deployment_tasks = \
self.env.get_default_plugin_deployment_tasks()
dg = DeploymentGraph.get_for_model(self.plugin_adapter.plugin)
DeploymentGraph.update(
dg,
{
'tasks': self.env.get_default_plugin_deployment_tasks()
}
)
depl_task = self.plugin_adapter.deployment_tasks[0]
depl_task = self.plugin_adapter.get_deployment_tasks()[0]
self.assertEqual(depl_task['parameters'].get('cwd'),
self.plugin_adapter.slaves_scripts_path)
def test_get_deployment_tasks_params_not_changed(self):
expected = 'path/to/some/dir'
self.plugin_adapter.deployment_tasks = \
self.env.get_default_plugin_deployment_tasks(
parameters={'cwd': expected}
)
depl_task = self.plugin_adapter.deployment_tasks[0]
dg = DeploymentGraph.get_for_model(self.plugin_adapter.plugin)
DeploymentGraph.update(
dg,
{
'tasks': self.env.get_default_plugin_deployment_tasks(
parameters={'cwd': expected})
}
)
depl_task = self.plugin_adapter.get_deployment_tasks()[0]
self.assertEqual(depl_task['parameters'].get('cwd'), expected)
def _find_path(self, config_name):
@ -274,7 +284,9 @@ class TestPluginV3(TestPluginBase):
v.update({
'cwd': '/etc/fuel/plugins/testing_plugin-0.1/'
})
self.assertEqual(self.plugin_adapter.deployment_tasks[0][k], v)
self.assertEqual(
self.plugin_adapter.get_deployment_tasks()[0][k],
v)
class TestPluginV4(TestPluginBase):
@ -333,7 +345,9 @@ class TestPluginV4(TestPluginBase):
v.update({
'cwd': '/etc/fuel/plugins/testing_plugin-0.1/'
})
self.assertEqual(self.plugin_adapter.deployment_tasks[0][k], v)
self.assertEqual(
self.plugin_adapter.get_deployment_tasks()[0][k],
v)
def test_empty_task_file_not_failing(self):
with mock.patch.object(

View File

@ -208,7 +208,10 @@ class TestPluginsDeploymentEnvironment(base.BaseTestCase):
{'id': 2, 'role': 'compute'}
]
plugin = mock.Mock(tasks=[], deployment_tasks=[])
plugin = mock.Mock(
tasks=[],
version='4.0.0',
get_deployment_tasks=lambda: [])
self.plugins = [plugin]