diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-05-06 16:01:38 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-05-06 16:01:38 +0000 |
| commit | ef0df189db0b4c18e2742bbd195a18afb535b908 (patch) | |
| tree | 9976cffd9225de61438bb525ab30d20b6fa35dc0 /nova/tests | |
| parent | 9a7683e59ba1c175f3986eb42480f66f0a7e7569 (diff) | |
| parent | 1a11790f2d26ec92858a3ffa100388310912fae1 (diff) | |
Merge "Convert to using oslo's execute() method."
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/baremetal/test_virtual_power_driver.py | 7 | ||||
| -rw-r--r-- | nova/tests/fake_utils.py | 4 | ||||
| -rw-r--r-- | nova/tests/network/test_manager.py | 3 | ||||
| -rw-r--r-- | nova/tests/test_crypto.py | 3 | ||||
| -rw-r--r-- | nova/tests/test_powervm.py | 4 | ||||
| -rw-r--r-- | nova/tests/test_utils.py | 86 |
6 files changed, 14 insertions, 93 deletions
diff --git a/nova/tests/baremetal/test_virtual_power_driver.py b/nova/tests/baremetal/test_virtual_power_driver.py index b98ef5182..4cac0a3ba 100644 --- a/nova/tests/baremetal/test_virtual_power_driver.py +++ b/nova/tests/baremetal/test_virtual_power_driver.py @@ -22,6 +22,7 @@ import mox from oslo.config import cfg from nova import exception +from nova.openstack.common import processutils 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 @@ -371,7 +372,7 @@ class VPDClassMethodsTestCase(BareMetalVPDTestCase): self.pm._set_connection().AndReturn(True) nutils.ssh_execute(None, '/usr/bin/VBoxManage test return', check_exit_code=True).\ - AndRaise(exception.ProcessExecutionError) + AndRaise(processutils.ProcessExecutionError) self.mox.ReplayAll() result = self.pm._run_command("test return") @@ -389,10 +390,10 @@ class VPDClassMethodsTestCase(BareMetalVPDTestCase): self.pm._check_for_node().AndReturn(['"testNode"']) nutils.ssh_execute('test', '/usr/bin/VBoxManage startvm ', check_exit_code=True).\ - AndRaise(exception.ProcessExecutionError) + AndRaise(processutils.ProcessExecutionError) nutils.ssh_execute('test', '/usr/bin/VBoxManage list runningvms', check_exit_code=True).\ - AndRaise(exception.ProcessExecutionError) + AndRaise(processutils.ProcessExecutionError) self.mox.ReplayAll() self.pm._connection = 'test' diff --git a/nova/tests/fake_utils.py b/nova/tests/fake_utils.py index 08a84e73f..6a295b43b 100644 --- a/nova/tests/fake_utils.py +++ b/nova/tests/fake_utils.py @@ -20,8 +20,8 @@ import re from eventlet import greenthread -from nova import exception from nova.openstack.common import log as logging +from nova.openstack.common import processutils from nova import utils LOG = logging.getLogger(__name__) @@ -92,7 +92,7 @@ def fake_execute(*cmd_parts, **kwargs): attempts=attempts, run_as_root=run_as_root, check_exit_code=check_exit_code) - except exception.ProcessExecutionError as e: + except processutils.ProcessExecutionError as e: LOG.debug(_('Faked command raised an exception %s'), e) raise diff --git a/nova/tests/network/test_manager.py b/nova/tests/network/test_manager.py index c9a4cd7d6..b47987b52 100644 --- a/nova/tests/network/test_manager.py +++ b/nova/tests/network/test_manager.py @@ -33,6 +33,7 @@ from nova.network import model as net_model from nova.openstack.common.db import exception as db_exc from nova.openstack.common import importutils from nova.openstack.common import log as logging +from nova.openstack.common import processutils from nova.openstack.common import rpc from nova.openstack.common.rpc import common as rpc_common from nova import quota @@ -809,7 +810,7 @@ class VlanNetworkTestCase(test.TestCase): self.local = True def fake8(*args, **kwargs): - raise exception.ProcessExecutionError('', + raise processutils.ProcessExecutionError('', 'Cannot find device "em0"\n') def fake9(*args, **kwargs): diff --git a/nova/tests/test_crypto.py b/nova/tests/test_crypto.py index e328babfe..2264273d7 100644 --- a/nova/tests/test_crypto.py +++ b/nova/tests/test_crypto.py @@ -23,6 +23,7 @@ import mox from nova import crypto from nova import db from nova import exception +from nova.openstack.common import processutils from nova import test from nova import utils @@ -200,7 +201,7 @@ e6fCXWECgYEAqgpGvva5kJ1ISgNwnJbwiNw0sOT9BMOsdNZBElf0kJIIy6FMPvap '-inkey', sshkey, process_input=text) return dec - except exception.ProcessExecutionError as exc: + except processutils.ProcessExecutionError as exc: raise exception.DecryptionFailure(reason=exc.stderr) def test_ssh_encrypt_decrypt_text(self): diff --git a/nova/tests/test_powervm.py b/nova/tests/test_powervm.py index 96954269e..73299f23a 100644 --- a/nova/tests/test_powervm.py +++ b/nova/tests/test_powervm.py @@ -22,13 +22,13 @@ import contextlib from nova import context from nova import db -from nova import exception as nova_exception from nova import test from nova.compute import instance_types from nova.compute import power_state from nova.compute import task_states from nova.network import model as network_model +from nova.openstack.common import processutils from nova.tests import fake_network_cache_model from nova.tests.image import fake from nova.virt import images @@ -227,7 +227,7 @@ class PowerVMDriverTestCase(test.TestCase): self.powervm_connection._powervm, 'get_host_stats', lambda *x, **y: raise_( - (nova_exception.ProcessExecutionError('instance_name')))) + (processutils.ProcessExecutionError('instance_name')))) fake_net_info = network_model.NetworkInfo([ fake_network_cache_model.new_vif()]) self.assertRaises(exception.PowerVMLPARCreationFailed, diff --git a/nova/tests/test_utils.py b/nova/tests/test_utils.py index af6a9b9aa..6b7af48fc 100644 --- a/nova/tests/test_utils.py +++ b/nova/tests/test_utils.py @@ -30,6 +30,7 @@ from oslo.config import cfg import nova from nova import exception +from nova.openstack.common import processutils from nova.openstack.common import timeutils from nova import test from nova import utils @@ -72,89 +73,6 @@ class ByteConversionTest(test.TestCase): self.assertRaises(TypeError, utils.to_bytes, v) -class ExecuteTestCase(test.TestCase): - - def test_retry_on_failure(self): - fd, tmpfilename = tempfile.mkstemp() - _, tmpfilename2 = tempfile.mkstemp() - try: - fp = os.fdopen(fd, 'w+') - fp.write('''#!/bin/sh -# If stdin fails to get passed during one of the runs, make a note. -if ! grep -q foo -then - echo 'failure' > "$1" -fi -# If stdin has failed to get passed during this or a previous run, exit early. -if grep failure "$1" -then - exit 1 -fi -runs="$(cat $1)" -if [ -z "$runs" ] -then - runs=0 -fi -runs=$(($runs + 1)) -echo $runs > "$1" -exit 1 -''') - fp.close() - os.chmod(tmpfilename, 0755) - self.assertRaises(exception.ProcessExecutionError, - utils.execute, - tmpfilename, tmpfilename2, attempts=10, - process_input='foo', - delay_on_retry=False) - fp = open(tmpfilename2, 'r') - runs = fp.read() - fp.close() - self.assertNotEquals(runs.strip(), 'failure', 'stdin did not ' - 'always get passed ' - 'correctly') - runs = int(runs.strip()) - self.assertEquals(runs, 10, - 'Ran %d times instead of 10.' % (runs,)) - finally: - os.unlink(tmpfilename) - os.unlink(tmpfilename2) - - def test_unknown_kwargs_raises_error(self): - self.assertRaises(exception.NovaException, - utils.execute, - '/usr/bin/env', 'true', - this_is_not_a_valid_kwarg=True) - - def test_check_exit_code_boolean(self): - utils.execute('/usr/bin/env', 'false', check_exit_code=False) - self.assertRaises(exception.ProcessExecutionError, - utils.execute, - '/usr/bin/env', 'false', check_exit_code=True) - - def test_no_retry_on_success(self): - fd, tmpfilename = tempfile.mkstemp() - _, tmpfilename2 = tempfile.mkstemp() - try: - fp = os.fdopen(fd, 'w+') - fp.write('''#!/bin/sh -# If we've already run, bail out. -grep -q foo "$1" && exit 1 -# Mark that we've run before. -echo foo > "$1" -# Check that stdin gets passed correctly. -grep foo -''') - fp.close() - os.chmod(tmpfilename, 0755) - utils.execute(tmpfilename, - tmpfilename2, - process_input='foo', - attempts=2) - finally: - os.unlink(tmpfilename) - os.unlink(tmpfilename2) - - class GetFromPathTestCase(test.TestCase): def test_tolerates_nones(self): f = utils.get_from_path @@ -429,7 +347,7 @@ class GenericUtilsTestCase(test.TestCase): def test_read_file_as_root(self): def fake_execute(*args, **kwargs): if args[1] == 'bad': - raise exception.ProcessExecutionError + raise processutils.ProcessExecutionError return 'fakecontents', None self.stubs.Set(utils, 'execute', fake_execute) |
