Merge lp:~smoser/curtin/trunk.vmtest-cleanup into lp:~curtin-dev/curtin/trunk

Proposed by Scott Moser
Status: Merged
Merged at revision: 501
Proposed branch: lp:~smoser/curtin/trunk.vmtest-cleanup
Merge into: lp:~curtin-dev/curtin/trunk
Diff against target: 308 lines (+73/-82)
6 files modified
tests/vmtests/__init__.py (+41/-33)
tests/vmtests/test_network.py (+23/-30)
tests/vmtests/test_network_bridging.py (+6/-12)
tests/vmtests/test_network_enisource.py (+1/-2)
tests/vmtests/test_network_mtu.py (+1/-4)
tests/vmtests/test_nvme.py (+1/-1)
To merge this branch: bzr merge lp:~smoser/curtin/trunk.vmtest-cleanup
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Ryan Harper (community) Approve
Review via email: mp+322980@code.launchpad.net

Commit message

tests: clean up usage of collect files

This adds a helper 'collect_path' to the vmtests base class, and then
uses it wherever appropriate. It also cleans up all code that
used read collect files to use load_collect_file.

Lastly, it updates output_files_exist and output_files_dont_exist
to show which files do or do not exist. Previously all you'd see
in the log was an assertion that something was or was not true.
Now, you'll see a list of files that do or do not exist, and not
just the first.

To post a comment you must log in.
491. By Scott Moser

fix assertEqual.. should be expected, actual

492. By Scott Moser

add a message

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :

Looks, good, likely needs a rebase.

review: Approve
493. By Scott Moser

merge from trunk

Revision history for this message
Scott Moser (smoser) wrote :

merged with trunk. should be good now.

494. By Scott Moser

change collect_path to be a class method, so it can be used from class-methods.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
495. By Scott Moser

