Merge ~smoser/cloud-init:bug/fix-py26-tests-assertNone into cloud-init:master

Proposed by Scott Moser on 2017-05-25
Status: Merged
Merged at revision: e5b2c011440aefe036c71a8c5e8ec547cc80f270
Proposed branch: ~smoser/cloud-init:bug/fix-py26-tests-assertNone
Merge into: cloud-init:master
Diff against target: 129 lines (+18/-17)
2 files modified
tests/unittests/test_datasource/test_altcloud.py (+2/-1)
tests/unittests/test_handler/test_handler_ntp.py (+16/-16)
Reviewer Review Type Date Requested Status
Chad Smith Approve on 2017-05-25
Server Team CI bot continuous-integration Approve on 2017-05-25
cloud-init commiters 2017-05-25 Pending
Review via email: mp+324585@code.launchpad.net

Commit Message

tests: fix unit tests usage of assertNone on centos 6.

python2.6 unittest.TestCase does not have the assertIsNone or
assertIsNotNone. We just have to explicitly use the unittest2
version, which we get from helpers.

The desire to use assertIsNone comes from flake8 (through hacking,
I believe).

Also, fix "{}.format('foo')" which is not valid in python2.6.

To post a comment you must log in.
Chad Smith (chad.smith) wrote :

Wow good to know about format issues on cent6 as I've used it in other places. I'll be wary for next time. +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/tests/unittests/test_datasource/test_altcloud.py b/tests/unittests/test_datasource/test_altcloud.py
2index b6d4a45..9c46abc 100644
3--- a/tests/unittests/test_datasource/test_altcloud.py
4+++ b/tests/unittests/test_datasource/test_altcloud.py
5@@ -17,7 +17,8 @@ import tempfile
6
7 from cloudinit import helpers
8 from cloudinit import util
9-from unittest import TestCase
10+
11+from ..helpers import TestCase
12
13 import cloudinit.sources.DataSourceAltCloud as dsac
14
15diff --git a/tests/unittests/test_handler/test_handler_ntp.py b/tests/unittests/test_handler/test_handler_ntp.py
16index 21f2ab1..bc4277b 100644
17--- a/tests/unittests/test_handler/test_handler_ntp.py
18+++ b/tests/unittests/test_handler/test_handler_ntp.py
19@@ -59,7 +59,7 @@ class TestNtp(FilesystemMockingTestCase):
20 with mock.patch("cloudinit.config.cc_ntp.NTP_CONF", ntpconf):
21 cc_ntp.rename_ntp_conf()
22 self.assertFalse(os.path.exists(ntpconf))
23- self.assertTrue(os.path.exists("{}.dist".format(ntpconf)))
24+ self.assertTrue(os.path.exists("{0}.dist".format(ntpconf)))
25
26 def test_ntp_rename_ntp_conf_skip_missing(self):
27 """When NTP_CONF doesn't exist rename_ntp doesn't create a file."""
28@@ -67,7 +67,7 @@ class TestNtp(FilesystemMockingTestCase):
29 self.assertFalse(os.path.exists(ntpconf))
30 with mock.patch("cloudinit.config.cc_ntp.NTP_CONF", ntpconf):
31 cc_ntp.rename_ntp_conf()
32- self.assertFalse(os.path.exists("{}.dist".format(ntpconf)))
33+ self.assertFalse(os.path.exists("{0}.dist".format(ntpconf)))
34 self.assertFalse(os.path.exists(ntpconf))
35
36 def test_write_ntp_config_template_from_ntp_conf_tmpl_with_servers(self):
37@@ -84,7 +84,7 @@ class TestNtp(FilesystemMockingTestCase):
38 mycloud = self._get_cloud(distro)
39 ntp_conf = self.tmp_path("ntp.conf", self.new_root) # Doesn't exist
40 # Create ntp.conf.tmpl
41- with open('{}.tmpl'.format(ntp_conf), 'wb') as stream:
42+ with open('{0}.tmpl'.format(ntp_conf), 'wb') as stream:
43 stream.write(NTP_TEMPLATE)
44 with mock.patch('cloudinit.config.cc_ntp.NTP_CONF', ntp_conf):
45 cc_ntp.write_ntp_config_template(cfg, mycloud)
46@@ -107,10 +107,10 @@ class TestNtp(FilesystemMockingTestCase):
47 mycloud = self._get_cloud(distro)
48 ntp_conf = self.tmp_path('ntp.conf', self.new_root) # Doesn't exist
49 # Create ntp.conf.tmpl which isn't read
50- with open('{}.tmpl'.format(ntp_conf), 'wb') as stream:
51+ with open('{0}.tmpl'.format(ntp_conf), 'wb') as stream:
52 stream.write(b'NOT READ: ntp.conf.<distro>.tmpl is primary')
53 # Create ntp.conf.tmpl.<distro>
54- with open('{}.{}.tmpl'.format(ntp_conf, distro), 'wb') as stream:
55+ with open('{0}.{1}.tmpl'.format(ntp_conf, distro), 'wb') as stream:
56 stream.write(NTP_TEMPLATE)
57 with mock.patch('cloudinit.config.cc_ntp.NTP_CONF', ntp_conf):
58 cc_ntp.write_ntp_config_template(cfg, mycloud)
59@@ -129,19 +129,19 @@ class TestNtp(FilesystemMockingTestCase):
60 mycloud = self._get_cloud(distro)
61 ntp_conf = self.tmp_path('ntp.conf', self.new_root) # Doesn't exist
62 # Create ntp.conf.tmpl
63- with open('{}.tmpl'.format(ntp_conf), 'wb') as stream:
64+ with open('{0}.tmpl'.format(ntp_conf), 'wb') as stream:
65 stream.write(NTP_TEMPLATE)
66 with mock.patch('cloudinit.config.cc_ntp.NTP_CONF', ntp_conf):
67 cc_ntp.write_ntp_config_template({}, mycloud)
68 content = util.read_file_or_url('file://' + ntp_conf).contents
69 default_pools = [
70- "{}.{}.pool.ntp.org".format(x, distro)
71+ "{0}.{1}.pool.ntp.org".format(x, distro)
72 for x in range(0, cc_ntp.NR_POOL_SERVERS)]
73 self.assertEqual(
74- "servers []\npools {}\n".format(default_pools),
75+ "servers []\npools {0}\n".format(default_pools),
76 content.decode())
77 self.assertIn(
78- "Adding distro default ntp pool servers: {}".format(
79+ "Adding distro default ntp pool servers: {0}".format(
80 ",".join(default_pools)),
81 self.logs.getvalue())
82
83@@ -158,7 +158,7 @@ class TestNtp(FilesystemMockingTestCase):
84 mycloud = self._get_cloud('ubuntu')
85 ntp_conf = self.tmp_path('ntp.conf', self.new_root) # Doesn't exist
86 # Create ntp.conf.tmpl
87- with open('{}.tmpl'.format(ntp_conf), 'wb') as stream:
88+ with open('{0}.tmpl'.format(ntp_conf), 'wb') as stream:
89 stream.write(NTP_TEMPLATE)
90 with mock.patch('cloudinit.config.cc_ntp.NTP_CONF', ntp_conf):
91 with mock.patch.object(util, 'which', return_value=None):
92@@ -166,7 +166,7 @@ class TestNtp(FilesystemMockingTestCase):
93
94 content = util.read_file_or_url('file://' + ntp_conf).contents
95 self.assertEqual(
96- 'servers {}\npools {}\n'.format(servers, pools),
97+ 'servers {0}\npools {1}\n'.format(servers, pools),
98 content.decode())
99
100 def test_ntp_handler_real_distro_templates(self):
101@@ -184,7 +184,7 @@ class TestNtp(FilesystemMockingTestCase):
102 mycloud = self._get_cloud(distro)
103 root_dir = dirname(dirname(os.path.realpath(util.__file__)))
104 tmpl_file = os.path.join(
105- '{}/templates/ntp.conf.{}.tmpl'.format(root_dir, distro))
106+ '{0}/templates/ntp.conf.{1}.tmpl'.format(root_dir, distro))
107 # Create a copy in our tmp_dir
108 shutil.copy(
109 tmpl_file,
110@@ -195,15 +195,15 @@ class TestNtp(FilesystemMockingTestCase):
111
112 content = util.read_file_or_url('file://' + ntp_conf).contents
113 expected_servers = '\n'.join([
114- 'server {} iburst'.format(server) for server in servers])
115+ 'server {0} iburst'.format(server) for server in servers])
116 self.assertIn(
117 expected_servers, content.decode(),
118- 'failed to render ntp.conf for distro:{}'.format(distro))
119+ 'failed to render ntp.conf for distro:{0}'.format(distro))
120 expected_pools = '\n'.join([
121- 'pool {} iburst'.format(pool) for pool in pools])
122+ 'pool {0} iburst'.format(pool) for pool in pools])
123 self.assertIn(
124 expected_pools, content.decode(),
125- 'failed to render ntp.conf for distro:{}'.format(distro))
126+ 'failed to render ntp.conf for distro:{0}'.format(distro))
127
128 def test_no_ntpcfg_does_nothing(self):
129 """When no ntp section is defined handler logs a warning and noops."""

Subscribers

People subscribed via source and target branches

to all changes: