~ubuntu-branches/ubuntu/precise/cloud-init/precise-updates

« back to all changes in this revision

Viewing changes to tests/unittests/test_datasource/test_maas.py

  • Committer: Package Import Robot
  • Author(s): Scott Moser
  • Date: 2012-03-16 14:12:38 UTC
  • mfrom: (174.1.12 precise)
  • Revision ID: package-import@ubuntu.com-20120316141238-iat4fh6u9qn4dn3d
Tags: 0.6.3~bzr547-0ubuntu1
* New upstream snapshot.
  * rename DataSourceMaaS to DataSourceMAAS.
  * support public-keys in DataSourceMAAS
  * Warn in user-data processing on non-multipart, non-handled data 
  * CloudStack data source added (not enabled by default)
* fix bug in cloud-init.postinst where the name used was wrong
  causing config-apt-pipelining to run more than intended

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
import os
4
4
from StringIO import StringIO
5
5
from copy import copy
6
 
from cloudinit.DataSourceMaaS import (
7
 
    MaasSeedDirNone,
8
 
    MaasSeedDirMalformed,
 
6
from cloudinit.DataSourceMAAS import (
 
7
    MAASSeedDirNone,
 
8
    MAASSeedDirMalformed,
9
9
    read_maas_seed_dir,
10
10
    read_maas_seed_url,
11
11
)
12
12
from mocker import MockerTestCase
13
13
 
14
14
 
15
 
class TestMaasDataSource(MockerTestCase):
 
15
class TestMAASDataSource(MockerTestCase):
16
16
 
17
17
    def setUp(self):
18
 
        super(TestMaasDataSource, self).setUp()
 
18
        super(TestMAASDataSource, self).setUp()
19
19
        # Make a temp directoy for tests to use.
20
20
        self.tmp = mkdtemp(prefix="unittest_")
21
21
 
22
22
    def tearDown(self):
23
 
        super(TestMaasDataSource, self).tearDown()
 
23
        super(TestMAASDataSource, self).tearDown()
24
24
        # Clean up temp directory
25
25
        rmtree(self.tmp)
26
26
 
29
29
 
30
30
        data = {'instance-id': 'i-valid01',
31
31
            'local-hostname': 'valid01-hostname',
32
 
            'user-data': 'valid01-userdata'}
 
32
            'user-data': 'valid01-userdata',
 
33
            'public-keys': 'ssh-rsa AAAAB3Nz...aC1yc2E= keyname'}
33
34
 
34
35
        my_d = os.path.join(self.tmp, "valid")
35
36
        populate_dir(my_d, data)
63
64
        self.assertFalse(('foo' in metadata))
64
65
 
65
66
    def test_seed_dir_invalid(self):
66
 
        """Verify that invalid seed_dir raises MaasSeedDirMalformed"""
 
67
        """Verify that invalid seed_dir raises MAASSeedDirMalformed"""
67
68
 
68
69
        valid = {'instance-id': 'i-instanceid',
69
70
            'local-hostname': 'test-hostname', 'user-data': ''}
75
76
        invalid_data = copy(valid)
76
77
        del invalid_data['local-hostname']
77
78
        populate_dir(my_d, invalid_data)
78
 
        self.assertRaises(MaasSeedDirMalformed, read_maas_seed_dir, my_d)
 
79
        self.assertRaises(MAASSeedDirMalformed, read_maas_seed_dir, my_d)
79
80
 
80
81
        # missing 'instance-id'
81
82
        my_d = "%s-02" % my_based
82
83
        invalid_data = copy(valid)
83
84
        del invalid_data['instance-id']
84
85
        populate_dir(my_d, invalid_data)
85
 
        self.assertRaises(MaasSeedDirMalformed, read_maas_seed_dir, my_d)
 
86
        self.assertRaises(MAASSeedDirMalformed, read_maas_seed_dir, my_d)
86
87
 
87
88
    def test_seed_dir_none(self):
88
 
        """Verify that empty seed_dir raises MaasSeedDirNone"""
 
89
        """Verify that empty seed_dir raises MAASSeedDirNone"""
89
90
 
90
91
        my_d = os.path.join(self.tmp, "valid_empty")
91
 
        self.assertRaises(MaasSeedDirNone, read_maas_seed_dir, my_d)
 
92
        self.assertRaises(MAASSeedDirNone, read_maas_seed_dir, my_d)
92
93
 
93
94
    def test_seed_dir_missing(self):
94
 
        """Verify that missing seed_dir raises MaasSeedDirNone"""
95
 
        self.assertRaises(MaasSeedDirNone, read_maas_seed_dir,
 
95
        """Verify that missing seed_dir raises MAASSeedDirNone"""
 
96
        self.assertRaises(MAASSeedDirNone, read_maas_seed_dir,
96
97
            os.path.join(self.tmp, "nonexistantdirectory"))
97
98
 
98
99
    def test_seed_url_valid(self):
99
100
        """Verify that valid seed_url is read as such"""
100
101
        valid = {'meta-data/instance-id': 'i-instanceid',
101
102
            'meta-data/local-hostname': 'test-hostname',
 
103
            'meta-data/public-keys': 'test-hostname',
102
104
            'user-data': 'foodata'}
103
105
 
104
106
        my_seed = "http://example.com/xmeta"
133
135
            valid['meta-data/local-hostname'])
134
136
 
135
137
    def test_seed_url_invalid(self):
136
 
        """Verify that invalid seed_url raises MaasSeedDirMalformed"""
 
138
        """Verify that invalid seed_url raises MAASSeedDirMalformed"""
137
139
        pass
138
140
 
139
141
    def test_seed_url_missing(self):
140
 
        """Verify seed_url with no found entries raises MaasSeedDirNone"""
 
142
        """Verify seed_url with no found entries raises MAASSeedDirNone"""
141
143
        pass
142
144
 
143
145