Merge "nova security-group-* should support uuid as input"
This commit is contained in:
commit
5b3a94aba8
novaclient
@ -30,6 +30,7 @@ from novaclient.openstack.common import timeutils
|
|||||||
import novaclient.shell
|
import novaclient.shell
|
||||||
from novaclient.tests.v1_1 import fakes
|
from novaclient.tests.v1_1 import fakes
|
||||||
from novaclient.tests import utils
|
from novaclient.tests import utils
|
||||||
|
import novaclient.v1_1.shell
|
||||||
|
|
||||||
|
|
||||||
class ShellFixture(fixtures.Fixture):
|
class ShellFixture(fixtures.Fixture):
|
||||||
@ -1820,3 +1821,35 @@ class ShellTest(utils.TestCase):
|
|||||||
self.assert_called('GET',
|
self.assert_called('GET',
|
||||||
'/os-migrations?cell_name=child1&host=host1'
|
'/os-migrations?cell_name=child1&host=host1'
|
||||||
'&status=finished')
|
'&status=finished')
|
||||||
|
|
||||||
|
|
||||||
|
class GetSecgroupTest(utils.TestCase):
|
||||||
|
def test_with_integer(self):
|
||||||
|
cs = mock.Mock(**{
|
||||||
|
'security_groups.get.return_value': 'sec_group',
|
||||||
|
'security_groups.list.return_value': [],
|
||||||
|
})
|
||||||
|
result = novaclient.v1_1.shell._get_secgroup(cs, '1')
|
||||||
|
self.assertEqual(result, 'sec_group')
|
||||||
|
cs.security_groups.get.assert_called_once_with('1')
|
||||||
|
|
||||||
|
def test_with_uuid(self):
|
||||||
|
cs = mock.Mock(**{
|
||||||
|
'security_groups.get.return_value': 'sec_group',
|
||||||
|
'security_groups.list.return_value': [],
|
||||||
|
})
|
||||||
|
result = novaclient.v1_1.shell._get_secgroup(
|
||||||
|
cs, 'c0c32459-dc5f-44dc-9a0a-473b28bac831')
|
||||||
|
self.assertEqual(result, 'sec_group')
|
||||||
|
cs.security_groups.get.assert_called_once_with(
|
||||||
|
'c0c32459-dc5f-44dc-9a0a-473b28bac831')
|
||||||
|
|
||||||
|
def test_with_an_nonexisting_name(self):
|
||||||
|
cs = mock.Mock(**{
|
||||||
|
'security_groups.get.return_value': 'sec_group',
|
||||||
|
'security_groups.list.return_value': [],
|
||||||
|
})
|
||||||
|
self.assertRaises(exceptions.CommandError,
|
||||||
|
novaclient.v1_1.shell._get_secgroup,
|
||||||
|
cs,
|
||||||
|
'abc')
|
||||||
|
@ -33,6 +33,7 @@ import six
|
|||||||
from novaclient import exceptions
|
from novaclient import exceptions
|
||||||
from novaclient.openstack.common import strutils
|
from novaclient.openstack.common import strutils
|
||||||
from novaclient.openstack.common import timeutils
|
from novaclient.openstack.common import timeutils
|
||||||
|
from novaclient.openstack.common import uuidutils
|
||||||
from novaclient import utils
|
from novaclient import utils
|
||||||
from novaclient.v1_1 import availability_zones
|
from novaclient.v1_1 import availability_zones
|
||||||
from novaclient.v1_1 import quotas
|
from novaclient.v1_1 import quotas
|
||||||
@ -2108,8 +2109,9 @@ def _print_secgroups(secgroups):
|
|||||||
|
|
||||||
|
|
||||||
def _get_secgroup(cs, secgroup):
|
def _get_secgroup(cs, secgroup):
|
||||||
# Check secgroup is an ID
|
# Check secgroup is an ID (nova-network) or UUID (neutron)
|
||||||
if utils.is_integer_like(strutils.safe_encode(secgroup)):
|
if (utils.is_integer_like(strutils.safe_encode(secgroup))
|
||||||
|
or uuidutils.is_uuid_like(secgroup)):
|
||||||
try:
|
try:
|
||||||
return cs.security_groups.get(secgroup)
|
return cs.security_groups.get(secgroup)
|
||||||
except exceptions.NotFound:
|
except exceptions.NotFound:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user