Merge ~newell-jensen/maas:lp1702690 into maas:master

Proposed by Newell Jensen
Status: Merged
Approved by: Newell Jensen
Approved revision: 2fff8e0cac941eecd3beec691edd1e3a0b6b67b6
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~newell-jensen/maas:lp1702690
Merge into: maas:master
Diff against target: 65 lines (+25/-9)
2 files modified
src/maasserver/models/node.py (+5/-6)
src/maasserver/models/tests/test_node.py (+20/-3)
Reviewer Review Type Date Requested Status
Mike Pontillo (community) Needs Information
Andres Rodriguez (community) Approve
Review via email: mp+327404@code.launchpad.net

Commit message

Set the machine's min_hwe_kernel to the setting's default_min_hwe_kernel when commissioning.

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

lgtm! But before you land, please add a new test (see inline)

review: Approve
Revision history for this message
Mike Pontillo (mpontillo) wrote :

Why do we have a min_hwe_kernel in the node model if we're just using the global config every time? Should it be removed, or is there another use case for it? Should we instead only set it to the global config during commissioning if the global configured minimum is greater than the current setting (if set)?

review: Needs Information
Revision history for this message
Andres Rodriguez (andreserl) wrote :

This is for commissioning only. Commissioning should always use whatever is the global setting. (this doesn't affect deployment).

For example, say we set the kernel in settings to ga-16.04. The machine boots fine, maas sets that min_hwe_kernel for the node, but the node fail because it cannot work on ga-16.04. So, we need hwe-16.04, and so we change it in the settings. As it stands today, when we try to commission again it will use 'ga-16.04' because that's the min, completely ignoring the fact that hwe-16.04 is set, hence always preventing the machine from booting because it will always try to boot ga-16.04.

That said, with the fix, it will always ensure we boot what's set on the global setting.

~newell-jensen/maas:lp1702690 updated
2fff8e0... by Newell Jensen

Add back unit test where node is in NEW state and the min_hwe_kernel is not set. Update new unit test to be in a READY state.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/models/node.py b/src/maasserver/models/node.py
2index 74028a2..0b92fb1 100644
3--- a/src/maasserver/models/node.py
4+++ b/src/maasserver/models/node.py
5@@ -1806,12 +1806,11 @@ class Node(CleanSave, TimestampedModel):
6 old_status = self.status
7 self.status = NODE_STATUS.COMMISSIONING
8 self.owner = user
9- # Set min_hwe_kernel to min_hwe_kernel if it isn't set incase
10- # commissioning failed and the user set the min globally and is
11- # retrying.
12- if not self.min_hwe_kernel:
13- self.min_hwe_kernel = Config.objects.get_config(
14- 'default_min_hwe_kernel')
15+ # Set min_hwe_kernel to default_min_hwe_kernel.
16+ # This makes sure that the min_hwe_kernel is up to date
17+ # with what is stored in the settings.
18+ self.min_hwe_kernel = Config.objects.get_config(
19+ 'default_min_hwe_kernel')
20 self.save()
21
22 try:
23diff --git a/src/maasserver/models/tests/test_node.py b/src/maasserver/models/tests/test_node.py
24index bbd7915..60d82db 100644
25--- a/src/maasserver/models/tests/test_node.py
26+++ b/src/maasserver/models/tests/test_node.py
27@@ -2465,7 +2465,7 @@ class TestNode(MAASServerTestCase):
28 self.assertThat(node_start, MockCalledOnceWith(
29 admin, user_data, NODE_STATUS.NEW, allow_power_cycle=True))
30
31- def test_start_commissioning_sets_min_hwe_kernel(self):
32+ def test_start_commissioning_sets_min_hwe_kernel_when_not_set(self):
33 node = factory.make_Node(status=NODE_STATUS.NEW)
34 node_start = self.patch(node, '_start')
35 node_start.side_effect = (
36@@ -2476,10 +2476,27 @@ class TestNode(MAASServerTestCase):
37 node_module, 'generate_user_data_for_status')
38 generate_user_data_for_status.return_value = user_data
39 admin = factory.make_admin()
40- Config.objects.set_config('default_min_hwe_kernel', 'hwe-v')
41+ Config.objects.set_config('default_min_hwe_kernel', 'hwe-16.04')
42 node.start_commissioning(admin)
43 post_commit_hooks.reset() # Ignore these for now.
44- self.assertEqual('hwe-v', node.min_hwe_kernel)
45+ self.assertEqual('hwe-16.04', node.min_hwe_kernel)
46+
47+ def test_start_commissioning_sets_min_hwe_kernel_when_previously_set(self):
48+ node = factory.make_Node(
49+ status=NODE_STATUS.READY, min_hwe_kernel='ga-16.04')
50+ node_start = self.patch(node, '_start')
51+ node_start.side_effect = (
52+ lambda user, user_data, old_status, allow_power_cycle: (
53+ post_commit()))
54+ user_data = factory.make_string().encode('ascii')
55+ generate_user_data_for_status = self.patch(
56+ node_module, 'generate_user_data_for_status')
57+ generate_user_data_for_status.return_value = user_data
58+ admin = factory.make_admin()
59+ Config.objects.set_config('default_min_hwe_kernel', 'hwe-16.04')
60+ node.start_commissioning(admin)
61+ post_commit_hooks.reset() # Ignore these for now.
62+ self.assertEqual('hwe-16.04', node.min_hwe_kernel)
63
64 def test_start_commissioning_starts_node_if_already_on(self):
65 node = factory.make_Node(

Subscribers

People subscribed via source and target branches