From 542909e52a6f3f2a9891b710f3755ea7c033a8d0 Mon Sep 17 00:00:00 2001 From: Yuriy Taraday Date: Thu, 28 Apr 2011 14:41:56 +0400 Subject: Sanitize get_console_output in libvirt_conn --- nova/virt/libvirt_conn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index 15adcccee..54186ced0 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -695,7 +695,7 @@ class LibvirtConnection(driver.ComputeDriver): else: fpath = console_log - return self._dump_file(fpath) + return self._dump_file(fpath).decode('utf8','replace').encode('ascii','replace') @exception.wrap_exception def get_ajax_console(self, instance): -- cgit From e49ef5187491d4143de8d0707595c9fb566d4211 Mon Sep 17 00:00:00 2001 From: Yuriy Taraday Date: Fri, 29 Apr 2011 13:20:31 +0400 Subject: Changed test_cloud and fake virt driver to show out the fix. --- nova/tests/test_cloud.py | 2 +- nova/virt/fake.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index c45bdd12c..f271c03f2 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -290,7 +290,7 @@ class CloudTestCase(test.TestCase): instance_id = rv['instancesSet'][0]['instanceId'] output = self.cloud.get_console_output(context=self.context, instance_id=[instance_id]) - self.assertEquals(b64decode(output['output']), 'FAKE CONSOLE OUTPUT') + self.assertEquals(b64decode(output['output']), 'FAKE CONSOLE?OUTPUT') # TODO(soren): We need this until we can stop polling in the rpc code # for unit tests. greenthread.sleep(0.3) diff --git a/nova/virt/fake.py b/nova/virt/fake.py index 33f37b512..59189277d 100644 --- a/nova/virt/fake.py +++ b/nova/virt/fake.py @@ -367,7 +367,8 @@ class FakeConnection(driver.ComputeDriver): return [0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L] def get_console_output(self, instance): - return 'FAKE CONSOLE OUTPUT' + return 'FAKE CONSOLE\xffOUTPUT'.decode('utf8','replace').encode('ascii','replace') + def get_ajax_console(self, instance): return {'token': 'FAKETOKEN', -- cgit From c38871690702ad3b6b39845ae33ee71465a8e95c Mon Sep 17 00:00:00 2001 From: Yuriy Taraday Date: Tue, 3 May 2011 11:05:45 +0400 Subject: Moved reencoding logic to compute manager and cloud EC2 API. --- nova/api/ec2/cloud.py | 2 +- nova/compute/manager.py | 3 ++- nova/tests/test_cloud.py | 3 ++- nova/virt/fake.py | 2 +- nova/virt/libvirt_conn.py | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 94fbf19ff..187f1399f 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -540,7 +540,7 @@ class CloudController(object): now = datetime.datetime.utcnow() return {"InstanceId": ec2_id, "Timestamp": now, - "output": base64.b64encode(output)} + "output": base64.b64encode(output.encode('utf-8','replace'))} def get_ajax_console(self, context, instance_id, **kwargs): ec2_id = instance_id[0] diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 61564cb7d..709b72bbb 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -713,7 +713,8 @@ class ComputeManager(manager.SchedulerDependentManager): instance_ref = self.db.instance_get(context, instance_id) LOG.audit(_("Get console output for instance %s"), instance_id, context=context) - return self.driver.get_console_output(instance_ref) + output = self.driver.get_console_output(instance_ref) + return output.decode('utf8','replace') @exception.wrap_exception def get_ajax_console(self, context, instance_id): diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index f271c03f2..311adfd5b 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -290,7 +290,8 @@ class CloudTestCase(test.TestCase): instance_id = rv['instancesSet'][0]['instanceId'] output = self.cloud.get_console_output(context=self.context, instance_id=[instance_id]) - self.assertEquals(b64decode(output['output']), 'FAKE CONSOLE?OUTPUT') + self.assertEquals(b64decode(output['output']).decode('utf-8'), + u'FAKE CONSOLE\ufffdOUTPUT') # TODO(soren): We need this until we can stop polling in the rpc code # for unit tests. greenthread.sleep(0.3) diff --git a/nova/virt/fake.py b/nova/virt/fake.py index 59189277d..832487deb 100644 --- a/nova/virt/fake.py +++ b/nova/virt/fake.py @@ -367,7 +367,7 @@ class FakeConnection(driver.ComputeDriver): return [0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L] def get_console_output(self, instance): - return 'FAKE CONSOLE\xffOUTPUT'.decode('utf8','replace').encode('ascii','replace') + return 'FAKE CONSOLE\xffOUTPUT' def get_ajax_console(self, instance): diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py index 54186ced0..15adcccee 100644 --- a/nova/virt/libvirt_conn.py +++ b/nova/virt/libvirt_conn.py @@ -695,7 +695,7 @@ class LibvirtConnection(driver.ComputeDriver): else: fpath = console_log - return self._dump_file(fpath).decode('utf8','replace').encode('ascii','replace') + return self._dump_file(fpath) @exception.wrap_exception def get_ajax_console(self, instance): -- cgit From 36aa631dfdea4d2041df3a60d1a294f6a80807b7 Mon Sep 17 00:00:00 2001 From: Yuriy Taraday Date: Tue, 3 May 2011 22:34:00 +0400 Subject: Add missed hyphen. --- 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 709b72bbb..93eb547ba 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -714,7 +714,7 @@ class ComputeManager(manager.SchedulerDependentManager): LOG.audit(_("Get console output for instance %s"), instance_id, context=context) output = self.driver.get_console_output(instance_ref) - return output.decode('utf8','replace') + return output.decode('utf-8','replace') @exception.wrap_exception def get_ajax_console(self, context, instance_id): -- cgit From 8f1d3ec3719f1c8cd587b653d380365ef0c16f51 Mon Sep 17 00:00:00 2001 From: Yuriy Taraday Date: Thu, 5 May 2011 07:50:58 +0400 Subject: Moved all reencoding to compute manager to satisfy both Direct API and internal cloud call. --- nova/api/ec2/cloud.py | 2 +- nova/compute/manager.py | 2 +- nova/tests/test_cloud.py | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 998d339f8..092b80fa2 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -538,7 +538,7 @@ class CloudController(object): now = datetime.datetime.utcnow() return {"InstanceId": ec2_id, "Timestamp": now, - "output": base64.b64encode(output.encode('utf-8','replace'))} + "output": base64.b64encode(output)} def get_ajax_console(self, context, instance_id, **kwargs): ec2_id = instance_id[0] diff --git a/nova/compute/manager.py b/nova/compute/manager.py index e698b0255..84feb98ec 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -750,7 +750,7 @@ class ComputeManager(manager.SchedulerDependentManager): LOG.audit(_("Get console output for instance %s"), instance_id, context=context) output = self.driver.get_console_output(instance_ref) - return output.decode('utf-8','replace') + return output.decode('utf-8','replace').encode('ascii','replace') @exception.wrap_exception def get_ajax_console(self, context, instance_id): diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index 311adfd5b..f271c03f2 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -290,8 +290,7 @@ class CloudTestCase(test.TestCase): instance_id = rv['instancesSet'][0]['instanceId'] output = self.cloud.get_console_output(context=self.context, instance_id=[instance_id]) - self.assertEquals(b64decode(output['output']).decode('utf-8'), - u'FAKE CONSOLE\ufffdOUTPUT') + self.assertEquals(b64decode(output['output']), 'FAKE CONSOLE?OUTPUT') # TODO(soren): We need this until we can stop polling in the rpc code # for unit tests. greenthread.sleep(0.3) -- cgit From 6ee9c2f2b9a7b359336cfad0c5c6b4e1ef78a0da Mon Sep 17 00:00:00 2001 From: Yuriy Taraday Date: Thu, 5 May 2011 07:53:04 +0400 Subject: Removed extra newline after get_console_output in fake virt driver. --- nova/virt/fake.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nova/virt/fake.py b/nova/virt/fake.py index 832487deb..5ac376e46 100644 --- a/nova/virt/fake.py +++ b/nova/virt/fake.py @@ -369,7 +369,6 @@ class FakeConnection(driver.ComputeDriver): def get_console_output(self, instance): return 'FAKE CONSOLE\xffOUTPUT' - def get_ajax_console(self, instance): return {'token': 'FAKETOKEN', 'host': 'fakeajaxconsole.com', -- cgit From 92294ab9b63ecac5baff3c01582faaba63e3b0b1 Mon Sep 17 00:00:00 2001 From: William Wolf Date: Thu, 5 May 2011 15:37:53 -0400 Subject: fixed issue with non-existent variable being passed to ImageNotFound exception --- nova/image/local.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/image/local.py b/nova/image/local.py index b6d8f3ba1..918180bae 100644 --- a/nova/image/local.py +++ b/nova/image/local.py @@ -102,7 +102,7 @@ class LocalImageService(service.BaseImageService): image = cantidate break if image is None: - raise exception.ImageNotFound(image_id=image_id) + raise exception.ImageNotFound(image_id=name) return image def get(self, context, image_id, data): -- cgit From 900e446a41a930b2585950e711948d6e45f37bdd Mon Sep 17 00:00:00 2001 From: William Wolf Date: Thu, 5 May 2011 15:38:45 -0400 Subject: added self to authors --- Authors | 1 + 1 file changed, 1 insertion(+) diff --git a/Authors b/Authors index 1cdeeff99..8adcde4d2 100644 --- a/Authors +++ b/Authors @@ -78,6 +78,7 @@ Trey Morris Tushar Patil Vasiliy Shlykov Vishvananda Ishaya +William Wolf Yoshiaki Tamura Youcef Laribi Zhixue Wu -- cgit From 57fbc3f748389410bad29a82e685e0af2ee26646 Mon Sep 17 00:00:00 2001 From: Yuriy Taraday Date: Fri, 6 May 2011 06:50:48 +0400 Subject: Added myself to Authors file. --- Authors | 1 + 1 file changed, 1 insertion(+) diff --git a/Authors b/Authors index 1cdeeff99..8a1571a09 100644 --- a/Authors +++ b/Authors @@ -80,4 +80,5 @@ Vasiliy Shlykov Vishvananda Ishaya Yoshiaki Tamura Youcef Laribi +Yuriy Taraday Zhixue Wu -- cgit From 6160e3dbdf0dcc736fb650d025da89b269edbf59 Mon Sep 17 00:00:00 2001 From: Yuriy Taraday Date: Fri, 6 May 2011 09:13:46 +0400 Subject: Add two whitespaces to conform PEP8. --- 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 84feb98ec..c6f957073 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -750,7 +750,7 @@ class ComputeManager(manager.SchedulerDependentManager): LOG.audit(_("Get console output for instance %s"), instance_id, context=context) output = self.driver.get_console_output(instance_ref) - return output.decode('utf-8','replace').encode('ascii','replace') + return output.decode('utf-8', 'replace').encode('ascii', 'replace') @exception.wrap_exception def get_ajax_console(self, context, instance_id): -- cgit From 4a0142bdcd3d15c629ca96ba6d3d7fdaa13ed278 Mon Sep 17 00:00:00 2001 From: William Wolf Date: Fri, 6 May 2011 14:11:18 -0400 Subject: added test for show_by_name ImageNotFound exception --- nova/tests/api/openstack/test_images.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index e5dd93c3f..2c329f920 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -75,6 +75,18 @@ class _BaseImageServiceTests(test.TestCase): self.context, 'bad image id') + def test_create_and_show_non_existing_image_by_name(self): + fixture = self._make_fixture('test image') + num_images = len(self.service.index(self.context)) + + image_id = self.service.create(self.context, fixture)['id'] + + self.assertNotEquals(None, image_id) + self.assertRaises(exception.ImageNotFound, + self.service.show_by_name, + self.context, + 'bad image id') + def test_update(self): fixture = self._make_fixture('test image') image_id = self.service.create(self.context, fixture)['id'] -- cgit