~lutostag/ubuntu/utopic/maas/1.5.2

« back to all changes in this revision

Viewing changes to src/provisioningserver/boot/tests/test_uefi.py

  • Committer: Greg Lutostanski
  • Date: 2014-06-02 17:15:15 UTC
  • Revision ID: gregory.lutostanski@canonical.com-20140602171515-imbicaxmaxxmhz39
 - Fix NodeForm's is_valid() method so that it uses Django's way of setting
   errors on forms instead of putting text in self.errors['architecture']
   (LP: #1301465)
 - Change BootMethods to return their own IReader per-request, update method
   names to reflect new usage. (LP: #1315154)
 - Return early and stop the DHCP server when the list of managed interfaces
   of the nodegroup is empty. (LP: #1324944)
 - Fix invalid attribute references in the VirshSSH class. Added more test
   for the VirshSSH class. (LP: #1324966)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from maastesting.factory import factory
20
20
from maastesting.testcase import MAASTestCase
 
21
from provisioningserver.boot import BytesReader
21
22
from provisioningserver.boot.tftppath import compose_image_path
22
23
from provisioningserver.boot.uefi import (
23
24
    re_config_file,
60
61
class TestRenderUEFIConfig(MAASTestCase):
61
62
    """Tests for `provisioningserver.boot.uefi.UEFIBootMethod`."""
62
63
 
63
 
    def test_render(self):
 
64
    def test_get_reader(self):
64
65
        # Given the right configuration options, the UEFI configuration is
65
66
        # correctly rendered.
66
67
        method = UEFIBootMethod()
67
68
        params = make_kernel_parameters(purpose="install")
68
 
        output = method.render_config(kernel_params=params)
69
 
        # The output is always a Unicode string.
70
 
        self.assertThat(output, IsInstance(unicode))
 
69
        output = method.get_reader(backend=None, kernel_params=params)
 
70
        # The output is a BytesReader.
 
71
        self.assertThat(output, IsInstance(BytesReader))
 
72
        output = output.read(10000)
71
73
        # The template has rendered without error. UEFI configurations
72
74
        # typically start with a DEFAULT line.
73
75
        self.assertThat(output, StartsWith("set default=\"0\""))
85
87
                    r'.*^\s+initrd %s/di-initrd$' % re.escape(image_dir),
86
88
                    re.MULTILINE | re.DOTALL)))
87
89
 
88
 
    def test_render_with_extra_arguments_does_not_affect_output(self):
89
 
        # render_config() allows any keyword arguments as a safety valve.
 
90
    def test_get_reader_with_extra_arguments_does_not_affect_output(self):
 
91
        # get_reader() allows any keyword arguments as a safety valve.
90
92
        method = UEFIBootMethod()
91
93
        options = {
 
94
            "backend": None,
92
95
            "kernel_params": make_kernel_parameters(purpose="install"),
93
96
        }
94
97
        # Capture the output before sprinking in some random options.
95
 
        output_before = method.render_config(**options)
 
98
        output_before = method.get_reader(**options).read(10000)
96
99
        # Sprinkle some magic in.
97
100
        options.update(
98
101
            (factory.make_name("name"), factory.make_name("value"))
99
102
            for _ in range(10))
100
103
        # Capture the output after sprinking in some random options.
101
 
        output_after = method.render_config(**options)
 
104
        output_after = method.get_reader(**options).read(10000)
102
105
        # The generated template is the same.
103
106
        self.assertEqual(output_before, output_after)
104
107
 
105
 
    def test_render_config_with_local_purpose(self):
 
108
    def test_get_reader_with_local_purpose(self):
106
109
        # If purpose is "local", the config.localboot.template should be
107
110
        # used.
108
111
        method = UEFIBootMethod()
109
112
        options = {
 
113
            "backend": None,
110
114
            "kernel_params": make_kernel_parameters(
111
115
                purpose="local", arch="amd64"),
112
116
            }
113
 
        output = method.render_config(**options)
 
117
        output = method.get_reader(**options).read(10000)
114
118
        self.assertIn("configfile /efi/ubuntu/grub.cfg", output)
115
119
 
116
120