From 3f829920687a537a0453ca4773999794513a79b9 Mon Sep 17 00:00:00 2001 From: Dragomir Penev <6687393+dragomirp@users.noreply.github.com> Date: Mon, 1 Jul 2024 14:39:21 +0300 Subject: [PATCH] [MISC] Don't use planned units for single unit cluster upgrade (#179) * Don't use planned units for single unit cluster upgrade * Fix linting --- lib/charms/data_platform_libs/v0/upgrade.py | 4 ++-- pyproject.toml | 10 ++++++---- tox.ini | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/charms/data_platform_libs/v0/upgrade.py b/lib/charms/data_platform_libs/v0/upgrade.py index 18a58ff0..4d909d64 100644 --- a/lib/charms/data_platform_libs/v0/upgrade.py +++ b/lib/charms/data_platform_libs/v0/upgrade.py @@ -285,7 +285,7 @@ def restart(self, event) -> None: # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 17 +LIBPATCH = 18 PYDEPS = ["pydantic>=1.10,<2", "poetry-core"] @@ -921,7 +921,7 @@ def _on_upgrade_charm(self, event: UpgradeCharmEvent) -> None: self.charm.unit.status = WaitingStatus("other units upgrading first...") self.peer_relation.data[self.charm.unit].update({"state": "ready"}) - if self.charm.app.planned_units() == 1: + if len(self.app_units) == 1: # single unit upgrade, emit upgrade_granted event right away getattr(self.on, "upgrade_granted").emit() diff --git a/pyproject.toml b/pyproject.toml index 3b8f5b83..930fe8e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,6 +42,11 @@ copyright-regexp = "Copyright\\s\\d{4}([-,]\\d{4})*\\s+%(author)s" [tool.ruff] line-length = 99 +extend-exclude = ["__pycache__", "*.egg_info"] +target-version="py310" +src = ["src", "tests", "lib"] + +[tool.ruff.lint] select = ["E", "W", "F", "C", "N", "D", "I001"] extend-ignore = [ "D203", @@ -58,12 +63,9 @@ extend-ignore = [ "D413", ] ignore = ["E501", "D107"] -extend-exclude = ["__pycache__", "*.egg_info"] per-file-ignores = {"tests/*" = ["D100","D101","D102","D103","D104", "E999"]} -target-version="py310" -src = ["src", "tests", "lib"] -[tool.ruff.mccabe] +[tool.ruff.lint.mccabe] max-complexity = 12 [tool.pyright] diff --git a/tox.ini b/tox.ini index 6e433e49..d7ea6a03 100644 --- a/tox.ini +++ b/tox.ini @@ -31,7 +31,7 @@ deps = black ruff commands = - ruff --fix {[vars]all_path} + ruff check --fix {[vars]all_path} black {[vars]all_path} [testenv:lint] @@ -59,7 +59,7 @@ commands = --ignore-words-list "assertIn" codespell {[vars]lib_path} - ruff {[vars]all_path} + ruff check {[vars]all_path} black --check --diff {[vars]all_path} pyright