def destroy_infra(databaseinfra, task=None): try: database = databaseinfra.databases.get() LOG.debug('Database found! {}'.format(database)) except IndexError: LOG.info("Database not found...") if not databaseinfra.plan.provider == databaseinfra.plan.CLOUDSTACK: LOG.error('Databaseinfra is not cloudstack infra') return True instances = [] hosts = [] for instance in databaseinfra.instances.all(): instances.append(instance) hosts.append(instance.hostname) workflow_dict = build_dict( plan=databaseinfra.plan, environment=databaseinfra.environment, steps=get_destroy_settings( databaseinfra.plan.replication_topology.class_path), qt=get_vm_qt(plan=databaseinfra.plan), dbtype=str(databaseinfra.plan.engine_type), hosts=hosts, instances=instances, databaseinfra=databaseinfra, database=database) if stop_workflow(workflow_dict=workflow_dict, task=task): return workflow_dict else: return False
def destroy_infra(databaseinfra, task=None): try: database = databaseinfra.databases.get() LOG.debug('Database found! {}'.format(database)) except IndexError: LOG.info("Database not found...") if not databaseinfra.plan.provider == databaseinfra.plan.CLOUDSTACK: LOG.error('Databaseinfra is not cloudstack infra') return True instances = [] hosts = [] for instance in databaseinfra.instances.all(): instances.append(instance) hosts.append(instance.hostname) workflow_dict = build_dict(plan=databaseinfra.plan, environment=databaseinfra.environment, steps=get_deploy_settings( databaseinfra.plan.engine_type.name), qt=get_vm_qt(plan=databaseinfra.plan), dbtype=str(databaseinfra.plan.engine_type), hosts=hosts, instances=instances, databaseinfra=databaseinfra, database=database ) if stop_workflow(workflow_dict=workflow_dict, task=task): return workflow_dict else: return False
def destroy_infra(databaseinfra, task=None): if not databaseinfra.plan.provider == databaseinfra.plan.CLOUDSTACK: return True instances = [] hosts = [] for instance in databaseinfra.instances.all(): instances.append(instance) hosts.append(instance.hostname) workflow_dict = build_dict(plan= databaseinfra.plan, environment= databaseinfra.environment, steps= get_engine_steps(engine= str(databaseinfra.plan.engine_type)), qt= get_vm_qt(plan= databaseinfra.plan), hosts= hosts, instances= instances, databaseinfra= databaseinfra, MYSQL = MYSQL, MONGODB = MONGODB, REDIS = REDIS, enginecod = get_engine(engine= str(databaseinfra.plan.engine_type)) ) if stop_workflow(workflow_dict= workflow_dict, task=task): return workflow_dict else: return False
def destroy_infra(databaseinfra, task=None): if not databaseinfra.plan.provider == databaseinfra.plan.CLOUDSTACK: return True instances = [] hosts = [] for instance in databaseinfra.instances.all(): instances.append(instance) hosts.append(instance.hostname) workflow_dict = build_dict(plan= databaseinfra.plan, environment= databaseinfra.environment, steps= get_engine_steps(engine= str(databaseinfra.plan.engine_type)), qt= get_vm_qt(plan= databaseinfra.plan), hosts= hosts, instances= instances, databaseinfra= databaseinfra, MYSQL = MYSQL, MONGODB = MONGODB, enginecod = get_engine(engine= str(databaseinfra.plan.engine_type)) ) if stop_workflow(workflow_dict= workflow_dict, task=task): return workflow_dict else: return False
def workflow_error_throws_exception(self): self.workflow_dict['steps'] = ('workflow.steps.tests.factory.TestStep4', 'workflow.steps.tests.factory.TestStep3') self.start_worflow = stop_workflow(self.workflow_dict) self.assertEqual(self.workflow_dict['total_steps'], 2) self.assertEqual(self.workflow_dict['exceptions']['error_codes'], [('DBAAS_0001', 'Workflow error')]) self.assertEqual(self.workflow_dict['steps'], ('workflow.steps.tests.factory.TestStep4', 'workflow.steps.tests.factory.TestStep3'))
def workflow_error_throws_exception(self): self.workflow_dict['steps'] = ( 'workflow.steps.tests.factory.TestStep4', 'workflow.steps.tests.factory.TestStep3') self.start_worflow = stop_workflow(self.workflow_dict) self.assertEqual(self.workflow_dict['total_steps'], 2) self.assertEqual(self.workflow_dict['exceptions']['error_codes'], [('DBAAS_0001', 'Workflow error')]) self.assertEqual(self.workflow_dict['steps'], ('workflow.steps.tests.factory.TestStep4', 'workflow.steps.tests.factory.TestStep3'))
def undo_resize_database_instance(database, cloudstackpack, instance, task=None): from dbaas_cloudstack.models import CloudStackPack original_cloudstackpack = CloudStackPack.objects.get( offering__serviceofferingid=database.offering_id, offering__region__environment=database.environment, engine_type__name=database.engine_type, ) workflow_dict = build_dict( database=database, cloudstackpack=cloudstackpack, original_cloudstackpack=original_cloudstackpack, environment=database.environment, instance=instance, steps=get_resize_settings(database.engine_type), ) stop_workflow(workflow_dict=workflow_dict, task=task) return workflow_dict
def execute_database_region_migration_undo(self, database_region_migration_detail_id, task_history=None, user=None): AuditRequest.new_request("execute_database_region_migration", user, "localhost") try: if task_history: arguments = task_history.arguments else: arguments = None task_history = TaskHistory.register(request=self.request, task_history=task_history, user=user, worker_name=get_worker_name()) if arguments: task_history.arguments = arguments task_history.save() database_region_migration_detail = DatabaseRegionMigrationDetail.objects.get( id=database_region_migration_detail_id) database_region_migration_detail.started_at = datetime.now() database_region_migration_detail.status = database_region_migration_detail.RUNNING database_region_migration_detail.is_migration_up = False database_region_migration_detail.save() database_region_migration = database_region_migration_detail.database_region_migration database = database_region_migration.database databaseinfra = database.databaseinfra source_environment = databaseinfra.environment target_environment = source_environment.equivalent_environment engine = database.engine_type steps = get_engine_steps(engine) workflow_steps = steps[ database_region_migration_detail.step].step_classes source_instances = [] source_hosts = [] for instance in databaseinfra.instances.filter( future_instance__isnull=False): source_instances.append(instance) if instance.instance_type != instance.REDIS: source_hosts.append(instance.hostname) target_instances = [] target_hosts = [] for instance in databaseinfra.instances.filter( future_instance__isnull=True): target_instances.append(instance) if instance.instance_type != instance.REDIS: target_hosts.append(instance.hostname) source_plan = databaseinfra.plan target_plan = source_plan.equivalent_plan_id if not source_hosts: raise Exception('There is no source host') if not source_instances: raise Exception('There is no source instance') if not target_hosts: raise Exception('There is no target host') if not target_instances: raise Exception('There is no target instance') source_secondary_ips = DatabaseInfraAttr.objects.filter( databaseinfra=databaseinfra, equivalent_dbinfraattr__isnull=False) source_secondary_ips = list(source_secondary_ips) workflow_dict = build_dict( database_region_migration_detail=database_region_migration_detail, database_region_migration=database_region_migration, database=database, databaseinfra=databaseinfra, source_environment=source_environment, target_environment=target_environment, steps=workflow_steps, engine=engine, source_instances=source_instances, source_plan=source_plan, target_plan=target_plan, source_hosts=source_hosts, target_instances=target_instances, target_hosts=target_hosts, source_secondary_ips=source_secondary_ips, ) stop_workflow(workflow_dict=workflow_dict, task=task_history) current_step = database_region_migration.current_step database_region_migration.current_step = current_step - 1 database_region_migration.save() database_region_migration_detail.status = database_region_migration_detail.SUCCESS database_region_migration_detail.finished_at = datetime.now() database_region_migration_detail.save() task_history.update_status_for( TaskHistory.STATUS_SUCCESS, details='Database region migration was succesfully') except Exception, e: traceback = full_stack() LOG.error("Ops... something went wrong: %s" % e) LOG.error(traceback) task_history.update_status_for(TaskHistory.STATUS_ERROR, details=traceback) database_region_migration_detail.status = database_region_migration_detail.ERROR database_region_migration_detail.finished_at = datetime.now() database_region_migration_detail.save() return
def execute_database_region_migration_undo(self, database_region_migration_detail_id, task_history=None, user=None): #AuditRequest.new_request("execute_database_region_migration", user, "localhost") try: if task_history: arguments = task_history.arguments else: arguments = None task_history = TaskHistory.register(request=self.request, task_history=task_history, user=user, worker_name=get_worker_name()) if arguments: task_history.arguments = arguments task_history.save() database_region_migration_detail = DatabaseRegionMigrationDetail.objects.get( id=database_region_migration_detail_id) database_region_migration = database_region_migration_detail.database_region_migration database = database_region_migration.database databaseinfra = database.databaseinfra source_environment = databaseinfra.environment target_environment = source_environment.equivalent_environment engine = database.engine_type steps = get_engine_steps(engine) workflow_steps = steps[ database_region_migration_detail.step].step_classes source_instances = [] source_hosts = [] for instance in databaseinfra.instances.filter( future_instance__isnull=False): source_instances.append(instance) source_hosts.append(instance.hostname) target_instances = [] target_hosts = [] for instance in databaseinfra.instances.filter( future_instance__isnull=True): target_instances.append(instance) target_hosts.append(instance.hostname) source_plan = databaseinfra.plan target_plan = source_plan.equivalent_plan_id workflow_dict = build_dict( database_region_migration_detail=database_region_migration_detail, database_region_migration=database_region_migration, database=database, databaseinfra=databaseinfra, source_environment=source_environment, target_environment=target_environment, steps=workflow_steps, engine=engine, source_instances=source_instances, source_plan=source_plan, target_plan=target_plan, source_hosts=source_hosts, target_instances=target_instances, target_hosts=target_hosts) stop_workflow(workflow_dict=workflow_dict, task=task_history) task_history.update_status_for( TaskHistory.STATUS_SUCCESS, details='Database region migration was succesfully') except Exception, e: traceback = full_stack() LOG.error("Ops... something went wrong: %s" % e) LOG.error(traceback) task_history.update_status_for(TaskHistory.STATUS_ERROR, details=traceback) return
def test_stop_workflow_without_steps(self): self.assertFalse(stop_workflow({}))
def setUp(self): self.workflow_dict = {} self.workflow_dict['steps'] = ( 'workflow.steps.tests.factory.TestStep1', 'workflow.steps.tests.factory.TestStep2') self.stop_workflow = stop_workflow(self.workflow_dict)
def setUp(self): self.workflow_dict = {} self.workflow_dict['steps'] = ('workflow.steps.tests.factory.TestStep1', 'workflow.steps.tests.factory.TestStep2') self.stop_workflow = stop_workflow(self.workflow_dict)
def execute_database_region_migration_undo(self, database_region_migration_detail_id, task_history=None, user=None): #AuditRequest.new_request("execute_database_region_migration", user, "localhost") try: if task_history: arguments = task_history.arguments else: arguments = None task_history = TaskHistory.register(request=self.request, task_history = task_history, user = user, worker_name = get_worker_name()) if arguments: task_history.arguments = arguments task_history.save() database_region_migration_detail = DatabaseRegionMigrationDetail.objects.get(id=database_region_migration_detail_id) database_region_migration = database_region_migration_detail.database_region_migration database = database_region_migration.database databaseinfra = database.databaseinfra source_environment = databaseinfra.environment target_environment = source_environment.equivalent_environment engine = database.engine_type steps = get_engine_steps(engine) workflow_steps = steps[database_region_migration_detail.step].step_classes source_instances = [] source_hosts = [] for instance in databaseinfra.instances.filter(future_instance__isnull = False): source_instances.append(instance) source_hosts.append(instance.hostname) target_instances = [] target_hosts = [] for instance in databaseinfra.instances.filter(future_instance__isnull = True): target_instances.append(instance) target_hosts.append(instance.hostname) source_plan = databaseinfra.plan target_plan = source_plan.equivalent_plan_id workflow_dict = build_dict(database_region_migration_detail = database_region_migration_detail, database_region_migration = database_region_migration, database = database, databaseinfra = databaseinfra, source_environment = source_environment, target_environment = target_environment, steps = workflow_steps, engine = engine, source_instances = source_instances, source_plan = source_plan, target_plan = target_plan, source_hosts = source_hosts, target_instances = target_instances, target_hosts = target_hosts ) stop_workflow(workflow_dict = workflow_dict, task = task_history) task_history.update_status_for(TaskHistory.STATUS_SUCCESS, details='Database region migration was succesfully') except Exception, e: traceback = full_stack() LOG.error("Ops... something went wrong: %s" % e) LOG.error(traceback) task_history.update_status_for(TaskHistory.STATUS_ERROR, details=traceback) return
def execute_database_region_migration_undo(self, database_region_migration_detail_id, task_history=None, user=None): AuditRequest.new_request( "execute_database_region_migration", user, "localhost") try: if task_history: arguments = task_history.arguments else: arguments = None task_history = TaskHistory.register(request=self.request, task_history=task_history, user=user, worker_name=get_worker_name()) if arguments: task_history.arguments = arguments task_history.save() database_region_migration_detail = DatabaseRegionMigrationDetail.objects.get( id=database_region_migration_detail_id) database_region_migration_detail.started_at = datetime.now() database_region_migration_detail.status = database_region_migration_detail.RUNNING database_region_migration_detail.is_migration_up = False database_region_migration_detail.save() database_region_migration = database_region_migration_detail.database_region_migration database = database_region_migration.database databaseinfra = database.databaseinfra source_environment = databaseinfra.environment target_environment = source_environment.equivalent_environment engine = database.engine_type steps = get_engine_steps(engine) workflow_steps = steps[ database_region_migration_detail.step].step_classes source_instances = [] source_hosts = [] for instance in databaseinfra.instances.filter(future_instance__isnull=False): source_instances.append(instance) if instance.instance_type != instance.REDIS: source_hosts.append(instance.hostname) target_instances = [] target_hosts = [] for instance in databaseinfra.instances.filter(future_instance__isnull=True): target_instances.append(instance) if instance.instance_type != instance.REDIS: target_hosts.append(instance.hostname) source_plan = databaseinfra.plan target_plan = source_plan.equivalent_plan_id if not source_hosts: raise Exception('There is no source host') if not source_instances: raise Exception('There is no source instance') if not target_hosts: raise Exception('There is no target host') if not target_instances: raise Exception('There is no target instance') source_secondary_ips = DatabaseInfraAttr.objects.filter(databaseinfra=databaseinfra, equivalent_dbinfraattr__isnull=False) source_secondary_ips = list(source_secondary_ips) workflow_dict = build_dict(database_region_migration_detail=database_region_migration_detail, database_region_migration=database_region_migration, database=database, databaseinfra=databaseinfra, source_environment=source_environment, target_environment=target_environment, steps=workflow_steps, engine=engine, source_instances=source_instances, source_plan=source_plan, target_plan=target_plan, source_hosts=source_hosts, target_instances=target_instances, target_hosts=target_hosts, source_secondary_ips=source_secondary_ips, ) stop_workflow(workflow_dict=workflow_dict, task=task_history) current_step = database_region_migration.current_step database_region_migration.current_step = current_step - 1 database_region_migration.save() database_region_migration_detail.status = database_region_migration_detail.SUCCESS database_region_migration_detail.finished_at = datetime.now() database_region_migration_detail.save() task_history.update_status_for( TaskHistory.STATUS_SUCCESS, details='Database region migration was succesfully') except Exception as e: traceback = full_stack() LOG.error("Ops... something went wrong: %s" % e) LOG.error(traceback) task_history.update_status_for( TaskHistory.STATUS_ERROR, details=traceback) database_region_migration_detail.status = database_region_migration_detail.ERROR database_region_migration_detail.finished_at = datetime.now() database_region_migration_detail.save() return finally: AuditRequest.cleanup_request()