Skip to content

Commit

Permalink
Showing 41 changed files with 100 additions and 221 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
@@ -350,7 +350,7 @@ test-tree-clean:
fi
find ${abs_top_builddir} -type d -name __pycache__ -exec rm -rf {} \; 2>/dev/null || :

check-local: check-local-deps test-tree-prep typos_check pylint isort_check black_check mypy tests_tier0 tests_tier1 pcsd-tests test-tree-clean
check-local: check-local-deps test-tree-prep typos_check pylint ruff_isort_check ruff_format_check mypy tests_tier0 tests_tier1 pcsd-tests test-tree-clean

clean-local: test-tree-clean
$(PYTHON) setup.py clean
2 changes: 1 addition & 1 deletion pcs/cli/common/tools.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@


def timeout_to_seconds_legacy(
timeout: Union[int, str]
timeout: Union[int, str],
) -> Union[int, str, None]:
"""
Transform pacemaker style timeout to number of seconds. If timeout is not
4 changes: 3 additions & 1 deletion pcs/cli/resource/output.py
Original file line number Diff line number Diff line change
@@ -286,7 +286,9 @@ def get_primitive_dto(
def get_group_dto(self, obj_id: str) -> Optional[CibResourceGroupDto]:
return self._groups_map.get(obj_id)

def _get_any_resource_dto(self, obj_id: str) -> Optional[
def _get_any_resource_dto(
self, obj_id: str
) -> Optional[
Union[
CibResourcePrimitiveDto,
CibResourceGroupDto,
10 changes: 3 additions & 7 deletions pcs/common/interface/dto.py
Original file line number Diff line number Diff line change
@@ -80,14 +80,12 @@ def _convert_dict(
value = [
# ignore _field.type may not have __args__
# this is prevented by _is_compatible_type
_convert_dict(_field.type.__args__[0], item) # type: ignore
_convert_dict(_field.type.__args__[0], item) # type: ignore[union-attr]
for item in value
]
elif isinstance(value, dict) and _is_compatible_type(_field.type, 1):
value = {
item_key: _convert_dict(
_field.type.__args__[1], item_val # type: ignore
)
item_key: _convert_dict(_field.type.__args__[1], item_val) # type: ignore[union-attr,arg-type]
for item_key, item_val in value.items()
}
elif isinstance(value, Enum):
@@ -124,9 +122,7 @@ def _convert_payload(klass: type[DTOTYPE], data: DtoPayload) -> DtoPayload:
]
elif isinstance(value, dict) and _is_compatible_type(_field.type, 1):
value = {
item_key: _convert_payload(
_field.type.__args__[1], item_val # type: ignore
)
item_key: _convert_payload(_field.type.__args__[1], item_val) # type: ignore[union-attr,arg-type]
for item_key, item_val in value.items()
}
del new_dict[new_name]
4 changes: 2 additions & 2 deletions pcs/common/pacemaker/constraint/all.py
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ def _get_constraint_ids(
CibConstraintTicketDto,
CibConstraintTicketSetDto,
]
]
],
) -> list[str]:
return [
constraint_dto.attributes.constraint_id
@@ -64,7 +64,7 @@ def _get_location_rule_ids(
CibConstraintLocationDto,
CibConstraintLocationSetDto,
]
]
],
) -> list[str]:
return [
rule_dto.id
8 changes: 2 additions & 6 deletions pcs/common/reports/messages.py
Original file line number Diff line number Diff line change
@@ -1611,9 +1611,7 @@ class ParseErrorCorosyncConfMissingSectionNameBeforeOpeningBrace(
Corosync config cannot be parsed due to a section name missing before {
"""

_code = (
codes.PARSE_ERROR_COROSYNC_CONF_MISSING_SECTION_NAME_BEFORE_OPENING_BRACE
)
_code = codes.PARSE_ERROR_COROSYNC_CONF_MISSING_SECTION_NAME_BEFORE_OPENING_BRACE

