Beispiel #1
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
Beispiel #2
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
Beispiel #3
0
    def test_apienforcer_decorator(self, mocker):
        ''' DrydockPolicy.authorized() should correctly use oslo_policy to enforce
            RBAC policy based on a DrydockRequestContext instance. authorized() is
            called via the policy.ApiEnforcer decorator.
        '''

        mocker.patch('oslo_policy.policy.Enforcer')

        ctx = DrydockRequestContext()
        policy_engine = policy.DrydockPolicy()

        # Configure context
        project_id = str(uuid.uuid4())
        ctx.project_id = project_id
        user_id = str(uuid.uuid4())
        ctx.user_id = user_id
        ctx.roles = ['admin']
        ctx.set_policy_engine(policy_engine)

        # Configure mocked request and response
        req = mocker.MagicMock()
        resp = mocker.MagicMock()
        req.context = ctx

        self.target_function(req, resp)

        expected_calls = [
            mocker.call.authorize('physical_provisioner:read_task', {
                'project_id': project_id,
                'user_id': user_id
            }, ctx.to_policy_view())
        ]

        policy_engine.enforcer.assert_has_calls(expected_calls)
    def test_authorize_context(self, mocker):
        ''' DrydockPolicy.authorized() should correctly use oslo_policy to enforce
            RBAC policy based on a DrydockRequestContext instance
        '''

        mocker.patch('oslo_policy.policy.Enforcer')
        ctx = DrydockRequestContext()

        # Configure context
        project_id = str(uuid.uuid4().hex)
        ctx.project_id = project_id
        user_id = str(uuid.uuid4().hex)
        ctx.user_id = user_id
        ctx.roles = ['admin']

        # Define action
        policy_action = 'physical_provisioner:read_task'

        policy_engine = DrydockPolicy()
        policy_engine.authorize(policy_action, ctx)

        expected_calls = [
            mocker.call.authorize(policy_action, {
                'project_id': project_id,
                'user_id': user_id
            }, ctx.to_policy_view())
        ]

        policy_engine.enforcer.assert_has_calls(expected_calls)
Beispiel #5
0
    def from_db(cls, d):
        """Create an instance from a DB-based dictionary.

        :param d: Dictionary of instance data
        """
        i = Task()

        i.task_id = uuid.UUID(bytes=bytes(d.get('task_id')))

        if d.get('parent_task_id', None) is not None:
            i.parent_task_id = uuid.UUID(bytes=bytes(d.get('parent_task_id')))

        if d.get('subtask_id_list', None) is not None:
            for t in d.get('subtask_id_list'):
                i.subtask_id_list.append(uuid.UUID(bytes=bytes(t)))

        simple_fields = [
            'status',
            'created',
            'created_by',
            'design_ref',
            'action',
            'terminated',
            'terminated_by',
            'terminate',
            'updated',
            'retry',
            'node_filter',
        ]

        for f in simple_fields:
            setattr(i, f, d.get(f, None))

        # Recreate result
        i.result = TaskStatus()
        i.result.error_count = d.get('result_error_count')
        i.result.message = d.get('result_message')
        i.result.reason = d.get('result_reason')
        i.result.status = d.get('result_status')
        i.result.successes = d.get('result_successes', [])
        i.result.failures = d.get('result_failures', [])
        i.result.links = d.get('result_links', [])

        # Deserialize the request context for this task
        if i.request_context is not None:
            i.request_context = DrydockRequestContext.from_dict(
                i.request_context)

        return i
Beispiel #6
0
    def test_read_tasks_builddata(self, falcontest, blank_state,
                                  deckhand_orchestrator):
        """Test that the tasks API includes build data when prompted."""
        req_hdr = {
            'Content-Type': 'application/json',
            'X-IDENTITY-STATUS': 'Confirmed',
            'X-USER-NAME': 'Test',
            'X-ROLES': 'admin',
        }
        # Seed DB with a task
        ctx = DrydockRequestContext()
        task = deckhand_orchestrator.create_task(
            action=hd_fields.OrchestratorAction.PrepareNodes,
            design_ref='http://foo.com',
            context=ctx)

        # Seed DB with build data for task
        build_data = objects.BuildData(node_name='foo',
                                       task_id=task.get_id(),
                                       generator='hello_world',
                                       data_format='text/plain',
                                       data_element='Hello World!')
        blank_state.post_build_data(build_data)

        url = '/api/v1.0/tasks/%s' % str(task.get_id())

        resp = falcontest.simulate_get(url,
                                       headers=req_hdr,
                                       query_string="builddata=true")

        assert resp.status == falcon.HTTP_200

        resp_body = resp.json

        assert isinstance(resp_body.get('build_data'), list)

        assert len(resp_body.get('build_data')) == 1