def set_up(wait_time=10): connection = SQLStore.get_connection() count = 3 while not connection and count: LOG.debug('Retrying to connect to Database \'{}\'...'.format( Helper.database)) count = count - 1 time.sleep(wait_time) connection = SQLStore.get_connection() if connection: # Create DB connection.cursor().execute( 'CREATE DATABASE IF NOT EXISTS {}'.format(Helper.database)) LOG.debug('Successfully connected to Database \'{}\'...'.format( Helper.database)) # Create tables PlanAdapter.create_table() ServiceTypeAdapter.create_table() PlanServiceTypeAdapter.create_table() ManifestAdapter.create_table() ServiceInstanceAdapter.create_table() LastOperationAdapter.create_table() connection.close() else: raise Exception('Could not connect to the DB')
def setUp(self): """PREREQUISITES""" PlanAdapter.create_table() ServiceTypeAdapter.create_table() PlanServiceTypeAdapter.create_table() self.service = ServiceTypeAdapter.sample_model('manifest1') ServiceTypeAdapter.save(self.service) ManifestAdapter.create_table() self.test_model = ManifestAdapter.sample_model('manifest1') _, self.result = SQLStore.add_manifest(self.test_model)
def add_service(service: ServiceType) -> tuple: if ServiceTypeAdapter.exists_in_db(service.id): return 'The service already exists in the catalog.', 409 PlanAdapter.create_table() PlanServiceTypeAdapter.create_table() ServiceTypeAdapter.save(service) if ServiceTypeAdapter.exists_in_db(service.id): return 'Service added successfully', 200 else: return 'Could not save the Service in the DB', 500
def setUp(self): """ PREREQUISITES """ PlanAdapter.create_table() ServiceTypeAdapter.create_table() PlanServiceTypeAdapter.create_table() # ManifestAdapter.create_table() self.service = ServiceTypeAdapter.sample_model('instance1') ServiceTypeAdapter.save(self.service) Adapter.create_table() self.test_model = Adapter.sample_model('instance1') self.id_name = Adapter.get_id(self.test_model) _, self.result = SQLStore.add_service_instance(self.test_model)
def add_manifest(manifest) -> tuple: if ManifestAdapter.exists_in_db(manifest.id): return 'The Manifest already exists in the catalog.', 409 ''' Attempt to Create Table ''' PlanAdapter.create_table() ServiceTypeAdapter.create_table() if ServiceTypeAdapter.exists_in_db( manifest.service_id) and PlanAdapter.exists_in_db( manifest.plan_id): ManifestAdapter.save(manifest) else: return 'Could not save the Manifest in the DB, Plan and Service don\'t exist', 500 if ManifestAdapter.exists_in_db(manifest.id): return 'Manifest added successfully', 200 else: return 'Could not save the Manifest in the DB', 500
def delete_last_operation(self, instance_id: str = None) -> tuple: if ServiceInstanceAdapter.exists_in_db(instance_id): instance = ServiceInstanceAdapter.find_by_id_name(instance_id) ''' Attempt to Create Table ''' PlanAdapter.create_table() ServiceTypeAdapter.create_table() ServiceTypeAdapter.create_table() ServiceInstanceAdapter.create_table() LastOperationAdapter.create_table() instance.state = None ServiceInstanceAdapter.save(instance) id_name = ServiceInstanceAdapter.get_id(instance) if ServiceInstanceAdapter.exists_in_db(id_name): return 'Instance added successfully', 200 else: return 'Could not save the Instance in the DB', 500 else: raise Exception('Service Instance not found')
def add_service_instance(instance: ServiceInstance) -> tuple: id_name = ServiceInstanceAdapter.get_id(instance) if ServiceInstanceAdapter.exists_in_db(id_name): LOG.warning( 'An existing instance was attempted to be saved. Updating it...' ) SQLStore.delete_service_instance(id_name) # return 'The Instance already exists in the catalog.', 409 ''' Attempt to Create Table ''' PlanAdapter.create_table() ServiceTypeAdapter.create_table() ManifestAdapter.create_table() ServiceInstanceAdapter.create_table() LastOperationAdapter.create_table() ServiceInstanceAdapter.save(instance) id_name = ServiceInstanceAdapter.get_id(instance) if ServiceInstanceAdapter.exists_in_db(id_name): LOG.warning('Instance added successfully...') return 'Instance added successfully', 200 else: LOG.warning('Could not save the Instance in the DB...') return 'Could not save the Instance in the DB', 500
def setUp(self): self.test_model = PlanAdapter.sample_model() PlanAdapter.create_table() PlanAdapter.save(self.test_model)
def setUp(self): self.test_model = ServiceTypeAdapter.sample_model('service1') ServiceTypeAdapter.create_table() PlanAdapter.create_table() PlanServiceTypeAdapter.create_table() _, self.result = SQLStore.add_service(self.test_model)