From 438b3e8fc2af1882d1df21eaf94331c2b0836490 Mon Sep 17 00:00:00 2001 From: Kendall Nelson Date: Mon, 24 Jul 2017 22:15:01 -0700 Subject: [PATCH] Mock execute in unit test This patch fixes the test_volume_create_after_thin_creation test to mock execute instead of defining an execute method inside the test. Since the unit test is run twice with different options, the unit test asserts different things depending on the configuration of how the test is being run. Change-Id: Ia841ca55b36aa19d4d6b174239f4d4200793d4e5 Closes-bug: 1676646 --- cinder/tests/unit/brick/test_brick_lvm.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/cinder/tests/unit/brick/test_brick_lvm.py b/cinder/tests/unit/brick/test_brick_lvm.py index e0bec3974b4..10653a5eee0 100644 --- a/cinder/tests/unit/brick/test_brick_lvm.py +++ b/cinder/tests/unit/brick/test_brick_lvm.py @@ -347,18 +347,23 @@ class BrickLvmTestCase(test.TestCase): See bug #1220286 for more info. """ - vg_name = "vg-name" pool_name = vg_name + "-pool" - pool_path = "%s/%s" % (vg_name, pool_name) - - def executor(obj, *cmd, **kwargs): - self.assertEqual(pool_path, cmd[-1]) - - self.vg._executor = executor self.vg.create_thin_pool(pool_name, "1G") - self.vg.create_volume("test", "1G", lv_type='thin') + with mock.patch.object(self.vg, '_execute'): + self.vg.create_volume("test", "1G", lv_type='thin') + if self.configuration.lvm_suppress_fd_warnings is False: + self.vg._execute.assert_called_once_with( + 'env', 'LC_ALL=C', 'lvcreate', '-T', '-V', + '1G', '-n', 'test', 'fake-vg/vg-name-pool', + root_helper='sudo', run_as_root=True) + else: + self.vg._execute.assert_called_once_with( + 'env', 'LC_ALL=C', 'LVM_SUPPRESS_FD_WARNINGS=1', + 'lvcreate', '-T', '-V', '1G', '-n', 'test', + 'fake-vg/vg-name-pool', root_helper='sudo', + run_as_root=True) self.assertEqual(pool_name, self.vg.vg_thin_pool) def test_volume_create_when_executor_failed(self):