예제 #1
0
    def test_catalog_can_return_multiple_services(self):
        self.broker.catalog.return_value = [
            Service(id='s1',
                    name='service_name1',
                    description='service_description1',
                    bindable=True,
                    plans=[
                        ServicePlan(id='p1',
                                    name='default1',
                                    description='plan_description1')
                    ]),
            Service(id='s2',
                    name='service_name2',
                    description='service_description2',
                    bindable=True,
                    plans=[
                        ServicePlan(id='p2',
                                    name='default2',
                                    description='plan_description2')
                    ])
        ]

        response = self.client.get('/v2/catalog',
                                   headers={
                                       'X-Broker-Api-Version': '2.13',
                                       'Authorization': self.auth_header,
                                       'unknown': 'unknown'
                                   })

        self.assertEqual(response.status_code, http.HTTPStatus.OK)
        self.assertDictEqual(
            dict(services=[
                dict(id='s1',
                     name='service_name1',
                     description='service_description1',
                     bindable=True,
                     instances_retrievable=False,
                     bindings_retrievable=False,
                     plan_updateable=False,
                     plans=[
                         dict(id='p1',
                              name='default1',
                              description='plan_description1')
                     ]),
                dict(id='s2',
                     name='service_name2',
                     description='service_description2',
                     bindable=True,
                     instances_retrievable=False,
                     bindings_retrievable=False,
                     plan_updateable=False,
                     plans=[
                         dict(id='p2',
                              name='default2',
                              description='plan_description2')
                     ])
            ]), response.json)
예제 #2
0
    def setUp(self) -> None:
        self.b1 = Mock()
        self.s1 = Service(id='s1', name='s1', description='s1', bindable=True,
                          plans=[ServicePlan('p1', name='', description='')])
        self.b1.catalog.return_value = [self.s1]

        self.b2 = Mock()
        self.s2 = Service(id='s2', name='s2', description='s2', bindable=True,
                          plans=[ServicePlan('p2', name='', description='')])
        self.b2.catalog.return_value = [self.s2]

        self.router = Router(self.b1, self.b2)
    def catalog(self) -> Service:
      # We should add the ability to inject the service plans
      # this is where cluster admins can create the various t-shirt
      # sizes to support for MongoDB
      
      print("loaded service providers\n".join("{}\t{}".format(k, v) for k, v in self.service_providers.items()))
      plans = []
      tags = ['MongoDB', 'Database' ]
      for provider_name in self.service_providers.keys():
        print("loading plans for provider: %s" % provider_name)
        provider = self.service_providers[provider_name]
        provider_plans = provider.plans()
        for plan in provider_plans:
          self.service_plans[plan.id]= { 'provider_name' : provider_name, 'plans' : provider_plans }
        plans.extend( provider_plans )
        tags.extend( provider.tags() )
            
      # Omitting this, needs nested v2.DashboardClient type
      #     dashboard_client='http://mongodb-open-service-broker:8080',

      catalog = Service(
            id='mongodb-open-service-broker',
            name='mongodb-open-service-broker-service',
            description='This service creates and provides your applications access to MongoDB services.',
            bindable=True,
            plans=plans,
            tags=list(set(tags)),
            plan_updateable=False,
      )
      self.__last_op = LastOperation("catalog", catalog )
      self.__catalog = catalog
      return catalog
예제 #4
0
 def catalog(self) -> Service:
     return Service(
         id="8c16de31-104a-47b0-ba79-25e747be91d6",
         name="external-domain",
         description=
         "Assign a custom domain to your application with TLS and an optional CDN.",
         bindable=False,
         metadata=ServiceMetadata(
             displayName=
             "AWS ALB (or CloudFront CDN) with SSL for custom domains",
             imageUrl="TODO",
             longDescription=
             "Create a custom domain to your application with TLS and an optional CDN. This will provision a TLS certificate from Let's Encrypt, a free certificate provider.",
             providerDisplayName="Cloud.gov",
             documentationUrl=
             "https://github.com/cloud-gov/external-domain-broker",
             supportUrl="https://cloud.gov/support",
         ),
         plans=[
             ServicePlan(
                 id="6f60835c-8964-4f1f-a19a-579fb27ce694",
                 name="domain",
                 description="Basic custom domain with TLS.",
             ),
             ServicePlan(
                 id="1cc78b0c-c296-48f5-9182-0b38404f79ef",
                 name="domain-with-cdn",
                 description="Custom domain with TLS and CloudFront.",
             ),
         ],
     )
