From 1e29f2b16ac56191a145c4cd96d2f55875c485e6 Mon Sep 17 00:00:00 2001 From: John Tran Date: Fri, 25 Mar 2011 13:17:51 -0700 Subject: [PATCH 1/8] added a simple test for describe_images with mock for detail funciton --- Authors | 1 + nova/tests/test_cloud.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/Authors b/Authors index 1679d2de..39a85195 100644 --- a/Authors +++ b/Authors @@ -29,6 +29,7 @@ Jesse Andrews Joe Heck Joel Moore John Dewey +John Tran Jonathan Bryce Jordan Rinke Josh Durgin diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index cf8ee7ef..2f0571ca 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -81,7 +81,12 @@ class CloudTestCase(test.TestCase): def fake_show(meh, context, id): return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1}} + def fake_detail(meh, context): + return [{'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1, + 'type':'machine'}}] + self.stubs.Set(local.LocalImageService, 'show', fake_show) + self.stubs.Set(local.LocalImageService, 'detail', fake_detail) self.stubs.Set(local.LocalImageService, 'show_by_name', fake_show) def tearDown(self): @@ -224,6 +229,11 @@ class CloudTestCase(test.TestCase): db.service_destroy(self.context, comp1['id']) db.service_destroy(self.context, comp2['id']) + def test_describe_images(self): + result = self.cloud.describe_images(self.context) + result = result['imagesSet'][0] + self.assertEqual(result['imageId'], 'ami-00000001') + def test_console_output(self): instance_type = FLAGS.default_instance_type max_count = 1 From 1222d65bf64531ee4dcbd25963f981395e70718f Mon Sep 17 00:00:00 2001 From: John Tran Date: Mon, 28 Mar 2011 11:29:23 -0700 Subject: [PATCH 2/8] when image_id provided cannot be found, returns more informative error message. --- nova/tests/test_cloud.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index 2f0571ca..8043d467 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -41,6 +41,7 @@ from nova.api.ec2 import cloud from nova.api.ec2 import ec2utils from nova.image import local from nova.objectstore import image +from nova.exception import NotEmpty, NotFound FLAGS = flags.FLAGS @@ -85,8 +86,12 @@ class CloudTestCase(test.TestCase): return [{'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1, 'type':'machine'}}] + def fake_delete(meh, context, id): + return None + self.stubs.Set(local.LocalImageService, 'show', fake_show) self.stubs.Set(local.LocalImageService, 'detail', fake_detail) + self.stubs.Set(local.LocalImageService, 'delete', fake_delete) self.stubs.Set(local.LocalImageService, 'show_by_name', fake_show) def tearDown(self): @@ -234,6 +239,16 @@ class CloudTestCase(test.TestCase): result = result['imagesSet'][0] self.assertEqual(result['imageId'], 'ami-00000001') + def test_deregister_image(self): + deregister_image = self.cloud.deregister_image + """When provided a valid image, should be successful""" + result1 = deregister_image(self.context, 'ami-00000001') + self.assertEqual(result1['imageId'], 'ami-00000001') + """Invalid image should throw an NotFound exception""" + self.stubs.UnsetAll() + self.assertRaises(NotFound, deregister_image, + self.context, 'ami-bad001') + def test_console_output(self): instance_type = FLAGS.default_instance_type max_count = 1 From f2c3e5b66c272f526929f207ab4589599722ceaa Mon Sep 17 00:00:00 2001 From: John Tran Date: Mon, 28 Mar 2011 18:16:55 -0700 Subject: [PATCH 3/8] made changes per code review: 1) removed import of image from objectstore 2) changed to comments instaed of triple quotes. --- nova/tests/test_cloud.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index 20c85d79..b8a95e45 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -41,8 +41,7 @@ from nova.compute import power_state from nova.api.ec2 import cloud from nova.api.ec2 import ec2utils from nova.image import local -from nova.objectstore import image -from nova.exception import NotEmpty, NotFound +from nova.exception import NotFound FLAGS = flags.FLAGS @@ -75,16 +74,7 @@ class CloudTestCase(test.TestCase): def fake_show(meh, context, id): return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1}} - def fake_detail(meh, context): - return [{'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1, - 'type':'machine'}}] - - def fake_delete(meh, context, id): - return None - self.stubs.Set(local.LocalImageService, 'show', fake_show) - self.stubs.Set(local.LocalImageService, 'detail', fake_detail) - self.stubs.Set(local.LocalImageService, 'delete', fake_delete) self.stubs.Set(local.LocalImageService, 'show_by_name', fake_show) def tearDown(self): @@ -228,17 +218,27 @@ class CloudTestCase(test.TestCase): db.service_destroy(self.context, comp2['id']) def test_describe_images(self): + def fake_detail(meh, context): + return [{'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1, + 'type':'machine'}}] + self.stubs.Set(local.LocalImageService, 'detail', fake_detail) result = self.cloud.describe_images(self.context) result = result['imagesSet'][0] self.assertEqual(result['imageId'], 'ami-00000001') def test_deregister_image(self): deregister_image = self.cloud.deregister_image - """When provided a valid image, should be successful""" + def fake_delete(meh, context, id): + return None + self.stubs.Set(local.LocalImageService, 'delete', fake_delete) + # valid image result1 = deregister_image(self.context, 'ami-00000001') self.assertEqual(result1['imageId'], 'ami-00000001') - """Invalid image should throw an NotFound exception""" + # invalid image self.stubs.UnsetAll() + def fake_detail_empty(meh, context): + return [] + self.stubs.Set(local.LocalImageService, 'detail', fake_detail_empty) self.assertRaises(NotFound, deregister_image, self.context, 'ami-bad001') From 5b4be8d7e563914cabff3e137c50113190d16b83 Mon Sep 17 00:00:00 2001 From: John Tran Date: Mon, 28 Mar 2011 18:19:56 -0700 Subject: [PATCH 4/8] cleaned up var name --- nova/tests/test_cloud.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index b8a95e45..07e52a6b 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -232,8 +232,8 @@ class CloudTestCase(test.TestCase): return None self.stubs.Set(local.LocalImageService, 'delete', fake_delete) # valid image - result1 = deregister_image(self.context, 'ami-00000001') - self.assertEqual(result1['imageId'], 'ami-00000001') + result = deregister_image(self.context, 'ami-00000001') + self.assertEqual(result['imageId'], 'ami-00000001') # invalid image self.stubs.UnsetAll() def fake_detail_empty(meh, context): From 71aaab3876511858e05e64c4757b9d6397a13ff0 Mon Sep 17 00:00:00 2001 From: John Tran Date: Tue, 29 Mar 2011 13:43:00 -0700 Subject: [PATCH 5/8] added blank lines in between functions & removed the test_describe_images (was meant for a diff bug lp682888) --- nova/tests/test_cloud.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index 07e52a6b..582e40e0 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -217,27 +217,22 @@ class CloudTestCase(test.TestCase): db.service_destroy(self.context, comp1['id']) db.service_destroy(self.context, comp2['id']) - def test_describe_images(self): - def fake_detail(meh, context): - return [{'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1, - 'type':'machine'}}] - self.stubs.Set(local.LocalImageService, 'detail', fake_detail) - result = self.cloud.describe_images(self.context) - result = result['imagesSet'][0] - self.assertEqual(result['imageId'], 'ami-00000001') - def test_deregister_image(self): deregister_image = self.cloud.deregister_image + def fake_delete(meh, context, id): return None + self.stubs.Set(local.LocalImageService, 'delete', fake_delete) # valid image result = deregister_image(self.context, 'ami-00000001') self.assertEqual(result['imageId'], 'ami-00000001') # invalid image self.stubs.UnsetAll() + def fake_detail_empty(meh, context): return [] + self.stubs.Set(local.LocalImageService, 'detail', fake_detail_empty) self.assertRaises(NotFound, deregister_image, self.context, 'ami-bad001') From 56f28d01c6a578a2e58a96e616363235556140a0 Mon Sep 17 00:00:00 2001 From: John Tran Date: Wed, 30 Mar 2011 12:37:56 -0700 Subject: [PATCH 6/8] updated per code review, replaced NotFound with exception.NotFound --- nova/tests/test_cloud.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index 582e40e0..145da8ad 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -36,12 +36,12 @@ from nova import rpc from nova import service from nova import test from nova import utils +from nova import exception from nova.auth import manager from nova.compute import power_state from nova.api.ec2 import cloud from nova.api.ec2 import ec2utils from nova.image import local -from nova.exception import NotFound FLAGS = flags.FLAGS @@ -234,7 +234,7 @@ class CloudTestCase(test.TestCase): return [] self.stubs.Set(local.LocalImageService, 'detail', fake_detail_empty) - self.assertRaises(NotFound, deregister_image, + self.assertRaises(exception.NotFound, deregister_image, self.context, 'ami-bad001') def test_console_output(self): From 0c0d6b8a496e5b2dcb37c380460cb039dcf71f68 Mon Sep 17 00:00:00 2001 From: John Tran Date: Wed, 30 Mar 2011 12:44:22 -0700 Subject: [PATCH 7/8] removed trailing whitespace --- nova/tests/test_cloud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index 145da8ad..cde8041f 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -36,7 +36,7 @@ from nova import rpc from nova import service from nova import test from nova import utils -from nova import exception +from nova import exception from nova.auth import manager from nova.compute import power_state from nova.api.ec2 import cloud From 0f0caa88adfe375d7416f04ccd1b3fa315292cae Mon Sep 17 00:00:00 2001 From: John Tran Date: Thu, 12 May 2011 12:51:03 -0700 Subject: [PATCH 8/8] incorporated ImageNotFound instead of NotFound --- nova/tests/test_cloud.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index 82dd14cb..af1dbfd4 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -282,7 +282,7 @@ class CloudTestCase(test.TestCase): def test_deregister_image(self): deregister_image = self.cloud.deregister_image - def fake_delete(meh, context, id): + def fake_delete(self, context, id): return None self.stubs.Set(local.LocalImageService, 'delete', fake_delete) @@ -292,11 +292,11 @@ class CloudTestCase(test.TestCase): # invalid image self.stubs.UnsetAll() - def fake_detail_empty(meh, context): + def fake_detail_empty(self, context): return [] self.stubs.Set(local.LocalImageService, 'detail', fake_detail_empty) - self.assertRaises(exception.NotFound, deregister_image, + self.assertRaises(exception.ImageNotFound, deregister_image, self.context, 'ami-bad001') def test_console_output(self):