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
=== modified file 'src/maasserver/forms.py'
--- src/maasserver/forms.py 2014-08-14 05:57:19 +0000
+++ src/maasserver/forms.py 2014-08-14 13:49:41 +0000
@@ -335,18 +335,16 @@
335 self.initial['distro_series'] = initial_value335 self.initial['distro_series'] = initial_value
336336
337 def clean_hostname(self):337 def clean_hostname(self):
338 # Don't allow the hostname to be changed if the node is338 # XXX 2014-08-14 jason-hobbs, bug=1356880; MAAS shouldn't allow
339 # currently allocated. Juju knows the node by its old name, so339 # a hostname to be changed on a "deployed" node, but it doesn't
340 # changing the name would confuse things.340 # yet have the ability to distinguish between an "acquired" node
341 hostname = self.instance.hostname341 # and a "deployed" node.
342 status = self.instance.status342
343 new_hostname = self.cleaned_data.get('hostname', hostname)343 new_hostname = self.cleaned_data.get('hostname')
344 if new_hostname != hostname and status == NODE_STATUS.ALLOCATED:344
345 raise ValidationError(345 # XXX 2014-07-30 jason-hobbs, bug=1350459: This check for no
346 "Can't change hostname to %s: node is in use." % new_hostname)346 # nodegroup shouldn't be necessary, but many tests don't provide
347347 # a nodegroup to NodeForm.
348 # XXX 2014-07-30 jason-hobbs, bug=1350459: This check shouldn't be
349 # necessary, but many tests don't provide a nodegroup to NodeForm.
350 if self.instance.nodegroup is None:348 if self.instance.nodegroup is None:
351 return new_hostname349 return new_hostname
352350
353351
=== modified file 'src/maasserver/tests/test_forms.py'
--- src/maasserver/tests/test_forms.py 2014-08-12 13:52:04 +0000
+++ src/maasserver/tests/test_forms.py 2014-08-14 13:49:41 +0000
@@ -710,37 +710,6 @@
710 (node.hostname, node.power_type, node.zone),710 (node.hostname, node.power_type, node.zone),
711 (hostname, power_type, zone))711 (hostname, power_type, zone))
712712
713 def test_AdminNodeForm_refuses_to_update_hostname_on_allocated_node(self):
714 old_name = factory.make_name('old-hostname')
715 new_name = factory.make_name('new-hostname')
716 node = factory.make_node(
717 hostname=old_name, status=NODE_STATUS.ALLOCATED)
718 form = AdminNodeForm(
719 data={
720 'hostname': new_name,
721 'architecture': node.architecture,
722 },
723 instance=node)
724 self.assertFalse(form.is_valid())
725 self.assertEqual(
726 ["Can't change hostname to %s: node is in use." % new_name],
727 form._errors['hostname'])
728
729 def test_AdminNodeForm_accepts_unchanged_hostname_on_allocated_node(self):
730 old_name = factory.make_name('old-hostname')
731 node = factory.make_node(
732 hostname=old_name, status=NODE_STATUS.ALLOCATED)
733 patch_usable_architectures(self, [node.architecture])
734 form = AdminNodeForm(
735 data={
736 'hostname': old_name,
737 'architecture': node.architecture,
738 },
739 instance=node)
740 self.assertTrue(form.is_valid(), form._errors)
741 form.save()
742 self.assertEqual(old_name, reload_object(node).hostname)
743
744 def test_AdminNodeForm_populates_power_type_choices(self):713 def test_AdminNodeForm_populates_power_type_choices(self):
745 form = AdminNodeForm()714 form = AdminNodeForm()
746 self.assertEqual(715 self.assertEqual(