Fix regexp for ss output

Previously we ignored when destination address was replaced by
asterisk.

Co-Authored-By: amuller@redhat.com

Change-Id: I68bbd43c1b98e5f21d2cbf7dc33a8bdccbb70bd0
Closes-Bug: 1567472
This commit is contained in:
Assaf Muller 2016-04-07 10:21:46 -04:00 committed by Jakub Libosvar
parent 444b3a5d9a
commit d5ae8645cc
3 changed files with 45 additions and 1 deletions

View File

@ -63,7 +63,7 @@ MACVTAP_PREFIX = 'macvtap'
LB_DEVICE_NAME_MAX_LEN = 10
SS_SOURCE_PORT_PATTERN = re.compile(
r'^.*\s+\d+\s+.*:(?P<port>\d+)\s+[0-9:].*')
r'^.*\s+\d+\s+.*:(?P<port>\d+)\s+[^\s]+:.*')
READ_TIMEOUT = os.environ.get('OS_TEST_READ_TIMEOUT', 5)

View File

@ -0,0 +1,44 @@
# Copyright 2016 Red Hat, Inc.
#
# 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 neutron.tests import base
from neutron.tests.common import net_helpers
ss_output = """
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 10 127.0.0.1:6640 *:*
LISTEN 0 128 *:46675 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 *:5432 *:*
LISTEN 0 128 *:3260 *:*
LISTEN 0 50 *:3306 *:*
ESTAB 0 36 10.0.0.202:22 10.0.0.44:45258
ESTAB 0 0 127.0.0.1:32965 127.0.0.1:4369
ESTAB 0 0 10.0.0.202:22 10.0.0.44:36104
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::4369 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 :::5432 :::*
LISTEN 0 128 :::3260 :::*
LISTEN 0 128 :::5672 :::*
ESTAB 0 0 ::ffff:127.0.0.1:4369 ::ffff:127.0.0.1:32965
"""
class PortAllocationTestCase(base.DietTestCase):
def test__get_source_ports_from_ss_output(self):
result = net_helpers._get_source_ports_from_ss_output(ss_output)
expected = {'6640', '46675', '5432', '3260', '3306', '22', '32965',
'4369', '5672', '80'}
self.assertEqual(expected, result)