def setUp(self):
        super().setUp()
        self.test_plan = Plan(
            id='testplan', name='testing plan', description='plan for testing',
            metadata=None, free=True, bindable=False
        )
        self.test_service = ServiceType(
            id='test',
            name='test_svc',
            short_name='TS',
            description='this is a test service',
            bindable=False,
            tags=['test', 'tester'],
            metadata=None, requires=[],
            plan_updateable=False, plans=[self.test_plan],
            dashboard_client=None)

        path = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
        with open(path + "/manifests/docker-compose.yml", "r") as mani_file:
            mani = mani_file.read()

        with open(path + '/manifests/test_endpoints.json', 'r') as ep_file:
            ep = ep_file.read()

        self.test_manifest = Manifest(
            id='test', plan_id=self.test_plan.id, service_id=self.test_service.id,
            manifest_type='dummy', manifest_content=mani, endpoints=json.loads(ep)
        )
Exemple #2
0
    def setUp(self):
        super().setUp()

        self.store = STORE
        self.instance_id = 'this_is_a_test_instance'

        self.test_plan = Plan(
            id='testplan', name='testing plan', description='plan for testing',
            metadata=None, free=True, bindable=False
        )

        self.test_service = ServiceType(
            id='test-svc', name='test_svc',
            description='this is a test service',
            bindable=False,
            tags=['test', 'tester'],
            metadata=None, requires=[],
            plan_updateable=False, plans=[self.test_plan],
            dashboard_client=None)

        self.store.add_service(self.test_service)
        print('Service registration content of:\n {content}'.format(content=json.dumps(self.test_service)))

        path = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
        with open(path + "/manifests/docker-compose.yml", "r") as mani_file:
            mani = mani_file.read()

        with open(path + '/manifests/test_endpoints.json', 'r') as ep_file:
            ep = ep_file.read()

        # if os.environ.get('DOCKER_TESTS', 'NO') == 'YES':
        #     self.test_manifest = Manifest(
        #         id='test-mani', plan_id=self.test_plan.id, service_id=self.test_service.id,
        #         manifest_type='docker-compose', manifest_content=mani, endpoints=json.loads(ep)
        #     )
        # else:
        self.test_manifest = Manifest(
            id='test-mani', plan_id=self.test_plan.id, service_id=self.test_service.id,
            manifest_type='dummy', manifest_content=mani, endpoints=json.loads(ep)
        )

        self.store.add_manifest(self.test_manifest)
        print('Manifest registration content of:\n {content}'.format(content=json.dumps(self.test_manifest)))
Exemple #3
0
def register_service(service):
    """
    Registers the service with the catalog.
    \"Service providers need a means to register their service with a service broker. This provides this
    functionality. Also using PUT a service provider can update their registration. Note that this requires the
    complete content and will REPLACE the existing service information registered with the broker.\"
    :param service: the service description to register
    :type service: dict | bytes

    :rtype: Empty
    """
    ok, message, code = _version_ok()
    if not ok:
        return message, code
    else:
        if connexion.request.is_json:
            service = ServiceType.from_dict(connexion.request.get_json())
        else:
            return "Supplied body content is not or is mal-formed JSON", 400
        STORE.add_service(service=service)
        return Empty()
    def setUp(self):
        super().setUp()
        sql_host = os.environ.get('ESM_SQL_HOST',
                                  os.environ.get('ET_EDM_MYSQL_HOST', ''))
        if sql_host:
            STORE.set_up()

        self.store = STORE
        if len(self.store.get_service_instance()) > 0:
            raise Exception(
                'This shouldnt happen - the store should be empty on each run!'
            )

        self.instance_id = 'this_is_a_test_instance'
        self.binding_id = 'this_is_a_test_instance_binding'

        self.test_plan = Plan(id='testplan',
                              name='testing plan',
                              description='plan for testing',
                              metadata=None,
                              free=True,
                              bindable=False)

        self.test_service = ServiceType(id='test-svc',
                                        name='test_svc',
                                        description='this is a test service',
                                        bindable=True,
                                        tags=['test', 'tester'],
                                        metadata=None,
                                        requires=[],
                                        plan_updateable=False,
                                        plans=[self.test_plan],
                                        dashboard_client=None)

        self.store.add_service(self.test_service)
        print('Service registration content of:\n {content}'.format(
            content=json.dumps(self.test_service)))

        path = os.path.dirname(
            os.path.abspath(inspect.getfile(inspect.currentframe())))
        with open(path + MANIFEST, "r") as mani_file:
            mani = mani_file.read()

        with open(path + '/manifests/test_endpoints.json', 'r') as ep_file:
            ep = ep_file.read()

        if os.getenv('DOCKER_TESTS', 'NO') == 'YES':
            m_type = 'docker-compose'
        else:
            m_type = 'dummy'

        self.test_manifest = Manifest(id='test-mani',
                                      plan_id=self.test_plan.id,
                                      service_id=self.test_service.id,
                                      manifest_type=m_type,
                                      manifest_content=mani,
                                      endpoints=json.loads(ep))
        self.store.add_manifest(self.test_manifest)
        print('Manifest registration content of:\n {content}'.format(
            content=json.dumps(self.test_manifest)))

        self.response = self._send_service_request()
        self._assert200(self.response)
Exemple #5
0
 def model_sql_to_model(model_sql: ServiceTypeSQL) -> ServiceType:
     model = ServiceType()
     ''' STRINGS '''
     model.name = model_sql.name
     model.id = model_sql.id_name
     model.short_name = model_sql.short_name
     model.description = model_sql.description
     ''' BOOLEANS '''
     model.bindable = model_sql.bindable
     model.plan_updateable = model_sql.plan_updateable
     ''' LISTS '''
     model.tags = json.loads(model_sql.tags)
     model.requires = json.loads(model_sql.requires)
     ''' OBJECTS '''
     model.metadata = ServiceMetadataAdapter.from_blob(model_sql.metadata)
     model.dashboard_client = DashboardClientAdapter.from_blob(
         model_sql.dashboard_client)
     model.plans = PlanAdapter.plans_from_service_sql(model_sql)
     return model
Exemple #6
0
 def sample_model(name='service1') -> ServiceType:
     model = ServiceType()
     ''' STRINGS '''
     model.id = name
     model.name = name
     model.short_name = name
     model.description = 'description' + name
     ''' BOOLEANS '''
     model.bindable = False
     model.plan_updateable = False
     ''' LISTS '''
     model.tags = ['description1']
     model.requires = ['requirement1']
     ''' OBJECTS '''
     model.metadata = ServiceMetadata(display_name='metadata1')
     model.dashboard_client = DashboardClient(id='client1')
     ''' PLANS '''
     model.plans = [
         PlanAdapter.sample_model(name + 'plan1'),
         PlanAdapter.sample_model(name + 'plan2')
     ]
     return model