Do not pass both port-id and fixed-ip to create server

Nova doesn't allow specify port-id and fixed-ip at the same
time when create server. This patch to avoid this problem
when create internal port by subnet.

Also, this change adds integration test for create server
with subnet and fixed_ip.

Change-Id: Ib16d7f90a4eb488a853f9c2093280596fc4d783b
Partial-Bug: #1533074
This commit is contained in:
huangtianhua 2016-01-13 17:24:32 +08:00
parent 39a2438f7f
commit 84564a3665
3 changed files with 80 additions and 7 deletions

View File

@ -223,16 +223,18 @@ class ServerNetworkMixin(object):
for idx, net in enumerate(networks):
self._validate_belonging_subnet_to_net(net)
nic_info = {'net-id': self._get_network_id(net)}
if net.get(self.NETWORK_FIXED_IP):
ip = net[self.NETWORK_FIXED_IP]
if netutils.is_valid_ipv6(ip):
nic_info['v6-fixed-ip'] = ip
else:
nic_info['v4-fixed-ip'] = ip
if net.get(self.NETWORK_PORT):
nic_info['port-id'] = net[self.NETWORK_PORT]
elif self.is_using_neutron() and net.get(self.NETWORK_SUBNET):
nic_info['port-id'] = self._create_internal_port(net, idx)
# if nic_info including 'port-id', do not set ip for nic
if not nic_info.get('port-id'):
if net.get(self.NETWORK_FIXED_IP):
ip = net[self.NETWORK_FIXED_IP]
if netutils.is_valid_ipv6(ip):
nic_info['v6-fixed-ip'] = ip
else:
nic_info['v4-fixed-ip'] = ip
nics.append(nic_info)
return nics

View File

@ -2496,7 +2496,12 @@ class ServersTest(common.HeatTestCase):
{'v4-fixed-ip': '192.0.2.0', 'net-id': None}],
server._build_nics([{'port': 'aaaabbbb'},
{'fixed_ip': '192.0.2.0'}]))
self.assertEqual([{'port-id': 'aaaabbbb', 'net-id': None},
{'port-id': 'aaaabbbb', 'net-id': None}],
server._build_nics([{'port': 'aaaabbbb',
'fixed_ip': '192.0.2.0'},
{'port': 'aaaabbbb',
'fixed_ip': '2002::2'}]))
self.assertEqual([{'port-id': 'aaaabbbb', 'net-id': None},
{'v6-fixed-ip': '2002::2', 'net-id': None}],
server._build_nics([{'port': 'aaaabbbb'},

View File

@ -0,0 +1,66 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from heat_integrationtests.functional import functional_base
server_with_sub_fixed_ip_template = '''
heat_template_version: 2016-04-08
description: Test template to test nova server with subnet and fixed_ip.
parameters:
flavor:
type: string
image:
type: string
resources:
net:
type: OS::Neutron::Net
properties:
name: my_net
subnet:
type: OS::Neutron::Subnet
properties:
network: {get_resource: net}
cidr: 11.11.11.0/24
server:
type: OS::Nova::Server
properties:
image: {get_param: image}
flavor: {get_param: flavor}
networks:
- subnet: {get_resource: subnet}
fixed_ip: 11.11.11.11
outputs:
networks:
value: {get_attr: [server, networks]}
'''
class CreateServerTest(functional_base.FunctionalTestsBase):
def setUp(self):
super(CreateServerTest, self).setUp()
def get_outputs(self, stack_identifier, output_key):
stack = self.client.stacks.get(stack_identifier)
output = self._stack_output(stack, output_key)
return output
def test_create_server_with_subnet_fixed_ip(self):
parms = {'flavor': self.conf.minimal_instance_type,
'image': self.conf.minimal_image_ref}
stack_identifier = self.stack_create(
template=server_with_sub_fixed_ip_template,
stack_name='server_with_sub_ip',
parameters=parms)
networks = self.get_outputs(stack_identifier, 'networks')
self.assertEqual(['11.11.11.11'], networks['my_net'])