~ubuntu-branches/ubuntu/utopic/maas/utopic-security

« back to all changes in this revision

Viewing changes to src/provisioningserver/utils/tests/test_curtin.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez, Jeroen Vermeulen, Andres Rodriguez, Jason Hobbs, Raphaël Badin, Louis Bouchard, Gavin Panella
  • Date: 2014-08-21 19:36:30 UTC
  • mfrom: (1.3.1)
  • Revision ID: package-import@ubuntu.com-20140821193630-kertpu5hd8yyss8h
Tags: 1.7.0~beta7+bzr3266-0ubuntu1
* New Upstream Snapshot, Beta 7 bzr3266

[ Jeroen Vermeulen ]
* debian/extras/99-maas-sudoers
  debian/maas-dhcp.postinst
  debian/rules
  - Add second DHCP server instance for IPv6.
* debian/maas-region-controller-min.install
  debian/maas-region-controller-min.lintian-overrides
  - Install deployment user-data: maas_configure_interfaces.py script.
* debian/maas-cluster-controller.links
  debian/maas-cluster-controller.install
  debian/maas-cluster-controller.postinst
  - Reflect Celery removal changes made in trunk r3067.
  - Don't install celeryconfig_cluster.py any longer. 
  - Don't install maas_local_celeryconfig_cluster.py any longer.
  - Don't symlink maas_local_celeryconfig_cluster.py from /etc to /usr.
  - Don't insert UUID into maas_local_celeryconfig_cluster.py.

[ Andres Rodriguez ]
* debian/maas-region-controller-min.postrm: Cleanup lefover files.
* debian/maas-dhcp.postrm: Clean leftover configs.
* Provide new maas-proxy package that replaces the usage of
  squid-deb-proxy:
  - debian/control: New maas-proxy package that replaces the usage
    of squid-deb-proxy; Drop depends on squid-deb-proxy.
  - Add upstrart job.
  - Ensure squid3 is stopped as maas-proxy uses a caching proxy.
* Remove Celery references to cluster controller:
  - Rename upstart job from maas-pserv to maas-cluster; rename
    maas-cluster-celery to maas-cluster-register. Ensure services
    are stopped on upgrade.
  - debian/maintscript: Cleanup config files.
  - Remove all references to the MAAS celery daemon and config
    files as we don't use it like that anymore
* Move some entries in debian/maintscript to
  debian/maas-cluster-controller.maintscript
* Remove usage of txlongpoll and rabbitmq-server. Handle upgrades
  to ensure these are removed correctly.

[ Jason Hobbs ]
* debian/maas-region-controller-min.install: Install
  maas-generate-winrm-cert script.

[ Raphaël Badin ]
* debian/extras/maas-region-admin: Bypass django-admin as it prints
  spurious messages to stdout (LP: #1365130).

[Louis Bouchard]
* debian/maas-cluster-controller.postinst:
  - Exclude /var/log/maas/rsyslog when changing ownership
    (LP: #1346703)

[Gavin Panella]
* debian/maas-cluster-controller.maas-clusterd.upstart:
  - Don't start-up the cluster controller unless a shared-secret has
    been installed.
* debian/maas-cluster-controller.maas-cluster-register.upstart: Drop.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2014 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Tests for Curtin-related utilities."""
 
5
 
 
6
from __future__ import (
 
7
    absolute_import,
 
8
    print_function,
 
9
    unicode_literals,
 
10
    )
 
11
 
 
12
str = None
 
13
 
 
14
__metaclass__ = type
 
15
__all__ = []
 
16
 
 
17
from maastesting.factory import factory
 
18
from maastesting.testcase import MAASTestCase
 
19
from provisioningserver.utils.curtin import (
 
20
    compose_mv_command,
 
21
    compose_write_text_file,
 
22
    )
 
23
from testtools.matchers import (
 
24
    AllMatch,
 
25
    ContainsAll,
 
26
    IsInstance,
 
27
    )
 
28
 
 
29
 
 
30
class TestComposeMvCommand(MAASTestCase):
 
31
 
 
32
    def test__returns_command_list(self):
 
33
        command = compose_mv_command(
 
34
            factory.make_name('source'), factory.make_name('dest'))
 
35
        self.expectThat(command, IsInstance(list))
 
36
        self.expectThat(command, AllMatch(IsInstance(unicode)))
 
37
 
 
38
    def test__runs_command_in_target(self):
 
39
        command = compose_mv_command(
 
40
            factory.make_name('source'), factory.make_name('dest'))
 
41
        self.assertEqual(['curtin', 'in-target', '--'], command[:3])
 
42
 
 
43
    def test__moves_file(self):
 
44
        source = factory.make_name('source')
 
45
        dest = factory.make_name('dest')
 
46
        self.assertEqual(
 
47
            ['mv', '--', source, dest],
 
48
            compose_mv_command(source, dest)[-4:])
 
49
 
 
50
 
 
51
class TestComposeWriteTextFile(MAASTestCase):
 
52
 
 
53
    def test__returns_complete_write_file_dict(self):
 
54
        preseed = compose_write_text_file(
 
55
            factory.make_name('file'), factory.make_name('content'))
 
56
        self.expectThat(preseed, IsInstance(dict))
 
57
        self.expectThat(
 
58
            preseed.keys(),
 
59
            ContainsAll(['path', 'content', 'owner', 'permissions']))
 
60
 
 
61
    def test__obeys_path_param(self):
 
62
        path = factory.make_name('path')
 
63
        preseed = compose_write_text_file(path, factory.make_name('content'))
 
64
        self.assertEqual(path, preseed['path'])
 
65
 
 
66
    def test__obeys_content_param(self):
 
67
        content = factory.make_name('content')
 
68
        preseed = compose_write_text_file(factory.make_name('path'), content)
 
69
        self.assertEqual(content, preseed['content'])
 
70
 
 
71
    def test__defaults_owner_to_root(self):
 
72
        preseed = compose_write_text_file(
 
73
            factory.make_name('file'), factory.make_name('content'))
 
74
        self.assertEqual('root:root', preseed['owner'])
 
75
 
 
76
    def test__obeys_owner_param(self):
 
77
        owner = '%s:%s' % (
 
78
            factory.make_name('user'),
 
79
            factory.make_name('group'),
 
80
            )
 
81
        preseed = compose_write_text_file(
 
82
            factory.make_name('file'), factory.make_name('content'),
 
83
            owner=owner)
 
84
        self.assertEqual(owner, preseed['owner'])
 
85
 
 
86
    def test__defaults_permissions_to_0600(self):
 
87
        preseed = compose_write_text_file(
 
88
            factory.make_name('file'), factory.make_name('content'))
 
89
        self.assertEqual('0600', preseed['permissions'])
 
90
 
 
91
    def test__obeys_permissions_param(self):
 
92
        permissions = 0123
 
93
        preseed = compose_write_text_file(
 
94
            factory.make_name('file'), factory.make_name('content'),
 
95
            permissions=permissions)
 
96
        self.assertEqual('0123', preseed['permissions'])