Now OSC server create check keys in --nic

Now OSC command to create server will check all the keys in --nic
and throws an exception if the key is invalid key.

Change-Id: I5482da0ae63d6d4298aa614e4d09bb0547da9ec3
Closes-Bug: #1681411
This commit is contained in:
M V P Nitesh 2017-06-14 18:29:08 +05:30
parent eb793dc8c6
commit fcafd987b0
2 changed files with 70 additions and 6 deletions

View File

@ -651,12 +651,16 @@ class CreateServer(command.ShowOne):
else:
nic_info = {"net-id": "", "v4-fixed-ip": "",
"v6-fixed-ip": "", "port-id": ""}
try:
nic_info.update(dict(kv_str.split("=", 1)
for kv_str in nic_str.split(",")))
except ValueError:
msg = _('Invalid --nic argument %s.') % nic_str
raise exceptions.CommandError(msg)
for kv_str in nic_str.split(","):
k, sep, v = kv_str.partition("=")
if k in nic_info and v:
nic_info[k] = v
else:
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>."))
raise exceptions.CommandError(msg % k)
if bool(nic_info["net-id"]) == bool(nic_info["port-id"]):
msg = _("either network or port should be specified "
"but not both")

View File

@ -795,6 +795,66 @@ class TestServerCreate(TestServer):
self.cmd.take_action, parsed_args)
self.assertNotCalled(self.servers_mock.create)
def test_server_create_with_invalid_network_key(self):
arglist = [
'--image', 'image1',
'--flavor', 'flavor1',
'--nic', 'abcdefgh=12324',
self.new_server.name,
]
verifylist = [
('image', 'image1'),
('flavor', 'flavor1'),
('nic', ['abcdefgh=12324']),
('config_drive', False),
('server_name', self.new_server.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.assertRaises(exceptions.CommandError,
self.cmd.take_action, parsed_args)
self.assertNotCalled(self.servers_mock.create)
def test_server_create_with_empty_network_key_value(self):
arglist = [
'--image', 'image1',
'--flavor', 'flavor1',
'--nic', 'net-id=',
self.new_server.name,
]
verifylist = [
('image', 'image1'),
('flavor', 'flavor1'),
('nic', ['net-id=']),
('config_drive', False),
('server_name', self.new_server.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.assertRaises(exceptions.CommandError,
self.cmd.take_action, parsed_args)
self.assertNotCalled(self.servers_mock.create)
def test_server_create_with_only_network_key(self):
arglist = [
'--image', 'image1',
'--flavor', 'flavor1',
'--nic', 'net-id',
self.new_server.name,
]
verifylist = [
('image', 'image1'),
('flavor', 'flavor1'),
('nic', ['net-id']),
('config_drive', False),
('server_name', self.new_server.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.assertRaises(exceptions.CommandError,
self.cmd.take_action, parsed_args)
self.assertNotCalled(self.servers_mock.create)
@mock.patch.object(common_utils, 'wait_for_status', return_value=True)
def test_server_create_with_wait_ok(self, mock_wait_for_status):
arglist = [