~ubuntu-branches/ubuntu/saucy/maas/saucy-updates

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez, Julian Edwards, Raphaël Badin, Jeroen Vermeulen, Andres Rodriguez, Robie Basak, Scott Moser, Diogo Matsubara
  • Date: 2012-10-08 13:10:23 UTC
  • mfrom: (1.1.18)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20121008131023-68glibh0pbqrgtfq
Tags: 0.1+bzr1223+dfsg-0ubuntu1
* New upstream release. (LP: #1062518)

[ Julian Edwards ]
* Split packaging of 'maas' into maas-{region,cluster}-controller
  - debian/control: Update accordingly.
  - debian/*.install: Move files accordingly
  - debian/*.{postinst,postrm,preinst}: Move files accordingly.
* Ensure isc-dhcp-server is disabled when installing maas-dhcp.
* Ensure maas-dns creates the maas user before trying to chown files.
* Make maas-cluster-controller autoconfigure itself when upgrading from the
  old maas package. (LP: #1059416)
* Add missing prerm file for maas-cluster-controller so that .pyc files
  are cleaned up. (LP: #1059973)

[ Raphaël Badin ]
* Install maas_local_celeryconfig.py in /etc/maas and symlink to
  /usr/share/maas.
* debian/maas.postinst: Create rabbitmq celery user/vhost.
* debian/maas.postinst: Update BROKER_URL in maas_local_celeryconfig.py.
* Use maas_local_celeryconfig_cluster.py as the local celery
  configuration file for the cluster worker.
* debian/maas-region-controller.maas-region-celery.upstart: Add region
  worker upstart script.
* Rename cluster worker upstart script into
  maas-cluster-controller.maas-clluster-celery.upstart.
* maas-cluster-controller.maas-celery.upstart: use "celeryconfig_cluster"
  as the Celery config module.
* debian/maas-common.install: Install celeryconfig_common.py.
* debian/maas-cluster-controller.install: Install celeryconfig_cluster.py.
* debian/maas-region-controller.install: Install celeryconfig.py.
* Split celery config into cluster and region configs.
* Add region celeryd upstart config.
* Define CELERY_CONFIG_MODULE in
  maas-cluster-controller.maas-cluster-celery.upstart

[ Jeroen Vermeulen ]
* Make maas_local_celery_config.py non-world readable.
* Make maas_local_celeryconfig_cluster.py non-world readable.
* Set root:maas ownership of local cluster config only *after*
  the maas user/group have been created

[ Andres Rodriguez ]
* debian/maas.postinst:
  - Always restart apache2.
  - Handle upgrades for new upstream release.
  - Handle upgrades for celery rabbitmq worker.
* Add binary package to install client tool.
  - debian/extras/maas-cli: Add binary.
  - debian/maas-cli.install: Add. Install maascli and apiclient.
  - debian/control: Add binary package.
* debian/control:
  - Depends on freeipmi-tools instead of ipmitool.
  - Conflicts/Replaces on maas for python-maas-client.
  - Depends on python-netifaces, python-lxml.
* Add python-maas-client binary package:
  - debian/python-maas-client.install: Add. Install 'apiclient' python module.
  - debian/control: Add package. python-django-maas and maas-cli now
    Depend on it.
* debian/rules: Install maas-dhcp-server upstart job.
* debian/maas.postrm: Remove celery worker rabbitmq user and host.
* debian/extras/99-maas-sudoers: Add for maas-dhcp-server upstart job
  instead of isc-dhcp-server (LP: #1055951)
* debian/maas-region-controller.postinst: Cleanup upgrade rules.
* debian/maas-cluster-controller.postinst: Fix 'local' usage.
* debian/maas-common.install: Install celeryconfig in appropriate location.
* debian/maas-cluster-controller.postrm: Add and delete maas user.
* debian/maas-dhcp.postinst: Stop isc-dhcp-server not isc_dhcp_server.
* debian/maas-region-controller.postinst:
  - Always update passwords on upgrade. No longer check versioning. (LP: #1060094).
  - Add MAAS server to allowed mirror in squid-deb-proxy
  - Source dbconfig conf file for maas-region-controller on upgrade because
    it writes a new config file and no longer preservers the previous password.
* debian/maas-cluster-controller.maas-cluster-celery.upstart: Remove set{uid/gid}.
* debian/maas-region-controller.install: Install maas-import-squashfs
* Handle removal of non existant files (LP: #1059556):
  - debian/maintscript: Added to handle removal of conffiles.
  - debian/control: Add Pre-depends and bump debhelper version.
* update po files for the templates.
* debian/extras/99-maas: Install in usr/share/maas/conf and symlink to the
  appropriate etc dir.
* debian/maas-cluster-controller.config: Source debconf at the beginning of the
  script. (LP: #1063857)
* debian/patches/99-temporary-fix-constraints.patch: Fix constraints maaping
  when deploying with juju. Temporary until it gets merged upstream

[ Robie Basak ]
* Add maas-cluster-controller dependency on uuid-runtime, needed for uuidgen
  by postinst.

[ Scott Moser ]
* debian/maas-dhcp.{install,apparmor,postrm} install apparmor profile into
  /etc/apparmor.d/dhcpd.d (LP: #1049177), and update apparmor profile for
  /usr/sbin/dhcpd on install/remove
* get the ip address for the dhcp server in config

[ Diogo Matsubara ]
* Add initial tests to be run by autotests:
  - debian/control: XS-Testsuite: autopkgtest
  - debian/tests/control: Add
  - debian/tests/maas-package-test: Add
  - tests/maas-integration.py: Add

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 customize_config."""
 
5
 
 
6
from __future__ import (
 
7
    absolute_import,
 
8
    print_function,
 
9
    unicode_literals,
 
10
    )
 
11
 
 
12
__metaclass__ = type
 
13
__all__ = []
 
14
 
 
15
from argparse import ArgumentParser
 
16
from io import BytesIO
 
17
import os.path
 
18
from subprocess import (
 
19
    PIPE,
 
20
    Popen,
 
21
    )
 
22
import sys
 
23
from textwrap import dedent
 
24
 
 
25
from maastesting.factory import factory
 
26
from maastesting.testcase import TestCase
 
27
import provisioningserver
 
28
from provisioningserver import customize_config
 
29
from provisioningserver.utils import maas_custom_config_markers
 
30
 
 
31
 
 
32
def locate_dev_root():
 
33
    """Return root of development source tree."""
 
34
    return os.path.join(
 
35
        os.path.dirname(provisioningserver.__file__),
 
36
        os.pardir, os.pardir)
 
37
 
 
38
 
 
39
class TestCustomizeConfig(TestCase):
 
40
 
 
41
    def run_command(self, input_file, stdin):
 
42
        self.patch(sys, 'stdin', BytesIO(stdin.encode('utf-8')))
 
43
        self.patch(sys, 'stdout', BytesIO())
 
44
        parser = ArgumentParser()
 
45
        customize_config.add_arguments(parser)
 
46
        parsed_args = parser.parse_args((input_file, ))
 
47
        customize_config.run(parsed_args)
 
48
 
 
49
    def test_runs_as_script(self):
 
50
        original_text = factory.getRandomString()
 
51
        original_file = self.make_file(original_text)
 
52
        script = "%s/bin/maas-provision" % locate_dev_root()
 
53
        command = Popen(
 
54
            [script, "customize-config", original_file],
 
55
            stdin=PIPE, stdout=PIPE,
 
56
            env=dict(PYTHONPATH=":".join(sys.path), LC_ALL='en_US.UTF-8'))
 
57
        command.communicate(original_text)
 
58
        self.assertEqual(0, command.returncode)
 
59
 
 
60
    def test_produces_sensible_text(self):
 
61
        header, footer = maas_custom_config_markers
 
62
        original_file = self.make_file(contents="Original text here.")
 
63
 
 
64
        self.run_command(original_file, stdin="Custom section here.")
 
65
 
 
66
        sys.stdout.seek(0)
 
67
        expected = dedent("""\
 
68
            Original text here.
 
69
            %s
 
70
            Custom section here.
 
71
            %s
 
72
            """) % (header, footer)
 
73
        output = sys.stdout.read()
 
74
        self.assertEqual(expected, output.decode('utf-8'))
 
75
 
 
76
    def test_does_not_modify_original(self):
 
77
        original_text = factory.getRandomString().encode('ascii')
 
78
        original_file = self.make_file(contents=original_text)
 
79
 
 
80
        self.run_command(original_file, factory.getRandomString())
 
81
 
 
82
        with open(original_file, 'rb') as reread_file:
 
83
            contents_after = reread_file.read()
 
84
 
 
85
        self.assertEqual(original_text, contents_after)