~registry/ubuntu-system-image/client

« back to all changes in this revision

Viewing changes to systemimage/tests/test_channel.py

  • Committer: Barry Warsaw
  • Date: 2015-01-16 22:56:50 UTC
  • mfrom: (293.1.18 lp1373467)
  • Revision ID: barry@python.org-20150116225650-fug42a0rd33g3gb2
 * Support multiple configuration files, as in a ``config.d`` directory.  Now,
   configuration files are named `NN_whatever.ini` where "NN" must be a
   numeric prefix.  Files are loaded in sorted numeric order, with later files
   overriding newer files.  Support for both the ``client.ini`` and
   ``channel.ini`` files has been removed. (LP: #1373467)
 * The ``[system]build_file`` variable has been removed.  Build number
   information now must come from the ``.ini`` files, and last update date
   comes from the newest ``.ini`` file loaded.

Also:

 * Manpages updated.
 * Removed support for the [system]build_file variable.
 * Massive renaming of test data files for better matchup with their
   associated tests.
 * Provide a little more information when a logging level command line
   parameter is a bogus value.
 * -C now takes path to configuration directory.
 * Add a little more debug-level logging.
 * More sophistication for the @configuration decorator.
 * touch_build() helper now takes a use_config optional keyword argument.
 * When running the test suite, -M now takes a full logging specifier,
   e.g. either a single word like `debug` or a split like `info:debug`.
 * Skip some tests when running under UDM, due to LP: #1411866

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
        # Test that parsing a simple top level channels.json file produces the
46
46
        # expected set of channels.  The Nexus 7 daily images have a device
47
47
        # specific keyring.
48
 
        channels = get_channels('channels_01.json')
 
48
        channels = get_channels('channel.channels_01.json')
49
49
        self.assertEqual(channels.daily.devices.nexus7.index,
50
50
                         '/daily/nexus7/index.json')
51
51
        self.assertEqual(channels.daily.devices.nexus7.keyring.path,
61
61
 
62
62
    def test_getattr_failure(self):
63
63
        # Test the getattr syntax on an unknown channel or device combination.
64
 
        channels = get_channels('channels_01.json')
 
64
        channels = get_channels('channel.channels_01.json')
65
65
        self.assertRaises(AttributeError, getattr, channels, 'bleeding')
66
66
        self.assertRaises(AttributeError, getattr, channels.stable, 'nexus3')
67
67
 
68
68
    def test_daily_proposed(self):
69
69
        # The channel name has a dash in it.
70
 
        channels = get_channels('channels_07.json')
 
70
        channels = get_channels('channel.channels_02.json')
71
71
        self.assertEqual(channels['daily-proposed'].devices.grouper.index,
72
72
                         '/daily-proposed/grouper/index.json')
73
73
 
74
74
    def test_bad_getitem(self):
75
75
        # Trying to get a channel via getitem which doesn't exist.
76
 
        channels = get_channels('channels_07.json')
 
76
        channels = get_channels('channel.channels_02.json')
77
77
        self.assertRaises(KeyError, getitem, channels, 'daily-testing')
78
78
 
79
79
    def test_channel_version(self):
80
80
        # The channel name has a dot in it.
81
 
        channels = get_channels('channels_08.json')
 
81
        channels = get_channels('channel.channels_03.json')
82
82
        self.assertEqual(channels['13.10'].devices.grouper.index,
83
83
                         '/13.10/grouper/index.json')
84
84
 
85
85
    def test_channel_version_proposed(self):
86
86
        # The channel name has both a dot and a dash in it.
87
 
        channels = get_channels('channels_08.json')
 
87
        channels = get_channels('channel.channels_03.json')
88
88
        self.assertEqual(channels['14.04-proposed'].devices.grouper.index,
89
89
                         '/14.04-proposed/grouper/index.json')
90
90
 
103
103
            self._serverdir = self._stack.enter_context(temporary_directory())
104
104
            self._stack.push(make_http_server(
105
105
                self._serverdir, 8943, 'cert.pem', 'key.pem'))
106
 
            copy('channels_01.json', self._serverdir, 'channels.json')
 
106
            copy('channel.channels_01.json', self._serverdir, 'channels.json')
107
107
            self._channels_path = os.path.join(
108
108
                self._serverdir, 'channels.json')
109
109
        except:
124
124
                         '/daily/nexus7/device-keyring.tar.xz.asc')
125
125
 
126
126
    @configuration
127
 
    def test_load_channel_bad_signature(self, ini_file):
 
127
    def test_load_channel_bad_signature(self):
128
128
        # We get an error if the signature on the channels.json file is bad.
129
129
        sign(self._channels_path, 'spare.gpg')
130
130
        setup_keyrings()
148
148
        self.assertRaises(SignatureError, next, self._state)
149
149
 
150
150
    @configuration
151
 
    def test_load_channel_bad_signature_gets_fixed(self, ini_file):
 
151
    def test_load_channel_bad_signature_gets_fixed(self, config_d):
152
152
        # Like above, but the second download of the image signing key results
153
153
        # in a properly signed channels.json file.
154
154
        sign(self._channels_path, 'spare.gpg')
165
165
                          os.path.join(self._serverdir, 'gpg',
166
166
                                       'image-signing.tar.xz'))
