From ccc4cca6e1d220a140dfa647aeff36bcae4f79dc Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Thu, 14 Nov 2013 13:29:42 -0500 Subject: [PATCH] Check only our VG name when testing if VG exists Rather than calling "vgs" we should just call "vgs " which returns only information about the VG we are querying. Also hardens test command string matching to error on unexpected calls. Change-Id: I25580e34b6589e161a51274f22dbb9ed922e43ed --- cinder/brick/local_dev/lvm.py | 2 +- cinder/tests/brick/test_brick_lvm.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cinder/brick/local_dev/lvm.py b/cinder/brick/local_dev/lvm.py index 4b3066c6a..47e6d5b9f 100644 --- a/cinder/brick/local_dev/lvm.py +++ b/cinder/brick/local_dev/lvm.py @@ -95,7 +95,7 @@ class LVM(executor.Executor): """ exists = False - cmd = ['vgs', '--noheadings', '-o', 'name'] + cmd = ['vgs', '--noheadings', '-o', 'name', self.vg_name] (out, err) = self._execute(*cmd, root_helper=self._root_helper, run_as_root=True) diff --git a/cinder/tests/brick/test_brick_lvm.py b/cinder/tests/brick/test_brick_lvm.py index 16df44b5b..83183b59e 100644 --- a/cinder/tests/brick/test_brick_lvm.py +++ b/cinder/tests/brick/test_brick_lvm.py @@ -67,9 +67,10 @@ class BrickLvmTestCase(test.TestCase): if 'vgs, --noheadings, --unit=g, -o, name' == cmd_string: data = " fake-volumes\n" - elif 'vgs, --noheadings, -o, name' == cmd_string: + data += " some-other-vg\n" + elif 'vgs, --noheadings, -o, name, fake-volumes' == cmd_string: data = " fake-volumes\n" - if 'vgs, --version' in cmd_string: + elif 'vgs, --version' in cmd_string: data = " LVM version: 2.02.95(2) (2012-03-06)\n" elif 'vgs, --noheadings, -o uuid, fake-volumes' in cmd_string: data = " kVxztV-dKpG-Rz7E-xtKY-jeju-QsYU-SLG6Z1\n" @@ -99,7 +100,7 @@ class BrickLvmTestCase(test.TestCase): data += " fake-volumes-2:/dev/sdb:10.00g:8.99g\n" data += " fake-volumes-3:/dev/sdc:10.00g:8.99g\n" else: - pass + raise AssertionError('unexpected command called: %s' % cmd_string) return (data, "") -- 2.45.2