def test_process_noop_task(self):
     task = {"id": "test", "type": "stage", "role": "*"}
     self.serializer.process_task(task,
                                  task_based_deployment.NullResolver(["1"]))
     self.assertItemsEqual(["1"], self.serializer.tasks_connections)
     self.assertItemsEqual(["test"], self.serializer.tasks_connections["1"])
     self.assertEqual("test",
                      self.serializer.tasks_connections["1"]["test"]["id"])
     self.assertEqual(
         "skipped", self.serializer.tasks_connections["1"]["test"]["type"])
     self.assertNotIn("skipped",
                      self.serializer.tasks_connections["1"]["test"])
 def test_process_task_de_duplication(self):
     task = {
         "id": "test",
         "type": "puppet",
         "parameters": {},
         "version": "2.0.0"
     }
     node_id = self.env.nodes[-1].uid
     self.serializer.process_task(
         task, task_based_deployment.NullResolver([node_id]))
     # check de-duplication
     self.serializer.process_task(
         task, task_based_deployment.NullResolver([node_id]))
     self.assertItemsEqual([node_id], self.serializer.tasks_connections)
     self.assertItemsEqual(["test"],
                           self.serializer.tasks_connections[node_id])
     self.assertEqual(
         "test", self.serializer.tasks_connections[node_id]["test"]["id"])
     self.assertEqual(
         "puppet",
         self.serializer.tasks_connections[node_id]["test"]["type"])
     self.assertNotIn(
         "skipped",
         self.serializer.tasks_connections[node_id]["test"]["type"])
    def test_process_separate_task_attributes_properly(self):
        task = {"id": "test", "type": "puppet", "role": "*"}
        task_prossesor = mock.MagicMock()
        serialized_task = {
            'id': 'test',
            'type': 'puppet',
            'uids': ['1'],
            'parameters': {
                'cwd': '/'
            },
            'requires': ['test2'],
            'required_for': 'test3',
            'cross_depends': [{
                'role': '*',
                'name': 'test4'
            }],
            'cross_depended_by': [{
                'role': '*',
                'name': 'test5'
            }],
            'requires_ex': [(None, 'test6')],
            'required_for_ex': [(None, 'test7')]
        }
        task_prossesor.process_tasks.return_value = [serialized_task.copy()]
        self.serializer.task_processor = task_prossesor

        self.serializer.process_task(task,
                                     task_based_deployment.NullResolver(["1"]))
        del serialized_task['uids']
        paramters = serialized_task.pop('parameters')
        self.assertItemsEqual(["1"], self.serializer.tasks_connections)
        self.assertItemsEqual(["test"], self.serializer.tasks_connections["1"])
        self.assertEqual(serialized_task,
                         self.serializer.tasks_connections["1"]['test'])
        self.assertEqual(
            {
                'id': 'test',
                'type': 'puppet',
                'parameters': paramters
            }, self.serializer.tasks_dictionary['test'])
 def test_resolve_relations(self):
     node_ids = ['1', '2']
     self.serializer.tasks_connections = {
         '1': {
             "task_1": {
                 "id": "task_1",
                 "requires": ["task_2"],
                 "cross_depends": {},
                 "cross_depended_by": {},
                 "type": "skipped",
                 "required_for": ["task_2"],
             },
             "task_2": {
                 "id": "task_2",
                 "requires": ["task"],
                 "required_for": ["task"],
                 "cross_depended_by": {},
                 "type": "skipped",
                 "cross_depends": [{
                     "name": "task"
                 }]
             }
         },
         '2': {
             "task_1": {
                 "id": "task_1",
                 "requires": ["task_2"],
                 "required_for": [],
                 "cross_depended_by": {},
                 "type": "skipped",
                 "cross_depends": [{
                     "name": "task"
                 }]
             },
             "task_2": {
                 "id": "task_2",
                 "required_for": ["task"],
                 "cross_depends": {},
                 "cross_depended_by": {},
                 "type": "skipped",
                 "requires": []
             }
         },
         None: {}
     }
     self.serializer.task_processor.origin_task_ids = {'task_1': 'task'}
     self.serializer.resolver = task_based_deployment.NullResolver(node_ids)
     self.serializer.resolve_dependencies()
     self.assertItemsEqual([
         {
             'node_id': '1',
             'name': 'task_2'
         },
     ], self.serializer.tasks_connections["1"]["task_1"]["required_for"])
     self.assertItemsEqual([
         {
             'node_id': '1',
             'name': 'task_end'
         },
         {
             'node_id': '2',
             'name': 'task_end'
         },
     ], self.serializer.tasks_connections["1"]["task_2"]["requires"])
     self.assertItemsEqual([
         {
             'node_id': '1',
             'name': 'task_start'
         },
     ], self.serializer.tasks_connections["1"]["task_2"]["required_for"])
     self.assertItemsEqual([
         {
             'node_id': '1',
             'name': 'task_end'
         },
         {
             'node_id': '2',
             'name': 'task_2'
         },
     ], self.serializer.tasks_connections["2"]["task_1"]["requires"])
     self.assertItemsEqual([
         {
             'node_id': '2',
             'name': 'task_start'
         },
     ], self.serializer.tasks_connections["2"]["task_2"]["required_for"])