Merge ~cgrabowski/maas:handle_different_channel_check_for_missing_channel into maas:master

Proposed by Christian Grabowski
Status: Merged
Approved by: Christian Grabowski
Approved revision: e551d2bf200baa28510c7bd52c70fd98ecb097ba
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~cgrabowski/maas:handle_different_channel_check_for_missing_channel
Merge into: maas:master
Diff against target: 94 lines (+41/-10)
2 files modified
src/maasserver/models/controllerinfo.py (+19/-10)
src/maasserver/models/tests/test_controllerinfo.py (+22/-0)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
Alberto Donato (community) Approve
Review via email: mp+415919@code.launchpad.net

Commit message

build channel from version, like we do for target version, when update origin is missing

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b handle_different_channel_check_for_missing_channel lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: bec34b10b30f9ecb5059aa09521eb962e14d6bf9

review: Approve
Revision history for this message
Alberto Donato (ack) wrote :

We should probably add another entry to VERSION_ISSUES for this specific case where a controller has no update_origin (and don't report the DIFFERENT_CHANNEL one in that case).

While the current message is misleading, I think it's correct to report lack of an update origin as an issue as that means the controller will never get updates (which has security-related implications).

review: Needs Fixing
Revision history for this message
Christian Grabowski (cgrabowski) :
Revision history for this message
Christian Grabowski (cgrabowski) wrote :

> We should probably add another entry to VERSION_ISSUES for this specific case
> where a controller has no update_origin (and don't report the
> DIFFERENT_CHANNEL one in that case).
>
> While the current message is misleading, I think it's correct to report lack
> of an update origin as an issue as that means the controller will never get
> updates (which has security-related implications).

That makes sense. I was thinking with regards to the scenario in the bug report where you purposely download the snap into an air-gapped env, but I suppose we should still flag that as it won't get updates.

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b handle_different_channel_check_for_missing_channel lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/11903/console
COMMIT: 79e8a3992f42f1c5a725cfddbbf8dcf4a14c4042

review: Needs Fixing
Revision history for this message
Alberto Donato (ack) wrote :

Thanks for the changes, looks good!

One nitpick inline

review: Approve
Revision history for this message
Christian Grabowski (cgrabowski) :
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b handle_different_channel_check_for_missing_channel lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/11914/console
COMMIT: c48ef59394ae046e4d4f82b8edc3e88eecec45b9

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b handle_different_channel_check_for_missing_channel lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: e551d2bf200baa28510c7bd52c70fd98ecb097ba

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

LANDING
-b handle_different_channel_check_for_missing_channel lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED BUILD
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/11916/consoleText

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/models/controllerinfo.py b/src/maasserver/models/controllerinfo.py
2index 16906e1..6e5c55c 100644
3--- a/src/maasserver/models/controllerinfo.py
4+++ b/src/maasserver/models/controllerinfo.py
5@@ -48,6 +48,7 @@ class VERSION_ISSUES(Enum):
6
7 DIFFERENT_CHANNEL = "different-channel"
8 DIFFERENT_COHORT = "different-cohort"
9+ MISSING_CHANNEL = "missing-channel"
10
11
12 class ControllerInfoManager(Manager):
13@@ -163,10 +164,13 @@ class ControllerInfo(CleanSave, TimestampedModel):
14 """Return a list of version-related issues compared to the target version."""
15 issues = []
16 if self.install_type == CONTROLLER_INSTALL_TYPE.SNAP:
17- if (
18- SnapChannel.from_string(self.update_origin)
19- != target.snap_channel
20- ):
21+ if self.update_origin:
22+ snap_channel = SnapChannel.from_string(self.update_origin)
23+ else:
24+ snap_channel = None
25+ issues.append(VERSION_ISSUES.MISSING_CHANNEL.value)
26+
27+ if snap_channel and snap_channel != target.snap_channel:
28 issues.append(VERSION_ISSUES.DIFFERENT_CHANNEL.value)
29 if self.snap_cohort != target.snap_cohort:
30 issues.append(VERSION_ISSUES.DIFFERENT_COHORT.value)
31@@ -198,6 +202,16 @@ def get_maas_version() -> Optional[MAASVersion]:
32 return versions[0][1]
33
34
35+def channel_from_version(version) -> SnapChannel:
36+ """ channel from version constructs a SnapChannel from a MAAS version """
37+ risk_map = {"alpha": "edge", "beta": "beta", "rc": "candidate"}
38+ risk = risk_map.get(version.qualifier_type, "stable")
39+ return SnapChannel(
40+ track=f"{version.major}.{version.minor}",
41+ risk=risk,
42+ )
43+
44+
45 def get_target_version() -> Optional[TargetVersion]:
46 """Get the target version for the deployment."""
47 highest_version = None
48@@ -264,12 +278,7 @@ def get_target_version() -> Optional[TargetVersion]:
49 )
50 else:
51 # compose the channel from the target version
52- risk_map = {"alpha": "edge", "beta": "beta", "rc": "candidate"}
53- risk = risk_map.get(version.qualifier_type, "stable")
54- snap_channel = SnapChannel(
55- track=f"{version.major}.{version.minor}",
56- risk=risk,
57- )
58+ snap_channel = channel_from_version(version)
59
60 # report a cohort only if all controllers with the target version are on
61 # the same cohort (or have no cohort)
62diff --git a/src/maasserver/models/tests/test_controllerinfo.py b/src/maasserver/models/tests/test_controllerinfo.py
63index d736cf2..1e979c1 100644
64--- a/src/maasserver/models/tests/test_controllerinfo.py
65+++ b/src/maasserver/models/tests/test_controllerinfo.py
66@@ -393,6 +393,28 @@ class TestControllerInfo(MAASServerTestCase):
67 ],
68 )
69
70+ def test_get_version_issue_flags_missing_channel(self):
71+ target_version = TargetVersion(
72+ version=MAASVersion.from_string("3.1.0-222-g.cafecafe"),
73+ snap_channel=SnapChannel.from_string("3.1/stable"),
74+ )
75+ controller = factory.make_RegionRackController()
76+ ControllerInfo.objects.set_versions_info(
77+ controller,
78+ SnapVersionsInfo(
79+ current={
80+ "revision": "1234",
81+ "version": "3.1.0-222-g.cafecafe",
82+ },
83+ ),
84+ )
85+ self.assertEqual(
86+ controller.info.get_version_issues(target_version),
87+ [
88+ VERSION_ISSUES.MISSING_CHANNEL.value,
89+ ],
90+ )
91+
92
93 class TestGetTargetVersion(MAASServerTestCase):
94 def test_empty(self):

Subscribers

People subscribed via source and target branches