167
167
        # This will succeed by grabbing a new image-signing key.
168
 
        config = Configuration(ini_file)
 
168
        config = Configuration(config_d)
169
169
        with open(config.gpg.image_signing, 'rb') as fp:
170
170
            checksum = hashlib.md5(fp.read()).digest()
171
171
        next(self._state)
180
180
            '/daily/nexus7/device-keyring.tar.xz.asc')
181
181
 
182
182
    @configuration
183
 
    def test_load_channel_blacklisted_signature(self, ini_file):
 
183
    def test_load_channel_blacklisted_signature(self, config_d):
184
184
        # We get an error if the signature on the channels.json file is good
185
185
        # but the key is blacklisted.
186
186
        sign(self._channels_path, 'image-signing.gpg')
193
193
        # cause the state machine to try to download a new image signing key,
194
194
        # so let's put the cached one up on the server.  This will still be
195
195
        # backlisted though.
196
 
        config = Configuration(ini_file)
 
196
        config = Configuration(config_d)
197
197
        key_path = os.path.join(self._serverdir, 'gpg', 'image-signing.tar.xz')
198
198
        shutil.copy(config.gpg.image_signing, key_path)
199
199
        shutil.copy(config.gpg.image_signing + '.asc', key_path + '.asc')
215
215
        self._stack = ExitStack()
216
216
        try:
217
217
            self._serverdir = self._stack.enter_context(temporary_directory())
218
 
            copy('channels_01.json', self._serverdir, 'channels.json')
 
218
            copy('channel.channels_01.json', self._serverdir, 'channels.json')
219
219
            sign(os.path.join(self._serverdir, 'channels.json'),
220
220
                 'image-signing.gpg')
221
221
        except:
242
242
    """LP: #1221841 introduces a new format to channels.json."""
243
243
    def test_channels(self):
244
244
        # We can parse new-style channels.json files.
245
 
        channels = get_channels('channels_09.json')
 
245
        channels = get_channels('channel.channels_04.json')
246
246
        self.assertEqual(channels.daily.alias, 'saucy')
247
247
        self.assertEqual(channels.daily.devices.grouper.index,
248
248
                         '/daily/grouper/index.json')
262
262
 
263
263
    def test_hidden_defaults_to_false(self):
264
264
        # If a channel does not have a hidden field, it defaults to false.
265
 
        channels = get_channels('channels_09.json')
 
265
        channels = get_channels('channel.channels_04.json')
266
266
        self.assertFalse(channels.daily.hidden)
267
267
 
268
268
    def test_getattr_failure(self):
269
269
        # Test the getattr syntax on an unknown channel or device combination.
270
 
        channels = get_channels('channels_09.json')
 
270
        channels = get_channels('channel.channels_04.json')
271
271
        self.assertRaises(AttributeError, getattr, channels, 'bleeding')
272
272
        self.assertRaises(
273
273
            AttributeError, getattr, channels.daily.devices, 'nexus3')
274
274
 
275
275
    def test_daily_proposed(self):
276
276
        # The channel name has a dash in it.
277
 
        channels = get_channels('channels_09.json')
 
277
        channels = get_channels('channel.channels_04.json')
278
278
        self.assertEqual(channels['saucy-proposed'].devices.grouper.index,
279
279
                         '/saucy-proposed/grouper/index.json')
280
280
 
281
281
    def test_bad_getitem(self):
282
282
        # Trying to get a channel via getitem which doesn't exist.
283
 
        channels = get_channels('channels_09.json')
 
283
        channels = get_channels('channel.channels_04.json')
284
284
        self.assertRaises(KeyError, getitem, channels, 'daily-testing')