Skip to content

Commit

Permalink
pep8: fixed parts of rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
ader1990 committed Oct 6, 2023
1 parent 86f83d9 commit ad8222d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 25 deletions.
40 changes: 24 additions & 16 deletions coriolis/minion_manager/rpc/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ class ReportMinionAllocationFailureForMigrationTask(
_BaseReportMinionAllocationFailureForActionTask):

def _get_task_name(self, action_id):
return MINION_POOL_REPORT_MIGRATION_ALLOCATION_FAILURE_TASK_NAME_FORMAT % (
action_id)
return (
MINION_POOL_REPORT_MIGRATION_ALLOCATION_FAILURE_TASK_NAME_FORMAT
% (action_id))

def _report_machine_allocation_failure(
self, context, action_id, failure_str):
Expand All @@ -198,8 +199,9 @@ class ReportMinionAllocationFailureForReplicaTask(
_BaseReportMinionAllocationFailureForActionTask):

def _get_task_name(self, action_id):
return MINION_POOL_REPORT_REPLICA_ALLOCATION_FAILURE_TASK_NAME_FORMAT % (
action_id)
return (
MINION_POOL_REPORT_REPLICA_ALLOCATION_FAILURE_TASK_NAME_FORMAT
% (action_id))

def _report_machine_allocation_failure(
self, context, action_id, failure_str):
Expand Down Expand Up @@ -402,8 +404,9 @@ def _get_action_label(self):
return "migration"

def _get_task_name(self, action_id):
return MINION_POOL_CONFIRM_MIGRATION_MINION_ALLOCATION_TASK_NAME_FORMAT % (
action_id)
return (
MINION_POOL_CONFIRM_MIGRATION_MINION_ALLOCATION_TASK_NAME_FORMAT
% (action_id))

def _confirm_machine_allocation_for_action(
self, context, action_id, machine_allocations):
Expand All @@ -418,8 +421,9 @@ def _get_action_label(self):
return "replica"

def _get_task_name(self, action_id):
return MINION_POOL_CONFIRM_REPLICA_MINION_ALLOCATION_TASK_NAME_FORMAT % (
action_id)
return (
MINION_POOL_CONFIRM_REPLICA_MINION_ALLOCATION_TASK_NAME_FORMAT
% (action_id))

