aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cleaner_tests/basic_function_tests
diff options
context:
space:
mode:
authorArif Ali <arif.ali@canonical.com>2024-01-15 18:51:04 -0800
committerJake Hunsaker <jacob.r.hunsaker@gmail.com>2024-04-12 11:50:48 -0400
commit93bcf51257ec4ce2b97c942e51e56546ce8cd0cd (patch)
treedb1e835f5de49918553281726d86f4660731313e /tests/cleaner_tests/basic_function_tests
parent4069af4bca5d20662389200f0d426d2d31f054e8 (diff)
downloadsos-93bcf51257ec4ce2b97c942e51e56546ce8cd0cd.tar.gz
[testing] Add most testing via tox.ini
Consolidate testing, so that things can be run from CLI, CI and various other means in a consistent way by using tox. * Updated all the flake8 tests in the tests folder. * Added pylint as a neutral test so that we can work on this in stages and have some collaboration on what we test and don't * The tox tests for unit, stageone, stagetwo testing makes is easier for users to know how to run tests, and not have to do things manually * Using tox for CI doesn't make sense, as that will create virtual envs and will disregard system/snap based python modules so may not work Signed-off-by: Arif Ali <arif.ali@canonical.com>
Diffstat (limited to 'tests/cleaner_tests/basic_function_tests')
-rw-r--r--tests/cleaner_tests/basic_function_tests/binary_test.py1
-rw-r--r--tests/cleaner_tests/basic_function_tests/report_with_mask.py55
2 files changed, 37 insertions, 19 deletions
diff --git a/tests/cleaner_tests/basic_function_tests/binary_test.py b/tests/cleaner_tests/basic_function_tests/binary_test.py
index 80bc841b..3fdbbd69 100644
--- a/tests/cleaner_tests/basic_function_tests/binary_test.py
+++ b/tests/cleaner_tests/basic_function_tests/binary_test.py
@@ -16,6 +16,5 @@ class BinaryPlugin(Plugin, IndependentPlugin):
plugin_name = 'binary_test'
short_desc = 'test plugin for removing binaries with --clean'
-
def setup(self):
self.add_copy_spec('/var/log/binary_test.tar.xz')
diff --git a/tests/cleaner_tests/basic_function_tests/report_with_mask.py b/tests/cleaner_tests/basic_function_tests/report_with_mask.py
index bb72cdde..2b694554 100644
--- a/tests/cleaner_tests/basic_function_tests/report_with_mask.py
+++ b/tests/cleaner_tests/basic_function_tests/report_with_mask.py
@@ -25,7 +25,8 @@ class ReportWithMask(StageOneReportTest):
# obfuscate a random word from /etc/hosts and ensure the updated
# sanitised file has same permissions (a+r)
try:
- self.hosts_obfuscated = open('/etc/hosts').read().strip('#\n').split()[-1]
+ self.hosts_obfuscated = open(
+ '/etc/hosts').read().strip('#\n').split()[-1]
except (FileNotFoundError, IndexError) as e:
self.warning(f"Unable to process /etc/hosts: {e}")
if self.hosts_obfuscated:
@@ -36,8 +37,10 @@ class ReportWithMask(StageOneReportTest):
self.assertOutputContains('Obfuscation completed')
def test_private_map_was_generated(self):
- self.assertOutputContains('A mapping of obfuscated elements is available at')
- map_file = re.findall('/.*sosreport-.*-private_map', self.cmd_output.stdout)[-1]
+ self.assertOutputContains(
+ 'A mapping of obfuscated elements is available at')
+ map_file = re.findall(
+ '/.*sosreport-.*-private_map', self.cmd_output.stdout)[-1]
self.assertFileExists(map_file)
def test_tarball_named_obfuscated(self):
@@ -53,40 +56,53 @@ class ReportWithMask(StageOneReportTest):
# Note: do not test for starting with the 100.* block here, as test
# machines may have /32 addresses. Instead, test that the actual
# IP address is not present
- self.assertFileNotHasContent('ip_addr', self.sysinfo['pre']['networking']['ip_addr'])
+ self.assertFileNotHasContent(
+ 'ip_addr',
+ self.sysinfo['pre']['networking']['ip_addr']
+ )
def test_loopback_was_not_obfuscated(self):
self.assertFileHasContent('ip_addr', '127.0.0.1/8')
def test_mac_addrs_were_obfuscated(self):
- content = self.get_file_content('sos_commands/networking/ip_maddr_show')
+ content = self.get_file_content(
+ 'sos_commands/networking/ip_maddr_show'
+ )
for line in content.splitlines():
if line.strip().startswith('link'):
mac = line.strip().split()[1]
- assert mac.startswith('53:4f:53'), "Found unobfuscated mac addr %s" % mac
+ assert \
+ mac.startswith('53:4f:53'), \
+ f"Found unobfuscated mac addr {mac}"
def test_perms_unchanged_on_modified_file(self):
if self.hosts_obfuscated:
imode_orig = stat('/etc/hosts').st_mode
- imode_obfuscated = stat(self.get_name_in_archive('etc/hosts')).st_mode
+ imode_obfuscated = stat(
+ self.get_name_in_archive('etc/hosts')).st_mode
self.assertEqual(imode_orig, imode_obfuscated)
class ReportWithUserCustomisations(StageOneReportTest):
- """Testing for 1) obfuscated keywords provided by the user (--keywords option),
- and 2) skipping to clean specific files (--skip-cleaning-files option)
+ """Testing for 1) obfuscated keywords provided by the user (--keywords
+ option), and 2) skipping to clean specific files (--skip-cleaning-files
+ option)
:avocado: tags=stageone
"""
- sos_cmd = '--clean -o filesys,kernel --keywords=fstab,Linux,tmp,BOOT_IMAGE,fs.dentry-state \
- --skip-cleaning-files proc/cmdline,sos_commands/*/sysctl* --no-update'
+ sos_cmd = ('--clean -o filesys,kernel --keywords=fstab,Linux,tmp,'
+ 'BOOT_IMAGE,fs.dentry-state --skip-cleaning-files '
+ 'proc/cmdline,sos_commands/*/sysctl* --no-update')
- # Will the 'tmp' be properly treated in path to working dir without raising an error?
- # To make this test effective, we assume the test runs on a system / with Policy
- # returning '/var/tmp' as temp.dir
+ # Will the 'tmp' be properly treated in path to working dir without
+ # raising an error?
+ # To make this test effective, we assume the test runs on a system / with
+ # Policy returning '/var/tmp' as temp.dir
def test_keyword_in_tempdir_path(self):
- self.assertOutputContains('Your sosreport has been generated and saved in:')
+ self.assertOutputContains(
+ 'Your sosreport has been generated and saved in:'
+ )
self.assertTrue('tmp/' in self.archive)
# Ok, sort of cheesy here but this does actually test filename changes on
@@ -102,7 +118,10 @@ class ReportWithUserCustomisations(StageOneReportTest):
self.assertFileHasContent('proc/cmdline', 'BOOT_IMAGE')
def test_skip_cleaning_glob_file(self):
- self.assertFileHasContent('sos_commands/kernel/sysctl_-a', 'fs.dentry-state')
+ self.assertFileHasContent(
+ 'sos_commands/kernel/sysctl_-a',
+ 'fs.dentry-state'
+ )
class DefaultRemoveBinaryFilesTest(StageTwoReportTest):
@@ -134,8 +153,8 @@ class KeepBinaryFilesTest(StageTwoReportTest):
def test_warning_message_shown(self):
self.assertOutputContains(
- 'WARNING: binary files that potentially contain sensitive information '
- 'will NOT be removed from the final archive'
+ 'WARNING: binary files that potentially contain sensitive '
+ 'information will NOT be removed from the final archive'
)
def test_binary_is_in_archive(self):