launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #08635
[Merge] lp:~allenap/maas/tempita-a-go-go into lp:maas
Gavin Panella has proposed merging lp:~allenap/maas/tempita-a-go-go into lp:maas with lp:~allenap/maas/fix-makefile-write-dhcp-stuff as a prerequisite.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~allenap/maas/tempita-a-go-go/+merge/109340
Use Tempita for DHCPConfigWriter, not because it really needs it, but because it's a simple job and a way to get Tempita into the tree.
--
https://code.launchpad.net/~allenap/maas/tempita-a-go-go/+merge/109340
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/maas/tempita-a-go-go into lp:maas.
=== modified file 'buildout.cfg'
--- buildout.cfg 2012-06-08 12:07:05 +0000
+++ buildout.cfg 2012-06-08 12:07:05 +0000
@@ -42,6 +42,7 @@
psycopg2
python-dateutil
PyYAML
+ Tempita
Twisted
txAMQP
# Convenient developer dependencies
@@ -153,6 +154,7 @@
oops-datedir-repo
oops-twisted
pyyaml
+ Tempita
twisted
txamqp
entry-points =
=== modified file 'src/provisioningserver/dhcp/config.py'
--- src/provisioningserver/dhcp/config.py 2012-06-07 18:12:48 +0000
+++ src/provisioningserver/dhcp/config.py 2012-06-08 12:07:05 +0000
@@ -18,12 +18,14 @@
from textwrap import dedent
+import tempita
+
class DHCPConfigError(Exception):
"""Exception raised for errors processing the DHCP config."""
-template = dedent("""\
+template_content = dedent("""\
class "pxe" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
}
@@ -32,13 +34,13 @@
"U-boot.armv7.highbank";
}
- subnet %(subnet)s netmask %(subnet_mask)s {
- next-server %(next_server)s;
- option subnet-mask %(subnet_mask)s;
- option broadcast-address %(broadcast_address)s;
- option domain-name-servers %(dns_servers)s;
- option routers %(gateway)s;
- range dynamic-bootp %(low_range)s %(high_range)s;
+ subnet {{subnet}} netmask {{subnet_mask}} {
+ next-server {{next_server}};
+ option subnet-mask {{subnet_mask}};
+ option broadcast-address {{broadcast_address}};
+ option domain-name-servers {{dns_servers}};
+ option routers {{gateway}};
+ range dynamic-bootp {{low_range}} {{high_range}};
pool {
allow members of "uboot-highbank";
@@ -51,6 +53,9 @@
}
""")
+template = tempita.Template(
+ template_content, name="%s.template" % __name__)
+
def get_config(**params):
"""Return a DHCP config file based on the supplied parameters.
@@ -71,8 +76,6 @@
# This is a really simple substitution for now but it's encapsulated
# here so that its implementation can be changed later if required.
try:
- return template % params
- except KeyError, e:
- raise DHCPConfigError(
- "Passed parameters are missing at least the value for %s" %
- e.message)
+ return template.substitute(params)
+ except NameError, error:
+ raise DHCPConfigError(*error.args)
=== modified file 'src/provisioningserver/dhcp/tests/test_config.py'
--- src/provisioningserver/dhcp/tests/test_config.py 2012-06-06 04:39:20 +0000
+++ src/provisioningserver/dhcp/tests/test_config.py 2012-06-08 12:07:05 +0000
@@ -12,31 +12,34 @@
__metaclass__ = type
__all__ = []
-from testtools import TestCase
from textwrap import dedent
from provisioningserver.dhcp import config
+import tempita
+from testtools import TestCase
+from testtools.matchers import StartsWith
class TestDHCPConfig(TestCase):
def setUp(self):
super(TestDHCPConfig, self).setUp()
- self.template = dedent("""\
- %(subnet)s
- %(subnet_mask)s
- %(next_server)s
- %(broadcast_address)s
- %(dns_servers)s
- %(gateway)s
- %(low_range)s
- %(high_range)s
+ self.template_content = dedent("""\
+ {{subnet}}
+ {{subnet_mask}}
+ {{next_server}}
+ {{broadcast_address}}
+ {{dns_servers}}
+ {{gateway}}
+ {{low_range}}
+ {{high_range}}
""")
+ self.template = tempita.Template(
+ content=self.template_content,
+ name="%s.template" % self.__class__.__name__)
def test_param_substitution(self):
- self.patch(
- config, "template", self.template
- )
+ self.patch(config, "template", self.template)
params = dict(
subnet="10.0.0.0",
@@ -50,13 +53,11 @@
output = config.get_config(**params)
- expected = self.template % params
+ expected = self.template.substitute(params)
self.assertEqual(expected, output)
def test_get_config_with_too_few_parameters(self):
- self.patch(
- config, "template", self.template
- )
+ self.patch(config, "template", self.template)
params = dict(
# subnet is missing
@@ -71,6 +72,4 @@
e = self.assertRaises(
config.DHCPConfigError, config.get_config, **params)
- self.assertEqual(
- "Passed parameters are missing at least the value for subnet",
- e.message)
+ self.assertThat(e.message, StartsWith("name 'subnet' is not defined"))
=== modified file 'versions.cfg'
--- versions.cfg 2012-05-23 11:20:09 +0000
+++ versions.cfg 2012-06-08 12:07:05 +0000
@@ -38,6 +38,7 @@
saucelabsfixture = 0.1
setuptools = 0.6.24
South = 0.7.3
+Tempita = 0.5.1
Twisted = 11.1.0
txAMQP = 0.5
txlongpoll = 0.3.1