Skip all types of service ports when creating allocation config

When astara creates allocation config, it has always skipped
service ports (historically VRRP ports), but it currently does not
skip LB ports.  This adds some constants where we can define astara's
service port labels and expand in the future, and takes these into
account when deciding which ports to leave out of allocation config.

Change-Id: I6d815b1e7e6e24120ad7fd9becc94a216bfb625b
Closes-bug: #1567163
This commit is contained in:
Adam Gandelman 2016-04-06 18:28:19 -07:00
parent 12785c941d
commit 968c7da141
5 changed files with 45 additions and 3 deletions

View File

@ -17,6 +17,8 @@
import re
from astara.common import constants
SERVICE_STATIC = 'static'
@ -74,10 +76,13 @@ def _subnet_config(subnet):
def _allocation_config(ports, subnets_dict):
r = re.compile('[:.]')
service_ports_re = re.compile(
'^ASTARA:(' + '|'.join(constants.ASTARA_SERVICE_PORT_TYPES) + '):.*$'
)
allocations = []
for port in ports:
if port.name.startswith('ASTARA:VRRP:'):
if service_ports_re.match(port.name):
continue
addrs = {

View File

@ -33,7 +33,7 @@ from oslo_utils import importutils
from astara.common.i18n import _, _LI, _LW
from astara.common.linux import ip_lib
from astara.api import keystone
from astara.common import rpc
from astara.common import constants, rpc
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
@ -1000,7 +1000,7 @@ class Neutron(object):
security_groups=[]
)
if label in ['VRRP', 'LB']:
if label in constants.ASTARA_SERVICE_PORT_TYPES:
port_dict['fixed_ips'] = []
# disable port_securty on VRRP
if self.conf.neutron_port_security_extension_enabled:

View File

@ -0,0 +1,19 @@
# Copyright (c) 2016 Akanda, Inc. All Rights Reserved.
#
# 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.
ASTARA_SERVICE_PORT_TYPES = [
'VRRP',
'LB',
]

View File

@ -74,6 +74,15 @@ fake_instance_vrrp_port = FakeModel(
first_v4='192.168.1.2',
device_id='v-v-v-v')
fake_instance_lb_port = FakeModel(
'4',
name='ASTARA:LB:foo',
mac_address='aa:aa:aa:aa:aa:bb',
network_id='int-net',
fixed_ips=[FakeModel('', ip_address='192.168.1.2', subnet_id='s1')],
first_v4='192.168.1.2',
device_id='v-v-v-v')
fake_subnet = FakeModel(
's1',
cidr=netaddr.IPNetwork('192.168.1.0/24'),

View File

@ -177,6 +177,15 @@ class TestCommonConfig(unittest.TestCase):
[]
)
def test_allocation_config_lb(self):
subnets_dict = {fakes.fake_subnet.id: fakes.fake_subnet}
self.assertEqual(
common._allocation_config(
[fakes.fake_instance_lb_port],
subnets_dict),
[]
)
def test_allocation_config_mgt(self):
subnets_dict = {fakes.fake_subnet.id: fakes.fake_subnet}
expected = [