def store_manifest(manifest_id, manifest): """ takes deployment description of a software service and associates with a service and plan takes deployment description of a software service and associates with a service and plan that is already registered in the service catalog. :param manifest_id: The manifest_id of a manifest to be associated with a plan of a servicetype. :type manifest_id: str :param manifest: the manifest to store :type manifest: dict | bytes :rtype: ServiceResponse """ ok, message, code = _version_ok() if not ok: return message, code else: if connexion.request.is_json: manifest = Manifest.from_dict(connexion.request.get_json()) else: return "Supplied body content is not or is mal-formed JSON", 400 if manifest.manifest_content.find( '</br>') > 0: # TODO(dizz) remove this check in R4 return "Manifest content contains '</br>'. Please remove these and replace with '\n'", 400 manifest.id = manifest_id result, code = STORE.add_manifest(manifest) if code == 200: return Empty(), code else: return result, code
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) )
def sample_model(name='manifest1') -> Manifest: model = Manifest() ''' STRINGS ''' model.id = name model.plan_id = name + 'plan1' model.service_id = name model.manifest_type = name + 'type' model.manifest_content = name + 'content' ''' OBJECTS ''' model.endpoints = {'endpoint': 'endpoint'} # using dict model.config = {'config': 'config'} # using dict return model
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)))
def model_sql_to_model(model_sql: ManifestSQL) -> Manifest: model = Manifest() ''' STRINGS ''' model.id = model_sql.id_name # model.id_name = model_sql.id_name model.manifest_type = model_sql.manifest_type model.manifest_content = model_sql.manifest_content ''' FOREIGN KEY ''' model.service_id = model_sql.service_id_name ''' FOREIGN KEY ''' model.plan_id = model_sql.plan_id_name ''' OBJECTS ''' model.endpoints = Helper().from_blob(model_sql.endpoints) model.config = Helper().from_blob(model_sql.config) return model
def model_sql_to_model(model_sql: ManifestSQL) -> Manifest: model = Manifest() ''' STRINGS ''' model.id_name = model_sql.id_name model.manifest_type = model_sql.manifest_type model.manifest_content = model_sql.manifest_content ''' FOREIGN KEY ''' model.service_id = model_sql.service_id_name ''' FOREIGN KEY ''' model.plan_id = model_sql.plan_id_name ''' OBJECTS ''' model.endpoints = model_sql.endpoints return model
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)