]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-network: always cleanup the testing environment
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 27 Jan 2022 21:59:43 +0000 (06:59 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 27 Jan 2022 21:59:52 +0000 (06:59 +0900)
Previously, if a subtest fail, then the cleanup process does not run,
and affects the subsequent tests.

test/test-network/systemd-networkd-tests.py

index 0233c4dd1fd48b85ab77483661bf585e9b454478..e7a84c7a98e1d20d3993e30193b044e17b9dbc0d 100755 (executable)
@@ -3053,7 +3053,6 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
         self.wait_operstate('test1', 'routable')
 
     def _test_activation_policy(self, test):
-        self.setUp()
         conffile = '25-activation-policy.network'
         if test:
             conffile = f'{conffile}.d/{test}.conf'
@@ -3088,15 +3087,14 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
             expect_up = initial_up if always else next_up
             next_up = not next_up
 
-        self.tearDown()
-
     def test_activation_policy(self):
         for test in ['up', 'always-up', 'manual', 'always-down', 'down', '']:
             with self.subTest(test=test):
+                self.setUp()
                 self._test_activation_policy(test)
+                self.tearDown()
 
     def _test_activation_policy_required_for_online(self, policy, required):
-        self.setUp()
         conffile = '25-activation-policy.network'
         units = ['11-dummy.netdev', '12-dummy.netdev', '12-dummy.network', conffile]
         if policy:
@@ -3131,13 +3129,13 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
         yesno = 'yes' if expected else 'no'
         self.assertRegex(output, f'Required For Online: {yesno}')
 
-        self.tearDown()
-
     def test_activation_policy_required_for_online(self):
         for policy in ['up', 'always-up', 'manual', 'always-down', 'down', 'bound', '']:
             for required in ['yes', 'no', '']:
                 with self.subTest(policy=policy, required=required):
+                    self.setUp()
                     self._test_activation_policy_required_for_online(policy, required)
+                    self.tearDown()
 
     def test_domain(self):
         copy_unit_to_networkd_unit_path('12-dummy.netdev', '24-search-domain.network')