예제 #5
0
def run_serve_starts_with_single_instance():
    broker = Mock()
    broker.catalog.return_value = Service('id', 'name', 'description', False,
                                          [])
    api.serve(broker, [
        api.BrokerCredentials("cfy-login", "cfy-pwd"),
        api.BrokerCredentials("k8s-login", "k8s-pwd")
    ])
예제 #6
0
 def setUp(self):
     self.broker.catalog.return_value = [
         Service(
             id='service-guid-here',
             name='',
             description='',
             bindable=True,
             plans=[ServicePlan('plan-guid-here', name='', description='')])
     ]
예제 #7
0
 def catalog(self) -> Service:
     return Service(id=self.service_guid,
                    name='TestService',
                    description='TestMe',
                    bindable=False,
                    plans=[
                        ServicePlan(id=self.plan_guid,
                                    name='TestPlan',
                                    description='TestMe')
                    ])
예제 #8
0
 def catalog(self) -> Union[Service, List[Service]]:
     return Service(id='service id 2',
                    name='service name 2',
                    description='service description 2',
                    bindable=False,
                    plans=[
                        ServicePlan(
                            id='plan id',
                            name='plan name',
                            description='plan description',
                        )
                    ])
예제 #9
0
 def catalog(self) -> Service:
     return Service(id=self.service_guid,
                    name='Jenkins enabled Git',
                    description='Create jenkins job for a given git repo',
                    bindable=True,
                    bindings_retrievable=True,
                    instances_retrievable=True,
                    plans=[
                        ServicePlan(id=self.plan_guid,
                                    name='Testing Plan',
                                    description='Used in Testing process',
                                    free=True)
                    ])
예제 #10
0
 def catalog(self):
     return Service(
         id=self._config.broker["id"],
         name=self._config.broker["name"],
         description=self._config.broker["description"],
         bindable=self._config.broker["bindable"],
         plans=self._config.broker["plans"],
         tags=self._config.broker["tags"],
         requires=self._config.broker["requires"],
         metadata=self._config.broker["metadata"],
         dashboard_client=self._config.broker["dashboard_client"],
         plan_updateable=self._config.broker["plan_updateable"],
     )
 def catalog(self) -> Union[Service, List[Service]]:
     return Service(id=self.service_guid,
                    name='InMemService',
                    description='InMemService',
                    bindable=True,
                    plans=[
                        ServicePlan(
                            id=self.plan_guid,
                            name='standard',
                            description='standard plan',
                            free=False,
                        )
                    ],
                    instances_retrievable=False,
                    bindings_retrievable=False)
예제 #12
0
 def catalog(self) -> Service:
     return Service(
         id="8c16de31-104a-47b0-ba79-25e747be91d6",
         name="external-domain",
         description=
         "Assign a custom domain to your application with TLS and an optional CDN.",
         bindable=False,
         metadata=ServiceMetadata(
             displayName=
             "AWS ALB (or CloudFront CDN) with SSL for custom domains",
             imageUrl="TODO",
             longDescription=
             "Create a custom domain to your application with TLS and an optional CDN. This will provision a TLS certificate from Let's Encrypt, a free certificate provider.",
             providerDisplayName="Cloud.gov",
             documentationUrl=
             "https://github.com/cloud-gov/external-domain-broker",
             supportUrl="https://cloud.gov/support",
         ),
         plans=[
             ServicePlan(
                 id=ALB_PLAN_ID,
                 name="domain",
                 description="Basic custom domain with TLS.",
             ),
             ServicePlan(
                 id=CDN_PLAN_ID,
                 name="domain-with-cdn",
                 description="Custom domain with TLS and CloudFront.",
             ),
             ServicePlan(
                 id=MIGRATION_PLAN_ID,
                 name="migration-not-for-direct-use",
                 description="Migration plan for internal autmation.",
                 plan_updateable=True,
             ),
         ],
     )
