summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Gundlach <michael.gundlach@rackspace.com>2010-10-04 16:39:05 -0400
committerMichael Gundlach <michael.gundlach@rackspace.com>2010-10-04 16:39:05 -0400
commitdd0f365c98ae68afff9a0fbc75e7d5b88499b282 (patch)
treeea9eac5f0f0f2061b9016c98d2d901b613d4407d
parent2a8e4a3e818f1d279a886e2e5f5ae49f3de26a4d (diff)
Fix broken unit tests
-rw-r--r--nova/api/ec2/cloud.py24
-rw-r--r--nova/db/sqlalchemy/api.py3
-rw-r--r--nova/tests/cloud_unittest.py3
-rw-r--r--nova/utils.py11
4 files changed, 28 insertions, 13 deletions
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py
index 2fec49da8..7f5f4c4e9 100644
--- a/nova/api/ec2/cloud.py
+++ b/nova/api/ec2/cloud.py
@@ -72,6 +72,20 @@ def _gen_key(context, user_id, key_name):
return {'private_key': private_key, 'fingerprint': fingerprint}
+def ec2_id_to_internal_id(ec2_id):
+ """Convert an ec2 ID (i-[base 36 number]) to an internal id (int)"""
+ return int(ec2_id[2:], 36)
+
+
+def internal_id_to_ec2_id(internal_id):
+ """Convert an internal ID (int) to an ec2 ID (i-[base 36 number])"""
+ digits = []
+ while internal_id != 0:
+ internal_id, remainder = divmod(internal_id, 36)
+ digits.append('0123456789abcdefghijklmnopqrstuvwxyz'[remainder])
+ return "i-%s" % ''.join(reversed(digits))
+
+
class CloudController(object):
""" CloudController provides the critical dispatch between
inbound API calls through the endpoint and messages
@@ -113,16 +127,6 @@ class CloudController(object):
result[key] = [line]
return result
- def ec2_id_to_internal_id(ec2_id):
- """Convert an ec2 ID (i-[base 36 number]) to an internal id (int)"""
- # TODO(gundlach): Maybe this should actually work?
- return ec2_id[2:]
-
- def internal_id_to_ec2_id(internal_id):
- """Convert an internal ID (int) to an ec2 ID (i-[base 36 number])"""
- # TODO(gundlach): Yo maybe this should actually convert to base 36
- return "i-%d" % internal_id
-
def get_metadata(self, address):
instance_ref = db.fixed_ip_get_instance(None, address)
if instance_ref is None:
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 6dd6b545a..9d43da3ba 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -377,6 +377,9 @@ def fixed_ip_update(_context, address, values):
###################
+#TODO(gundlach): instance_create and volume_create are nearly identical
+#and should be refactored. I expect there are other copy-and-paste
+#functions between the two of them as well.
def instance_create(_context, values):
instance_ref = models.Instance()
for (key, value) in values.iteritems():
diff --git a/nova/tests/cloud_unittest.py b/nova/tests/cloud_unittest.py
index d316db153..615e589cf 100644
--- a/nova/tests/cloud_unittest.py
+++ b/nova/tests/cloud_unittest.py
@@ -236,7 +236,8 @@ class CloudTestCase(test.TrialTestCase):
def test_update_of_instance_display_fields(self):
inst = db.instance_create({}, {})
- self.cloud.update_instance(self.context, inst['internal_id'],
+ ec2_id = cloud.internal_id_to_ec2_id(inst['internal_id'])
+ self.cloud.update_instance(self.context, ec2_id,
display_name='c00l 1m4g3')
inst = db.instance_get({}, inst['id'])
self.assertEqual('c00l 1m4g3', inst['display_name'])
diff --git a/nova/utils.py b/nova/utils.py
index 5f64b13c4..b1699bda8 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -126,8 +126,15 @@ def runthis(prompt, cmd, check_exit_code = True):
def generate_uid(topic, size=8):
- return '%s-%s' % (topic, ''.join([random.choice('01234567890abcdefghijklmnopqrstuvwxyz') for x in xrange(size)]))
-
+ if topic == "i":
+ # Instances have integer internal ids.
+ #TODO(gundlach): We should make this more than 32 bits, but we need to
+ #figure out how to make the DB happy with 64 bit integers.
+ 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))
def generate_mac():