Added the pre/post tasks from plugins to list of deployment task

- The plugin deployment tasks are proceeded with the core-tasks.
- The plugin pre-deployment tasks will be added as
    chain between pre_deployment_end and deploy_start.
- The plugin post-deployment tasks will be added as
    chain after post_deployment_end.

Closes-Bug: #1527325
Change-Id: I5b416d9507b2ae1503c356a9828a0b7be85c1eb1
This commit is contained in:
Bulat Gaifullin 2015-12-16 15:15:37 +03:00
parent 62f8c8be2e
commit 56c811cedd
9 changed files with 257 additions and 142 deletions

View File

@ -366,6 +366,11 @@ INTERNAL_TASKS = (ORCHESTRATOR_TASK_TYPES.group,
ORCHESTRATOR_TASK_TYPES.stage,
ORCHESTRATOR_TASK_TYPES.skipped)
PLUGIN_PRE_DEPLOYMENT_HOOK = "_plugin_pre_deployment_hook"
PLUGIN_POST_DEPLOYMENT_HOOK = "_plugin_post_deployment_hook"
# filter for deployment tasks which should be rerun on deployed nodes to make
# re-setup of network on nodes
TASKS_TO_RERUN_ON_DEPLOY_CHANGES = ['deploy_changes']

View File

