From 87d90616df651787f52a59be37457335eb881ed7 Mon Sep 17 00:00:00 2001 From: Johannes Erdfelt Date: Wed, 15 Jun 2011 22:57:05 +0000 Subject: Workaround windows agent bugs where some responses have trailing \\r\\n --- nova/virt/xenapi/vmops.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 190bf7c20..5ca041059 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -526,7 +526,9 @@ class VMOps(object): # No response from the agent return resp_dict = json.loads(resp) - return resp_dict['message'] + # Some old versions of the windows agent have a trailing \\r\\n + # (ie CRLF escaped) for some reason. Strip that off + return resp_dict['message'].replace('\\r\\n', '') if timeout: vm_ref = self._get_vm_opaque_ref(instance) @@ -592,7 +594,9 @@ class VMOps(object): # There was some sort of error; the message will contain # a description of the error. raise RuntimeError(resp_dict['message']) - agent_pub = int(resp_dict['message']) + # Some old versions of the windows agent have a trailing \\r\\n + # (ie CRLF escaped) for some reason. Strip that off + agent_pub = int(resp_dict['message'].replace('\\r\\n', '')) dh.compute_shared(agent_pub) enc_pass = dh.encrypt(new_pass) # Send the encrypted password -- cgit From 46e016348ff4303310af328fa1af8fab513632c9 Mon Sep 17 00:00:00 2001 From: Johannes Erdfelt Date: Wed, 15 Jun 2011 23:11:00 +0000 Subject: Add trailing LF (\n) to password for compatibility with old agents --- nova/virt/xenapi/vmops.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 5ca041059..24e293a7b 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -526,8 +526,8 @@ class VMOps(object): # No response from the agent return resp_dict = json.loads(resp) - # Some old versions of the windows agent have a trailing \\r\\n - # (ie CRLF escaped) for some reason. Strip that off + # Some old versions of the Windows agent have a trailing \\r\\n + # (ie CRLF escaped) for some reason. Strip that off. return resp_dict['message'].replace('\\r\\n', '') if timeout: @@ -594,11 +594,13 @@ class VMOps(object): # There was some sort of error; the message will contain # a description of the error. raise RuntimeError(resp_dict['message']) - # Some old versions of the windows agent have a trailing \\r\\n - # (ie CRLF escaped) for some reason. Strip that off + # Some old versions of the Windows agent have a trailing \\r\\n + # (ie CRLF escaped) for some reason. Strip that off. agent_pub = int(resp_dict['message'].replace('\\r\\n', '')) dh.compute_shared(agent_pub) - enc_pass = dh.encrypt(new_pass) + # Some old versions of Linux and Windows agent expect trailing \n + # on password to work correctly. + enc_pass = dh.encrypt(new_pass + '\n') # Send the encrypted password password_transaction_id = str(uuid.uuid4()) password_args = {'id': password_transaction_id, 'enc_pass': enc_pass} -- cgit From 62ce69c1c63df818a2a6f1be6cdad33cbe6ef796 Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Mon, 27 Jun 2011 20:21:45 -0700 Subject: getting started --- nova/rpc.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/nova/rpc.py b/nova/rpc.py index 2e78a31e7..d4ac19c20 100644 --- a/nova/rpc.py +++ b/nova/rpc.py @@ -45,6 +45,8 @@ from nova import flags from nova import log as logging from nova import utils +from nova.notifier import api as notifier + LOG = logging.getLogger('nova.rpc') @@ -312,6 +314,7 @@ class ConsumerSet(object): if not it: break while True: + ex = None try: it.next() except StopIteration: @@ -319,7 +322,17 @@ class ConsumerSet(object): except greenlet.GreenletExit: running = False break + except exception.NovaException, e: + if not e.notification_level: + ex = e + # We have an exception we can + # tell the Notification system about. + # Pass it on. + except Exception as e: + ex = e + + if ex: LOG.exception(_("Exception while processing consumer")) self.reconnect() # Break to outer loop -- cgit From 4c98425ba7a53c8b966317444abe2d4f7b6556d8 Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Tue, 28 Jun 2011 05:51:40 -0700 Subject: refactoring to compute from scheduler --- nova/notifier/api.py | 39 +++++++++++++++++++++++++++++++++++++++ nova/rpc.py | 9 ++------- nova/scheduler/driver.py | 10 ++++++++++ 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/nova/notifier/api.py b/nova/notifier/api.py index d49517c8b..027aa7cc3 100644 --- a/nova/notifier/api.py +++ b/nova/notifier/api.py @@ -37,6 +37,45 @@ class BadPriorityException(Exception): pass +def publisher_id(service, host=None): + if not host: + host = FLAGS.host + return "%s.%s" % (service, host) + + +def msgkeys(event_type, instance_id, level, publisher_id): + return dict(event_type=event_type, instance_id=instance_id, + notification_level=level, publisher_id=publisher_id) + + +def safe_notify(publisher_id, event_type, priority, payload): + try: + notify(publisher_id, event_type, notification_level, payload) + exception Exception, e: + LOG.exception(_("Problem '%(e)' attempting to " + "send to notification system." % locals())) + + +def instance_safe_notify(publisher_id, event_type, priority, instance_id, + extra_payload=None): + payload = dict(instance_id = instance_id) + if extra_payload: + payload.extend(extra_payload) + safe_notify(publisher_id, event_type, priority, payload) + + +def exception_to_notification(self, ex): + required = ['instance_id', 'publisher_id', 'notification_level', + 'event_type'] + for key in required: + if not (hasattr(ex, key) and ex.key): + return # Doesn't have everything we need. Skip it. + instance_id = ex.instance_id + publisher_id = ex.publisher_id + notification_level = ex.notification_level + event_type = ex.event_type + instance_safe_notify(publisher_id, event_type, priority, instance_id) + def notify(publisher_id, event_type, priority, payload): """ Sends a notification using the specified driver diff --git a/nova/rpc.py b/nova/rpc.py index d4ac19c20..47d63769a 100644 --- a/nova/rpc.py +++ b/nova/rpc.py @@ -44,7 +44,6 @@ from nova import fakerabbit from nova import flags from nova import log as logging from nova import utils - from nova.notifier import api as notifier @@ -323,12 +322,8 @@ class ConsumerSet(object): running = False break except exception.NovaException, e: - if not e.notification_level: - ex = e - # We have an exception we can - # tell the Notification system about. - # Pass it on. - + ex = e + notifier.exception_to_notification(e) except Exception as e: ex = e diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py index 0b257c5d8..7e5a15c7f 100644 --- a/nova/scheduler/driver.py +++ b/nova/scheduler/driver.py @@ -27,6 +27,7 @@ from nova import db from nova import exception from nova import flags from nova import log as logging +from nova import notifier from nova import rpc from nova import utils from nova.compute import power_state @@ -47,6 +48,15 @@ class WillNotSchedule(exception.Error): pass +def publisher_id(host=None): + return notifier.publisher_id("scheduler", host) + + +def notifier(instance_id, event_type, level, host=None): + return dict(instance_id=instance_id, event_type=event_type, + notification_level=level, host=publisher_id(host)) + + class Scheduler(object): """The base class that all Scheduler clases should inherit from.""" -- cgit From a0f968235332e5400d507bbafa99bc0728aa8479 Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Tue, 28 Jun 2011 21:04:50 -0700 Subject: moved to wrap_exception decorator --- nova/compute/manager.py | 7 ++++++- nova/exception.py | 8 +++++++- nova/notifier/api.py | 26 -------------------------- nova/rpc.py | 8 -------- 4 files changed, 13 insertions(+), 36 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 5aed2c677..86d375b9e 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -54,6 +54,7 @@ from nova import utils from nova import volume from nova.compute import power_state from nova.compute.utils import terminate_volumes +from nova.notifier import api as notifier from nova.virt import driver @@ -111,6 +112,10 @@ def checks_instance_lock(function): return decorated_function +def publisher_id(host=None): + return notifier.publisher_id("compute", host) + + class ComputeManager(manager.SchedulerDependentManager): """Manages the running instances from creation to destruction.""" @@ -1158,7 +1163,7 @@ class ComputeManager(manager.SchedulerDependentManager): {"method": "pre_live_migration", "args": {'instance_id': instance_id}}) - except Exception: + except Exception, e: msg = _("Pre live migration for %(i_name)s failed at %(dest)s") LOG.error(msg % locals()) self.recover_live_migration(context, instance_ref) diff --git a/nova/exception.py b/nova/exception.py index f3a452228..4b625dd04 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -81,11 +81,17 @@ def wrap_db_error(f): _wrap.func_name = f.func_name -def wrap_exception(f): +def wrap_exception(f, notifier=None, publisher_id=None, level=None): def _wrap(*args, **kw): try: return f(*args, **kw) except Exception, e: + if notifier != None and 'safe_notify' in notifier.dir(): + event_type = f.__name__ + payload = dict(args=args, exception=e) + payload.update(kw) + notifier.safe_notify(publisher_id, event_type, level, payload) + if not isinstance(e, Error): #exc_type, exc_value, exc_traceback = sys.exc_info() LOG.exception(_('Uncaught exception')) diff --git a/nova/notifier/api.py b/nova/notifier/api.py index 027aa7cc3..89527be16 100644 --- a/nova/notifier/api.py +++ b/nova/notifier/api.py @@ -43,11 +43,6 @@ def publisher_id(service, host=None): return "%s.%s" % (service, host) -def msgkeys(event_type, instance_id, level, publisher_id): - return dict(event_type=event_type, instance_id=instance_id, - notification_level=level, publisher_id=publisher_id) - - def safe_notify(publisher_id, event_type, priority, payload): try: notify(publisher_id, event_type, notification_level, payload) @@ -55,27 +50,6 @@ def safe_notify(publisher_id, event_type, priority, payload): LOG.exception(_("Problem '%(e)' attempting to " "send to notification system." % locals())) - -def instance_safe_notify(publisher_id, event_type, priority, instance_id, - extra_payload=None): - payload = dict(instance_id = instance_id) - if extra_payload: - payload.extend(extra_payload) - safe_notify(publisher_id, event_type, priority, payload) - - -def exception_to_notification(self, ex): - required = ['instance_id', 'publisher_id', 'notification_level', - 'event_type'] - for key in required: - if not (hasattr(ex, key) and ex.key): - return # Doesn't have everything we need. Skip it. - instance_id = ex.instance_id - publisher_id = ex.publisher_id - notification_level = ex.notification_level - event_type = ex.event_type - instance_safe_notify(publisher_id, event_type, priority, instance_id) - def notify(publisher_id, event_type, priority, payload): """ Sends a notification using the specified driver diff --git a/nova/rpc.py b/nova/rpc.py index 47d63769a..2e78a31e7 100644 --- a/nova/rpc.py +++ b/nova/rpc.py @@ -44,7 +44,6 @@ from nova import fakerabbit from nova import flags from nova import log as logging from nova import utils -from nova.notifier import api as notifier LOG = logging.getLogger('nova.rpc') @@ -313,7 +312,6 @@ class ConsumerSet(object): if not it: break while True: - ex = None try: it.next() except StopIteration: @@ -321,13 +319,7 @@ class ConsumerSet(object): except greenlet.GreenletExit: running = False break - except exception.NovaException, e: - ex = e - notifier.exception_to_notification(e) except Exception as e: - ex = e - - if ex: LOG.exception(_("Exception while processing consumer")) self.reconnect() # Break to outer loop -- cgit From 8bd200505ada97780d3a63927cfadcded456b30d Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Wed, 29 Jun 2011 08:14:43 -0700 Subject: moved to wrap_exception approach --- nova/compute/manager.py | 20 ++++++++++---------- nova/exception.py | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 86d375b9e..f8ec3c861 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -200,7 +200,7 @@ class ComputeManager(manager.SchedulerDependentManager): def get_console_pool_info(self, context, console_type): return self.driver.get_console_pool_info(console_type) - @exception.wrap_exception + @exception.wrap_exception(publisher_id()) def refresh_security_group_rules(self, context, security_group_id, **kwargs): """Tell the virtualization driver to refresh security group rules. @@ -210,7 +210,7 @@ class ComputeManager(manager.SchedulerDependentManager): """ return self.driver.refresh_security_group_rules(security_group_id) - @exception.wrap_exception + @exception.wrap_exception(publisher_id()) def refresh_security_group_members(self, context, security_group_id, **kwargs): """Tell the virtualization driver to refresh security group members. @@ -220,7 +220,7 @@ class ComputeManager(manager.SchedulerDependentManager): """ return self.driver.refresh_security_group_members(security_group_id) - @exception.wrap_exception + @exception.wrap_exception(publisher_id()) def refresh_provider_fw_rules(self, context, **_kwargs): """This call passes straight through to the virtualization driver.""" return self.driver.refresh_provider_fw_rules() @@ -355,11 +355,11 @@ class ComputeManager(manager.SchedulerDependentManager): # be fixed once we have no-db-messaging pass - @exception.wrap_exception + @exception.wrap_exception(publisher_id()) def run_instance(self, context, instance_id, **kwargs): self._run_instance(context, instance_id, **kwargs) - @exception.wrap_exception + @exception.wrap_exception(publisher_id()) @checks_instance_lock def start_instance(self, context, instance_id): """Starting an instance on this host.""" @@ -421,7 +421,7 @@ class ComputeManager(manager.SchedulerDependentManager): if action_str == 'Terminating': terminate_volumes(self.db, context, instance_id) - @exception.wrap_exception + @exception.wrap_exception(publisher_id()) @checks_instance_lock def terminate_instance(self, context, instance_id): """Terminate an instance on this host.""" @@ -430,14 +430,14 @@ class ComputeManager(manager.SchedulerDependentManager): # TODO(ja): should we keep it in a terminated state for a bit? self.db.instance_destroy(context, instance_id) - @exception.wrap_exception + @exception.wrap_exception(publisher_id()) @checks_instance_lock def stop_instance(self, context, instance_id): """Stopping an instance on this host.""" self._shutdown_instance(context, instance_id, 'Stopping') # instance state will be updated to stopped by _poll_instance_states() - @exception.wrap_exception + @exception.wrap_exception(publisher_id()) @checks_instance_lock def rebuild_instance(self, context, instance_id, **kwargs): """Destroy and re-make this instance. @@ -466,7 +466,7 @@ class ComputeManager(manager.SchedulerDependentManager): self._update_launched_at(context, instance_id) self._update_state(context, instance_id) - @exception.wrap_exception + @exception.wrap_exception(publisher_id()) @checks_instance_lock def reboot_instance(self, context, instance_id): """Reboot an instance on this host.""" @@ -491,7 +491,7 @@ class ComputeManager(manager.SchedulerDependentManager): self.driver.reboot(instance_ref) self._update_state(context, instance_id) - @exception.wrap_exception + @exception.wrap_exception(publisher_id()) def snapshot_instance(self, context, instance_id, image_id): """Snapshot an instance on this host.""" context = context.elevated() diff --git a/nova/exception.py b/nova/exception.py index 4b625dd04..fb2094c04 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -25,6 +25,7 @@ SHOULD include dedicated exception logging. """ from nova import log as logging +from nova.notifier import api as notifier LOG = logging.getLogger('nova.exception') @@ -81,13 +82,12 @@ def wrap_db_error(f): _wrap.func_name = f.func_name -def wrap_exception(f, notifier=None, publisher_id=None, level=None): +def wrap_exception(f, event_type=None, publisher_id=None, level=notifier.ERROR): def _wrap(*args, **kw): try: return f(*args, **kw) except Exception, e: - if notifier != None and 'safe_notify' in notifier.dir(): - event_type = f.__name__ + if event_type and publisher_id: payload = dict(args=args, exception=e) payload.update(kw) notifier.safe_notify(publisher_id, event_type, level, payload) -- cgit From 799919fe59d4a4faed1ce4effd9705173671e4da Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Wed, 29 Jun 2011 19:10:11 -0700 Subject: done and done --- nova/exception.py | 3 ++- nova/tests/test_exception.py | 58 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/nova/exception.py b/nova/exception.py index c6d2bbc3d..ea590199c 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -82,7 +82,8 @@ def wrap_db_error(f): _wrap.func_name = f.func_name -def wrap_exception(notifier=None, publisher_id=None, event_type=None, level=None): +def wrap_exception(notifier=None, publisher_id=None, event_type=None, + level=None): """This decorator wraps a method to catch any exceptions that may get thrown. It logs the exception as well as optionally sending it to the notification system. diff --git a/nova/tests/test_exception.py b/nova/tests/test_exception.py index 4d3b9cc73..7e30d150f 100644 --- a/nova/tests/test_exception.py +++ b/nova/tests/test_exception.py @@ -32,3 +32,61 @@ class ApiErrorTestCase(test.TestCase): self.assertEqual(err.__str__(), 'blah code: fake error') self.assertEqual(err.code, 'blah code') self.assertEqual(err.msg, 'fake error') + + +class FakeNotifier(object): + """Acts like the nova.notifier.api module.""" + ERROR = 88 + + def __init__(self): + self.provided_publisher = None + self.provided_event = None + self.provided_priority = None + self.provided_payload = None + + def safe_notify(self, publisher, event, priority, payload): + self.provided_publisher = publisher + self.provided_event = event + self.provided_priority = priority + self.provided_payload = payload + + +def good_function(): + return 99 + + +def bad_function_error(): + raise exception.Error() + + +def bad_function_exception(): + raise Exception() + + +class WrapExceptionTestCase(test.TestCase): + def test_wrap_exception(self): + wrapped = exception.wrap_exception() + self.assertEquals(99, wrapped(good_function)()) + self.assertRaises(exception.Error, wrapped(bad_function_error)) + + # Note that Exception is converted to Error ... + self.assertRaises(exception.Error, wrapped(bad_function_exception)) + + def test_wrap_exception_with_notifier(self): + notifier = FakeNotifier() + wrapped = exception.wrap_exception(notifier, "publisher", "event", + "level") + self.assertRaises(exception.Error, wrapped(bad_function_exception)) + self.assertEquals(notifier.provided_publisher, "publisher") + self.assertEquals(notifier.provided_event, "event") + self.assertEquals(notifier.provided_priority, "level") + for key in ['exception', 'args']: + self.assertTrue(key in notifier.provided_payload.keys()) + + def test_wrap_exception_with_notifier_defaults(self): + notifier = FakeNotifier() + wrapped = exception.wrap_exception(notifier) + self.assertRaises(exception.Error, wrapped(bad_function_exception)) + self.assertEquals(notifier.provided_publisher, None) + self.assertEquals(notifier.provided_event, "bad_function_exception") + self.assertEquals(notifier.provided_priority, notifier.ERROR) -- cgit From 002b389aa90059c1c1986d4c1a3fbcd38527b4b4 Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Wed, 29 Jun 2011 19:11:27 -0700 Subject: pep8 --- nova/tests/test_exception.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/test_exception.py b/nova/tests/test_exception.py index 7e30d150f..63c807a84 100644 --- a/nova/tests/test_exception.py +++ b/nova/tests/test_exception.py @@ -49,7 +49,7 @@ class FakeNotifier(object): self.provided_event = event self.provided_priority = priority self.provided_payload = payload - + def good_function(): return 99 -- cgit From d17171b4277337388b372459571d9f3904798bca Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Wed, 29 Jun 2011 19:19:40 -0700 Subject: pep8 --- nova/tests/test_exception.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/test_exception.py b/nova/tests/test_exception.py index 63c807a84..16e273f89 100644 --- a/nova/tests/test_exception.py +++ b/nova/tests/test_exception.py @@ -71,7 +71,7 @@ class WrapExceptionTestCase(test.TestCase): # Note that Exception is converted to Error ... self.assertRaises(exception.Error, wrapped(bad_function_exception)) - + def test_wrap_exception_with_notifier(self): notifier = FakeNotifier() wrapped = exception.wrap_exception(notifier, "publisher", "event", -- cgit From fbe296a7ab3bf1b9ee2bf765d13b5675ff4d6295 Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Wed, 29 Jun 2011 20:02:30 -0700 Subject: clean up --- nova/api/openstack/wsgi.py | 1 - nova/compute/manager.py | 1 - nova/scheduler/driver.py | 5 ----- 3 files changed, 7 deletions(-) diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index 836a13b62..5b6e3cb1d 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -394,5 +394,4 @@ class Resource(wsgi.Application): """Find action-spefic method on controller and call it.""" controller_method = getattr(self.controller, action) - print "DISPATCHING", self.controller, action return controller_method(req=request, **action_args) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 78c98cf42..d5530c296 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -1183,7 +1183,6 @@ class ComputeManager(manager.SchedulerDependentManager): :returns: See driver.update_available_resource() """ - print "UPDATE AVAILABLE" return self.driver.update_available_resource(context, self.host) def pre_live_migration(self, context, instance_id, time=None): diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py index db392a607..ec2c9ef78 100644 --- a/nova/scheduler/driver.py +++ b/nova/scheduler/driver.py @@ -30,7 +30,6 @@ from nova import log as logging from nova import rpc from nova import utils from nova.compute import power_state -from nova.notifier import api as notifier_api FLAGS = flags.FLAGS @@ -49,10 +48,6 @@ class WillNotSchedule(exception.Error): pass -def publisher_id(host=None): - return notifier_api.publisher_id("scheduler", host) - - class Scheduler(object): """The base class that all Scheduler clases should inherit from.""" -- cgit From e789dd29c48ee8ad2b10eeb9ff24725f0e696bed Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Fri, 1 Jul 2011 07:31:17 -0700 Subject: review fixes --- nova/exception.py | 4 ++-- nova/notifier/api.py | 14 +++++--------- nova/tests/test_exception.py | 7 ++++++- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/nova/exception.py b/nova/exception.py index ea590199c..6e277b68d 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -113,8 +113,8 @@ def wrap_exception(notifier=None, publisher_id=None, event_type=None, # propagated. temp_type = f.__name__ - notifier.safe_notify(publisher_id, temp_type, temp_level, - payload) + notifier.notify(publisher_id, temp_type, temp_level, + payload) if not isinstance(e, Error): #exc_type, exc_value, exc_traceback = sys.exc_info() diff --git a/nova/notifier/api.py b/nova/notifier/api.py index d388eda96..98969fd3e 100644 --- a/nova/notifier/api.py +++ b/nova/notifier/api.py @@ -45,14 +45,6 @@ def publisher_id(service, host=None): return "%s.%s" % (service, host) -def safe_notify(publisher_id, event_type, priority, payload): - try: - notify(publisher_id, event_type, notification_level, payload) - except Exception, e: - LOG.exception(_("Problem '%(e)s' attempting to " - "send to notification system." % locals())) - - def notify(publisher_id, event_type, priority, payload): """ Sends a notification using the specified driver @@ -95,4 +87,8 @@ def notify(publisher_id, event_type, priority, payload): priority=priority, payload=payload, timestamp=str(utils.utcnow())) - driver.notify(msg) + try: + driver.notify(msg) + except Exception, e: + LOG.exception(_("Problem '%(e)s' attempting to " + "send to notification system." % locals())) diff --git a/nova/tests/test_exception.py b/nova/tests/test_exception.py index 16e273f89..692b714e5 100644 --- a/nova/tests/test_exception.py +++ b/nova/tests/test_exception.py @@ -64,11 +64,16 @@ def bad_function_exception(): class WrapExceptionTestCase(test.TestCase): - def test_wrap_exception(self): + def test_wrap_exception_good_return(self): wrapped = exception.wrap_exception() self.assertEquals(99, wrapped(good_function)()) + + def test_wrap_exception_throws_error(self): + wrapped = exception.wrap_exception() self.assertRaises(exception.Error, wrapped(bad_function_error)) + def test_wrap_exception_throws_exception(self): + wrapped = exception.wrap_exception() # Note that Exception is converted to Error ... self.assertRaises(exception.Error, wrapped(bad_function_exception)) -- cgit From 81716e8142fac86e779514997335999df4375a34 Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Fri, 1 Jul 2011 07:38:17 -0700 Subject: tweak --- nova/tests/test_exception.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/test_exception.py b/nova/tests/test_exception.py index 692b714e5..cd74f8871 100644 --- a/nova/tests/test_exception.py +++ b/nova/tests/test_exception.py @@ -44,7 +44,7 @@ class FakeNotifier(object): self.provided_priority = None self.provided_payload = None - def safe_notify(self, publisher, event, priority, payload): + def notify(self, publisher, event, priority, payload): self.provided_publisher = publisher self.provided_event = event self.provided_priority = priority -- cgit From 72bdbc314ac311e8c831410bc4f9c8935bf9d5e8 Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Fri, 1 Jul 2011 08:09:19 -0700 Subject: trunk merge --- nova/compute/manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 016915d2f..cf42a39aa 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -842,7 +842,7 @@ class ComputeManager(manager.SchedulerDependentManager): self.inject_network_info(context, instance_id) self.reset_network(context, instance_id) - @exception.wrap_exception + @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @checks_instance_lock def pause_instance(self, context, instance_id): """Pause an instance on this host.""" -- cgit From 4227264153e06d576387f76b267f3d35ff17f391 Mon Sep 17 00:00:00 2001 From: Mike Scherbakov Date: Sat, 2 Jul 2011 01:28:13 +0400 Subject: Improvements to nova-manage: network list now includes vlan and projectID, added servers list filtered by zone if needed --- bin/nova-manage | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index 7dfe91698..8ba78a56a 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -615,15 +615,19 @@ class NetworkCommands(object): def list(self): """List all created networks""" - print "%-18s\t%-15s\t%-15s\t%-15s" % (_('network'), - _('netmask'), - _('start address'), - 'DNS') + print "%-18s\t%-15s\t%-15s\t%-15s\t%-15s\t%-15s" % (_('network'), + _('netmask'), + _('start address'), + _('DNS'), + _('VlanID'), + 'project') for network in db.network_get_all(context.get_admin_context()): - print "%-18s\t%-15s\t%-15s\t%-15s" % (network.cidr, - network.netmask, - network.dhcp_start, - network.dns) + print "%-18s\t%-15s\t%-15s\t%-15s\t%-15s\t%-15s" % (network.cidr, + network.netmask, + network.dhcp_start, + network.dns, + network.vlan, + network.project_id) def delete(self, fixed_range): """Deletes a network""" @@ -812,6 +816,28 @@ class ServiceCommands(object): {"method": "update_available_resource"}) +class ServerCommands(object): + """List servers""" + + def list(self, zone=None): + """Show a list of all servers. Filter by zone. + args: [zone]""" + print "%-25s\t%-15s" % (_('host'), + _('zone')) + ctxt = context.get_admin_context() + now = utils.utcnow() + services = db.service_get_all(ctxt) + if zone: + services = [s for s in services if s['availability_zone'] == zone] + servers = [] + for srv in services: + if not [s for s in servers if s['host'] == srv['host']]: + servers.append(srv) + + for srv in servers: + print "%-25s\t%-15s" % (srv['host'], srv['availability_zone']) + + class DbCommands(object): """Class for managing the database.""" @@ -1191,6 +1217,7 @@ CATEGORIES = [ ('project', ProjectCommands), ('role', RoleCommands), ('service', ServiceCommands), + ('server', ServerCommands), ('shell', ShellCommands), ('user', UserCommands), ('version', VersionCommands), -- cgit From 479b55aefadd88e59a6cd489a39df53fecc46bdf Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Wed, 6 Jul 2011 13:19:37 -0400 Subject: updated expected xml in images show test to represent current spec --- nova/tests/api/openstack/test_images.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index 1e046531c..9291997bc 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -1161,7 +1161,9 @@ class ImageXMLSerializationTest(test.TestCase): TIMESTAMP = "2010-10-11T10:30:22Z" SERVER_HREF = 'http://localhost/v1.1/servers/123' + SERVER_BOOKMARK = 'http://localhost/servers/123' IMAGE_HREF = 'http://localhost/v1.1/images/%s' + IMAGE_BOOKMARK = 'http://localhost/images/%s' def test_show(self): serializer = images.ImageXMLSerializer() @@ -1181,7 +1183,6 @@ class ImageXMLSerializationTest(test.TestCase): { 'href': self.IMAGE_HREF % (1,), 'rel': 'bookmark', - 'type': 'application/json', }, ], }, @@ -1191,24 +1192,27 @@ class ImageXMLSerializationTest(test.TestCase): actual = minidom.parseString(output.replace(" ", "")) expected_server_href = self.SERVER_HREF + expected_server_bookmark = self.SERVER_BOOKMARK_ expected_href = self.IMAGE_HREF % (1, ) + expected_bookmark = self.IMAGE_BOOKMARK % (1, ) expected_now = self.TIMESTAMP expected = minidom.parseString(""" - - - + progress="80"> + + + + + + - - value1 - + value1 """.replace(" ", "") % (locals())) -- cgit From 94a6af26e46d4df35294ad0bf4dc4883b7bf052e Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Wed, 6 Jul 2011 14:47:41 -0400 Subject: Further test update and begin correcting serialization --- nova/api/openstack/images.py | 5 +++-- nova/tests/api/openstack/test_images.py | 30 ++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index bde9507c8..2e3d4f157 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -267,8 +267,9 @@ class ImageXMLSerializer(wsgi.XMLDictSerializer): metadata = { "attributes": { "image": ["id", "name", "updated", "created", "status", - "serverId", "progress", "serverRef"], - "link": ["rel", "type", "href"], + "serverId", "progress"], + "link": ["rel", "href"], + "server": ["name", "id"], }, } diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index 9291997bc..4f00ac1f8 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -1168,14 +1168,29 @@ class ImageXMLSerializationTest(test.TestCase): def test_show(self): serializer = images.ImageXMLSerializer() + #so we can see the full diff in the output + self.maxDiff = None fixture = { 'image': { 'id': 1, 'name': 'Image1', 'created': self.TIMESTAMP, 'updated': self.TIMESTAMP, - 'serverRef': self.SERVER_HREF, 'status': 'ACTIVE', + 'server': { + 'id': 1, + 'name': 'Server1', + 'links': [ + { + 'href': self.SERVER_BOOKMARK, + 'rel': 'bookmark', + }, + { + 'href': self.SERVER_HREF, + 'rel': 'self', + }, + ], + }, 'metadata': { 'key1': 'value1', }, @@ -1184,6 +1199,10 @@ class ImageXMLSerializationTest(test.TestCase): 'href': self.IMAGE_HREF % (1,), 'rel': 'bookmark', }, + { + 'href': self.IMAGE_BOOKMARK % (1,), + 'rel': 'self', + }, ], }, } @@ -1192,7 +1211,7 @@ class ImageXMLSerializationTest(test.TestCase): actual = minidom.parseString(output.replace(" ", "")) expected_server_href = self.SERVER_HREF - expected_server_bookmark = self.SERVER_BOOKMARK_ + expected_server_bookmark = self.SERVER_BOOKMARK expected_href = self.IMAGE_HREF % (1, ) expected_bookmark = self.IMAGE_BOOKMARK % (1, ) expected_now = self.TIMESTAMP @@ -1205,18 +1224,21 @@ class ImageXMLSerializationTest(test.TestCase): created="%(expected_now)s" status="ACTIVE" progress="80"> - + - value1 + + value1 + """.replace(" ", "") % (locals())) + print actual.toxml() self.assertEqual(expected.toxml(), actual.toxml()) def test_show_zero_metadata(self): -- cgit From 0415c413872697c6f9fecc28928af0525780f868 Mon Sep 17 00:00:00 2001 From: Mark Washenberger Date: Wed, 6 Jul 2011 16:40:00 -0400 Subject: correct test_show --- nova/api/openstack/images.py | 70 ++++++++++++++++++++++----------- nova/tests/api/openstack/test_images.py | 23 ++++++----- 2 files changed, 61 insertions(+), 32 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 2e3d4f157..750b034b9 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -262,34 +262,60 @@ class ControllerV11(Controller): return {'instance_ref': server_ref} -class ImageXMLSerializer(wsgi.XMLDictSerializer): +class ImageXMLSerializer(wsgi.DictSerializer): - metadata = { - "attributes": { - "image": ["id", "name", "updated", "created", "status", - "serverId", "progress"], - "link": ["rel", "href"], - "server": ["name", "id"], - }, - } - - xmlns = wsgi.XMLNS_V11 + xmlns = {'': wsgi.XMLNS_V11, 'atom': "http://www.w3.org/2005/Atom"} def __init__(self): self.metadata_serializer = image_metadata.ImageMetadataXMLSerializer() + def _add_xmlns(self, node): + for key, ns in self.xmlns.iteritems(): + if key is not '': + name = 'xmlns:%s' % key + else: + name = 'xmlns' + node.setAttribute(name, ns) + def _image_to_xml(self, xml_doc, image): - try: - metadata = image.pop('metadata').items() - except Exception: - LOG.debug(_("Image object missing metadata attribute")) - metadata = {} + image_node = xml_doc.createElement('image') + self._add_image_attributes(image_node, image) - node = self._to_xml_node(xml_doc, self.metadata, 'image', image) - metadata_node = self.metadata_serializer.meta_list_to_xml(xml_doc, - metadata) - node.appendChild(metadata_node) - return node + server_node = self._create_server_node(xml_doc, image['server']) + image_node.appendChild(server_node) + + metadata = image.get('metadata', {}) + metadata_node = self._create_metadata_node(xml_doc, metadata.items()) + image_node.appendChild(metadata_node) + + self._add_atom_links(xml_doc, image_node, image['links']) + + return image_node + + def _add_image_attributes(self, node, image): + node.setAttribute('id', str(image['id'])) + node.setAttribute('name', image['name']) + node.setAttribute('created', image['created']) + node.setAttribute('updated', image['updated']) + node.setAttribute('status', image['status']) + node.setAttribute('progress', str(image['progress'])) + + def _create_server_node(self, xml_doc, server): + server_node = xml_doc.createElement('server') + server_node.setAttribute('id', str(server['id'])) + server_node.setAttribute('name', server['name']) + self._add_atom_links(xml_doc, server_node, server['links']) + return server_node + + def _create_metadata_node(self, xml_doc, metadata): + return self.metadata_serializer.meta_list_to_xml(xml_doc, metadata) + + def _add_atom_links(self, xml_doc, node, links): + for link in links: + link_node = xml_doc.createElement('atom:link') + link_node.setAttribute('rel', link['rel']) + link_node.setAttribute('href', link['href']) + node.appendChild(link_node) def _image_list_to_xml(self, xml_doc, images): container_node = xml_doc.createElement('images') @@ -307,7 +333,7 @@ class ImageXMLSerializer(wsgi.XMLDictSerializer): def _image_list_to_xml_string(self, images): xml_doc = minidom.Document() container_node = self._image_list_to_xml(xml_doc, images) - self._add_xmlns(container_node) + self._add_xmlns(item_node) return container_node.toprettyxml(indent=' ') def detail(self, images_dict): diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index 4f00ac1f8..873607997 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -1177,18 +1177,19 @@ class ImageXMLSerializationTest(test.TestCase): 'created': self.TIMESTAMP, 'updated': self.TIMESTAMP, 'status': 'ACTIVE', + 'progress': 80, 'server': { 'id': 1, 'name': 'Server1', 'links': [ - { - 'href': self.SERVER_BOOKMARK, - 'rel': 'bookmark', - }, { 'href': self.SERVER_HREF, 'rel': 'self', }, + { + 'href': self.SERVER_BOOKMARK, + 'rel': 'bookmark', + }, ], }, 'metadata': { @@ -1197,11 +1198,11 @@ class ImageXMLSerializationTest(test.TestCase): 'links': [ { 'href': self.IMAGE_HREF % (1,), - 'rel': 'bookmark', + 'rel': 'self', }, { 'href': self.IMAGE_BOOKMARK % (1,), - 'rel': 'self', + 'rel': 'bookmark', }, ], }, @@ -1225,19 +1226,21 @@ class ImageXMLSerializationTest(test.TestCase): status="ACTIVE" progress="80"> - - + + - - value1 + + """.replace(" ", "") % (locals())) + print expected.toxml() + print '---' print actual.toxml() self.assertEqual(expected.toxml(), actual.toxml()) -- cgit From 8caf69dc93d9112e9be8989cd2136a407e09df44 Mon Sep 17 00:00:00 2001 From: Mark Washenberger Date: Thu, 7 Jul 2011 09:24:40 -0400 Subject: progress and server are optional --- nova/api/openstack/images.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 750b034b9..eaa7aef5a 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -281,8 +281,9 @@ class ImageXMLSerializer(wsgi.DictSerializer): image_node = xml_doc.createElement('image') self._add_image_attributes(image_node, image) - server_node = self._create_server_node(xml_doc, image['server']) - image_node.appendChild(server_node) + if 'server' in image: + server_node = self._create_server_node(xml_doc, image['server']) + image_node.appendChild(server_node) metadata = image.get('metadata', {}) metadata_node = self._create_metadata_node(xml_doc, metadata.items()) @@ -298,7 +299,8 @@ class ImageXMLSerializer(wsgi.DictSerializer): node.setAttribute('created', image['created']) node.setAttribute('updated', image['updated']) node.setAttribute('status', image['status']) - node.setAttribute('progress', str(image['progress'])) + if 'progress' in image: + node.setAttribute('progress', str(image['progress'])) def _create_server_node(self, xml_doc, server): server_node = xml_doc.createElement('server') @@ -333,7 +335,7 @@ class ImageXMLSerializer(wsgi.DictSerializer): def _image_list_to_xml_string(self, images): xml_doc = minidom.Document() container_node = self._image_list_to_xml(xml_doc, images) - self._add_xmlns(item_node) + self._add_xmlns(container_node) return container_node.toprettyxml(indent=' ') def detail(self, images_dict): -- cgit From b50e92d43f958bf966fce4f608daa467b40453c1 Mon Sep 17 00:00:00 2001 From: Mark Washenberger Date: Thu, 7 Jul 2011 10:48:17 -0400 Subject: make server and image metadata optional --- nova/api/openstack/images.py | 7 +- nova/tests/api/openstack/test_images.py | 158 +++++++++++++++++++++++++------- 2 files changed, 128 insertions(+), 37 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index eaa7aef5a..8746db4e0 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -285,9 +285,10 @@ class ImageXMLSerializer(wsgi.DictSerializer): server_node = self._create_server_node(xml_doc, image['server']) image_node.appendChild(server_node) - metadata = image.get('metadata', {}) - metadata_node = self._create_metadata_node(xml_doc, metadata.items()) - image_node.appendChild(metadata_node) + metadata = image.get('metadata', {}).items() + if len(metadata) > 0: + metadata_node = self._create_metadata_node(xml_doc, metadata) + image_node.appendChild(metadata_node) self._add_atom_links(xml_doc, image_node, image['links']) diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index 873607997..25c7001f5 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -1197,11 +1197,11 @@ class ImageXMLSerializationTest(test.TestCase): }, 'links': [ { - 'href': self.IMAGE_HREF % (1,), + 'href': self.IMAGE_HREF % 1, 'rel': 'self', }, { - 'href': self.IMAGE_BOOKMARK % (1,), + 'href': self.IMAGE_BOOKMARK % 1, 'rel': 'bookmark', }, ], @@ -1213,8 +1213,8 @@ class ImageXMLSerializationTest(test.TestCase): expected_server_href = self.SERVER_HREF expected_server_bookmark = self.SERVER_BOOKMARK - expected_href = self.IMAGE_HREF % (1, ) - expected_bookmark = self.IMAGE_BOOKMARK % (1, ) + expected_href = self.IMAGE_HREF % 1 + expected_bookmark = self.IMAGE_BOOKMARK % 1 expected_now = self.TIMESTAMP expected = minidom.parseString(""" """.replace(" ", "") % (locals())) - print expected.toxml() - print '---' - print actual.toxml() self.assertEqual(expected.toxml(), actual.toxml()) def test_show_zero_metadata(self): serializer = images.ImageXMLSerializer() + self.maxDiff = None fixture = { 'image': { 'id': 1, 'name': 'Image1', 'created': self.TIMESTAMP, 'updated': self.TIMESTAMP, - 'serverRef': self.SERVER_HREF, 'status': 'ACTIVE', + 'server': { + 'id': 1, + 'name': 'Server1', + 'links': [ + { + 'href': self.SERVER_HREF, + 'rel': 'self', + }, + { + 'href': self.SERVER_BOOKMARK, + 'rel': 'bookmark', + }, + ], + }, 'metadata': {}, 'links': [ { - 'href': self.IMAGE_HREF % (1,), + 'href': self.IMAGE_HREF % 1, + 'rel': 'self', + }, + { + 'href': self.IMAGE_BOOKMARK % 1, 'rel': 'bookmark', - 'type': 'application/json', }, ], }, @@ -1270,21 +1284,24 @@ class ImageXMLSerializationTest(test.TestCase): actual = minidom.parseString(output.replace(" ", "")) expected_server_href = self.SERVER_HREF - expected_href = self.IMAGE_HREF % (1, ) + expected_server_bookmark = self.SERVER_BOOKMARK + expected_href = self.IMAGE_HREF % 1 + expected_bookmark = self.IMAGE_BOOKMARK % 1 expected_now = self.TIMESTAMP expected = minidom.parseString(""" - - - - + status="ACTIVE"> + + + + + + """.replace(" ", "") % (locals())) @@ -1293,22 +1310,38 @@ class ImageXMLSerializationTest(test.TestCase): def test_show_image_no_metadata_key(self): serializer = images.ImageXMLSerializer() + self.maxDiff = None fixture = { 'image': { 'id': 1, 'name': 'Image1', 'created': self.TIMESTAMP, 'updated': self.TIMESTAMP, - 'serverRef': self.SERVER_HREF, 'status': 'ACTIVE', + 'server': { + 'id': 1, + 'name': 'Server1', + 'links': [ + { + 'href': self.SERVER_HREF, + 'rel': 'self', + }, + { + 'href': self.SERVER_BOOKMARK, + 'rel': 'bookmark', + }, + ], + }, 'links': [ { - 'href': self.IMAGE_HREF % (1,), + 'href': self.IMAGE_HREF % 1, + 'rel': 'self', + }, + { + 'href': self.IMAGE_BOOKMARK % 1, 'rel': 'bookmark', - 'type': 'application/json', }, ], - }, } @@ -1316,21 +1349,78 @@ class ImageXMLSerializationTest(test.TestCase): actual = minidom.parseString(output.replace(" ", "")) expected_server_href = self.SERVER_HREF - expected_href = self.IMAGE_HREF % (1, ) + expected_server_bookmark = self.SERVER_BOOKMARK + expected_href = self.IMAGE_HREF % 1 + expected_bookmark = self.IMAGE_BOOKMARK % 1 expected_now = self.TIMESTAMP expected = minidom.parseString(""" - - - - + status="ACTIVE"> + + + + + + + + """.replace(" ", "") % (locals())) + + self.assertEqual(expected.toxml(), actual.toxml()) + + def test_show_no_server(self): + serializer = images.ImageXMLSerializer() + + #so we can see the full diff in the output + self.maxDiff = None + fixture = { + 'image': { + 'id': 1, + 'name': 'Image1', + 'created': self.TIMESTAMP, + 'updated': self.TIMESTAMP, + 'status': 'ACTIVE', + 'metadata': { + 'key1': 'value1', + }, + 'links': [ + { + 'href': self.IMAGE_HREF % 1, + 'rel': 'self', + }, + { + 'href': self.IMAGE_BOOKMARK % 1, + 'rel': 'bookmark', + }, + ], + }, + } + + output = serializer.serialize(fixture, 'show') + actual = minidom.parseString(output.replace(" ", "")) + + expected_href = self.IMAGE_HREF % 1 + expected_bookmark = self.IMAGE_BOOKMARK % 1 + expected_now = self.TIMESTAMP + expected = minidom.parseString(""" + + + + value1 + + + + """.replace(" ", "") % (locals())) @@ -1528,7 +1618,7 @@ class ImageXMLSerializationTest(test.TestCase): }, 'links': [ { - 'href': self.IMAGE_HREF % (1,), + 'href': self.IMAGE_HREF % 1, 'rel': 'bookmark', 'type': 'application/json', }, @@ -1540,7 +1630,7 @@ class ImageXMLSerializationTest(test.TestCase): actual = minidom.parseString(output.replace(" ", "")) expected_server_href = self.SERVER_HREF - expected_href = self.IMAGE_HREF % (1, ) + expected_href = self.IMAGE_HREF % 1 expected_now = self.TIMESTAMP expected = minidom.parseString(""" Date: Thu, 7 Jul 2011 11:06:35 -0400 Subject: Updated test_detail --- nova/tests/api/openstack/test_images.py | 117 +++++++++++++++++++------------- 1 file changed, 69 insertions(+), 48 deletions(-) diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index 701d8be8a..3e8d4700d 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -1473,84 +1473,105 @@ class ImageXMLSerializationTest(test.TestCase): def test_detail(self): serializer = images.ImageXMLSerializer() - fixtures = { + #so we can see the full diff in the output + self.maxDiff = None + fixture = { 'images': [ { 'id': 1, 'name': 'Image1', 'created': self.TIMESTAMP, 'updated': self.TIMESTAMP, - 'serverRef': self.SERVER_HREF, 'status': 'ACTIVE', - 'metadata': { - 'key1': 'value1', - 'key2': 'value2', + 'server': { + 'id': 1, + 'name': 'Server1', + 'links': [ + { + 'href': self.SERVER_HREF, + 'rel': 'self', + }, + { + 'href': self.SERVER_BOOKMARK, + 'rel': 'bookmark', + }, + ], }, 'links': [ { - 'href': 'http://localhost/v1.1/images/1', + 'href': self.IMAGE_HREF % 1, + 'rel': 'self', + }, + { + 'href': self.IMAGE_BOOKMARK % 1, 'rel': 'bookmark', - 'type': 'application/json', }, ], }, { 'id': 2, - 'name': 'queued image', + 'name': 'Image2', 'created': self.TIMESTAMP, 'updated': self.TIMESTAMP, - 'serverRef': self.SERVER_HREF, - 'metadata': {}, - 'status': 'QUEUED', + 'status': 'SAVING', + 'progress': 80, + 'metadata': { + 'key1': 'value1', + }, 'links': [ { - 'href': 'http://localhost/v1.1/images/2', + 'href': self.IMAGE_HREF % 2, + 'rel': 'self', + }, + { + 'href': self.IMAGE_BOOKMARK % 2, 'rel': 'bookmark', - 'type': 'application/json', }, ], }, - ], + ] } - output = serializer.serialize(fixtures, 'detail') + output = serializer.serialize(fixture, 'detail') actual = minidom.parseString(output.replace(" ", "")) - expected_serverRef = self.SERVER_HREF + expected_server_href = self.SERVER_HREF + expected_server_bookmark = self.SERVER_BOOKMARK + expected_href = self.IMAGE_HREF % 1 + expected_bookmark = self.IMAGE_BOOKMARK % 1 + expected_href_two = self.IMAGE_HREF % 2 + expected_bookmark_two = self.IMAGE_BOOKMARK % 2 expected_now = self.TIMESTAMP expected = minidom.parseString(""" - - - - - - - - value2 - - - value1 - - - - - - - - - + + + + + + + + + + + + + value1 + + + + + """.replace(" ", "") % (locals())) -- cgit From 63d579523985cbd4c896d9a05e523761e1cadb3a Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 7 Jul 2011 11:11:40 -0400 Subject: fixed image create response test --- nova/tests/api/openstack/test_images.py | 44 +++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index 3e8d4700d..c8e7df096 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -1580,22 +1580,41 @@ class ImageXMLSerializationTest(test.TestCase): def test_create(self): serializer = images.ImageXMLSerializer() + #so we can see the full diff in the output + self.maxDiff = None fixture = { 'image': { 'id': 1, 'name': 'Image1', 'created': self.TIMESTAMP, 'updated': self.TIMESTAMP, - 'serverRef': self.SERVER_HREF, - 'status': 'ACTIVE', + 'status': 'SAVING', + 'progress': 80, + 'server': { + 'id': 1, + 'name': 'Server1', + 'links': [ + { + 'href': self.SERVER_HREF, + 'rel': 'self', + }, + { + 'href': self.SERVER_BOOKMARK, + 'rel': 'bookmark', + }, + ], + }, 'metadata': { 'key1': 'value1', }, 'links': [ { 'href': self.IMAGE_HREF % 1, + 'rel': 'self', + }, + { + 'href': self.IMAGE_BOOKMARK % 1, 'rel': 'bookmark', - 'type': 'application/json', }, ], }, @@ -1605,25 +1624,30 @@ class ImageXMLSerializationTest(test.TestCase): actual = minidom.parseString(output.replace(" ", "")) expected_server_href = self.SERVER_HREF + expected_server_bookmark = self.SERVER_BOOKMARK expected_href = self.IMAGE_HREF % 1 + expected_bookmark = self.IMAGE_BOOKMARK % 1 expected_now = self.TIMESTAMP expected = minidom.parseString(""" - - - + status="SAVING" + progress="80"> + + + + value1 + + """.replace(" ", "") % (locals())) -- cgit From ddc33b8163423c5138b40885cb3430104896c676 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 7 Jul 2011 11:36:45 -0400 Subject: Added image index --- nova/api/openstack/images.py | 41 ++++++++++++++----- nova/tests/api/openstack/test_images.py | 71 +++++++++++++-------------------- 2 files changed, 60 insertions(+), 52 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 8746db4e0..a81dd4299 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -278,6 +278,13 @@ class ImageXMLSerializer(wsgi.DictSerializer): node.setAttribute(name, ns) def _image_to_xml(self, xml_doc, image): + image_node = xml_doc.createElement('image') + image_node.setAttribute('id', str(image['id'])) + image_node.setAttribute('name', image['name']) + self._add_atom_links(xml_doc, image_node, image['links']) + return image_node + + def _image_to_xml_detailed(self, xml_doc, image): image_node = xml_doc.createElement('image') self._add_image_attributes(image_node, image) @@ -320,33 +327,49 @@ class ImageXMLSerializer(wsgi.DictSerializer): link_node.setAttribute('href', link['href']) node.appendChild(link_node) - def _image_list_to_xml(self, xml_doc, images): + def _image_list_to_xml(self, xml_doc, images, image_to_xml): container_node = xml_doc.createElement('images') for image in images: - item_node = self._image_to_xml(xml_doc, image) + item_node = image_to_xml(xml_doc, image) container_node.appendChild(item_node) return container_node - def _image_to_xml_string(self, image): + def _image_to_xml_string(self, image, detailed): xml_doc = minidom.Document() - item_node = self._image_to_xml(xml_doc, image) + if detailed: + image_to_xml = self._image_to_xml_detailed + else: + image_to_xml = self._image_to_xml + item_node = image_to_xml(xml_doc, image) self._add_xmlns(item_node) return item_node.toprettyxml(indent=' ') - def _image_list_to_xml_string(self, images): + def _image_list_to_xml_string(self, images, detailed): xml_doc = minidom.Document() - container_node = self._image_list_to_xml(xml_doc, images) + if detailed: + image_to_xml = self._image_to_xml_detailed + else: + image_to_xml = self._image_to_xml + container_node = self._image_list_to_xml(xml_doc, images, image_to_xml) + self._add_xmlns(container_node) return container_node.toprettyxml(indent=' ') + def index(self, images_dict): + return self._image_list_to_xml_string(images_dict['images'], + detailed=False) + def detail(self, images_dict): - return self._image_list_to_xml_string(images_dict['images']) + return self._image_list_to_xml_string(images_dict['images'], + detailed=True) def show(self, image_dict): - return self._image_to_xml_string(image_dict['image']) + return self._image_to_xml_string(image_dict['image'], + detailed=True) def create(self, image_dict): - return self._image_to_xml_string(image_dict['image']) + return self._image_to_xml_string(image_dict['image'], + detailed=True) def create_resource(version='1.0'): diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index c8e7df096..cf68f5f53 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -1383,70 +1383,53 @@ class ImageXMLSerializationTest(test.TestCase): def test_index(self): serializer = images.ImageXMLSerializer() - fixtures = { + #so we can see the full diff in the output + self.maxDiff = None + fixture = { 'images': [ { 'id': 1, 'name': 'Image1', - 'created': self.TIMESTAMP, - 'updated': self.TIMESTAMP, - 'serverRef': self.SERVER_HREF, - 'status': 'ACTIVE', 'links': [ { - 'href': 'http://localhost/v1.1/images/1', - 'rel': 'bookmark', - 'type': 'application/json', + 'href': self.IMAGE_HREF % 1, + 'rel': 'self', }, ], }, { 'id': 2, - 'name': 'queued image', - 'created': self.TIMESTAMP, - 'updated': self.TIMESTAMP, - 'serverRef': self.SERVER_HREF, - 'status': 'QUEUED', + 'name': 'Image2', 'links': [ { - 'href': 'http://localhost/v1.1/images/2', - 'rel': 'bookmark', - 'type': 'application/json', + 'href': self.IMAGE_HREF % 2, + 'rel': 'self', }, ], }, - ], + ] } - output = serializer.serialize(fixtures, 'index') + output = serializer.serialize(fixture, 'index') actual = minidom.parseString(output.replace(" ", "")) - expected_serverRef = self.SERVER_HREF + expected_server_href = self.SERVER_HREF + expected_server_bookmark = self.SERVER_BOOKMARK + expected_href = self.IMAGE_HREF % 1 + expected_bookmark = self.IMAGE_BOOKMARK % 1 + expected_href_two = self.IMAGE_HREF % 2 + expected_bookmark_two = self.IMAGE_BOOKMARK % 2 expected_now = self.TIMESTAMP expected = minidom.parseString(""" - - - - - - - - - - - + + + + + + + """.replace(" ", "") % (locals())) @@ -1465,7 +1448,9 @@ class ImageXMLSerializationTest(test.TestCase): expected_serverRef = self.SERVER_HREF expected_now = self.TIMESTAMP expected = minidom.parseString(""" - + """.replace(" ", "") % (locals())) self.assertEqual(expected.toxml(), actual.toxml()) -- cgit From 49683f2f84a9eb4436c63465d11ae8f451265eae Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 7 Jul 2011 14:08:57 -0400 Subject: Dried up images XML serialization --- nova/api/openstack/images.py | 80 ++++++++++++++++++------------------------- nova/api/openstack/servers.py | 12 +++++++ nova/api/openstack/wsgi.py | 12 +++++++ 3 files changed, 58 insertions(+), 46 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index a81dd4299..bc7517c40 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -27,6 +27,7 @@ from nova import utils from nova.api.openstack import common from nova.api.openstack import faults from nova.api.openstack import image_metadata +from nova.api.openstack import servers from nova.api.openstack.views import images as images_view from nova.api.openstack import wsgi @@ -262,26 +263,19 @@ class ControllerV11(Controller): return {'instance_ref': server_ref} -class ImageXMLSerializer(wsgi.DictSerializer): +class ImageXMLSerializer(wsgi.XMLDictSerializer): - xmlns = {'': wsgi.XMLNS_V11, 'atom': "http://www.w3.org/2005/Atom"} + xmlns = wsgi.XMLNS_V11 def __init__(self): self.metadata_serializer = image_metadata.ImageMetadataXMLSerializer() - - def _add_xmlns(self, node): - for key, ns in self.xmlns.iteritems(): - if key is not '': - name = 'xmlns:%s' % key - else: - name = 'xmlns' - node.setAttribute(name, ns) + self.server_serializer = servers.ServerXMLSerializer() def _image_to_xml(self, xml_doc, image): image_node = xml_doc.createElement('image') image_node.setAttribute('id', str(image['id'])) image_node.setAttribute('name', image['name']) - self._add_atom_links(xml_doc, image_node, image['links']) + self._create_link_nodes(xml_doc, image_node, image['links']) return image_node def _image_to_xml_detailed(self, xml_doc, image): @@ -297,7 +291,7 @@ class ImageXMLSerializer(wsgi.DictSerializer): metadata_node = self._create_metadata_node(xml_doc, metadata) image_node.appendChild(metadata_node) - self._add_atom_links(xml_doc, image_node, image['links']) + self._create_link_nodes(xml_doc, image_node, image['links']) return image_node @@ -310,25 +304,19 @@ class ImageXMLSerializer(wsgi.DictSerializer): if 'progress' in image: node.setAttribute('progress', str(image['progress'])) - def _create_server_node(self, xml_doc, server): - server_node = xml_doc.createElement('server') - server_node.setAttribute('id', str(server['id'])) - server_node.setAttribute('name', server['name']) - self._add_atom_links(xml_doc, server_node, server['links']) - return server_node - def _create_metadata_node(self, xml_doc, metadata): return self.metadata_serializer.meta_list_to_xml(xml_doc, metadata) - def _add_atom_links(self, xml_doc, node, links): - for link in links: - link_node = xml_doc.createElement('atom:link') - link_node.setAttribute('rel', link['rel']) - link_node.setAttribute('href', link['href']) - node.appendChild(link_node) + def _create_server_node(self, xml_doc, server): + return self.server_serializer.server_to_xml(xml_doc, server) - def _image_list_to_xml(self, xml_doc, images, image_to_xml): + def _image_list_to_xml(self, xml_doc, images, detailed): container_node = xml_doc.createElement('images') + if detailed: + image_to_xml = self._image_to_xml_detailed + else: + image_to_xml = self._image_to_xml + for image in images: item_node = image_to_xml(xml_doc, image) container_node.appendChild(item_node) @@ -342,34 +330,34 @@ class ImageXMLSerializer(wsgi.DictSerializer): image_to_xml = self._image_to_xml item_node = image_to_xml(xml_doc, image) self._add_xmlns(item_node) - return item_node.toprettyxml(indent=' ') - - def _image_list_to_xml_string(self, images, detailed): - xml_doc = minidom.Document() - if detailed: - image_to_xml = self._image_to_xml_detailed - else: - image_to_xml = self._image_to_xml - container_node = self._image_list_to_xml(xml_doc, images, image_to_xml) - - self._add_xmlns(container_node) - return container_node.toprettyxml(indent=' ') + self._add_atom_xmlns(item_node) + return item_node.toprettyxml(indent=' ', encoding='UTF-8') def index(self, images_dict): - return self._image_list_to_xml_string(images_dict['images'], - detailed=False) + xml_doc = minidom.Document() + node = self._image_list_to_xml(xml_doc, + images_dict['images'], + detailed=False) + return self.xml_string(node) def detail(self, images_dict): - return self._image_list_to_xml_string(images_dict['images'], - detailed=True) + xml_doc = minidom.Document() + node = self._image_list_to_xml(xml_doc, + images_dict['images'], + detailed=True) + return self.xml_string(node) def show(self, image_dict): - return self._image_to_xml_string(image_dict['image'], - detailed=True) + xml_doc = minidom.Document() + node = self._image_to_xml_detailed(xml_doc, + image_dict['image']) + return self.xml_string(node) def create(self, image_dict): - return self._image_to_xml_string(image_dict['image'], - detailed=True) + xml_doc = minidom.Document() + node = self._image_to_xml_detailed(xml_doc, + image_dict['image']) + return self.xml_string(node) def create_resource(version='1.0'): diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index fc1ab8d46..cff4e9b82 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -627,3 +627,15 @@ def create_resource(version='1.0'): return wsgi.Resource(controller, serializers=serializers, deserializers=deserializers) + + +class ServerXMLSerializer(wsgi.XMLDictSerializer): + def __init__(self, xmlns=wsgi.XMLNS_V11): + super(ServerXMLSerializer, self).__init__(xmlns=xmlns) + + def server_to_xml(self, xml_doc, server): + server_node = xml_doc.createElement('server') + server_node.setAttribute('id', str(server['id'])) + server_node.setAttribute('name', server['name']) + self._create_link_nodes(xml_doc, server_node, server['links']) + return server_node diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index 5b6e3cb1d..693c85b97 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -236,9 +236,14 @@ class XMLDictSerializer(DictSerializer): return node.toprettyxml(indent=' ', encoding='utf-8') + def xml_string(self, node): + self._add_xmlns(node) + return node.toprettyxml(indent=' ', encoding='UTF-8') + def _add_xmlns(self, node): if self.xmlns is not None: node.setAttribute('xmlns', self.xmlns) + node.setAttribute('xmlns:atom', "http://www.w3.org/2005/Atom") def _to_xml_node(self, doc, metadata, nodename, data): """Recursive method to convert data members to XML nodes.""" @@ -294,6 +299,13 @@ class XMLDictSerializer(DictSerializer): result.appendChild(node) return result + def _create_link_nodes(self, xml_doc, node, links): + for link in links: + link_node = xml_doc.createElement('atom:link') + link_node.setAttribute('rel', link['rel']) + link_node.setAttribute('href', link['href']) + node.appendChild(link_node) + class ResponseSerializer(object): """Encode the necessary pieces into a response object""" -- cgit From 14ee32f07536f5686794d2dbe8f1fad159af4dfe Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 7 Jul 2011 14:09:23 -0400 Subject: Dried up images XML serialization --- nova/api/openstack/images.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index bc7517c40..c540037fa 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -322,17 +322,6 @@ class ImageXMLSerializer(wsgi.XMLDictSerializer): container_node.appendChild(item_node) return container_node - def _image_to_xml_string(self, image, detailed): - xml_doc = minidom.Document() - if detailed: - image_to_xml = self._image_to_xml_detailed - else: - image_to_xml = self._image_to_xml - item_node = image_to_xml(xml_doc, image) - self._add_xmlns(item_node) - self._add_atom_xmlns(item_node) - return item_node.toprettyxml(indent=' ', encoding='UTF-8') - def index(self, images_dict): xml_doc = minidom.Document() node = self._image_list_to_xml(xml_doc, -- cgit From 162b9651c3e251d8acae764f08372f764597f8ca Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 7 Jul 2011 14:27:27 -0400 Subject: Added param to keep current things from breaking until we update all of the xml serializers and view builders to reflect the current spec --- nova/api/openstack/images.py | 8 ++++---- nova/api/openstack/wsgi.py | 15 ++++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index c540037fa..8f75fae4c 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -327,26 +327,26 @@ class ImageXMLSerializer(wsgi.XMLDictSerializer): node = self._image_list_to_xml(xml_doc, images_dict['images'], detailed=False) - return self.xml_string(node) + return self.xml_string(node, True) def detail(self, images_dict): xml_doc = minidom.Document() node = self._image_list_to_xml(xml_doc, images_dict['images'], detailed=True) - return self.xml_string(node) + return self.xml_string(node, True) def show(self, image_dict): xml_doc = minidom.Document() node = self._image_to_xml_detailed(xml_doc, image_dict['image']) - return self.xml_string(node) + return self.xml_string(node, True) def create(self, image_dict): xml_doc = minidom.Document() node = self._image_to_xml_detailed(xml_doc, image_dict['image']) - return self.xml_string(node) + return self.xml_string(node, True) def create_resource(version='1.0'): diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index 693c85b97..4ac7b56c9 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -232,18 +232,19 @@ class XMLDictSerializer(DictSerializer): doc = minidom.Document() node = self._to_xml_node(doc, self.metadata, root_key, data[root_key]) - self._add_xmlns(node) + return self.xml_string(node) - return node.toprettyxml(indent=' ', encoding='utf-8') - - def xml_string(self, node): - self._add_xmlns(node) + def xml_string(self, node, has_atom=False): + self._add_xmlns(node, has_atom) return node.toprettyxml(indent=' ', encoding='UTF-8') - def _add_xmlns(self, node): + #NOTE (ameade): the has_atom should be removed after all of the + # xml serializers and view builders have been updated + def _add_xmlns(self, node, has_atom=False): if self.xmlns is not None: node.setAttribute('xmlns', self.xmlns) - node.setAttribute('xmlns:atom', "http://www.w3.org/2005/Atom") + if has_atom: + node.setAttribute('xmlns:atom', "http://www.w3.org/2005/Atom") def _to_xml_node(self, doc, metadata, nodename, data): """Recursive method to convert data members to XML nodes.""" -- cgit From e9d712c52830725b24f20da7ff8662e97d22014d Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 7 Jul 2011 14:51:12 -0400 Subject: Removed bookmark link from non detailed image viewbuilder --- nova/api/openstack/views/images.py | 13 ++++++------- nova/tests/api/openstack/test_images.py | 4 ---- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py index 005341c62..fc4c1b55e 100644 --- a/nova/api/openstack/views/images.py +++ b/nova/api/openstack/views/images.py @@ -108,18 +108,17 @@ class ViewBuilderV11(ViewBuilder): href = self.generate_href(image_obj["id"]) bookmark = self.generate_bookmark(image_obj["id"]) - if detail: - image["metadata"] = image_obj.get("properties", {}) - image["links"] = [{ "rel": "self", "href": href, - }, - { - "rel": "bookmark", - "href": bookmark, }] + if detail: + image["metadata"] = image_obj.get("properties", {}) + image["links"].append({"rel": "bookmark", + "href": bookmark, + }) + return image def generate_bookmark(self, image_id): diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index cf68f5f53..d45195286 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -559,10 +559,6 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): "links": [{ "rel": "self", "href": href, - }, - { - "rel": "bookmark", - "href": bookmark, }], } self.assertTrue(test_image in response_list) -- cgit From 1940ccffb6c22c39d6c21be4e84f20e350599f71 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 7 Jul 2011 16:19:21 -0400 Subject: Removed serverRef from some tests and viewbuilder --- nova/api/openstack/views/images.py | 4 +++- nova/tests/api/openstack/test_images.py | 33 ++------------------------------- 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py index fc4c1b55e..ae8e73678 100644 --- a/nova/api/openstack/views/images.py +++ b/nova/api/openstack/views/images.py @@ -98,7 +98,9 @@ class ViewBuilderV11(ViewBuilder): def _build_server(self, image, image_obj): try: - image['serverRef'] = image_obj['properties']['instance_ref'] + serverRef = image_obj['properties']['instance_ref'] + #TODO (ameade) get the server information + #image['server'] = ? except KeyError: return diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index d45195286..7e2240830 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -401,12 +401,13 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): href = "http://localhost/v1.1/images/124" bookmark = "http://localhost/images/124" + server_href = "http://localhost/v1.1/servers/42" + server_bookmark = "http://localhost/servers/42" expected_image = { "image": { "id": 124, "name": "queued snapshot", - "serverRef": "http://localhost/v1.1/servers/42", "updated": self.NOW_API_FORMAT, "created": self.NOW_API_FORMAT, "status": "QUEUED", @@ -648,7 +649,6 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): u'instance_ref': u'http://localhost/v1.1/servers/42', u'user_id': u'1', }, - 'serverRef': "http://localhost/v1.1/servers/42", 'updated': self.NOW_API_FORMAT, 'created': self.NOW_API_FORMAT, 'status': 'QUEUED', @@ -668,7 +668,6 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): u'instance_ref': u'http://localhost/v1.1/servers/42', u'user_id': u'1', }, - 'serverRef': "http://localhost/v1.1/servers/42", 'updated': self.NOW_API_FORMAT, 'created': self.NOW_API_FORMAT, 'status': 'SAVING', @@ -689,7 +688,6 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): u'instance_ref': u'http://localhost/v1.1/servers/42', u'user_id': u'1', }, - 'serverRef': "http://localhost/v1.1/servers/42", 'updated': self.NOW_API_FORMAT, 'created': self.NOW_API_FORMAT, 'status': 'ACTIVE', @@ -709,7 +707,6 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): u'instance_ref': u'http://localhost/v1.1/servers/42', u'user_id': u'1', }, - 'serverRef': "http://localhost/v1.1/servers/42", 'updated': self.NOW_API_FORMAT, 'created': self.NOW_API_FORMAT, 'status': 'FAILED', @@ -1029,30 +1026,6 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): response = req.get_response(fakes.wsgi_app()) self.assertEqual(200, response.status_int) - def test_create_image_v1_1_actual_server_ref(self): - - serverRef = 'http://localhost/v1.1/servers/1' - body = dict(image=dict(serverRef=serverRef, name='Backup 1')) - req = webob.Request.blank('/v1.1/images') - req.method = 'POST' - req.body = json.dumps(body) - req.headers["content-type"] = "application/json" - response = req.get_response(fakes.wsgi_app()) - self.assertEqual(200, response.status_int) - result = json.loads(response.body) - self.assertEqual(result['image']['serverRef'], serverRef) - - def test_create_image_v1_1_server_ref_bad_hostname(self): - - serverRef = 'http://asdf/v1.1/servers/1' - body = dict(image=dict(serverRef=serverRef, name='Backup 1')) - req = webob.Request.blank('/v1.1/images') - req.method = 'POST' - req.body = json.dumps(body) - req.headers["content-type"] = "application/json" - response = req.get_response(fakes.wsgi_app()) - self.assertEqual(400, response.status_int) - def test_create_image_v1_1_no_server_ref(self): body = dict(image=dict(name='Snapshot 1')) @@ -1441,8 +1414,6 @@ class ImageXMLSerializationTest(test.TestCase): output = serializer.serialize(fixtures, 'index') actual = minidom.parseString(output.replace(" ", "")) - expected_serverRef = self.SERVER_HREF - expected_now = self.TIMESTAMP expected = minidom.parseString(""" Date: Thu, 7 Jul 2011 16:29:17 -0400 Subject: Temporarily moved create server node functionality into images.py Temporarily changed image XML tests to expect server entities with only ids --- nova/api/openstack/images.py | 7 +++++-- nova/api/openstack/servers.py | 12 ------------ nova/tests/api/openstack/test_images.py | 25 +++++-------------------- 3 files changed, 10 insertions(+), 34 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 8f75fae4c..a6af6da6f 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -269,7 +269,6 @@ class ImageXMLSerializer(wsgi.XMLDictSerializer): def __init__(self): self.metadata_serializer = image_metadata.ImageMetadataXMLSerializer() - self.server_serializer = servers.ServerXMLSerializer() def _image_to_xml(self, xml_doc, image): image_node = xml_doc.createElement('image') @@ -308,7 +307,11 @@ class ImageXMLSerializer(wsgi.XMLDictSerializer): return self.metadata_serializer.meta_list_to_xml(xml_doc, metadata) def _create_server_node(self, xml_doc, server): - return self.server_serializer.server_to_xml(xml_doc, server) + server_node = xml_doc.createElement('server') + server_node.setAttribute('id', str(server['id'])) + #server_node.setAttribute('name', server['name']) + #self._create_link_nodes(xml_doc, server_node, server['links']) + return server_node def _image_list_to_xml(self, xml_doc, images, detailed): container_node = xml_doc.createElement('images') diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index cff4e9b82..fc1ab8d46 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -627,15 +627,3 @@ def create_resource(version='1.0'): return wsgi.Resource(controller, serializers=serializers, deserializers=deserializers) - - -class ServerXMLSerializer(wsgi.XMLDictSerializer): - def __init__(self, xmlns=wsgi.XMLNS_V11): - super(ServerXMLSerializer, self).__init__(xmlns=xmlns) - - def server_to_xml(self, xml_doc, server): - server_node = xml_doc.createElement('server') - server_node.setAttribute('id', str(server['id'])) - server_node.setAttribute('name', server['name']) - self._create_link_nodes(xml_doc, server_node, server['links']) - return server_node diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index 7e2240830..d407057a8 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -1148,10 +1148,7 @@ class ImageXMLSerializationTest(test.TestCase): created="%(expected_now)s" status="ACTIVE" progress="80"> - - - - + value1 @@ -1219,10 +1216,7 @@ class ImageXMLSerializationTest(test.TestCase): updated="%(expected_now)s" created="%(expected_now)s" status="ACTIVE"> - - - - + @@ -1284,10 +1278,7 @@ class ImageXMLSerializationTest(test.TestCase): updated="%(expected_now)s" created="%(expected_now)s" status="ACTIVE"> - - - - + @@ -1503,10 +1494,7 @@ class ImageXMLSerializationTest(test.TestCase): updated="%(expected_now)s" created="%(expected_now)s" status="ACTIVE"> - - - - + @@ -1589,10 +1577,7 @@ class ImageXMLSerializationTest(test.TestCase): created="%(expected_now)s" status="SAVING" progress="80"> - - - - + value1 -- cgit From 7c90561e7288967c364a874cde13d88a8cb8fab4 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 7 Jul 2011 16:32:17 -0400 Subject: Changed name of xml_string to to_xml_string --- nova/api/openstack/images.py | 8 ++++---- nova/api/openstack/wsgi.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index a6af6da6f..e5496ed94 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -330,26 +330,26 @@ class ImageXMLSerializer(wsgi.XMLDictSerializer): node = self._image_list_to_xml(xml_doc, images_dict['images'], detailed=False) - return self.xml_string(node, True) + return self.to_xml_string(node, True) def detail(self, images_dict): xml_doc = minidom.Document() node = self._image_list_to_xml(xml_doc, images_dict['images'], detailed=True) - return self.xml_string(node, True) + return self.to_xml_string(node, True) def show(self, image_dict): xml_doc = minidom.Document() node = self._image_to_xml_detailed(xml_doc, image_dict['image']) - return self.xml_string(node, True) + return self.to_xml_string(node, True) def create(self, image_dict): xml_doc = minidom.Document() node = self._image_to_xml_detailed(xml_doc, image_dict['image']) - return self.xml_string(node, True) + return self.to_xml_string(node, True) def create_resource(version='1.0'): diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index 4ac7b56c9..f13bd6cc1 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -232,9 +232,9 @@ class XMLDictSerializer(DictSerializer): doc = minidom.Document() node = self._to_xml_node(doc, self.metadata, root_key, data[root_key]) - return self.xml_string(node) + return self.to_xml_string(node) - def xml_string(self, node, has_atom=False): + def to_xml_string(self, node, has_atom=False): self._add_xmlns(node, has_atom) return node.toprettyxml(indent=' ', encoding='UTF-8') -- cgit From d4540d2abde8db9519d8e4dad9b57a116a2c8b9e Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 7 Jul 2011 16:41:22 -0400 Subject: Updated _create_link_nodes to be consistent with other create_*_nodes --- nova/api/openstack/images.py | 15 ++++++++++++--- nova/api/openstack/wsgi.py | 6 ++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index e5496ed94..bf98a5cdd 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -274,7 +274,10 @@ class ImageXMLSerializer(wsgi.XMLDictSerializer): image_node = xml_doc.createElement('image') image_node.setAttribute('id', str(image['id'])) image_node.setAttribute('name', image['name']) - self._create_link_nodes(xml_doc, image_node, image['links']) + link_nodes = self._create_link_nodes(xml_doc, + image['links']) + for link_node in link_nodes: + image_node.appendChild(link_node) return image_node def _image_to_xml_detailed(self, xml_doc, image): @@ -290,7 +293,10 @@ class ImageXMLSerializer(wsgi.XMLDictSerializer): metadata_node = self._create_metadata_node(xml_doc, metadata) image_node.appendChild(metadata_node) - self._create_link_nodes(xml_doc, image_node, image['links']) + link_nodes = self._create_link_nodes(xml_doc, + image['links']) + for link_node in link_nodes: + image_node.appendChild(link_node) return image_node @@ -310,7 +316,10 @@ class ImageXMLSerializer(wsgi.XMLDictSerializer): server_node = xml_doc.createElement('server') server_node.setAttribute('id', str(server['id'])) #server_node.setAttribute('name', server['name']) - #self._create_link_nodes(xml_doc, server_node, server['links']) + #link_nodes = self._create_link_nodes(xml_doc, + # image['links']) + #for link_node in link_nodes: + # server_node.appendChild(link_node) return server_node def _image_list_to_xml(self, xml_doc, images, detailed): diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index f13bd6cc1..03f83001a 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -300,12 +300,14 @@ class XMLDictSerializer(DictSerializer): result.appendChild(node) return result - def _create_link_nodes(self, xml_doc, node, links): + def _create_link_nodes(self, xml_doc, links): + link_nodes = [] for link in links: link_node = xml_doc.createElement('atom:link') link_node.setAttribute('rel', link['rel']) link_node.setAttribute('href', link['href']) - node.appendChild(link_node) + link_nodes.append(link_node) + return link_nodes class ResponseSerializer(object): -- cgit From a8c9082c701a65f221f218cd8baa92b3859fc0ab Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 7 Jul 2011 16:52:32 -0400 Subject: Added server entity to images that only has id --- nova/api/openstack/views/images.py | 5 +++-- nova/tests/api/openstack/test_images.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py index ae8e73678..d1f89a785 100644 --- a/nova/api/openstack/views/images.py +++ b/nova/api/openstack/views/images.py @@ -99,8 +99,9 @@ class ViewBuilderV11(ViewBuilder): def _build_server(self, image, image_obj): try: serverRef = image_obj['properties']['instance_ref'] - #TODO (ameade) get the server information - #image['server'] = ? + image['server'] = { + "id": common.get_id_from_href(serverRef), + } except KeyError: return diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index d407057a8..87e5c6d7f 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -411,6 +411,9 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): "updated": self.NOW_API_FORMAT, "created": self.NOW_API_FORMAT, "status": "QUEUED", + 'server': { + 'id': 42, + }, "metadata": { "instance_ref": "http://localhost/v1.1/servers/42", "user_id": "1", @@ -652,6 +655,9 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): 'updated': self.NOW_API_FORMAT, 'created': self.NOW_API_FORMAT, 'status': 'QUEUED', + 'server': { + 'id': 42, + }, "links": [{ "rel": "self", "href": "http://localhost/v1.1/images/124", @@ -672,6 +678,9 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): 'created': self.NOW_API_FORMAT, 'status': 'SAVING', 'progress': 0, + 'server': { + 'id': 42, + }, "links": [{ "rel": "self", "href": "http://localhost/v1.1/images/125", @@ -691,6 +700,9 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): 'updated': self.NOW_API_FORMAT, 'created': self.NOW_API_FORMAT, 'status': 'ACTIVE', + 'server': { + 'id': 42, + }, "links": [{ "rel": "self", "href": "http://localhost/v1.1/images/126", @@ -710,6 +722,9 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): 'updated': self.NOW_API_FORMAT, 'created': self.NOW_API_FORMAT, 'status': 'FAILED', + 'server': { + 'id': 42, + }, "links": [{ "rel": "self", "href": "http://localhost/v1.1/images/127", -- cgit From 495137fb383766ae5345fd8b30610a93483c0eaf Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Tue, 12 Jul 2011 12:01:13 -0400 Subject: Updated remove_version_from_href to be more intelligent Added tests --- nova/api/openstack/common.py | 14 ++++++++++-- nova/tests/api/openstack/test_common.py | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 9aa384f33..83854b13f 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -136,11 +136,21 @@ def get_id_from_href(href): raise webob.exc.HTTPBadRequest(_('could not parse id from href')) -def remove_version_from_href(base_url): +def remove_version_from_href(href): """Removes the api version from the href. Given: 'http://www.nova.com/v1.1/123' Returns: 'http://www.nova.com/123' """ - return base_url.rsplit('/', 1).pop(0) + try: + #matches /v#.# + new_href = re.sub(r'[/][v][0-9]*.[0-9]*', '', href) + if new_href == href: + msg = _('href does not contain version') + raise webob.exc.HTTPBadRequest(explanation=msg) + return new_href + except: + LOG.debug(_("Error removing version from href: %s") % href) + msg = _('could not parse version from href') + raise webob.exc.HTTPBadRequest(explanation=msg) diff --git a/nova/tests/api/openstack/test_common.py b/nova/tests/api/openstack/test_common.py index 29cb8b944..584953c3a 100644 --- a/nova/tests/api/openstack/test_common.py +++ b/nova/tests/api/openstack/test_common.py @@ -190,3 +190,42 @@ class PaginationParamsTest(test.TestCase): req = Request.blank('/?limit=20&marker=40') self.assertEqual(common.get_pagination_params(req), {'marker': 40, 'limit': 20}) + + +class MiscFunctionsTest(test.TestCase): + + def test_remove_version_from_href(self): + + fixture = 'http://www.testsite.com/v1.1/images' + expected = 'http://www.testsite.com/images' + actual = common.remove_version_from_href(fixture) + self.assertEqual(actual, expected) + + def test_remove_version_from_href_2(self): + + fixture = 'http://www.testsite.com/v1.1/' + expected = 'http://www.testsite.com/' + actual = common.remove_version_from_href(fixture) + self.assertEqual(actual, expected) + + def test_remove_version_from_href_bad_request(self): + + fixture = 'http://www.testsite.com/1.1/images' + self.assertRaises(webob.exc.HTTPBadRequest, + common.remove_version_from_href, + fixture) + + def test_get_id_from_href(self): + + fixture = 'http://www.testsite.com/dir/45' + actual = common.get_id_from_href(fixture) + expected = 45 + self.assertEqual(actual, expected) + + def test_get_id_from_href_bad_request(self): + + fixture = 'http://45' + self.assertRaises(webob.exc.HTTPBadRequest, + common.get_id_from_href, + fixture) + -- cgit From 50357685282b9200ccc8c82361c5266f1f413531 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Tue, 12 Jul 2011 12:11:49 -0400 Subject: pep8 --- nova/tests/api/openstack/test_common.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/nova/tests/api/openstack/test_common.py b/nova/tests/api/openstack/test_common.py index 584953c3a..1143fb502 100644 --- a/nova/tests/api/openstack/test_common.py +++ b/nova/tests/api/openstack/test_common.py @@ -195,37 +195,31 @@ class PaginationParamsTest(test.TestCase): class MiscFunctionsTest(test.TestCase): def test_remove_version_from_href(self): - fixture = 'http://www.testsite.com/v1.1/images' expected = 'http://www.testsite.com/images' actual = common.remove_version_from_href(fixture) self.assertEqual(actual, expected) def test_remove_version_from_href_2(self): - fixture = 'http://www.testsite.com/v1.1/' expected = 'http://www.testsite.com/' actual = common.remove_version_from_href(fixture) self.assertEqual(actual, expected) def test_remove_version_from_href_bad_request(self): - fixture = 'http://www.testsite.com/1.1/images' self.assertRaises(webob.exc.HTTPBadRequest, common.remove_version_from_href, fixture) def test_get_id_from_href(self): - fixture = 'http://www.testsite.com/dir/45' actual = common.get_id_from_href(fixture) expected = 45 self.assertEqual(actual, expected) def test_get_id_from_href_bad_request(self): - fixture = 'http://45' self.assertRaises(webob.exc.HTTPBadRequest, common.get_id_from_href, fixture) - -- cgit From 5ab2fd27ea930669c01f309dbbfb794fd7c37ad6 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Tue, 12 Jul 2011 12:42:56 -0400 Subject: updated images tests --- nova/tests/api/openstack/test_images.py | 74 ++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index 306c0b1db..696493d4f 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -413,6 +413,14 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): "status": "QUEUED", 'server': { 'id': 42, + "links": [{ + "rel": "self", + "href": server_href, + }, + { + "rel": "bookmark", + "href": server_bookmark, + }], }, "metadata": { "instance_ref": "http://localhost/v1.1/servers/42", @@ -628,6 +636,8 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): response_dict = json.loads(response.body) response_list = response_dict["images"] + server_href = "http://localhost/v1.1/servers/42" + server_bookmark = "http://localhost/servers/42" expected = [{ 'id': 123, @@ -657,6 +667,14 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): 'status': 'QUEUED', 'server': { 'id': 42, + "links": [{ + "rel": "self", + "href": server_href, + }, + { + "rel": "bookmark", + "href": server_bookmark, + }], }, "links": [{ "rel": "self", @@ -680,6 +698,14 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): 'progress': 0, 'server': { 'id': 42, + "links": [{ + "rel": "self", + "href": server_href, + }, + { + "rel": "bookmark", + "href": server_bookmark, + }], }, "links": [{ "rel": "self", @@ -702,6 +728,14 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): 'status': 'ACTIVE', 'server': { 'id': 42, + "links": [{ + "rel": "self", + "href": server_href, + }, + { + "rel": "bookmark", + "href": server_bookmark, + }], }, "links": [{ "rel": "self", @@ -724,6 +758,14 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): 'status': 'FAILED', 'server': { 'id': 42, + "links": [{ + "rel": "self", + "href": server_href, + }, + { + "rel": "bookmark", + "href": server_bookmark, + }], }, "links": [{ "rel": "self", @@ -1044,6 +1086,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): def test_create_image_v1_1_actual_server_ref(self): serverRef = 'http://localhost/v1.1/servers/1' + serverBookmark = 'http://localhost/servers/1' body = dict(image=dict(serverRef=serverRef, name='Backup 1')) req = webob.Request.blank('/v1.1/images') req.method = 'POST' @@ -1052,11 +1095,25 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): response = req.get_response(fakes.wsgi_app()) self.assertEqual(200, response.status_int) result = json.loads(response.body) - self.assertEqual(result['image']['serverRef'], serverRef) + expected = { + 'id': '1', + 'links': [ + { + 'rel': 'self', + 'href': serverRef, + }, + { + 'rel': 'bookmark', + 'href': serverBookmark, + }, + ] + } + self.assertEqual(result['image']['server'], expected) def test_create_image_v1_1_actual_server_ref_port(self): serverRef = 'http://localhost:8774/v1.1/servers/1' + serverBookmark = 'http://localhost:8774/servers/1' body = dict(image=dict(serverRef=serverRef, name='Backup 1')) req = webob.Request.blank('/v1.1/images') req.method = 'POST' @@ -1065,7 +1122,20 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): response = req.get_response(fakes.wsgi_app()) self.assertEqual(200, response.status_int) result = json.loads(response.body) - self.assertEqual(result['image']['serverRef'], serverRef) + expected = { + 'id': '1', + 'links': [ + { + 'rel': 'self', + 'href': serverRef, + }, + { + 'rel': 'bookmark', + 'href': serverBookmark, + }, + ] + } + self.assertEqual(result['image']['server'], expected) def test_create_image_v1_1_server_ref_bad_hostname(self): -- cgit From 3c8de7e99e7cd8868f63fb0d15845b2462b77b3e Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Tue, 12 Jul 2011 12:46:15 -0400 Subject: Updated images viewbuilder to return links in server entity --- nova/api/openstack/views/images.py | 10 ++++++++++ nova/tests/api/openstack/test_images.py | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py index d1f89a785..5c0510377 100644 --- a/nova/api/openstack/views/images.py +++ b/nova/api/openstack/views/images.py @@ -101,6 +101,16 @@ class ViewBuilderV11(ViewBuilder): serverRef = image_obj['properties']['instance_ref'] image['server'] = { "id": common.get_id_from_href(serverRef), + "links": [ + { + "rel": "self", + "href": serverRef, + }, + { + "rel": "bookmark", + "href": common.remove_version_from_href(serverRef), + }, + ] } except KeyError: return diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index 696493d4f..c1ead6e28 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -1096,7 +1096,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): self.assertEqual(200, response.status_int) result = json.loads(response.body) expected = { - 'id': '1', + 'id': 1, 'links': [ { 'rel': 'self', @@ -1123,7 +1123,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): self.assertEqual(200, response.status_int) result = json.loads(response.body) expected = { - 'id': '1', + 'id': 1, 'links': [ { 'rel': 'self', -- cgit From f4dc32ad0729b40ebe5765a57edff9535b992953 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Tue, 12 Jul 2011 12:55:37 -0400 Subject: Updated ImageXMLSerializer to serialize links in the server entity --- nova/api/openstack/images.py | 9 ++++----- nova/tests/api/openstack/test_images.py | 30 ++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 873e025c7..d0317583e 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -325,11 +325,10 @@ class ImageXMLSerializer(wsgi.XMLDictSerializer): def _create_server_node(self, xml_doc, server): server_node = xml_doc.createElement('server') server_node.setAttribute('id', str(server['id'])) - #server_node.setAttribute('name', server['name']) - #link_nodes = self._create_link_nodes(xml_doc, - # image['links']) - #for link_node in link_nodes: - # server_node.appendChild(link_node) + link_nodes = self._create_link_nodes(xml_doc, + server['links']) + for link_node in link_nodes: + server_node.appendChild(link_node) return server_node def _image_list_to_xml(self, xml_doc, images, detailed): diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index c1ead6e28..f0d7be2b9 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -1225,7 +1225,6 @@ class ImageXMLSerializationTest(test.TestCase): 'progress': 80, 'server': { 'id': 1, - 'name': 'Server1', 'links': [ { 'href': self.SERVER_HREF, @@ -1270,7 +1269,10 @@ class ImageXMLSerializationTest(test.TestCase): created="%(expected_now)s" status="ACTIVE" progress="80"> - + + + + value1 @@ -1296,7 +1298,6 @@ class ImageXMLSerializationTest(test.TestCase): 'status': 'ACTIVE', 'server': { 'id': 1, - 'name': 'Server1', 'links': [ { 'href': self.SERVER_HREF, @@ -1338,7 +1339,10 @@ class ImageXMLSerializationTest(test.TestCase): updated="%(expected_now)s" created="%(expected_now)s" status="ACTIVE"> - + + + + @@ -1359,7 +1363,6 @@ class ImageXMLSerializationTest(test.TestCase): 'status': 'ACTIVE', 'server': { 'id': 1, - 'name': 'Server1', 'links': [ { 'href': self.SERVER_HREF, @@ -1400,7 +1403,10 @@ class ImageXMLSerializationTest(test.TestCase): updated="%(expected_now)s" created="%(expected_now)s" status="ACTIVE"> - + + + + @@ -1550,7 +1556,6 @@ class ImageXMLSerializationTest(test.TestCase): 'status': 'ACTIVE', 'server': { 'id': 1, - 'name': 'Server1', 'links': [ { 'href': self.SERVER_HREF, @@ -1616,7 +1621,10 @@ class ImageXMLSerializationTest(test.TestCase): updated="%(expected_now)s" created="%(expected_now)s" status="ACTIVE"> - + + + + @@ -1654,7 +1662,6 @@ class ImageXMLSerializationTest(test.TestCase): 'progress': 80, 'server': { 'id': 1, - 'name': 'Server1', 'links': [ { 'href': self.SERVER_HREF, @@ -1699,7 +1706,10 @@ class ImageXMLSerializationTest(test.TestCase): created="%(expected_now)s" status="SAVING" progress="80"> - + + + + value1 -- cgit From 7a700362d63de1da51e9a890d854c3b0eeb97aae Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Tue, 12 Jul 2011 13:29:26 -0400 Subject: minor cleanup --- nova/api/openstack/wsgi.py | 4 +++- nova/tests/api/openstack/test_images.py | 12 ------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index 4e4ce4121..c3f841aa5 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -277,7 +277,9 @@ class XMLDictSerializer(DictSerializer): return node.toprettyxml(indent=' ', encoding='UTF-8') #NOTE (ameade): the has_atom should be removed after all of the - # xml serializers and view builders have been updated + # xml serializers and view builders have been updated to the current + # spec that required all responses include the xmlns:atom, the has_atom + # flag is to prevent current tests from breaking def _add_xmlns(self, node, has_atom=False): if self.xmlns is not None: node.setAttribute('xmlns', self.xmlns) diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index f0d7be2b9..716b73f6c 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -1213,8 +1213,6 @@ class ImageXMLSerializationTest(test.TestCase): def test_show(self): serializer = images.ImageXMLSerializer() - #so we can see the full diff in the output - self.maxDiff = None fixture = { 'image': { 'id': 1, @@ -1288,7 +1286,6 @@ class ImageXMLSerializationTest(test.TestCase): def test_show_zero_metadata(self): serializer = images.ImageXMLSerializer() - self.maxDiff = None fixture = { 'image': { 'id': 1, @@ -1353,7 +1350,6 @@ class ImageXMLSerializationTest(test.TestCase): def test_show_image_no_metadata_key(self): serializer = images.ImageXMLSerializer() - self.maxDiff = None fixture = { 'image': { 'id': 1, @@ -1417,8 +1413,6 @@ class ImageXMLSerializationTest(test.TestCase): def test_show_no_server(self): serializer = images.ImageXMLSerializer() - #so we can see the full diff in the output - self.maxDiff = None fixture = { 'image': { 'id': 1, @@ -1471,8 +1465,6 @@ class ImageXMLSerializationTest(test.TestCase): def test_index(self): serializer = images.ImageXMLSerializer() - #so we can see the full diff in the output - self.maxDiff = None fixture = { 'images': [ { @@ -1544,8 +1536,6 @@ class ImageXMLSerializationTest(test.TestCase): def test_detail(self): serializer = images.ImageXMLSerializer() - #so we can see the full diff in the output - self.maxDiff = None fixture = { 'images': [ { @@ -1650,8 +1640,6 @@ class ImageXMLSerializationTest(test.TestCase): def test_create(self): serializer = images.ImageXMLSerializer() - #so we can see the full diff in the output - self.maxDiff = None fixture = { 'image': { 'id': 1, -- cgit From 915c7d52fa1b2afe6af9686210982d5bc043be97 Mon Sep 17 00:00:00 2001 From: Mike Scherbakov Date: Tue, 12 Jul 2011 11:07:30 -0700 Subject: Renamed 'nova-manage server list' -> 'nova-manage host list' to differentiate physical hosts from VMs --- bin/nova-manage | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index 8ba78a56a..94ab22092 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -816,11 +816,11 @@ class ServiceCommands(object): {"method": "update_available_resource"}) -class ServerCommands(object): - """List servers""" +class HostCommands(object): + """List hosts""" def list(self, zone=None): - """Show a list of all servers. Filter by zone. + """Show a list of all physical hosts. Filter by zone. args: [zone]""" print "%-25s\t%-15s" % (_('host'), _('zone')) @@ -829,13 +829,13 @@ class ServerCommands(object): services = db.service_get_all(ctxt) if zone: services = [s for s in services if s['availability_zone'] == zone] - servers = [] + hosts = [] for srv in services: - if not [s for s in servers if s['host'] == srv['host']]: - servers.append(srv) + if not [h for h in hosts if h['host'] == srv['host']]: + hosts.append(srv) - for srv in servers: - print "%-25s\t%-15s" % (srv['host'], srv['availability_zone']) + for h in hosts: + print "%-25s\t%-15s" % (h['host'], h['availability_zone']) class DbCommands(object): @@ -1211,13 +1211,13 @@ CATEGORIES = [ ('fixed', FixedIpCommands), ('flavor', InstanceTypeCommands), ('floating', FloatingIpCommands), + ('host', HostCommands), ('instance_type', InstanceTypeCommands), ('image', ImageCommands), ('network', NetworkCommands), ('project', ProjectCommands), ('role', RoleCommands), ('service', ServiceCommands), - ('server', ServerCommands), ('shell', ShellCommands), ('user', UserCommands), ('version', VersionCommands), -- cgit From c085294ccb6a8d449ccfd5739be67ee12538f48f Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Tue, 12 Jul 2011 14:19:30 -0400 Subject: Updated some common.py functions to raise ValueErrors instead of HTTPBadRequests --- nova/api/openstack/common.py | 13 +++++++------ nova/tests/api/openstack/test_common.py | 4 ++-- nova/tests/api/openstack/test_images.py | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 83854b13f..79969d393 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -133,7 +133,7 @@ def get_id_from_href(href): return int(urlparse(href).path.split('/')[-1]) except: LOG.debug(_("Error extracting id from href: %s") % href) - raise webob.exc.HTTPBadRequest(_('could not parse id from href')) + raise ValueError(_('could not parse id from href')) def remove_version_from_href(href): @@ -146,11 +146,12 @@ def remove_version_from_href(href): try: #matches /v#.# new_href = re.sub(r'[/][v][0-9]*.[0-9]*', '', href) - if new_href == href: - msg = _('href does not contain version') - raise webob.exc.HTTPBadRequest(explanation=msg) - return new_href except: LOG.debug(_("Error removing version from href: %s") % href) msg = _('could not parse version from href') - raise webob.exc.HTTPBadRequest(explanation=msg) + raise ValueError(msg) + + if new_href == href: + msg = _('href does not contain version') + raise ValueError(msg) + return new_href diff --git a/nova/tests/api/openstack/test_common.py b/nova/tests/api/openstack/test_common.py index 1143fb502..7440bccfb 100644 --- a/nova/tests/api/openstack/test_common.py +++ b/nova/tests/api/openstack/test_common.py @@ -208,7 +208,7 @@ class MiscFunctionsTest(test.TestCase): def test_remove_version_from_href_bad_request(self): fixture = 'http://www.testsite.com/1.1/images' - self.assertRaises(webob.exc.HTTPBadRequest, + self.assertRaises(ValueError, common.remove_version_from_href, fixture) @@ -220,6 +220,6 @@ class MiscFunctionsTest(test.TestCase): def test_get_id_from_href_bad_request(self): fixture = 'http://45' - self.assertRaises(webob.exc.HTTPBadRequest, + self.assertRaises(ValueError, common.get_id_from_href, fixture) diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index 716b73f6c..c1bdd6906 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -1158,6 +1158,28 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): response = req.get_response(fakes.wsgi_app()) self.assertEqual(400, response.status_int) + def test_create_image_v1_1_server_ref_missing_version(self): + + serverRef = 'http://localhost/servers/1' + body = dict(image=dict(serverRef=serverRef, name='Backup 1')) + req = webob.Request.blank('/v1.1/images') + req.method = 'POST' + req.body = json.dumps(body) + req.headers["content-type"] = "application/json" + response = req.get_response(fakes.wsgi_app()) + self.assertEqual(400, response.status_int) + + def test_create_image_v1_1_server_ref_missing_id(self): + + serverRef = 'http://localhost/v1.1/servers' + body = dict(image=dict(serverRef=serverRef, name='Backup 1')) + req = webob.Request.blank('/v1.1/images') + req.method = 'POST' + req.body = json.dumps(body) + req.headers["content-type"] = "application/json" + response = req.get_response(fakes.wsgi_app()) + self.assertEqual(400, response.status_int) + @classmethod def _make_image_fixtures(cls): image_id = 123 -- cgit From 952196a533c3577945a2c4245436d09eb75e0eb6 Mon Sep 17 00:00:00 2001 From: Mohammed Naser Date: Tue, 12 Jul 2011 19:12:21 -0400 Subject: Made sure the network manager accepts kwargs for FlatManager --- nova/network/manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/network/manager.py b/nova/network/manager.py index 21d151033..383fbd32f 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -696,7 +696,7 @@ class FlatManager(NetworkManager): timeout_fixed_ips = False - def _allocate_fixed_ips(self, context, instance_id, networks): + def _allocate_fixed_ips(self, context, instance_id, networks, **kwargs): """Calls allocate_fixed_ip once for each network.""" for network in networks: self.allocate_fixed_ip(context, instance_id, network) -- cgit From 7acb3d63cd2c487c78994e15f1e015d3b81febf8 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Tue, 12 Jul 2011 21:50:12 -0400 Subject: Don't pop 'vpn' on kwargs inside a loop in RPCAllocateFixedIP._allocate_fixed_ips (fixes KeyError's). Fix allocate_fixed_ip method signature for FlatDHCP. --- nova/network/manager.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nova/network/manager.py b/nova/network/manager.py index 383fbd32f..007766998 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -128,6 +128,7 @@ class RPCAllocateFixedIP(object): """Calls allocate_fixed_ip once for each network.""" green_pool = greenpool.GreenPool() + vpn = kwargs.pop('vpn') for network in networks: if network['host'] != self.host: # need to call allocate_fixed_ip to correct network host @@ -136,15 +137,14 @@ class RPCAllocateFixedIP(object): args = {} args['instance_id'] = instance_id args['network_id'] = network['id'] - args['vpn'] = kwargs.pop('vpn') + args['vpn'] = vpn green_pool.spawn_n(rpc.call, context, topic, {'method': '_rpc_allocate_fixed_ip', 'args': args}) else: # i am the correct host, run here - self.allocate_fixed_ip(context, instance_id, network, - vpn=kwargs.pop('vpn')) + self.allocate_fixed_ip(context, instance_id, network, vpn=vpn) # wait for all of the allocates (if any) to finish green_pool.waitall() @@ -753,7 +753,7 @@ class FlatDHCPManager(FloatingIP, RPCAllocateFixedIP, NetworkManager): self.driver.ensure_bridge(network['bridge'], network['bridge_interface']) - def allocate_fixed_ip(self, context, instance_id, network): + def allocate_fixed_ip(self, context, instance_id, network, **kwargs): """Allocate flat_network fixed_ip, then setup dhcp for this network.""" address = super(FlatDHCPManager, self).allocate_fixed_ip(context, instance_id, -- cgit From f794139e6ad70949bdaf26417989f3940e8af3b7 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Wed, 13 Jul 2011 08:34:41 -0400 Subject: Added Mohammed Naser to Authors file. --- Authors | 1 + 1 file changed, 1 insertion(+) diff --git a/Authors b/Authors index 4aa65eea2..2e50cfbe0 100644 --- a/Authors +++ b/Authors @@ -65,6 +65,7 @@ Masanori Itoh Matt Dietz Michael Gundlach Mike Scherbakov +Mohammed Naser Monsyne Dragon Monty Taylor MORITA Kazutaka -- cgit From b9ea0f43c186d5fbc232b0ddd11c3e64898136ab Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Wed, 13 Jul 2011 17:16:27 -0400 Subject: support '-' to indicate stdout in nova-manage project 'environment' and 'zip' This just adds support to do: nova-manage project zip test-project admin - > out.zip nova-manage project environment test-project admin - | grep NOVA_URL --- bin/nova-manage | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index 7dfe91698..b5247f8c3 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -414,8 +414,11 @@ class ProjectCommands(object): except (exception.UserNotFound, exception.ProjectNotFound) as ex: print ex raise - with open(filename, 'w') as f: - f.write(rc) + if filename == "-": + f = sys.stdout + else: + f = open(filename, 'w') + f.write(rc) def list(self, username=None): """Lists all projects @@ -465,8 +468,11 @@ class ProjectCommands(object): arguments: project_id user_id [filename='nova.zip]""" try: zip_file = self.manager.get_credentials(user_id, project_id) - with open(filename, 'w') as f: - f.write(zip_file) + if filename == "-": + f = sys.stdout + else: + f = open(filename, 'w') + f.write(zip_file) except (exception.UserNotFound, exception.ProjectNotFound) as ex: print ex raise -- cgit From 7ed74cb999483e589e186944cb9116f507dbe60d Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Wed, 13 Jul 2011 22:01:52 -0400 Subject: use 'with' so that close is called on file handle --- bin/nova-manage | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/nova-manage b/bin/nova-manage index b5247f8c3..a83fe70f8 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -415,10 +415,10 @@ class ProjectCommands(object): print ex raise if filename == "-": - f = sys.stdout + sys.stdout.write(rc) else: - f = open(filename, 'w') - f.write(rc) + with open(filename, 'w') as f: + f.write(rc) def list(self, username=None): """Lists all projects @@ -469,10 +469,10 @@ class ProjectCommands(object): try: zip_file = self.manager.get_credentials(user_id, project_id) if filename == "-": - f = sys.stdout + sys.stdout.write(zip_file) else: - f = open(filename, 'w') - f.write(zip_file) + with open(filename, 'w') as f: + f.write(zip_file) except (exception.UserNotFound, exception.ProjectNotFound) as ex: print ex raise -- cgit From ee143766a32486664d47aee11f792854cbedd4ff Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 14 Jul 2011 07:08:02 -0400 Subject: add self to authors --- Authors | 1 + 1 file changed, 1 insertion(+) diff --git a/Authors b/Authors index 2e50cfbe0..a366cec87 100644 --- a/Authors +++ b/Authors @@ -85,6 +85,7 @@ Ryan Lucio Salvatore Orlando Sandy Walsh Sateesh Chodapuneedi +Scott Moser Soren Hansen Thierry Carrez Todd Willey -- cgit From 7d3859833d0647cad15c614e816df9440bb99d44 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 14 Jul 2011 16:52:27 -0500 Subject: catching the correct exception --- nova/network/manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/network/manager.py b/nova/network/manager.py index 824e8d24d..24736f53d 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -340,7 +340,7 @@ class NetworkManager(manager.SchedulerDependentManager): """Set the network hosts for any networks which are unset.""" try: networks = self.db.network_get_all(context) - except Exception.NoNetworksFound: + except exception.NoNetworksFound: # we don't care if no networks are found pass @@ -357,7 +357,7 @@ class NetworkManager(manager.SchedulerDependentManager): # a non-vlan instance should connect to try: networks = self.db.network_get_all(context) - except Exception.NoNetworksFound: + except exception.NoNetworksFound: # we don't care if no networks are found pass -- cgit From dd78adbcf0b85f9473b5240af3366fb1dc2d4133 Mon Sep 17 00:00:00 2001 From: Stephanie Reese Date: Thu, 14 Jul 2011 23:09:28 -0400 Subject: Fixed remove_version_from_href Added tests --- nova/api/openstack/common.py | 13 ++++++++++--- nova/tests/api/openstack/test_common.py | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 79969d393..8e12ce0c0 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -137,15 +137,22 @@ def get_id_from_href(href): def remove_version_from_href(href): - """Removes the api version from the href. + """Removes the first api version from the href. Given: 'http://www.nova.com/v1.1/123' Returns: 'http://www.nova.com/123' + Given: 'http://www.nova.com/v1.1' + Returns: 'http://www.nova.com' + """ try: - #matches /v#.# - new_href = re.sub(r'[/][v][0-9]*.[0-9]*', '', href) + #removes the first instance that matches /v#.#/ + new_href = re.sub(r'[/][v][0-9]+\.[0-9]+[/]', '/', href, count=1) + + #if no version was found, try finding /v#.# at the end of the string + if new_href == href: + new_href = re.sub(r'[/][v][0-9]+\.[0-9]+$', '', href, count=1) except: LOG.debug(_("Error removing version from href: %s") % href) msg = _('could not parse version from href') diff --git a/nova/tests/api/openstack/test_common.py b/nova/tests/api/openstack/test_common.py index 7440bccfb..4c4d03995 100644 --- a/nova/tests/api/openstack/test_common.py +++ b/nova/tests/api/openstack/test_common.py @@ -206,12 +206,36 @@ class MiscFunctionsTest(test.TestCase): actual = common.remove_version_from_href(fixture) self.assertEqual(actual, expected) + def test_remove_version_from_href_3(self): + fixture = 'http://www.testsite.com/v10.10' + expected = 'http://www.testsite.com' + actual = common.remove_version_from_href(fixture) + self.assertEqual(actual, expected) + + def test_remove_version_from_href_4(self): + fixture = 'http://www.testsite.com/v1.1/images/v10.5' + expected = 'http://www.testsite.com/images/v10.5' + actual = common.remove_version_from_href(fixture) + self.assertEqual(actual, expected) + def test_remove_version_from_href_bad_request(self): fixture = 'http://www.testsite.com/1.1/images' self.assertRaises(ValueError, common.remove_version_from_href, fixture) + def test_remove_version_from_href_bad_request_2(self): + fixture = 'http://www.testsite.com/v/images' + self.assertRaises(ValueError, + common.remove_version_from_href, + fixture) + + def test_remove_version_from_href_bad_request_3(self): + fixture = 'http://www.testsite.com/v1.1images' + self.assertRaises(ValueError, + common.remove_version_from_href, + fixture) + def test_get_id_from_href(self): fixture = 'http://www.testsite.com/dir/45' actual = common.get_id_from_href(fixture) -- cgit From 0aeec37c27e91d031ef53eeec9952c4f470990a1 Mon Sep 17 00:00:00 2001 From: Stephanie Reese Date: Thu, 14 Jul 2011 23:12:42 -0400 Subject: Updated Authors --- Authors | 1 + 1 file changed, 1 insertion(+) diff --git a/Authors b/Authors index 2e50cfbe0..62edd6771 100644 --- a/Authors +++ b/Authors @@ -86,6 +86,7 @@ Salvatore Orlando Sandy Walsh Sateesh Chodapuneedi Soren Hansen +Stephanie Reese Thierry Carrez Todd Willey Trey Morris -- cgit