def test_instance_deletion(self): _, result = SQLStore.delete_service_instance(self.id_name) self.assertEqual(self.result, 200, msg='Assert Instance Deleted') exists = Adapter.exists_in_db(self.id_name) self.assertFalse(exists, msg='Assert Instance does NOT Exist.') model_sql = Adapter.find_by_id_name(self.id_name) self.assertIsNone(model_sql)
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 get_last_operation(instance_id: str = None) -> List[ServiceInstance]: if instance_id: if ServiceInstanceAdapter.exists_in_db(instance_id): model_sql = ServiceInstanceAdapter.find_by_id_name(instance_id) model = ServiceInstanceAdapter.model_sql_to_model(model_sql) return [model.state] else: return [] else: LOG.warning('No instance ID was provided') return []
def delete_service_instance(instance_id: str = None): # -> None: if instance_id: if ServiceInstanceAdapter.exists_in_db(instance_id): ServiceInstanceAdapter.delete(instance_id) return 'Instance Deleted', 200 else: return 'Instance ID not found', 500 else: LastOperationAdapter.delete_all() ServiceInstanceAdapter.delete_all() return 'Deleted all Instances', 200
def get_service_instance(instance_id: str = None) -> List[ServiceInstance]: if instance_id: if ServiceInstanceAdapter.exists_in_db(instance_id): model_sql = ServiceInstanceAdapter.find_by_id_name(instance_id) model = ServiceInstanceAdapter.model_sql_to_model(model_sql) return [model] else: return [] else: models = ServiceInstanceAdapter.get_all() return models
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 test_adapter_save_to_update(self): self.test_model.state = LastOperationAdapter.sample_model( 'instance-updated!') model_sql = Adapter.save(self.test_model) exists = Adapter.exists_in_db(model_sql.id_name) self.assertTrue(exists)
def test_instance_created(self): self.assertEqual(self.result, 200, msg='Assert Successful Add') exists = Adapter.exists_in_db(self.id_name) self.assertTrue(exists, msg='Assert Instance exists.') model_sql = Adapter.find_by_id_name(self.id_name) self.assertIsInstance(model_sql, ServiceInstanceSQL)