diff --git a/cou/apps/base.py b/cou/apps/base.py index e8fea10b..d7080003 100644 --- a/cou/apps/base.py +++ b/cou/apps/base.py @@ -116,7 +116,7 @@ def __str__(self) -> str: "name": unit.name, "machine": unit.machine.machine_id, "workload_version": unit.workload_version, - "os_version": str(self.unit_max_os_version(unit)), + "os_version": str(self.get_latest_os_version(unit)), } for unit in self.units.values() }, @@ -191,7 +191,7 @@ def is_valid_track(self, charm_channel: str) -> bool: except ValueError: return self.is_from_charm_store - def unit_max_os_version(self, unit: COUUnit) -> OpenStackRelease: + def get_latest_os_version(self, unit: COUUnit) -> OpenStackRelease: """Get the latest compatible OpenStack release based on the unit workload version. :param unit: Application Unit @@ -251,7 +251,7 @@ def os_release_units(self) -> dict[OpenStackRelease, list[str]]: """ os_versions = defaultdict(list) for unit in self.units.values(): - os_version = self.unit_max_os_version(unit) + os_version = self.get_latest_os_version(unit) os_versions[os_version].append(unit.name) return dict(os_versions) diff --git a/cou/apps/channel_based.py b/cou/apps/channel_based.py index 4d24e80e..364e0508 100644 --- a/cou/apps/channel_based.py +++ b/cou/apps/channel_based.py @@ -28,7 +28,7 @@ class ChannelBasedApplication(OpenStackApplication): """Application for charms that are channel based.""" - def unit_max_os_version(self, unit: COUUnit) -> OpenStackRelease: + def get_latest_os_version(self, unit: COUUnit) -> OpenStackRelease: """Get the latest compatible OpenStack release based on the channel. :param unit: COUUnit diff --git a/cou/steps/hypervisor.py b/cou/steps/hypervisor.py index a43a40c2..077e16c4 100644 --- a/cou/steps/hypervisor.py +++ b/cou/steps/hypervisor.py @@ -126,24 +126,25 @@ def machines(self) -> list[COUMachine]: """ return self._machines - def azs(self, target: OpenStackRelease) -> AZs: + def get_azs(self, target: OpenStackRelease) -> AZs: """Return a list of AZs defined in individual applications. - Each AZ contains a dictionary of application name and all units in the AZ. + Each AZ contains a dictionary of application name and all units not yet upgraded + in the AZ for a certain target. eg. az1: - cinder: - - cinder/0 - - cinder/1 - - cinder/2 + - cinder/0 + - cinder/1 + - cinder/2 - nova-compute - - nova-compute/0 - - nova-compute/1 - - nova-compute/2 + - nova-compute/0 + - nova-compute/1 + - nova-compute/2 ... az2 - cinder - -cinder/3 + -cinder/3 ... ... @@ -156,14 +157,12 @@ def azs(self, target: OpenStackRelease) -> AZs: for app in self.apps: for unit in app.units.values(): if unit.machine not in self.machines: - logger.debug("skipping machine %s", unit.machine.machine_id) + logger.info("skipping machine %s", unit.machine.machine_id) continue - unit_os_release = app.unit_max_os_version(unit) + unit_os_release = app.get_latest_os_version(unit) if unit_os_release >= target: - logger.debug( - "skipping unit %s is already on %s", unit.name, str(unit_os_release) - ) + logger.debug("skipping unit %s is already on %s", unit.name, unit_os_release) continue # NOTE(rgildein): If there is no AZ, we will use empty string and all units will @@ -279,7 +278,7 @@ def generate_upgrade_plan(self, target: OpenStackRelease, force: bool) -> Upgrad :rtype: UpgradePlan """ plan = UpgradePlan("Upgrading all applications deployed on machines with hypervisor.") - for az, group in self.azs(target).items(): + for az, group in self.get_azs(target).items(): hypervisor_plan = HypervisorUpgradePlan(f"Upgrade plan for '{group.name}' to {target}") # pre upgrade steps diff --git a/tests/unit/apps/test_auxiliary.py b/tests/unit/apps/test_auxiliary.py index a7e648b3..bf5953e3 100644 --- a/tests/unit/apps/test_auxiliary.py +++ b/tests/unit/apps/test_auxiliary.py @@ -416,7 +416,7 @@ def test_auxiliary_app_unknown_version_raise_ApplicationError(model): workload_version=version, ) with pytest.raises(ApplicationError, match=exp_msg): - app.unit_max_os_version(app.units[f"{charm}/0"]) + app.get_latest_os_version(app.units[f"{charm}/0"]) def test_auxiliary_raise_error_unknown_series(model): @@ -589,7 +589,7 @@ def test_ceph_mon_app(model): assert app.channel == "pacific/stable" assert app.os_origin == "cloud:focal-xena" - assert app.unit_max_os_version(app.units[f"{charm}/0"]) == OpenStackRelease("xena") + assert app.get_latest_os_version(app.units[f"{charm}/0"]) == OpenStackRelease("xena") assert app.apt_source_codename == "xena" assert app.channel_codename == "xena" assert app.is_subordinate is False diff --git a/tests/unit/apps/test_base.py b/tests/unit/apps/test_base.py index 44f0be30..fddb3a5f 100644 --- a/tests/unit/apps/test_base.py +++ b/tests/unit/apps/test_base.py @@ -54,7 +54,7 @@ def test_openstack_application_magic_functions(model): @patch("cou.apps.base.OpenStackApplication._verify_channel", return_value=None) @patch("cou.utils.openstack.OpenStackCodenameLookup.find_compatible_versions") -def test_applicationunit_max_os_version_failed(mock_find_compatible_versions, model): +def test_applicationget_latest_os_version_failed(mock_find_compatible_versions, model): charm = "app" app_name = "my_app" unit = COUUnit( @@ -83,7 +83,7 @@ def test_applicationunit_max_os_version_failed(mock_find_compatible_versions, mo ) with pytest.raises(ApplicationError, match=exp_error): - app.unit_max_os_version(unit) + app.get_latest_os_version(unit) mock_find_compatible_versions.assert_called_once_with(charm, unit.workload_version) diff --git a/tests/unit/apps/test_channel_based.py b/tests/unit/apps/test_channel_based.py index 8d7e23b7..cc16833c 100644 --- a/tests/unit/apps/test_channel_based.py +++ b/tests/unit/apps/test_channel_based.py @@ -57,7 +57,7 @@ def test_application_versionless(model): assert app.current_os_release == "ussuri" assert app.is_versionless is True - assert app.unit_max_os_version(units["glance-simplestreams-sync/0"]) == app.channel_codename + assert app.get_latest_os_version(units["glance-simplestreams-sync/0"]) == app.channel_codename def test_application_gnocchi_ussuri(model): diff --git a/tests/unit/steps/test_hypervisor.py b/tests/unit/steps/test_hypervisor.py index d15f245e..45a64d02 100644 --- a/tests/unit/steps/test_hypervisor.py +++ b/tests/unit/steps/test_hypervisor.py @@ -143,12 +143,12 @@ def test_hypervisor_azs_grouping(): app1 = MagicMock(spec_set=COUApplication)() app1.name = "app1" app1.units = {name: unit for name, unit in units.items() if name.startswith("app1")} - app1.unit_max_os_version.return_value = OpenStackRelease("ussuri") + app1.get_latest_os_version.return_value = OpenStackRelease("ussuri") app2 = MagicMock(spec_set=COUApplication)() app2.name = "app2" app2.units = {name: unit for name, unit in units.items() if name.startswith("app2")} - app2.unit_max_os_version.return_value = OpenStackRelease("ussuri") + app2.get_latest_os_version.return_value = OpenStackRelease("ussuri") # passing all machines to the HypervisorUpgradePlanner exp_azs_all = AZs() @@ -161,7 +161,7 @@ def test_hypervisor_azs_grouping(): hypervisor_planner_all = HypervisorUpgradePlanner([app1, app2], list(machines.values())) - assert dict(hypervisor_planner_all.azs(target)) == exp_azs_all + assert dict(hypervisor_planner_all.get_azs(target)) == exp_azs_all # passing machine 0 to the HypervisorUpgradePlanner exp_azs_0 = AZs() @@ -169,14 +169,14 @@ def test_hypervisor_azs_grouping(): exp_azs_0["az0"].app_units["app2"] = [units["app2/0"]] hypervisor_planner_machine_0 = HypervisorUpgradePlanner([app1, app2], [machines["0"]]) - assert dict(hypervisor_planner_machine_0.azs(target)) == exp_azs_0 + assert dict(hypervisor_planner_machine_0.get_azs(target)) == exp_azs_0 # passing machine 1 to the HypervisorUpgradePlanner exp_azs_1 = AZs() exp_azs_1["az0"].app_units["app1"] = [units["app1/1"]] hypervisor_planner_machine_1 = HypervisorUpgradePlanner([app1, app2], [machines["1"]]) - assert dict(hypervisor_planner_machine_1.azs(target)) == exp_azs_1 + assert dict(hypervisor_planner_machine_1.get_azs(target)) == exp_azs_1 def test_hypervisor_azs_grouping_units_different_os_release(): @@ -241,7 +241,7 @@ def side_effect_app1(value): } return os_release[value.name] - app1.unit_max_os_version.side_effect = side_effect_app1 + app1.get_latest_os_version.side_effect = side_effect_app1 app2 = MagicMock(spec_set=COUApplication)() app2.name = "app2" @@ -255,7 +255,7 @@ def side_effect_app2(value): } return os_release[value.name] - app2.unit_max_os_version.side_effect = side_effect_app2 + app2.get_latest_os_version.side_effect = side_effect_app2 # passing all machines to the HypervisorUpgradePlanner exp_azs_all = AZs() @@ -266,19 +266,19 @@ def side_effect_app2(value): hypervisor_planner_all = HypervisorUpgradePlanner([app1, app2], list(machines.values())) - assert dict(hypervisor_planner_all.azs(target)) == exp_azs_all + assert dict(hypervisor_planner_all.get_azs(target)) == exp_azs_all # passing machine 0 to the HypervisorUpgradePlanner exp_azs_0 = AZs() hypervisor_planner_machine_0 = HypervisorUpgradePlanner([app1, app2], [machines["0"]]) - assert dict(hypervisor_planner_machine_0.azs(target)) == exp_azs_0 + assert dict(hypervisor_planner_machine_0.get_azs(target)) == exp_azs_0 # passing machine 1 to the HypervisorUpgradePlanner exp_azs_1 = AZs() hypervisor_planner_machine_1 = HypervisorUpgradePlanner([app1, app2], [machines["1"]]) - assert dict(hypervisor_planner_machine_1.azs(target)) == exp_azs_1 + assert dict(hypervisor_planner_machine_1.get_azs(target)) == exp_azs_1 def test_hypervisor_upgrade_plan(model): @@ -502,7 +502,7 @@ def test_hypervisor_upgrade_plan_some_units_upgraded(model): """Testing generating hypervisors upgrade plan partially upgraded.""" target = OpenStackRelease("victoria") exp_plan = dedent_plan( - """ + """\ Upgrading all applications deployed on machines with hypervisor. Upgrade plan for 'az-1' to victoria Upgrade software packages of 'cinder' from the current APT repositories