Added fault_tolerance_group to deployment metadata

This property contains list of groups, that is built from
tasks with type 'group' and each task may contain property
fault_tolerance, that shall be moved from openstack.yaml
to deployment tasks.
For plugins this attribute is filled from roles_metadata
for all tasks with type group (for backward compatibility).

DocImpact
Partial-Bug: 1435610
Change-Id: I1969b953eca667c09248a6b67ffee37bfd20f474
This commit is contained in:
Bulat Gaifullin
2016-05-30 19:51:18 +03:00
parent 40041a1132
commit ebe80dc4ef
7 changed files with 182 additions and 15 deletions

View File

@@ -63,7 +63,7 @@ class TestTransactionSerializer(BaseUnitTest):
'type': 'puppet', 'version': '2.0.0',
'parameters': {},
'cross_depended_by': [{'name': 'task3'}]
},
}
]
cls.nodes = [
@@ -271,12 +271,23 @@ class TestTransactionSerializer(BaseUnitTest):
'cross_depends': [{'name': 'task2', 'role': 'self'}],
})
tasks.append({
'type': 'group', 'roles': 'custom',
'id': 'custom', 'type': 'group', 'roles': 'custom',
'fault_tolerance': '100%',
'tasks': ['task4', 'task2']
})
tasks.append({
'id': 'controller', 'type': 'group', 'roles': 'controller',
'fault_tolerance': '0%',
'tasks': ['task4', 'task2']
})
tasks.append({
'id': 'compute', 'type': 'group', 'roles': 'compute',
'tasks': ['task4', 'task2']
})
serialized = lcm.TransactionSerializer.serialize(
self.context, tasks, self.role_resolver
)[1]
)
tasks_per_node = serialized[1]
self.datadiff(
[
{
@@ -291,11 +302,36 @@ class TestTransactionSerializer(BaseUnitTest):
},
],
serialized['4'],
tasks_per_node['4'],
ignore_keys=['parameters', 'fail_on_error'],
compare_sorted=True
)
tasks_metadata = serialized[2]
self.datadiff(
{
'fault_tolerance_groups': [
{
'name': 'custom',
'node_ids': ['4'],
'fault_tolerance': 1
},
{
'name': 'controller',
'node_ids': ['1'],
'fault_tolerance': 0
},
{
'name': 'compute',
'node_ids': ['2'],
'fault_tolerance': 2
}
]
},
tasks_metadata,
compare_sorted=True
)
def test_expand_dependencies(self):
serializer = lcm.TransactionSerializer(
self.context, self.role_resolver
@@ -404,3 +440,33 @@ class TestTransactionSerializer(BaseUnitTest):
)
def test_multi_processing_serialization(self):
self.test_serialize_integration()
def test_get_fault_tolerance(self):
self.assertEqual(
11,
lcm.TransactionSerializer.calculate_fault_tolerance(None, 10)
)
self.assertEqual(
10,
lcm.TransactionSerializer.calculate_fault_tolerance('10', 10)
)
self.assertEqual(
10,
lcm.TransactionSerializer.calculate_fault_tolerance(10, 10)
)
self.assertEqual(
1,
lcm.TransactionSerializer.calculate_fault_tolerance('10%', 10)
)
self.assertEqual(
11,
lcm.TransactionSerializer.calculate_fault_tolerance('a%', 10)
)
self.assertEqual(
9,
lcm.TransactionSerializer.calculate_fault_tolerance('-10%', 10)
)
self.assertEqual(
9,
lcm.TransactionSerializer.calculate_fault_tolerance('-1', 10)
)

View File

@@ -51,14 +51,16 @@ class TestPluginBase(base.BaseTestCase):
'role_y': {
'name': 'Role Y',
'description': 'Role Y is ...',
'restrictions': []
'restrictions': [],
'fault_tolerance': '5%'
},
'role_z': {
'name': 'Role Z',
'description': 'Role Z is ...',
'restrictions': [
'settings:some.stuff.value == false'
]
],
'fault_tolerance': '10%'
}
}
)
@@ -175,6 +177,38 @@ class TestPluginBase(base.BaseTestCase):
self.assertEqual(depl_task['parameters'].get('cwd'),
self.plugin_adapter.slaves_scripts_path)
@mock.patch('nailgun.plugins.adapters.DeploymentGraph')
def test_fault_tolerance_set_for_task_groups(self, deployment_graph_mock):
deployment_graph_mock.get_for_model.return_value = True
deployment_graph_mock.get_tasks.return_value = [
{
'id': 'role_x',
'type': consts.ORCHESTRATOR_TASK_TYPES.group,
'roles': ['role_x'],
'fault_tolerance': '0'
},
{
'id': 'role_y',
'type': consts.ORCHESTRATOR_TASK_TYPES.group,
'roles': ['role_y'],
},
{
'id': 'role_z',
'type': consts.ORCHESTRATOR_TASK_TYPES.group,
'roles': ['role_z'],
'fault_tolerance': '50%'
},
]
depl_task = self.plugin_adapter.get_deployment_tasks()
fault_tolerance_groups = {
task['id']: task.get('fault_tolerance')
for task in depl_task
}
self.assertEqual(
{'role_x': '0', 'role_y': '5%', 'role_z': '50%'},
fault_tolerance_groups
)
def test_get_deployment_tasks_params_not_changed(self):
expected = 'path/to/some/dir'
dg = DeploymentGraph.get_for_model(self.plugin_adapter.plugin)