def test_need_update_task(self):
        serializer = lcm.TransactionSerializer(self.context,
                                               self.role_resolver)
        self.assertTrue(
            serializer.need_update_task({}, {
                "id": "task1",
                "type": "puppet"
            }))
        self.assertTrue(
            serializer.need_update_task({"task1": {
                "type": "skipped"
            }}, {
                "id": "task1",
                "type": "puppet"
            }))

        self.assertFalse(
            serializer.need_update_task({"task1": {
                "type": "skipped"
            }}, {
                "id": "task1",
                "type": "skipped"
            }))

        self.assertFalse(
            serializer.need_update_task({"task1": {
                "type": "puppet"
            }}, {
                "id": "task1",
                "type": "skipped"
            }))
 def test_resolve_nodes(self):
     serializer = lcm.TransactionSerializer(self.context,
                                            self.role_resolver)
     self.assertEqual([None],
                      serializer.resolve_nodes({
                          'id':
                          'deploy_start',
                          'type':
                          consts.ORCHESTRATOR_TASK_TYPES.stage
                      }))
     self.assertItemsEqual(
         ['2'],
         serializer.resolve_nodes(
             {
                 'id': 'deploy_start',
                 'type': consts.ORCHESTRATOR_TASK_TYPES.skipped,
                 'groups': ['compute']
             }, ))
     self.assertItemsEqual(['1'],
                           serializer.resolve_nodes({
                               'id':
                               'deploy_start',
                               'type':
                               consts.ORCHESTRATOR_TASK_TYPES.skipped,
                               'roles': ['controller']
                           }))
    def test_expand_cross_dependencies(self):
        serializer = lcm.TransactionSerializer(self.context,
                                               self.role_resolver)
        serializer.tasks_graph = {
            '1': {
                'task1': {},
                'task2': {}
            },
            '2': {
                'task3': {},
                'task2': {},
                'task1': {}
            },
            '3': {
                'task3': {}
            },
            None: {
                'deploy_start': {},
                'deploy_end': {}
            }
        }
        self.assertItemsEqual([],
                              serializer.expand_cross_dependencies(
                                  'task1', '1', None))
        self.assertItemsEqual([],
                              serializer.expand_cross_dependencies(
                                  'task1', '1', []))

        self.assertItemsEqual([('deploy_start', None), ('task2', '2'),
                               ('task3', '2'), ('task3', '3')],
                              serializer.expand_cross_dependencies(
                                  'task2', '1', [{
                                      'name': 'deploy_start',
                                      'role': None
                                  }, {
                                      'name': 'task2',
                                      'role': '/.*/'
                                  }, {
                                      'name': 'task3',
                                      'role': '/.*/'
                                  }]))
        self.assertItemsEqual([('task2', '2'), ('task1', '1')],
                              serializer.expand_cross_dependencies(
                                  'task2', '1', [{
                                      'name': 'task2'
                                  }, {
                                      'name': 'task1',
                                      'role': 'self'
                                  }]))
 def test_expand_dependencies(self):
     serializer = lcm.TransactionSerializer(
         self.context, self.resolver
     )
     serializer.tasks_graph = {
         '1': {'task1': {}},
         '2': {'task2': {}},
         None: {'deploy_start': {}, 'deploy_end': {}}
     }
     self.assertItemsEqual([], serializer.expand_dependencies('1', None))
     self.assertItemsEqual([], serializer.expand_dependencies('1', []))
     self.assertItemsEqual(
         [('deploy_start', None), ('task2', '2')],
         serializer.expand_dependencies('2', ['deploy_start', 'task2'])
     )
 def test_dependencies_de_duplication(self):
     serializer = lcm.TransactionSerializer(self.context,
                                            self.role_resolver)
     serializer.tasks_graph = {
         None: {},
         '1': {
             'task1': {
                 'id': 'task1',
                 'requires': ['task2'],
                 'cross_depends': [
                     {
                         'role': 'self',
                         'name': 'task2'
                     },
                 ]
             },
             'task2': {
                 'id': 'task2',
                 'required_for': ['task1'],
                 'cross_depended_by': [{
                     'role': 'self',
                     'name': 'task1'
                 }]
             }
         }
     }
     serializer.resolve_dependencies()
     self.datadiff(
         {
             'task1': {
                 'id': 'task1',
                 'requires': [{
                     'node_id': '1',
                     'name': 'task2'
                 }],
             },
             'task2': {
                 'id': 'task2',
                 'required_for': [{
                     'node_id': '1',
                     'name': 'task1'
                 }],
             }
         },
         serializer.tasks_graph['1'],
         compare_sorted=True)