@property
def message(self) -> str:
@@ -1643,9 +1641,7 @@ class ParseErrorCorosyncConfExtraCharactersBeforeOrAfterClosingBrace(
Corosync config cannot be parsed due to extra characters before or after }
"""

_code = (
codes.PARSE_ERROR_COROSYNC_CONF_EXTRA_CHARACTERS_BEFORE_OR_AFTER_CLOSING_BRACE
)
_code = codes.PARSE_ERROR_COROSYNC_CONF_EXTRA_CHARACTERS_BEFORE_OR_AFTER_CLOSING_BRACE

@property
def message(self) -> str:
2 changes: 1 addition & 1 deletion pcs/common/resource_status.py
Original file line number Diff line number Diff line change
@@ -1088,7 +1088,7 @@ def _is_orphaned(resource: Union[PrimitiveStatusDto, GroupStatusDto]) -> bool:


def _filter_clone_orphans(
instance_list: Sequence[Union[PrimitiveStatusDto, GroupStatusDto]]
instance_list: Sequence[Union[PrimitiveStatusDto, GroupStatusDto]],
) -> list[Union[PrimitiveStatusDto, GroupStatusDto]]:
return [
instance for instance in instance_list if not _is_orphaned(instance)
4 changes: 2 additions & 2 deletions pcs/common/str_tools.py
Original file line number Diff line number Diff line change
@@ -99,7 +99,7 @@ def format_name_value_list(item_list: Sequence[tuple[str, str]]) -> list[str]:
# For now, tuple[str, str, str] is sufficient. Feel free to change it if
# needed, e.g. when values can be integers.
def format_name_value_id_list(
item_list: Sequence[tuple[str, str, str]]
item_list: Sequence[tuple[str, str, str]],
) -> list[str]:
"""
Turn 3-tuples to 'name=value (id: id))' strings with standard quoting
@@ -119,7 +119,7 @@ def pairs_to_text(pairs: Sequence[tuple[str, str]]) -> list[str]:


def format_name_value_default_list(
item_list: Sequence[tuple[str, str, bool]]
item_list: Sequence[tuple[str, str, bool]],
) -> list[str]:
"""
Turn 3-tuples to 'name=value' or 'name=value (default)' strings with
3 changes: 1 addition & 2 deletions pcs/lib/cib/constraint/ticket.py
Original file line number Diff line number Diff line change
@@ -154,8 +154,7 @@ def prepare_options_plain(
validate.NamesIn(
# rsc and rsc-ticket are passed as parameters not as items in the
# options dict
(set(ATTRIB) | set(ATTRIB_PLAIN) | {"id"})
- {"rsc", "ticket"}
(set(ATTRIB) | set(ATTRIB_PLAIN) | {"id"}) - {"rsc", "ticket"}
).validate(options)
)

4 changes: 1 addition & 3 deletions pcs/lib/cib/resource/remote_node.py
Original file line number Diff line number Diff line change
@@ -25,9 +25,7 @@

_IS_REMOTE_AGENT_XPATH_SNIPPET = """
@class="{0}" and @provider="{1}" and @type="{2}"
""".format(
AGENT_NAME.standard, AGENT_NAME.provider, AGENT_NAME.type
)
""".format(AGENT_NAME.standard, AGENT_NAME.provider, AGENT_NAME.type)

