~lutostag/ubuntu/trusty/maas/1.5.2+packagefix

« back to all changes in this revision

Viewing changes to src/provisioningserver/tests/test_maas_import_pxe_files.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2014-03-28 10:43:53 UTC
  • mto: This revision was merged to the branch mainline in revision 57.
  • Revision ID: package-import@ubuntu.com-20140328104353-ekpolg0pm5xnvq2s
Tags: upstream-1.5+bzr2204
ImportĀ upstreamĀ versionĀ 1.5+bzr2204

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2012, 2013 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2012-2014 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
"""Tests for the maas-import-pxe-files script."""
16
16
 
17
17
import os
18
18
from subprocess import check_call
 
19
import unittest
19
20
 
20
21
from maastesting import root
21
22
from maastesting.factory import factory
24
25
    age_file,
25
26
    get_write_time,
26
27
    )
27
 
from provisioningserver.pxe import tftppath
28
 
from provisioningserver.testing.config import ConfigFixture
 
28
from provisioningserver.boot import tftppath
 
29
from provisioningserver.boot.pxe import PXEBootMethod
 
30
from provisioningserver.boot.uefi import UEFIBootMethod
 
31
from provisioningserver.testing.config import set_tftp_root
29
32
from testtools.content import text_content
30
33
from testtools.matchers import (
31
34
    DirExists,
103
106
    return [compose_download_kernel_name(arch, release), 'initrd.gz']
104
107
 
105
108
 
 
109
def compose_uefi_dir(archive, release):
 
110
    """File locations expected to be found in the archive for UEFI netboot.
 
111
 
 
112
    :param archive: Archive directory (corresponding to the script's ARCHIVE
 
113
        setting, except here it's a filesystem path not a URL).
 
114
    :param release: distro release
 
115
    :return: A 2-tuple of:
 
116
        * Base path of the current/ dir.
 
117
        * Requisite files for this archive.
 
118
    """
 
119
    basepath = os.path.join(
 
120
        archive, 'dists', release, 'main', 'uefi', 'grub2-amd64', 'current')
 
121
    return basepath, ['grubnetx64.efi.signed']
 
122
 
 
123
 
106
124
def generate_md5sums(basepath):
107
125
    """Write MD5SUMS file at basepath."""
108
126
    script = [
115
133
 
116
134
def compose_tftp_bootloader_path(tftproot):
117
135
    """Compose path for MAAS TFTP bootloader."""
118
 
    return tftppath.locate_tftp_path(
119
 
        tftppath.compose_bootloader_path(), tftproot)
120
 
 
121
 
 
122
 
def compose_tftp_path(tftproot, arch, release, purpose, *path):
 
136
    pxe_method = PXEBootMethod()
 
137
    return tftppath.locate_tftp_path(
 
138
        pxe_method.bootloader_path, tftproot)
 
139
 
 
140
 
 
141
def compose_tftp_uefi_bootloader_path(tftproot):
 
142
    """Compose path for MAAS UEFI TFTP bootloader."""
 
143
    uefi_method = UEFIBootMethod()
 
144
    return tftppath.locate_tftp_path(
 
145
        uefi_method.bootloader_path, tftproot)
 
146
 
 
147
 
 
148
def compose_tftp_path(tftproot, arch, release, label, purpose, *path):
123
149
    """Compose path for MAAS TFTP files for given architecture.
124
150
 
125
151
    After the TFTP root directory and the architecture, just append any path
128
154
    """
129
155
    return os.path.join(
130
156
        tftppath.locate_tftp_path(
131
 
            tftppath.compose_image_path(arch[0], arch[1], release, purpose),
 
157
            tftppath.compose_image_path(
 
158
                arch[0], arch[1], release, label, purpose),
132
159
            tftproot),
133
160
        *path)
134
161
 
145
172
 
146
173
    def setUp(self):
147
174
        super(TestImportPXEFiles, self).setUp()
 
175
        raise unittest.SkipTest(
 
176
            "XXX rvb 2014-03-21 bug=1295479: Disabled.  The "
 
177
            "maas-import-pxe-files script has been replaced with a "
 
178
            "new version to use simplestreams v2's data.  These tests need "
 
179
            "to be completely refactored.")
148
180
        self.tftproot = self.make_dir()
149
 
        self.config = {"tftp": {"root": self.tftproot}}
150
 
        self.config_fixture = ConfigFixture(self.config)
151
 
        self.useFixture(self.config_fixture)
 
181
        self.config_fixture = self.useFixture(set_tftp_root(self.tftproot))
152
182
 
153
183
    def get_arch(self):
154
184
        """Return an existing, supported architecture/subarchitecture pair."""
168
198
        for filename in compose_download_filenames(arch, release):
169
199
            factory.make_file(download, filename)
170
200
        generate_md5sums(basepath)
 
201
        uefi_archive, uefi_filenames = compose_uefi_dir(archive, release)
 
202
        os.makedirs(uefi_archive)
 
203
        for uefi in uefi_filenames:
 
204
            factory.make_file(uefi_archive, uefi)
171
205
        return archive
172
206
 
173
207
    def call_script(self, archive_dir, tftproot, arch=None, release=None):
185
219
        env = {
186
220
            'MAIN_ARCHIVE': 'file://%s' % archive_dir,
187
221
            'PORTS_ARCHIVE': 'file://%s' % archive_dir,
 
222
            'STABLE_RELEASE': release,
188
223
            # Substitute curl for wget; it accepts file:// URLs.
189
224
            'DOWNLOAD': 'curl -O --silent',
190
225
            'PATH': os.pathsep.join(path),
194
229
            # Suppress GPG checks as we can't sign the file from
195
230
            # here.
196
231
            'IGNORE_GPG': '1',
 
232
            # Don't check for broken efinet, so arch will be
 
233
            # correct for the download.
 
234
            'CHECK_BROKEN_EFINET': '0',
 
235
            # Skip shim.efi.sifned, as we don't want it to really
 
236
            # download the package
 
237
            'SKIP_SHIM_SIGNED': '1',
197
238
        }
198
239
        env.update(self.config_fixture.environ)
199
240
        if arch is not None:
229
270
        expected_contents = read_file('/usr/lib/syslinux', 'pxelinux.0')
230
271
        self.assertThat(tftp_path, FileContains(expected_contents))
231
272
 
 
273
    def test_procures_uefi_grubnet(self):
 
274
        arch = self.get_arch()
 
275
        release = 'precise'
 
276
        archive = self.make_downloads(arch=arch, release=release)
 
277
        self.call_script(archive, self.tftproot, arch=arch, release=release)
 
278
        tftp_path = os.path.join(self.tftproot, 'grubx64.efi')
 
279
        uefi_archive, _ = compose_uefi_dir(archive, release)
 
280
        expected_contents = read_file(uefi_archive, 'grubnetx64.efi.signed')
 
281
        self.assertThat(tftp_path, FileContains(expected_contents))
 
282
 
 
283
    def test_updates_uefi_grubnet(self):
 
284
        arch = self.get_arch()
 
285
        release = 'precise'
 
286
        archive = self.make_downloads(arch=arch, release=release)
 
287
        tftp_path = os.path.join(self.tftproot, 'grubx64.efi')
 
288
        with open(tftp_path, 'w') as existing_file:
 
289
            existing_file.write(factory.getRandomString())
 
290
        self.call_script(archive, self.tftproot, arch=arch, release=release)
 
291
        uefi_archive, _ = compose_uefi_dir(archive, release)
 
292
        expected_contents = read_file(uefi_archive, 'grubnetx64.efi.signed')
 
293
        self.assertThat(tftp_path, FileContains(expected_contents))
 
294
 
232
295
    def test_procures_install_image(self):
233
296
        arch = self.get_arch()
234
297
        release = 'precise'
235
298
        archive = self.make_downloads(arch=arch, release=release)
236
299
        self.call_script(archive, self.tftproot, arch=arch, release=release)
237
300
        tftp_path = compose_tftp_path(
238
 
            self.tftproot, arch, release, 'install', 'linux')
 
301
            self.tftproot, arch, release, 'release', 'install', 'linux')
239
302
        _, download_path = compose_download_dir(archive, arch, release)
240
303
        expected_contents = read_file(
241
304
            download_path, compose_download_kernel_name(arch, release))
245
308
        arch = self.get_arch()
246
309
        release = 'precise'
247
310
        tftp_path = compose_tftp_path(
248
 
            self.tftproot, arch, release, 'install', 'linux')
 
311
            self.tftproot, arch, release, 'release', 'install', 'linux')
249
312
        os.makedirs(os.path.dirname(tftp_path))
250
313
        with open(tftp_path, 'w') as existing_file:
251
314
            existing_file.write(factory.getRandomString())
262
325
        archive = self.make_downloads(arch=arch, release=release)
263
326
        self.call_script(archive, self.tftproot, arch=arch, release=release)
264
327
        tftp_path = compose_tftp_path(
265
 
            self.tftproot, arch, release, 'install', 'linux')
 
328
            self.tftproot, arch, release, 'release', 'install', 'linux')
266
329
        backdate(tftp_path)
267
330
        original_timestamp = get_write_time(tftp_path)
268
331
        self.call_script(archive, self.tftproot, arch=arch, release=release)
280
343
 
281
344
        # The script does not install the broken image, and does not fail.
282
345
        installed_kernel = compose_tftp_path(
283
 
            self.tftproot, arch, release, 'initrd.gz')
 
346
            self.tftproot, arch, release, 'release', 'initrd.gz')
284
347
        self.assertThat(installed_kernel, Not(DirExists()))