Esempio n. 1
0
    def test_supports_volume_mounts(self):
        self.broker.bind.return_value = Binding(volume_mounts=[
            VolumeMount(driver="",
                        container_dir="",
                        mode="",
                        device_type="",
                        device=SharedDevice(volume_id="",
                                            mount_config=dict(config1="1")))
        ])

        response = self.client.put(
            "/v2/service_instances/here-instance_id/service_bindings/here-binding_id",
            data=json.dumps({
                "service_id": "service-guid-here",
                "plan_id": "plan-guid-here",
                "bind_resource": {
                    "app_guid": "app-guid-here"
                }
            }),
            headers={
                'X-Broker-Api-Version': '2.13',
                'Content-Type': 'application/json',
                'Authorization': self.auth_header
            })

        self.assertEqual(response.status_code, http.HTTPStatus.CREATED)
        self.assertEqual(
            response.json,
            dict(volume_mounts=[
                dict(driver="",
                     container_dir="",
                     mode="",
                     device_type="",
                     device=dict(volume_id="", mount_config=dict(config1="1")))
            ]))
Esempio n. 2
0
    def test_bind_ignores_unknown_parameters(self):
        self.broker.bind.return_value = Binding(
            credentials=expected_credentials
        )

        self.client.put(
            "/v2/service_instances/here-instance_id/service_bindings/here-binding_id",
            data=json.dumps({
                "service_id": "service-guid-here",
                "plan_id": "plan-guid-here",
                "unknown": "unknown",
                "bind_resource": {
                    "unknown": "unknown"
                },
            }),
            headers={
                'X-Broker-Api-Version': '2.13',
                'Content-Type': 'application/json',
                'Authorization': self.auth_header
            })

        actual_instance_id, actual_binding_id, actual_details = self.broker.bind.call_args[0]
        self.assertEqual(actual_instance_id, "here-instance_id")
        self.assertEqual(actual_binding_id, "here-binding_id")

        self.assertIsInstance(actual_details, BindDetails)
        self.assertEqual(actual_details.service_id, "service-guid-here")
        self.assertEqual(actual_details.plan_id, "plan-guid-here")

        self.assertIsNone(actual_details.app_guid)
        self.assertIsNone(actual_details.parameters)
        self.assertIsNotNone(actual_details.bind_resource)
Esempio n. 3
0
    def test_routes_bind(self):
        self.b1.bind.return_value = Binding()

        _ = self.router.bind(str(uuid4()), str(uuid4()),
                             BindDetails('s1', 'p1'), True)

        self.assertTrue(self.b1.bind.called)
Esempio n. 4
0
    def test_bind_called_just_with_required_fields(self):
        self.broker.bind.return_value = Binding(
            credentials=expected_credentials)

        _ = self.client.put(
            "/v2/service_instances/here-instance_id/service_bindings/here-binding_id",
            data=json.dumps({
                "service_id": "service-guid-here",
                "plan_id": "plan-guid-here"
            }),
            headers={
                'X-Broker-Api-Version': '2.13',
                'Authorization': self.auth_header
            })

        actual_instance_id, actual_binding_id, actual_details = self.broker.bind.call_args[
            0]
        self.assertEqual(actual_instance_id, "here-instance_id")
        self.assertEqual(actual_binding_id, "here-binding_id")

        self.assertIsInstance(actual_details, BindDetails)
        self.assertEqual(actual_details.service_id, "service-guid-here")
        self.assertEqual(actual_details.plan_id, "plan-guid-here")

        self.assertIsNone(actual_details.app_guid)
        self.assertIsNone(actual_details.parameters)
        self.assertIsNone(actual_details.bind_resource)
Esempio n. 5
0
    def bind_discovery_instance(self, instance_id: str, binding_id: str, service_id: str, plan_id: str,
                                bind_resource: BindResource, parameters: dict=None):
        if instance_id not in self.service_instance_map:
            return Binding(state="failed")

        credentials = dict()
        service_instance = self.service_instance_map[instance_id]
        credentials["endpoints"] = service_instance.params["endpoints"]
        service_binding = OpcuaServiceBinding(binding_id, instance_id, service_id, plan_id, bind_resource, parameters)
        service_binding.params["credentials"] = credentials

        service_binding_map = dict()
        service_binding_map[binding_id] = service_binding
        self.service_binding_map = service_binding_map

        print("Discovery service binding {0} is bound to service instance {1} successfully\n"
              .format(binding_id, instance_id))
        return Binding(credentials=credentials)
Esempio n. 6
0
    def bind(self, instance_id: str, binding_id: str, details: BindDetails,
             async_allowed: bool, **kwargs) -> Binding:
        if not async_allowed:
            raise errors.ErrAsyncRequired()

        instance = self.service_instances.get(instance_id, {})
        if instance and instance.get('state') == self.CREATED:
            instance['state'] = self.BINDING
            return Binding(BindState.IS_ASYNC, operation='bind')
