Просмотр исходного кода

Add 'skip_allocation' option for minion pool creation.

Nashwan Azhari 5 лет назад
Родитель
Сommit
5d0a6ea4e9

+ 7 - 3
coriolis/api/v1/minion_pools.py

@@ -120,22 +120,26 @@ class MinionPoolController(api_wsgi.Controller):
         self._check_pool_retention_strategy(
             minion_retention_strategy)
         notes = minion_pool.get("notes")
+
+        skip_allocation = minion_pool.get('skip_allocation', False)
         return (
             name, endpoint_id, pool_platform, pool_os_type,
             environment_options, minimum_minions, maximum_minions,
-            minion_max_idle_time, minion_retention_strategy, notes)
+            minion_max_idle_time, minion_retention_strategy, notes,
+            skip_allocation)
 
     def create(self, req, body):
         context = req.environ["coriolis.context"]
         context.can(pools_policies.get_minion_pools_policy_label("create"))
         (name, endpoint_id, pool_platform, pool_os_type, environment_options,
          minimum_minions, maximum_minions, minion_max_idle_time,
-         minion_retention_strategy, notes) = (
+         minion_retention_strategy, notes, skip_allocation) = (
             self._validate_create_body(context, body))
         return minion_pool_view.single(req, self._minion_pool_api.create(
             context, name, endpoint_id, pool_platform, pool_os_type,
             environment_options, minimum_minions, maximum_minions,
-            minion_max_idle_time, minion_retention_strategy, notes=notes))
+            minion_max_idle_time, minion_retention_strategy, notes=notes,
+            skip_allocation=skip_allocation))
 
     @api_utils.format_keyerror_message(resource='minion_pool', method='update')
     def _validate_update_body(self, id, context, body):

+ 3 - 2
coriolis/minion_manager/rpc/client.py

@@ -72,7 +72,8 @@ class MinionManagerClient(object):
     def create_minion_pool(
             self, ctxt, name, endpoint_id, pool_platform, pool_os_type,
             environment_options, minimum_minions, maximum_minions,
-            minion_max_idle_time, minion_retention_strategy, notes=None):
+            minion_max_idle_time, minion_retention_strategy, notes=None,
+            skip_allocation=False):
         return self._client.call(
             ctxt, 'create_minion_pool', name=name, endpoint_id=endpoint_id,
             pool_platform=pool_platform, pool_os_type=pool_os_type,
@@ -81,7 +82,7 @@ class MinionManagerClient(object):
             maximum_minions=maximum_minions,
             minion_max_idle_time=minion_max_idle_time,
             minion_retention_strategy=minion_retention_strategy,
-            notes=notes)
+            notes=notes, skip_allocation=skip_allocation)
 
     def set_up_shared_minion_pool_resources(self, ctxt, minion_pool_id):
         return self._client.call(

+ 14 - 11
coriolis/minion_manager/rpc/server.py

@@ -76,7 +76,7 @@ class MinionManagerServerEndpoint(object):
 
         worker_service = self._scheduler_client.get_worker_service_for_specs(
             ctxt, enabled=True,
-            region_sets=[[reg.id for reg in endpoint['mapped_regions']]],
+            region_sets=[[reg['id'] for reg in endpoint['mapped_regions']]],
             provider_requirements={
                 endpoint['type']: [
                     constants.PROVIDER_TYPE_SOURCE_MINION_POOL]})
@@ -93,7 +93,7 @@ class MinionManagerServerEndpoint(object):
 
         worker_service = self._scheduler_client.get_worker_service_for_specs(
             ctxt, enabled=True,
-            region_sets=[[reg.id for reg in endpoint['mapped_regions']]],
+            region_sets=[[reg['id'] for reg in endpoint['mapped_regions']]],
             provider_requirements={
                 endpoint['type']: [
                     constants.PROVIDER_TYPE_DESTINATION_MINION_POOL]})
@@ -110,7 +110,7 @@ class MinionManagerServerEndpoint(object):
 
         worker_service = self._scheduler_client.get_worker_service_for_specs(
             ctxt, enabled=True,
-            region_sets=[[reg.id for reg in endpoint['mapped_regions']]],
+            region_sets=[[reg['id'] for reg in endpoint['mapped_regions']]],
             provider_requirements={
                 endpoint['type']: [
                     constants.PROVIDER_TYPE_SOURCE_MINION_POOL]})
@@ -126,7 +126,7 @@ class MinionManagerServerEndpoint(object):
 
         worker_service = self._scheduler_client.get_worker_service_for_specs(
             ctxt, enabled=True,
-            region_sets=[[reg.id for reg in endpoint['mapped_regions']]],
+            region_sets=[[reg['id'] for reg in endpoint['mapped_regions']]],
             provider_requirements={
                 endpoint['type']: [
                     constants.PROVIDER_TYPE_DESTINATION_MINION_POOL]})
@@ -593,7 +593,8 @@ class MinionManagerServerEndpoint(object):
     def create_minion_pool(
             self, ctxt, name, endpoint_id, pool_platform, pool_os_type,
             environment_options, minimum_minions, maximum_minions,
-            minion_max_idle_time, minion_retention_strategy, notes=None):
+            minion_max_idle_time, minion_retention_strategy, notes=None,
+            skip_allocation=False):
 
         endpoint_dict = self._conductor_client.get_endpoint(
             ctxt, endpoint_id)
