Merge ~pkopylov/qa-regression-testing:fix-test-util-linux-swapon into qa-regression-testing:master

Proposed by Pavel Kopylov
Status: Needs review
Proposed branch: ~pkopylov/qa-regression-testing:fix-test-util-linux-swapon
Merge into: qa-regression-testing:master
Diff against target: 43 lines (+17/-3)
1 file modified
scripts/test-util-linux.py (+17/-3)
Reviewer Review Type Date Requested Status
Ubuntu Security Team Pending
Review via email: mp+442107@code.launchpad.net

Description of the change

There is a problem with the swapon utility. Here is the display_summary(void) function which uses get_swaps(). If /proc/swaps doesn't contain any partition on Ubuntu 16 the get_swaps() returns NULL and there is no output of either swapon --show or swapon --summary at all.

Also, the swapon's manual declares command line keys --summary and -s as deprecated, so the right solution is using a similar key named --show.

So, I suggest checking if /proc/swaps exists at all and if this file contains at least two strings (because the first string in this file is just titles).

To post a comment you must log in.
Revision history for this message
Steve Beattie (sbeattie) wrote :

Hay Pavel, thanks for submitting this. One issue with converting to swapon --show is that the Ubuntu Security Team is still supporting 14.04 LTS / trusty, where the swapon command does not support the --show argument.

I have pushed a commit that will use swapon --show in newer releases, and also checks the contents of /proc/swaps, and doesn't expect any output from swapon if there's no entries besides the column headers in /proc/swaps. Probably the better solution is to always create a small swapfile and check the output of swapon to ensure it's present.

The commit is at https://git.launchpad.net/qa-regression-testing/commit/?id=079add3ae1812d37164c80cf06ff6d399a8b27c3

Thanks!

Unmerged commits

2b27bd1... by Pavel Kopylov

Fix test-util-linux to pass the swapon test on system has no swap partitions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/scripts/test-util-linux.py b/scripts/test-util-linux.py
2index 9c6bc4e..fabe540 100755
3--- a/scripts/test-util-linux.py
4+++ b/scripts/test-util-linux.py
5@@ -25,6 +25,7 @@
6 - test the other utils that aren't included here
7 - perform more than run tests on a few tools
8 '''
9+# QRT-Packages: coreutils
10 # QRT-Depends: util-linux
11 # QRT-Privilege: root
12
13@@ -219,14 +220,27 @@ class MountTest(testlib.TestlibCase):
14
15 def test_swapon(self):
16 '''Test swapon'''
17+ proc_file = '/proc/swaps'
18+ if os.path.exists(proc_file):
19+ # do test if /proc/swaps contains one or more swap partitions, so this file
20+ # encounters two or more lines.
21+ rc, output = testlib.cmd(['wc','-l',proc_file])
22+ if rc == 0 and int(output.split()[0]) > 1:
23 # for now, just see if it runs
24- rc, report = testlib.cmd(['swapon', '-s'])
25+ rc, report = testlib.cmd(['swapon', '--show'])
26 expected = 0
27 result = 'Got exit code %d, expected %d\n' % (rc, expected)
28 self.assertEqual(expected, rc, result + report)
29
30- result = "Couldn't find 'Filename' in report"
31- self.assertTrue('Filename' in report, result + report)
32+ # however, we use the --show parameter because
33+ # either -s or --summary were deprecated,
34+ # according to man swapon
35+ result = "Couldn't find 'NAME' in report"
36+ self.assertTrue('NAME' in report, result + report)
37+ else:
38+ return self._skipped('skipped because /proc/swaps contains no swap partitions')
39+ else:
40+ return self._skipped('skipped because /proc/swaps is not presented')
41
42 def test_losetup(self):
43 '''Test losetup'''

Subscribers

People subscribed via source and target branches