We interchangeably use UUID and str objects for object UUIDs and run
into problems when we assume an ID is a string.
To reduce confusion, just use strings everywhere. We don't actually
use UUIDs except for their string representation.
---
imagefactory/ImageWarehouse.py | 12 ++++++------
imagefactory/Template.py | 7 +++----
imagefactory/builders/BaseBuilder.py | 2 +-
imagefactory/builders/FedoraBuilder.py | 20 +++++++++-----------
imagefactory/qmfagent/BuildAdaptor.py | 2 +-
tests/testImageWarehouse.py | 12 ++++++------
6 files changed, 26 insertions(+), 29 deletions(-)
diff --git a/imagefactory/ImageWarehouse.py b/imagefactory/ImageWarehouse.py
index b69abee..ecf22eb 100644
--- a/imagefactory/ImageWarehouse.py
+++ b/imagefactory/ImageWarehouse.py
@@ -222,7 +222,7 @@ class ImageWarehouse(object):
except Exception, e:
raise WarehouseError("Problem encountered trying to reach image
warehouse. Please check that iwhd is running and reachable.\nException text: %s" %
(e, ))
- meta_data = dict(uuid=str(image_id), object_type="image")
+ meta_data = dict(uuid=image_id, object_type="image")
if(metadata):
meta_data.update(metadata)
self.set_metadata_for_object_at_url(meta_data, object_url)
@@ -237,19 +237,19 @@ class ImageWarehouse(object):
self._http_put(object_url, txt)
- meta_data = dict(uuid=str(image_id), object_type="provider_image")
+ meta_data = dict(uuid=image_id, object_type="provider_image")
if(metadata):
meta_data.update(metadata)
self.set_metadata_for_object_at_url(meta_data, object_url)
def store_template(self, template, template_id=None, metadata=None):
if(not template_id):
- template_id = uuid.uuid4()
+ template_id = str(uuid.uuid4())
object_url = self.__url_for_id_of_type(template_id,
object_type="template")
self._http_put(object_url, template)
- meta_data = dict(uuid=str(template_id), object_type="template")
+ meta_data = dict(uuid=template_id, object_type="template")
if(metadata):
meta_data.update(metadata)
self.set_metadata_for_object_at_url(meta_data, object_url)
@@ -258,12 +258,12 @@ class ImageWarehouse(object):
def store_icicle(self, icicle, icicle_id=None, metadata=None):
if(not icicle_id):
- icicle_id = uuid.uuid4()
+ icicle_id = str(uuid.uuid4())
object_url = self.__url_for_id_of_type(icicle_id,
object_type="icicle")
self._http_put(object_url, icicle)
- meta_data = dict(uuid=str(icicle_id), object_type="icicle")
+ meta_data = dict(uuid=icicle_id, object_type="icicle")
if(metadata):
meta_data.update(metadata)
self.set_metadata_for_object_at_url(meta_data, object_url)
diff --git a/imagefactory/Template.py b/imagefactory/Template.py
index bb64bd7..0bba587 100644
--- a/imagefactory/Template.py
+++ b/imagefactory/Template.py
@@ -21,7 +21,6 @@
import logging
import httplib2
import re
-import uuid
import os.path
from imagefactory.ApplicationConfiguration import ApplicationConfiguration
from imagefactory.ImageWarehouse import ImageWarehouse
@@ -130,12 +129,12 @@ class Template(object):
def __fetch_template_for_uuid(self, uuid_string):
xml_string, metadata = self.warehouse.template_with_id(uuid_string)
if(xml_string and self.__string_is_xml_template(xml_string)):
- return uuid.UUID(uuid_string), xml_string
+ return uuid_string, xml_string
else:
self.log.debug("Unable to fetch a valid template given template id
%s:\n%s\nWill try fetching template id from an image with this id..." % (uuid_string,
self.__abbreviated_template(xml_string)))
template_id, xml_string, metadata =
self.warehouse.template_for_image_id(uuid_string)
if(template_id and xml_string and
self.__string_is_xml_template(xml_string)):
- return uuid.UUID(template_id), xml_string
+ return template_id, xml_string
else:
self.log.debug("Unable to fetch a valid template given an image id
%s:\n%s\n" % (uuid_string, self.__abbreviated_template(xml_string)))
return None, None
@@ -149,7 +148,7 @@ class Template(object):
match = regex.search(url)
if (match):
- template_id = uuid.UUID(match.group())
+ template_id = match.group()
response_headers, response = httplib2.Http().request(url, "GET",
headers={'content-type':'text/plain'})
if(response and self.__string_is_xml_template(response)):
diff --git a/imagefactory/builders/BaseBuilder.py b/imagefactory/builders/BaseBuilder.py
index b9546fa..3109f18 100644
--- a/imagefactory/builders/BaseBuilder.py
+++ b/imagefactory/builders/BaseBuilder.py
@@ -191,7 +191,7 @@ class BaseBuilder(object):
def __init__(self, template, target):
super(BaseBuilder, self).__init__()
self.log = logging.getLogger('%s.%s' % (__name__,
self.__class__.__name__))
- self.image_id = uuid.uuid4()
+ self.image_id = str(uuid.uuid4())
if(type(template) == Template):
self.template = template
elif(type(template) == str):
diff --git a/imagefactory/builders/FedoraBuilder.py
b/imagefactory/builders/FedoraBuilder.py
index 39edf76..c832149 100644
--- a/imagefactory/builders/FedoraBuilder.py
+++ b/imagefactory/builders/FedoraBuilder.py
@@ -84,8 +84,6 @@ class FedoraBuilder(BaseBuilder):
super(FedoraBuilder, self).__init__(template, target)
self.app_config = ApplicationConfiguration().configuration
self.warehouse_url = self.app_config['warehouse']
- # TODO: Should this be in base? Does image_id ever need to be an actual UUID
object?
- self.image_id = str(self.image_id)
# May not be necessary to do both of these
self.tdlobj = oz.TDL.TDL(xmlstring=self.template.xml)
@@ -104,7 +102,7 @@ class FedoraBuilder(BaseBuilder):
self.guest.diskimage = self.app_config["imgdir"] +
"/base-image-" + self.image_id + ".dsk"
# Oz assumes unique names - TDL built for multiple backends guarantees they are
not unique
# We don't really care about the name so just force uniqueness
- self.guest.name = self.guest.name + "-" + str(self.image_id)
+ self.guest.name = self.guest.name + "-" + self.image_id
def build_image(self):
try:
@@ -524,7 +522,7 @@ class FedoraBuilder(BaseBuilder):
mypub = open("/etc/oz/id_rsa-icicle-gen.pub")
server_files = { "/root/.ssh/authorized_keys":mypub }
- instance_name = "factory-build-%s" % (str(self.image_id))
+ instance_name = "factory-build-%s" % (self.image_id, )
jeos_instance = cloudservers.servers.create(instance_name,jeos_image, onegig_flavor,
files=server_files)
for i in range(30):
@@ -576,7 +574,7 @@ class FedoraBuilder(BaseBuilder):
self.guest.do_customize(guestaddr)
self.log.debug("Done!")
- image_name = "factory-image-%s" % (str(self.image_id))
+ image_name = "factory-image-%s" % (self.image_id, )
snap_image = cloudservers.images.create(image_name, jeos_instance)
self.log.debug("New Rackspace image created with ID: %s" %
(snap_image.id))
@@ -696,7 +694,7 @@ chmod 600 /root/.ssh/authorized_keys
conn = ec2region.connect(aws_access_key_id=self.ec2_access_key,
aws_secret_access_key=self.ec2_secret_key)
# Create a use-once SSH-able security group
- factory_security_group_name = "imagefactory-%s" % (str(self.image_id))
+ factory_security_group_name = "imagefactory-%s" % (self.image_id, )
factory_security_group_desc = "Temporary ImageFactory generated security
group with SSH access"
self.log.debug("Creating temporary security group (%s)" %
(factory_security_group_name))
factory_security_group = conn.create_security_group(factory_security_group_name,
factory_security_group_desc)
@@ -844,7 +842,7 @@ chmod 600 /root/.ssh/authorized_keys
instance.stop()
factory_security_group.delete()
- self.log.debug("FedoraBuilder instance %s pushed image with uuid %s to
provider_image UUID (%s) and set metadata: %s" % (id(self), str(image_id),
str(self.image_id), str(metadata)))
+ self.log.debug("FedoraBuilder instance %s pushed image with uuid %s to
provider_image UUID (%s) and set metadata: %s" % (id(self), image_id, self.image_id,
str(metadata)))
self.percent_complete=100
self.status="COMPLETED"
@@ -866,7 +864,7 @@ chmod 600 /root/.ssh/authorized_keys
if not os.path.isdir(staging):
raise ImageFactoryException("Staging dir (%s) for condorcloud is not
present" % (staging))
- image_base = "/condorimage-" + str(self.image_id) + ".img"
+ image_base = "/condorimage-" + self.image_id + ".img"
staging_image = staging + image_base
# Copy to staging location
@@ -876,7 +874,7 @@ chmod 600 /root/.ssh/authorized_keys
raise ImageFactoryException("Copy of condorcloud image to staging
location (%s) failed" % (staging_image))
# Retrieve original XML and write it out to the final dir
- image_xml_base="/condorimage-" + str(self.image_id) + ".xml"
+ image_xml_base="/condorimage-" + self.image_id + ".xml"
image_xml_file= storage + image_xml_base
image_metadata =
self.warehouse.metadata_for_id_of_type(("target_parameters",), image_id,
"image")
@@ -919,7 +917,7 @@ chmod 600 /root/.ssh/authorized_keys
# {"westford_esx": {"api-url":
"https://vsphere.virt.bos.redhat.com/sdk", "username":
"Administrator", "password": "changeme",
# "datastore": "datastore1", "network_name":
"VM Network" } }
- vm_name = "factory-image-" + str(self.image_id)
+ vm_name = "factory-image-" + self.image_id
vm_import = VMImport(provider_data['api-url'],
provider_data['username'], provider_data['password'])
vm_import.import_vm(datastore=provider_data['datastore'], network_name =
provider_data['network_name'],
name=vm_name, disksize_kb = (10*1024*1024 + 2 ), memory=512,
num_cpus=1,
@@ -1166,7 +1164,7 @@ chmod 600 /root/.ssh/authorized_keys
#self.output_descriptor="unknown"
#metadata = dict(uuid=self.image_id, type="provider_image",
template=self.template, target=self.target, icicle=self.output_descriptor, image=image_id,
provider=provider, target_identifier=ami_id)
- self.log.debug("FedoraBuilder instance %s pushed image with uuid %s to
provider_image UUID (%s) and set metadata: %s" % (id(self), str(image_id),
str(self.image_id), str(metadata)))
+ self.log.debug("FedoraBuilder instance %s pushed image with uuid %s to
provider_image UUID (%s) and set metadata: %s" % (id(self), image_id, self.image_id,
str(metadata)))
self.percent_complete=100
def abort(self):
diff --git a/imagefactory/qmfagent/BuildAdaptor.py
b/imagefactory/qmfagent/BuildAdaptor.py
index ab064d0..b4979b4 100644
--- a/imagefactory/qmfagent/BuildAdaptor.py
+++ b/imagefactory/qmfagent/BuildAdaptor.py
@@ -149,7 +149,7 @@ class BuildAdaptor(object):
self.builder =
BuildDispatcher.builder_for_target_with_template(template=template, target=target)
# Register as a delegate to the builder
self.builder.delegate = self
- self.image = str(self.builder.image_id)
+ self.image = self.builder.image_id
def build_image(self):
BuildDispatcher.builder_thread_with_method(builder=self.builder,
method_name="build_image")
diff --git a/tests/testImageWarehouse.py b/tests/testImageWarehouse.py
index 5f7724d..1545490 100644
--- a/tests/testImageWarehouse.py
+++ b/tests/testImageWarehouse.py
@@ -39,7 +39,7 @@ class testImageWarehouse(unittest.TestCase):
"""Tests CRUD operations on images, templates, icicles, and
metadata on those objects..."""
# IMAGE
# store an image
- image_id = uuid.uuid4()
+ image_id = str(uuid.uuid4())
file_content = "This is just to test storing an image in warehouse. There
is not much to see here."
file_path = "/tmp/testImageWarehouse_testStoreAndFetchImage.%s" %
(image_id, )
with open(file_path, 'w') as test_file:
@@ -58,7 +58,7 @@ class testImageWarehouse(unittest.TestCase):
template_id = self.warehouse.store_template(template_content)
self.assertIsNotNone(template_id)
# store the template with a specified id
- template_id_known = uuid.uuid4()
+ template_id_known = str(uuid.uuid4())
template_id2 = self.warehouse.store_template(template_content,
template_id_known)
self.assertEqual(template_id_known, template_id2)
# fetch the templates
@@ -69,7 +69,7 @@ class testImageWarehouse(unittest.TestCase):
# set the template id for an image and fetch it back
self.warehouse.set_metadata_for_id_of_type(dict(template=template_id), image_id,
"image")
template_id3, fetched_template_content3, template_metadata3 =
self.warehouse.template_for_image_id(image_id)
- self.assertEqual(str(template_id), template_id3)
+ self.assertEqual(template_id, template_id3)
self.assertEqual(template_content, fetched_template_content3)
# ICICLE
@@ -78,7 +78,7 @@ class testImageWarehouse(unittest.TestCase):
icicle_id = self.warehouse.store_icicle(icicle_content)
self.assertIsNotNone(icicle_id)
# store the icicle with a specified id
- icicle_id_known = uuid.uuid4()
+ icicle_id_known = str(uuid.uuid4())
icicle_id2 = self.warehouse.store_icicle(icicle_content, icicle_id_known)
self.assertEqual(icicle_id_known, icicle_id2)
# fetch the icicles
@@ -89,7 +89,7 @@ class testImageWarehouse(unittest.TestCase):
# set the icicle id for an image and fetch it back
self.warehouse.set_metadata_for_id_of_type(dict(icicle=icicle_id), image_id,
"image")
icicle_id3, fetched_icicle_content3, icicle_metadata3 =
self.warehouse.icicle_for_image_id(image_id)
- self.assertEqual(str(icicle_id), icicle_id3)
+ self.assertEqual(icicle_id, icicle_id3)
self.assertEqual(icicle_content, fetched_icicle_content3)
self.assertTrue(self.warehouse.remove_image_with_id(image_id))
@@ -99,7 +99,7 @@ class testImageWarehouse(unittest.TestCase):
self.assertTrue(self.warehouse.remove_icicle_with_id(icicle_id2))
def testBucketCreation(self):
- #
self.assert_(self.warehouse.create_bucket_at_url("%s/unittests-create_bucket/%s"
% (self.warehouse.url, uuid.uuid4())))
+ #
self.assert_(self.warehouse.create_bucket_at_url("%s/unittests-create_bucket/%s"
% (self.warehouse.url, str(uuid.uuid4()))))
self.warehouse.create_bucket_at_url("%s/unittests-create_bucket" %
(self.warehouse.url, ))
self.assert_(self.warehouse.create_bucket_at_url("%s/unittests-create_bucket/%s"
% (self.warehouse.url, time.asctime().replace(' ', '-'))))
--
1.7.4.4