From 5d5dc3b26b62c0e259b0b9dac8158d7f62c9abe7 Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Tue, 16 Jun 2015 01:07:18 +0000 Subject: [PATCH] Fix test_create_security_group_with_no_name test_create_security_group_with_no_name should be for existence check of "name" parameter on "create a security group" API. But current test just checks the existence of "security_group" parameter instead because the test request body structure was wrong. This patch fixes it. In addition, this patch adds the type check of "name" parameter to the MockClient because Neutron receives None value as "name" parameter, it returns BadRequest to Nova. I11da9ec32b64b5a109d65afe77aa32be71a807a3 fixes the error handling already, but the MockClient was not fixed. So this patch fixes it also. Change-Id: I4697b9a2b9ad2a13fbb4a08c0437545cd24c9c2a --- .../compute/contrib/test_neutron_security_groups.py | 9 +++++++++ .../openstack/compute/contrib/test_security_groups.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/nova/tests/unit/api/openstack/compute/contrib/test_neutron_security_groups.py b/nova/tests/unit/api/openstack/compute/contrib/test_neutron_security_groups.py index 9f63c0d1da..01d76b8778 100644 --- a/nova/tests/unit/api/openstack/compute/contrib/test_neutron_security_groups.py +++ b/nova/tests/unit/api/openstack/compute/contrib/test_neutron_security_groups.py @@ -12,6 +12,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +import six import uuid import mock @@ -638,6 +639,14 @@ class MockClient(object): def create_security_group(self, body=None): s = body.get('security_group') + if not isinstance(s.get('name', ''), six.string_types): + msg = ('BadRequest: Invalid input for name. Reason: ' + 'None is not a valid string.') + raise n_exc.BadRequest(message=msg) + if not isinstance(s.get('description.', ''), six.string_types): + msg = ('BadRequest: Invalid input for description. Reason: ' + 'None is not a valid string.') + raise n_exc.BadRequest(message=msg) if len(s.get('name')) > 255 or len(s.get('description')) > 255: msg = 'Security Group name great than 255' raise n_exc.NeutronClientException(message=msg, status_code=401) diff --git a/nova/tests/unit/api/openstack/compute/contrib/test_security_groups.py b/nova/tests/unit/api/openstack/compute/contrib/test_security_groups.py index 9669a3eb8a..580386ea84 100644 --- a/nova/tests/unit/api/openstack/compute/contrib/test_security_groups.py +++ b/nova/tests/unit/api/openstack/compute/contrib/test_security_groups.py @@ -164,7 +164,7 @@ class TestSecurityGroupsV21(test.TestCase): req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups') self.assertRaises(webob.exc.HTTPBadRequest, - self.controller.create, req, sg) + self.controller.create, req, {'security_group': sg}) self._assert_no_security_groups_reserved(req.environ['nova.context'])