diff --git a/nova/tests/api_unittest.py b/nova/tests/api_unittest.py index 80493b10a..0b1c3e353 100644 --- a/nova/tests/api_unittest.py +++ b/nova/tests/api_unittest.py @@ -242,7 +242,7 @@ class ApiEc2TestCase(test.BaseTestCase): self.assertEquals(int(group.rules[0].from_port), 80) self.assertEquals(int(group.rules[0].to_port), 81) self.assertEquals(len(group.rules[0].grants), 1) - self.assertEquals(str(group.rules[0].grants[0]), '0.0.0.0/0') + self.assertEquals(str(group.rules[0].grants[0]), '0.0.0.0/0') self.expect_http() self.mox.ReplayAll() diff --git a/nova/tests/fake_flags.py b/nova/tests/fake_flags.py index d695d68a6..501162465 100644 --- a/nova/tests/fake_flags.py +++ b/nova/tests/fake_flags.py @@ -33,9 +33,9 @@ FLAGS.num_networks = 5 FLAGS.fake_network = True flags.DECLARE('num_shelves', 'nova.volume.driver') flags.DECLARE('blades_per_shelf', 'nova.volume.driver') -flags.DECLARE('iscsi_target_ids', 'nova.volume.driver') +flags.DECLARE('iscsi_num_targets', 'nova.volume.driver') FLAGS.num_shelves = 2 FLAGS.blades_per_shelf = 4 -FLAGS.iscsi_target_ids = 8 +FLAGS.iscsi_num_targets = 8 FLAGS.verbose = True FLAGS.sql_connection = 'sqlite:///nova.sqlite' diff --git a/nova/tests/scheduler_unittest.py b/nova/tests/scheduler_unittest.py index 27345d055..cb5fe6b9c 100644 --- a/nova/tests/scheduler_unittest.py +++ b/nova/tests/scheduler_unittest.py @@ -81,7 +81,7 @@ class SimpleDriverTestCase(test.TrialTestCase): max_cores=4, max_gigabytes=4, network_manager='nova.network.manager.FlatManager', - volume_driver='nova.volume.driver.FakeAOEDriver', + volume_driver='nova.volume.driver.FakeISCSIDriver', scheduler_driver='nova.scheduler.simple.SimpleScheduler') self.scheduler = manager.SchedulerManager() self.manager = auth_manager.AuthManager() diff --git a/nova/tests/virt_unittest.py b/nova/tests/virt_unittest.py index ce78d450c..d49383fb7 100644 --- a/nova/tests/virt_unittest.py +++ b/nova/tests/virt_unittest.py @@ -91,7 +91,7 @@ class LibvirtConnTestCase(test.TrialTestCase): FLAGS.libvirt_type = libvirt_type conn = libvirt_conn.LibvirtConnection(True) - uri, template = conn.get_uri_and_template() + uri, _template, _rescue = conn.get_uri_and_templates() self.assertEquals(uri, expected_uri) xml = conn.to_xml(instance_ref) @@ -114,7 +114,7 @@ class LibvirtConnTestCase(test.TrialTestCase): for (libvirt_type, (expected_uri, checks)) in type_uri_map.iteritems(): FLAGS.libvirt_type = libvirt_type conn = libvirt_conn.LibvirtConnection(True) - uri, template = conn.get_uri_and_template() + uri, _template, _rescue = conn.get_uri_and_templates() self.assertEquals(uri, testuri) def tearDown(self): diff --git a/nova/tests/volume_unittest.py b/nova/tests/volume_unittest.py index 34e04c8b8..7ff9b58d7 100644 --- a/nova/tests/volume_unittest.py +++ b/nova/tests/volume_unittest.py @@ -85,7 +85,7 @@ class VolumeTestCase(test.TrialTestCase): def test_too_many_volumes(self): """Ensure that NoMoreTargets is raised when we run out of volumes""" vols = [] - total_slots = FLAGS.iscsi_target_ids + total_slots = FLAGS.iscsi_num_targets for _index in xrange(total_slots): volume_id = self._create_volume() yield self.volume.create_volume(self.context, volume_id) @@ -157,12 +157,13 @@ class VolumeTestCase(test.TrialTestCase): """Make sure targets aren't duplicated""" volume_ids.append(volume_id) admin_context = context.get_admin_context() - target_id = db.volume_get_target_id(admin_context, volume_id) - self.assert_(target_id not in targets) - targets.append(target_id) - logging.debug("Target %s allocated", target_id) + iscsi_target = db.volume_get_iscsi_target_num(admin_context, + volume_id) + self.assert_(iscsi_target not in targets) + targets.append(iscsi_target) + logging.debug("Target %s allocated", iscsi_target) deferreds = [] - total_slots = FLAGS.iscsi_target_ids + total_slots = FLAGS.iscsi_num_targets for _index in xrange(total_slots): volume_id = self._create_volume() d = self.volume.create_volume(self.context, volume_id) diff --git a/nova/utils.py b/nova/utils.py index 7683fc9f4..2c53b027e 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -28,6 +28,7 @@ import random import subprocess import socket import sys +from xml.sax import saxutils from twisted.internet.threads import deferToThread @@ -131,13 +132,9 @@ def runthis(prompt, cmd, check_exit_code=True): def generate_uid(topic, size=8): - if topic == "i": - # Instances have integer internal ids. - return random.randint(0, 2 ** 32 - 1) - else: - characters = '01234567890abcdefghijklmnopqrstuvwxyz' - choices = [random.choice(characters) for x in xrange(size)] - return '%s-%s' % (topic, ''.join(choices)) + characters = '01234567890abcdefghijklmnopqrstuvwxyz' + choices = [random.choice(characters) for x in xrange(size)] + return '%s-%s' % (topic, ''.join(choices)) def generate_mac(): @@ -212,3 +209,27 @@ def deferredToThread(f): def g(*args, **kwargs): return deferToThread(f, *args, **kwargs) return g + + +def xhtml_escape(value): + """Escapes a string so it is valid within XML or XHTML. + + Code is directly from the utf8 function in + http://github.com/facebook/tornado/blob/master/tornado/escape.py + + """ + return saxutils.escape(value, {'"': """}) + + +def utf8(value): + """Try to turn a string into utf-8 if possible. + + Code is directly from the utf8 function in + http://github.com/facebook/tornado/blob/master/tornado/escape.py + + """ + if isinstance(value, unicode): + return value.encode("utf-8") + assert isinstance(value, str) + return value +