예제 #13
0
    def catalog(self) -> Service:

        self.logger.debug("loaded service providers\n".join(
            "{}\t{}".format(k, v) for k, v in self.service_providers.items()))
        plans = []
        tags = ['MongoDB', 'Database']
        for provider_name in self.service_providers.keys():
            self.logger.debug("loading plans for provider: %s" % provider_name)
            provider = self.service_providers[provider_name]
            self.logger.debug(f'{provider}')
            provider_plans = provider.plans()
            for plan in provider_plans:
                self.logger.debug(f'plan={plan}')
                self.service_plans[plan.id] = {
                    'provider_name': provider_name,
                    'plans': provider_plans
                }
            plans.extend(provider_plans)
            tags.extend(provider.tags())

        # Omitting this, needs nested v2.DashboardClient type
        #     dashboard_client='http://mongodb-open-service-broker:8080',

        catalog = Service(
            id='mongodb-open-service-broker',
            name='mongodb-open-service-broker-service',
            description=
            'The MongoDB Enterprise Open Service Broker. https://mongodb.com/osb',
            bindable=True,
            plans=plans,
            tags=list(set(tags)),
            plan_updateable=False,
        )
        self.__last_op = LastOperation("catalog", catalog)
        self.__catalog = catalog
        return catalog
예제 #14
0
    def test_catalog_returns_200_with_service_information(self):
        '''
        This tests all the possible information a catalog could have. Including custom Service-/ServicePlanMetadata
        '''
        self.broker.catalog.return_value = Service(
            id='s1',
            name='service_name',
            description='service_description',
            bindable=True,
            plans=[ServicePlan(
                id='p1',
                name='default',
                description='plan_description',
                metadata=ServicePlanMetadata(
                    displayName='displayName',
                    bullets=['bullet1'],
                    costs=[ServicePlanCost(
                        amount={'requests': 1},
                        unit='unit'
                    )],
                    custom_field2='custom_field2'
                ),
                free=True,
                bindable=True
            )],
            tags=['tag1', 'tag2'],
            requires=['something'],
            metadata=ServiceMetadata(
                displayName='displayName',
                imageUrl='imageUrl',
                longDescription='longDescription',
                providerDisplayName='providerDisplayName',
                documentationUrl='documentationUrl',
                supportUrl='supportUrl',
                shareable=True,
                custom_field1='custom_field1'
            ),
            dashboard_client=ServiceDashboardClient(
                id='id',
                secret='secret',
                redirect_uri='redirect_uri'
            ),
            plan_updateable=True
        )

        response = self.client.get(
            '/v2/catalog',
            headers={
                'X-Broker-Api-Version': '2.13',
                'Authorization': self.auth_header,
                'unknown': 'unknown'
            })

        self.assertEqual(response.status_code, http.HTTPStatus.OK)
        self.assertEqual(response.json,
                         dict(
                             services=[
                                 dict(id='s1',
                                      name='service_name',
                                      description='service_description',
                                      bindable=True,
                                      plans=[dict(
                                          id='p1',
                                          name='default',
                                          description='plan_description',
                                          metadata=dict(
                                              displayName='displayName',
                                              bullets=['bullet1'],
                                              costs=[dict(
                                                  amount={'requests': 1},
                                                  unit='unit'
                                              )],
                                              custom_field2='custom_field2'
                                          ),
                                          free=True,
                                          bindable=True
                                      )],
                                      tags=['tag1', 'tag2'],
                                      requires=['something'],
                                      metadata=dict(
                                          displayName='displayName',
                                          imageUrl='imageUrl',
                                          longDescription='longDescription',
                                          providerDisplayName='providerDisplayName',
                                          documentationUrl='documentationUrl',
                                          supportUrl='supportUrl',
                                          shareable=True,
                                          custom_field1='custom_field1'
                                      ),
                                      dashboard_client=dict(
                                          id='id',
                                          secret='secret',
                                          redirect_uri='redirect_uri'
                                      ),
                                      plan_updateable=True
                                      )
                             ]
                         ))