fix some tests that did not collect fstab or ls_dname

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/vmtests/__init__.py'
2--- tests/vmtests/__init__.py 2017-04-21 20:08:30 +0000
3+++ tests/vmtests/__init__.py 2017-05-12 19:12:20 +0000
4@@ -942,19 +942,26 @@
5 return boot_log_wrap(cls.__name__, myboot, cmd, console_log, timeout,
6 purpose)
7
8+ @classmethod
9+ def collect_path(cls, path):
10+ # return a full path to the collected file
11+ # prepending ./ makes '/root/file' or 'root/file' work as expected.
12+ return os.path.normpath(os.path.join(cls.td.collect, "./" + path))
13+
14 # Misc functions that are useful for many tests
15 def output_files_exist(self, files):
16- for f in files:
17- logger.debug('checking file %s', f)
18- self.assertTrue(os.path.exists(os.path.join(self.td.collect, f)))
19+ missing = [f for f in files
20+ if not os.path.exists(self.collect_path(f))]
21+ self.assertEqual([], missing,
22+ msg="expected collected files do not exist.")
23
24 def output_files_dont_exist(self, files):
25- for f in files:
26- logger.debug('checking file %s', f)
27- self.assertFalse(os.path.exists(os.path.join(self.td.collect, f)))
28+ found = [f for f in files if os.path.exists(self.collect_path(f))]
29+ self.assertEqual([], found,
30+ msg="Collected files exist that should not.")
31
32 def load_collect_file(self, filename, mode="r"):
33- with open(os.path.join(self.td.collect, filename), mode) as fp:
34+ with open(self.collect_path(filename), mode) as fp:
35 return fp.read()
36
37 def load_log_file(self, filename):
38@@ -999,8 +1006,7 @@
39 self.assertRegexpMatches(s, r)
40
41 def get_blkid_data(self, blkid_file):
42- with open(os.path.join(self.td.collect, blkid_file)) as fp:
43- data = fp.read()
44+ data = self.load_collect_file(blkid_file)
45 ret = {}
46 for line in data.splitlines():
47 if line == "":
48@@ -1010,29 +1016,32 @@
49 return ret
50
51 def test_fstab(self):
52- if (os.path.exists(self.td.collect + "fstab") and
53- self.fstab_expected is not None):
54- with open(os.path.join(self.td.collect, "fstab")) as fp:
55- fstab_lines = fp.readlines()
56- fstab_entry = None
57- for line in fstab_lines:
58- for device, mntpoint in self.fstab_expected.items():
59- if device in line:
60- fstab_entry = line
61- self.assertIsNotNone(fstab_entry)
62- self.assertEqual(fstab_entry.split(' ')[1],
63- mntpoint)
64+ if self.fstab_expected is None:
65+ return
66+ path = self.collect_path("fstab")
67+ if not os.path.exists(path):
68+ return
69+ fstab_entry = None
70+ for line in util.load_file(path).splitlines():
71+ for device, mntpoint in self.fstab_expected.items():
72+ if device in line:
73+ fstab_entry = line
74+ self.assertIsNotNone(fstab_entry)
75+ self.assertEqual(fstab_entry.split(' ')[1],
76+ mntpoint)
77
78 def test_dname(self):
79- fpath = os.path.join(self.td.collect, "ls_dname")
80- if (os.path.exists(fpath) and self.disk_to_check is not None):
81- with open(fpath, "r") as fp:
82- contents = fp.read().splitlines()
83- for diskname, part in self.disk_to_check:
84- if part is not 0:
85- link = diskname + "-part" + str(part)
86- self.assertIn(link, contents)
87- self.assertIn(diskname, contents)
88+ if self.disk_to_check is None:
89+ return
90+ path = self.collect_path("ls_dname")
91+ if not os.path.exists(path):
92+ return
93+ contents = util.load_file(path)
94+ for diskname, part in self.disk_to_check:
95+ if part is not 0:
96+ link = diskname + "-part" + str(part)
97+ self.assertIn(link, contents)
98+ self.assertIn(diskname, contents)
99
100 def test_reporting_data(self):
101 with open(self.reporting_log, 'r') as fp:
102@@ -1057,8 +1066,7 @@
103 """ Check that curtin has removed /etc/network/interfaces.d/eth0.cfg
104 by examining the output of a find /etc/network > find_interfaces.d
105 """
106- fpath = os.path.join(self.td.collect, "find_interfacesd")
107- interfacesd = util.load_file(fpath)
108+ interfacesd = self.load_collect_file("find_interfacesd")
109 self.assertNotIn("/etc/network/interfaces.d/eth0.cfg",
110 interfacesd.split("\n"))
111
112@@ -1116,7 +1124,7 @@
113 @classmethod
114 def collect_output(cls):
115 logger.debug('Psuedo extracting output disk')
116- with open(os.path.join(cls.td.collect, "fstab"), "w") as fp:
117+ with open(cls.collect_path("fstab"), "w") as fp:
118 fp.write('\n'.join(("# psuedo fstab",
119 "LABEL=root / ext4 defaults 0 1")))
120
121
122=== modified file 'tests/vmtests/test_network.py'
123--- tests/vmtests/test_network.py 2017-02-01 20:32:13 +0000
124+++ tests/vmtests/test_network.py 2017-05-12 19:12:20 +0000
125@@ -2,7 +2,6 @@
126 from .releases import base_vm_classes as relbase
127
128 import ipaddress
129-import os
130 import re
131 import textwrap
132 import yaml
133@@ -46,9 +45,8 @@
134 ])
135
136 def test_etc_network_interfaces(self):
137- with open(os.path.join(self.td.collect, "interfaces")) as fp:
138- eni = fp.read()
139- logger.debug('etc/network/interfaces:\n{}'.format(eni))
140+ eni = self.load_collect_file("interfaces")
141+ logger.debug('etc/network/interfaces:\n{}'.format(eni))
142
143 expected_eni = self.get_expected_etc_network_interfaces()
144 eni_lines = eni.split('\n')
145@@ -56,9 +54,8 @@
146 self.assertTrue(line in eni_lines)
147
148 def test_etc_resolvconf(self):
149- with open(os.path.join(self.td.collect, "resolv.conf")) as fp:
150- resolvconf = fp.read()
151- logger.debug('etc/resolv.conf:\n{}'.format(resolvconf))
152+ resolvconf = self.load_collect_file("resolv.conf")
153+ logger.debug('etc/resolv.conf:\n{}'.format(resolvconf))
154
155 resolv_lines = resolvconf.split('\n')
156 logger.debug('resolv.conf lines:\n{}'.format(resolv_lines))
157@@ -140,34 +137,30 @@
158 logger.debug('expected_network_state:\n{}'.format(
159 yaml.dump(network_state, default_flow_style=False, indent=4)))
160
161- with open(os.path.join(self.td.collect, "ip_a")) as fp:
162- ip_a = fp.read()
163- logger.debug('ip a:\n{}'.format(ip_a))
164+ ip_a = self.load_collect_file("ip_a")
165+ logger.debug('ip a:\n{}'.format(ip_a))
166
167 ip_dict = helpers.ip_a_to_dict(ip_a)
168 print('parsed ip_a dict:\n{}'.format(
169 yaml.dump(ip_dict, default_flow_style=False, indent=4)))
170
171- with open(os.path.join(self.td.collect, "ip_route_show")) as fp:
172- ip_route_show = fp.read()
173- logger.debug("ip route show:\n{}".format(ip_route_show))
174- for line in [line for line in ip_route_show.split('\n')
175- if 'src' in line]:
176- m = re.search(r'^(?P<network>\S+)\sdev\s' +
177- r'(?P<devname>\S+)\s+' +
178- r'proto kernel\s+scope link' +
179- r'\s+src\s(?P<src_ip>\S+)',
180- line)
181- route_info = m.groupdict('')
182- logger.debug(route_info)
183-
184- with open(os.path.join(self.td.collect, "route_n")) as fp:
185- route_n = fp.read()
186- logger.debug("route -n:\n{}".format(route_n))
187-
188- with open(os.path.join(self.td.collect, "route_6_n")) as fp:
189- route_6_n = fp.read()
190- logger.debug("route -6 -n:\n{}".format(route_6_n))
191+ ip_route_show = self.load_collect_file("ip_route_show")
192+ logger.debug("ip route show:\n{}".format(ip_route_show))
193+ for line in [line for line in ip_route_show.split('\n')
194+ if 'src' in line]:
195+ m = re.search(r'^(?P<network>\S+)\sdev\s' +
196+ r'(?P<devname>\S+)\s+' +
197+ r'proto kernel\s+scope link' +
198+ r'\s+src\s(?P<src_ip>\S+)',
199+ line)
200+ route_info = m.groupdict('')
201+ logger.debug(route_info)
202+
203+ route_n = self.load_collect_file("route_n")
204+ logger.debug("route -n:\n{}".format(route_n))
205+
206+ route_6_n = self.load_collect_file("route_6_n")
207+ logger.debug("route -6 -n:\n{}".format(route_6_n))
208
209 routes = {
210 '4': route_n,
211
212=== modified file 'tests/vmtests/test_network_bridging.py'
213--- tests/vmtests/test_network_bridging.py 2017-02-08 20:51:48 +0000
214+++ tests/vmtests/test_network_bridging.py 2017-05-12 19:12:20 +0000
215@@ -3,7 +3,6 @@
216 from .test_network import TestNetworkBaseTestsAbs
217 from curtin import util
218
219-import os
220 import textwrap
221
222
223@@ -107,22 +106,17 @@
224 "sysfs_br0_eth2"])
225
226 def test_bridge_utils_installed(self):
227- with open(os.path.join(self.td.collect,
228- "bridge-utils_installed")) as fp:
229- status = fp.read().strip()
230- logger.debug('bridge-utils installed: {}'.format(status))
231- self.assertEqual('install ok installed', status)
232+ status = self.load_collect_file("bridge-utils_installed").strip()
233+ logger.debug('bridge-utils installed: {}'.format(status))
234+ self.assertEqual('install ok installed', status)
235
236 def test_bridge_params(self):
237 """ Test if configure bridge params match values on the device """
238
239 def _load_sysfs_bridge_data():
240- sysfs_br0 = sysfs_to_dict(os.path.join(self.td.collect,
241- "sysfs_br0"))
242- sysfs_br0_eth1 = sysfs_to_dict(os.path.join(self.td.collect,
243- "sysfs_br0_eth1"))
244- sysfs_br0_eth2 = sysfs_to_dict(os.path.join(self.td.collect,
245- "sysfs_br0_eth2"))
246+ sysfs_br0 = sysfs_to_dict(self.collect_path("sysfs_br0"))
247+ sysfs_br0_eth1 = sysfs_to_dict(self.collect_path("sysfs_br0_eth1"))
248+ sysfs_br0_eth2 = sysfs_to_dict(self.collect_path("sysfs_br0_eth2"))
249 return {
250 'br0': sysfs_br0,
251 'eth1': sysfs_br0_eth1,
252
253=== modified file 'tests/vmtests/test_network_enisource.py'
254--- tests/vmtests/test_network_enisource.py 2017-02-07 16:52:56 +0000
255+++ tests/vmtests/test_network_enisource.py 2017-05-12 19:12:20 +0000
256@@ -2,7 +2,6 @@
257 from .releases import base_vm_classes as relbase
258 from .test_network import TestNetworkBaseTestsAbs
259
260-import os
261 import subprocess
262 import yaml
263
264@@ -38,7 +37,7 @@
265 """ Compare injected configuration as parsed by curtin matches
266 how ifup configured the interface."""
267 # interfaces uses absolute paths, fix for test-case
268- interfaces = os.path.join(self.td.collect, "interfaces")
269+ interfaces = self.collect_path("interfaces")
270 cmd = ['sed', '-i.orig', '-e', 's,/etc/network/,,g',
271 '{}'.format(interfaces)]
272 subprocess.check_call(cmd, stderr=subprocess.STDOUT)
273
274=== modified file 'tests/vmtests/test_network_mtu.py'
275--- tests/vmtests/test_network_mtu.py 2017-02-01 20:32:13 +0000
276+++ tests/vmtests/test_network_mtu.py 2017-05-12 19:12:20 +0000
277@@ -1,8 +1,6 @@
278 from .releases import base_vm_classes as relbase
279 from .test_network_ipv6 import TestNetworkIPV6Abs
280-from curtin import util
281
282-import os
283 import textwrap
284
285
286@@ -46,8 +44,7 @@
287 }
288 mtu_val = {}
289 for fnk in mtu_fn.keys():
290- fn = os.path.join(self.td.collect, mtu_fn[fnk])
291- mtu_val.update({fnk: int(util.load_file(fn))})
292+ mtu_val.update({fnk: int(self.load_collect_file(mtu_fn[fnk]))})
293
294 return mtu_val
295
296
297=== modified file 'tests/vmtests/test_nvme.py'
298--- tests/vmtests/test_nvme.py 2017-04-10 16:50:47 +0000
299+++ tests/vmtests/test_nvme.py 2017-05-12 19:12:20 +0000
300@@ -42,7 +42,7 @@
301 self.output_files_exist(["ls_nvme", "ls_dname", "ls_dev_nvme"])
302
303 def test_nvme_device_names(self):
304- ls_nvme = os.path.join(self.td.collect, 'ls_nvme')
305+ ls_nvme = self.collect_path('ls_nvme')
306 # trusty and vivid do not have sys/class/nvme but
307 # nvme devices do work
308 if os.path.getsize(ls_nvme) > 0:

Subscribers

People subscribed via source and target branches