~harlowja/cloud-init/cloud-init-net-refactor

« back to all changes in this revision

Viewing changes to tests/unittests/test_data.py

Enable flake8 and fix a large amount of reported issues

Show diffs side-by-side

added added

removed removed

Lines of Context:
106
106
        ci.consume_data()
107
107
        cc_contents = util.load_file(ci.paths.get_ipath("cloud_config"))
108
108
        cc = util.load_yaml(cc_contents)
109
 
        self.assertEquals(2, len(cc))
110
 
        self.assertEquals('qux', cc['baz'])
111
 
        self.assertEquals('qux2', cc['bar'])
 
109
        self.assertEqual(2, len(cc))
 
110
        self.assertEqual('qux', cc['baz'])
 
111
        self.assertEqual('qux2', cc['bar'])
112
112
 
113
113
    def test_simple_jsonp_vendor_and_user(self):
114
114
        # test that user-data wins over vendor
145
145
        (_which_ran, _failures) = mods.run_section('cloud_init_modules')
146
146
        cfg = mods.cfg
147
147
        self.assertIn('vendor_data', cfg)
148
 
        self.assertEquals('qux', cfg['baz'])
149
 
        self.assertEquals('qux2', cfg['bar'])
150
 
        self.assertEquals('quxC', cfg['foo'])
 
148
        self.assertEqual('qux', cfg['baz'])
 
149
        self.assertEqual('qux2', cfg['bar'])
 
150
        self.assertEqual('quxC', cfg['foo'])
151
151
 
152
152
    def test_simple_jsonp_no_vendor_consumed(self):
153
153
        # make sure that vendor data is not consumed
184
184
        mods = stages.Modules(initer)
185
185
        (_which_ran, _failures) = mods.run_section('cloud_init_modules')
186
186
        cfg = mods.cfg
187
 
        self.assertEquals('qux', cfg['baz'])
188
 
        self.assertEquals('qux2', cfg['bar'])
 
187
        self.assertEqual('qux', cfg['baz'])
 
188
        self.assertEqual('qux2', cfg['bar'])
189
189
        self.assertNotIn('foo', cfg)
190
190
 
191
191
    def test_mixed_cloud_config(self):
222
222
        ci.consume_data()
223
223
        cc_contents = util.load_file(ci.paths.get_ipath("cloud_config"))
224
224
        cc = util.load_yaml(cc_contents)
225
 
        self.assertEquals(1, len(cc))
226
 
        self.assertEquals('c', cc['a'])
 
225
        self.assertEqual(1, len(cc))
 
226
        self.assertEqual('c', cc['a'])
227
227
 
228
228
    def test_vendor_user_yaml_cloud_config(self):
229
229
        vendor_blob = '''
263
263
        (_which_ran, _failures) = mods.run_section('cloud_init_modules')
264
264
        cfg = mods.cfg
265
265
        self.assertIn('vendor_data', cfg)
266
 
        self.assertEquals('c', cfg['a'])
267
 
        self.assertEquals('user', cfg['name'])
 
266
        self.assertEqual('c', cfg['a'])
 
267
        self.assertEqual('user', cfg['name'])
268
268
        self.assertNotIn('x', cfg['run'])
269
269
        self.assertNotIn('y', cfg['run'])
270
270
        self.assertIn('z', cfg['run'])
358
358
                              None)
359
359
        contents = util.load_file(paths.get_ipath('cloud_config'))
360
360
        contents = util.load_yaml(contents)
361
 
        self.assertEquals(contents['run'], ['b', 'c', 'stuff', 'morestuff'])
362
 
        self.assertEquals(contents['a'], 'be')
363
 
        self.assertEquals(contents['e'], [1, 2, 3])
364
 
        self.assertEquals(contents['p'], 1)
 
361
        self.assertEqual(contents['run'], ['b', 'c', 'stuff', 'morestuff'])
 
362
        self.assertEqual(contents['a'], 'be')
 
363
        self.assertEqual(contents['e'], [1, 2, 3])
 
364
        self.assertEqual(contents['p'], 1)
365
365
 
366
366
    def test_unhandled_type_warning(self):
367
367
        """Raw text without magic is ignored but shows warning."""
411
411
        contents = util.load_file(ci.paths.get_ipath("cloud_config"))
412
412
        contents = util.load_yaml(contents)
413
413
        self.assertTrue(isinstance(contents, dict))
414
 
        self.assertEquals(3, len(contents))
415
 
        self.assertEquals(2, contents['a'])
416
 
        self.assertEquals(3, contents['b'])
417
 
        self.assertEquals(4, contents['c'])
 
414
        self.assertEqual(3, len(contents))
 
415
        self.assertEqual(2, contents['a'])
 
416
        self.assertEqual(3, contents['b'])
 
417
        self.assertEqual(4, contents['c'])
418
418
 
419
419
    def test_mime_text_plain(self):
420
420
        """Mime message of type text/plain is ignored but shows warning."""
449
449
 
450
450
        mockobj.assert_has_calls([
451
451
            mock.call(outpath, script, 0o700),
452
 
            mock.call(ci.paths.get_ipath("cloud_config"), "", 0o600),
453
 
            ])
 
452
            mock.call(ci.paths.get_ipath("cloud_config"), "", 0o600)])
454
453
 
455
454
    def test_mime_text_x_shellscript(self):
456
455
        """Mime message of type text/x-shellscript is treated as script."""
470
469
 
471
470
        mockobj.assert_has_calls([
472
471
            mock.call(outpath, script, 0o700),
473
 
            mock.call(ci.paths.get_ipath("cloud_config"), "", 0o600),
474
 
            ])
 
472
            mock.call(ci.paths.get_ipath("cloud_config"), "", 0o600)])
475
473
 
476
474
    def test_mime_text_plain_shell(self):
477
475
        """Mime type text/plain starting #!/bin/sh is treated as script."""
491
489
 
492
490
        mockobj.assert_has_calls([
493
491
            mock.call(outpath, script, 0o700),
494
 
            mock.call(ci.paths.get_ipath("cloud_config"), "", 0o600),
495
 
            ])
 
492
            mock.call(ci.paths.get_ipath("cloud_config"), "", 0o600)])
496
493
 
497
494
    def test_mime_application_octet_stream(self):
498
495
        """Mime type application/octet-stream is ignored but shows warning."""