예제 #15
0
 def catalog(self):
     return Service(
         id='f02f46b2-d20d-4b6b-a9fa-6e7d28fddc9c',
         name='tu-files',
         description=
         'Highly available network drive for institutes and organizational units.',
         bindable=True,
         metadata=ServiceMetadata(
             displayName='TUfiles',
             imageUrl='http://example.com/tufiles_logo.png',
             longDescription=
             'With TUfiles, we give you the opportunity to store data on a central and readily available network drive with backup (hosted on Windows servers). TUfiles is suitable for storing data with moderate access requirements, but high availability demands. TUfiles is not suitable for applications demanding high storage performance for a long period of time, such as high-performance databases, computer applications with high data access requirements and for storing local Microsoft Outlook PST files and backups.',
             providerDisplayName='TU.it',
             documentationUrl='https://www.it.tuwien.ac.at/tufiles/',
             supportUrl='https://support.tuwien.ac.at/assystnet/'),
         plans=[
             ServicePlan(
                 id='04cd4e4a-f296-4090-b4f4-0e5717bb90c6',
                 name='standard',
                 description=
                 'Highly available network drive with standard authorization concept.',
                 free=False,
                 metadata=ServicePlanMetaData(
                     displayName='Standard authorization concept',
                     bullets=[
                         'Redundant and readily available network drive',
                         'You can personally administer access rights and authorisations in folders',
                         'Useful for working with older file versions',
                         'With Windows 7/8/8.1/10, Linux and MacOS from SMB version 2.1',
                         'Not intended for storing your backups'
                     ],
                     costs=[
                         ServicePlanCost(amount={'eur': 0.03},
                                         unit='GB per quarter')
                     ]),
                 schemas=Schemas(
                     service_instance={
                         'create': {
                             'parameters': {
                                 '$schema':
                                 'http://json-schema.org/draft-04/schema#',
                                 'type': 'object',
                                 'properties': {
                                     'share-name': {
                                         'description':
                                         'Name of the network drive.',
                                         'type': 'string'
                                     },
                                     'size': {
                                         'description':
                                         'Size of storage in GB.',
                                         'type': 'int'
                                     },
                                     'authorization-group': {
                                         'description':
                                         'Name of the upTUdate authorization group.',
                                         'type': 'string'
                                     }
                                 }
                             }
                         },
                         'update': {
                             'parameters': {
                                 '$schema':
                                 'http://json-schema.org/draft-04/schema#',
                                 'type': 'object',
                                 'properties': {
                                     'size': {
                                         'description':
                                         'Size of storage in GB.',
                                         'type': 'int'
                                     },
                                 }
                             }
                         }
                     },
                     service_binding={
                         'create': {
                             'parameters': {
                                 '$schema':
                                 'http://json-schema.org/draft-04/schema#',
                                 'type': 'object',
                                 'properties': {
                                     'xxxx': {
                                         'description':
                                         'Some parameter needed for binding the service instance.',
                                         'type': 'string'
                                     }
                                 }
                             }
                         }
                     }))
         ],
         tags=['network-drive', 'storage'],
         plan_updateable=True,
     )
예제 #16
0
    def test_catalog_returns_200_with_service_information(self):
        self.broker.catalog.return_value = Service(
            id="s1",
            name="service_name",
            description="service_description",
            bindable=True,
            plans=[
                ServicePlan(id="p1",
                            name="default",
                            description="plan_description",
                            metadata=ServicePlanMetaData(
                                displayName="displayName",
                                bullets=["bullet1"],
                                costs=[
                                    ServicePlanCost(amount={"requests": 1},
                                                    unit="unit")
                                ]),
                            free=True,
                            bindable=True)
            ],
            tags=['tag1', 'tag2'],
            requires=['something'],
            metadata=ServiceMetadata(displayName="displayName",
                                     imageUrl="imageUrl",
                                     longDescription="longDescription",
                                     providerDisplayName="providerDisplayName",
                                     documentationUrl="documentationUrl",
                                     supportUrl="supportUrl"),
            dashboard_client=ServiceDashboardClient(
                id="id", secret="secret", redirect_uri="redirect_uri"),
            plan_updateable=True)

        response = self.client.get("/v2/catalog",
                                   headers={
                                       'X-Broker-Api-Version': '2.13',
                                       'Authorization': self.auth_header,
                                       "unknown": "unknown"
                                   })

        self.assertEqual(response.status_code, http.HTTPStatus.OK)
        self.assertEqual(
            response.json,
            dict(services=[
                dict(id="s1",
                     name="service_name",
                     description="service_description",
                     bindable=True,
                     plans=[
                         dict(id="p1",
                              name="default",
                              description="plan_description",
                              metadata=dict(displayName="displayName",
                                            bullets=["bullet1"],
                                            costs=[
                                                dict(amount={"requests": 1},
                                                     unit="unit")
                                            ]),
                              free=True,
                              bindable=True)
                     ],
                     tags=['tag1', 'tag2'],
                     requires=['something'],
                     metadata=dict(displayName="displayName",
                                   imageUrl="imageUrl",
                                   longDescription="longDescription",
                                   providerDisplayName="providerDisplayName",
                                   documentationUrl="documentationUrl",
                                   supportUrl="supportUrl"),
                     dashboard_client=dict(id="id",
                                           secret="secret",
                                           redirect_uri="redirect_uri"),
                     plan_updateable=True)
            ]))
