summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorMichael Still <mikal@stillhq.com>2012-10-23 14:25:25 -0700
committerMichael Still <mikal@stillhq.com>2012-10-25 09:20:46 +1100
commit0d4e6dbe6f17d0a8d0f93833c1ea70f79944d945 (patch)
treecdd80ba89da8567c5e1abc82a0ede862d6dd578d /nova/tests
parent86b91474d16fb9842bb75dc7ebd1af364cc8a058 (diff)
Migrate to fileutils and lockutils.
Migrate nova to using openstack-common's file and lock utilities. Resolves bug 1063230. Change-Id: I1a4c87856bc08cd33b61d7098ed856baa4583654
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/network/test_linux_net.py33
-rw-r--r--nova/tests/test_imagebackend.py13
-rw-r--r--nova/tests/test_libvirt.py3
-rw-r--r--nova/tests/test_misc.py94
-rw-r--r--nova/tests/test_utils.py37
5 files changed, 27 insertions, 153 deletions
diff --git a/nova/tests/network/test_linux_net.py b/nova/tests/network/test_linux_net.py
index 72bf71674..f69023ef8 100644
--- a/nova/tests/network/test_linux_net.py
+++ b/nova/tests/network/test_linux_net.py
@@ -23,6 +23,7 @@ from nova import context
from nova import db
from nova import flags
from nova.network import linux_net
+from nova.openstack.common import fileutils
from nova.openstack.common import importutils
from nova.openstack.common import log as logging
from nova import test
@@ -236,18 +237,18 @@ class LinuxNetworkTestCase(test.TestCase):
self.flags(use_single_default_gateway=True)
self.mox.StubOutWithMock(self.driver, 'write_to_file')
- self.mox.StubOutWithMock(utils, 'ensure_tree')
+ self.mox.StubOutWithMock(fileutils, 'ensure_tree')
self.mox.StubOutWithMock(os, 'chmod')
self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg())
self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg())
- utils.ensure_tree(mox.IgnoreArg())
- utils.ensure_tree(mox.IgnoreArg())
- utils.ensure_tree(mox.IgnoreArg())
- utils.ensure_tree(mox.IgnoreArg())
- utils.ensure_tree(mox.IgnoreArg())
- utils.ensure_tree(mox.IgnoreArg())
- utils.ensure_tree(mox.IgnoreArg())
+ fileutils.ensure_tree(mox.IgnoreArg())
+ fileutils.ensure_tree(mox.IgnoreArg())
+ fileutils.ensure_tree(mox.IgnoreArg())
+ fileutils.ensure_tree(mox.IgnoreArg())
+ fileutils.ensure_tree(mox.IgnoreArg())
+ fileutils.ensure_tree(mox.IgnoreArg())
+ fileutils.ensure_tree(mox.IgnoreArg())
os.chmod(mox.IgnoreArg(), mox.IgnoreArg())
os.chmod(mox.IgnoreArg(), mox.IgnoreArg())
@@ -259,18 +260,18 @@ class LinuxNetworkTestCase(test.TestCase):
self.flags(use_single_default_gateway=True)
self.mox.StubOutWithMock(self.driver, 'write_to_file')
- self.mox.StubOutWithMock(utils, 'ensure_tree')
+ self.mox.StubOutWithMock(fileutils, 'ensure_tree')
self.mox.StubOutWithMock(os, 'chmod')
self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg())
self.driver.write_to_file(mox.IgnoreArg(), mox.IgnoreArg())
- utils.ensure_tree(mox.IgnoreArg())
- utils.ensure_tree(mox.IgnoreArg())
- utils.ensure_tree(mox.IgnoreArg())
- utils.ensure_tree(mox.IgnoreArg())
- utils.ensure_tree(mox.IgnoreArg())
- utils.ensure_tree(mox.IgnoreArg())
- utils.ensure_tree(mox.IgnoreArg())
+ fileutils.ensure_tree(mox.IgnoreArg())
+ fileutils.ensure_tree(mox.IgnoreArg())
+ fileutils.ensure_tree(mox.IgnoreArg())
+ fileutils.ensure_tree(mox.IgnoreArg())
+ fileutils.ensure_tree(mox.IgnoreArg())
+ fileutils.ensure_tree(mox.IgnoreArg())
+ fileutils.ensure_tree(mox.IgnoreArg())
os.chmod(mox.IgnoreArg(), mox.IgnoreArg())
os.chmod(mox.IgnoreArg(), mox.IgnoreArg())
diff --git a/nova/tests/test_imagebackend.py b/nova/tests/test_imagebackend.py
index f0bb71829..088cb0a82 100644
--- a/nova/tests/test_imagebackend.py
+++ b/nova/tests/test_imagebackend.py
@@ -18,6 +18,7 @@
import os
from nova import flags
+from nova.openstack.common import fileutils
from nova import test
from nova.tests import fake_libvirt_utils
from nova.virt.libvirt import imagebackend
@@ -56,8 +57,8 @@ class _ImageTestCase(test.TestCase):
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)
fn = self.mox.CreateMockAnything()
fn(target=self.TEMPLATE_PATH)
- self.mox.StubOutWithMock(imagebackend.utils, 'ensure_tree')
- imagebackend.utils.ensure_tree(self.TEMPLATE_DIR)
+ self.mox.StubOutWithMock(imagebackend.fileutils, 'ensure_tree')
+ imagebackend.fileutils.ensure_tree(self.TEMPLATE_DIR)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
@@ -83,7 +84,7 @@ class _ImageTestCase(test.TestCase):
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)
fn = self.mox.CreateMockAnything()
fn(target=self.TEMPLATE_PATH)
- self.mox.StubOutWithMock(imagebackend.utils, 'ensure_tree')
+ self.mox.StubOutWithMock(imagebackend.fileutils, 'ensure_tree')
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
@@ -117,7 +118,8 @@ class RawTestCase(_ImageTestCase):
def prepare_mocks(self):
fn = self.mox.CreateMockAnything()
- self.mox.StubOutWithMock(imagebackend.utils.synchronized, '__call__')
+ self.mox.StubOutWithMock(imagebackend.lockutils.synchronized,
+ '__call__')
self.mox.StubOutWithMock(imagebackend.libvirt_utils, 'copy_image')
self.mox.StubOutWithMock(imagebackend.disk, 'extend')
return fn
@@ -167,7 +169,8 @@ class Qcow2TestCase(_ImageTestCase):
def prepare_mocks(self):
fn = self.mox.CreateMockAnything()
- self.mox.StubOutWithMock(imagebackend.utils.synchronized, '__call__')
+ self.mox.StubOutWithMock(imagebackend.lockutils.synchronized,
+ '__call__')
self.mox.StubOutWithMock(imagebackend.libvirt_utils,
'create_cow_image')
self.mox.StubOutWithMock(imagebackend.libvirt_utils, 'copy_image')
diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py
index 7e73516b0..c84440e58 100644
--- a/nova/tests/test_libvirt.py
+++ b/nova/tests/test_libvirt.py
@@ -37,6 +37,7 @@ from nova import context
from nova import db
from nova import exception
from nova import flags
+from nova.openstack.common import fileutils
from nova.openstack.common import importutils
from nova.openstack.common import jsonutils
from nova.openstack.common import log as logging
@@ -448,7 +449,7 @@ class CacheConcurrencyTestCase(test.TestCase):
# use for tests. So, create the path here so utils.synchronized()
# won't delete it out from under one of the threads.
self.lock_path = os.path.join(FLAGS.instances_path, 'locks')
- utils.ensure_tree(self.lock_path)
+ fileutils.ensure_tree(self.lock_path)
def fake_exists(fname):
basedir = os.path.join(FLAGS.instances_path, FLAGS.base_dir_name)
diff --git a/nova/tests/test_misc.py b/nova/tests/test_misc.py
index 10443ecde..4e989f315 100644
--- a/nova/tests/test_misc.py
+++ b/nova/tests/test_misc.py
@@ -24,7 +24,6 @@ from eventlet import greenthread
from nova import exception
from nova import test
-from nova import utils
class ExceptionTestCase(test.TestCase):
@@ -63,96 +62,3 @@ class ProjectTestCase(test.TestCase):
helpful_msg = (_("The following migrations are missing a downgrade:"
"\n\t%s") % '\n\t'.join(sorted(missing_downgrade)))
self.assert_(not missing_downgrade, helpful_msg)
-
-
-class LockTestCase(test.TestCase):
- def test_synchronized_wrapped_function_metadata(self):
- @utils.synchronized('whatever')
- def foo():
- """Bar"""
- pass
- self.assertEquals(foo.__doc__, 'Bar', "Wrapped function's docstring "
- "got lost")
- self.assertEquals(foo.__name__, 'foo', "Wrapped function's name "
- "got mangled")
-
- def test_synchronized_internally(self):
- """We can lock across multiple green threads"""
- saved_sem_num = len(utils._semaphores)
- seen_threads = list()
-
- @utils.synchronized('testlock2', external=False)
- def f(id):
- for x in range(10):
- seen_threads.append(id)
- greenthread.sleep(0)
-
- threads = []
- pool = greenpool.GreenPool(10)
- for i in range(10):
- threads.append(pool.spawn(f, i))
-
- for thread in threads:
- thread.wait()
-
- self.assertEquals(len(seen_threads), 100)
- # Looking at the seen threads, split it into chunks of 10, and verify
- # that the last 9 match the first in each chunk.
- for i in range(10):
- for j in range(9):
- self.assertEquals(seen_threads[i * 10],
- seen_threads[i * 10 + 1 + j])
-
- self.assertEqual(saved_sem_num, len(utils._semaphores),
- "Semaphore leak detected")
-
- def test_nested_external_works(self):
- """We can nest external syncs"""
- with utils.tempdir() as tempdir:
- self.flags(lock_path=tempdir)
- sentinel = object()
-
- @utils.synchronized('testlock1', external=True)
- def outer_lock():
-
- @utils.synchronized('testlock2', external=True)
- def inner_lock():
- return sentinel
- return inner_lock()
-
- self.assertEqual(sentinel, outer_lock())
-
- def test_synchronized_externally(self):
- """We can lock across multiple processes"""
- with utils.tempdir() as tempdir:
- self.flags(lock_path=tempdir)
- rpipe1, wpipe1 = os.pipe()
- rpipe2, wpipe2 = os.pipe()
-
- @utils.synchronized('testlock1', external=True)
- def f(rpipe, wpipe):
- try:
- os.write(wpipe, "foo")
- except OSError, e:
- self.assertEquals(e.errno, errno.EPIPE)
- return
-
- rfds, _wfds, _efds = select.select([rpipe], [], [], 1)
- self.assertEquals(len(rfds), 0, "The other process, which was"
- " supposed to be locked, "
- "wrote on its end of the "
- "pipe")
- os.close(rpipe)
-
- pid = os.fork()
- if pid > 0:
- os.close(wpipe1)
- os.close(rpipe2)
-
- f(rpipe1, wpipe2)
- else:
- os.close(rpipe1)
- os.close(wpipe2)
-
- f(rpipe2, wpipe1)
- os._exit(0)
diff --git a/nova/tests/test_utils.py b/nova/tests/test_utils.py
index dbd2c1cbe..f97d6eeb7 100644
--- a/nova/tests/test_utils.py
+++ b/nova/tests/test_utils.py
@@ -543,35 +543,6 @@ class MonkeyPatchTestCase(test.TestCase):
in nova.tests.monkey_patch_example.CALLED_FUNCTION)
-class TestFileLocks(test.TestCase):
- def test_concurrent_green_lock_succeeds(self):
- """Verify spawn_n greenthreads with two locks run concurrently."""
- self.completed = False
- with utils.tempdir() as tmpdir:
-
- def locka(wait):
- a = utils.InterProcessLock(os.path.join(tmpdir, 'a'))
- with a:
- wait.wait()
- self.completed = True
-
- def lockb(wait):
- b = utils.InterProcessLock(os.path.join(tmpdir, 'b'))
- with b:
- wait.wait()
-
- wait1 = eventlet.event.Event()
- wait2 = eventlet.event.Event()
- pool = greenpool.GreenPool()
- pool.spawn_n(locka, wait1)
- pool.spawn_n(lockb, wait2)
- wait2.send()
- eventlet.sleep(0)
- wait1.send()
- pool.waitall()
- self.assertTrue(self.completed)
-
-
class AuditPeriodTest(test.TestCase):
def setUp(self):
@@ -778,11 +749,3 @@ class MkfsTestCase(test.TestCase):
utils.mkfs('ext4', '/my/block/dev')
utils.mkfs('swap', '/my/swap/block/dev')
-
-
-class EnsureTree(test.TestCase):
- def test_ensure_tree(self):
- with utils.tempdir() as tmpdir:
- testdir = '%s/foo/bar/baz' % (tmpdir,)
- utils.ensure_tree(testdir)
- self.assertTrue(os.path.isdir(testdir))