def _confirm_machine_allocation_for_action(
self, context, action_id, machine_allocations):
Expand Down Expand Up @@ -624,7 +628,7 @@ def __init__(
resource_deployment_task_type = (
constants.TASK_TYPE_SET_UP_DESTINATION_POOL_SHARED_RESOURCES)
resource_cleanup_task_type = (
constants.TASK_TYPE_TEAR_DOWN_DESTINATION_POOL_SHARED_RESOURCES)
constants.TASK_TYPE_TEAR_DOWN_DESTINATION_POOL_SHARED_RESOURCES) # noqa: E501
super(AllocateSharedPoolResourcesTask, self).__init__(
minion_pool_id, minion_machine_id, resource_deployment_task_type,
cleanup_task_runner_type=resource_cleanup_task_type, **kwargs)
Expand Down Expand Up @@ -699,7 +703,7 @@ def __init__(
constants.TASK_TYPE_TEAR_DOWN_SOURCE_POOL_SHARED_RESOURCES)
if minion_pool_type != constants.PROVIDER_PLATFORM_SOURCE:
resource_deallocation_task = (
constants.TASK_TYPE_TEAR_DOWN_DESTINATION_POOL_SHARED_RESOURCES)
constants.TASK_TYPE_TEAR_DOWN_DESTINATION_POOL_SHARED_RESOURCES) # noqa: E501
super(DeallocateSharedPoolResourcesTask, self).__init__(
minion_pool_id, minion_machine_id, resource_deallocation_task,
**kwargs)
Expand Down Expand Up @@ -770,7 +774,8 @@ def execute(self, context, origin, destination, task_info):
"Minion machine entry with ID '%s' already exists within "
"the DB and it is in '%s' status instead of the expected "
"'%s' status. Existing machine's properties are: %s" % (
self._minion_machine_id, minion_machine.allocation_status,
self._minion_machine_id,
minion_machine.allocation_status,
constants.MINION_MACHINE_STATUS_UNINITIALIZED,
minion_machine.to_dict()))
if minion_machine.pool_id != self._minion_pool_id:
Expand Down Expand Up @@ -962,8 +967,9 @@ def revert(self, context, origin, destination, task_info, **kwargs):
context, origin, destination, cleanup_info, **kwargs)
except Exception:
log_msg = (
"[Task '%s'] Exception occurred while attempting to revert "
"deployment of minion machine with ID '%s' for pool '%s'." % (
"[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))
if not self._raise_on_cleanup_failure:
Expand Down Expand Up @@ -1063,7 +1069,7 @@ class HealthcheckMinionMachineTask(BaseMinionManangerTask):
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,
machine_status_on_success=constants.MINION_MACHINE_STATUS_AVAILABLE, # noqa: E501
**kwargs):
self._fail_on_error = fail_on_error
self._machine_status_on_success = machine_status_on_success
Expand Down Expand Up @@ -1232,15 +1238,17 @@ def execute(self, context, origin, destination, task_info):
machine = self._get_minion_machine(
context, self._minion_machine_id, raise_if_not_found=True)

if machine.power_status == constants.MINION_MACHINE_POWER_STATUS_POWERED_ON:
if (machine.power_status ==
constants.MINION_MACHINE_POWER_STATUS_POWERED_ON):
LOG.debug(
"[Task '%s'] Minion machine with ID '%s' from pool '%s' is "
"already marked as powered on. Returning early." % (
self._task_name, self._minion_machine_id,
self._minion_pool_id))
return task_info

if machine.power_status != constants.MINION_MACHINE_POWER_STATUS_POWERED_OFF:
if (machine.power_status !=
constants.MINION_MACHINE_POWER_STATUS_POWERED_OFF):
raise exception.InvalidMinionMachineState(
"Minion machine with ID '%s' from pool '%s' is in '%s' state "
"instead of the expected '%s' required for it to be powered "
Expand Down
19 changes: 10 additions & 9 deletions coriolis/tests/conductor/rpc/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@

from unittest import mock

from coriolis import constants, exception, schemas, utils
from coriolis.conductor.rpc import server
from coriolis import constants
from coriolis.db import api as db_api
from coriolis.db.sqlalchemy import models
from coriolis import exception
from coriolis.licensing import client as licensing_client
from coriolis.tests import test_base, testutils
from coriolis import schemas
from coriolis.tests import test_base
from coriolis.tests import testutils
from coriolis import utils
from coriolis.worker.rpc import client as rpc_worker_client
from oslo_concurrency import lockutils
from oslo_config import cfg
Expand Down Expand Up @@ -2104,8 +2108,7 @@ def call_set_task_host():
# task status is not in accepted state
with self.assertRaisesRegex(
exception.InvalidTaskState,
"expected statuses",
):
"expected statuses"):
call_set_task_host()

mock_get_task.assert_called_once_with(
Expand Down Expand Up @@ -2133,8 +2136,7 @@ def call_set_task_host():
)
with self.assertRaisesRegex(
exception.InvalidTaskState,
"has no host",
):
"has no host"):
call_set_task_host()

@mock.patch.object(
Expand Down Expand Up @@ -2551,8 +2553,7 @@ def test_advance_execution_state_scheduled_tasks(
mock_cancel_tasks_execution, # pylint: disable=unused-argument
mock_get_execution_status, # pylint: disable=unused-argument
mock_set_tasks_execution_status, # pylint: disable=unused-argument
config,
):
config):
tasks = config.get('tasks', [])
execution = mock.Mock(
status=constants.EXECUTION_STATUS_RUNNING,
Expand All @@ -2575,7 +2576,7 @@ def test_advance_execution_state_scheduled_tasks(
)

for task in tasks:
if not 'expected_status' in task:
if 'expected_status' not in task:
continue
kwargs = {'exception_details': mock.ANY}
if task['expected_status'] == constants.TASK_STATUS_PENDING:
Expand Down

0 comments on commit ad8222d

Please sign in to comment.