Merge lp:~jason-hobbs/maas/allow-hostname-change-while-allocated into lp:~maas-committers/maas/trunk

Proposed by Jason Hobbs
Status: Merged
Approved by: Jason Hobbs
Approved revision: no longer in the source branch.
Merged at revision: 2699
Proposed branch: lp:~jason-hobbs/maas/allow-hostname-change-while-allocated
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 74 lines (+10/-43)
2 files modified
src/maasserver/forms.py (+10/-12)
src/maasserver/tests/test_forms.py (+0/-31)
To merge this branch: bzr merge lp:~jason-hobbs/maas/allow-hostname-change-while-allocated
Reviewer Review Type Date Requested Status
Jason Hobbs (community) Approve
Julian Edwards (community) Approve
Review via email: mp+227372@code.launchpad.net

Commit message

Allow changing a hostname while a node is acquired.

Description of the change

This rolls back most of r1314. A similar check for "node started" instead of "node acquired" is expected to be added in the future, once MAAS grows the ability to track a node's start/stop state. In the mean time, I think it makes sense to be less restrictive and allow more use cases.

To post a comment you must log in.
Revision history for this message
Jason Hobbs (jason-hobbs) wrote :

We will revisit this towards the end of the sprint next week - there is a plan to implement acquired vs. acquired+started tracking in MAAS.

Revision history for this message
Julian Edwards (julian-edwards) wrote :

I think this is fine, but please file a bug with the intended behaviour and XXX with a reference to it in the code.

review: Approve
Revision history for this message
Jason Hobbs (jason-hobbs) wrote :

Approving minor comment change.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/forms.py'
2--- src/maasserver/forms.py 2014-08-14 05:57:19 +0000
3+++ src/maasserver/forms.py 2014-08-14 13:49:41 +0000
4@@ -335,18 +335,16 @@
5 self.initial['distro_series'] = initial_value
6
7 def clean_hostname(self):
8- # Don't allow the hostname to be changed if the node is
9- # currently allocated. Juju knows the node by its old name, so
10- # changing the name would confuse things.
11- hostname = self.instance.hostname
12- status = self.instance.status
13- new_hostname = self.cleaned_data.get('hostname', hostname)
14- if new_hostname != hostname and status == NODE_STATUS.ALLOCATED:
15- raise ValidationError(
16- "Can't change hostname to %s: node is in use." % new_hostname)
17-
18- # XXX 2014-07-30 jason-hobbs, bug=1350459: This check shouldn't be
19- # necessary, but many tests don't provide a nodegroup to NodeForm.
20+ # XXX 2014-08-14 jason-hobbs, bug=1356880; MAAS shouldn't allow
21+ # a hostname to be changed on a "deployed" node, but it doesn't
22+ # yet have the ability to distinguish between an "acquired" node
23+ # and a "deployed" node.
24+
25+ new_hostname = self.cleaned_data.get('hostname')
26+
27+ # XXX 2014-07-30 jason-hobbs, bug=1350459: This check for no
28+ # nodegroup shouldn't be necessary, but many tests don't provide
29+ # a nodegroup to NodeForm.
30 if self.instance.nodegroup is None:
31 return new_hostname
32
33
34=== modified file 'src/maasserver/tests/test_forms.py'
35--- src/maasserver/tests/test_forms.py 2014-08-12 13:52:04 +0000
36+++ src/maasserver/tests/test_forms.py 2014-08-14 13:49:41 +0000
37@@ -710,37 +710,6 @@
38 (node.hostname, node.power_type, node.zone),
39 (hostname, power_type, zone))
40
41- def test_AdminNodeForm_refuses_to_update_hostname_on_allocated_node(self):
42- old_name = factory.make_name('old-hostname')
43- new_name = factory.make_name('new-hostname')
44- node = factory.make_node(
45- hostname=old_name, status=NODE_STATUS.ALLOCATED)
46- form = AdminNodeForm(
47- data={
48- 'hostname': new_name,
49- 'architecture': node.architecture,
50- },
51- instance=node)
52- self.assertFalse(form.is_valid())
53- self.assertEqual(
54- ["Can't change hostname to %s: node is in use." % new_name],
55- form._errors['hostname'])
56-
57- def test_AdminNodeForm_accepts_unchanged_hostname_on_allocated_node(self):
58- old_name = factory.make_name('old-hostname')
59- node = factory.make_node(
60- hostname=old_name, status=NODE_STATUS.ALLOCATED)
61- patch_usable_architectures(self, [node.architecture])
62- form = AdminNodeForm(
63- data={
64- 'hostname': old_name,
65- 'architecture': node.architecture,
66- },
67- instance=node)
68- self.assertTrue(form.is_valid(), form._errors)
69- form.save()
70- self.assertEqual(old_name, reload_object(node).hostname)
71-
72 def test_AdminNodeForm_populates_power_type_choices(self):
73 form = AdminNodeForm()
74 self.assertEqual(