Merge "Avoid any capitalization of the name "None""

This commit is contained in:
Zuul 2022-07-28 19:58:19 +00:00 committed by Gerrit Code Review
commit a4b1482157
5 changed files with 45 additions and 3 deletions

View File

@ -194,6 +194,11 @@ class CreateShare(command.ShowOne):
# TODO(s0ru): the table shows 'Field', 'Value'
share_client = self.app.client_manager.share
if parsed_args.name:
if parsed_args.name.capitalize() == 'None':
raise apiclient_exceptions.CommandError(
"Share name cannot be with the value 'None'")
if parsed_args.share_type:
share_type = apiutils.find_resource(share_client.share_types,
parsed_args.share_type).id

View File

@ -14,6 +14,7 @@
#
import argparse
import ddt
from unittest import mock
import uuid
@ -70,6 +71,7 @@ class TestShare(manila_fakes.TestShare):
return shares
@ddt.ddt
class TestShareCreate(TestShare):
def setUp(self):
@ -360,6 +362,28 @@ class TestShareCreate(TestShare):
self.cmd.take_action,
parsed_args)
@ddt.data('None', 'NONE', 'none')
def test_create_share_with_the_name_none(self, name):
arglist = [
'--name', name,
self.new_share.share_proto,
str(self.new_share.size),
'--share-type', self.share_type.id,
]
verifylist = [
('name', name),
('share_proto', self.new_share.share_proto),
('size', self.new_share.size),
('share_type', self.share_type.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.assertRaises(
exceptions.CommandError,
self.cmd.take_action,
parsed_args)
class TestShareDelete(TestShare):

View File

@ -2201,6 +2201,12 @@ class ShellTest(test_utils.TestCase):
self.assertRaises(
exceptions.CommandError, self.run_command, "create nfs 1")
@ddt.data('None', 'NONE', 'none')
def test_create_share_with_the_name_none(self, name):
self.assertRaises(
exceptions.CommandError, self.run_command,
"create nfs 1 --name %s --share-type test_type" % name)
def test_allow_access_cert(self):
self.run_command("access-allow 1234 cert client.example.com")

View File

@ -986,9 +986,10 @@ def do_create(cs, args):
if args.snapshot_id:
snapshot = _find_share_snapshot(cs, args.snapshot_id).id
if args.name == 'None':
raise exceptions.CommandError(
"Share name cannot be with the value 'None'")
if args.name:
if args.name.capitalize() == 'None':
raise exceptions.CommandError(
"Share name cannot be with the value 'None'")
if not args.share_type:
try:

View File

@ -0,0 +1,6 @@
---
fixes:
- |
`Launchpad bug 1909477 <https://bugs.launchpad.net/python-manilaclient/+bug/1909477>`_
has been fixed by prevent sending the share creation request with any capitalization of
the name "None".