@@ -612,13 +613,15 @@ class MinionManagerServerEndpoint(object):
         minion_pool.minion_retention_strategy = minion_retention_strategy
 
         db_api.add_minion_pool(ctxt, minion_pool)
-        allocation_flow = self._get_minion_pool_allocation_flow(minion_pool)
 
-        # start the deployment flow:
-        initial_store = self._get_pool_allocation_initial_store(
-            ctxt, minion_pool, endpoint_dict)
-        self._taskflow_runner.run_flow_in_background(
-            allocation_flow, store=initial_store)
+        if not skip_allocation:
+            allocation_flow = self._get_minion_pool_allocation_flow(
+                minion_pool)
+            # start the deployment flow:
+            initial_store = self._get_pool_allocation_initial_store(
+                ctxt, minion_pool, endpoint_dict)
+            self._taskflow_runner.run_flow_in_background(
+                allocation_flow, store=initial_store)
 
         return self.get_minion_pool(ctxt, minion_pool.id)
 

+ 9 - 0
coriolis/minion_manager/rpc/tasks.py

@@ -38,6 +38,8 @@ class UpdateMinionPoolStatusTask(coriolis_taskflow_base.BaseCoriolisTaskflowTask
     Is capable of recording and reverting the state.
     """
 
+    default_provides = ["latest_status"]
+
     def __init__(
             self, minion_pool_id, target_status,
             status_to_revert_to=None, **kwargs):
@@ -85,6 +87,8 @@ class UpdateMinionPoolStatusTask(coriolis_taskflow_base.BaseCoriolisTaskflowTask
                 "Pool status transitioned from '%s' to '%s'" % (
                     self._previous_status, self._target_status))
 
+        return self._target_status
+
     def revert(self, context, *args, **kwargs):
         super(UpdateMinionPoolStatusTask, self).revert(*args, **kwargs)
 
@@ -217,6 +221,11 @@ class ValidateMinionPoolOptionsTask(BaseMinionManangerTask):
         self._add_minion_pool_event(
             context, "Successfully validated minion pool options")
 
+    def revert(self, context, origin, destination, task_info, **kwargs):
+        LOG.debug("[%s] Nothing to revert for validation" % self._task_name)
+        res = super(ValidateMinionPoolOptionsTask, self).execute(
+            context, origin, destination, task_info)
+
 
 class AllocateSharedPoolResourcesTask(BaseMinionManangerTask):
 

+ 4 - 2
coriolis/minion_pools/api.py

@@ -12,11 +12,13 @@ class API(object):
     def create(
             self, ctxt, name, endpoint_id, pool_platform, pool_os_type,
             environment_options, minimum_minions, maximum_minions,
-            minion_max_idle_time, minion_retention_strategy, notes=None):
+            minion_max_idle_time, minion_retention_strategy, notes=None,
+            skip_allocation=False):
         return self._rpc_client.create_minion_pool(
             ctxt, name, endpoint_id, pool_platform, pool_os_type,
             environment_options, minimum_minions, maximum_minions,
-            minion_max_idle_time, minion_retention_strategy, notes=notes)
+            minion_max_idle_time, minion_retention_strategy, notes=notes,
+            skip_allocation=skip_allocation)
 
     def update(self, ctxt, minion_pool_id, updated_values):
         return self._rpc_client.update_minion_pool(

+ 2 - 2
coriolis/scheduler/rpc/client.py

@@ -119,9 +119,9 @@ class SchedulerClient(rpc.BaseRPCClient):
         # determine required Coriolis regions based on the endpoints:
         required_region_sets = []
         origin_endpoint_region_ids = [
-            r.id for r in origin_endpoint['mapped_regions']]
+            r['id'] for r in origin_endpoint['mapped_regions']]
         destination_endpoint_region_ids = [
-            r.id for r in destination_endpoint['mapped_regions']]
+            r['id'] for r in destination_endpoint['mapped_regions']]
 
         required_platform = task_cls.get_required_platform()
         if required_platform in (

+ 14 - 1
coriolis/taskflow/base.py

@@ -47,6 +47,19 @@ class BaseCoriolisTaskflowTask(taskflow_tasks.Task):
             if full_tracebacks:
                 label = "Traceback"
                 failure_str = task_failure.traceback_str
+            else:
+                failure_str = task_failure.exception_str
+                if isinstance(
+                        task_failure.exception,
+                        exception.TaskProcessException):
+                    # NOTE: TaskProcessException contains a full trace
+                    # from the worker service so we must split it:
+                    exception_lines = task_failure.exception_str.split('\n')
+                    if exception_lines:
+                        if len(exception_lines) > 2:
+                            failure_str = exception_lines[-2].strip()
+                        else:
+                            failure_str = exception_lines[-1].strip()
             res = (
                 "%s %s for task '%s': %s\n" % (
                     res, label, task_id, failure_str))
@@ -186,7 +199,7 @@ class BaseRunWorkerTask(BaseCoriolisTaskflowTask):
         try:
             LOG.debug(
                 "Starting to run task '%s' (type '%s') on worker service." % (
-                    task_id, task_type))
+                    self._task_name, task_type))
             res = worker_rpc.run_task(
                 ctxt, None, self._task_id, task_type, origin, destination,
                 self._task_instance, task_info)