Beispiel #1
0
    def test_empty_orchestration_response(self):
        orchestration_response = Response(
            b'{"response": []}',
            'JSON',
            200,
        )

        handled_responses = csr.process_orchestration(orchestration_response)

        assert handled_responses == []
Beispiel #2
0
    def add_orchestration_rule(
            self,
            service_definition: str,
            method: str,
            protocol: str = '',
            access_policy: str = '',
            payload_format: str = '',
            # TODO: Should **kwargs just be orchestration_flags and preferred_providers?
            orchestration_flags: OrchestrationFlags = OrchestrationFlags.OVERRIDE_STORE,
            **kwargs,
    ) -> None:
        """
        Add orchestration rule for provided_service definition

        Args:
            service_definition: Service definition that is looked up from the orchestrator.
            method: The HTTP method given in uppercase that is used to consume the provided_service.
            access_policy: Service access policy.
        """

        requested_service = Service(
                service_definition,
                interface=ServiceInterface.with_access_policy(
                        protocol,
                        access_policy,
                        payload_format,
                ),
                access_policy=access_policy
        )

        orchestration_form = forms.OrchestrationForm.make(
                self.system,
                requested_service,
                orchestration_flags,
                **kwargs
        )

        # TODO: Add an argument for arrowhead forms in consume_service, and one for the ssl-files
        orchestration_response = self.consume_service(
                CoreServices.ORCHESTRATION.service_definition,
                json=orchestration_form.dto(),
                cert=self.cert,
        )

        rules = responses.process_orchestration(orchestration_response, method)

        for rule in rules:
            self.orchestration_rules.store(rule)
Beispiel #3
0
    def test_orchestration_response(self, orchestration_data):
        orchestrator_response = Response(
            json.dumps(orchestration_data).encode(),
            'JSON',
            200,
        )

        orchestration_rules = csr.process_orchestration(
            orchestrator_response, 'GET')
        assert len(orchestration_rules) == len(orchestration_data['response'])

        first_rule = orchestration_rules[0]

        assert first_rule.service_definition == 'test'
        assert first_rule.endpoint == '127.0.0.1:3456/test/provided_service'
        assert first_rule.method == 'GET'
        assert first_rule.authorization_token == 'h983u43h9834p'
        assert first_rule.access_policy == 'TOKEN'
Beispiel #4
0
    async def add_orchestration_rule(  # type: ignore
            self,
            service_definition: str,
            method: str,
            protocol: str = '',
            access_policy: str = '',
            payload_format: str = '',
            orchestration_flags: OrchestrationFlags = OrchestrationFlags.OVERRIDE_STORE,
            **kwargs,
    ):
        """
        Add orchestration rule for provided_service definition

        Args:
            service_definition: Service definition that is looked up from the orchestrator.
            method: The HTTP method given in uppercase that is used to consume the provided_service.
            access_policy: Service access policy.
        """

        requested_service = Service.make(
                service_definition,
                protocol=protocol,
                access_policy=access_policy,
                payload_format=payload_format,
        )

        orchestration_form = arrowhead_client.client.core_service_forms.client.OrchestrationForm.make(
                self.system,
                requested_service,
                orchestration_flags,
                **kwargs
        )

        # TODO: Add an argument for arrowhead forms in consume_service, and one for the ssl-files
        orchestration_response = await self.consume_service(
                CoreServices.ORCHESTRATION.service_definition,
                json=orchestration_form.dto(),
                # cert=self.cert,
        )

        rules = responses.process_orchestration(orchestration_response, method)

        for rule in rules:
            self.orchestration_rules.store(rule)
Beispiel #5
0
    def test_bad_orchestration_response(self):
        orchestrator_response = Response(b'{"errorMessage": ""}', 'JSON', 400)

        with pytest.raises(errors.OrchestrationError):
            orchestration_rules = csr.process_orchestration(
                orchestrator_response, 'GET')