Merge "Update help for --nic opt and make net-id or port-id required"

This commit is contained in:
Jenkins 2013-06-21 13:48:52 +00:00 committed by Gerrit Code Review
commit 05ca996e67
2 changed files with 37 additions and 10 deletions

View File

@ -338,6 +338,21 @@ class ShellTest(utils.TestCase):
},
)
def tets_boot_nics_no_value(self):
cmd = ('boot --image 1 --flavor 1 '
'--nic net-id some-server')
self.assertRaises(exceptions.CommandError, self.run_command, cmd)
def test_boot_nics_random_key(self):
cmd = ('boot --image 1 --flavor 1 '
'--nic net-id=a=c,v4-fixed-ip=10.0.0.1,foo=bar some-server')
self.assertRaises(exceptions.CommandError, self.run_command, cmd)
def test_boot_nics_no_netid_or_portid(self):
cmd = ('boot --image 1 --flavor 1 '
'--nic v4-fixed-ip=10.0.0.1 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')
expected_file_data = open(testfile).read().encode('base64')

View File

@ -141,16 +141,26 @@ def _boot(cs, args, reservation_id=None, min_count=None, max_count=None):
nics = []
for nic_str in args.nics:
err_msg = ("Invalid nic argument '%s'. Nic arguments must be of the "
"form --nic <net-id=net-uuid,v4-fixed-ip=ip-addr,"
"port-id=port-uuid>, with at minimum net-id or port-id "
"specified." % nic_str)
nic_info = {"net-id": "", "v4-fixed-ip": "", "port-id": ""}
for kv_str in nic_str.split(","):
try:
k, v = kv_str.split("=", 1)
nic_info[k] = v
except ValueError as e:
raise exceptions.CommandError(
"Invalid nic argument '%s'. Nic arguments must be of the "
"form --nic <net-id=net-uuid[,v4-fixed-ip=ip-addr]"
"[,port-id=port-uuid]>" % nic_str)
raise exceptions.CommandError(err_msg)
if k in nic_info:
nic_info[k] = v
else:
raise exceptions.CommandError(err_msg)
if not nic_info['net-id'] and not nic_info['port-id']:
raise exceptions.CommandError(err_msg)
nics.append(nic_info)
hints = {}
@ -269,11 +279,13 @@ def _boot(cs, args, reservation_id=None, min_count=None, max_count=None):
action='append',
dest='nics',
default=[],
help="Create a NIC on the server.\n"
"Specify option multiple times to create multiple NICs.\n"
"net-id: attach NIC to network with this UUID (optional)\n"
"v4-fixed-ip: IPv4 fixed address for NIC (optional).\n"
"port-id: attach NIC to port with this UUID (optional)")
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), "
"v4-fixed-ip: IPv4 fixed address for NIC (optional), "
"port-id: attach NIC to port with this UUID "
"(required if no net-id)")
@utils.arg('--config-drive',
metavar="<value>",
dest='config_drive',