Merge lp:~julian-edwards/maas/cluster-name-override-bug-1380805 into lp:~maas-committers/maas/trunk

Proposed by Julian Edwards
Status: Rejected
Rejected by: Julian Edwards
Proposed branch: lp:~julian-edwards/maas/cluster-name-override-bug-1380805
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 36 lines (+15/-0)
2 files modified
src/maasserver/forms.py (+4/-0)
src/maasserver/tests/test_forms_nodegroup.py (+11/-0)
To merge this branch: bzr merge lp:~julian-edwards/maas/cluster-name-override-bug-1380805
Reviewer Review Type Date Requested Status
Gavin Panella (community) Abstain
Raphaël Badin (community) Abstain
Review via email: mp+238226@code.launchpad.net

Commit message

Don't default cluster_name in NodeGroupDefineForm if it's already set. This is possibly the cause of clusters getting unilaterally renamed as part of the new cluster registration protocol for RPC when upgrading to 1.7.

Description of the change

The fix depends on the "instance" being present in the form; I'm testing this now in the real world to see if that's the case, but it will take an hour or more to install a fresh 1.5 and then upgrade to a test 1.7 package.

To post a comment you must log in.
Revision history for this message
Julian Edwards (julian-edwards) wrote :

Oh well I just tested this, and after upgrade the cluster name was empty! So this is clearly the wrong approach, but I am a little stumped. I'll wait for rvb to get here as I am still missing info on how rpc-based cluster registration works nowadays.

Revision history for this message
Gavin Panella (allenap) wrote :

See in maasserver.rpc.clusters.register_cluster:

def register_cluster(uuid, name=None, domain=None, networks=None, url=None):
    ...
    # Massage the data so that we can pass it into NodeGroupDefineForm.
    data = {
        "cluster_name": name,
        "name": domain,
        "uuid": uuid,
    }

I suggest only including `cluster_name` (and `name` too, thought that's
not directly relevant to this bug) when it's not None, i.e.:

    data = {"uuid": uuid}
    if name is not None:
        data["cluster_name"] = name
    if domain is not None:
        data["name"] = domain

I'm not 100% certain that'll work, but it seems worth trying.

review: Needs Fixing
Revision history for this message
Raphaël Badin (rvb) :
review: Approve
Revision history for this message
Raphaël Badin (rvb) :
review: Abstain
Revision history for this message
Gavin Panella (allenap) wrote :

I think lp:~allenap/maas/cluster-name-override--bug-1380805 has superseded this, but maybe there's a need for this too?

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

On Tuesday 14 Oct 2014 16:00:32 you wrote:
> Review: Abstain
>
> I think lp:~allenap/maas/cluster-name-override--bug-1380805 has superseded
> this, but maybe there's a need for this too?

It's possible there's a need but does anyone remember why it was done like
that in the first place? There's an intriguing comment in the docstring:

    This form can create a new `NodeGroup`, or in the case where a cluster
    automatically becomes the master, updating an existing one.

Unmerged revisions

3248. By Julian Edwards

add back defaulting behaviour if the name doesn't exist yet

3247. By Julian Edwards

Don't default cluster_name as it can override the existing name

3246. By Julian Edwards

Failing test

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-10-10 04:55:03 +0000
3+++ src/maasserver/forms.py 2014-10-14 01:36:02 +0000
4@@ -1650,6 +1650,10 @@
5
6 def clean(self):
7 cleaned_data = super(NodeGroupDefineForm, self).clean()
8+ if self.instance.cluster_name:
9+ # Deliberately vague check, could be None or empty.
10+ # Don't override any existing cluster_name.
11+ return cleaned_data
12 cluster_name = cleaned_data.get("cluster_name")
13 uuid = cleaned_data.get("uuid")
14 if uuid and not cluster_name:
15
16=== modified file 'src/maasserver/tests/test_forms_nodegroup.py'
17--- src/maasserver/tests/test_forms_nodegroup.py 2014-09-19 04:49:07 +0000
18+++ src/maasserver/tests/test_forms_nodegroup.py 2014-10-14 01:36:02 +0000
19@@ -227,6 +227,17 @@
20 nodegroup = form.save()
21 self.assertIn(uuid, nodegroup.cluster_name)
22
23+ def test_does_not_override_existing_cluster_name(self):
24+ cluster_name = factory.make_name('cluster_name')
25+ cluster = factory.make_NodeGroup(cluster_name=cluster_name)
26+ form = NodeGroupDefineForm(
27+ instance=cluster,
28+ status=NODEGROUP_STATUS.ACCEPTED,
29+ data={'name': cluster.name, 'uuid': cluster.uuid})
30+ self.assertTrue(form.is_valid(), form._errors)
31+ new_cluster = form.save()
32+ self.assertEqual(cluster_name, new_cluster.cluster_name)
33+
34 def test_populates_cluster_name(self):
35 cluster_name = factory.make_name('cluster_name')
36 uuid = factory.make_UUID()