Skip to content

Commit

Permalink
pep8: fix using autopep8 agressive
Browse files Browse the repository at this point in the history
  • Loading branch information
ader1990 committed Oct 3, 2023
1 parent 6326c94 commit 554ddfe
Show file tree
Hide file tree
Showing 28 changed files with 136 additions and 78 deletions.
3 changes: 1 addition & 2 deletions coriolis/api/v1/endpoint_destination_minion_pool_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ def index(self, req, endpoint_id):
options = {}

return endpoint_options_view.destination_minion_pool_options_collection(
req,
self._minion_pool_options_api.get_endpoint_destination_minion_pool_options(
req, self._minion_pool_options_api.get_endpoint_destination_minion_pool_options(
context, endpoint_id, env=env, option_names=options))


Expand Down
3 changes: 1 addition & 2 deletions coriolis/api/v1/endpoint_source_minion_pool_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ def index(self, req, endpoint_id):
options = {}

return endpoint_options_view.source_minion_pool_options_collection(
req,
self._minion_pool_options_api.get_endpoint_source_minion_pool_options(
req, self._minion_pool_options_api.get_endpoint_source_minion_pool_options(
context, endpoint_id, env=env, option_names=options))


Expand Down
3 changes: 1 addition & 2 deletions coriolis/api/v1/minion_pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ def _validate_update_body(self, id, context, body):
elif minion_pool['platform'] == (
constants.PROVIDER_PLATFORM_DESTINATION):
self._endpoints_api.validate_endpoint_destination_minion_pool_options(
context, minion_pool['endpoint_id'],
vals['environment_options'])
context, minion_pool['endpoint_id'], vals['environment_options'])
else:
raise Exception(
"Unknown pool platform: %s" % minion_pool[
Expand Down
10 changes: 5 additions & 5 deletions coriolis/api/v1/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ def _setup_routes(self, mapper, ext_mgr):

self.resources['endpoint_destination_minion_pool_options'] = \
endpoint_destination_minion_pool_options.create_resource()
mapper.resource('minion_pool_options',
'endpoints/{endpoint_id}/destination-minion-pool-options',
controller=(
self.resources[
'endpoint_destination_minion_pool_options']))
mapper.resource(
'minion_pool_options',
'endpoints/{endpoint_id}/destination-minion-pool-options',
controller=(
self.resources['endpoint_destination_minion_pool_options']))

endpoint_actions_resource = endpoint_actions.create_resource()
self.resources['endpoint_actions'] = endpoint_actions_resource
Expand Down
2 changes: 1 addition & 1 deletion coriolis/api/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _get_show_deleted(val):
return val
try:
show_deleted = json.loads(val)
if type(show_deleted) is bool:
if isinstance(show_deleted, bool):
return show_deleted
except Exception as err:
LOG.warn(
Expand Down
2 changes: 1 addition & 1 deletion coriolis/api/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ def _process_stack(self, request, action, action_args,
# No exceptions; convert action_result into a
# ResponseObject
resp_obj = None
if type(action_result) is dict or action_result is None:
if isinstance(action_result, dict) or action_result is None:
resp_obj = ResponseObject(action_result)
elif isinstance(action_result, ResponseObject):
resp_obj = action_result
Expand Down
2 changes: 1 addition & 1 deletion coriolis/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


def get_cache_decorator(provider):
if type(provider) is not str or provider == "":
if not isinstance(provider, str) or provider == "":
raise exception.CoriolisException(
"Invalid provider name")
MEMOIZE = cache.get_memoization_decorator(
Expand Down
10 changes: 8 additions & 2 deletions coriolis/conductor/rpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,11 @@ def set_task_error(self, ctxt, task_id, exception_details):

def add_task_event(self, ctxt, task_id, level, message):
self._cast(
ctxt, 'add_task_event', task_id=task_id, level=level, message=message)
ctxt,
'add_task_event',
task_id=task_id,
level=level,
message=message)

def add_task_progress_update(
self, ctxt, task_id, message, initial_step=0, total_steps=0,
Expand Down Expand Up @@ -426,7 +430,9 @@ def confirm_replica_minions_allocation(
def report_replica_minions_allocation_error(
self, ctxt, replica_id, minion_allocation_error_details):
self._call(
ctxt, 'report_replica_minions_allocation_error', replica_id=replica_id,
ctxt,
'report_replica_minions_allocation_error',
replica_id=replica_id,
minion_allocation_error_details=minion_allocation_error_details)

def confirm_migration_minions_allocation(
Expand Down
36 changes: 24 additions & 12 deletions coriolis/conductor/rpc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1703,21 +1703,33 @@ def report_migration_minions_allocation_error(
LOG.warn(
"Error occured while allocating minion machines for Migration '%s'. "
"Cancelling the current Execution ('%s'). Error was: %s",
migration_id, execution.id, minion_allocation_error_details)
migration_id,
execution.id,
minion_allocation_error_details)
self._cancel_tasks_execution(
ctxt, execution, requery=True)
self._set_tasks_execution_status(
ctxt, execution,
constants.EXECUTION_STATUS_ERROR_ALLOCATING_MINIONS)

def migrate_instances(self, ctxt, origin_endpoint_id,
destination_endpoint_id, origin_minion_pool_id,
destination_minion_pool_id,
instance_osmorphing_minion_pool_mappings,
source_environment, destination_environment,
instances, network_map, storage_mappings,
replication_count, shutdown_instances=False,
notes=None, skip_os_morphing=False, user_scripts=None):
def migrate_instances(
self,
ctxt,
origin_endpoint_id,
destination_endpoint_id,
origin_minion_pool_id,
destination_minion_pool_id,
instance_osmorphing_minion_pool_mappings,
source_environment,
destination_environment,
instances,
network_map,
storage_mappings,
replication_count,
shutdown_instances=False,
notes=None,
skip_os_morphing=False,
user_scripts=None):
origin_endpoint = self.get_endpoint(ctxt, origin_endpoint_id)
destination_endpoint = self.get_endpoint(ctxt, destination_endpoint_id)
self._check_endpoints(ctxt, origin_endpoint, destination_endpoint)
Expand Down Expand Up @@ -2470,7 +2482,8 @@ def _check_clean_execution_deadlock(
constants.TASK_STATUS_CANCELED_FROM_DEADLOCK,
exception_details=TASK_DEADLOCK_ERROR_MESSAGE)
LOG.warn(
"Marking deadlocked execution '%s' as DEADLOCKED", execution.id)
"Marking deadlocked execution '%s' as DEADLOCKED",
execution.id)
self._set_tasks_execution_status(
ctxt, execution, constants.EXECUTION_STATUS_DEADLOCKED)
LOG.error(
Expand Down Expand Up @@ -2951,8 +2964,7 @@ def _check_other_tasks_running(execution, current_task):
LOG.info(
"All tasks of the '%s' Replica update procedure have "
"completed successfully. Setting the updated parameter "
"values on the parent Replica itself.",
execution.action_id)
"values on the parent Replica itself.", execution.action_id)
# NOTE: considering all the instances of the Replica get
# the same params, it doesn't matter which instance's
# update task finishes last:
Expand Down
2 changes: 1 addition & 1 deletion coriolis/cron/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def is_expired(self):

def should_run(self, dt):
# NOTE(gsamfira): I find your lack of strong typing....disturbing
if type(dt) is not datetime.datetime:
if not isinstance(dt, datetime.datetime):
raise exception.CoriolisException("Invalid datetime object")
if self.is_expired():
LOG.debug('Job %s has expired', self.name)
Expand Down
4 changes: 2 additions & 2 deletions coriolis/db/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ def get_region_mappings_for_endpoint(
models.EndpointRegionMapping.endpoint_id == endpoint_id)
if enabled_regions_only:
q = q.filter(
models.Region.enabled == True)
models.Region.enabled)
return q.all()


Expand Down Expand Up @@ -1244,7 +1244,7 @@ def get_region_mappings_for_service(
models.ServiceRegionMapping.service_id == service_id)
if enabled_regions_only:
q = q.filter(
models.Region.enabled == True)
models.Region.enabled)
return q.all()


Expand Down
2 changes: 1 addition & 1 deletion coriolis/db/sqlalchemy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def process_result_value(self, value, dialect):
data = None
try:
data = zlib.decompress(value)
except:
except BaseException:
data = value
return jsonutils.loads(data)

Expand Down
7 changes: 6 additions & 1 deletion coriolis/licensing/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ def _put(self, resource, body, response_key=None, appliance_scoped=True):
response_key=response_key,
appliance_scoped=appliance_scoped)

def _delete(self, resource, body, response_key=None, appliance_scoped=True):
def _delete(
self,
resource,
body,
response_key=None,
appliance_scoped=True):
return self._do_req(
"DELETE", resource, body=body,
response_key=response_key,
Expand Down
9 changes: 7 additions & 2 deletions coriolis/minion_manager/rpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ def add_minion_pool_progress_update(
initial_step=initial_step, total_steps=total_steps)

def update_minion_pool_progress_update(
self, ctxt, minion_pool_id, progress_update_index, new_current_step,
new_total_steps=None, new_message=None):
self,
ctxt,
minion_pool_id,
progress_update_index,
new_current_step,
new_total_steps=None,
new_message=None):
self._cast(
ctxt, 'update_minion_pool_progress_update',
minion_pool_id=minion_pool_id,
Expand Down
55 changes: 38 additions & 17 deletions coriolis/minion_manager/rpc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,12 @@ def add_minion_pool_event(self, ctxt, minion_pool_id, level, message):
self._add_minion_pool_event(ctxt, minion_pool_id, level, message)

def _add_minion_pool_progress_update(
self, ctxt, minion_pool_id, message, initial_step=0, total_steps=0):
self,
ctxt,
minion_pool_id,
message,
initial_step=0,
total_steps=0):
LOG.info(
"Adding pool progress update for %s: %s", minion_pool_id, message)
db_api.add_minion_pool_progress_update(
Expand All @@ -303,7 +308,12 @@ def _add_minion_pool_progress_update(

@minion_manager_utils.minion_pool_synchronized_op
def add_minion_pool_progress_update(
self, ctxt, minion_pool_id, message, initial_step=0, total_steps=0):
self,
ctxt,
minion_pool_id,
message,
initial_step=0,
total_steps=0):
self._add_minion_pool_progress_update(
ctxt, minion_pool_id, message, initial_step=initial_step,
total_steps=total_steps)
Expand Down Expand Up @@ -471,7 +481,9 @@ def _check_pool_minion_count(
else:
osmorphing_pool_mappings[pool_id].append(instance_id)

for (pool_id, instances_to_osmorph) in osmorphing_pool_mappings.items():
for (
pool_id,
instances_to_osmorph) in osmorphing_pool_mappings.items():
osmorphing_pool = _get_pool(pool_id)
if osmorphing_pool.endpoint_id != (
action['destination_endpoint_id']):
Expand Down Expand Up @@ -689,7 +701,9 @@ def _select_machine(minion_pool, exclude=None):
LOG.info(
"Adding new minion machine with ID '%s' to the DB for pool "
"'%s' for use with action '%s'.",
new_machine_id, minion_pool.id, action_id)
new_machine_id,
minion_pool.id,
action_id)
db_api.add_minion_machine(ctxt, new_machine)
new_machine_db_entries_added.append(new_machine.id)
self._add_minion_pool_event(
Expand Down Expand Up @@ -1033,7 +1047,9 @@ def _cleanup_machines_with_statuses_for_action(
if machine.pool_id in exclude_pools:
LOG.debug(
"Skipping deletion of machine '%s' (status '%s') from "
"whitelisted pool '%s'", machine.id, machine.allocation_status,
"whitelisted pool '%s'",
machine.id,
machine.allocation_status,
machine.pool_id)
continue

Expand Down Expand Up @@ -1120,8 +1136,8 @@ def deallocate_minion_machines_for_action(self, ctxt, action_id):
LOG.warn(
"Found minion machine '%s' in pool '%s' which "
"is in '%s' status. Removing from the DB "
"entirely." % (
machine.id, pool_id, machine.allocation_status))
"entirely." %
(machine.id, pool_id, machine.allocation_status))
db_api.delete_minion_machine(
ctxt, machine.id)
LOG.info(
Expand All @@ -1132,7 +1148,10 @@ def deallocate_minion_machines_for_action(self, ctxt, action_id):
"Going to mark minion machine '%s' (current status "
"'%s') of pool '%s' as available following machine "
"deallocation request for action '%s'.",
machine.id, machine.allocation_status, pool_id, action_id)
machine.id,
machine.allocation_status,
pool_id,
action_id)
machine_ids_to_deallocate.append(machine.id)

LOG.info(
Expand All @@ -1156,8 +1175,8 @@ def _get_healtchcheck_flow_for_minion_machine(
and redeployment subflow on error. """
# define healthcheck subflow for each machine:
machine_healthcheck_subflow = graph_flow.Flow(
minion_manager_tasks.MINION_POOL_HEALTHCHECK_MACHINE_SUBFLOW_NAME_FORMAT % (
minion_pool.id, minion_machine.id))
minion_manager_tasks.MINION_POOL_HEALTHCHECK_MACHINE_SUBFLOW_NAME_FORMAT %
(minion_pool.id, minion_machine.id))

# add healtcheck task to healthcheck subflow:
machine_healthcheck_task = (
Expand Down Expand Up @@ -1204,8 +1223,8 @@ def _get_healtchcheck_flow_for_minion_machine(

# define reallocation subflow:
machine_reallocation_subflow = linear_flow.Flow(
minion_manager_tasks.MINION_POOL_REALLOCATE_MACHINE_SUBFLOW_NAME_FORMAT % (
minion_pool.id, minion_machine.id))
minion_manager_tasks.MINION_POOL_REALLOCATE_MACHINE_SUBFLOW_NAME_FORMAT %
(minion_pool.id, minion_machine.id))
machine_reallocation_subflow.add(
minion_manager_tasks.DeallocateMinionMachineTask(
minion_pool.id, minion_machine.id, minion_pool.platform,
Expand Down Expand Up @@ -1686,14 +1705,16 @@ def _get_minion_pool_deallocation_flow(
# NOTE: bool(flow) == False if the flow has no child flows/tasks:
if machines_flow:
# tansition pool to DEALLOCATING_MACHINES:
deallocation_flow.add(minion_manager_tasks.UpdateMinionPoolStatusTask(
minion_pool.id,
constants.MINION_POOL_STATUS_DEALLOCATING_MACHINES,
status_to_revert_to=constants.MINION_POOL_STATUS_ERROR))
deallocation_flow.add(
minion_manager_tasks.UpdateMinionPoolStatusTask(
minion_pool.id,
constants.MINION_POOL_STATUS_DEALLOCATING_MACHINES,
status_to_revert_to=constants.MINION_POOL_STATUS_ERROR))
deallocation_flow.add(machines_flow)
else:
LOG.debug(
"No machines for pool '%s' require deallocating.", minion_pool.id)
"No machines for pool '%s' require deallocating.",
minion_pool.id)

# transition pool to DEALLOCATING_SHARED_RESOURCES:
deallocation_flow.add(minion_manager_tasks.UpdateMinionPoolStatusTask(
Expand Down
16 changes: 9 additions & 7 deletions coriolis/minion_manager/rpc/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,9 +964,8 @@ def revert(self, context, origin, destination, task_info, **kwargs):
except Exception:
log_msg = (
"[Task '%s'] Exception occurred while attempting to revert "
"deployment of minion machine with ID '%s' for pool '%s'." % (
self._task_name, self._minion_machine_id,
self._minion_pool_id))
"deployment of minion machine with ID '%s' for pool '%s'." %
(self._task_name, self._minion_machine_id, self._minion_pool_id))
if not self._raise_on_cleanup_failure:
log_msg = (
"%s Ignoring exception." % log_msg)
Expand Down Expand Up @@ -1062,10 +1061,13 @@ class HealthcheckMinionMachineTask(BaseMinionManangerTask):
""" Task which healthchecks the given minion machine. """

def __init__(
self, minion_pool_id, minion_machine_id, minion_pool_type,
fail_on_error=False,
machine_status_on_success=constants.MINION_MACHINE_STATUS_AVAILABLE,
**kwargs):
self,
minion_pool_id,
minion_machine_id,
minion_pool_type,
fail_on_error=False,
machine_status_on_success=constants.MINION_MACHINE_STATUS_AVAILABLE,
**kwargs):
self._fail_on_error = fail_on_error
self._machine_status_on_success = machine_status_on_success
resource_healthcheck_task = (
Expand Down
2 changes: 1 addition & 1 deletion coriolis/osmorphing/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _version_supported_util(cls, version, minimum, maximum=None):
if not version:
return False

if type(version) is not str:
if not isinstance(version, str):
raise ValueError(
"Non-string version provided: %s (type %s)" % (
version, type(version)))
Expand Down
Loading

0 comments on commit 554ddfe

Please sign in to comment.