launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #06782
[Merge] lp:~julian-edwards/maas/vdenv-enlistment into lp:maas
Julian Edwards has proposed merging lp:~julian-edwards/maas/vdenv-enlistment into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~julian-edwards/maas/vdenv-enlistment/+merge/98393
Ensure that vdenv's cobbler-setup also pokes the test nodes into MAAS.
I had to make system_id and status settable over the API as well hence the changes in MAAS.
--
https://code.launchpad.net/~julian-edwards/maas/vdenv-enlistment/+merge/98393
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~julian-edwards/maas/vdenv-enlistment into lp:maas.
=== modified file 'src/maasserver/forms.py'
--- src/maasserver/forms.py 2012-03-19 15:41:55 +0000
+++ src/maasserver/forms.py 2012-03-20 11:08:19 +0000
@@ -36,10 +36,13 @@
ARCHITECTURE,
ARCHITECTURE_CHOICES,
Config,
+ generate_node_system_id,
MACAddress,
Node,
NODE_AFTER_COMMISSIONING_ACTION,
NODE_AFTER_COMMISSIONING_ACTION_CHOICES,
+ NODE_STATUS_CHOICES,
+ NODE_STATUS,
)
@@ -71,16 +74,30 @@
after_commissioning_action = forms.TypedChoiceField(
choices=NODE_AFTER_COMMISSIONING_ACTION_CHOICES, required=False,
empty_value=NODE_AFTER_COMMISSIONING_ACTION.DEFAULT)
+ status = forms.TypedChoiceField(
+ choices=NODE_STATUS_CHOICES, required=False,
+ empty_value=NODE_STATUS.DEFAULT_STATUS)
architecture = forms.ChoiceField(
choices=ARCHITECTURE_CHOICES, required=True,
initial=ARCHITECTURE.i386,
error_messages={'invalid_choice': INVALID_ARCHITECTURE_MESSAGE})
+ def save(self, commit=True):
+ node = super(NodeForm, self).save(commit=False)
+ # Because we allow system_id to be set over the API it needs to
+ # be defaulted correctly here; defaulting on the model doesn't
+ # work as the default is an empty string, not None, coming from
+ # the form.
+ if self.cleaned_data['system_id'] == "":
+ node.system_id = generate_node_system_id()
+ node.save()
+ return node
+
class Meta:
model = Node
fields = (
'hostname', 'system_id', 'after_commissioning_action',
- 'architecture', 'power_type')
+ 'architecture', 'status', 'power_type')
class MACAddressForm(ModelForm):
=== modified file 'src/maasserver/models.py'
--- src/maasserver/models.py 2012-03-19 15:41:55 +0000
+++ src/maasserver/models.py 2012-03-20 11:08:19 +0000
@@ -343,12 +343,12 @@
system_id = models.CharField(
max_length=41, unique=True, default=generate_node_system_id,
- editable=False)
+ editable=True)
hostname = models.CharField(max_length=255, default='', blank=True)
status = models.IntegerField(
- max_length=10, choices=NODE_STATUS_CHOICES, editable=False,
+ max_length=10, choices=NODE_STATUS_CHOICES, editable=True,
default=NODE_STATUS.DEFAULT_STATUS)
owner = models.ForeignKey(
=== modified file 'src/maasserver/tests/test_api.py'
--- src/maasserver/tests/test_api.py 2012-03-19 17:39:39 +0000
+++ src/maasserver/tests/test_api.py 2012-03-20 11:08:19 +0000
@@ -80,6 +80,33 @@
self.assertEqual(2, diane.after_commissioning_action)
self.assertEqual(architecture, diane.architecture)
+ def test_POST_new_can_set_status(self):
+ architecture = factory.getRandomChoice(ARCHITECTURE_CHOICES)
+ response = self.client.post(
+ self.get_uri('nodes/'), {
+ 'op': 'new',
+ 'architecture': architecture,
+ 'mac_addresses': ['00:11:22:33:44:55'],
+ 'status': '4',
+ })
+ node = Node.objects.get(
+ system_id=json.loads(response.content)['system_id'])
+ self.assertEqual(4, node.status)
+
+ def test_POST_new_can_set_system_id(self):
+ architecture = factory.getRandomChoice(ARCHITECTURE_CHOICES)
+ system_id = "testnode"
+ response = self.client.post(
+ self.get_uri('nodes/'), {
+ 'op': 'new',
+ 'architecture': architecture,
+ 'mac_addresses': ['00:11:22:33:44:55'],
+ 'system_id': system_id,
+ })
+ node = Node.objects.get(
+ system_id=json.loads(response.content)['system_id'])
+ self.assertEqual(system_id, node.system_id)
+
def test_POST_new_power_type_defaults_to_asking_config(self):
architecture = factory.getRandomChoice(ARCHITECTURE_CHOICES)
response = self.client.post(
=== modified file 'vdenv/HOWTO'
--- vdenv/HOWTO 2012-03-09 20:44:46 +0000
+++ vdenv/HOWTO 2012-03-20 11:08:19 +0000
@@ -35,7 +35,13 @@
read keyowner
./bin/authorize-ssh $cobblerlogin $keyowner
-## populate the nodes into the cobbler server
+## populate the nodes into the cobbler server and MAAS server
+cat <<EOF
+About to populate test nodes into cobbler and the MAAS database. Please
+make sure MAAS is running ("make run" from another window).
+[hit enter to continue]
+EOF
+read
./setup.py cobbler-setup
## Listen for libvirt requests from the Cobbler server.
=== modified file 'vdenv/setup.py'
--- vdenv/setup.py 2012-03-12 16:40:38 +0000
+++ vdenv/setup.py 2012-03-20 11:08:19 +0000
@@ -195,6 +195,7 @@
hostip = "%s.1" % config['network']['ip_pre']
arch = get_profile_arch()
profile = "precise-%s-juju" % arch
+ # TODO: should be maas-precise-%s ???
cob = System(config, "zimmer")
cobbler_url = "http://%s/cobbler_api" % cob.ipaddr
@@ -207,6 +208,19 @@
for system in systems:
cobbler_addsystem(server, token, system, profile, hostip)
+ # Poke the data into MAAS's database. We could use Python to do this
+ # but meh, curl is a one liner.
+ print("Adding %s to MAAS" % system.name)
+ cmd = [
+ "curl", "--data",
+ "op=new&mac_addresses=%s&hostname=%s&system_id=%s&status=4"
+ "&architecture=amd64" %
+ (system.mac, system.name, system.name),
+ "http://localhost:5240/api/1.0/nodes/"]
+ print(cmd)
+ subprocess.check_call(cmd)
+
+
def main():
outpre = "libvirt-cobbler-"
cfg_file = "settings.cfg"
Follow ups