Add checks for showing dp with name
This patch adds checking input arg. If not uuid, raise CommandError with output like 'Only UUID of device_profile allowed'. Closes-Bug: #1936877 Change-Id: I24999d0f39cbd027ef5c797ed2e9bf0bbfe8a793
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user