launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #09051
[Merge] lp:~julian-edwards/maas/tftp-config-task into lp:maas
Julian Edwards has proposed merging lp:~julian-edwards/maas/tftp-config-task into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~julian-edwards/maas/tftp-config-task/+merge/111328
This adds a task to write out TFTP configs for nodes. I don't remember who I did a pre-imp with unfortunately but probably all of you at some point :)
Note that it writes a separate config for each MAC on the node.
--
https://code.launchpad.net/~julian-edwards/maas/tftp-config-task/+merge/111328
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~julian-edwards/maas/tftp-config-task into lp:maas.
=== modified file 'src/provisioningserver/tasks.py'
--- src/provisioningserver/tasks.py 2012-05-29 06:13:48 +0000
+++ src/provisioningserver/tasks.py 2012-06-21 02:52:20 +0000
@@ -17,10 +17,12 @@
from celery.decorators import task
+from maasserver.models import MACAddress
from provisioningserver.power.poweraction import (
PowerAction,
PowerActionFail,
)
+from provisioningserver.pxe.pxeconfig import PXEConfig
def issue_power_action(power_type, power_change, **kwargs):
@@ -57,3 +59,21 @@
def power_off(power_type, **kwargs):
"""Turn a node off."""
issue_power_action(power_type, 'off', **kwargs)
+
+
+@task
+def write_tftp_config_for_node(node, pxe_target_dir=None, **kwargs):
+ """Write out the TFTP MAC-based config for `node`.
+
+ A config file is written for each MAC associated with the node.
+
+ :param node: A :class:`maasserver.models.Node`.
+ :param **kwargs: Keyword args passed to PXEConfig.write_config()
+ """
+ arch = node.architecture
+ # TODO: fix subarch when node.py starts modelling sub-architecture for ARM
+ subarch = "generic"
+ macs = MACAddress.objects.filter(node=node)
+ for mac in macs:
+ pxeconfig = PXEConfig(arch, subarch, mac.mac_address, pxe_target_dir)
+ pxeconfig.write_config(**kwargs)
=== modified file 'src/provisioningserver/tests/test_tasks.py'
--- src/provisioningserver/tests/test_tasks.py 2012-05-29 08:07:16 +0000
+++ src/provisioningserver/tests/test_tasks.py 2012-06-21 02:52:20 +0000
@@ -12,16 +12,22 @@
__metaclass__ = type
__all__ = []
+import os
+
+from maasserver.enum import ARCHITECTURE
+from maasserver.testing.factory import factory
from maastesting.celery import CeleryFixture
+from maastesting.matchers import ContainsAll
from maastesting.testcase import TestCase
from provisioningserver.enum import POWER_TYPE
from provisioningserver.power.poweraction import PowerActionFail
from provisioningserver.tasks import (
power_off,
power_on,
+ write_tftp_config_for_node,
)
from testresources import FixtureResource
-
+from testtools.matchers import FileContains
# An arbitrary MAC address. Not using a properly random one here since
# we might accidentally affect real machines on the network.
@@ -49,3 +55,37 @@
self.assertRaises(
PowerActionFail, power_off.delay,
POWER_TYPE.WAKE_ON_LAN, mac=arbitrary_mac)
+
+
+class TestTFTPTasks(TestCase):
+
+ resources = (
+ ("celery", FixtureResource(CeleryFixture())),
+ )
+
+ def test_write_tftp_config_for_node_writes_files(self):
+ arch = ARCHITECTURE.i386
+ node = factory.make_node(architecture=arch)
+ mac = factory.make_mac_address(node=node).mac_address
+ mac2 = factory.make_mac_address(node=node).mac_address
+ target_dir = self.make_dir()
+ kernel = factory.getRandomString()
+ menutitle = factory.getRandomString()
+ append = factory.getRandomString()
+
+ result = write_tftp_config_for_node.delay(
+ node, pxe_target_dir=target_dir, menutitle=menutitle,
+ kernelimage=kernel, append=append)
+
+ self.assertTrue(result.successful(), result)
+ expected_file1 = os.path.join(
+ target_dir, arch, "generic", "pxelinux.cfg", mac.replace(":", "-"))
+ expected_file2 = os.path.join(
+ target_dir, arch, "generic", "pxelinux.cfg",
+ mac2.replace(":", "-"))
+ self.assertThat(
+ expected_file1,
+ FileContains(matcher=ContainsAll((kernel, menutitle, append))))
+ self.assertThat(
+ expected_file2,
+ FileContains(matcher=ContainsAll((kernel, menutitle, append))))