@ -16,12 +16,12 @@
"""Serializer for plugins tasks"""
import itertools
from nailgun import consts
from nailgun.errors import errors
from nailgun.logger import logger
from nailgun.orchestrator.tasks_serializer import get_uids_for_roles
from nailgun.orchestrator.tasks_serializer import get_uids_for_tasks
from nailgun.orchestrator.tasks_serializer import LegacyRoleResolver
import nailgun.orchestrator.tasks_templates as templates
from nailgun.plugins.manager import PluginManager
from nailgun.settings import settings
@ -30,12 +30,19 @@ from nailgun.settings import settings
class BasePluginDeploymentHooksSerializer(object):
# TODO(dshulyak) refactor it to be consistent with task_serializer
def __init__(self, cluster, nodes):
def __init__(self, cluster, nodes, role_resolver=None):
"""Initialises.
:param cluster: the cluster object instance
:param nodes: the list of nodes for deployment
:param role_resolver: the instance of BaseRoleResolver
"""
self.cluster = cluster
self.nodes = nodes
self.role_resolver = role_resolver or LegacyRoleResolver(nodes)
def deployment_tasks(self, plugins, stage):
tasks = []
plugin_tasks = []
sorted_plugins = sorted(plugins, key=lambda p: p.plugin.name)
@ -47,7 +54,7 @@ class BasePluginDeploymentHooksSerializer(object):
sorted_tasks = self._sort_by_stage_postfix(plugin_tasks)
for task in sorted_tasks:
make_task = None
uids = get_uids_for_roles(self.nodes, task['role'])
uids = self.role_resolver.resolve(task['role'])
if not uids:
continue
@ -62,23 +69,23 @@ class BasePluginDeploymentHooksSerializer(object):
'not supported').format(task)
if make_task:
tasks.append(self._serialize_task(make_task(uids, task), task))
return tasks
yield self._serialize_task(make_task(uids, task), task)
def _set_tasks_defaults(self, plugin, tasks):
for task in tasks:
self._set_task_defaults(plugin, task)
return tasks
def _set_task_defaults(self, plugin, task):
@staticmethod
def _set_task_defaults(plugin, task):
task['parameters'].setdefault('cwd', plugin.slaves_scripts_path)
task.setdefault('diagnostic_name', plugin.full_name)
task.setdefault('fail_on_error', True)
return task
def _serialize_task(self, task, default_task):
@staticmethod
def _serialize_task(task, default_task):
task.update({
'diagnostic_name': default_task['diagnostic_name'],
'fail_on_error': default_task['fail_on_error']})
@ -88,7 +95,8 @@ class BasePluginDeploymentHooksSerializer(object):
return self._serialize_task(
self._set_task_defaults(plugin, task), task)
def _sort_by_stage_postfix(self, tasks):
@staticmethod
def _sort_by_stage_postfix(tasks):
"""Sorts tasks by task postfixes
for example here are several tasks' stages:
@ -103,7 +111,7 @@ class BasePluginDeploymentHooksSerializer(object):
stage: post_deployment # because by default postifx is 0
stage: post_deployment/100
"""
def postfix(task):
def get_postfix(task):
stage_list = task['stage'].split('/')
postfix = stage_list[-1] if len(stage_list) > 1 else 0
@ -117,18 +125,18 @@ class BasePluginDeploymentHooksSerializer(object):
return postfix
return sorted(tasks, key=postfix)
return sorted(tasks, key=get_postfix)
class PluginsPreDeploymentHooksSerializer(BasePluginDeploymentHooksSerializer):
def serialize(self):
tasks = []
plugins = PluginManager.get_cluster_plugins_with_tasks(self.cluster)
tasks.extend(self.create_repositories(plugins))
tasks.extend(self.sync_scripts(plugins))
tasks.extend(self.deployment_tasks(plugins))
return tasks
return itertools.chain(
self.create_repositories(plugins),
self.sync_scripts(plugins),
self.deployment_tasks(plugins)
)
def _get_node_uids_for_plugin_tasks(self, plugin):
# TODO(aroma): remove concatenation of tasks when unified way of
@ -136,22 +144,37 @@ class PluginsPreDeploymentHooksSerializer(BasePluginDeploymentHooksSerializer):
# plugin tasks
tasks_to_process = plugin.tasks + plugin.deployment_tasks
uids = get_uids_for_tasks(self.nodes, tasks_to_process)
roles = []
for task in tasks_to_process:
# plugin tasks may store information about node
# role not only in `role` key but also in `groups`
task_role = task.get('role', task.get('groups'))
if task_role == consts.TASK_ROLES.all:
# just return all nodes
return self.role_resolver.resolve(consts.TASK_ROLES.all)
elif task_role == consts.TASK_ROLES.master:
# NOTE(aroma): pre-deployment tasks should not be executed on
# master node because in some cases it leads to errors due to
# commands need to be run are not compatible with master node
# OS (CentOS). E.g. of such situation - create repository
# executes `apt-get update` which fails on CentOS
continue
elif isinstance(task_role, list):
roles.extend(task_role)
# if task has 'skipped' status it is allowed that 'roles' and
# 'groups' are not be specified
elif task['type'] != consts.ORCHESTRATOR_TASK_TYPES.skipped:
logger.warn(
'Wrong roles format in task %s: either '
'`roles` or `groups` must be specified and contain '
'a list of roles or "*"',
task)
# NOTE(aroma): pre-deployment tasks should not be executed on
# master node because in some cases it leads to errors due to
# commands need to be run are not compatible with master node
# OS (CentOS). E.g. of such situation - create repository
# executes `apt-get update` which fails on CentOS
if consts.MASTER_NODE_UID in uids:
uids.remove(consts.MASTER_NODE_UID)
return uids
return self.role_resolver.resolve(roles)
def create_repositories(self, plugins):
operating_system = self.cluster.release.operating_system
repo_tasks = []
for plugin in plugins:
uids = self._get_node_uids_for_plugin_tasks(plugin)
@ -162,54 +185,49 @@ class PluginsPreDeploymentHooksSerializer(BasePluginDeploymentHooksSerializer):
if operating_system == consts.RELEASE_OS.centos:
repo = self.get_centos_repo(plugin)
repo_tasks.append(
self.serialize_task(
plugin,
templates.make_centos_repo_task(uids, repo)))
yield self.serialize_task(
plugin,
templates.make_centos_repo_task(uids, repo)
)
elif operating_system == consts.RELEASE_OS.ubuntu:
repo = self.get_ubuntu_repo(plugin)
repo_tasks.append(
self.serialize_task(
plugin,
templates.make_ubuntu_sources_task(uids, repo)))
yield self.serialize_task(
plugin,
templates.make_ubuntu_sources_task(uids, repo)
)
# do not add preferences task to task list if we can't
# complete it (e.g. can't retrieve or parse Release file)
task = templates.make_ubuntu_preferences_task(uids, repo)
if task is not None:
repo_tasks.append(self.serialize_task(plugin, task))
yield self.serialize_task(plugin, task)
# apt-get update executed after every additional source.list
# to be able understand what plugin source.list caused error
repo_tasks.append(
self.serialize_task(
plugin,
templates.make_apt_update_task(uids)))
yield self.serialize_task(
plugin,
templates.make_apt_update_task(uids)
)
else:
raise errors.InvalidOperatingSystem(
'Operating system {0} is invalid'.format(operating_system))
return repo_tasks
def sync_scripts(self, plugins):
tasks = []
for plugin in plugins:
uids = self._get_node_uids_for_plugin_tasks(plugin)
if not uids:
continue
tasks.append(
self.serialize_task(
plugin,
templates.make_sync_scripts_task(
uids,
plugin.master_scripts_path(self.cluster),
plugin.slaves_scripts_path)))
return tasks
yield self.serialize_task(
plugin,
templates.make_sync_scripts_task(
uids,
plugin.master_scripts_path(self.cluster),
plugin.slaves_scripts_path)
)
def deployment_tasks(self, plugins):
return super(
@ -237,10 +255,8 @@ class PluginsPostDeploymentHooksSerializer(
BasePluginDeploymentHooksSerializer):
def serialize(self):
tasks = []
plugins = PluginManager.get_cluster_plugins_with_tasks(self.cluster)
tasks.extend(self.deployment_tasks(plugins))
return tasks
return self.deployment_tasks(plugins)
def deployment_tasks(self, plugins):
return super(

View File

@ -22,7 +22,7 @@ from nailgun.orchestrator.priority_serializers import PriorityStrategy
def stage_serialize(serializer, graph_tasks, cluster, nodes):
"""Serialize tasks for given stage
:param serialize: orchestrator.plugins.BasePluginDeploymentHooksSerializer
:param serializer: plugins_serializers.BasePluginDeploymentHooksSerializer
:param graph_tasks: list of tasks
:param cluster: cluster db object
:param nodes: list of node db objects

View File

@ -24,6 +24,7 @@ import six
from nailgun import consts
from nailgun.errors import errors
from nailgun.logger import logger
from nailgun.orchestrator import plugins_serializers
from nailgun.orchestrator.tasks_serializer import CreateVMsOnCompute
from nailgun.orchestrator.tasks_serializer import StandartConfigRolesHook
from nailgun.orchestrator.tasks_serializer import TaskSerializers
@ -50,11 +51,68 @@ class NoopSerializer(StandartConfigRolesHook):
yield make_noop_task(uids, self.task)
class PluginTaskSerializer(StandartConfigRolesHook):
serializer_class = None
def should_execute(self):
return True
def serialize(self):
serializer = self.serializer_class(
self.cluster, self.nodes, role_resolver=self.role_resolver
)
return serializer.serialize()
class PluginPreDeploymentSerializer(PluginTaskSerializer):
"""Serializes plugin pre-deployment tasks."""
serializer_class = \
plugins_serializers.PluginsPreDeploymentHooksSerializer
class PluginPostDeploymentSerializer(PluginTaskSerializer):
"""Serializes plugin post-deployment tasks."""
serializer_class = \
plugins_serializers.PluginsPostDeploymentHooksSerializer
def add_plugin_deployment_hooks(tasks):
"""Adds the artificial tasks for deployment hooks from plugins.
:param tasks: the origin list of deployment tasks
:return: the sequence of deployment tasks that includes
pre/post deployment hooks for plugins
"""
# TODO(bgaifullin): Make this tasks in plugins as obsolete
# and drop support of them
# of Task Based Deployment
# Added fake task for pre and post.
# This will cause engine to generate chain of tasks for each stage.
# Tasks in chain will run step by step.
hooks = [
{'id': consts.PLUGIN_PRE_DEPLOYMENT_HOOK,
'version': consts.TASK_CROSS_DEPENDENCY,
'type': consts.PLUGIN_PRE_DEPLOYMENT_HOOK,
'requires': [consts.STAGES.pre_deployment + '_end'],
'required_for': [consts.STAGES.deploy + '_start']},
{'id': consts.PLUGIN_POST_DEPLOYMENT_HOOK,
'version': consts.TASK_CROSS_DEPENDENCY,
'type': consts.PLUGIN_POST_DEPLOYMENT_HOOK,
'requires': [consts.STAGES.post_deployment + '_end']}
]
return itertools.chain(iter(tasks), iter(hooks))
class DeployTaskSerializer(TaskSerializers):
noop_task_types = (
consts.ORCHESTRATOR_TASK_TYPES.skipped,
consts.ORCHESTRATOR_TASK_TYPES.stage
)
task_types_mapping = {
consts.ORCHESTRATOR_TASK_TYPES.skipped: NoopSerializer,
consts.ORCHESTRATOR_TASK_TYPES.stage: NoopSerializer,
consts.PLUGIN_PRE_DEPLOYMENT_HOOK: PluginPreDeploymentSerializer,
consts.PLUGIN_POST_DEPLOYMENT_HOOK: PluginPostDeploymentSerializer
}
def __init__(self):
# because we are used only stage_serializers need to
@ -65,8 +123,9 @@ class DeployTaskSerializer(TaskSerializers):
)
def get_stage_serializer(self, task):
if task.get('type') in self.noop_task_types:
return NoopSerializer
serializer = self.task_types_mapping.get(task['type'], None)
if serializer is not None:
return serializer
return super(DeployTaskSerializer, self).get_stage_serializer(
task
)
@ -310,7 +369,7 @@ class TasksSerializer(object):
:return: the list of serialized task per node
"""
serializer = cls(cluster, nodes)
serializer.resolve_nodes(tasks, nodes)
serializer.resolve_nodes(add_plugin_deployment_hooks(tasks), nodes)
serializer.resolve_dependencies()
return dict(
(k, list(six.itervalues(v)))

View File

@ -31,35 +31,6 @@ from nailgun.settings import settings
from nailgun.utils.role_resolver import BaseRoleResolver
def get_uids_for_tasks(nodes, tasks):
"""Return node uids where particular tasks should be executed
:param nodes: list of Node db objects
:param tasks: list of dicts
:returns: list of strings
"""
roles = []
for task in tasks:
# plugin tasks may store information about node
# role not only in `role` key but also in `groups`
task_role = task.get('role', task.get('groups'))
if task_role == consts.TASK_ROLES.all:
return get_uids_for_roles(nodes, consts.TASK_ROLES.all)
elif task_role == consts.TASK_ROLES.master:
return [consts.MASTER_NODE_UID]
elif isinstance(task_role, list):
roles.extend(task_role)
# if task has 'skipped' status it is allowed that 'roles' and
# 'groups' are not be specified
elif task['type'] != consts.ORCHESTRATOR_TASK_TYPES.skipped:
logger.warn(
'Wrong roles format in task %s: either '
'`roles` or `groups` must be specified and contain '
'a list of roles or "*"',
task)
return get_uids_for_roles(nodes, roles)
def get_uids_for_roles(nodes, roles):
"""Returns list of uids for nodes that matches roles

View File

@ -46,7 +46,7 @@ from nailgun.orchestrator import deployment_graph
from nailgun.orchestrator import deployment_serializers
from nailgun.orchestrator import provisioning_serializers
from nailgun.orchestrator import stages
from nailgun.orchestrator import task_based_deploy
from nailgun.orchestrator import task_based_deployment
from nailgun.orchestrator import tasks_serializer
from nailgun.orchestrator import tasks_templates
from nailgun.settings import settings
@ -239,7 +239,7 @@ class DeploymentTask(object):
serialized_cluster = deployment_serializers.serialize(
None, task.cluster, nodes
)
serialized_tasks = task_based_deploy.TasksSerializer.serialize(
serialized_tasks = task_based_deployment.TasksSerializer.serialize(
task.cluster, nodes, deployment_tasks
)
return {

View File

@ -19,7 +19,7 @@ import mock
from nailgun import consts
from nailgun.errors import errors
from nailgun.orchestrator.task_based_deploy import TasksSerializer
from nailgun.orchestrator.task_based_deployment import TasksSerializer
from nailgun.test.base import BaseIntegrationTest
from nailgun.test.base import fake_tasks
@ -34,7 +34,11 @@ class TestTaskDeploy(BaseIntegrationTest):
{"name": "Second",
"roles": ["compute"],
"pending_addition": True}
]
],
release_kwargs={
'operating_system': consts.RELEASE_OS.ubuntu,
'version': '2015.1.0-8.0',
},
)
self.cluster = self.env.clusters[-1]
@ -44,6 +48,25 @@ class TestTaskDeploy(BaseIntegrationTest):
self.cluster.attributes.editable = cluster_attrs
self.db().flush()
def add_plugin_with_tasks(self, task_id):
deployment_tasks = self.env.get_default_plugin_deployment_tasks(
id=task_id, type="skipped",
role=["compute"]
)
tasks = self.env.get_default_plugin_tasks(
role=["compute"]
)
tasks.extend(self.env.get_default_plugin_tasks(
role=["compute"], stage="pre_deployment"
))
self.env.create_plugin(
cluster=self.cluster,
enabled=True,
package_version="4.0.0",
deployment_tasks=deployment_tasks, tasks=tasks
)
self.db.flush()
@fake_tasks(mock_rpc=False, fake_rpc=False)
@mock.patch('nailgun.rpc.cast')
def get_deploy_message(self, rpc_cast):
@ -84,3 +107,36 @@ class TestTaskDeploy(BaseIntegrationTest):
"pre_deployment", "post_deployment"],
message["args"]
)
@mock.patch.object(TasksSerializer, "ensure_task_based_deploy_allowed")
@mock.patch('nailgun.plugins.adapters.os.path.exists', return_value=True)
@mock.patch('nailgun.plugins.adapters.PluginAdapterBase._load_tasks')
def test_task_deploy_with_plugins(self, load_tasks, *_):
self.enable_deploy_task(True)
self.add_plugin_with_tasks("plugin_deployment_task")
# There is bug[1] in PluginAdapters,
# it always reads the tasks from local file sytem.
# [1] https://bugs.launchpad.net/fuel/+bug/1527320
load_tasks.return_value = self.env.plugins[-1].tasks
message = self.get_deploy_message()
compute_uid = next(
(x.uid for x in self.env.nodes if 'compute' in x.roles), None
)
self.assertIsNotNone(compute_uid)
compute_tasks = message['args']['deployment_tasks'][compute_uid]
expected_tasks = {
consts.PLUGIN_PRE_DEPLOYMENT_HOOK + "_start",
consts.PLUGIN_PRE_DEPLOYMENT_HOOK + "_end",
consts.PLUGIN_POST_DEPLOYMENT_HOOK,
"plugin_deployment_task"
}
for task in compute_tasks:
expected_tasks.discard(task['id'])
if len(expected_tasks):
self.fail(
"The following task is not found in tasks for deploy {0}."
.format(sorted(expected_tasks))
)

View File

@ -18,12 +18,12 @@ import copy
import mock
from nailgun import consts
from nailgun.test import base
from nailgun.orchestrator.plugins_serializers import \
BasePluginDeploymentHooksSerializer
from nailgun.orchestrator.plugins_serializers import \
PluginsPreDeploymentHooksSerializer
from nailgun.test import base
from nailgun.utils.role_resolver import NullResolver
class TestBasePluginDeploymentHooksSerializer(base.BaseTestCase):
@ -38,10 +38,11 @@ class TestBasePluginDeploymentHooksSerializer(base.BaseTestCase):
]
self.hook = BasePluginDeploymentHooksSerializer(
self.nodes,
self.cluster)
self.cluster,
role_resolver=NullResolver([x['id'] for x in self.nodes])
)
@mock.patch('nailgun.orchestrator.plugins_serializers.get_uids_for_roles')
def test_original_order_of_deployment_tasks(self, get_uids_for_roles_mock):
def test_original_order_of_deployment_tasks(self):
stage = 'pre_deployment'
role = 'controller'
@ -60,9 +61,7 @@ class TestBasePluginDeploymentHooksSerializer(base.BaseTestCase):
'parameters': {'cmd': 'test2', 'cwd': '/', 'timeout': 15}}
]
get_uids_for_roles_mock.return_value = [1, 2]
raw_result = self.hook.deployment_tasks([plugin], stage)
raw_result = list(self.hook.deployment_tasks([plugin], stage))
result = [r['type'] for r in raw_result]
self.assertEqual(result, ['shell', 'puppet', 'shell'])
self.assertEqual(raw_result[0]['parameters']['cmd'], 'test1')
@ -71,8 +70,7 @@ class TestBasePluginDeploymentHooksSerializer(base.BaseTestCase):
'modules')
self.assertEqual(raw_result[2]['parameters']['cmd'], 'test2')
@mock.patch('nailgun.orchestrator.plugins_serializers.get_uids_for_roles')
def test_support_reboot_type_task(self, get_uids_for_roles_mock):
def test_support_reboot_type_task(self):
stage = 'pre_deployment'
plugin = mock.Mock()
@ -85,8 +83,6 @@ class TestBasePluginDeploymentHooksSerializer(base.BaseTestCase):
'stage': stage,
'parameters': {'timeout': 15}}]
get_uids_for_roles_mock.return_value = [1, 2]
result = self.hook.deployment_tasks([plugin], stage)
expecting_format = {
'id': None,
@ -96,11 +92,9 @@ class TestBasePluginDeploymentHooksSerializer(base.BaseTestCase):
'type': 'reboot',
'uids': [1, 2]}
self.assertEqual(result, [expecting_format])
self.assertItemsEqual([expecting_format], result)
@mock.patch('nailgun.orchestrator.plugins_serializers.get_uids_for_roles',
return_value=[1, 2])
def test_generates_scripts_path_in_case_of_several_plugins(self, _):
def test_generates_scripts_path_in_case_of_several_plugins(self):
stage = 'pre_deployment'
plugins = []
names = ['plugin_name1', 'plugin_name2']
@ -122,8 +116,6 @@ class TestBasePluginDeploymentHooksSerializer(base.BaseTestCase):
self.assertEqual(script_paths, names)
@mock.patch('nailgun.orchestrator.plugins_serializers.get_uids_for_roles',
return_value=[1, 2])
class TestTasksDeploymentOrder(base.BaseTestCase):
def setUp(self):
@ -134,7 +126,9 @@ class TestTasksDeploymentOrder(base.BaseTestCase):
{'id': 2, 'role': 'compute'}]
self.hook = BasePluginDeploymentHooksSerializer(
self.nodes,
self.cluster)
self.cluster,
role_resolver=NullResolver([x['id'] for x in self.nodes])
)
def make_plugin_mock_with_stages(self, plugin_name, stages):
common_attrs = {
@ -155,7 +149,7 @@ class TestTasksDeploymentOrder(base.BaseTestCase):
return plugin
def test_sorts_plugins_by_numerical_postfixes(self, _):
def test_sorts_plugins_by_numerical_postfixes(self):
plugin1 = self.make_plugin_mock_with_stages('name1', [
'pre_deployment/-100',
'pre_deployment/100.0',
@ -197,14 +191,13 @@ class TestPluginsPreDeploymentHooksSerializer(base.BaseTestCase):
]
self.hook = PluginsPreDeploymentHooksSerializer(
self.cluster,
self.nodes)
self.nodes,
role_resolver=NullResolver([x['id'] for x in self.nodes])
)
plugin = mock.Mock(tasks=[], deployment_tasks=[])
self.plugins = [plugin]
@mock.patch(
'nailgun.orchestrator.plugins_serializers.get_uids_for_tasks',
return_value=[1, 2])
@mock.patch(
'nailgun.orchestrator.plugins_serializers.'
'templates.make_ubuntu_sources_task',
@ -220,7 +213,7 @@ class TestPluginsPreDeploymentHooksSerializer(base.BaseTestCase):
return_value={'task_type': 'apt_update_task',
'parameters': {}})
def test_create_repositories_ubuntu_does_not_generate_prefences_if_none(
self, _, __, ___, ____):
self, *_):
self.cluster.release.operating_system = consts.RELEASE_OS.ubuntu
tasks = self.hook.create_repositories(self.plugins)
self.assertItemsEqual(

View File

@ -17,7 +17,7 @@
import mock
from nailgun import consts
from nailgun.orchestrator import task_based_deploy
from nailgun.orchestrator import task_based_deployment
from nailgun.test.base import BaseTestCase
from nailgun.test.base import BaseUnitTest
@ -34,7 +34,7 @@ class TestTaskSerializers(BaseTestCase):
'roles': ['compute']}
]
)
self.serializer = task_based_deploy.TasksSerializer(
self.serializer = task_based_deployment.TasksSerializer(
self.env.clusters[-1], self.env.nodes
)
@ -79,7 +79,7 @@ class TestTaskSerializers(BaseTestCase):
{"id": "test2", "role": ["compute"], "type": "stage"},
]
self.assertRaises(
task_based_deploy.errors.TaskBaseDeploymentNotAllowed,
task_based_deployment.errors.TaskBaseDeploymentNotAllowed,
self.serializer.serialize,
self.env.clusters[-1], self.env.nodes, tasks
)
@ -87,11 +87,11 @@ class TestTaskSerializers(BaseTestCase):
def test_process_task_de_duplication(self):
task = {"id": "test", "type": "puppet", "parameters": {}}
self.serializer.process_task(
task, ["1"], task_based_deploy.NullResolver
task, ["1"], task_based_deployment.NullResolver
)
# check de-duplication
self.serializer.process_task(
task, ["1"], task_based_deploy.NullResolver
task, ["1"], task_based_deployment.NullResolver
)
self.assertItemsEqual(["1"], self.serializer.tasks_per_node)
self.assertItemsEqual(["test"], self.serializer.tasks_per_node["1"])
@ -110,7 +110,7 @@ class TestTaskSerializers(BaseTestCase):
"id": "test", "type": "puppet", "parameters": {}, 'skipped': True
}
self.serializer.process_task(
task, ["1"], task_based_deploy.NullResolver
task, ["1"], task_based_deployment.NullResolver
)
self.assertItemsEqual(["1"], self.serializer.tasks_per_node)
self.assertItemsEqual(["test"], self.serializer.tasks_per_node["1"])
@ -127,7 +127,7 @@ class TestTaskSerializers(BaseTestCase):
def test_process_noop_task(self):
task = {"id": "test", "type": "stage", "role": "*"}
self.serializer.process_task(
task, ["1"], task_based_deploy.NullResolver
task, ["1"], task_based_deployment.NullResolver
)
self.assertItemsEqual(["1"], self.serializer.tasks_per_node)
self.assertItemsEqual(["test"], self.serializer.tasks_per_node["1"])
@ -277,7 +277,7 @@ class TestTaskSerializers(BaseTestCase):
self.serializer.resolve_relation('task_1', node_ids, False)
)
@mock.patch.object(task_based_deploy, 'logger')
@mock.patch.object(task_based_deployment, 'logger')
def test_resolve_relation_warn_if_not_found(self, m_logger):
node_ids = ['1', '2', '3']
self.serializer.tasks_per_node = dict(
@ -296,17 +296,17 @@ class TestTaskSerializers(BaseTestCase):
def test_ensure_task_based_deployment_allowed(self):
self.assertRaises(
task_based_deploy.errors.TaskBaseDeploymentNotAllowed,
task_based_deployment.errors.TaskBaseDeploymentNotAllowed,
self.serializer.ensure_task_based_deploy_allowed,
{'id': 'task'}
)
self.assertRaises(
task_based_deploy.errors.TaskBaseDeploymentNotAllowed,
task_based_deployment.errors.TaskBaseDeploymentNotAllowed,
self.serializer.ensure_task_based_deploy_allowed,
{'id': 'task', 'version': '1.2.3'}
)
self.assertNotRaises(
task_based_deploy.errors.TaskBaseDeploymentNotAllowed,
task_based_deployment.errors.TaskBaseDeploymentNotAllowed,
self.serializer.ensure_task_based_deploy_allowed,
{'id': 'task', 'version': consts.TASK_CROSS_DEPENDENCY}
)
@ -326,7 +326,7 @@ class TestNoopSerializer(BaseTestCase):
)
def test_get_uids(self):
serializer = task_based_deploy.NoopSerializer(
serializer = task_based_deployment.NoopSerializer(
{'id': 'deploy_start', 'type': 'stage'},
self.env, self.env.nodes
)
@ -338,7 +338,7 @@ class TestNoopSerializer(BaseTestCase):
)
def test_serialize(self):
serializer = task_based_deploy.NoopSerializer(
serializer = task_based_deployment.NoopSerializer(
{'id': 'deploy_start', 'type': 'stage'},
self.env, self.env.nodes
)
@ -365,22 +365,22 @@ class TestDeploymentTaskSerializer(BaseUnitTest):
return task
def test_get_stage_serializer(self):
factory = task_based_deploy.DeployTaskSerializer()
factory = task_based_deployment.DeployTaskSerializer()
self.assertIs(
task_based_deploy.CreateVMsOnCompute,
task_based_deployment.CreateVMsOnCompute,
factory.get_stage_serializer(
self.make_task('generate_vms')
)
)
self.assertIs(
task_based_deploy.NoopSerializer,
task_based_deployment.NoopSerializer,
factory.get_stage_serializer(
self.make_task('post_deployment', type='stage')
)
)
self.assertIs(
task_based_deploy.NoopSerializer,
task_based_deployment.NoopSerializer,
factory.get_stage_serializer(
self.make_task('pre_deployment', type='skipped')
)
@ -390,14 +390,29 @@ class TestDeploymentTaskSerializer(BaseUnitTest):
factory.get_stage_serializer(
self.make_task('upload_repos')
),
task_based_deploy.StandartConfigRolesHook
task_based_deployment.StandartConfigRolesHook
)
)
def test_get_stage_serializer_for_plugins(self):
factory = task_based_deployment.DeployTaskSerializer()
self.assertIs(
task_based_deployment.PluginPostDeploymentSerializer,
factory.get_stage_serializer(
{"type": consts.PLUGIN_POST_DEPLOYMENT_HOOK}
)
)
self.assertIs(
task_based_deployment.PluginPreDeploymentSerializer,
factory.get_stage_serializer(
{"type": consts.PLUGIN_PRE_DEPLOYMENT_HOOK}
)
)
class TestTaskProcessor(BaseUnitTest):
def setUp(self):
self.processor = task_based_deploy.TaskProcessor()
self.processor = task_based_deployment.TaskProcessor()
def test_link_tasks_on_same_node(self):
previous = {