예제 #17
0
class CatalogTest(BrokerTestCase):
    service = Service(id="s1",
                      name="service_name",
                      description="service_description",
                      bindable=True,
                      plans=[
                          ServicePlan(id="p1",
                                      name="default",
                                      description="plan_description")
                      ])

    def test_catalog_called_with_the_right_values(self):
        self.broker.catalog.return_value = self.service

        self.client.get("/v2/catalog",
                        headers={
                            'X-Broker-Api-Version': '2.13',
                            'Authorization': self.auth_header
                        })

        self.assertTrue(self.broker.catalog.called)

    def test_catalog_ignores_request_headers(self):
        self.broker.catalog.return_value = self.service

        self.client.get("/v2/catalog",
                        headers={
                            'X-Broker-Api-Version': '2.13',
                            'Authorization': self.auth_header,
                            "unknown": "unknown"
                        })

        self.assertTrue(self.broker.catalog.called)

    def test_catalog_returns_200_with_service_information(self):
        self.broker.catalog.return_value = Service(
            id="s1",
            name="service_name",
            description="service_description",
            bindable=True,
            plans=[
                ServicePlan(id="p1",
                            name="default",
                            description="plan_description",
                            metadata=ServicePlanMetaData(
                                displayName="displayName",
                                bullets=["bullet1"],
                                costs=[
                                    ServicePlanCost(amount={"requests": 1},
                                                    unit="unit")
                                ]),
                            free=True,
                            bindable=True)
            ],
            tags=['tag1', 'tag2'],
            requires=['something'],
            metadata=ServiceMetadata(displayName="displayName",
                                     imageUrl="imageUrl",
                                     longDescription="longDescription",
                                     providerDisplayName="providerDisplayName",
                                     documentationUrl="documentationUrl",
                                     supportUrl="supportUrl"),
            dashboard_client=ServiceDashboardClient(
                id="id", secret="secret", redirect_uri="redirect_uri"),
            plan_updateable=True)

        response = self.client.get("/v2/catalog",
                                   headers={
                                       'X-Broker-Api-Version': '2.13',
                                       'Authorization': self.auth_header,
                                       "unknown": "unknown"
                                   })

        self.assertEqual(response.status_code, http.HTTPStatus.OK)
        self.assertEqual(
            response.json,
            dict(services=[
                dict(id="s1",
                     name="service_name",
                     description="service_description",
                     bindable=True,
                     plans=[
                         dict(id="p1",
                              name="default",
                              description="plan_description",
                              metadata=dict(displayName="displayName",
                                            bullets=["bullet1"],
                                            costs=[
                                                dict(amount={"requests": 1},
                                                     unit="unit")
                                            ]),
                              free=True,
                              bindable=True)
                     ],
                     tags=['tag1', 'tag2'],
                     requires=['something'],
                     metadata=dict(displayName="displayName",
                                   imageUrl="imageUrl",
                                   longDescription="longDescription",
                                   providerDisplayName="providerDisplayName",
                                   documentationUrl="documentationUrl",
                                   supportUrl="supportUrl"),
                     dashboard_client=dict(id="id",
                                           secret="secret",
                                           redirect_uri="redirect_uri"),
                     plan_updateable=True)
            ]))

    def test_catalog_returns_200_with_minimal_service_information(self):
        self.broker.catalog.return_value = self.service

        response = self.client.get(
            "/v2/catalog",
            headers={
                'X-Broker-Api-Version':
                '2.13',
                'X-Broker-Api-Originating-Identity':
                'test ' +
                base64.standard_b64encode(b'{"user_id":123}').decode('ascii'),
                'Authorization':
                self.auth_header,
                "unknown":
                "unknown"
            })

        self.assertEqual(response.status_code, http.HTTPStatus.OK)
        self.assertEqual(
            response.json,
            dict(services=[
                dict(id="s1",
                     name="service_name",
                     description="service_description",
                     bindable=True,
                     plan_updateable=False,
                     plans=[
                         dict(id="p1",
                              name="default",
                              description="plan_description")
                     ])
            ]))

    def test_catalog_returns_500_if_error_raised(self):
        self.broker.catalog.side_effect = Exception("ERROR")

        response = self.client.get("/v2/catalog",
                                   headers={
                                       'X-Broker-Api-Version': '2.13',
                                       'Authorization': self.auth_header,
                                       "unknown": "unknown"
                                   })

        self.assertEqual(response.status_code,
                         http.HTTPStatus.INTERNAL_SERVER_ERROR)
        self.assertEqual(response.json, dict(description="ERROR"))
