summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSoren Hansen <soren@linux2go.dk>2011-03-24 10:01:22 +0000
committerTarmac <>2011-03-24 10:01:22 +0000
commit2434138bbc73a8dbaee44c66cb7bed9f1fa40b2b (patch)
tree9bbc2582741d3dab8a05cc50b24b1e5421b6d838
parent08fd7016db5b0e435b8d9728345739afcf3cb152 (diff)
parent03257f78a8006e1e8e7e080af85163427cee7c5c (diff)
downloadnova-2434138bbc73a8dbaee44c66cb7bed9f1fa40b2b.tar.gz
nova-2434138bbc73a8dbaee44c66cb7bed9f1fa40b2b.tar.xz
nova-2434138bbc73a8dbaee44c66cb7bed9f1fa40b2b.zip
Pass a fake timing source to live_migration_pre in every test that expectes it to fail, shaving off a whole minute of test run time.
-rw-r--r--nova/compute/manager.py8
-rw-r--r--nova/tests/test_compute.py14
-rw-r--r--nova/tests/test_virt.py15
-rw-r--r--nova/virt/libvirt_conn.py7
4 files changed, 36 insertions, 8 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 9591a6c19..7316d1510 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -42,9 +42,10 @@ import string
import socket
import sys
import tempfile
-import time
import functools
+from eventlet import greenthread
+
from nova import exception
from nova import flags
from nova import log as logging
@@ -844,7 +845,7 @@ class ComputeManager(manager.Manager):
return self.driver.update_available_resource(context, self.host)
- def pre_live_migration(self, context, instance_id):
+ def pre_live_migration(self, context, instance_id, time=None):
"""Preparations for live migration at dest host.
:param context: security context
@@ -852,6 +853,9 @@ class ComputeManager(manager.Manager):
"""
+ if not time:
+ time = greenthread
+
# Getting instance info
instance_ref = self.db.instance_get(context, instance_id)
ec2_id = instance_ref['hostname']
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index 14ff8842b..d1ef68de4 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -44,6 +44,14 @@ flags.DECLARE('stub_network', 'nova.compute.manager')
flags.DECLARE('live_migration_retry_count', 'nova.compute.manager')
+class FakeTime(object):
+ def __init__(self):
+ self.counter = 0
+
+ def sleep(self, t):
+ self.counter += t
+
+
class ComputeTestCase(test.TestCase):
"""Test case for compute"""
def setUp(self):
@@ -393,7 +401,7 @@ class ComputeTestCase(test.TestCase):
self.mox.ReplayAll()
self.assertRaises(exception.NotFound,
self.compute.pre_live_migration,
- c, instance_ref['id'])
+ c, instance_ref['id'], time=FakeTime())
def test_pre_live_migration_instance_has_volume(self):
"""Confirm setup_compute_volume is called when volume is mounted."""
@@ -446,7 +454,7 @@ class ComputeTestCase(test.TestCase):
self.compute.driver = drivermock
self.mox.ReplayAll()
- ret = self.compute.pre_live_migration(c, i_ref['id'])
+ ret = self.compute.pre_live_migration(c, i_ref['id'], time=FakeTime())
self.assertEqual(ret, None)
def test_pre_live_migration_setup_compute_node_fail(self):
@@ -479,7 +487,7 @@ class ComputeTestCase(test.TestCase):
self.mox.ReplayAll()
self.assertRaises(exception.ProcessExecutionError,
self.compute.pre_live_migration,
- c, i_ref['id'])
+ c, i_ref['id'], time=FakeTime())
def test_live_migration_works_correctly_with_volume(self):
"""Confirm check_for_export to confirm volume health check."""
diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py
index 6bafac39f..fb0ba53b1 100644
--- a/nova/tests/test_virt.py
+++ b/nova/tests/test_virt.py
@@ -427,6 +427,15 @@ class LibvirtConnTestCase(test.TestCase):
def fake_raise(self):
raise libvirt.libvirtError('ERR')
+ class FakeTime(object):
+ def __init__(self):
+ self.counter = 0
+
+ def sleep(self, t):
+ self.counter += t
+
+ fake_timer = FakeTime()
+
self.create_fake_libvirt_mock(nwfilterLookupByName=fake_raise)
instance_ref = db.instance_create(self.context, self.test_instance)
@@ -436,11 +445,15 @@ class LibvirtConnTestCase(test.TestCase):
conn = libvirt_conn.LibvirtConnection(False)
conn.firewall_driver.setattr('setup_basic_filtering', fake_none)
conn.firewall_driver.setattr('prepare_instance_filter', fake_none)
- conn.ensure_filtering_rules_for_instance(instance_ref)
+ conn.ensure_filtering_rules_for_instance(instance_ref,
+ time=fake_timer)
except exception.Error, e:
c1 = (0 <= e.message.find('Timeout migrating for'))
self.assertTrue(c1)
+ self.assertEqual(29, fake_timer.counter, "Didn't wait the expected "
+ "amount of time")
+
db.instance_destroy(self.context, instance_ref['id'])
def test_live_migration_raises_exception(self):
diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py
index 96f42a8f8..e1a0a6f29 100644
--- a/nova/virt/libvirt_conn.py
+++ b/nova/virt/libvirt_conn.py
@@ -42,7 +42,6 @@ import shutil
import sys
import random
import subprocess
-import time
import uuid
from xml.dom import minidom
@@ -1172,7 +1171,8 @@ class LibvirtConnection(driver.ComputeDriver):
return
- def ensure_filtering_rules_for_instance(self, instance_ref):
+ def ensure_filtering_rules_for_instance(self, instance_ref,
+ time=None):
"""Setting up filtering rules and waiting for its completion.
To migrate an instance, filtering rules to hypervisors
@@ -1196,6 +1196,9 @@ class LibvirtConnection(driver.ComputeDriver):
"""
+ if not time:
+ time = greenthread
+
# If any instances never launch at destination host,
# basic-filtering must be set here.
self.firewall_driver.setup_basic_filtering(instance_ref)