Ensure *-show input uuid is not empty
Ironic *-show does not ensure that uuid are not empty. This patch adds checks to the client to ensure that command line arguments are not empty strings or only whitespace. It will raise a command exception if *-show command line argument is an empty string or only whitespace. Change-Id: Ia34957922006da5ecbbfc7483040d67ac51f0ada Closes-Bug: 1442436
This commit is contained in:
parent
cbc1ce5b0a
commit
cec37d5a67
@ -245,3 +245,9 @@ def make_configdrive(path):
|
||||
|
||||
tmpzipfile.seek(0)
|
||||
return base64.b64encode(tmpzipfile.read())
|
||||
|
||||
|
||||
def check_empty_arg(arg, arg_descriptor):
|
||||
if not arg.strip():
|
||||
raise exc.CommandError(_('%(arg)s cannot be empty or only have blank'
|
||||
' spaces') % {'arg': arg_descriptor})
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
import mock
|
||||
|
||||
from ironicclient.openstack.common.apiclient import exceptions
|
||||
from ironicclient.openstack.common import cliutils
|
||||
from ironicclient.tests.unit import utils
|
||||
import ironicclient.v1.chassis_shell as c_shell
|
||||
@ -31,3 +32,19 @@ class ChassisShellTest(utils.BaseTestCase):
|
||||
exp = ['created_at', 'description', 'extra', 'updated_at', 'uuid']
|
||||
act = actual.keys()
|
||||
self.assertEqual(sorted(exp), sorted(act))
|
||||
|
||||
def test_do_chassis_show_space_uuid(self):
|
||||
client_mock = mock.MagicMock()
|
||||
args = mock.MagicMock()
|
||||
args.chassis = ' '
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
c_shell.do_chassis_show,
|
||||
client_mock, args)
|
||||
|
||||
def test_do_chassis_show_empty_uuid(self):
|
||||
client_mock = mock.MagicMock()
|
||||
args = mock.MagicMock()
|
||||
args.chassis = ''
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
c_shell.do_chassis_show,
|
||||
client_mock, args)
|
||||
|
@ -179,6 +179,42 @@ class NodeShellTest(utils.BaseTestCase):
|
||||
# assert get() wasn't called
|
||||
self.assertFalse(client_mock.node.get.called)
|
||||
|
||||
def test_do_node_show_by_space_node_uuid(self):
|
||||
client_mock = mock.MagicMock()
|
||||
args = mock.MagicMock()
|
||||
args.node = ' '
|
||||
args.instance_uuid = False
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
n_shell.do_node_show,
|
||||
client_mock, args)
|
||||
|
||||
def test_do_node_show_by_space_instance_uuid(self):
|
||||
client_mock = mock.MagicMock()
|
||||
args = mock.MagicMock()
|
||||
args.node = ' '
|
||||
args.instance_uuid = True
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
n_shell.do_node_show,
|
||||
client_mock, args)
|
||||
|
||||
def test_do_node_show_by_empty_node_uuid(self):
|
||||
client_mock = mock.MagicMock()
|
||||
args = mock.MagicMock()
|
||||
args.node = ''
|
||||
args.instance_uuid = False
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
n_shell.do_node_show,
|
||||
client_mock, args)
|
||||
|
||||
def test_do_node_show_by_empty_instance_uuid(self):
|
||||
client_mock = mock.MagicMock()
|
||||
args = mock.MagicMock()
|
||||
args.node = ''
|
||||
args.instance_uuid = True
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
n_shell.do_node_show,
|
||||
client_mock, args)
|
||||
|
||||
def test_do_node_set_maintenance_true(self):
|
||||
client_mock = mock.MagicMock()
|
||||
args = mock.MagicMock()
|
||||
|
@ -17,6 +17,7 @@
|
||||
import mock
|
||||
|
||||
from ironicclient.common import utils as commonutils
|
||||
from ironicclient.openstack.common.apiclient import exceptions
|
||||
from ironicclient.openstack.common import cliutils
|
||||
from ironicclient.tests.unit import utils
|
||||
import ironicclient.v1.port_shell as p_shell
|
||||
@ -46,6 +47,24 @@ class PortShellTest(utils.BaseTestCase):
|
||||
# assert get_by_address() wasn't called
|
||||
self.assertFalse(client_mock.port.get_by_address.called)
|
||||
|
||||
def test_do_port_show_space_uuid(self):
|
||||
client_mock = mock.MagicMock()
|
||||
args = mock.MagicMock()
|
||||
args.port = ' '
|
||||
args.address = False
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
p_shell.do_port_show,
|
||||
client_mock, args)
|
||||
|
||||
def test_do_port_show_empty_uuid(self):
|
||||
client_mock = mock.MagicMock()
|
||||
args = mock.MagicMock()
|
||||
args.port = ''
|
||||
args.address = False
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
p_shell.do_port_show,
|
||||
client_mock, args)
|
||||
|
||||
def test_do_port_show_by_address(self):
|
||||
client_mock = mock.MagicMock()
|
||||
args = mock.MagicMock()
|
||||
|
@ -29,6 +29,7 @@ def _print_chassis_show(chassis):
|
||||
@cliutils.arg('chassis', metavar='<chassis>', help="UUID of the chassis.")
|
||||
def do_chassis_show(cc, args):
|
||||
"""Show detailed information about a chassis."""
|
||||
utils.check_empty_arg(args.chassis, '<chassis>')
|
||||
chassis = cc.chassis.get(args.chassis)
|
||||
_print_chassis_show(chassis)
|
||||
|
||||
|
@ -44,6 +44,7 @@ def _print_node_show(node):
|
||||
help='<id> is an instance UUID.')
|
||||
def do_node_show(cc, args):
|
||||
"""Show detailed information about a node."""
|
||||
utils.check_empty_arg(args.node, '<id>')
|
||||
if args.instance_uuid:
|
||||
node = cc.node.get_by_instance_uuid(args.node)
|
||||
else:
|
||||
|
@ -42,6 +42,7 @@ def do_port_show(cc, args):
|
||||
if args.address:
|
||||
port = cc.port.get_by_address(args.port)
|
||||
else:
|
||||
utils.check_empty_arg(args.port, '<id>')
|
||||
port = cc.port.get(args.port)
|
||||
_print_port_show(port)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user