예제 #18
0
 def catalog(self):
     return Service(
         id='c4573c4b-0fec-4c2d-b650-a3daa91a3bf0',
         name='tu-cloud',
         description=
         'File Sync and Share service located on servers of the TU Wien.',
         bindable=True,
         metadata=ServiceMetadata(
             displayName='TUcloud',
             imageUrl='http://example.com/tucloud_logo.png',
             longDescription=
             'With our File Sync and Share service, you can save your data to a \"virtual memory stick\". The open source software ownCloud runs on TU.it servers and basically offers the familiar features also provided by public cloud systems such as Dropbox.',
             providerDisplayName='TU.it',
             documentationUrl='https://www.it.tuwien.ac.at/tuprocloud/',
             supportUrl='https://support.tuwien.ac.at/assystnet/'),
         plans=[
             ServicePlan(
                 id='b1e8a5fd-0abc-4259-8d66-ab6fe8ee8b1d',
                 name='tu-owncloud',
                 description=
                 'Free file sync and share service for internal use.',
                 free=True,
                 metadata=ServicePlanMetaData(
                     displayName='TUownCloud',
                     bullets=[
                         '20 GB of personal storage space',
                         'Running on TU.it servers - your data is present locally on our systems',
                         'Data access possible via clients, web and WebDAV',
                         'Synchronisation with any number of devices is either automatic or in accordance with settings you make yourself'
                     ])),
             ServicePlan(
                 id='433b4d74-6ed9-41f5-81e6-4bef7fd66c1f',
                 name='tu-procloud',
                 description=
                 'File sync and share service for collaboration with external project partners.',
                 free=False,
                 metadata=ServicePlanMetaData(
                     displayName='TUproCloud',
                     bullets=[
                         'Collaborate with external project partners',
                         'File-synchronization and sharing',
                         'Configure access / authorization of members',
                         'Several 100GB of storage possible'
                     ],
                     costs=[
                         ServicePlanCost(amount={'eur': 0.03},
                                         unit='GB per quarter')
                     ]),
                 schemas=Schemas(
                     service_instance={
                         'create': {
                             'parameters': {
                                 '$schema':
                                 'http://json-schema.org/draft-04/schema#',
                                 'type': 'object',
                                 'properties': {
                                     'name': {
                                         'description':
                                         'Unique TU-wide name, not changeable.',
                                         'type': 'string'
                                     },
                                     'size': {
                                         'description':
                                         'Size of storage in GB.',
                                         'type': 'int'
                                     },
                                 }
                             }
                         },
                         'update': {
                             'parameters': {
                                 '$schema':
                                 'http://json-schema.org/draft-04/schema#',
                                 'type': 'object',
                                 'properties': {
                                     'size': {
                                         'description':
                                         'Size of storage in GB.',
                                         'type': 'int'
                                     },
                                 }
                             }
                         }
                     },
                     service_binding={
                         'create': {
                             'parameters': {
                                 '$schema':
                                 'http://json-schema.org/draft-04/schema#',
                                 'type': 'object',
                                 'properties': {
                                     'xxxx': {
                                         'description':
                                         'Some parameter needed for binding the service instance.',
                                         'type': 'string'
                                     }
                                 }
                             }
                         }
                     }))
         ],
         tags=['cloud-storage', 'file-sync', 'share'],
         plan_updateable=True,
     )
