From d29d2fbea9bd8aa48d11cc3d999b1e4d4d1f1f8e Mon Sep 17 00:00:00 2001 From: Justin Shepherd Date: Mon, 29 Aug 2011 20:24:53 -0500 Subject: [PATCH] Fixes Bug: lp825024 Added 'size' to the unsupported_fields array in image_add(). Added a test case to functional/test_misc.py that tests for this bug. Change-Id: Ib223b31656cd75de0b95a0186ea907f93b6c943e --- bin/glance | 2 +- glance/tests/functional/test_misc.py | 36 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/bin/glance b/bin/glance index 7308b5d7d7..76af8ff4e9 100755 --- a/bin/glance +++ b/bin/glance @@ -211,7 +211,7 @@ EXAMPLES 'container_format': fields.pop('container_format', 'ovf')} # Strip any args that are not supported - unsupported_fields = ['status'] + unsupported_fields = ['status', 'size'] for field in unsupported_fields: if field in fields.keys(): print 'Found non-settable field %s. Removing.' % field diff --git a/glance/tests/functional/test_misc.py b/glance/tests/functional/test_misc.py index 1b9cdfd7e0..165efc8b3a 100644 --- a/glance/tests/functional/test_misc.py +++ b/glance/tests/functional/test_misc.py @@ -19,6 +19,7 @@ import httplib2 import json import os +import tempfile from glance.tests import functional from glance.tests.utils import execute @@ -117,3 +118,38 @@ def test_exception_not_eaten_from_registry_to_api(self): "in output: %s" % out) self.stop_servers() + + def test_api_treats_size_as_a_normal_property(self): + """ + A test for LP bug #825024 -- glance client currently + treats size as a normal property. + """ + + self.cleanup() + self.start_servers() + + # 1. POST /images with public image named Image1 + # attribute and no custom properties. Verify a 200 OK is returned + with tempfile.NamedTemporaryFile() as image_file: + image_file.write("XXX") + image_file.flush() + image_file_name = image_file.name + cmd = "bin/glance --port=%d add is_public=True name=MyImage "\ + "size=12345 < %s" % (self.api_port, image_file_name) + + exitcode, out, err = execute(cmd) + + self.assertEqual(0, exitcode) + self.assertTrue('Found non-settable field size. Removing.' in out) + self.assertTrue('Added new image with ID: 1' in out) + + # 2. Verify image added as public image + cmd = "bin/glance --port=%d show %d" % (self.api_port, 1) + + exitcode, out, err = execute(cmd) + + self.assertEqual(0, exitcode) + lines = out.split("\n")[2:-1] + self.assertFalse("12345" in out) + + self.stop_servers()