~oddbloke/cloud-init/fix-gce-az

« back to all changes in this revision

Viewing changes to tests/unittests/test_distros/test_generic.py

  • Committer: Daniel Watkins
  • Date: 2015-07-22 12:06:34 UTC
  • Revision ID: daniel.watkins@canonical.com-20150722120634-wsg8rwzcaanhc2pn
Make full data source available to code that handles mirror selection.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
import shutil
8
8
import tempfile
9
9
 
 
10
try:
 
11
    from unittest import mock
 
12
except ImportError:
 
13
    import mock
 
14
 
10
15
unknown_arch_info = {
11
16
    'arches': ['default'],
12
17
    'failsafe': {'primary': 'http://fs-primary-default',
144
149
 
145
150
    def test_get_package_mirror_info_az_ec2(self):
146
151
        arch_mirrors = gapmi(package_mirrors, arch="amd64")
 
152
        data_source_mock = mock.Mock(availability_zone="us-east-1a")
147
153
 
148
 
        results = gpmi(arch_mirrors, availability_zone="us-east-1a",
 
154
        results = gpmi(arch_mirrors, data_source=data_source_mock,
149
155
                       mirror_filter=self.return_first)
150
156
        self.assertEqual(results,
151
157
                         {'primary': 'http://us-east-1.ec2/',
152
158
                          'security': 'http://security-mirror1-intel'})
153
159
 
154
 
        results = gpmi(arch_mirrors, availability_zone="us-east-1a",
 
160
        results = gpmi(arch_mirrors, data_source=data_source_mock,
155
161
                       mirror_filter=self.return_second)
156
162
        self.assertEqual(results,
157
163
                         {'primary': 'http://us-east-1a.clouds/',
158
164
                          'security': 'http://security-mirror2-intel'})
159
165
 
160
 
        results = gpmi(arch_mirrors, availability_zone="us-east-1a",
 
166
        results = gpmi(arch_mirrors, data_source=data_source_mock,
161
167
                       mirror_filter=self.return_none)
162
168
        self.assertEqual(results, package_mirrors[0]['failsafe'])
163
169
 
164
170
    def test_get_package_mirror_info_az_non_ec2(self):
165
171
        arch_mirrors = gapmi(package_mirrors, arch="amd64")
 
172
        data_source_mock = mock.Mock(availability_zone="nova.cloudvendor")
166
173
 
167
 
        results = gpmi(arch_mirrors, availability_zone="nova.cloudvendor",
 
174
        results = gpmi(arch_mirrors, data_source=data_source_mock,
168
175
                       mirror_filter=self.return_first)
169
176
        self.assertEqual(results,
170
177
                         {'primary': 'http://nova.cloudvendor.clouds/',
171
178
                          'security': 'http://security-mirror1-intel'})
172
179
 
173
 
        results = gpmi(arch_mirrors, availability_zone="nova.cloudvendor",
 
180
        results = gpmi(arch_mirrors, data_source=data_source_mock,
174
181
                       mirror_filter=self.return_last)
175
182
        self.assertEqual(results,
176
183
                         {'primary': 'http://nova.cloudvendor.clouds/',
178
185
 
179
186
    def test_get_package_mirror_info_none(self):
180
187
        arch_mirrors = gapmi(package_mirrors, arch="amd64")
 
188
        data_source_mock = mock.Mock(availability_zone=None)
181
189
 
182
190
        # because both search entries here replacement based on
183
191
        # availability-zone, the filter will be called with an empty list and
184
192
        # failsafe should be taken.
185
 
        results = gpmi(arch_mirrors, availability_zone=None,
 
193
        results = gpmi(arch_mirrors, data_source=data_source_mock,
186
194
                       mirror_filter=self.return_first)
187
195
        self.assertEqual(results,
188
196
                         {'primary': 'http://fs-primary-intel',
189
197
                          'security': 'http://security-mirror1-intel'})
190
198
 
191
 
        results = gpmi(arch_mirrors, availability_zone=None,
 
199
        results = gpmi(arch_mirrors, data_source=data_source_mock,
192
200
                       mirror_filter=self.return_last)
193
201
        self.assertEqual(results,
194
202
                         {'primary': 'http://fs-primary-intel',
195
203
                          'security': 'http://security-mirror2-intel'})
196
204
 
 
205
    def test_systemd_in_use(self):
 
206
        cls = distros.fetch("ubuntu")
 
207
        d = cls("ubuntu", {}, None)
 
208
        self.patchOS(self.tmp)
 
209
        self.patchUtils(self.tmp)
 
210
        os.makedirs('/run/systemd/system')
 
211
        self.assertTrue(d.uses_systemd())
 
212
 
 
213
    def test_systemd_not_in_use(self):
 
214
        cls = distros.fetch("ubuntu")
 
215
        d = cls("ubuntu", {}, None)
 
216
        self.patchOS(self.tmp)
 
217
        self.patchUtils(self.tmp)
 
218
        self.assertFalse(d.uses_systemd())
 
219
 
 
220
    def test_systemd_symlink(self):
 
221
        cls = distros.fetch("ubuntu")
 
222
        d = cls("ubuntu", {}, None)
 
223
        self.patchOS(self.tmp)
 
224
        self.patchUtils(self.tmp)
 
225
        os.makedirs('/run/systemd')
 
226
        os.symlink('/', '/run/systemd/system')
 
227
        self.assertFalse(d.uses_systemd())
197
228
 
198
229
# def _get_package_mirror_info(mirror_info, availability_zone=None,
199
230
#                             mirror_filter=util.search_for_mirror):