Merge "Ensure *-show input uuid is not empty"

This commit is contained in:
Jenkins 2015-04-24 15:22:28 +00:00 committed by Gerrit Code Review
commit a68770bbb3
7 changed files with 81 additions and 0 deletions

View File

@ -243,3 +243,9 @@ def make_configdrive(path):
tmpzipfile.seek(0) tmpzipfile.seek(0)
return base64.b64encode(tmpzipfile.read()) 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})

View File

@ -14,6 +14,7 @@
import mock import mock
from ironicclient.openstack.common.apiclient import exceptions
from ironicclient.openstack.common import cliutils from ironicclient.openstack.common import cliutils
from ironicclient.tests.unit import utils from ironicclient.tests.unit import utils
import ironicclient.v1.chassis_shell as c_shell import ironicclient.v1.chassis_shell as c_shell
@ -29,3 +30,19 @@ class ChassisShellTest(utils.BaseTestCase):
exp = ['created_at', 'description', 'extra', 'updated_at', 'uuid'] exp = ['created_at', 'description', 'extra', 'updated_at', 'uuid']
act = actual.keys() act = actual.keys()
self.assertEqual(sorted(exp), sorted(act)) 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)

View File

@ -177,6 +177,42 @@ class NodeShellTest(utils.BaseTestCase):
# assert get() wasn't called # assert get() wasn't called
self.assertFalse(client_mock.node.get.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): def test_do_node_set_maintenance_true(self):
client_mock = mock.MagicMock() client_mock = mock.MagicMock()
args = mock.MagicMock() args = mock.MagicMock()

View File

@ -15,6 +15,7 @@
import mock import mock
from ironicclient.common import utils as commonutils from ironicclient.common import utils as commonutils
from ironicclient.openstack.common.apiclient import exceptions
from ironicclient.openstack.common import cliutils from ironicclient.openstack.common import cliutils
from ironicclient.tests.unit import utils from ironicclient.tests.unit import utils
import ironicclient.v1.port_shell as p_shell import ironicclient.v1.port_shell as p_shell
@ -44,6 +45,24 @@ class PortShellTest(utils.BaseTestCase):
# assert get_by_address() wasn't called # assert get_by_address() wasn't called
self.assertFalse(client_mock.port.get_by_address.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): def test_do_port_show_by_address(self):
client_mock = mock.MagicMock() client_mock = mock.MagicMock()
args = mock.MagicMock() args = mock.MagicMock()

View File

@ -27,6 +27,7 @@ def _print_chassis_show(chassis):
@cliutils.arg('chassis', metavar='<chassis>', help="UUID of the chassis.") @cliutils.arg('chassis', metavar='<chassis>', help="UUID of the chassis.")
def do_chassis_show(cc, args): def do_chassis_show(cc, args):
"""Show detailed information about a chassis.""" """Show detailed information about a chassis."""
utils.check_empty_arg(args.chassis, '<chassis>')
chassis = cc.chassis.get(args.chassis) chassis = cc.chassis.get(args.chassis)
_print_chassis_show(chassis) _print_chassis_show(chassis)

View File

@ -42,6 +42,7 @@ def _print_node_show(node):
help='<id> is an instance UUID.') help='<id> is an instance UUID.')
def do_node_show(cc, args): def do_node_show(cc, args):
"""Show detailed information about a node.""" """Show detailed information about a node."""
utils.check_empty_arg(args.node, '<id>')
if args.instance_uuid: if args.instance_uuid:
node = cc.node.get_by_instance_uuid(args.node) node = cc.node.get_by_instance_uuid(args.node)
else: else:

View File

@ -40,6 +40,7 @@ def do_port_show(cc, args):
if args.address: if args.address:
port = cc.port.get_by_address(args.port) port = cc.port.get_by_address(args.port)
else: else:
utils.check_empty_arg(args.port, '<id>')
port = cc.port.get(args.port) port = cc.port.get(args.port)
_print_port_show(port) _print_port_show(port)