From 7f2cae4d63d1fb9c351d88ad911166f55e89c2f4 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 16 Dec 2010 18:01:21 +0000 Subject: fixed up openstack api images index and detail --- nova/api/openstack/images.py | 58 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 4a0a8e6f1..3a9bdea64 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -27,6 +27,40 @@ from nova.api.openstack import faults FLAGS = flags.FLAGS +def _entity_list(entities): + """ Coerces a list of images into proper dictionary format + entities is a list of entities (dicts) """ + return dict(images=entities) + +def _entity_detail(inst): + """ Maps everything to Rackspace-like attributes for return + also pares down attributes to those we want + inst is a single entity (dict) """ + status_mapping = { + 'pending': 'queued', + 'decrypting': 'preparing', + 'untarring': 'saving', + 'available': 'active', + new_inst = {} + mapped_keys = {status:'imageState', id:'imageId', name:'imageLocation'} + + for k,v in mapped_keys.iteritems(): + new_inst[k] = inst[v] + + new_inst['status'] = status_mapping[inew_inst['status']] + + return new_inst + +def _entity_inst(inst): + """ Filters all model attributes save for id and name + inst is a single entity (dict) """ + return _filter_keys(inst, ['id','name']) + +def _filter_keys(inst, keys): + """ Filters all model attributes for keys + inst is a single entity (dict) """ + return dict( (k,v) for k,v in inst.iteritems() if k in keys) + class Controller(wsgi.Controller): @@ -40,24 +74,24 @@ class Controller(wsgi.Controller): self._service = utils.import_object(FLAGS.image_service) def index(self, req): - """Return all public images in brief.""" - return dict(images=[dict(id=img['id'], name=img['name']) - for img in self.detail(req)['images']]) + """ Return all public images in brief """ + items = self._service.index(req.environ['nova.context']) + items = nova.api.openstack.limited(items, req) + items = [_entity_inst(item) for item in items] + return dict(images=items) def detail(self, req): - """Return all public images in detail.""" + """ Return all public images in detail """ try: - images = self._service.detail(req.environ['nova.context']) - images = nova.api.openstack.limited(images, req) + items = self._service.detail(req.environ['nova.context']) except NotImplementedError: - # Emulate detail() using repeated calls to show() - images = self._service.index(ctxt) - images = nova.api.openstack.limited(images, req) - images = [self._service.show(ctxt, i['id']) for i in images] - return dict(images=images) + items = self._service.index(req.environ['nova.context']) + items = nova.api.openstack.limited(items, req) + items = [_entity_detail(item) for item in items] + return dict(images=items) def show(self, req, id): - """Return data about the given image id.""" + """ Return data about the given image id """ return dict(image=self._service.show(req.environ['nova.context'], id)) def delete(self, req, id): -- cgit From 7b0c5b3f06328ec9dbb02b2def306d671353354e Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 16 Dec 2010 18:09:25 +0000 Subject: typo --- nova/api/openstack/images.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 3a9bdea64..78c07abde 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -40,7 +40,7 @@ def _entity_detail(inst): 'pending': 'queued', 'decrypting': 'preparing', 'untarring': 'saving', - 'available': 'active', + 'available': 'active'} new_inst = {} mapped_keys = {status:'imageState', id:'imageId', name:'imageLocation'} -- cgit From fc1354a639edb1c3a7f979f58bb90918c63695ab Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 16 Dec 2010 18:17:53 +0000 Subject: fixed a couple of more syntax errors --- nova/api/openstack/images.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 78c07abde..7f2be5472 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -41,15 +41,15 @@ def _entity_detail(inst): 'decrypting': 'preparing', 'untarring': 'saving', 'available': 'active'} - new_inst = {} - mapped_keys = {status:'imageState', id:'imageId', name:'imageLocation'} + mapped_inst = {} + mapped_keys = {'status':'imageState', 'id':'imageId', 'name':'imageLocation'} for k,v in mapped_keys.iteritems(): - new_inst[k] = inst[v] + mapped_inst[k] = inst[v] - new_inst['status'] = status_mapping[inew_inst['status']] + mapped_inst['status'] = status_mapping[mapped_inst['status']] - return new_inst + return mapped_inst def _entity_inst(inst): """ Filters all model attributes save for id and name -- cgit From d71b9a34c3f76f95227da0f7a746cc5a1a76da24 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Sun, 19 Dec 2010 23:51:17 +0000 Subject: small clean up --- nova/api/openstack/images.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 7f2be5472..df5e1530f 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -41,9 +41,14 @@ def _entity_detail(inst): 'decrypting': 'preparing', 'untarring': 'saving', 'available': 'active'} - mapped_inst = {} - mapped_keys = {'status':'imageState', 'id':'imageId', 'name':'imageLocation'} + # TODO(tr3buchet): this map is specific to s3 object store, + # fix once the local image service is working + mapped_keys = {'status':'imageState', + 'id':'imageId', + 'name':'imageLocation'} + + mapped_inst = {} for k,v in mapped_keys.iteritems(): mapped_inst[k] = inst[v] @@ -54,9 +59,9 @@ def _entity_detail(inst): def _entity_inst(inst): """ Filters all model attributes save for id and name inst is a single entity (dict) """ - return _filter_keys(inst, ['id','name']) + return _select_keys(inst, ['id','name']) -def _filter_keys(inst, keys): +def _select_keys(inst, keys): """ Filters all model attributes for keys inst is a single entity (dict) """ return dict( (k,v) for k,v in inst.iteritems() if k in keys) -- cgit From b5756f6abf582b04a5fe6744d6a139b12440e35a Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Mon, 20 Dec 2010 21:12:20 +0000 Subject: fixed some pep8 business --- nova/api/openstack/images.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index df5e1530f..0f808a6bf 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -27,11 +27,13 @@ from nova.api.openstack import faults FLAGS = flags.FLAGS + def _entity_list(entities): """ Coerces a list of images into proper dictionary format entities is a list of entities (dicts) """ return dict(images=entities) + def _entity_detail(inst): """ Maps everything to Rackspace-like attributes for return also pares down attributes to those we want @@ -44,27 +46,29 @@ def _entity_detail(inst): # TODO(tr3buchet): this map is specific to s3 object store, # fix once the local image service is working - mapped_keys = {'status':'imageState', - 'id':'imageId', - 'name':'imageLocation'} + mapped_keys = {'status': 'imageState', + 'id': 'imageId', + 'name': 'imageLocation'} mapped_inst = {} - for k,v in mapped_keys.iteritems(): + for k, v in mapped_keys.iteritems(): mapped_inst[k] = inst[v] mapped_inst['status'] = status_mapping[mapped_inst['status']] return mapped_inst + def _entity_inst(inst): """ Filters all model attributes save for id and name inst is a single entity (dict) """ - return _select_keys(inst, ['id','name']) + return _select_keys(inst, ['id', 'name']) + def _select_keys(inst, keys): """ Filters all model attributes for keys inst is a single entity (dict) """ - return dict( (k,v) for k,v in inst.iteritems() if k in keys) + return dict((k, v) for k, v in inst.iteritems() if k in keys) class Controller(wsgi.Controller): -- cgit From aded4faba96e4de88f0294604927ef824cb249be Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Mon, 20 Dec 2010 22:55:11 +0000 Subject: added suspend and resume --- nova/api/openstack/__init__.py | 2 ++ nova/api/openstack/servers.py | 22 ++++++++++++++++++++++ nova/compute/api.py | 18 ++++++++++++++++++ nova/compute/manager.py | 32 ++++++++++++++++++++++++++++++++ nova/tests/api/openstack/test_servers.py | 32 ++++++++++++++++++++++++++++++-- nova/tests/compute_unittest.py | 8 ++++++++ nova/virt/fake.py | 8 ++++++++ nova/virt/libvirt_conn.py | 8 ++++++++ nova/virt/xenapi/vmops.py | 23 +++++++++++++++++++++-- nova/virt/xenapi_conn.py | 8 ++++++++ 10 files changed, 157 insertions(+), 4 deletions(-) diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py index 210df8d24..2553313e4 100644 --- a/nova/api/openstack/__init__.py +++ b/nova/api/openstack/__init__.py @@ -176,6 +176,8 @@ class APIRouter(wsgi.Router): logging.debug("Including admin operations in API.") server_members['pause'] = 'POST' server_members['unpause'] = 'POST' + server_members['suspend'] = 'POST' + server_members['resume'] = 'POST' mapper.resource("server", "servers", controller=servers.Controller(), collection={'detail': 'GET'}, diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index 5c3322f7c..e6700ee96 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -195,3 +195,25 @@ class Controller(wsgi.Controller): logging.error("Compute.api::unpause %s", readable) return faults.Fault(exc.HTTPUnprocessableEntity()) return exc.HTTPAccepted() + + def suspend(self, req, id): + """permit admins to suspend the server""" + context = req.environ['nova.context'] + try: + self.compute_api.suspend(context, id) + except: + readable = traceback.format_exc() + logging.error("compute.api::suspend %s", readable) + return faults.Fault(exc.HTTPUnprocessableEntity()) + return exc.HTTPAccepted() + + def resume(self, req, id): + """permit admins to resume the server from suspend""" + context = req.environ['nova.context'] + try: + self.compute_api.resume(context, id) + except: + readable = traceback.format_exc() + logging.error("compute.api::resume %s", readable) + return faults.Fault(exc.HTTPUnprocessableEntity()) + return exc.HTTPAccepted() diff --git a/nova/compute/api.py b/nova/compute/api.py index c740814da..bb144d12f 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -298,6 +298,24 @@ class ComputeAPI(base.Base): {"method": "unpause_instance", "args": {"instance_id": instance['id']}}) + def suspend(self, context, instance_id): + """suspend the instance with instance_id""" + instance = self.db.instance_get_by_internal_id(context, instance_id) + host = instance['host'] + rpc.cast(context, + self.db.queue_get_for(context, FLAGS.compute_topic, host), + {"method": "suspend_instance", + "args": {"instance_id": instance['id']}}) + + def resume(self, context, instance_id): + """resume the instance with instance_id""" + instance = self.db.instance_get_by_internal_id(context, instance_id) + host = instance['host'] + rpc.cast(context, + self.db.queue_get_for(context, FLAGS.compute_topic, host), + {"method": "resume_instance", + "args": {"instance_id": instance['id']}}) + def rescue(self, context, instance_id): """Rescue the given instance.""" instance = self.db.instance_get_by_internal_id(context, instance_id) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index a84af6bb9..b1ac2db88 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -227,6 +227,38 @@ class ComputeManager(manager.Manager): instance_id, result)) + @exception.wrap_exception + def suspend_instance(self, context, instance_id): + """suspend the instance with instance_id""" + context = context.elevated() + instance_ref = self.db.instance_get(context, instance_id) + + logging.debug('instance %s: suspending', instance_ref['internal_id']) + self.db.instance_set_state(context, instance_id, + power_state.NOSTATE, + 'suspending') + self.driver.suspend(instance_ref, + lambda result: self._update_state_callback(self, + context, + instance_id, + result)) + + @exception.wrap_exception + def resume_instance(self, context, instance_id): + """resume the suspended instance with instance_id""" + context = context.elevated() + instance_ref = self.db.instance_get(context, instance_id) + + logging.debug('instance %s: resuming', instance_ref['internal_id']) + self.db.instance_set_state(context, instance_id, + power_state.NOSTATE, + 'resuming') + self.driver.resume(instance_ref, + lambda result: self._update_state_callback(self, + context, + instance_id, + result)) + @exception.wrap_exception def get_console_output(self, context, instance_id): """Send the console output for an instance.""" diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py index 3820f5f27..5d23db588 100644 --- a/nova/tests/api/openstack/test_servers.py +++ b/nova/tests/api/openstack/test_servers.py @@ -88,9 +88,13 @@ class ServersTest(unittest.TestCase): self.stubs.Set(nova.db.api, 'instance_get_floating_address', instance_address) self.stubs.Set(nova.compute.api.ComputeAPI, 'pause', - fake_compute_api) + fake_compute_api) self.stubs.Set(nova.compute.api.ComputeAPI, 'unpause', - fake_compute_api) + fake_compute_api) + self.stubs.Set(nova.compute.api.ComputeAPI, 'suspend', + fake_compute_api) + self.stubs.Set(nova.compute.api.ComputeAPI, 'resume', + fake_compute_api) self.allow_admin = FLAGS.allow_admin_api def tearDown(self): @@ -246,6 +250,30 @@ class ServersTest(unittest.TestCase): res = req.get_response(nova.api.API('os')) self.assertEqual(res.status_int, 202) + def test_server_suspend(self): + FLAGS.allow_admin_api = True + body = dict(server=dict( + name='server_test', imageId=2, flavorId=2, metadata={}, + personality={})) + req = webob.Request.blank('/v1.0/servers/1/suspend') + req.method = 'POST' + req.content_type = 'application/json' + req.body = json.dumps(body) + res = req.get_response(nova.api.API('os')) + self.assertEqual(res.status_int, 202) + + def test_server_resume(self): + FLAGS.allow_admin_api = True + body = dict(server=dict( + name='server_test', imageId=2, flavorId=2, metadata={}, + personality={})) + req = webob.Request.blank('/v1.0/servers/1/resume') + req.method = 'POST' + req.content_type = 'application/json' + req.body = json.dumps(body) + res = req.get_response(nova.api.API('os')) + self.assertEqual(res.status_int, 202) + def test_server_reboot(self): body = dict(server=dict( name='server_test', imageId=2, flavorId=2, metadata={}, diff --git a/nova/tests/compute_unittest.py b/nova/tests/compute_unittest.py index 187ca31de..111a43cdc 100644 --- a/nova/tests/compute_unittest.py +++ b/nova/tests/compute_unittest.py @@ -135,6 +135,14 @@ class ComputeTestCase(test.TestCase): self.compute.unpause_instance(self.context, instance_id) self.compute.terminate_instance(self.context, instance_id) + def test_suspend(self): + """ensure instance can be suspended""" + instance_id = self._create_instance() + self.compute.run_instance(self.context, instance_id) + self.compute.suspend_instance(self.context, instance_id) + self.compute.resume_instance(self.context, instance_id) + self.compute.terminate_instance(self.context, instance_id) + def test_reboot(self): """Ensure instance can be rebooted""" instance_id = self._create_instance() diff --git a/nova/virt/fake.py b/nova/virt/fake.py index 55c6dcef9..54787751e 100644 --- a/nova/virt/fake.py +++ b/nova/virt/fake.py @@ -142,6 +142,14 @@ class FakeConnection(object): """ pass + def suspend(self, instance, callback): + """suspend the specified instance""" + pass + + def resume(self, instance, callback): + """resume the specified instance""" + pass + def destroy(self, instance): """ Destroy (shutdown and delete) the specified instance. diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index ad101db2a..6c77a2693 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -269,6 +269,14 @@ class LibvirtConnection(object): def unpause(self, instance, callback): raise exception.APIError("unpause not supported for libvirt.") + @exception.wrap_exception + def suspend(self, instance, callback): + raise exception.APIError("suspend not supported for libvirt") + + @exception.wrap_exception + def resume(self, instance, callback): + raise exception.APIError("resume not supported for libvirt") + @exception.wrap_exception def rescue(self, instance): self.destroy(instance, False) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index a18eacf07..eb6743a7a 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -144,11 +144,29 @@ class VMOps(object): task = self._session.call_xenapi('Async.VM.unpause', vm) self._wait_with_callback(task, callback) + def suspend(self, instance, callback): + """suspend the specified instance""" + instance_name = instance.name + vm = VMHelper.lookup(self._session, instance_name) + if vm is None: + raise Exception("suspend: instance not present %s" % instance_name) + task = self._session.call_xenapi('Async.VM.suspend', vm) + self._wait_with_callback(task, callback) + + def resume(self, instance, callback): + """resume the specified instance""" + instance_name = instance.name + vm = VMHelper.lookup(self._session, instance_name) + if vm is None: + raise Exception("resume: instance not present %s" % instance_name) + task = self._session.call_xenapi('Async.VM.resume', vm) + self._wait_with_callback(task, callback) + def get_info(self, instance_id): """ Return data about VM instance """ vm = VMHelper.lookup_blocking(self._session, instance_id) if vm is None: - raise Exception('instance not present %s' % instance_id) + raise Exception("get_info: instance not present %s" % instance_id) rec = self._session.get_xenapi().VM.get_record(vm) return VMHelper.compile_info(rec) @@ -156,7 +174,8 @@ class VMOps(object): """Return data about VM diagnostics""" vm = VMHelper.lookup(self._session, instance_id) if vm is None: - raise Exception("instance not present %s" % instance_id) + raise Exception("get_diagnostics: instance not present %s" % \ + instance_id) rec = self._session.get_xenapi().VM.get_record(vm) return VMHelper.compile_diagnostics(self._session, rec) diff --git a/nova/virt/xenapi_conn.py b/nova/virt/xenapi_conn.py index 21ed2cd65..7e430cbdc 100644 --- a/nova/virt/xenapi_conn.py +++ b/nova/virt/xenapi_conn.py @@ -132,6 +132,14 @@ class XenAPIConnection(object): """ Unpause paused VM instance """ self._vmops.unpause(instance, callback) + def suspend(self, instance, callback): + """suspend the specified instance""" + self._vmops.suspend(instance, callback) + + def resume(self, instance, callback): + """resume the specified instance""" + self._vmops.resume(instance, callback) + def get_info(self, instance_id): """ Return data about VM instance """ return self._vmops.get_info(instance_id) -- cgit From f9e2bbdf1182f54d69f6005eb7c39007eddbd3cd Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Tue, 21 Dec 2010 20:06:53 +0000 Subject: correct xenapi resume call --- nova/virt/xenapi/vmops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index eb6743a7a..3ec131600 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -159,7 +159,7 @@ class VMOps(object): vm = VMHelper.lookup(self._session, instance_name) if vm is None: raise Exception("resume: instance not present %s" % instance_name) - task = self._session.call_xenapi('Async.VM.resume', vm) + task = self._session.call_xenapi('Async.VM.resume', vm, False, True) self._wait_with_callback(task, callback) def get_info(self, instance_id): -- cgit From 62286399b69218418020baaf524292c1677d27d3 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 23 Dec 2010 06:48:15 +0000 Subject: added suspend as a power state --- nova/api/openstack/servers.py | 3 ++- nova/compute/power_state.py | 4 +++- nova/virt/xenapi/vm_utils.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index e6700ee96..9ee52ef2f 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -45,7 +45,8 @@ def _entity_detail(inst): power_state.NOSTATE: 'build', power_state.RUNNING: 'active', power_state.BLOCKED: 'active', - power_state.PAUSED: 'suspended', + power_state.SUSPENDED: 'suspended', + power_state.PAUSED: 'error', power_state.SHUTDOWN: 'active', power_state.SHUTOFF: 'active', power_state.CRASHED: 'error'} diff --git a/nova/compute/power_state.py b/nova/compute/power_state.py index cefdf2d9e..37039d2ec 100644 --- a/nova/compute/power_state.py +++ b/nova/compute/power_state.py @@ -26,6 +26,7 @@ PAUSED = 0x03 SHUTDOWN = 0x04 SHUTOFF = 0x05 CRASHED = 0x06 +SUSPENDED = 0x07 def name(code): @@ -36,5 +37,6 @@ def name(code): PAUSED: 'paused', SHUTDOWN: 'shutdown', SHUTOFF: 'shutdown', - CRASHED: 'crashed'} + CRASHED: 'crashed', + SUSPENDED: 'suspended'} return d[code] diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 017a6eab0..667da27ea 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -37,7 +37,7 @@ XENAPI_POWER_STATE = { 'Halted': power_state.SHUTDOWN, 'Running': power_state.RUNNING, 'Paused': power_state.PAUSED, - 'Suspended': power_state.SHUTDOWN, # FIXME + 'Suspended': power_state.SUSPENDED, 'Crashed': power_state.CRASHED} XenAPI = None -- cgit From 45c75b0c8ecea6952d68cc28d2925c6a42a799de Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 23 Dec 2010 07:05:45 +0000 Subject: added power state logging to nova.virt.xenapi.vm_utils --- nova/virt/xenapi/vm_utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 667da27ea..095e32ae2 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -217,6 +217,10 @@ class VMHelper(): @classmethod def compile_info(cls, record): + logging.info("(VM_UTILS) xenserver vm state -> |%s|", + record['power_state']) + logging.info("(VM_UTILS) xenapi power_state -> |%s|", + XENAPI_POWER_STATE[record['power_state']]) return {'state': XENAPI_POWER_STATE[record['power_state']], 'max_mem': long(record['memory_static_max']) >> 10, 'mem': long(record['memory_dynamic_max']) >> 10, -- cgit From a0ca9d4a9550370cc262574fbee097e5b70e408d Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 23 Dec 2010 20:35:16 +0000 Subject: added _() for gettext and a couple of pep8s --- nova/api/openstack/servers.py | 8 ++++---- nova/compute/manager.py | 4 ++-- nova/tests/compute_unittest.py | 4 ++-- nova/virt/fake.py | 8 ++++++-- nova/virt/xenapi/vm_utils.py | 4 ++-- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index 9ee52ef2f..d3e5badea 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -182,7 +182,7 @@ class Controller(wsgi.Controller): self.compute_api.pause(ctxt, id) except: readable = traceback.format_exc() - logging.error("Compute.api::pause %s", readable) + logging.error(_("Compute.api::pause %s"), readable) return faults.Fault(exc.HTTPUnprocessableEntity()) return exc.HTTPAccepted() @@ -193,7 +193,7 @@ class Controller(wsgi.Controller): self.compute_api.unpause(ctxt, id) except: readable = traceback.format_exc() - logging.error("Compute.api::unpause %s", readable) + logging.error(_("Compute.api::unpause %s"), readable) return faults.Fault(exc.HTTPUnprocessableEntity()) return exc.HTTPAccepted() @@ -204,7 +204,7 @@ class Controller(wsgi.Controller): self.compute_api.suspend(context, id) except: readable = traceback.format_exc() - logging.error("compute.api::suspend %s", readable) + logging.error(_("compute.api::suspend %s"), readable) return faults.Fault(exc.HTTPUnprocessableEntity()) return exc.HTTPAccepted() @@ -215,6 +215,6 @@ class Controller(wsgi.Controller): self.compute_api.resume(context, id) except: readable = traceback.format_exc() - logging.error("compute.api::resume %s", readable) + logging.error(_("compute.api::resume %s"), readable) return faults.Fault(exc.HTTPUnprocessableEntity()) return exc.HTTPAccepted() diff --git a/nova/compute/manager.py b/nova/compute/manager.py index b1ac2db88..f96f0ca9c 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -233,7 +233,7 @@ class ComputeManager(manager.Manager): context = context.elevated() instance_ref = self.db.instance_get(context, instance_id) - logging.debug('instance %s: suspending', instance_ref['internal_id']) + logging.debug(_('instance %s: suspending'), instance_ref['internal_id']) self.db.instance_set_state(context, instance_id, power_state.NOSTATE, 'suspending') @@ -249,7 +249,7 @@ class ComputeManager(manager.Manager): context = context.elevated() instance_ref = self.db.instance_get(context, instance_id) - logging.debug('instance %s: resuming', instance_ref['internal_id']) + logging.debug(_('instance %s: resuming'), instance_ref['internal_id']) self.db.instance_set_state(context, instance_id, power_state.NOSTATE, 'resuming') diff --git a/nova/tests/compute_unittest.py b/nova/tests/compute_unittest.py index 111a43cdc..14954c3a2 100644 --- a/nova/tests/compute_unittest.py +++ b/nova/tests/compute_unittest.py @@ -100,13 +100,13 @@ class ComputeTestCase(test.TestCase): self.compute.run_instance(self.context, instance_id) instances = db.instance_get_all(context.get_admin_context()) - logging.info("Running instances: %s", instances) + logging.info(_("Running instances: %s"), instances) self.assertEqual(len(instances), 1) self.compute.terminate_instance(self.context, instance_id) instances = db.instance_get_all(context.get_admin_context()) - logging.info("After terminating instances: %s", instances) + logging.info(_("After terminating instances: %s"), instances) self.assertEqual(len(instances), 0) def test_run_terminate_timestamps(self): diff --git a/nova/virt/fake.py b/nova/virt/fake.py index 54787751e..3bb062294 100644 --- a/nova/virt/fake.py +++ b/nova/virt/fake.py @@ -143,11 +143,15 @@ class FakeConnection(object): pass def suspend(self, instance, callback): - """suspend the specified instance""" + """ + suspend the specified instance + """ pass def resume(self, instance, callback): - """resume the specified instance""" + """ + resume the specified instance + """ pass def destroy(self, instance): diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 095e32ae2..dc8359204 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -217,9 +217,9 @@ class VMHelper(): @classmethod def compile_info(cls, record): - logging.info("(VM_UTILS) xenserver vm state -> |%s|", + logging.info(_("(VM_UTILS) xenserver vm state -> |%s|"), record['power_state']) - logging.info("(VM_UTILS) xenapi power_state -> |%s|", + logging.info(_("(VM_UTILS) xenapi power_state -> |%s|"), XENAPI_POWER_STATE[record['power_state']]) return {'state': XENAPI_POWER_STATE[record['power_state']], 'max_mem': long(record['memory_static_max']) >> 10, -- cgit From 8e1122997867a16c161954004b5f1722282a97ef Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 23 Dec 2010 21:45:01 +0000 Subject: fixed error occuring when tests used glance attributes, fixed docstrings --- nova/api/openstack/images.py | 51 +++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 0f808a6bf..4f16b0ed4 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -29,15 +29,21 @@ FLAGS = flags.FLAGS def _entity_list(entities): - """ Coerces a list of images into proper dictionary format - entities is a list of entities (dicts) """ + """ + Coerces a list of images into proper dictionary format + entities is a list of entities (dicts) + + """ return dict(images=entities) def _entity_detail(inst): - """ Maps everything to Rackspace-like attributes for return - also pares down attributes to those we want - inst is a single entity (dict) """ + """ + Maps everything to Rackspace-like attributes for return + also pares down attributes to those we want + inst is a single entity (dict) + + """ status_mapping = { 'pending': 'queued', 'decrypting': 'preparing', @@ -45,14 +51,23 @@ def _entity_detail(inst): 'available': 'active'} # TODO(tr3buchet): this map is specific to s3 object store, - # fix once the local image service is working + # replace with a list of keys for _select_keys later mapped_keys = {'status': 'imageState', 'id': 'imageId', 'name': 'imageLocation'} mapped_inst = {} - for k, v in mapped_keys.iteritems(): - mapped_inst[k] = inst[v] + # TODO(tr3buchet): + # this chunk of code works with s3 and the local image service/glance + # when we switch to glance/local image service it can be replaced with + # a call to _select_keys, and mapped_keys can be changed to a list + try: + for k, v in mapped_keys.iteritems(): + # map s3 fields + mapped_inst[k] = inst[v] + except KeyError: + mapped_inst = _select_keys(inst, mapped_keys.keys()) + mapped_inst['status'] = status_mapping[mapped_inst['status']] @@ -60,14 +75,20 @@ def _entity_detail(inst): def _entity_inst(inst): - """ Filters all model attributes save for id and name - inst is a single entity (dict) """ + """ + Filters all model attributes save for id and name + inst is a single entity (dict) + + """ return _select_keys(inst, ['id', 'name']) def _select_keys(inst, keys): - """ Filters all model attributes for keys - inst is a single entity (dict) """ + """ + Filters all model attributes except for keys + inst is a single entity (dict) + + """ return dict((k, v) for k, v in inst.iteritems() if k in keys) @@ -83,14 +104,14 @@ class Controller(wsgi.Controller): self._service = utils.import_object(FLAGS.image_service) def index(self, req): - """ Return all public images in brief """ + """Return all public images in brief""" items = self._service.index(req.environ['nova.context']) items = nova.api.openstack.limited(items, req) items = [_entity_inst(item) for item in items] return dict(images=items) def detail(self, req): - """ Return all public images in detail """ + """Return all public images in detail""" try: items = self._service.detail(req.environ['nova.context']) except NotImplementedError: @@ -100,7 +121,7 @@ class Controller(wsgi.Controller): return dict(images=items) def show(self, req, id): - """ Return data about the given image id """ + """Return data about the given image id""" return dict(image=self._service.show(req.environ['nova.context'], id)) def delete(self, req, id): -- cgit From 1c26d2b2ce824dbc64525eea699efbfa8bf04617 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 23 Dec 2010 21:48:14 +0000 Subject: updated since dietz moved the limited function --- nova/api/openstack/images.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 4f16b0ed4..132afc5fc 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -106,7 +106,7 @@ class Controller(wsgi.Controller): def index(self, req): """Return all public images in brief""" items = self._service.index(req.environ['nova.context']) - items = nova.api.openstack.limited(items, req) + items = common.limited(images, req) items = [_entity_inst(item) for item in items] return dict(images=items) @@ -116,7 +116,7 @@ class Controller(wsgi.Controller): items = self._service.detail(req.environ['nova.context']) except NotImplementedError: items = self._service.index(req.environ['nova.context']) - items = nova.api.openstack.limited(items, req) + items = common.limited(images, req) items = [_entity_detail(item) for item in items] return dict(images=items) -- cgit From 6df8d6827d48572ba4cc7cf13fd69286f0dcafe1 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 23 Dec 2010 22:00:44 +0000 Subject: fixed typo --- nova/api/openstack/images.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 515fd4423..787e23acc 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -108,7 +108,7 @@ class Controller(wsgi.Controller): def index(self, req): """Return all public images in brief""" items = self._service.index(req.environ['nova.context']) - items = common.limited(images, req) + items = common.limited(items, req) items = [_entity_inst(item) for item in items] return dict(images=items) @@ -118,7 +118,7 @@ class Controller(wsgi.Controller): items = self._service.detail(req.environ['nova.context']) except NotImplementedError: items = self._service.index(req.environ['nova.context']) - items = common.limited(images, req) + items = common.limited(items, req) items = [_entity_detail(item) for item in items] return dict(images=items) -- cgit From 257da8a0e5fd949f62232bf2eef9d91f36fc41ce Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 23 Dec 2010 23:09:58 +0000 Subject: fixed the os api image test for glance --- nova/tests/api/openstack/test_images.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index f610cbf9c..e849b5ea6 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -223,6 +223,21 @@ class ImageControllerWithGlanceServiceTest(unittest.TestCase): res = req.get_response(nova.api.API('os')) res_dict = json.loads(res.body) + def _is_equivalent_subset(x, y): + if set(x) <= set(y): + for k, v in x.iteritems(): + if x[k] != y[k]: + return False + return True + return False + for image in res_dict['images']: - self.assertEquals(1, self.IMAGE_FIXTURES.count(image), - "image %s not in fixtures!" % str(image)) + for image_fixture in IMAGE_FIXTURES: + if _is_equivalent_subset(image, image_fixture): + break + else: + self.assertFalse("image %s not in fixtures!" % str(image)) + +# for image in res_dict['images']: +# self.assertEquals(1, self.IMAGE_FIXTURES.count(image), +# "image %s not in fixtures!" % str(image)) -- cgit From 391ab4dd63297afcc9449059bcadfe6ac5008b5f Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 23 Dec 2010 23:13:03 +0000 Subject: typo --- nova/tests/api/openstack/test_images.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index e849b5ea6..1986a2b5f 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -232,7 +232,7 @@ class ImageControllerWithGlanceServiceTest(unittest.TestCase): return False for image in res_dict['images']: - for image_fixture in IMAGE_FIXTURES: + for image_fixture in self.IMAGE_FIXTURES: if _is_equivalent_subset(image, image_fixture): break else: -- cgit From d8d66d4c2c25d25892289e08ca52720f9d123d88 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 23 Dec 2010 23:19:24 +0000 Subject: trying again --- nova/tests/api/openstack/test_images.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index 1986a2b5f..16a910a3f 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -236,7 +236,7 @@ class ImageControllerWithGlanceServiceTest(unittest.TestCase): if _is_equivalent_subset(image, image_fixture): break else: - self.assertFalse("image %s not in fixtures!" % str(image)) + self.assertEquals(1,2,"image %s not in fixtures!" % str(image)) # for image in res_dict['images']: # self.assertEquals(1, self.IMAGE_FIXTURES.count(image), -- cgit From 26a8afd85233e142f97fdcc802c41b9a765efb32 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 23 Dec 2010 23:27:39 +0000 Subject: applied power state conversion to test --- nova/tests/api/openstack/test_images.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index 16a910a3f..ec0119bfe 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -227,6 +227,8 @@ class ImageControllerWithGlanceServiceTest(unittest.TestCase): if set(x) <= set(y): for k, v in x.iteritems(): if x[k] != y[k]: + if x[k] == 'active' and y[k] == 'available': + next return False return True return False -- cgit From f793e186910c1aec10759f5d05e305cf6889a02f Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 23 Dec 2010 23:52:33 +0000 Subject: another typo --- nova/tests/api/openstack/test_images.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index ec0119bfe..d9845eb71 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -228,7 +228,7 @@ class ImageControllerWithGlanceServiceTest(unittest.TestCase): for k, v in x.iteritems(): if x[k] != y[k]: if x[k] == 'active' and y[k] == 'available': - next + continue return False return True return False -- cgit From 1c00947aa86597d918d651b5385a6a4d72671c10 Mon Sep 17 00:00:00 2001 From: Armando Migliaccio Date: Sun, 26 Dec 2010 14:08:38 +0000 Subject: logs inner exception in nova/utils.py->import_class --- nova/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nova/utils.py b/nova/utils.py index b9045a50c..15112faa2 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -48,7 +48,8 @@ def import_class(import_str): try: __import__(mod_str) return getattr(sys.modules[mod_str], class_str) - except (ImportError, ValueError, AttributeError): + except (ImportError, ValueError, AttributeError), exc: + logging.debug(_('Inner Exception: %s'), exc) raise exception.NotFound(_('Class %s cannot be found') % class_str) -- cgit From 4b271b9e25ac2573cbb82f4b89434d608a91a8c7 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Mon, 27 Dec 2010 16:41:41 +0000 Subject: couple of pep8s --- nova/api/openstack/images.py | 1 - nova/tests/api/openstack/test_images.py | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 787e23acc..e848a2e3e 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -70,7 +70,6 @@ def _entity_detail(inst): except KeyError: mapped_inst = _select_keys(inst, mapped_keys.keys()) - mapped_inst['status'] = status_mapping[mapped_inst['status']] return mapped_inst diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index d9845eb71..ae11f7531 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -238,7 +238,8 @@ class ImageControllerWithGlanceServiceTest(unittest.TestCase): if _is_equivalent_subset(image, image_fixture): break else: - self.assertEquals(1,2,"image %s not in fixtures!" % str(image)) + self.assertEquals(1, 2, "image %s not in fixtures!" % \ + str(image)) # for image in res_dict['images']: # self.assertEquals(1, self.IMAGE_FIXTURES.count(image), -- cgit From 404015903646a00901ad1310c2a7731f960fae75 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Mon, 27 Dec 2010 17:18:43 +0000 Subject: removed \ --- nova/tests/api/openstack/test_images.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index ae11f7531..f2c8bc935 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -238,7 +238,7 @@ class ImageControllerWithGlanceServiceTest(unittest.TestCase): if _is_equivalent_subset(image, image_fixture): break else: - self.assertEquals(1, 2, "image %s not in fixtures!" % \ + self.assertEquals(1, 2, "image %s not in fixtures!" % str(image)) # for image in res_dict['images']: -- cgit From d2ec717f7f819503f977c7a6f35e96867cc6c512 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Mon, 27 Dec 2010 20:06:45 +0000 Subject: renaming things to be a bit more descriptive --- nova/api/openstack/images.py | 60 ++++++++++++++++----------------- nova/tests/api/openstack/test_images.py | 4 --- 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index e848a2e3e..ea22b07ba 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -30,30 +30,18 @@ from nova.api.openstack import faults FLAGS = flags.FLAGS -def _entity_list(entities): +def _translate_keys(inst): """ - Coerces a list of images into proper dictionary format - entities is a list of entities (dicts) - - """ - return dict(images=entities) - - -def _entity_detail(inst): - """ - Maps everything to Rackspace-like attributes for return + Maps key names to Rackspace-like attributes for return also pares down attributes to those we want - inst is a single entity (dict) + inst is a single item (dict) - """ - status_mapping = { - 'pending': 'queued', - 'decrypting': 'preparing', - 'untarring': 'saving', - 'available': 'active'} + Note: should be removed when the set of keys expected by the api + and the set of keys returned by the image service are equivalent + """ # TODO(tr3buchet): this map is specific to s3 object store, - # replace with a list of keys for _select_keys later + # replace with a list of keys for _filter_keys later mapped_keys = {'status': 'imageState', 'id': 'imageId', 'name': 'imageLocation'} @@ -62,32 +50,41 @@ def _entity_detail(inst): # TODO(tr3buchet): # this chunk of code works with s3 and the local image service/glance # when we switch to glance/local image service it can be replaced with - # a call to _select_keys, and mapped_keys can be changed to a list + # a call to _filter_keys, and mapped_keys can be changed to a list try: for k, v in mapped_keys.iteritems(): # map s3 fields mapped_inst[k] = inst[v] except KeyError: - mapped_inst = _select_keys(inst, mapped_keys.keys()) - - mapped_inst['status'] = status_mapping[mapped_inst['status']] + # return only the fields api expects + mapped_inst = _filter_keys(inst, mapped_keys.keys()) return mapped_inst -def _entity_inst(inst): +def _translate_status(inst): """ - Filters all model attributes save for id and name - inst is a single entity (dict) + Translates status of image to match current Rackspace api bindings + inst is a single item (dict) + + Note: should be removed when the set of statuses expected by the api + and the set of statuses returned by the image service are equivalent """ - return _select_keys(inst, ['id', 'name']) + mapped_inst = {} + status_mapping = { + 'pending': 'queued', + 'decrypting': 'preparing', + 'untarring': 'saving', + 'available': 'active'} + mapped_inst['status'] = status_mapping[mapped_inst['status']] + return mapped_inst -def _select_keys(inst, keys): +def _filter_keys(inst, keys): """ Filters all model attributes except for keys - inst is a single entity (dict) + inst is a single item (dict) """ return dict((k, v) for k, v in inst.iteritems() if k in keys) @@ -108,7 +105,7 @@ class Controller(wsgi.Controller): """Return all public images in brief""" items = self._service.index(req.environ['nova.context']) items = common.limited(items, req) - items = [_entity_inst(item) for item in items] + items = [_filter_keys(item, ('id', 'name')) for item in items] return dict(images=items) def detail(self, req): @@ -118,7 +115,8 @@ class Controller(wsgi.Controller): except NotImplementedError: items = self._service.index(req.environ['nova.context']) items = common.limited(items, req) - items = [_entity_detail(item) for item in items] + items = [_translate_keys(item) for item in items] + items = [_translate_status(item) for item in items] return dict(images=items) def show(self, req, id): diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index f2c8bc935..1b4031217 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -240,7 +240,3 @@ class ImageControllerWithGlanceServiceTest(unittest.TestCase): else: self.assertEquals(1, 2, "image %s not in fixtures!" % str(image)) - -# for image in res_dict['images']: -# self.assertEquals(1, self.IMAGE_FIXTURES.count(image), -# "image %s not in fixtures!" % str(image)) -- cgit From 0c983d1f3cba82f992fc128985f4f794fb76190f Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Mon, 27 Dec 2010 20:11:36 +0000 Subject: syntax error --- nova/api/openstack/images.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index ea22b07ba..8a16bcb0f 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -77,7 +77,7 @@ def _translate_status(inst): 'decrypting': 'preparing', 'untarring': 'saving', 'available': 'active'} - mapped_inst['status'] = status_mapping[mapped_inst['status']] + mapped_inst['status'] = status_mapping[inst['status']] return mapped_inst -- cgit From e86f765181a9d0a75486a98e827cc8505b7c4111 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Mon, 27 Dec 2010 20:17:53 +0000 Subject: inst -> item --- nova/api/openstack/images.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 8a16bcb0f..77625bab5 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -30,11 +30,11 @@ from nova.api.openstack import faults FLAGS = flags.FLAGS -def _translate_keys(inst): +def _translate_keys(item): """ Maps key names to Rackspace-like attributes for return also pares down attributes to those we want - inst is a single item (dict) + item is a dict Note: should be removed when the set of keys expected by the api and the set of keys returned by the image service are equivalent @@ -46,7 +46,7 @@ def _translate_keys(inst): 'id': 'imageId', 'name': 'imageLocation'} - mapped_inst = {} + mapped_item = {} # TODO(tr3buchet): # this chunk of code works with s3 and the local image service/glance # when we switch to glance/local image service it can be replaced with @@ -54,40 +54,40 @@ def _translate_keys(inst): try: for k, v in mapped_keys.iteritems(): # map s3 fields - mapped_inst[k] = inst[v] + mapped_item[k] = item[v] except KeyError: # return only the fields api expects - mapped_inst = _filter_keys(inst, mapped_keys.keys()) + mapped_item = _filter_keys(item, mapped_keys.keys()) - return mapped_inst + return mapped_item -def _translate_status(inst): +def _translate_status(item): """ Translates status of image to match current Rackspace api bindings - inst is a single item (dict) + item is a dict Note: should be removed when the set of statuses expected by the api and the set of statuses returned by the image service are equivalent """ - mapped_inst = {} + mapped_item = {} status_mapping = { 'pending': 'queued', 'decrypting': 'preparing', 'untarring': 'saving', 'available': 'active'} - mapped_inst['status'] = status_mapping[inst['status']] - return mapped_inst + mapped_item['status'] = status_mapping[item['status']] + return mapped_item -def _filter_keys(inst, keys): +def _filter_keys(item, keys): """ Filters all model attributes except for keys - inst is a single item (dict) + item is a dict """ - return dict((k, v) for k, v in inst.iteritems() if k in keys) + return dict((k, v) for k, v in item.iteritems() if k in keys) class Controller(wsgi.Controller): -- cgit From 243ba12a903b2eac30dd99305a92f76e430cfb49 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Mon, 27 Dec 2010 20:39:48 +0000 Subject: translate status was returning the wrong item --- nova/api/openstack/images.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 77625bab5..ba35fbc78 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -71,14 +71,13 @@ def _translate_status(item): and the set of statuses returned by the image service are equivalent """ - mapped_item = {} status_mapping = { 'pending': 'queued', 'decrypting': 'preparing', 'untarring': 'saving', 'available': 'active'} - mapped_item['status'] = status_mapping[item['status']] - return mapped_item + item['status'] = status_mapping[item['status']] + return item def _filter_keys(item, keys): -- cgit From 7cc68042a911dc38f1c2c24b3361757c16142b74 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Mon, 27 Dec 2010 22:59:08 +0000 Subject: missed a couple of gettext _() --- nova/virt/xenapi/vmops.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index cb5a49350..d756eae53 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -178,7 +178,8 @@ class VMOps(object): instance_name = instance.name vm = VMHelper.lookup(self._session, instance_name) if vm is None: - raise Exception("suspend: instance not present %s" % instance_name) + raise Exception(_("suspend: instance not present %s") % + instance_name) task = self._session.call_xenapi('Async.VM.suspend', vm) self._wait_with_callback(task, callback) @@ -187,7 +188,8 @@ class VMOps(object): instance_name = instance.name vm = VMHelper.lookup(self._session, instance_name) if vm is None: - raise Exception("resume: instance not present %s" % instance_name) + raise Exception(_("resume: instance not present %s") % + instance_name) task = self._session.call_xenapi('Async.VM.resume', vm, False, True) self._wait_with_callback(task, callback) -- cgit From 821fc6b5bce393e584d2c0f93243beb43ff547a5 Mon Sep 17 00:00:00 2001 From: Ewan Mellor Date: Tue, 28 Dec 2010 01:09:42 +0000 Subject: Bug #694890: run_tests.sh sometimes doesn't pass arguments to nosetest Change the argument parsing in run_tests.sh so that we explicitly gather the arguments that aren't meant for run_tests.sh, and pass them on to nosetests. --- run_tests.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/run_tests.sh b/run_tests.sh index 67214996d..ffb0b6295 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -21,6 +21,7 @@ function process_option { -V|--virtual-env) let always_venv=1; let never_venv=0;; -N|--no-virtual-env) let always_venv=0; let never_venv=1;; -f|--force) let force=1;; + *) noseargs="$noseargs $1" esac } @@ -29,15 +30,18 @@ with_venv=tools/with_venv.sh always_venv=0 never_venv=0 force=0 +noseargs= for arg in "$@"; do process_option $arg done +NOSETESTS="nosetests -v $noseargs" + if [ $never_venv -eq 1 ]; then # Just run the test suites in current environment rm -f nova.sqlite - nosetests -v + $NOSETESTS exit fi @@ -49,7 +53,7 @@ fi if [ -e ${venv} ]; then ${with_venv} rm -f nova.sqlite - ${with_venv} nosetests -v $@ + ${with_venv} $NOSETESTS else if [ $always_venv -eq 1 ]; then # Automatically install the virtualenv @@ -62,10 +66,10 @@ else python tools/install_venv.py else rm -f nova.sqlite - nosetests -v + $NOSETESTS exit fi fi ${with_venv} rm -f nova.sqlite - ${with_venv} nosetests -v $@ + ${with_venv} $NOSETESTS fi -- cgit From 32bfe6acdf8e462f90c72c9230b77c8c6fdca93b Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Tue, 28 Dec 2010 05:14:21 +0000 Subject: fixed a line length --- nova/compute/manager.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index d5e0c38b0..70b175e7c 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -302,7 +302,8 @@ class ComputeManager(manager.Manager): context = context.elevated() instance_ref = self.db.instance_get(context, instance_id) - logging.debug(_('instance %s: suspending'), instance_ref['internal_id']) + logging.debug(_('instance %s: suspending'), + instance_ref['internal_id']) self.db.instance_set_state(context, instance_id, power_state.NOSTATE, 'suspending') -- cgit