Correct the network parameter when creating server
* Add support of specifying port-id * Remove the port-type parameter Change-Id: I2b56e83a1e5543457d821fa8d43d65285c87f6df Closes-Bug: #1715598
This commit is contained in:
parent
991f3b86e8
commit
ec673bcec7
@ -105,10 +105,9 @@ class CreateServer(command.ShowOne):
|
|||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--nic",
|
"--nic",
|
||||||
metavar="net-id=NETWORK[,port-type=PORT_TYPE]",
|
metavar="<net-id=NETWORK, port-id=PORT>",
|
||||||
required=True,
|
required=True,
|
||||||
required_keys=['net-id'],
|
optional_keys=['net-id', 'port-id'],
|
||||||
optional_keys=['port-type'],
|
|
||||||
action=parseractions.MultiKeyValueAction,
|
action=parseractions.MultiKeyValueAction,
|
||||||
help=_("Create a NIC on the server. "
|
help=_("Create a NIC on the server. "
|
||||||
"Specify option multiple times to create multiple NICs."),
|
"Specify option multiple times to create multiple NICs."),
|
||||||
@ -181,12 +180,12 @@ class CreateServer(command.ShowOne):
|
|||||||
parsed_args.image)
|
parsed_args.image)
|
||||||
|
|
||||||
for nic in parsed_args.nic:
|
for nic in parsed_args.nic:
|
||||||
if 'port-type' in nic:
|
|
||||||
nic['port_type'] = nic['port-type']
|
|
||||||
del nic['port-type']
|
|
||||||
if 'net-id' in nic:
|
if 'net-id' in nic:
|
||||||
nic['net_id'] = nic['net-id']
|
nic['net_id'] = nic['net-id']
|
||||||
del nic['net-id']
|
del nic['net-id']
|
||||||
|
if 'port-id' in nic:
|
||||||
|
nic['port_id'] = nic['port-id']
|
||||||
|
del nic['port-id']
|
||||||
|
|
||||||
files = {}
|
files = {}
|
||||||
for f in parsed_args.file:
|
for f in parsed_args.file:
|
||||||
@ -658,7 +657,7 @@ class ShowServerNetworkInfo(command.Lister):
|
|||||||
)
|
)
|
||||||
data = bc_client.server.get_server_nics(server.uuid)
|
data = bc_client.server.get_server_nics(server.uuid)
|
||||||
columns = ('network_id', 'port_id', 'mac_address', 'fixed_ips',
|
columns = ('network_id', 'port_id', 'mac_address', 'fixed_ips',
|
||||||
'floating_ip', 'port_type')
|
'floating_ip')
|
||||||
formatters = {'fixed_ips': lambda s: json.dumps(s, indent=4)}
|
formatters = {'fixed_ips': lambda s: json.dumps(s, indent=4)}
|
||||||
return (columns,
|
return (columns,
|
||||||
(utils.get_item_properties(
|
(utils.get_item_properties(
|
||||||
|
@ -81,12 +81,12 @@ class TestServerCreate(TestServer):
|
|||||||
('image', image_id)]
|
('image', image_id)]
|
||||||
called_networks = copy.deepcopy(networks)
|
called_networks = copy.deepcopy(networks)
|
||||||
for nic in called_networks:
|
for nic in called_networks:
|
||||||
if 'port-type' in nic:
|
|
||||||
nic['port_type'] = nic['port-type']
|
|
||||||
del nic['port-type']
|
|
||||||
if 'net-id' in nic:
|
if 'net-id' in nic:
|
||||||
nic['net_id'] = nic['net-id']
|
nic['net_id'] = nic['net-id']
|
||||||
del nic['net-id']
|
del nic['net-id']
|
||||||
|
if 'port-id' in nic:
|
||||||
|
nic['port_id'] = nic['port-id']
|
||||||
|
del nic['port-id']
|
||||||
called_data = {'server': {'name': name,
|
called_data = {'server': {'name': name,
|
||||||
'image_uuid': image_id,
|
'image_uuid': image_id,
|
||||||
'flavor_uuid': flavor_id,
|
'flavor_uuid': flavor_id,
|
||||||
@ -94,17 +94,12 @@ class TestServerCreate(TestServer):
|
|||||||
'min_count': 1,
|
'min_count': 1,
|
||||||
'max_count': 1}}
|
'max_count': 1}}
|
||||||
for network in networks:
|
for network in networks:
|
||||||
network_id = network.get('net-id')
|
if 'net-id' in network:
|
||||||
port_type = network.get('port-type')
|
arglist.extend(['--nic', 'net-id=' + network['net-id']])
|
||||||
if port_type:
|
verifylist.append(('nic', [{'net-id': network['net-id']}]))
|
||||||
arglist.extend(
|
elif 'port-id' in network:
|
||||||
['--nic',
|
arglist.extend(['--nic', 'port-id=' + network['port-id']])
|
||||||
'net-id=' + network_id + ',port-type=' + port_type])
|
verifylist.append(('nic', [{'port-id': network['port-id']}]))
|
||||||
verifylist.append(
|
|
||||||
('nic', [{'net-id': network_id, 'port-type': port_type}]))
|
|
||||||
else:
|
|
||||||
arglist.extend(['--nic', 'net-id=' + network_id])
|
|
||||||
verifylist.append(('nic', [{'net-id': network_id}]))
|
|
||||||
if description:
|
if description:
|
||||||
arglist.extend(['--description', description])
|
arglist.extend(['--description', description])
|
||||||
verifylist.append(('description', description))
|
verifylist.append(('description', description))
|
||||||
@ -187,17 +182,6 @@ class TestServerCreate(TestServer):
|
|||||||
name, flavor_id, image_id,
|
name, flavor_id, image_id,
|
||||||
networks, availability_zone=fake_az)
|
networks, availability_zone=fake_az)
|
||||||
|
|
||||||
def test_server_create_with_port_type(self, mock_create, mock_find):
|
|
||||||
name = 'server1'
|
|
||||||
flavor_id = 'flavor-id-' + uuidutils.generate_uuid(dashed=False)
|
|
||||||
image_id = 'image-id-' + uuidutils.generate_uuid(dashed=False)
|
|
||||||
networks = [{'net-id': 'net-id-' + uuidutils.generate_uuid(
|
|
||||||
dashed=False),
|
|
||||||
'port-type': 'normal'}]
|
|
||||||
self._test_create_fake_server(mock_create, mock_find,
|
|
||||||
name, flavor_id, image_id,
|
|
||||||
networks)
|
|
||||||
|
|
||||||
def test_server_create_with_metadata(self, mock_create, mock_find):
|
def test_server_create_with_metadata(self, mock_create, mock_find):
|
||||||
name = 'server1'
|
name = 'server1'
|
||||||
flavor_id = 'flavor-id-' + uuidutils.generate_uuid(dashed=False)
|
flavor_id = 'flavor-id-' + uuidutils.generate_uuid(dashed=False)
|
||||||
@ -209,6 +193,16 @@ class TestServerCreate(TestServer):
|
|||||||
name, flavor_id, image_id,
|
name, flavor_id, image_id,
|
||||||
networks, properties=properties)
|
networks, properties=properties)
|
||||||
|
|
||||||
|
def test_server_create_with_port_specified(self, mock_create, mock_find):
|
||||||
|
name = 'server1'
|
||||||
|
flavor_id = 'flavor-id-' + uuidutils.generate_uuid(dashed=False)
|
||||||
|
image_id = 'image-id-' + uuidutils.generate_uuid(dashed=False)
|
||||||
|
networks = [{'port-id': 'port-id-' + uuidutils.generate_uuid(
|
||||||
|
dashed=False)}]
|
||||||
|
self._test_create_fake_server(mock_create, mock_find,
|
||||||
|
name, flavor_id, image_id,
|
||||||
|
networks)
|
||||||
|
|
||||||
|
|
||||||
@mock.patch.object(utils, 'find_resource')
|
@mock.patch.object(utils, 'find_resource')
|
||||||
@mock.patch.object(server_mgr.ServerManager, '_update')
|
@mock.patch.object(server_mgr.ServerManager, '_update')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user