diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-05-13 19:16:49 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-05-13 19:16:49 +0000 |
| commit | e31af73cd77cfc963dc003680f4b5042ee9cd6df (patch) | |
| tree | f021404a34a77b2b2623b3b9752dffc8bc9ae71b /nova/tests | |
| parent | 30d85bc9aeb3cf691b3505acd48bb953d87e6002 (diff) | |
| parent | 6be85774aec674eef7bfbf66f8885a4531c7c605 (diff) | |
Merge "Convert to using newly imported processutils."
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/baremetal/test_virtual_power_driver.py | 15 | ||||
| -rw-r--r-- | nova/tests/fake_processutils.py (renamed from nova/tests/fake_utils.py) | 7 | ||||
| -rw-r--r-- | nova/tests/test_imagebackend.py | 14 | ||||
| -rw-r--r-- | nova/tests/test_virt_disk_vfs_localfs.py | 115 | ||||
| -rw-r--r-- | nova/tests/test_xenapi.py | 10 |
5 files changed, 99 insertions, 62 deletions
diff --git a/nova/tests/baremetal/test_virtual_power_driver.py b/nova/tests/baremetal/test_virtual_power_driver.py index 4cac0a3ba..d6d615194 100644 --- a/nova/tests/baremetal/test_virtual_power_driver.py +++ b/nova/tests/baremetal/test_virtual_power_driver.py @@ -27,7 +27,6 @@ from nova.tests.baremetal.db import base as bm_db_base from nova.tests.baremetal.db import utils as bm_db_utils from nova.tests.image import fake as fake_image from nova.tests import utils -from nova import utils as nutils from nova.virt.baremetal import db from nova.virt.baremetal import virtual_power_driver import nova.virt.powervm.common as connection @@ -352,9 +351,9 @@ class VPDClassMethodsTestCase(BareMetalVPDTestCase): self._create_pm() self.mox.StubOutWithMock(self.pm, '_set_connection') - self.mox.StubOutWithMock(nutils, 'ssh_execute') + self.mox.StubOutWithMock(processutils, 'ssh_execute') self.pm._set_connection().AndReturn(True) - nutils.ssh_execute(None, '/usr/bin/VBoxManage test return', + processutils.ssh_execute(None, '/usr/bin/VBoxManage test return', check_exit_code=True).AndReturn(("test\nreturn", "")) self.pm._matched_name = 'testNode' self.mox.ReplayAll() @@ -367,10 +366,10 @@ class VPDClassMethodsTestCase(BareMetalVPDTestCase): self._create_pm() self.mox.StubOutWithMock(self.pm, '_set_connection') - self.mox.StubOutWithMock(nutils, 'ssh_execute') + self.mox.StubOutWithMock(processutils, 'ssh_execute') self.pm._set_connection().AndReturn(True) - nutils.ssh_execute(None, '/usr/bin/VBoxManage test return', + processutils.ssh_execute(None, '/usr/bin/VBoxManage test return', check_exit_code=True).\ AndRaise(processutils.ProcessExecutionError) self.mox.ReplayAll() @@ -384,14 +383,14 @@ class VPDClassMethodsTestCase(BareMetalVPDTestCase): self._create_pm() self.mox.StubOutWithMock(self.pm, '_check_for_node') - self.mox.StubOutWithMock(nutils, 'ssh_execute') + self.mox.StubOutWithMock(processutils, 'ssh_execute') self.pm._check_for_node().AndReturn(['"testNode"']) self.pm._check_for_node().AndReturn(['"testNode"']) - nutils.ssh_execute('test', '/usr/bin/VBoxManage startvm ', + processutils.ssh_execute('test', '/usr/bin/VBoxManage startvm ', check_exit_code=True).\ AndRaise(processutils.ProcessExecutionError) - nutils.ssh_execute('test', '/usr/bin/VBoxManage list runningvms', + processutils.ssh_execute('test', '/usr/bin/VBoxManage list runningvms', check_exit_code=True).\ AndRaise(processutils.ProcessExecutionError) diff --git a/nova/tests/fake_utils.py b/nova/tests/fake_processutils.py index 6a295b43b..04d39e7e5 100644 --- a/nova/tests/fake_utils.py +++ b/nova/tests/fake_processutils.py @@ -14,7 +14,7 @@ # License for the specific language governing permissions and limitations # under the License. -"""This modules stubs out functions in nova.utils.""" +"""This modules stubs out functions in openstack.common.processutils.""" import re @@ -22,7 +22,6 @@ from eventlet import greenthread from nova.openstack.common import log as logging from nova.openstack.common import processutils -from nova import utils LOG = logging.getLogger(__name__) @@ -106,7 +105,7 @@ def fake_execute(*cmd_parts, **kwargs): return reply -def stub_out_utils_execute(stubs): +def stub_out_processutils_execute(stubs): fake_execute_set_repliers([]) fake_execute_clear_log() - stubs.Set(utils, 'execute', fake_execute) + stubs.Set(processutils, 'execute', fake_execute) diff --git a/nova/tests/test_imagebackend.py b/nova/tests/test_imagebackend.py index 4ec36daa8..0f1d8532b 100644 --- a/nova/tests/test_imagebackend.py +++ b/nova/tests/test_imagebackend.py @@ -24,7 +24,7 @@ from nova import exception from nova.openstack.common import uuidutils from nova import test from nova.tests import fake_libvirt_utils -from nova.tests import fake_utils +from nova.tests import fake_processutils from nova.virt.libvirt import imagebackend CONF = cfg.CONF @@ -131,8 +131,8 @@ class _ImageTestCase(object): def test_prealloc_image(self): CONF.set_override('preallocate_images', 'space') - fake_utils.fake_execute_clear_log() - fake_utils.stub_out_utils_execute(self.stubs) + fake_processutils.fake_execute_clear_log() + fake_processutils.stub_out_processutils_execute(self.stubs) image = self.image_class(self.INSTANCE, self.NAME) def fake_fetch(target, *args, **kwargs): @@ -144,7 +144,7 @@ class _ImageTestCase(object): image.cache(fake_fetch, self.TEMPLATE_PATH, self.SIZE) image.cache(fake_fetch, self.TEMPLATE_PATH, self.SIZE) - self.assertEqual(fake_utils.fake_execute_get_log(), + self.assertEqual(fake_processutils.fake_execute_get_log(), ['fallocate -n -l 1 %s.fallocate_test' % self.PATH, 'fallocate -n -l %s %s' % (self.SIZE, self.PATH), 'fallocate -n -l %s %s' % (self.SIZE, self.PATH)]) @@ -427,8 +427,8 @@ class LvmTestCase(_ImageTestCase, test.TestCase): def test_prealloc_image(self): CONF.set_override('preallocate_images', 'space') - fake_utils.fake_execute_clear_log() - fake_utils.stub_out_utils_execute(self.stubs) + fake_processutils.fake_execute_clear_log() + fake_processutils.stub_out_processutils_execute(self.stubs) image = self.image_class(self.INSTANCE, self.NAME) def fake_fetch(target, *args, **kwargs): @@ -438,7 +438,7 @@ class LvmTestCase(_ImageTestCase, test.TestCase): image.cache(fake_fetch, self.TEMPLATE_PATH, self.SIZE) - self.assertEqual(fake_utils.fake_execute_get_log(), []) + self.assertEqual(fake_processutils.fake_execute_get_log(), []) class BackendTestCase(test.TestCase): diff --git a/nova/tests/test_virt_disk_vfs_localfs.py b/nova/tests/test_virt_disk_vfs_localfs.py index 5bbac670e..b52817b18 100644 --- a/nova/tests/test_virt_disk_vfs_localfs.py +++ b/nova/tests/test_virt_disk_vfs_localfs.py @@ -14,13 +14,17 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo.config import cfg + from nova import exception +from nova.openstack.common import processutils from nova import test from nova.tests import utils as tests_utils -from nova import utils from nova.virt.disk.vfs import localfs as vfsimpl +CONF = cfg.CONF + dirs = [] files = {} commands = [] @@ -121,13 +125,13 @@ class VirtDiskVFSLocalFSTestPaths(test.TestCase): def setUp(self): super(VirtDiskVFSLocalFSTestPaths, self).setUp() - real_execute = utils.execute + real_execute = processutils.execute def nonroot_execute(*cmd_parts, **kwargs): kwargs.pop('run_as_root', None) return real_execute(*cmd_parts, **kwargs) - self.stubs.Set(utils, 'execute', nonroot_execute) + self.stubs.Set(processutils, 'execute', nonroot_execute) def test_check_safe_path(self): if tests_utils.is_osx(): @@ -152,7 +156,7 @@ class VirtDiskVFSLocalFSTest(test.TestCase): global dirs, commands dirs = [] commands = [] - self.stubs.Set(utils, 'execute', fake_execute) + self.stubs.Set(processutils, 'execute', fake_execute) vfs = vfsimpl.VFSLocalFS(imgfile="/dummy.qcow2", imgfmt="qcow2") vfs.imgdir = "/scratch/dir" @@ -162,25 +166,30 @@ class VirtDiskVFSLocalFSTest(test.TestCase): self.assertEqual(dirs, ["/scratch/dir/some/dir", "/scratch/dir/other/dir"]), + root_helper = 'sudo nova-rootwrap %s' % CONF.rootwrap_config self.assertEqual(commands, [{'args': ('readlink', '-nm', '/scratch/dir/some/dir'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('mkdir', '-p', '/scratch/dir/some/dir'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('readlink', '-nm', '/scratch/dir/other/dir'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('mkdir', '-p', '/scratch/dir/other/dir'), - 'kwargs': {'run_as_root': True}}]) + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}]) def test_append_file(self): global files, commands files = {} commands = [] - self.stubs.Set(utils, 'execute', fake_execute) + self.stubs.Set(processutils, 'execute', fake_execute) vfs = vfsimpl.VFSLocalFS(imgfile="/dummy.qcow2", imgfmt="qcow2") vfs.imgdir = "/scratch/dir" @@ -190,20 +199,23 @@ class VirtDiskVFSLocalFSTest(test.TestCase): self.assertEquals(files["/scratch/dir/some/file"]["content"], "Hello World Goodbye") + root_helper = 'sudo nova-rootwrap %s' % CONF.rootwrap_config self.assertEqual(commands, [{'args': ('readlink', '-nm', '/scratch/dir/some/file'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('tee', '-a', '/scratch/dir/some/file'), 'kwargs': {'process_input': ' Goodbye', - 'run_as_root': True}}]) + 'run_as_root': True, + 'root_helper': root_helper}}]) def test_replace_file(self): global files, commands files = {} commands = [] - self.stubs.Set(utils, 'execute', fake_execute) + self.stubs.Set(processutils, 'execute', fake_execute) vfs = vfsimpl.VFSLocalFS(imgfile="/dummy.qcow2", imgfmt="qcow2") vfs.imgdir = "/scratch/dir" @@ -213,36 +225,42 @@ class VirtDiskVFSLocalFSTest(test.TestCase): self.assertEquals(files["/scratch/dir/some/file"]["content"], "Goodbye") + root_helper = 'sudo nova-rootwrap %s' % CONF.rootwrap_config self.assertEqual(commands, [{'args': ('readlink', '-nm', '/scratch/dir/some/file'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('tee', '/scratch/dir/some/file'), 'kwargs': {'process_input': 'Goodbye', - 'run_as_root': True}}]) + 'run_as_root': True, + 'root_helper': root_helper}}]) def test_read_file(self): global commands, files files = {} commands = [] - self.stubs.Set(utils, 'execute', fake_execute) + self.stubs.Set(processutils, 'execute', fake_execute) vfs = vfsimpl.VFSLocalFS(imgfile="/dummy.qcow2", imgfmt="qcow2") vfs.imgdir = "/scratch/dir" self.assertEqual(vfs.read_file("/some/file"), "Hello World") + root_helper = 'sudo nova-rootwrap %s' % CONF.rootwrap_config self.assertEqual(commands, [{'args': ('readlink', '-nm', '/scratch/dir/some/file'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('cat', '/scratch/dir/some/file'), - 'kwargs': {'run_as_root': True}}]) + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}]) def test_has_file(self): global commands, files files = {} commands = [] - self.stubs.Set(utils, 'execute', fake_execute) + self.stubs.Set(processutils, 'execute', fake_execute) vfs = vfsimpl.VFSLocalFS(imgfile="/dummy.qcow2", imgfmt="qcow2") vfs.imgdir = "/scratch/dir" @@ -251,31 +269,38 @@ class VirtDiskVFSLocalFSTest(test.TestCase): self.assertTrue(vfs.has_file("/some/file")) self.assertFalse(vfs.has_file("/other/file")) + root_helper = 'sudo nova-rootwrap %s' % CONF.rootwrap_config self.assertEqual(commands, [{'args': ('readlink', '-nm', '/scratch/dir/some/file'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('cat', '/scratch/dir/some/file'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('readlink', '-nm', '/scratch/dir/some/file'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('readlink', '-e', '/scratch/dir/some/file'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('readlink', '-nm', '/scratch/dir/other/file'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('readlink', '-e', '/scratch/dir/other/file'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, ]) def test_set_permissions(self): global commands, files commands = [] files = {} - self.stubs.Set(utils, 'execute', fake_execute) + self.stubs.Set(processutils, 'execute', fake_execute) vfs = vfsimpl.VFSLocalFS(imgfile="/dummy.qcow2", imgfmt="qcow2") vfs.imgdir = "/scratch/dir" @@ -284,24 +309,29 @@ class VirtDiskVFSLocalFSTest(test.TestCase): vfs.set_permissions("/some/file", 0777) self.assertEquals(files["/scratch/dir/some/file"]["mode"], 0777) + root_helper = 'sudo nova-rootwrap %s' % CONF.rootwrap_config self.assertEqual(commands, [{'args': ('readlink', '-nm', '/scratch/dir/some/file'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('cat', '/scratch/dir/some/file'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('readlink', '-nm', '/scratch/dir/some/file'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('chmod', '777', '/scratch/dir/some/file'), - 'kwargs': {'run_as_root': True}}]) + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}]) def test_set_ownership(self): global commands, files commands = [] files = {} - self.stubs.Set(utils, 'execute', fake_execute) + self.stubs.Set(processutils, 'execute', fake_execute) vfs = vfsimpl.VFSLocalFS(imgfile="/dummy.qcow2", imgfmt="qcow2") vfs.imgdir = "/scratch/dir" @@ -322,27 +352,36 @@ class VirtDiskVFSLocalFSTest(test.TestCase): self.assertEquals(files["/scratch/dir/some/file"]["uid"], 110) self.assertEquals(files["/scratch/dir/some/file"]["gid"], 600) + root_helper = 'sudo nova-rootwrap %s' % CONF.rootwrap_config self.assertEqual(commands, [{'args': ('readlink', '-nm', '/scratch/dir/some/file'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('cat', '/scratch/dir/some/file'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('readlink', '-nm', '/scratch/dir/some/file'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('chown', 'fred', '/scratch/dir/some/file'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('readlink', '-nm', '/scratch/dir/some/file'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('chgrp', 'users', '/scratch/dir/some/file'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('readlink', '-nm', '/scratch/dir/some/file'), - 'kwargs': {'run_as_root': True}}, + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}, {'args': ('chown', 'joe:admins', '/scratch/dir/some/file'), - 'kwargs': {'run_as_root': True}}]) + 'kwargs': {'run_as_root': True, + 'root_helper': root_helper}}]) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 62e9b08f1..9a366d7bf 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -39,7 +39,7 @@ from nova.openstack.common import log as logging from nova import test from nova.tests.db import fakes as db_fakes from nova.tests import fake_network -from nova.tests import fake_utils +from nova.tests import fake_processutils import nova.tests.image.fake as fake_image from nova.tests import matchers from nova.tests.xenapi import stubs @@ -323,7 +323,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase): stubs.stubout_get_this_vm_uuid(self.stubs) stubs.stubout_is_vdi_pv(self.stubs) stubs.stub_out_vm_methods(self.stubs) - fake_utils.stub_out_utils_execute(self.stubs) + fake_processutils.stub_out_processutils_execute(self.stubs) self.user_id = 'fake' self.project_id = 'fake' self.context = context.RequestContext(self.user_id, self.project_id) @@ -872,7 +872,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase): def _readlink_handler(cmd_parts, **kwargs): return os.path.realpath(cmd_parts[2]), '' - fake_utils.fake_execute_set_repliers([ + fake_processutils.fake_execute_set_repliers([ # Capture the tee .../etc/network/interfaces command (r'tee.*interfaces', _tee_handler), (r'readlink -nm.*', _readlink_handler), @@ -917,7 +917,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase): self._tee_executed = True return '', '' - fake_utils.fake_execute_set_repliers([ + fake_processutils.fake_execute_set_repliers([ (r'mount', _mount_handler), (r'umount', _umount_handler), (r'tee.*interfaces', _tee_handler)]) @@ -1319,7 +1319,7 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase): self.migration = db.migration_create( context.get_admin_context(), migration_values) - fake_utils.stub_out_utils_execute(self.stubs) + fake_processutils.stub_out_processutils_execute(self.stubs) stubs.stub_out_migration_methods(self.stubs) stubs.stubout_get_this_vm_uuid(self.stubs) |