예제 #19
0
class CatalogTest(BrokerTestCase):
    service = Service(
        id='s1',
        name='service_name',
        description='service_description',
        bindable=True,
        plans=[ServicePlan(id='p1', name='default', description='plan_description')]
    )

    def test_catalog_called_with_the_right_values(self):
        self.broker.catalog.return_value = self.service

        self.client.get(
            '/v2/catalog',
            headers={
                'X-Broker-Api-Version': '2.13',
                'Authorization': self.auth_header
            })

        self.assertTrue(self.broker.catalog.called)

    def test_catalog_ignores_request_headers(self):
        self.broker.catalog.return_value = self.service

        self.client.get(
            '/v2/catalog',
            headers={
                'X-Broker-Api-Version': '2.13',
                'Authorization': self.auth_header,
                'unknown': 'unknown'
            })

        self.assertTrue(self.broker.catalog.called)

    def test_catalog_returns_200_with_service_information(self):
        '''
        This tests all the possible information a catalog could have. Including custom Service-/ServicePlanMetadata
        '''
        self.broker.catalog.return_value = Service(
            id='s1',
            name='service_name',
            description='service_description',
            bindable=True,
            plans=[ServicePlan(
                id='p1',
                name='default',
                description='plan_description',
                metadata=ServicePlanMetadata(
                    displayName='displayName',
                    bullets=['bullet1'],
                    costs=[ServicePlanCost(
                        amount={'requests': 1},
                        unit='unit'
                    )],
                    custom_field2='custom_field2'
                ),
                free=True,
                bindable=True
            )],
            tags=['tag1', 'tag2'],
            requires=['something'],
            metadata=ServiceMetadata(
                displayName='displayName',
                imageUrl='imageUrl',
                longDescription='longDescription',
                providerDisplayName='providerDisplayName',
                documentationUrl='documentationUrl',
                supportUrl='supportUrl',
                shareable=True,
                custom_field1='custom_field1'
            ),
            dashboard_client=ServiceDashboardClient(
                id='id',
                secret='secret',
                redirect_uri='redirect_uri'
            ),
            plan_updateable=True
        )

        response = self.client.get(
            '/v2/catalog',
            headers={
                'X-Broker-Api-Version': '2.13',
                'Authorization': self.auth_header,
                'unknown': 'unknown'
            })

        self.assertEqual(response.status_code, http.HTTPStatus.OK)
        self.assertEqual(response.json,
                         dict(
                             services=[
                                 dict(id='s1',
                                      name='service_name',
                                      description='service_description',
                                      bindable=True,
                                      plans=[dict(
                                          id='p1',
                                          name='default',
                                          description='plan_description',
                                          metadata=dict(
                                              displayName='displayName',
                                              bullets=['bullet1'],
                                              costs=[dict(
                                                  amount={'requests': 1},
                                                  unit='unit'
                                              )],
                                              custom_field2='custom_field2'
                                          ),
                                          free=True,
                                          bindable=True
                                      )],
                                      tags=['tag1', 'tag2'],
                                      requires=['something'],
                                      metadata=dict(
                                          displayName='displayName',
                                          imageUrl='imageUrl',
                                          longDescription='longDescription',
                                          providerDisplayName='providerDisplayName',
                                          documentationUrl='documentationUrl',
                                          supportUrl='supportUrl',
                                          shareable=True,
                                          custom_field1='custom_field1'
                                      ),
                                      dashboard_client=dict(
                                          id='id',
                                          secret='secret',
                                          redirect_uri='redirect_uri'
                                      ),
                                      plan_updateable=True
                                      )
                             ]
                         ))

    def test_catalog_returns_200_with_minimal_service_information(self):
        self.broker.catalog.return_value = self.service

        response = self.client.get(
            '/v2/catalog',
            headers={
                'X-Broker-Api-Version': '2.13',
                'X-Broker-Api-Originating-Identity': 'test ' + base64.standard_b64encode(b'{"user_id":123}').decode(
                    'ascii'),
                'Authorization': self.auth_header,
                'unknown': 'unknown'
            })

        self.assertEqual(response.status_code, http.HTTPStatus.OK)
        self.assertEqual(response.json,
                         dict(
                             services=[
                                 dict(
                                     id='s1',
                                     name='service_name',
                                     description='service_description',
                                     bindable=True,
                                     plan_updateable=False,
                                     plans=[dict(id='p1', name='default', description='plan_description')]
                                 )
                             ]
                         ))

    def test_catalog_returns_500_if_error_raised(self):
        self.broker.catalog.side_effect = Exception('ERROR')

        response = self.client.get(
            '/v2/catalog',
            headers={
                'X-Broker-Api-Version': '2.13',
                'Authorization': self.auth_header,
                'unknown': 'unknown'
            })

        self.assertEqual(response.status_code, http.HTTPStatus.INTERNAL_SERVER_ERROR)
        self.assertEqual(response.json,
                         dict(
                             description='ERROR'
                         ))
