~allenap/maas/tftp-permissions

« back to all changes in this revision

Viewing changes to src/provisioningserver/pxe/tests/test_config.py

  • Committer: Tarmac
  • Author(s): Jeroen Vermeulen
  • Date: 2012-08-30 16:41:00 UTC
  • mfrom: (947.1.11 bug-1042877)
  • Revision ID: ed@carob-20120830164100-bdo6ne0370451tkp
[r=allenap][bug=1042877][author=jtv] Move our TFTP hierachy, and dispense with the bootpath (the "maas/" prefix in PXE TFTP paths).

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from maastesting.matchers import ContainsAll
22
22
from maastesting.testcase import TestCase
23
23
import mock
24
 
import posixpath
25
24
from provisioningserver import kernel_opts
26
25
from provisioningserver.pxe import config
27
26
from provisioningserver.pxe.config import render_pxe_config
150
149
    def test_render(self):
151
150
        # Given the right configuration options, the PXE configuration is
152
151
        # correctly rendered.
153
 
        bootpath = factory.make_name("bootpath")
154
152
        params = make_kernel_parameters()
155
 
        output = render_pxe_config(bootpath=bootpath, kernel_params=params)
 
153
        output = render_pxe_config(kernel_params=params)
156
154
        # The output is always a Unicode string.
157
155
        self.assertThat(output, IsInstance(unicode))
158
156
        # The template has rendered without error. PXELINUX configurations
162
160
        image_dir = compose_image_path(
163
161
            arch=params.arch, subarch=params.subarch,
164
162
            release=params.release, purpose=params.purpose)
165
 
        image_dir = posixpath.relpath(image_dir, bootpath)
166
163
        self.assertThat(
167
164
            output, MatchesAll(
168
165
                MatchesRegex(
177
174
 
178
175
    def test_render_with_extra_arguments_does_not_affect_output(self):
179
176
        # render_pxe_config() allows any keyword arguments as a safety valve.
180
 
        options = {
181
 
            "bootpath": factory.make_name("bootpath"),
182
 
            "kernel_params": make_kernel_parameters(),
183
 
            }
 
177
        options = {"kernel_params": make_kernel_parameters()}
184
178
        # Capture the output before sprinking in some random options.
185
179
        output_before = render_pxe_config(**options)
186
180
        # Sprinkle some magic in.
196
190
        # If purpose is "local", the config.localboot.template should be
197
191
        # used.
198
192
        options = {
199
 
            "bootpath": factory.make_name("bootpath"),
200
193
            "kernel_params":
201
194
                make_kernel_parameters()._replace(purpose="local"),
202
195
            }
207
200
        # Intel i386 is a special case and needs to use the chain.c32
208
201
        # loader as the LOCALBOOT PXE directive is unreliable.
209
202
        options = {
210
 
            "bootpath": factory.make_name("bootpath"),
211
203
            "kernel_params": make_kernel_parameters()._replace(
212
204
                arch="i386", purpose="local"),
213
205
            }
219
211
        # Intel amd64 is a special case and needs to use the chain.c32
220
212
        # loader as the LOCALBOOT PXE directive is unreliable.
221
213
        options = {
222
 
            "bootpath": factory.make_name("bootpath"),
223
214
            "kernel_params": make_kernel_parameters()._replace(
224
215
                arch="amd64", purpose="local"),
225
216
            }
233
224
        get_ephemeral_name = self.patch(kernel_opts, "get_ephemeral_name")
234
225
        get_ephemeral_name.return_value = factory.make_name("ephemeral")
235
226
        options = {
236
 
            "bootpath": factory.make_name("bootpath"),
237
227
            "kernel_params": make_kernel_parameters()._replace(
238
228
                purpose="commissioning"),
239
229
            }
251
241
            default_section["APPEND"].split())
252
242
        # Both "i386" and "amd64" sections exist.
253
243
        self.assertThat(config, ContainsAll(("i386", "amd64")))
254
 
        # Each section defines KERNEL, INITRD, and APPEND settings, each
255
 
        # containing paths referring to their architectures.
 
244
        # Each section defines KERNEL, INITRD, and APPEND settings.  The
 
245
        # KERNEL and INITRD ones contain paths referring to their
 
246
        # architectures.
256
247
        for section_label in ("i386", "amd64"):
257
248
            section = config[section_label]
258
249
            self.assertThat(
259
250
                section, ContainsAll(("KERNEL", "INITRD", "APPEND")))
260
 
            contains_arch_path = Contains("/%s/" % section_label)
 
251
            contains_arch_path = StartsWith("%s/" % section_label)
261
252
            self.assertThat(section["KERNEL"], contains_arch_path)
262
253
            self.assertThat(section["INITRD"], contains_arch_path)
263
 
            self.assertThat(section["APPEND"], contains_arch_path)
 
254
            self.assertIn("APPEND", section)