_HAS_SERVER_XPATH_SNIPPET = """
instance_attributes/nvpair[
4 changes: 1 addition & 3 deletions pcs/lib/cib/resource/stonith.py
Original file line number Diff line number Diff line change
@@ -244,9 +244,7 @@ def _get_lrm_rsc_op_elements(
./status/node_state[@uname=$node_name]
/lrm/lrm_resources/lrm_resource[@id=$resource_id]
/lrm_rsc_op[@operation=$op_name{interval}]
""".format(
interval=" and @interval=$interval" if interval else ""
),
""".format(interval=" and @interval=$interval" if interval else ""),
node_name=node_name,
resource_id=resource_id,
op_name=op_name,
4 changes: 2 additions & 2 deletions pcs/lib/commands/resource.py
Original file line number Diff line number Diff line change
@@ -2041,7 +2041,7 @@ def ban(env, resource_id, node=None, master=False, lifetime=None, wait=False):


def _resource_running_on_nodes(
resource_state: Dict[str, List[str]]
resource_state: Dict[str, List[str]],
) -> FrozenSet[str]:
if resource_state:
return frozenset(
@@ -2473,7 +2473,7 @@ def _find_resources_expand_tags(


def get_required_cib_version_for_primitive(
op_list: Iterable[Mapping[str, str]]
op_list: Iterable[Mapping[str, str]],
) -> Optional[Version]:
for op in op_list:
if op.get("on-fail", "") == "demote":
6 changes: 2 additions & 4 deletions pcs/lib/corosync/config_validators.py
Original file line number Diff line number Diff line change
@@ -912,9 +912,7 @@ def _update_link_options_knet(
)
).validate(new_options) + validate.ValidatorAll(
_get_link_options_validators_knet_relations()
).validate(
after_update
)
).validate(after_update)


def add_link(
@@ -2039,7 +2037,7 @@ def _get_qdevice_generic_options_validators(


def _split_heuristics_exec_options(
options: Mapping[str, str]
options: Mapping[str, str],
) -> tuple[dict[str, str], dict[str, str]]:
options_exec = {}
options_nonexec = {}
4 changes: 1 addition & 3 deletions pcs/lib/pacemaker/state.py
Original file line number Diff line number Diff line change
@@ -266,9 +266,7 @@ def is_resource_managed(cluster_state, resource_id):
.//resource[{predicate_id}]
|
.//group[{predicate_id}]/resource
""".format(
predicate_id=_id_xpath_predicate
),
""".format(predicate_id=_id_xpath_predicate),
id=resource_id,
)
if primitive_list:
2 changes: 1 addition & 1 deletion pcs/lib/resource_agent/ocf_transform.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@


def ocf_version_to_ocf_unified(
metadata: Union[ResourceAgentMetadataOcf1_0, ResourceAgentMetadataOcf1_1]
metadata: Union[ResourceAgentMetadataOcf1_0, ResourceAgentMetadataOcf1_1],
) -> ResourceAgentMetadata:
"""
Transform specific version OCF metadata to a universal format
4 changes: 2 additions & 2 deletions pcs/lib/validate.py
Original file line number Diff line number Diff line change
@@ -122,7 +122,7 @@ def values_to_pairs(


def pairs_to_values(
option_dict: Mapping[TypeOptionName, Union[TypeOptionValue, ValuePair]]
option_dict: Mapping[TypeOptionName, Union[TypeOptionValue, ValuePair]],
) -> TypeOptionRawMap:
"""
Take a dict which has OptionValuePairs as its values and return dict with
@@ -142,7 +142,7 @@ def pairs_to_values(
def option_value_normalization(
normalization_map: Mapping[
TypeOptionName, Callable[[TypeOptionValue], TypeOptionValue]
]
],
) -> TypeNormalizeFunc:
"""
Return function that takes key and value and return the normalized form.
2 changes: 1 addition & 1 deletion pcs_test/suite.py
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ def prepare_test_name(test_name):


def tests_from_suite(
test_candidate: Union[unittest.TestCase, unittest.TestSuite]
test_candidate: Union[unittest.TestCase, unittest.TestSuite],
) -> list[str]:
if isinstance(test_candidate, unittest.TestCase):
return [test_candidate.id()]
4 changes: 1 addition & 3 deletions pcs_test/tier0/cli/cluster_property/test_command.py
Original file line number Diff line number Diff line change
@@ -582,9 +582,7 @@ def setUp(self):
self.cluster_property = mock.MagicMock(
spec_set=["get_cluster_properties_definition_legacy"]
)
self.cluster_property.get_cluster_properties_definition_legacy.return_value = (
{}
)
self.cluster_property.get_cluster_properties_definition_legacy.return_value = {}
self.lib.cluster_property = self.cluster_property

def _call_cmd(self, argv, modifiers=None):
8 changes: 2 additions & 6 deletions pcs_test/tier0/common/test_tools_xml_fromstring.py
Original file line number Diff line number Diff line change
@@ -42,9 +42,7 @@ def test_large_xml(self):
/>
</storage>
</bundle>
""".format(
i
)
""".format(i)
for i in range(20000)
]
),
@@ -94,9 +92,7 @@ def test_large_xml(self):
op-digest="3b2ba04195253e454b50aa4a340af042"
/>
</lrm_resource>
""".format(
"{0}-{1}".format(i, j)
)
""".format("{0}-{1}".format(i, j))
for j in range(98)
]
),
8 changes: 3 additions & 5 deletions pcs_test/tier0/daemon/async_tasks/helpers.py
Original file line number Diff line number Diff line change
@@ -82,11 +82,9 @@ def prepare_scheduler(self):
self.logging_queue,
# mp.Queue(),
]
self.mp_pool_mock = (
mock.patch("multiprocessing.Pool", spec=mp.Pool)
.start()
.return_value
) = mock.Mock()
self.mp_pool_mock = mock.patch(
"multiprocessing.Pool", spec=mp.Pool
).start().return_value = mock.Mock()
# This might be needed when logger is called by get_logger, but is it?
self.scheduler = scheduler.Scheduler(
scheduler.SchedulerConfig(
16 changes: 4 additions & 12 deletions pcs_test/tier0/lib/auth/test_provider.py
Original file line number Diff line number Diff line change
@@ -118,9 +118,7 @@ def test_empty_file(self):
data = b""
new_data = b"new data"
io_buffer = BytesIO(data)
self.file_instance_mock.raw_file.update.return_value.__enter__.return_value = (
io_buffer
)
self.file_instance_mock.raw_file.update.return_value.__enter__.return_value = io_buffer
self.file_instance_mock.facade_to_raw.return_value = new_data
with self.provider._update_facade() as empty_facade:
self.assertEqual(tuple(), empty_facade.config)
@@ -152,9 +150,7 @@ def test_write_error(self):
_FILE_METADATA, RawFileError.ACTION_UPDATE, reason
)
io_buffer = BytesIO(data)
self.file_instance_mock.raw_file.update.return_value.__enter__.return_value = (
io_buffer
)
self.file_instance_mock.raw_file.update.return_value.__enter__.return_value = io_buffer
self.file_instance_mock.raw_to_facade.return_value = mock_facade
self.file_instance_mock.facade_to_raw.return_value = new_data
with self.assertRaises(_UpdateFacadeError):
@@ -172,9 +168,7 @@ def test_parsing_error(self):
data = b"original data"
new_data = b"new data"
io_buffer = BytesIO(data)
self.file_instance_mock.raw_file.update.return_value.__enter__.return_value = (
io_buffer
)
self.file_instance_mock.raw_file.update.return_value.__enter__.return_value = io_buffer
self.file_instance_mock.raw_to_facade.side_effect = (
ParserErrorException()
)
@@ -195,9 +189,7 @@ def test_success(self):
new_data = b"new data"
mock_facade = "facade"
io_buffer = BytesIO(data)
self.file_instance_mock.raw_file.update.return_value.__enter__.return_value = (
io_buffer
)
self.file_instance_mock.raw_file.update.return_value.__enter__.return_value = io_buffer
self.file_instance_mock.raw_to_facade.return_value = mock_facade
self.file_instance_mock.facade_to_raw.return_value = new_data
with self.provider._update_facade() as facade:
12 changes: 3 additions & 9 deletions pcs_test/tier0/lib/booth/test_resource.py
Original file line number Diff line number Diff line change
@@ -18,9 +18,7 @@ def fixture_resources_with_booth(booth_config_file_path):
</instance_attributes>
</primitive>
</resources>
""".format(
booth_config_file_path
)
""".format(booth_config_file_path)
)


@@ -32,9 +30,7 @@ def fixture_booth_element(_id, booth_config_file_path):
<nvpair name="config" value="{1}"/>
</instance_attributes>
</primitive>
""".format(
_id, booth_config_file_path
)
""".format(_id, booth_config_file_path)
)


@@ -50,9 +46,7 @@ def fixture_ip_element(_id, ip=""):
/>
</instance_attributes>
</primitive>
""".format(
_id, ip
)
""".format(_id, ip)
)


4 changes: 1 addition & 3 deletions pcs_test/tier0/lib/cib/resource/test_validations.py
Original file line number Diff line number Diff line change
@@ -772,6 +772,4 @@ def test_bundle_resource(self):

class ValidateUnmoveUnban(ValidateMoveBanClearMixin, TestCase):
validate = staticmethod(validations.validate_unmove_unban)
report_code_bad_master = (
reports.codes.CANNOT_UNMOVE_UNBAN_RESOURCE_MASTER_RESOURCE_NOT_PROMOTABLE
)
report_code_bad_master = reports.codes.CANNOT_UNMOVE_UNBAN_RESOURCE_MASTER_RESOURCE_NOT_PROMOTABLE
Loading

0 comments on commit 38d64f2

Please sign in to comment.