]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix intermittent UT failures in test_utils
authorarmando-migliaccio <armamig@gmail.com>
Tue, 7 Apr 2015 22:37:59 +0000 (15:37 -0700)
committerarmando-migliaccio <armamig@gmail.com>
Tue, 7 Apr 2015 23:40:47 +0000 (16:40 -0700)
Change eba4c2941ee introduced these tests. However they are not that useful as they
simply mimick the code, without really ensuring that the behavior is expected, so
they provide negative value ([1]), plus, they fail randomly.

This patch removes them in favor of a more useful functional check.

[1] http://googletesting.blogspot.com/2015/01/testing-on-toilet-change-detector-tests.html

Closes-bug: #1441347

Change-Id: I8a321995295deef7f6d30be303486be491e2771f

neutron/tests/functional/agent/linux/test_process_monitor.py
neutron/tests/unit/agent/linux/test_utils.py

index 1bf50803fc6e567d99eca5f65e84edb61524dc24..51bf796682e41ce8f1aa32b2ee21ab4c0206b1e8 100644 (file)
@@ -12,6 +12,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import os
+
 from oslo_config import cfg
 from six import moves
 
@@ -78,6 +80,10 @@ class BaseTestProcessMonitor(base.BaseTestCase):
         def all_children_active():
             return all(pm.active for pm in self._child_processes)
 
+        for pm in self._child_processes:
+            directory = os.path.dirname(pm.get_pid_file_name())
+            self.assertEqual(0o755, os.stat(directory).st_mode & 0o777)
+
         # we need to allow extra_time for the check process to happen
         # and properly execute action over the gone processes under
         # high load conditions
index a1e1b85f2e96ead524113c3ce2230c0e59976394..512f1bd7788011b71eed90348a3499913545e16b 100644 (file)
@@ -12,8 +12,6 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import os
-
 import mock
 import socket
 import testtools
@@ -227,20 +225,6 @@ class TestBaseOSUtils(base.BaseTestCase):
     EGID = 456
     EGNAME = 'group'
 
-    @mock.patch.object(os.path, 'isdir', return_value=False)
-    @mock.patch.object(os, 'makedirs')
-    def test_ensure_dir_not_exist(self, makedirs, isdir):
-        utils.ensure_dir('/the')
-        isdir.assert_called_once_with('/the')
-        makedirs.assert_called_once_with('/the', 0o755)
-
-    @mock.patch.object(os.path, 'isdir', return_value=True)
-    @mock.patch.object(os, 'makedirs')
-    def test_ensure_dir_exist(self, makedirs, isdir):
-        utils.ensure_dir('/the')
-        isdir.assert_called_once_with('/the')
-        self.assertFalse(makedirs.called)
-
     @mock.patch('os.geteuid', return_value=EUID)
     @mock.patch('pwd.getpwuid', return_value=FakeUser(EUNAME))
     def test_is_effective_user_id(self, getpwuid, geteuid):