Esempio n. 7
0
    def test_routes_bind_and_enforces_allow_async_false(self):
        self.b1.bind.return_value = Binding()
        instace_guid = str(uuid4())
        binding_id = str(uuid4())
        bind_details = BindDetails('s1', 'p1')

        _ = self.router.bind(instace_guid, binding_id, bind_details, True)

        self.b1.bind.assert_called_once_with(instace_guid, binding_id,
                                             bind_details, False)
Esempio n. 8
0
 def bind(self, instance_id: str, binding_id: str, details: BindDetails,
          async_allowed: bool, **kwargs) -> Binding:
     instance = self.service_instances.get(instance_id, {})
     if instance and instance.get('state') == self.CREATED:
         self.service_instances[instance_id]['state'] = self.BINDING
         clone_url = instance.get('repo_clone_url')
         html_url = instance.get('repo_html_url')
         credentials = {
             'git_repo_url': html_url,
             'git_repo_clone_url': clone_url
         }
         self.service_instances[instance_id]['state'] = self.BOUND
         return Binding(state=BindState.SUCCESSFUL_BOUND,
                        credentials=credentials)
     else:
         raise errors.ErrBindingAlreadyExists()
Esempio n. 9
0
    def test_returns_200_if_identical_binding_already_exists(self):
        self.broker.bind.return_value = Binding(state=BindState.IDENTICAL_ALREADY_EXISTS)

        response = self.client.put(
            "/v2/service_instances/here-instance_id/service_bindings/here-binding_id",
            data=json.dumps({
                "service_id": "service-guid-here",
                "plan_id": "plan-guid-here",
                "bind_resource": {}
            }),
            headers={
                'X-Broker-Api-Version': '2.13',
                'Content-Type': 'application/json',
                'Authorization': self.auth_header
            })

        self.assertEqual(response.status_code, http.HTTPStatus.OK)
        self.assertEqual(response.json, dict())
Esempio n. 10
0
    def test_returns_201_if_binding_has_been_created(self):
        self.broker.bind.return_value = Binding(
            credentials=expected_credentials)

        response = self.client.put(
            "/v2/service_instances/here-instance_id/service_bindings/here-binding_id",
            data=json.dumps({
                "service_id": "service-guid-here",
                "plan_id": "plan-guid-here",
                "bind_resource": {
                    "app_guid": "app-guid-here"
                }
            }),
            headers={
                'X-Broker-Api-Version': '2.13',
                'Authorization': self.auth_header
            })

        self.assertEqual(response.status_code, http.HTTPStatus.CREATED)
        self.assertEqual(response.json, dict(credentials=expected_credentials))
Esempio n. 11
0
    def test_returns_202_for_async_binding(self):
        self.broker.bind.return_value = Binding(state=BindState.IS_ASYNC,
                                                operation='bind')

        response = self.client.put(
            "/v2/service_instances/here-instance_id/service_bindings/here-binding_id&accepts_incomplete=true",
            data=json.dumps({
                "service_id": "service-guid-here",
                "plan_id": "plan-guid-here",
                "bind_resource": {
                    "app_guid": "app-guid-here"
                }
            }),
            headers={
                'X-Broker-Api-Version': '2.13',
                'Content-Type': 'application/json',
                'Authorization': self.auth_header
            })

        self.assertEqual(http.HTTPStatus.ACCEPTED, response.status_code)
        self.assertEqual(response.json, {'operation': 'bind'})
Esempio n. 12
0
    def test_bind_called_with_the_right_values(self):
        self.broker.bind.return_value = Binding(
            credentials=expected_credentials)

        self.client.put(
            "/v2/service_instances/here-instance_id/service_bindings/here-binding_id",
            data=json.dumps({
                "service_id": "service-guid-here",
                "plan_id": "plan-guid-here",
                "bind_resource": {
                    "app_guid": "app-guid-here",
                    "route": "route-here"
                },
                "parameters": {
                    "parameter1": 1
                }
            }),
            headers={
                'X-Broker-Api-Version': '2.13',
                'Content-Type': 'application/json',
                'Authorization': self.auth_header
            })

        actual_instance_id, actual_binding_id, actual_details, async_allowed = self.broker.bind.call_args[
            0]
        self.assertEqual(actual_instance_id, "here-instance_id")
        self.assertEqual(actual_binding_id, "here-binding_id")

        self.assertIsInstance(actual_details, BindDetails)
        self.assertEqual(actual_details.service_id, "service-guid-here")
        self.assertEqual(actual_details.plan_id, "plan-guid-here")
        self.assertEqual(actual_details.parameters, dict(parameter1=1))

        self.assertIsInstance(actual_details.bind_resource, BindResource)
        self.assertEqual(actual_details.bind_resource.app_guid,
                         "app-guid-here")
        self.assertEqual(actual_details.bind_resource.route, "route-here")

        self.assertFalse(async_allowed)
 def bind(self, instance_id: str, binding_id: str, details: BindDetails,
          async_allowed: bool, **kwargs) -> Binding:
     instance = self.service_instances.get(instance_id, {})
     if instance and instance.get('state') == self.CREATED:
         instance['state'] = self.BOUND
         return Binding(BindState.SUCCESSFUL_BOUND)