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

« back to all changes in this revision

Viewing changes to src/metadataserver/commissioning/tests/test_snippets.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 2012-2014 Canonical Ltd.  This software is licensed under the
2
 
# GNU Affero General Public License version 3 (see the file LICENSE).
3
 
 
4
 
"""Test the snippets-related support routines for commissioning user data."""
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
 
import os.path
18
 
 
19
 
from maastesting.factory import factory
20
 
from maastesting.testcase import MAASTestCase
21
 
from metadataserver.commissioning.snippets import (
22
 
    get_snippet_context,
23
 
    is_snippet,
24
 
    list_snippets,
25
 
    read_snippet,
26
 
    strip_name,
27
 
    )
28
 
 
29
 
 
30
 
class TestSnippets(MAASTestCase):
31
 
 
32
 
    def test_read_snippet_reads_snippet_file(self):
33
 
        contents = factory.make_string()
34
 
        snippet = self.make_file(contents=contents)
35
 
        self.assertEqual(
36
 
            contents,
37
 
            read_snippet(os.path.dirname(snippet), os.path.basename(snippet)))
38
 
 
39
 
    def test_strip_name_leaves_simple_names_intact(self):
40
 
        simple_name = factory.make_string()
41
 
        self.assertEqual(simple_name, strip_name(simple_name))
42
 
 
43
 
    def test_strip_name_replaces_dots(self):
44
 
        self.assertEqual('_x_y_', strip_name('.x.y.'))
45
 
 
46
 
    def test_is_snippet(self):
47
 
        are_snippets = {
48
 
            'snippet': True,
49
 
            'with-dash': True,
50
 
            'module.py': True,
51
 
            '.backup': False,
52
 
            'backup~': False,
53
 
            'module.pyc': False,
54
 
            '__init__.pyc': False,
55
 
            'tests': False,
56
 
        }
57
 
        self.assertEqual(
58
 
            are_snippets,
59
 
            {name: is_snippet(name) for name in are_snippets})
60
 
 
61
 
    def test_list_snippets(self):
62
 
        snippets_dir = self.make_dir()
63
 
        factory.make_file(snippets_dir, 'snippet')
64
 
        factory.make_file(snippets_dir, '.backup.pyc')
65
 
        self.assertItemsEqual(['snippet'], list_snippets(snippets_dir))
66
 
 
67
 
    def test_get_snippet_context(self):
68
 
        contents = factory.make_string()
69
 
        snippets_dir = self.make_dir()
70
 
        factory.make_file(snippets_dir, 'snippet.py', contents=contents)
71
 
        self.assertItemsEqual(
72
 
            {'snippet_py': contents},
73
 
            get_snippet_context(snippets_dir=snippets_dir))
74
 
 
75
 
    def test_get_snippet_context_empty_if_no_snippets(self):
76
 
        snippets_dir = self.make_dir()
77
 
        context = {}
78
 
        self.assertEqual(
79
 
            context, get_snippet_context(snippets_dir=snippets_dir))