launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #10377
[Merge] lp:~jtv/maas/factory-sets-node-nodegroup into lp:maas
Jeroen T. Vermeulen has proposed merging lp:~jtv/maas/factory-sets-node-nodegroup into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~jtv/maas/factory-sets-node-nodegroup/+merge/117238
This fixes one of several problems I ran into while making Node.nodegroup mandatory. The others aren't proving so easy to solve, so we might as well get this simple fix in first.
Jeroen
--
https://code.launchpad.net/~jtv/maas/factory-sets-node-nodegroup/+merge/117238
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/maas/factory-sets-node-nodegroup into lp:maas.
=== modified file 'src/maasserver/testing/factory.py'
--- src/maasserver/testing/factory.py 2012-07-25 15:25:42 +0000
+++ src/maasserver/testing/factory.py 2012-07-30 11:04:19 +0000
@@ -88,15 +88,17 @@
def make_node(self, mac=False, hostname='', set_hostname=False,
status=None, architecture=ARCHITECTURE.i386, updated=None,
- created=None, **kwargs):
+ created=None, nodegroup=None, **kwargs):
# hostname=None is a valid value, hence the set_hostname trick.
if hostname is '' and set_hostname:
hostname = self.getRandomString(20)
if status is None:
status = NODE_STATUS.DEFAULT_STATUS
+ if nodegroup is None:
+ nodegroup = self.make_node_group()
node = Node(
hostname=hostname, status=status, architecture=architecture,
- **kwargs)
+ nodegroup=nodegroup, **kwargs)
self._save_node_unchecked(node)
if mac:
self.make_mac_address(node=node)
=== modified file 'src/maasserver/testing/tests/test_factory.py'
--- src/maasserver/testing/tests/test_factory.py 2012-04-16 10:00:51 +0000
+++ src/maasserver/testing/tests/test_factory.py 2012-07-30 11:04:19 +0000
@@ -14,6 +14,7 @@
from random import randint
+from maasserver.models import NodeGroup
from maasserver.testing.factory import factory
from maastesting.testcase import TestCase
@@ -41,3 +42,15 @@
but_not = [2]
self.assertEqual(
10, factory.getRandomChoice(options, but_not=but_not))
+
+ def test_make_node_creates_nodegroup_if_none_given(self):
+ existing_nodegroup_ids = set(
+ nodegroup.id for nodegroup in NodeGroup.objects.all())
+ new_node = factory.make_node()
+ self.assertIsNotNone(new_node.nodegroup)
+ self.assertNotIn(new_node.nodegroup.id, existing_nodegroup_ids)
+
+ def test_make_node_uses_given_nodegroup(self):
+ nodegroup = factory.make_node_group()
+ self.assertEqual(
+ nodegroup, factory.make_node(nodegroup=nodegroup).nodegroup)