def side_effect(*args):
     task_id = str(args[0])
     LOG.debug(task_id)
     # Basic task
     if task_id == '11111111-1111-1111-1111-111111111111':
         new_task = objects.Task()
         new_task.task_id = '11111111-1111-1111-1111-111111111111'
         new_task.result = objects.TaskStatus()
         new_task.result.set_status(hd_fields.ActionResult.Failure)
         new_task.result.add_status_msg(msg='Test',
                                        error=True,
                                        ctx_type='N/A',
                                        ctx='N/A')
         return new_task
     # Task not found
     if task_id == '11111111-1111-1111-1111-111111111112':
         return None
     # Task layers
     if task_id == '11111111-1111-1111-1111-111111111113':
         new_task = objects.Task()
         new_task.task_id = '11111111-1111-1111-1111-111111111113'
         new_task.subtask_id_list = [
             '11111111-1111-1111-1111-111111111114',
             '11111111-1111-1111-1111-111111111115'
         ]
         return new_task
     if task_id == '11111111-1111-1111-1111-111111111114':
         new_task = objects.Task()
         new_task.task_id = '11111111-1111-1111-1111-111111111114'
         return new_task
     if task_id == '11111111-1111-1111-1111-111111111115':
         new_task = objects.Task()
         new_task.task_id = '11111111-1111-1111-1111-111111111115'
         new_task.subtask_id_list = [
             '11111111-1111-1111-1111-111111111116',
             '11111111-1111-1111-1111-111111111117'
         ]
         return new_task
     if task_id == '11111111-1111-1111-1111-111111111116':
         new_task = objects.Task()
         new_task.task_id = '11111111-1111-1111-1111-111111111116'
         new_task.result = objects.TaskStatus()
         new_task.result.set_status(hd_fields.ActionResult.Failure)
         new_task.result.add_status_msg(msg='Test',
                                        error=True,
                                        ctx_type='N/A',
                                        ctx='N/A')
         LOG.debug('error_count')
         LOG.debug(new_task.result.error_count)
         return new_task
     LOG.debug('returning None')
     return None
Esempio n. 2
0
    def test_build_data_collection(self, setup, blank_state, mocker,
                                   deckhand_orchestrator):
        """Test that the build data collection from MaaS works."""
        sample_data = {
            'lshw': '<xml><test>foo</test></xml>'.encode(),
            'lldp': '<xml><test>bar</test></xml>'.encode(),
        }
        bson_data = bson.loads(bson.dumps(sample_data))

        machine = mocker.MagicMock()
        mocker_config = {
            'get_details.return_value': bson_data,
            'hostname': 'foo',
        }
        machine.configure_mock(**mocker_config)

        task = objects.Task(statemgr=blank_state)

        action = ConfigureHardware(task, deckhand_orchestrator, blank_state)

        action.collect_build_data(machine)

        bd = blank_state.get_build_data(node_name='foo')

        assert len(bd) == 2
Esempio n. 3
0
    def test_subtask_append(self, blank_state):
        """Test that the atomic subtask append method works."""

        task = objects.Task(action='deploy_node',
                            design_ref='http://foobar/design')
        subtask = objects.Task(action='deploy_node',
                               design_ref='http://foobar/design',
                               parent_task_id=task.task_id)

        blank_state.post_task(task)
        blank_state.post_task(subtask)
        blank_state.add_subtask(task.task_id, subtask.task_id)

        test_task = blank_state.get_task(task.task_id)

        assert subtask.task_id in test_task.subtask_id_list
Esempio n. 4
0
    def task_task_node_filter(self, blank_state):
        """Test that a persisted task persists node filter."""
        ctx = DrydockRequestContext()
        ctx.user = '******'
        ctx.external_marker = str(uuid.uuid4())

        node_filter = {
            'filter_set_type': 'union',
            'filter_set': [{
                'node_names': ['foo'],
                'filter_type': 'union'
            }]
        }
        task = objects.Task(action='deploy_node',
                            node_filter=node_filter,
                            design_ref='http://foo.bar/design',
                            context=ctx)

        result = blank_state.post_task(task)

        assert result

        saved_task = blank_state.get_task(task.get_id())

        assert saved_task.node_filter == node_filter
    def populateddb(self, blank_state):
        """Add dummy task to test against."""
        task = objects.Task(
            action='prepare_site', design_ref='http://test.com/design')

        blank_state.post_task(task)

        return task
    def test_task_failure_focus(self, setup):
        """Test that marking a task failed works correctly."""
        task = objects.Task(action=hd_fields.OrchestratorAction.Noop,
                            design_ref="http://foo.com")

        task.failure(focus='foo')

        assert task.result.status == hd_fields.ActionResult.Failure
        assert 'foo' in task.result.failures
    def test_task_success_focus(self, setup):
        """Test that marking a task successful works correctly."""
        task = objects.Task(action=hd_fields.OrchestratorAction.Noop,
                            design_ref="http://foo.com")

        task.success(focus='foo')

        assert task.result.status == hd_fields.ActionResult.Success
        assert 'foo' in task.result.successes
Esempio n. 8
0
    def test_task_insert(self, blank_state):
        """Test that a task can be inserted into the database."""
        ctx = DrydockRequestContext()
        ctx.user = '******'
        ctx.external_marker = str(uuid.uuid4())

        task = objects.Task(action='deploy_node',
                            design_ref='http://foo.bar/design',
                            context=ctx)

        result = blank_state.post_task(task)

        assert result
    def test_task_failure_nf(self, setup):
        """Test that a task can generate a node filter based on its failure."""
        task = objects.Task(action=hd_fields.OrchestratorAction.Noop,
                            design_ref="http://foo.com")

        expected_nf = {
            'filter_set_type': 'intersection',
            'filter_set': [{
                'node_names': ['foo'],
                'filter_type': 'union',
            }]
        }

        task.failure(focus='foo')

        nf = task.node_filter_from_failures()

        assert nf == expected_nf
Esempio n. 10
0
    def create_task(self, **kwargs):
        """Create a new task and persist it."""
        new_task = objects.Task(statemgr=self.state_manager, **kwargs)
        self.state_manager.post_task(new_task)

        return new_task