예제 #20
0
 def catalog(self):
     return Service(
         id='e636ea62-a613-41a5-88b5-34f7be4b8d34',
         name='tu-host',
         description=
         'Run virtual machine on central, highly available virtualization platform',
         bindable=False,
         metadata=ServiceMetadata(
             displayName='TUhost',
             imageUrl='http://example.com/tuhost_logo.png',
             longDescription=
             'You have the opportunity to operate virtual machines on the central and highly available TU.it virtualisation platform, hosted on VMware ESXi. TUhost is suitable for operating servers with moderate resource requirements, but high availability demands. The virtualisation platform is not suitable for operating servers that are to support applications demanding a particularly high computing capacity and/or storage performance, such as simulation calculations, high-performance databases or storage for vast quantities of data.',
             providerDisplayName='TU.it',
             documentationUrl='https://www.it.tuwien.ac.at/tuhost/',
             supportUrl='https://support.tuwien.ac.at/assystnet/'),
         plans=[
             ServicePlan(
                 id='057997b7-22ac-4d6b-90a9-b2c8d5e289e6',
                 name='standard',
                 description=
                 'Configurable, highly available Virtual Machine.',
                 free=False,
                 bindable=False,
                 metadata=ServicePlanMetaData(
                     displayName='TUhost Standard',
                     bullets=[
                         'Provision of virtual servers including storage for TU organisational units',
                         'Backup for VMs', 'VM administration portal',
                         'Restore option in self-service via a portal'
                     ],
                     costs=[
                         ServicePlanCost(amount={'eur': 8},
                                         unit='vCPU per quarter'),
                         ServicePlanCost(amount={'eur': 8},
                                         unit='GB RAM per quarter'),
                         ServicePlanCost(amount={'eur': 0.1},
                                         unit='GB system disk per quarter'),
                         ServicePlanCost(amount={'eur': 0.1},
                                         unit='GB data disk per quarter'),
                         ServicePlanCost(
                             amount={'eur': 0.25},
                             unit='GB high-performance disk per quarter'),
                     ]),
                 schemas=Schemas(service_instance={
                     'create': {
                         'parameters': {
                             '$schema':
                             'http://json-schema.org/draft-04/schema#',
                             'type': 'object',
                             'properties': {
                                 'vmName': {
                                     'description':
                                     'Virtual machine name (host.subdomain).',
                                     'type': 'string'
                                 },
                                 'vCPUs': {
                                     'description':
                                     'Number of virtual CPUs.',
                                     'type': 'int'
                                 },
                                 'ram': {
                                     'description': 'Amount of RAM in GB.',
                                     'type': 'int'
                                 },
                                 'diskSys': {
                                     'description':
                                     'Amount of system disk storage in GB.',
                                     'type': 'int'
                                 },
                                 'diskData': {
                                     'description':
                                     'Amount of data disk storage in GB.',
                                     'type': 'int'
                                 },
                                 'diskHighPerf': {
                                     'description':
                                     'Amount of high performance disk storage in GB.',
                                     'type': 'int'
                                 },
                                 'os': {
                                     'description':
                                     'Virtual machine operating system.',
                                     'type':
                                     'string',
                                     'enum':
                                     ['CentOS', 'Debian', 'Windows Server']
                                 },
                                 'usage': {
                                     'description':
                                     'Intended usage of the virtual machine.',
                                     'type': 'string'
                                 },
                             }
                         }
                     },
                     'update': {
                         'parameters': {
                             '$schema':
                             'http://json-schema.org/draft-04/schema#',
                             'type': 'object',
                             'properties': {
                                 'vCPUs': {
                                     'description':
                                     'Number of virtual CPUs.',
                                     'type': 'int'
                                 },
                                 'ram': {
                                     'description': 'Amount of RAM in GB.',
                                     'type': 'int'
                                 },
                                 'diskSys': {
                                     'description':
                                     'Amount of system disk storage in GB.',
                                     'type': 'int'
                                 },
                                 'diskData': {
                                     'description':
                                     'Amount of data disk storage in GB.',
                                     'type': 'int'
                                 },
                                 'diskHighPerf': {
                                     'description':
                                     'Amount of high performance disk storage in GB.',
                                     'type': 'int'
                                 },
                             }
                         }
                     }
                 },
                                 service_binding={
                                     'create': {
                                         'parameters': {
                                             '$schema':
                                             'http://json-schema.org/draft-04/schema#',
                                             'type': 'object',
                                             'properties': {
                                                 'xxxx': {
                                                     'description':
                                                     'Some parameter needed for binding the service instance.',
                                                     'type': 'string'
                                                 }
                                             }
                                         }
                                     }
                                 })),
         ],
         tags=['vm', 'virtual-server'],
         plan_updateable=True,
     )