diff --git a/cyborgclient/osc/v2/device_profile.py b/cyborgclient/osc/v2/device_profile.py index 55e9f38..c3d89a2 100644 --- a/cyborgclient/osc/v2/device_profile.py +++ b/cyborgclient/osc/v2/device_profile.py @@ -20,6 +20,7 @@ from openstack import exceptions as sdk_exc from osc_lib.command import command from osc_lib import utils as oscutils from oslo_serialization import jsonutils +from oslo_utils import uuidutils from cyborgclient.common import utils from cyborgclient import exceptions as exc @@ -166,6 +167,10 @@ class ShowDeviceProfile(command.ShowOne): def _show_device_profile(acc_client, uuid): """Show detailed info about device_profile.""" + if not uuidutils.is_uuid_like(uuid): + raise exc.CommandError(_('Only UUID of device_profile allowed. ' + 'Invalid input: %s') % uuid) + columns = ( "created_at", "updated_at", diff --git a/cyborgclient/tests/unit/osc/v2/test_device_profile.py b/cyborgclient/tests/unit/osc/v2/test_device_profile.py index 881b0ad..c03fcf0 100644 --- a/cyborgclient/tests/unit/osc/v2/test_device_profile.py +++ b/cyborgclient/tests/unit/osc/v2/test_device_profile.py @@ -12,6 +12,7 @@ # import copy +from cyborgclient import exceptions as exc from cyborgclient.osc.v2 import device_profile as osc_device_profile from cyborgclient.tests.unit.osc.v2 import fakes as acc_fakes @@ -88,3 +89,20 @@ class TestDeviceProfileList(TestDeviceProfile): acc_fakes.device_profile_groups, ), ] self.assertEqual(datalist, list(data)) + + +class TestDeviceProfileShow(TestDeviceProfile): + + def setUp(self): + super(TestDeviceProfileShow, self).setUp() + self.cmd = osc_device_profile.ShowDeviceProfile(self.app, None) + + def test_device_profile_show_with_name(self): + arg_list = [acc_fakes.device_profile_name] + verify_list = [] + parsed_args = self.check_parser(self.cmd, arg_list, verify_list) + result = self.assertRaises(exc.CommandError, + self.cmd.take_action, + parsed_args) + self.assertIn("Only UUID of device_profile allowed. " + "Invalid input: fake_devprof_name", str(result))