Clean up floating ip tests

There are timeout issues as well as sometimes something goes wrong in
the shade floating ip tests. Update the tests to try to make them more
stable.

This also fixes a bug in find_available_ip that was causing ips with
port_ids to be returned that was accidentally working in the functional
tests as a race condition.

While working on this, pycodestyle made a release and broke us. Add pep8
changes to allow landing this patch. Fix two of them, ignore two of them.

Change-Id: I128e85048b91f0508798d6c0c2a7e3aacb1c92c1
This commit is contained in:
Monty Taylor
2018-05-08 12:26:44 -05:00
parent 2e7e83e1c6
commit d5fd3e8f1b
10 changed files with 56 additions and 35 deletions

View File

@@ -12,15 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from openstack._log import enable_logging # noqa
import openstack.config
import openstack.connection
__all__ = [
'connect',
'enable_logging',
]
from openstack._log import enable_logging # noqa
import openstack.config
import openstack.connection
def connect(
cloud=None,

View File

@@ -44,11 +44,17 @@ def poll_for_events(
cloud, stack_name, action=None, poll_period=5, marker=None):
"""Continuously poll events and logs for performed action on stack."""
if action:
def stop_check_action(a):
stop_status = ('%s_FAILED' % action, '%s_COMPLETE' % action)
stop_check = lambda a: a in stop_status
return a in stop_status
def stop_check_no_action(a):
return a.endswith('_COMPLETE') or a.endswith('_FAILED')
if action:
stop_check = stop_check_action
else:
stop_check = lambda a: a.endswith('_COMPLETE') or a.endswith('_FAILED')
stop_check = stop_check_no_action
no_event_polls = 0
msg_template = "\n Stack %(name)s %(status)s \n"

View File

@@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
__all__ = ['OpenStackInventory']
import functools
from openstack.config import loader
@@ -21,6 +19,8 @@ from openstack import connection
from openstack import exceptions
from openstack.cloud import _utils
__all__ = ['OpenStackInventory']
class OpenStackInventory(object):

View File

@@ -155,11 +155,6 @@ try to find it and if that fails, you would create it::
Additional information about the services can be found in the
:ref:`service-proxies` documentation.
"""
__all__ = [
'from_config',
'Connection',
]
import warnings
import keystoneauth1.exceptions
@@ -175,6 +170,11 @@ from openstack import exceptions
from openstack import service_description
from openstack import task_manager
__all__ = [
'from_config',
'Connection',
]
if requestsexceptions.SubjectAltNameWarning:
warnings.filterwarnings(
'ignore', category=requestsexceptions.SubjectAltNameWarning)

View File

@@ -79,8 +79,9 @@ class FloatingIP(resource.Resource, tag.TagMixin):
@classmethod
def find_available(cls, session):
info = cls.list(session, port_id='')
try:
return next(info)
except StopIteration:
return None
# server-side filtering on empty values is not always supported.
# TODO(mordred) Make this check for support for the server-side filter
for ip in cls.list(session):
if not ip.port_id:
return ip
return None

View File

@@ -11,11 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
__all__ = [
'OpenStackServiceDescription',
'ServiceDescription',
]
import importlib
import os_service_types
@@ -23,6 +18,11 @@ import os_service_types
from openstack import _log
from openstack import proxy
__all__ = [
'OpenStackServiceDescription',
'ServiceDescription',
]
_logger = _log.setup_logging('openstack')
_service_type_manager = os_service_types.ServiceTypes()

View File

@@ -20,6 +20,8 @@ Functional tests for floating IP resource.
"""
import pprint
import six
import sys
from testtools import content
@@ -50,6 +52,7 @@ class TestFloatingIP(base.BaseFunctionalTestCase):
def _cleanup_network(self):
exception_list = list()
tb_list = list()
# Delete stale networks as well as networks created for this test
if self.user_cloud.has_service('network'):
@@ -58,7 +61,7 @@ class TestFloatingIP(base.BaseFunctionalTestCase):
try:
if r['name'].startswith(self.new_item_name):
self.user_cloud.update_router(
r['id'], ext_gateway_net_id=None)
r, ext_gateway_net_id=None)
for s in self.user_cloud.list_subnets():
if s['name'].startswith(self.new_item_name):
try:
@@ -66,31 +69,41 @@ class TestFloatingIP(base.BaseFunctionalTestCase):
r, subnet_id=s['id'])
except Exception:
pass
self.user_cloud.delete_router(name_or_id=r['id'])
self.user_cloud.delete_router(r)
except Exception as e:
exception_list.append(str(e))
exception_list.append(e)
tb_list.append(sys.exc_info()[2])
continue
# Delete subnets
for s in self.user_cloud.list_subnets():
if s['name'].startswith(self.new_item_name):
try:
self.user_cloud.delete_subnet(name_or_id=s['id'])
self.user_cloud.delete_subnet(s)
except Exception as e:
exception_list.append(str(e))
exception_list.append(e)
tb_list.append(sys.exc_info()[2])
continue
# Delete networks
for n in self.user_cloud.list_networks():
if n['name'].startswith(self.new_item_name):
try:
self.user_cloud.delete_network(name_or_id=n['id'])
self.user_cloud.delete_network(n)
except Exception as e:
exception_list.append(str(e))
exception_list.append(e)
tb_list.append(sys.exc_info()[2])
continue
if exception_list:
# Raise an error: we must make users aware that something went
# wrong
raise OpenStackCloudException('\n'.join(exception_list))
if len(exception_list) > 1:
self.addDetail(
'exceptions',
content.text_content(
'\n'.join([str(ex) for ex in exception_list])))
exc = exception_list[0]
tb = tb_list[0]
six.reraise(type(exc), exc, tb)
def _cleanup_servers(self):
exception_list = list()
@@ -119,7 +132,7 @@ class TestFloatingIP(base.BaseFunctionalTestCase):
if (ip.get('fixed_ip', None) == fixed_ip
or ip.get('fixed_ip_address', None) == fixed_ip):
try:
self.user_cloud.delete_floating_ip(ip['id'])
self.user_cloud.delete_floating_ip(ip)
except Exception as e:
exception_list.append(str(e))
continue

View File

@@ -36,6 +36,7 @@ class TestFloatingIP(base.BaseFunctionalTest):
def setUp(self):
super(TestFloatingIP, self).setUp()
self.TIMEOUT_SCALING_FACTOR = 1.5
self.ROT_NAME = self.getUniqueString()
self.EXT_NET_NAME = self.getUniqueString()
self.EXT_SUB_NAME = self.getUniqueString()

View File

@@ -89,7 +89,7 @@ class TestFloatingIP(base.TestCase):
mock_session.get.assert_called_with(
floating_ip.FloatingIP.base_path,
headers={'Accept': 'application/json'},
params={'port_id': ''})
params={})
def test_find_available_nada(self):
mock_session = mock.Mock(spec=adapter.Adapter)

View File

@@ -95,7 +95,7 @@ commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasen
# H306 Is about alphabetical imports - there's a lot to fix.
# H4 Are about docstrings and there's just a huge pile of pre-existing issues.
# D* Came from sdk, unknown why they're skipped.
ignore = H103,H306,H4,D100,D101,D102,D103,D104,D105,D200,D202,D204,D205,D211,D301,D400,D401
ignore = H103,H306,H4,D100,D101,D102,D103,D104,D105,D200,D202,D204,D205,D211,D301,D400,D401,F405,W503
show-source = True
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build