~ubuntu-branches/ubuntu/raring/maas/raring-proposed

« back to all changes in this revision

Viewing changes to src/maasserver/tests/test_commands_install_pxe_bootloader.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-17 08:28:36 UTC
  • mfrom: (1.1.16)
  • Revision ID: package-import@ubuntu.com-20120717082836-ucb2vou8tqg353eq
Tags: 0.1+bzr777+dfsg-0ubuntu1
* New upstream release
* Only run 'maas' command as root. (LP: #974046)
  - debian/extras/maas: Check id.
  - debian/maas.install: Install in 'sbin'.
* debian/maas.postinst:
  - restart apache2 after everything gets processed.
  - Update version to handle upgrades.
* debian/extras/maas-provision: Add wrapper to access 'maasprovisiong'
  command line.
* debian/patches/99_temporary_fix_path.patch: Dropped. No longer needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2012 Canonical Ltd.  This software is licensed under the
2
 
# GNU Affero General Public License version 3 (see the file LICENSE).
3
 
 
4
 
"""Tests for the install_pxe_bootloader command."""
5
 
 
6
 
from __future__ import (
7
 
    absolute_import,
8
 
    print_function,
9
 
    unicode_literals,
10
 
    )
11
 
 
12
 
__metaclass__ = type
13
 
__all__ = []
14
 
 
15
 
import os.path
16
 
 
17
 
from django.core.management import call_command
18
 
from maasserver.management.commands.install_pxe_bootloader import (
19
 
    install_bootloader,
20
 
    make_destination,
21
 
    )
22
 
from maastesting.factory import factory
23
 
from maastesting.testcase import TestCase
24
 
from maastesting.utils import (
25
 
    age_file,
26
 
    get_write_time,
27
 
    )
28
 
from provisioningserver.pxe.tftppath import (
29
 
    compose_bootloader_path,
30
 
    locate_tftp_path,
31
 
    )
32
 
from testtools.matchers import (
33
 
    DirExists,
34
 
    FileContains,
35
 
    FileExists,
36
 
    Not,
37
 
    )
38
 
 
39
 
 
40
 
class TestInstallPXEBootloader(TestCase):
41
 
 
42
 
    def test_integration(self):
43
 
        loader = self.make_file()
44
 
        tftproot = self.make_dir()
45
 
        arch = factory.make_name('arch')
46
 
        subarch = factory.make_name('subarch')
47
 
 
48
 
        call_command(
49
 
            'install_pxe_bootloader', arch=arch, subarch=subarch,
50
 
            loader=loader, tftproot=tftproot)
51
 
 
52
 
        self.assertThat(
53
 
            locate_tftp_path(
54
 
                compose_bootloader_path(arch, subarch), tftproot=tftproot),
55
 
            FileExists())
56
 
        self.assertThat(loader, Not(FileExists()))
57
 
 
58
 
    def test_make_destination_creates_directory_if_not_present(self):
59
 
        tftproot = self.make_dir()
60
 
        arch = factory.make_name('arch')
61
 
        subarch = factory.make_name('subarch')
62
 
        dest = make_destination(tftproot, arch, subarch)
63
 
        self.assertThat(os.path.dirname(dest), DirExists())
64
 
 
65
 
    def test_make_destination_returns_existing_directory(self):
66
 
        tftproot = self.make_dir()
67
 
        arch = factory.make_name('arch')
68
 
        subarch = factory.make_name('subarch')
69
 
        make_destination(tftproot, arch, subarch)
70
 
        dest = make_destination(tftproot, arch, subarch)
71
 
        self.assertThat(os.path.dirname(dest), DirExists())
72
 
 
73
 
    def test_install_bootloader_installs_new_bootloader(self):
74
 
        contents = factory.getRandomString()
75
 
        loader = self.make_file(contents=contents)
76
 
        install_dir = self.make_dir()
77
 
        dest = os.path.join(install_dir, factory.make_name('loader'))
78
 
        install_bootloader(loader, dest)
79
 
        self.assertThat(dest, FileContains(contents))
80
 
 
81
 
    def test_install_bootloader_replaces_bootloader_if_changed(self):
82
 
        contents = factory.getRandomString()
83
 
        loader = self.make_file(contents=contents)
84
 
        dest = self.make_file(contents="Old contents")
85
 
        install_bootloader(loader, dest)
86
 
        self.assertThat(dest, FileContains(contents))
87
 
 
88
 
    def test_install_bootloader_skips_if_unchanged(self):
89
 
        contents = factory.getRandomString()
90
 
        dest = self.make_file(contents=contents)
91
 
        age_file(dest, 100)
92
 
        original_write_time = get_write_time(dest)
93
 
        loader = self.make_file(contents=contents)
94
 
        install_bootloader(loader, dest)
95
 
        self.assertThat(dest, FileContains(contents))
96
 
        self.assertEqual(original_write_time, get_write_time(dest))
97
 
 
98
 
    def test_install_bootloader_sweeps_aside_dot_new_if_any(self):
99
 
        contents = factory.getRandomString()
100
 
        loader = self.make_file(contents=contents)
101
 
        dest = self.make_file(contents="Old contents")
102
 
        temp_file = '%s.new' % dest
103
 
        factory.make_file(
104
 
            os.path.dirname(temp_file), name=os.path.basename(temp_file))
105
 
        install_bootloader(loader, dest)
106
 
        self.assertThat(dest, FileContains(contents))