From 6e8e2adc3501b51f89d8766344caebc12c1948ba Mon Sep 17 00:00:00 2001 From: Celso Providelo Date: Thu, 5 Feb 2015 09:17:54 -0500 Subject: [PATCH 1/2] Fix autopkgtest tests, extending the current test setup to mangle the shared configuration file appropriately for each test context (autopkgtest & boottest). --- britney.conf | 2 +- tests/test_autopkgtest.py | 16 ++++++++++++++++ tests/test_boottest.py | 6 +++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/britney.conf b/britney.conf index 940e796..827bd1f 100644 --- a/britney.conf +++ b/britney.conf @@ -62,7 +62,7 @@ SMOOTH_UPDATES = badgers REMOVE_OBSOLETE = no -ADT_ENABLE = no +ADT_ENABLE = yes ADT_DEBUG = no ADT_ARCHES = amd64 i386 diff --git a/tests/test_autopkgtest.py b/tests/test_autopkgtest.py index d77fabc..04f1a92 100644 --- a/tests/test_autopkgtest.py +++ b/tests/test_autopkgtest.py @@ -31,6 +31,16 @@ class TestAutoPkgTest(TestBase): def setUp(self): super(TestAutoPkgTest, self).setUp() + # Mofify configuration according to the test context. + self.old_config = None + with open(self.britney_conf, 'r') as fp: + self.old_config = fp.read() + # Disable boottests. + config = self.old_config.replace( + 'BOOTTEST_ENABLE = yes', 'BOOTTEST_ENABLE = no') + with open(self.britney_conf, 'w') as fp: + fp.write(config) + # fake adt-britney script self.adt_britney = os.path.join( self.data.home, 'auto-package-testing', 'jenkins', 'adt-britney') @@ -53,6 +63,12 @@ echo "$@" >> /%s/adt-britney.log ''' % self.data.path) 'Conflicts': 'green'}) self.data.add('justdata', False, {'Architecture': 'all'}) + def tearDown(self): + """Replace the old_config.""" + with open(self.britney_conf, 'w') as fp: + fp.write(self.old_config) + super(TestAutoPkgTest, self).tearDown() + def __merge_records(self, results, history=""): '''Merges a list of results with records in history. diff --git a/tests/test_boottest.py b/tests/test_boottest.py index 8a588b9..41e07ee 100644 --- a/tests/test_boottest.py +++ b/tests/test_boottest.py @@ -117,11 +117,10 @@ class TestBoottestEnd2End(TestBase): def setUp(self): super(TestBoottestEnd2End, self).setUp() - self.britney_conf = os.path.join( - PROJECT_DIR, 'britney.conf') - old_config = None + self.old_config = None with open(self.britney_conf, 'r') as fp: self.old_config = fp.read() + # Disable autopkgtests. config = self.old_config.replace( 'ADT_ENABLE = yes', 'ADT_ENABLE = no') # Disable TouchManifest auto-fetching. @@ -151,6 +150,7 @@ class TestBoottestEnd2End(TestBase): """ Replace the old_config. """ with open(self.britney_conf, 'w') as fp: fp.write(self.old_config) + super(TestBoottestEnd2End, self).tearDown() def create_manifest(self, lines): """Create a manifest for this britney run context.""" From 72b01f8cc72acb19955b12b1c0299094ed4f0415 Mon Sep 17 00:00:00 2001 From: Celso Providelo Date: Thu, 5 Feb 2015 09:43:23 -0500 Subject: [PATCH 2/2] Using addCleanup() for restoring original configuration contents in tests. --- tests/__init__.py | 5 +++++ tests/test_autopkgtest.py | 14 ++++---------- tests/test_boottest.py | 18 +++++++----------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 6370632..81c0316 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -135,6 +135,11 @@ class TestBase(unittest.TestCase): def tearDown(self): del self.data + def restore_config(self, content): + """Helper for restoring configuration contents on cleanup.""" + with open(self.britney_conf, 'w') as fp: + fp.write(content) + def run_britney(self, args=[]): '''Run britney. diff --git a/tests/test_autopkgtest.py b/tests/test_autopkgtest.py index 04f1a92..6112098 100644 --- a/tests/test_autopkgtest.py +++ b/tests/test_autopkgtest.py @@ -32,14 +32,14 @@ class TestAutoPkgTest(TestBase): super(TestAutoPkgTest, self).setUp() # Mofify configuration according to the test context. - self.old_config = None with open(self.britney_conf, 'r') as fp: - self.old_config = fp.read() + original_config = fp.read() # Disable boottests. - config = self.old_config.replace( + new_config = original_config.replace( 'BOOTTEST_ENABLE = yes', 'BOOTTEST_ENABLE = no') with open(self.britney_conf, 'w') as fp: - fp.write(config) + fp.write(new_config) + self.addCleanup(self.restore_config, original_config) # fake adt-britney script self.adt_britney = os.path.join( @@ -63,12 +63,6 @@ echo "$@" >> /%s/adt-britney.log ''' % self.data.path) 'Conflicts': 'green'}) self.data.add('justdata', False, {'Architecture': 'all'}) - def tearDown(self): - """Replace the old_config.""" - with open(self.britney_conf, 'w') as fp: - fp.write(self.old_config) - super(TestAutoPkgTest, self).tearDown() - def __merge_records(self, results, history=""): '''Merges a list of results with records in history. diff --git a/tests/test_boottest.py b/tests/test_boottest.py index 41e07ee..01772e8 100644 --- a/tests/test_boottest.py +++ b/tests/test_boottest.py @@ -117,17 +117,19 @@ class TestBoottestEnd2End(TestBase): def setUp(self): super(TestBoottestEnd2End, self).setUp() - self.old_config = None + + # Modify shared configuration file. with open(self.britney_conf, 'r') as fp: - self.old_config = fp.read() + original_config = fp.read() # Disable autopkgtests. - config = self.old_config.replace( + new_config = original_config.replace( 'ADT_ENABLE = yes', 'ADT_ENABLE = no') # Disable TouchManifest auto-fetching. - config = config.replace( + new_config = new_config.replace( 'BOOTTEST_FETCH = yes', 'BOOTTEST_FETCH = no') with open(self.britney_conf, 'w') as fp: - fp.write(config) + fp.write(new_config) + self.addCleanup(self.restore_config, original_config) self.data.add('libc6', False, {'Architecture': 'armhf'}), @@ -146,12 +148,6 @@ class TestBoottestEnd2End(TestBase): 'pyqt5:armhf 1.0', ]) - def tearDown(self): - """ Replace the old_config. """ - with open(self.britney_conf, 'w') as fp: - fp.write(self.old_config) - super(TestBoottestEnd2End, self).tearDown() - def create_manifest(self, lines): """Create a manifest for this britney run context.""" path = os.path.join(