From 6326c94c7e568e32cf99992fdbc2a5fb53742bf3 Mon Sep 17 00:00:00 2001 From: Adrian Vladu Date: Tue, 3 Oct 2023 17:45:20 +0300 Subject: [PATCH] pep8: fix pep8 warnings using autopep8 --- coriolis/api/v1/views/diagnostic_view.py | 2 +- coriolis/db/sqlalchemy/models.py | 6 +-- coriolis/db/sqlalchemy/types.py | 2 +- coriolis/events.py | 7 ++-- coriolis/minion_manager/rpc/client.py | 5 ++- coriolis/minion_manager/rpc/server.py | 18 +++++---- coriolis/osmorphing/osmount/windows.py | 2 +- coriolis/osmorphing/windows.py | 2 +- coriolis/providers/backup_writers.py | 6 +-- coriolis/providers/base.py | 1 - coriolis/providers/provider_utils.py | 42 ++++++++++----------- coriolis/providers/replicator.py | 5 ++- coriolis/rpc.py | 6 +-- coriolis/scheduler/rpc/client.py | 2 +- coriolis/scheduler/rpc/server.py | 1 - coriolis/scheduler/scheduler_utils.py | 1 + coriolis/service.py | 1 + coriolis/taskflow/base.py | 12 +++--- coriolis/taskflow/runner.py | 2 +- coriolis/tasks/minion_pool_tasks.py | 2 +- coriolis/tests/conductor/rpc/test_server.py | 16 ++++---- coriolis/tests/test_schemas.py | 6 ++- coriolis/tests/worker/rpc/test_server.py | 10 ++--- 23 files changed, 82 insertions(+), 75 deletions(-) diff --git a/coriolis/api/v1/views/diagnostic_view.py b/coriolis/api/v1/views/diagnostic_view.py index 295ee9c2a..871b7f64c 100644 --- a/coriolis/api/v1/views/diagnostic_view.py +++ b/coriolis/api/v1/views/diagnostic_view.py @@ -3,7 +3,7 @@ def single(req, diag): - return {"diagnostic": diag} + return {"diagnostic": diag} def collection(req, diag): diff --git a/coriolis/db/sqlalchemy/models.py b/coriolis/db/sqlalchemy/models.py index 6be5070c6..bd5da9881 100644 --- a/coriolis/db/sqlalchemy/models.py +++ b/coriolis/db/sqlalchemy/models.py @@ -45,7 +45,7 @@ def to_dict(self): class MinionPoolEvent(BASE, models.TimestampMixin, models.SoftDeleteMixin, - models.ModelBase): + models.ModelBase): __tablename__ = 'minion_pool_event' id = sqlalchemy.Column(sqlalchemy.String(36), @@ -538,8 +538,8 @@ def to_dict(self): class MinionPool( - BASE, models.TimestampMixin, models.ModelBase, - models.SoftDeleteMixin): + BASE, models.TimestampMixin, models.ModelBase, + models.SoftDeleteMixin): __tablename__ = 'minion_pool' id = sqlalchemy.Column( diff --git a/coriolis/db/sqlalchemy/types.py b/coriolis/db/sqlalchemy/types.py index a9c45704f..e1671b73b 100644 --- a/coriolis/db/sqlalchemy/types.py +++ b/coriolis/db/sqlalchemy/types.py @@ -56,7 +56,7 @@ class Bson(Blob): def process_bind_param(self, value, dialect): return zlib.compress( - jsonutils.dumps(value).encode('utf-8')) + jsonutils.dumps(value).encode('utf-8')) def process_result_value(self, value, dialect): if value is None: diff --git a/coriolis/events.py b/coriolis/events.py index 7026087d0..66021fcae 100644 --- a/coriolis/events.py +++ b/coriolis/events.py @@ -56,18 +56,19 @@ def add_percentage_step(self, message, total_steps, initial_step=0): if initial_step > 0 and total_steps > 0: perc = int(initial_step * 100 // total_steps) self._perc_steps[progress_update_id] = _PercStepData( - progress_update_id, perc, initial_step, total_steps) + progress_update_id, perc, initial_step, total_steps) return self._perc_steps[progress_update_id] def set_percentage_step(self, step, new_current_step): perc_step = self._perc_steps.get( - step.progress_update_id, None) + step.progress_update_id, None) if perc_step is None: return if perc_step.last_value > new_current_step: - LOG.warn("rollback for perc update %s not allowed" % step.progress_update_id) + LOG.warn("rollback for perc update %s not allowed" % + step.progress_update_id) return perc = 0 diff --git a/coriolis/minion_manager/rpc/client.py b/coriolis/minion_manager/rpc/client.py index 7225afc7d..0afd71ce7 100644 --- a/coriolis/minion_manager/rpc/client.py +++ b/coriolis/minion_manager/rpc/client.py @@ -26,7 +26,8 @@ class MinionManagerClient(rpc.BaseRPCClient): def __init__(self, timeout=None): - target = messaging.Target(topic='coriolis_minion_manager', version=VERSION) + target = messaging.Target( + topic='coriolis_minion_manager', version=VERSION) if timeout is None: timeout = CONF.minion_manager.minion_mananger_rpc_timeout super(MinionManagerClient, self).__init__( @@ -81,7 +82,7 @@ def allocate_minion_machines_for_migration( include_osmorphing_minions=include_osmorphing_minions) def deallocate_minion_machine(self, ctxt, minion_machine_id): - return self._cast( + return self._cast( ctxt, 'deallocate_minion_machine', minion_machine_id=minion_machine_id) diff --git a/coriolis/minion_manager/rpc/server.py b/coriolis/minion_manager/rpc/server.py index 114513c11..c8d707282 100644 --- a/coriolis/minion_manager/rpc/server.py +++ b/coriolis/minion_manager/rpc/server.py @@ -351,12 +351,14 @@ def validate_minion_pool_selections_for_action(self, ctxt, action): for pool in db_api.get_minion_pools( ctxt, include_machines=False, include_events=False, include_progress_updates=False, to_dict=False)} + def _get_pool(pool_id): pool = minion_pools.get(pool_id) if not pool: raise exception.NotFound( "Could not find minion pool with ID '%s'." % pool_id) return pool + def _check_pool_minion_count( minion_pool, instances, minion_pool_type=""): desired_minion_count = len(instances) @@ -364,7 +366,7 @@ def _check_pool_minion_count( raise exception.InvalidMinionPoolState( "Minion Pool '%s' is an invalid state ('%s') to be " "used as a %s pool for action '%s'. The pool must be " - "in '%s' status." % ( + "in '%s' status." % ( minion_pool.id, minion_pool.status, minion_pool_type.lower(), action['id'], constants.MINION_POOL_STATUS_ALLOCATED)) @@ -569,7 +571,7 @@ def _make_minion_machine_allocation_subflow_for_action( num_instances = len(action_instances) num_currently_available_machines = len(currently_available_machines) if num_instances > (len(currently_available_machines) + ( - extra_available_machine_slots)): + extra_available_machine_slots)): raise exception.InvalidMinionPoolState( "Minion pool '%s' is unable to accommodate the requested " "number of machines (%s) for transfer action '%s', as it only " @@ -816,7 +818,7 @@ def _check_pool_allocation_status( raise exception.InvalidMinionPoolState( "Minion Pool '%s' is an invalid state ('%s') to be " "used as a %s pool for action '%s'. The pool must be " - "in '%s' status." % ( + "in '%s' status." % ( minion_pool.id, minion_pool.status, minion_pool_type.lower(), action['id'], constants.MINION_POOL_STATUS_ALLOCATED)) @@ -1042,7 +1044,7 @@ def _cleanup_machines_with_statuses_for_action( for (pool_id, machines) in pool_machine_mappings.items(): with minion_manager_utils.get_minion_pool_lock( - pool_id, external=True): + pool_id, external=True): for machine in machines: LOG.debug( "Deleting machine with ID '%s' (pool '%s', status '%s') " @@ -1322,8 +1324,8 @@ def _get_minion_pool_refresh_flow( constants.MINION_POOL_MACHINE_RETENTION_STRATEGY_DELETE): pool_refresh_flow.add( minion_manager_tasks.DeallocateMinionMachineTask( - minion_pool.id, machine.id, - minion_pool.platform)) + minion_pool.id, machine.id, + minion_pool.platform)) else: raise exception.InvalidMinionPoolState( "Unknown minion pool retention strategy '%s' for pool " @@ -1347,7 +1349,7 @@ def _get_minion_pool_refresh_flow( # update DB entried for all machines and emit relevant events: if skipped_machines: - base_msg = ( + base_msg = ( "The following minion machines were skipped during the " "refreshing of the minion pool as they were in other " "statuses than the serviceable ones: %s") @@ -1739,7 +1741,7 @@ def deallocate_minion_pool(self, ctxt, minion_pool_id, force=False): if not force: raise exception.InvalidMinionPoolState( "Minion pool '%s' cannot be deallocated as the pool" - " is in '%s' state instead of one of the expected %s"% ( + " is in '%s' state instead of one of the expected %s" % ( minion_pool_id, minion_pool.status, acceptable_deallocation_statuses)) else: diff --git a/coriolis/osmorphing/osmount/windows.py b/coriolis/osmorphing/osmount/windows.py index a349d5d20..be52a177f 100644 --- a/coriolis/osmorphing/osmount/windows.py +++ b/coriolis/osmorphing/osmount/windows.py @@ -239,7 +239,7 @@ def mount_os(self): self._set_volumes_drive_letter() self._refresh_storage() fs_roots = utils.retry_on_error(sleep_seconds=5)(self._get_fs_roots)( - fail_if_empty=True) + fail_if_empty=True) system_drive = self._get_system_drive() for fs_root in [r for r in fs_roots if not r[:-1] == system_drive]: diff --git a/coriolis/osmorphing/windows.py b/coriolis/osmorphing/windows.py index 0adfca35c..2b32fc66a 100644 --- a/coriolis/osmorphing/windows.py +++ b/coriolis/osmorphing/windows.py @@ -148,7 +148,7 @@ $IPS_INFO = ConvertFrom-Json $ips_info_json Invoke-Main $NICS_INFO $IPS_INFO -""" # noqa +""" # noqa class BaseWindowsMorphingTools(base.BaseOSMorphingTools): diff --git a/coriolis/providers/backup_writers.py b/coriolis/providers/backup_writers.py index a11a8ac7e..d476572e2 100644 --- a/coriolis/providers/backup_writers.py +++ b/coriolis/providers/backup_writers.py @@ -368,8 +368,8 @@ def write(self, data): if self._exception: raise exception.CoriolisException( - "Failed to write data. See log " - "for details.") from self._exception + "Failed to write data. See log " + "for details.") from self._exception payload = { "offset": self._offset, @@ -923,7 +923,7 @@ def _init_writer(self, ssh, cert_paths): "srv_key": cert_paths["srv_key"], "srv_cert": cert_paths["srv_crt"], "listen_port": self._writer_port, - } + } self._change_binary_se_context(ssh) utils.create_service( ssh, cmdline, _CORIOLIS_HTTP_WRITER_CMD, start=True) diff --git a/coriolis/providers/base.py b/coriolis/providers/base.py index 06bedd7a9..d9190a3dc 100644 --- a/coriolis/providers/base.py +++ b/coriolis/providers/base.py @@ -201,7 +201,6 @@ def get_os_morphing_tools(self, os_type, osmorphing_info): """ raise exception.OSMorphingToolsNotFound(os_type=os_type) - def get_custom_os_detect_tools(self, os_type, osmorphing_info): """ Returns a list of custom OSDetect classes which inherit from coriolis.osmorphing.osdetect.base.BaseOSDetectTools. diff --git a/coriolis/providers/provider_utils.py b/coriolis/providers/provider_utils.py index cc5a1f464..ed976e49d 100644 --- a/coriolis/providers/provider_utils.py +++ b/coriolis/providers/provider_utils.py @@ -111,24 +111,24 @@ def get_storage_mapping_for_disk( def check_changed_storage_mappings(volumes_info, old_storage_mappings, new_storage_mappings): - if not volumes_info: - return - - old_backend_mappings = old_storage_mappings.get('backend_mappings', []) - old_disk_mappings = old_storage_mappings.get('disk_mappings', []) - new_backend_mappings = new_storage_mappings.get('backend_mappings', []) - new_disk_mappings = new_storage_mappings.get('disk_mappings', []) - - old_backend_mappings_set = [ - tuple(mapping.values()) for mapping in old_backend_mappings] - old_disk_mappings_set = [ - tuple(mapping.values()) for mapping in old_disk_mappings] - new_backend_mappings_set = [ - tuple(mapping.values()) for mapping in new_backend_mappings] - new_disk_mappings_set = [ - tuple(mapping.values()) for mapping in new_disk_mappings] - - if (old_backend_mappings_set != new_backend_mappings_set or - old_disk_mappings_set != new_disk_mappings_set): - raise exception.CoriolisException("Modifying storage mappings is " - "not supported.") + if not volumes_info: + return + + old_backend_mappings = old_storage_mappings.get('backend_mappings', []) + old_disk_mappings = old_storage_mappings.get('disk_mappings', []) + new_backend_mappings = new_storage_mappings.get('backend_mappings', []) + new_disk_mappings = new_storage_mappings.get('disk_mappings', []) + + old_backend_mappings_set = [ + tuple(mapping.values()) for mapping in old_backend_mappings] + old_disk_mappings_set = [ + tuple(mapping.values()) for mapping in old_disk_mappings] + new_backend_mappings_set = [ + tuple(mapping.values()) for mapping in new_backend_mappings] + new_disk_mappings_set = [ + tuple(mapping.values()) for mapping in new_disk_mappings] + + if (old_backend_mappings_set != new_backend_mappings_set or + old_disk_mappings_set != new_disk_mappings_set): + raise exception.CoriolisException("Modifying storage mappings is " + "not supported.") diff --git a/coriolis/providers/replicator.py b/coriolis/providers/replicator.py index 2347073de..86368716f 100644 --- a/coriolis/providers/replicator.py +++ b/coriolis/providers/replicator.py @@ -378,7 +378,7 @@ def attach_new_disk( new_device_paths = [dev['device-path'] for dev in new_disks_status] LOG.debug( "Polled devices while waiting for disk '%s' to attach " - "(try %d/%d): %s", disk_id, i+1, retry_count, new_device_paths) + "(try %d/%d): %s", disk_id, i + 1, retry_count, new_device_paths) # check for missing/multiple new device paths: missing_device_paths = ( @@ -390,7 +390,8 @@ def attach_new_disk( dev for dev in previous_disks_status if dev['device-path'] in missing_device_paths]) - new_device_paths = set(new_device_paths) - set(previous_device_paths) + new_device_paths = set(new_device_paths) - \ + set(previous_device_paths) if new_device_paths: break else: diff --git a/coriolis/rpc.py b/coriolis/rpc.py index 4a1dfe5a1..33bb3827c 100644 --- a/coriolis/rpc.py +++ b/coriolis/rpc.py @@ -102,9 +102,9 @@ def _transport(self): def _rpc_client(self): return messaging.RPCClient( - self._transport, self._target, - serializer=self._serializer, - timeout=self._timeout) + self._transport, self._target, + serializer=self._serializer, + timeout=self._timeout) def _call(self, ctxt, method, **kwargs): client = self._rpc_client() diff --git a/coriolis/scheduler/rpc/client.py b/coriolis/scheduler/rpc/client.py index 2bc2f9d60..61c009064 100644 --- a/coriolis/scheduler/rpc/client.py +++ b/coriolis/scheduler/rpc/client.py @@ -167,7 +167,7 @@ def get_worker_service_for_task( LOG.warn( "Failed to schedule task with ID '%s' (attempt %d/%d). " "Waiting %d seconds and then retrying. Error was: %s", - task['id'], i+1, retry_count, retry_period, + task['id'], i + 1, retry_count, retry_period, utils.get_exception_details()) time.sleep(retry_period) diff --git a/coriolis/scheduler/rpc/server.py b/coriolis/scheduler/rpc/server.py index d162ee91c..fc1a0399a 100644 --- a/coriolis/scheduler/rpc/server.py +++ b/coriolis/scheduler/rpc/server.py @@ -57,7 +57,6 @@ def _get_weighted_filtered_services( scores = [] - service_ids = [service.id for service in services] LOG.debug( "Running following filters on worker services '%s': %s", diff --git a/coriolis/scheduler/scheduler_utils.py b/coriolis/scheduler/scheduler_utils.py index 820b00ea1..c8baa79dd 100644 --- a/coriolis/scheduler/scheduler_utils.py +++ b/coriolis/scheduler/scheduler_utils.py @@ -58,6 +58,7 @@ def get_any_worker_service( return service return db_api.get_service(ctxt, service['id']) + def get_worker_rpc_for_host(host, *client_args, **client_kwargs): rpc_client_class = RPC_TOPIC_TO_CLIENT_CLASS_MAP[ constants.WORKER_MAIN_MESSAGING_TOPIC] diff --git a/coriolis/service.py b/coriolis/service.py index eb1ae6ec0..e73715ac7 100644 --- a/coriolis/service.py +++ b/coriolis/service.py @@ -42,6 +42,7 @@ def get_worker_count_from_args(argv): --worker-process-count is not present), as well as the unprocessed args. """ parser = argparse.ArgumentParser() + def _check_positive_worker_count(worker_count): count = int(worker_count) if count <= 0: diff --git a/coriolis/taskflow/base.py b/coriolis/taskflow/base.py index 5ba3eed7d..c3eba2bc9 100644 --- a/coriolis/taskflow/base.py +++ b/coriolis/taskflow/base.py @@ -15,7 +15,7 @@ TASK_RETURN_VALUE_FORMAT = "%s-result" % ( - constants.TASK_LOCK_NAME_FORMAT) + constants.TASK_LOCK_NAME_FORMAT) LOG = logging.getLogger() taskflow_opts = [ @@ -154,8 +154,8 @@ def _set_requires_for_task_info_fields(self, kwargs): cleanup_task_deps = list( set( cleanup_task_runner.get_required_task_info_properties( - )).difference( - main_task_runner.get_returned_task_info_properties())) + )).difference( + main_task_runner.get_returned_task_info_properties())) new_requires.extend(cleanup_task_deps) kwargs['requires'] = new_requires @@ -173,8 +173,8 @@ def _set_provides_for_task_info_fields(self, kwargs): cleanup_task_res = list( set( cleanup_task_runner.get_returned_task_info_properties( - )).difference( - main_task_runner.get_returned_task_info_properties())) + )).difference( + main_task_runner.get_returned_task_info_properties())) new_provides.extend(cleanup_task_res) kwargs['provides'] = new_provides @@ -193,7 +193,7 @@ def _get_worker_service_rpc_for_task( LOG.debug( "[Task '%s'] Was offered the following worker service for executing " "Taskflow worker task '%s': %s", - self._task_name, task_id, worker_service['id']) + self._task_name, task_id, worker_service['id']) return rpc_worker_client.WorkerClient.from_service_definition( worker_service, timeout=rpc_timeout) diff --git a/coriolis/taskflow/runner.py b/coriolis/taskflow/runner.py index 92822aba9..f8417bb82 100644 --- a/coriolis/taskflow/runner.py +++ b/coriolis/taskflow/runner.py @@ -6,7 +6,7 @@ import sys from logging import handlers -import eventlet #noqa +import eventlet # noqa from oslo_config import cfg from oslo_log import log as logging from six.moves import queue diff --git a/coriolis/tasks/minion_pool_tasks.py b/coriolis/tasks/minion_pool_tasks.py index 24e4db80e..605928b20 100644 --- a/coriolis/tasks/minion_pool_tasks.py +++ b/coriolis/tasks/minion_pool_tasks.py @@ -764,7 +764,7 @@ def _get_provider_pool_validation_operation(cls, provider): @classmethod def _get_minion_task_info_field_mappings(cls): - return OSMOPRHING_MINION_TASK_INFO_FIELD_MAPPINGS + return OSMOPRHING_MINION_TASK_INFO_FIELD_MAPPINGS class _BaseReleaseMinionTask(base.TaskRunner): diff --git a/coriolis/tests/conductor/rpc/test_server.py b/coriolis/tests/conductor/rpc/test_server.py index ca66cfe67..ef115facc 100644 --- a/coriolis/tests/conductor/rpc/test_server.py +++ b/coriolis/tests/conductor/rpc/test_server.py @@ -368,7 +368,7 @@ def test_get_endpoint_destination_options( mock_get_endpoint.return_value.connection_info, mock.sentinel.environment, mock.sentinel.option_names, - ) + ) self.assertEqual( options, @@ -521,7 +521,7 @@ def test_validate_endpoint_target_environment( mock.sentinel.context, mock_get_endpoint.return_value.type, mock.sentinel.target_env, - ) + ) @mock.patch.object( server.ConductorServerEndpoint, "_get_worker_service_rpc_for_specs" @@ -556,7 +556,7 @@ def test_validate_endpoint_source_environment( mock.sentinel.context, mock_get_endpoint.return_value.type, mock.sentinel.source_env, - ) + ) @mock.patch.object( rpc_worker_client.WorkerClient, "from_service_definition" @@ -572,7 +572,7 @@ def test_get_available_providers( mock_service_definition.return_value\ .get_available_providers.assert_called_once_with( mock.sentinel.context - ) + ) self.assertEqual( providers, mock_service_definition @@ -599,7 +599,7 @@ def test_get_provider_schemas( mock.sentinel.context, mock.sentinel.platform_name, mock.sentinel.provider_type, - ) + ) self.assertEqual( provider_schemas, mock_service_definition.return_value @@ -694,7 +694,7 @@ def test_get_worker_service_rpc_for_task( retry_count=5, retry_period=2, random_choice=True, - ) + ) mock_service_definition.assert_called_once_with( mock_scheduler_client.get_worker_service_for_task.return_value ) @@ -2466,8 +2466,8 @@ def call_advance_execution_state( task_info = { mock.sentinel.instance: { 'test': 'info', - }, - } + }, + } mock_get_action.return_value = mock.Mock( info=task_info ) diff --git a/coriolis/tests/test_schemas.py b/coriolis/tests/test_schemas.py index 9d19d6578..637d35b7c 100644 --- a/coriolis/tests/test_schemas.py +++ b/coriolis/tests/test_schemas.py @@ -73,7 +73,8 @@ def test_validate_value(self, mock_validate): schemas.validate_value(test_value, test_schema) - mock_validate.assert_called_once_with(test_value, test_schema, format_checker=None) + mock_validate.assert_called_once_with( + test_value, test_schema, format_checker=None) @mock.patch.object(json, 'loads') @mock.patch.object(jsonschema, 'validate') @@ -87,4 +88,5 @@ def test_validate_string(self, mock_validate, mock_loads): schemas.validate_string(test_string, test_schema) mock_loads.assert_called_once_with(test_string) - mock_validate.assert_called_once_with(test_value, test_schema, format_checker=None) + mock_validate.assert_called_once_with( + test_value, test_schema, format_checker=None) diff --git a/coriolis/tests/worker/rpc/test_server.py b/coriolis/tests/worker/rpc/test_server.py index fbf2520aa..6b5908bc6 100644 --- a/coriolis/tests/worker/rpc/test_server.py +++ b/coriolis/tests/worker/rpc/test_server.py @@ -433,7 +433,7 @@ def call_get_endpoint_destination_options(): mock_get_secret.return_value, env=mock.sentinel.environment, option_names=mock.sentinel.option_names, - ) + ) mock_validate.assert_called_once_with( mock_get_provider.return_value .get_target_environment_options.return_value, @@ -484,7 +484,7 @@ def call_get_endpoint_source_minion_pool_options(): mock_get_secret.return_value, env=mock.sentinel.environment, option_names=mock.sentinel.option_names, - ) + ) mock_validate.assert_called_once_with( mock_get_provider.return_value .get_minion_pool_options.return_value, @@ -536,7 +536,7 @@ def call_get_endpoint_destination_minion_pool_options(): mock_get_secret.return_value, env=mock.sentinel.environment, option_names=mock.sentinel.option_names, - ) + ) mock_validate.assert_called_once_with( mock_get_provider.return_value .get_minion_pool_options.return_value, @@ -588,7 +588,7 @@ def call_get_endpoint_source_options(): mock_get_secret.return_value, env=mock.sentinel.environment, option_names=mock.sentinel.option_names, - ) + ) mock_validate.assert_called_once_with( mock_get_provider.return_value .get_source_environment_options.return_value, @@ -875,7 +875,7 @@ def call_validate_endpoint_connection(): mock_get_provider.return_value\ .validate_connection.assert_called_once_with( mock.sentinel.context, mock_get_secret.return_value - ) + ) self.assertEqual(result, (True, None))