Make port-id and net-id keys mutually exclusive

These keys are never used together, and port-id always takes precedence
in Nova API when present. This patch makes these parameters mutually
exclusive and updates help strings accordingly.

Change-Id: I207dc637cb69d9ab3ff6024a657d2c1890057b4d
Closes-Bug: #1314097
This commit is contained in:
Pavlo Shchelokovskyy 2014-04-29 18:56:04 +03:00
parent 02ee4fc79e
commit 9f6679ebd3
4 changed files with 18 additions and 8 deletions

View File

@ -539,6 +539,11 @@ class ShellTest(utils.TestCase):
'--nic v4-fixed-ip=10.0.0.1 some-server')
self.assertRaises(exceptions.CommandError, self.run_command, cmd)
def test_boot_nics_netid_and_portid(self):
cmd = ('boot --image 1 --flavor 1 '
'--nic port-id=some=port,net-id=some=net some-server')
self.assertRaises(exceptions.CommandError, self.run_command, cmd)
def test_boot_files(self):
testfile = os.path.join(os.path.dirname(__file__), 'testfile.txt')
data = open(testfile).read()

View File

@ -469,6 +469,11 @@ class ShellTest(utils.TestCase):
'--nic v4-fixed-ip=10.0.0.1 some-server')
self.assertRaises(exceptions.CommandError, self.run_command, cmd)
def test_boot_nics_netid_and_portid(self):
cmd = ('boot --image 1 --flavor 1 '
'--nic port-id=some=port,net-id=some=net some-server')
self.assertRaises(exceptions.CommandError, self.run_command, cmd)
def test_boot_num_instances(self):
self.run_command('boot --image 1 --flavor 1 --num-instances 3 server')
self.assert_called_anytime(

View File

@ -227,7 +227,7 @@ def _boot(cs, args):
err_msg = (_("Invalid nic argument '%s'. Nic arguments must be of "
"the form --nic <net-id=net-uuid,v4-fixed-ip=ip-addr,"
"v6-fixed-ip=ip-addr,port-id=port-uuid>, with at minimum "
"net-id or port-id specified.") % nic_str)
"net-id or port-id (but not both) specified.") % nic_str)
nic_info = {"net-id": "", "v4-fixed-ip": "", "v6-fixed-ip": "",
"port-id": ""}
@ -242,7 +242,7 @@ def _boot(cs, args):
else:
raise exceptions.CommandError(err_msg)
if not nic_info['net-id'] and not nic_info['port-id']:
if bool(nic_info['net-id']) == bool(nic_info['port-id']):
raise exceptions.CommandError(err_msg)
nics.append(nic_info)
@ -401,11 +401,11 @@ def _boot(cs, args):
help=_("Create a NIC on the server. "
"Specify option multiple times to create multiple NICs. "
"net-id: attach NIC to network with this UUID "
"(required if no port-id), "
"(either port-id or net-id must be provided), "
"v4-fixed-ip: IPv4 fixed address for NIC (optional), "
"v6-fixed-ip: IPv6 fixed address for NIC (optional), "
"port-id: attach NIC to port with this UUID "
"(required if no net-id)"))
"(either port-id or net-id must be provided)."))
@utils.arg('--config-drive',
metavar="<value>",
dest='config_drive',

View File

@ -138,7 +138,7 @@ def _boot(cs, args):
err_msg = ("Invalid nic argument '%s'. Nic arguments must be of the "
"form --nic <net-id=net-uuid,v4-fixed-ip=ip-addr,"
"v6-fixed-ip=ip-addr,port-id=port-uuid>, with at minimum "
"net-id or port-id specified." % nic_str)
"net-id or port-id (but not both) specified." % nic_str)
nic_info = {"net-id": "", "v4-fixed-ip": "", "v6-fixed-ip": "",
"port-id": ""}
@ -153,7 +153,7 @@ def _boot(cs, args):
else:
raise exceptions.CommandError(err_msg)
if not nic_info['net-id'] and not nic_info['port-id']:
if bool(nic_info['net-id']) == bool(nic_info['port-id']):
raise exceptions.CommandError(err_msg)
nics.append(nic_info)
@ -277,11 +277,11 @@ def _boot(cs, args):
help="Create a NIC on the server. "
"Specify option multiple times to create multiple NICs. "
"net-id: attach NIC to network with this UUID "
"(required if no port-id), "
"(either port-id or net-id must be provided), "
"v4-fixed-ip: IPv4 fixed address for NIC (optional), "
"v6-fixed-ip: IPv6 fixed address for NIC (optional), "
"port-id: attach NIC to port with this UUID "
"(required if no net-id)")
"(either port-id or net-id must be provided).")
@utils.arg('--config-drive',
metavar="<value>",
dest='config_drive',