Merge ~smoser/cloud-init:bug/run_test_net into cloud-init:master
- Git
- lp:~smoser/cloud-init
- bug/run_test_net
- Merge into master
Status: | Merged |
---|---|
Merged at revision: | 65e01b463cee0bdb8c8b415e78abfcc3262aad89 |
Proposed branch: | ~smoser/cloud-init:bug/run_test_net |
Merge into: | cloud-init:master |
Diff against target: |
338 lines (+55/-61) 5 files modified
tests/unittests/helpers.py (+27/-20) tests/unittests/test__init__.py (+6/-6) tests/unittests/test_atomic_helper.py (+2/-2) tests/unittests/test_distros/test_user_data_normalize.py (+0/-0) tests/unittests/test_net.py (+20/-33) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
cloud-init Commiters | Pending | ||
Review via email: mp+315402@code.launchpad.net |
Commit message
tests: remove executable bit on test_net, so it runs, and fix it.
The test_user_
the executable bit set, and thus are skipped by nose by default.
We could set run with the --exe flag, but they should not have
gotten this way.
Other changes here:
* replace TempDirTestCase with CiTestCase, which has some nice
tmp_dir() and tmp_path() functions. Going forward the intent
is to have CiTestCase be the base test case for tests.
* test_net: switch to CiTestCase and fix usage that was
silently broken, because of exe bit.
* populate_dir: return the list of files that it writes rather
than having no return value.
* CiTestCase:
* support tmp_path("foo") that returns a full path to 'foo'
under a tmpdir.
* add tmp_dir() to get a temp dir and clean up.
Description of the change
Preview Diff
1 | diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py | |||
2 | index a093346..90e2431 100644 | |||
3 | --- a/tests/unittests/helpers.py | |||
4 | +++ b/tests/unittests/helpers.py | |||
5 | @@ -2,6 +2,7 @@ | |||
6 | 2 | 2 | ||
7 | 3 | from __future__ import print_function | 3 | from __future__ import print_function |
8 | 4 | 4 | ||
9 | 5 | import functools | ||
10 | 5 | import os | 6 | import os |
11 | 6 | import shutil | 7 | import shutil |
12 | 7 | import sys | 8 | import sys |
13 | @@ -82,6 +83,28 @@ class TestCase(unittest2.TestCase): | |||
14 | 82 | pass | 83 | pass |
15 | 83 | 84 | ||
16 | 84 | 85 | ||
17 | 86 | class CiTestCase(TestCase): | ||
18 | 87 | """This is the preferred test case base class unless user | ||
19 | 88 | needs other test case classes below.""" | ||
20 | 89 | def tmp_dir(self, dir=None, cleanup=True): | ||
21 | 90 | # return a full path to a temporary directory that will be cleaned up. | ||
22 | 91 | if dir is None: | ||
23 | 92 | tmpd = tempfile.mkdtemp( | ||
24 | 93 | prefix="ci-%s." % self.__class__.__name__) | ||
25 | 94 | else: | ||
26 | 95 | tmpd = tempfile.mkdtemp(dir=dir) | ||
27 | 96 | self.addCleanup(functools.partial(shutil.rmtree, tmpd)) | ||
28 | 97 | return tmpd | ||
29 | 98 | |||
30 | 99 | def tmp_path(self, path, dir=None): | ||
31 | 100 | # return an absolute path to 'path' under dir. | ||
32 | 101 | # if dir is None, one will be created with tmp_dir() | ||
33 | 102 | # the file is not created or modified. | ||
34 | 103 | if dir is None: | ||
35 | 104 | dir = self.tmp_dir() | ||
36 | 105 | return os.path.normpath(os.path.abspath(os.path.join(dir, path))) | ||
37 | 106 | |||
38 | 107 | |||
39 | 85 | class ResourceUsingTestCase(TestCase): | 108 | class ResourceUsingTestCase(TestCase): |
40 | 86 | def setUp(self): | 109 | def setUp(self): |
41 | 87 | super(ResourceUsingTestCase, self).setUp() | 110 | super(ResourceUsingTestCase, self).setUp() |
42 | @@ -227,29 +250,10 @@ class HttprettyTestCase(TestCase): | |||
43 | 227 | super(HttprettyTestCase, self).tearDown() | 250 | super(HttprettyTestCase, self).tearDown() |
44 | 228 | 251 | ||
45 | 229 | 252 | ||
46 | 230 | class TempDirTestCase(TestCase): | ||
47 | 231 | # provide a tempdir per class, not per test. | ||
48 | 232 | @classmethod | ||
49 | 233 | def setUpClass(cls): | ||
50 | 234 | cls.tmpd = tempfile.mkdtemp(prefix="ci-%s." % cls.__name__) | ||
51 | 235 | return TestCase.setUpClass() | ||
52 | 236 | |||
53 | 237 | @classmethod | ||
54 | 238 | def tearDownClass(cls): | ||
55 | 239 | shutil.rmtree(cls.tmpd) | ||
56 | 240 | return TestCase.tearDownClass() | ||
57 | 241 | |||
58 | 242 | def tmp_path(self, path): | ||
59 | 243 | # if absolute path (starts with /), then make ./path | ||
60 | 244 | if path.startswith(os.path.sep): | ||
61 | 245 | path = "." + path | ||
62 | 246 | |||
63 | 247 | return os.path.normpath(os.path.join(self.tmpd, path)) | ||
64 | 248 | |||
65 | 249 | |||
66 | 250 | def populate_dir(path, files): | 253 | def populate_dir(path, files): |
67 | 251 | if not os.path.exists(path): | 254 | if not os.path.exists(path): |
68 | 252 | os.makedirs(path) | 255 | os.makedirs(path) |
69 | 256 | ret = [] | ||
70 | 253 | for (name, content) in files.items(): | 257 | for (name, content) in files.items(): |
71 | 254 | p = os.path.join(path, name) | 258 | p = os.path.join(path, name) |
72 | 255 | util.ensure_dir(os.path.dirname(p)) | 259 | util.ensure_dir(os.path.dirname(p)) |
73 | @@ -259,6 +263,9 @@ def populate_dir(path, files): | |||
74 | 259 | else: | 263 | else: |
75 | 260 | fp.write(content.encode('utf-8')) | 264 | fp.write(content.encode('utf-8')) |
76 | 261 | fp.close() | 265 | fp.close() |
77 | 266 | ret.append(p) | ||
78 | 267 | |||
79 | 268 | return ret | ||
80 | 262 | 269 | ||
81 | 263 | 270 | ||
82 | 264 | def dir2dict(startdir, prefix=None): | 271 | def dir2dict(startdir, prefix=None): |
83 | diff --git a/tests/unittests/test__init__.py b/tests/unittests/test__init__.py | |||
84 | index e6f4c31..781f6d5 100644 | |||
85 | --- a/tests/unittests/test__init__.py | |||
86 | +++ b/tests/unittests/test__init__.py | |||
87 | @@ -12,7 +12,7 @@ from cloudinit import settings | |||
88 | 12 | from cloudinit import url_helper | 12 | from cloudinit import url_helper |
89 | 13 | from cloudinit import util | 13 | from cloudinit import util |
90 | 14 | 14 | ||
92 | 15 | from .helpers import TestCase, TempDirTestCase, ExitStack, mock | 15 | from .helpers import TestCase, CiTestCase, ExitStack, mock |
93 | 16 | 16 | ||
94 | 17 | 17 | ||
95 | 18 | class FakeModule(handlers.Handler): | 18 | class FakeModule(handlers.Handler): |
96 | @@ -172,7 +172,7 @@ class TestHandlerHandlePart(TestCase): | |||
97 | 172 | self.data, self.ctype, self.filename, self.payload) | 172 | self.data, self.ctype, self.filename, self.payload) |
98 | 173 | 173 | ||
99 | 174 | 174 | ||
101 | 175 | class TestCmdlineUrl(TempDirTestCase): | 175 | class TestCmdlineUrl(CiTestCase): |
102 | 176 | def test_parse_cmdline_url_nokey_raises_keyerror(self): | 176 | def test_parse_cmdline_url_nokey_raises_keyerror(self): |
103 | 177 | self.assertRaises( | 177 | self.assertRaises( |
104 | 178 | KeyError, main.parse_cmdline_url, 'root=foo bar single') | 178 | KeyError, main.parse_cmdline_url, 'root=foo bar single') |
105 | @@ -189,7 +189,7 @@ class TestCmdlineUrl(TempDirTestCase): | |||
106 | 189 | cmdline = "ro %s=%s bar=1" % (key, url) | 189 | cmdline = "ro %s=%s bar=1" % (key, url) |
107 | 190 | m_read.return_value = url_helper.StringResponse(b"unexpected blob") | 190 | m_read.return_value = url_helper.StringResponse(b"unexpected blob") |
108 | 191 | 191 | ||
110 | 192 | fpath = self.tmp_path("test_valid") | 192 | fpath = self.tmp_path("ccfile") |
111 | 193 | lvl, msg = main.attempt_cmdline_url( | 193 | lvl, msg = main.attempt_cmdline_url( |
112 | 194 | fpath, network=True, cmdline=cmdline) | 194 | fpath, network=True, cmdline=cmdline) |
113 | 195 | self.assertEqual(logging.WARN, lvl) | 195 | self.assertEqual(logging.WARN, lvl) |
114 | @@ -203,7 +203,7 @@ class TestCmdlineUrl(TempDirTestCase): | |||
115 | 203 | cmdline = "ro %s=%s bar=1" % ('cloud-config-url', url) | 203 | cmdline = "ro %s=%s bar=1" % ('cloud-config-url', url) |
116 | 204 | 204 | ||
117 | 205 | m_read.return_value = url_helper.StringResponse(payload) | 205 | m_read.return_value = url_helper.StringResponse(payload) |
119 | 206 | fpath = self.tmp_path("test_valid") | 206 | fpath = self.tmp_path("ccfile") |
120 | 207 | lvl, msg = main.attempt_cmdline_url( | 207 | lvl, msg = main.attempt_cmdline_url( |
121 | 208 | fpath, network=True, cmdline=cmdline) | 208 | fpath, network=True, cmdline=cmdline) |
122 | 209 | self.assertEqual(util.load_file(fpath, decode=False), payload) | 209 | self.assertEqual(util.load_file(fpath, decode=False), payload) |
123 | @@ -213,7 +213,7 @@ class TestCmdlineUrl(TempDirTestCase): | |||
124 | 213 | @mock.patch('cloudinit.cmd.main.util.read_file_or_url') | 213 | @mock.patch('cloudinit.cmd.main.util.read_file_or_url') |
125 | 214 | def test_no_key_found(self, m_read): | 214 | def test_no_key_found(self, m_read): |
126 | 215 | cmdline = "ro mykey=http://example.com/foo root=foo" | 215 | cmdline = "ro mykey=http://example.com/foo root=foo" |
128 | 216 | fpath = self.tmp_path("test_no_key_found") | 216 | fpath = self.tmp_path("ccpath") |
129 | 217 | lvl, msg = main.attempt_cmdline_url( | 217 | lvl, msg = main.attempt_cmdline_url( |
130 | 218 | fpath, network=True, cmdline=cmdline) | 218 | fpath, network=True, cmdline=cmdline) |
131 | 219 | 219 | ||
132 | @@ -225,7 +225,7 @@ class TestCmdlineUrl(TempDirTestCase): | |||
133 | 225 | def test_exception_warns(self, m_read): | 225 | def test_exception_warns(self, m_read): |
134 | 226 | url = "http://example.com/foo" | 226 | url = "http://example.com/foo" |
135 | 227 | cmdline = "ro cloud-config-url=%s root=LABEL=bar" % url | 227 | cmdline = "ro cloud-config-url=%s root=LABEL=bar" % url |
137 | 228 | fpath = self.tmp_path("test_no_key_found") | 228 | fpath = self.tmp_path("ccfile") |
138 | 229 | m_read.side_effect = url_helper.UrlError( | 229 | m_read.side_effect = url_helper.UrlError( |
139 | 230 | cause="Unexpected Error", url="http://example.com/foo") | 230 | cause="Unexpected Error", url="http://example.com/foo") |
140 | 231 | 231 | ||
141 | diff --git a/tests/unittests/test_atomic_helper.py b/tests/unittests/test_atomic_helper.py | |||
142 | index e170c7c..515919d 100644 | |||
143 | --- a/tests/unittests/test_atomic_helper.py | |||
144 | +++ b/tests/unittests/test_atomic_helper.py | |||
145 | @@ -6,10 +6,10 @@ import stat | |||
146 | 6 | 6 | ||
147 | 7 | from cloudinit import atomic_helper | 7 | from cloudinit import atomic_helper |
148 | 8 | 8 | ||
150 | 9 | from . import helpers | 9 | from .helpers import CiTestCase |
151 | 10 | 10 | ||
152 | 11 | 11 | ||
154 | 12 | class TestAtomicHelper(helpers.TempDirTestCase): | 12 | class TestAtomicHelper(CiTestCase): |
155 | 13 | def test_basic_usage(self): | 13 | def test_basic_usage(self): |
156 | 14 | """write_file takes bytes if no omode.""" | 14 | """write_file takes bytes if no omode.""" |
157 | 15 | path = self.tmp_path("test_basic_usage") | 15 | path = self.tmp_path("test_basic_usage") |
158 | diff --git a/tests/unittests/test_distros/test_user_data_normalize.py b/tests/unittests/test_distros/test_user_data_normalize.py | |||
159 | 16 | old mode 100755 | 16 | old mode 100755 |
160 | 17 | new mode 100644 | 17 | new mode 100644 |
161 | index 88746e0..88746e0 | |||
162 | --- a/tests/unittests/test_distros/test_user_data_normalize.py | |||
163 | +++ b/tests/unittests/test_distros/test_user_data_normalize.py | |||
164 | diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py | |||
165 | 18 | old mode 100755 | 18 | old mode 100755 |
166 | 19 | new mode 100644 | 19 | new mode 100644 |
167 | index 1090282..2c2bde9 | |||
168 | --- a/tests/unittests/test_net.py | |||
169 | +++ b/tests/unittests/test_net.py | |||
170 | @@ -8,11 +8,10 @@ from cloudinit.net import sysconfig | |||
171 | 8 | from cloudinit.sources.helpers import openstack | 8 | from cloudinit.sources.helpers import openstack |
172 | 9 | from cloudinit import util | 9 | from cloudinit import util |
173 | 10 | 10 | ||
174 | 11 | from .helpers import CiTestCase | ||
175 | 11 | from .helpers import dir2dict | 12 | from .helpers import dir2dict |
176 | 12 | from .helpers import mock | 13 | from .helpers import mock |
177 | 13 | from .helpers import populate_dir | 14 | from .helpers import populate_dir |
178 | 14 | from .helpers import TempDirTestCase | ||
179 | 15 | from .helpers import TestCase | ||
180 | 16 | 15 | ||
181 | 17 | import base64 | 16 | import base64 |
182 | 18 | import copy | 17 | import copy |
183 | @@ -20,8 +19,6 @@ import gzip | |||
184 | 20 | import io | 19 | import io |
185 | 21 | import json | 20 | import json |
186 | 22 | import os | 21 | import os |
187 | 23 | import shutil | ||
188 | 24 | import tempfile | ||
189 | 25 | import textwrap | 22 | import textwrap |
190 | 26 | import yaml | 23 | import yaml |
191 | 27 | 24 | ||
192 | @@ -478,7 +475,7 @@ def _setup_test(tmp_dir, mock_get_devicelist, mock_read_sys_net, | |||
193 | 478 | mock_sys_dev_path.side_effect = sys_dev_path | 475 | mock_sys_dev_path.side_effect = sys_dev_path |
194 | 479 | 476 | ||
195 | 480 | 477 | ||
197 | 481 | class TestSysConfigRendering(TestCase): | 478 | class TestSysConfigRendering(CiTestCase): |
198 | 482 | 479 | ||
199 | 483 | @mock.patch("cloudinit.net.sys_dev_path") | 480 | @mock.patch("cloudinit.net.sys_dev_path") |
200 | 484 | @mock.patch("cloudinit.net.read_sys_net") | 481 | @mock.patch("cloudinit.net.read_sys_net") |
201 | @@ -486,8 +483,7 @@ class TestSysConfigRendering(TestCase): | |||
202 | 486 | def test_default_generation(self, mock_get_devicelist, | 483 | def test_default_generation(self, mock_get_devicelist, |
203 | 487 | mock_read_sys_net, | 484 | mock_read_sys_net, |
204 | 488 | mock_sys_dev_path): | 485 | mock_sys_dev_path): |
207 | 489 | tmp_dir = tempfile.mkdtemp() | 486 | tmp_dir = self.tmp_dir() |
206 | 490 | self.addCleanup(shutil.rmtree, tmp_dir) | ||
208 | 491 | _setup_test(tmp_dir, mock_get_devicelist, | 487 | _setup_test(tmp_dir, mock_get_devicelist, |
209 | 492 | mock_read_sys_net, mock_sys_dev_path) | 488 | mock_read_sys_net, mock_sys_dev_path) |
210 | 493 | 489 | ||
211 | @@ -518,9 +514,7 @@ USERCTL=no | |||
212 | 518 | self.assertEqual(expected_content, content) | 514 | self.assertEqual(expected_content, content) |
213 | 519 | 515 | ||
214 | 520 | def test_openstack_rendering_samples(self): | 516 | def test_openstack_rendering_samples(self): |
218 | 521 | tmp_dir = tempfile.mkdtemp() | 517 | render_dir = self.tmp_dir() |
216 | 522 | self.addCleanup(shutil.rmtree, tmp_dir) | ||
217 | 523 | render_dir = os.path.join(tmp_dir, "render") | ||
219 | 524 | for os_sample in OS_SAMPLES: | 518 | for os_sample in OS_SAMPLES: |
220 | 525 | ex_input = os_sample['in_data'] | 519 | ex_input = os_sample['in_data'] |
221 | 526 | ex_mac_addrs = os_sample['in_macs'] | 520 | ex_mac_addrs = os_sample['in_macs'] |
222 | @@ -535,7 +529,7 @@ USERCTL=no | |||
223 | 535 | self.assertEqual(expected_content, fh.read()) | 529 | self.assertEqual(expected_content, fh.read()) |
224 | 536 | 530 | ||
225 | 537 | 531 | ||
227 | 538 | class TestEniNetRendering(TestCase): | 532 | class TestEniNetRendering(CiTestCase): |
228 | 539 | 533 | ||
229 | 540 | @mock.patch("cloudinit.net.sys_dev_path") | 534 | @mock.patch("cloudinit.net.sys_dev_path") |
230 | 541 | @mock.patch("cloudinit.net.read_sys_net") | 535 | @mock.patch("cloudinit.net.read_sys_net") |
231 | @@ -543,8 +537,7 @@ class TestEniNetRendering(TestCase): | |||
232 | 543 | def test_default_generation(self, mock_get_devicelist, | 537 | def test_default_generation(self, mock_get_devicelist, |
233 | 544 | mock_read_sys_net, | 538 | mock_read_sys_net, |
234 | 545 | mock_sys_dev_path): | 539 | mock_sys_dev_path): |
237 | 546 | tmp_dir = tempfile.mkdtemp() | 540 | tmp_dir = self.tmp_dir() |
236 | 547 | self.addCleanup(shutil.rmtree, tmp_dir) | ||
238 | 548 | _setup_test(tmp_dir, mock_get_devicelist, | 541 | _setup_test(tmp_dir, mock_get_devicelist, |
239 | 549 | mock_read_sys_net, mock_sys_dev_path) | 542 | mock_read_sys_net, mock_sys_dev_path) |
240 | 550 | 543 | ||
241 | @@ -576,7 +569,7 @@ iface eth1000 inet dhcp | |||
242 | 576 | self.assertEqual(expected.lstrip(), contents.lstrip()) | 569 | self.assertEqual(expected.lstrip(), contents.lstrip()) |
243 | 577 | 570 | ||
244 | 578 | 571 | ||
246 | 579 | class TestEniNetworkStateToEni(TestCase): | 572 | class TestEniNetworkStateToEni(CiTestCase): |
247 | 580 | mycfg = { | 573 | mycfg = { |
248 | 581 | 'config': [{"type": "physical", "name": "eth0", | 574 | 'config': [{"type": "physical", "name": "eth0", |
249 | 582 | "mac_address": "c0:d6:9f:2c:e8:80", | 575 | "mac_address": "c0:d6:9f:2c:e8:80", |
250 | @@ -607,7 +600,7 @@ class TestEniNetworkStateToEni(TestCase): | |||
251 | 607 | self.assertNotIn("hwaddress", rendered) | 600 | self.assertNotIn("hwaddress", rendered) |
252 | 608 | 601 | ||
253 | 609 | 602 | ||
255 | 610 | class TestCmdlineConfigParsing(TestCase): | 603 | class TestCmdlineConfigParsing(CiTestCase): |
256 | 611 | simple_cfg = { | 604 | simple_cfg = { |
257 | 612 | 'config': [{"type": "physical", "name": "eth0", | 605 | 'config': [{"type": "physical", "name": "eth0", |
258 | 613 | "mac_address": "c0:d6:9f:2c:e8:80", | 606 | "mac_address": "c0:d6:9f:2c:e8:80", |
259 | @@ -665,7 +658,7 @@ class TestCmdlineConfigParsing(TestCase): | |||
260 | 665 | self.assertEqual(found, self.simple_cfg) | 658 | self.assertEqual(found, self.simple_cfg) |
261 | 666 | 659 | ||
262 | 667 | 660 | ||
264 | 668 | class TestCmdlineReadKernelConfig(TempDirTestCase): | 661 | class TestCmdlineReadKernelConfig(CiTestCase): |
265 | 669 | macs = { | 662 | macs = { |
266 | 670 | 'eth0': '14:02:ec:42:48:00', | 663 | 'eth0': '14:02:ec:42:48:00', |
267 | 671 | 'eno1': '14:02:ec:42:48:01', | 664 | 'eno1': '14:02:ec:42:48:01', |
268 | @@ -673,8 +666,7 @@ class TestCmdlineReadKernelConfig(TempDirTestCase): | |||
269 | 673 | 666 | ||
270 | 674 | def test_ip_cmdline_read_kernel_cmdline_ip(self): | 667 | def test_ip_cmdline_read_kernel_cmdline_ip(self): |
271 | 675 | content = {'net-eth0.conf': DHCP_CONTENT_1} | 668 | content = {'net-eth0.conf': DHCP_CONTENT_1} |
274 | 676 | populate_dir(self.tmp, content) | 669 | files = sorted(populate_dir(self.tmp_dir(), content)) |
273 | 677 | files = [os.path.join(self.tmp, k) for k in content.keys()] | ||
275 | 678 | found = cmdline.read_kernel_cmdline_config( | 670 | found = cmdline.read_kernel_cmdline_config( |
276 | 679 | files=files, cmdline='foo ip=dhcp', mac_addrs=self.macs) | 671 | files=files, cmdline='foo ip=dhcp', mac_addrs=self.macs) |
277 | 680 | exp1 = copy.deepcopy(DHCP_EXPECTED_1) | 672 | exp1 = copy.deepcopy(DHCP_EXPECTED_1) |
278 | @@ -684,8 +676,7 @@ class TestCmdlineReadKernelConfig(TempDirTestCase): | |||
279 | 684 | 676 | ||
280 | 685 | def test_ip_cmdline_read_kernel_cmdline_ip6(self): | 677 | def test_ip_cmdline_read_kernel_cmdline_ip6(self): |
281 | 686 | content = {'net6-eno1.conf': DHCP6_CONTENT_1} | 678 | content = {'net6-eno1.conf': DHCP6_CONTENT_1} |
284 | 687 | populate_dir(self.tmp, content) | 679 | files = sorted(populate_dir(self.tmp_dir(), content)) |
283 | 688 | files = [os.path.join(self.tmp, k) for k in content.keys()] | ||
285 | 689 | found = cmdline.read_kernel_cmdline_config( | 680 | found = cmdline.read_kernel_cmdline_config( |
286 | 690 | files=files, cmdline='foo ip6=dhcp root=/dev/sda', | 681 | files=files, cmdline='foo ip6=dhcp root=/dev/sda', |
287 | 691 | mac_addrs=self.macs) | 682 | mac_addrs=self.macs) |
288 | @@ -701,8 +692,7 @@ class TestCmdlineReadKernelConfig(TempDirTestCase): | |||
289 | 701 | def test_ip_cmdline_read_kernel_cmdline_none(self): | 692 | def test_ip_cmdline_read_kernel_cmdline_none(self): |
290 | 702 | # if there is no ip= or ip6= on cmdline, return value should be None | 693 | # if there is no ip= or ip6= on cmdline, return value should be None |
291 | 703 | content = {'net6-eno1.conf': DHCP6_CONTENT_1} | 694 | content = {'net6-eno1.conf': DHCP6_CONTENT_1} |
294 | 704 | populate_dir(self.tmp, content) | 695 | files = sorted(populate_dir(self.tmp_dir(), content)) |
293 | 705 | files = [os.path.join(self.tmp, k) for k in content.keys()] | ||
295 | 706 | found = cmdline.read_kernel_cmdline_config( | 696 | found = cmdline.read_kernel_cmdline_config( |
296 | 707 | files=files, cmdline='foo root=/dev/sda', mac_addrs=self.macs) | 697 | files=files, cmdline='foo root=/dev/sda', mac_addrs=self.macs) |
297 | 708 | self.assertEqual(found, None) | 698 | self.assertEqual(found, None) |
298 | @@ -710,8 +700,7 @@ class TestCmdlineReadKernelConfig(TempDirTestCase): | |||
299 | 710 | def test_ip_cmdline_both_ip_ip6(self): | 700 | def test_ip_cmdline_both_ip_ip6(self): |
300 | 711 | content = {'net-eth0.conf': DHCP_CONTENT_1, | 701 | content = {'net-eth0.conf': DHCP_CONTENT_1, |
301 | 712 | 'net6-eth0.conf': DHCP6_CONTENT_1.replace('eno1', 'eth0')} | 702 | 'net6-eth0.conf': DHCP6_CONTENT_1.replace('eno1', 'eth0')} |
304 | 713 | populate_dir(self.tmp, content) | 703 | files = sorted(populate_dir(self.tmp_dir(), content)) |
303 | 714 | files = [os.path.join(self.tmp, k) for k in sorted(content.keys())] | ||
305 | 715 | found = cmdline.read_kernel_cmdline_config( | 704 | found = cmdline.read_kernel_cmdline_config( |
306 | 716 | files=files, cmdline='foo ip=dhcp ip6=dhcp', mac_addrs=self.macs) | 705 | files=files, cmdline='foo ip=dhcp ip6=dhcp', mac_addrs=self.macs) |
307 | 717 | 706 | ||
308 | @@ -725,14 +714,12 @@ class TestCmdlineReadKernelConfig(TempDirTestCase): | |||
309 | 725 | self.assertEqual(found['config'], expected) | 714 | self.assertEqual(found['config'], expected) |
310 | 726 | 715 | ||
311 | 727 | 716 | ||
318 | 728 | class TestEniRoundTrip(TestCase): | 717 | class TestEniRoundTrip(CiTestCase): |
313 | 729 | def setUp(self): | ||
314 | 730 | super(TestCase, self).setUp() | ||
315 | 731 | self.tmp_dir = tempfile.mkdtemp() | ||
316 | 732 | self.addCleanup(shutil.rmtree, self.tmp_dir) | ||
317 | 733 | |||
319 | 734 | def _render_and_read(self, network_config=None, state=None, eni_path=None, | 718 | def _render_and_read(self, network_config=None, state=None, eni_path=None, |
321 | 735 | links_prefix=None, netrules_path=None): | 719 | links_prefix=None, netrules_path=None, dir=None): |
322 | 720 | if dir is None: | ||
323 | 721 | dir = self.tmp_dir() | ||
324 | 722 | |||
325 | 736 | if network_config: | 723 | if network_config: |
326 | 737 | ns = network_state.parse_net_config_data(network_config) | 724 | ns = network_state.parse_net_config_data(network_config) |
327 | 738 | elif state: | 725 | elif state: |
328 | @@ -747,8 +734,8 @@ class TestEniRoundTrip(TestCase): | |||
329 | 747 | config={'eni_path': eni_path, 'links_path_prefix': links_prefix, | 734 | config={'eni_path': eni_path, 'links_path_prefix': links_prefix, |
330 | 748 | 'netrules_path': netrules_path}) | 735 | 'netrules_path': netrules_path}) |
331 | 749 | 736 | ||
334 | 750 | renderer.render_network_state(self.tmp_dir, ns) | 737 | renderer.render_network_state(dir, ns) |
335 | 751 | return dir2dict(self.tmp_dir) | 738 | return dir2dict(dir) |
336 | 752 | 739 | ||
337 | 753 | def testsimple_convert_and_render(self): | 740 | def testsimple_convert_and_render(self): |
338 | 754 | network_config = eni.convert_eni_data(EXAMPLE_ENI) | 741 | network_config = eni.convert_eni_data(EXAMPLE_ENI) |