Move wait_until_true to neutron.common.utils
We need to be able to re-use wait_until_true in tempest scenario tests. There is tempest bug https://bugs.launchpad.net/tempest/+bug/1592345 that prevents us to do so. Also wait_until_true is not linux specific so it makes more sense to have it in common package. Change-Id: Ib8b0e51dbd9edaa58391774d428a737836dfdf77
This commit is contained in:
parent
e162ce1ed6
commit
a626172706
neutron
agent/linux
cmd/sanity
common
tests
common
fullstack
functional
@ -113,7 +113,7 @@ class AsyncProcess(object):
|
||||
self._spawn()
|
||||
|
||||
if block:
|
||||
utils.wait_until_true(self.is_active)
|
||||
common_utils.wait_until_true(self.is_active)
|
||||
|
||||
def stop(self, block=False, kill_signal=signal.SIGKILL):
|
||||
"""Halt the process and watcher threads.
|
||||
@ -131,7 +131,7 @@ class AsyncProcess(object):
|
||||
raise AsyncProcessException(_('Process is not running.'))
|
||||
|
||||
if block:
|
||||
utils.wait_until_true(lambda: not self.is_active())
|
||||
common_utils.wait_until_true(lambda: not self.is_active())
|
||||
|
||||
def _spawn(self):
|
||||
"""Spawn a process and its watchers."""
|
||||
|
@ -28,6 +28,7 @@ import six
|
||||
from neutron._i18n import _, _LE
|
||||
from neutron.agent.common import utils
|
||||
from neutron.common import exceptions as n_exc
|
||||
from neutron.common import utils as common_utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -656,7 +657,7 @@ class IpAddrCommand(IpDeviceCommandBase):
|
||||
address=address, reason=_('Duplicate address detected'))
|
||||
errmsg = _("Exceeded %s second limit waiting for "
|
||||
"address to leave the tentative state.") % wait_time
|
||||
utils.utils.wait_until_true(
|
||||
common_utils.wait_until_true(
|
||||
is_address_ready, timeout=wait_time, sleep=0.20,
|
||||
exception=AddressNotReady(address=address, reason=errmsg))
|
||||
|
||||
|
@ -24,7 +24,6 @@ import six
|
||||
from stevedore import driver
|
||||
|
||||
from neutron._i18n import _
|
||||
from neutron.agent.linux import utils as linux_utils
|
||||
from neutron.callbacks import events
|
||||
from neutron.callbacks import registry
|
||||
from neutron.callbacks import resources
|
||||
@ -221,12 +220,12 @@ class PrefixDelegation(object):
|
||||
def _ensure_lla_task(self, gw_ifname, ns_name, lla_with_mask):
|
||||
# It would be insane for taking so long unless DAD test failed
|
||||
# In that case, the subnet would never be assigned a prefix.
|
||||
linux_utils.wait_until_true(functools.partial(self._lla_available,
|
||||
gw_ifname,
|
||||
ns_name,
|
||||
lla_with_mask),
|
||||
timeout=l3_constants.LLA_TASK_TIMEOUT,
|
||||
sleep=2)
|
||||
utils.wait_until_true(functools.partial(self._lla_available,
|
||||
gw_ifname,
|
||||
ns_name,
|
||||
lla_with_mask),
|
||||
timeout=l3_constants.LLA_TASK_TIMEOUT,
|
||||
sleep=2)
|
||||
|
||||
def _lla_available(self, gw_ifname, ns_name, lla_with_mask):
|
||||
llas = self._get_llas(gw_ifname, ns_name)
|
||||
|
@ -23,6 +23,7 @@ import socket
|
||||
import struct
|
||||
import threading
|
||||
|
||||
import debtcollector
|
||||
import eventlet
|
||||
from eventlet.green import subprocess
|
||||
from eventlet import greenthread
|
||||
@ -288,20 +289,9 @@ def pid_invoked_with_cmdline(pid, expected_cmd):
|
||||
return cmd_matches_expected(cmd, expected_cmd)
|
||||
|
||||
|
||||
def wait_until_true(predicate, timeout=60, sleep=1, exception=None):
|
||||
"""
|
||||
Wait until callable predicate is evaluated as True
|
||||
|
||||
:param predicate: Callable deciding whether waiting should continue.
|
||||
Best practice is to instantiate predicate with functools.partial()
|
||||
:param timeout: Timeout in seconds how long should function wait.
|
||||
:param sleep: Polling interval for results in seconds.
|
||||
:param exception: Exception class for eventlet.Timeout.
|
||||
(see doc for eventlet.Timeout for more information)
|
||||
"""
|
||||
with eventlet.timeout.Timeout(timeout, exception):
|
||||
while not predicate():
|
||||
eventlet.sleep(sleep)
|
||||
wait_until_true = debtcollector.moves.moved_function(
|
||||
utils.wait_until_true, 'wait_until_true', __name__,
|
||||
version='Newton', removal_version='Ocata')
|
||||
|
||||
|
||||
def ensure_directory_exists_without_file(path):
|
||||
|
@ -33,6 +33,7 @@ from neutron.agent.linux import ip_link_support
|
||||
from neutron.agent.linux import keepalived
|
||||
from neutron.agent.linux import utils as agent_utils
|
||||
from neutron.common import constants
|
||||
from neutron.common import utils as common_utils
|
||||
from neutron.plugins.common import constants as const
|
||||
from neutron.plugins.ml2.drivers.openvswitch.agent.common \
|
||||
import constants as ovs_const
|
||||
@ -244,14 +245,14 @@ class KeepalivedIPv6Test(object):
|
||||
|
||||
def verify_ipv6_address_assignment(self, gw_dev):
|
||||
process = self.manager.get_process()
|
||||
agent_utils.wait_until_true(lambda: process.active)
|
||||
common_utils.wait_until_true(lambda: process.active)
|
||||
|
||||
def _gw_vip_assigned():
|
||||
iface_ip = gw_dev.addr.list(ip_version=6, scope='global')
|
||||
if iface_ip:
|
||||
return self.gw_vip == iface_ip[0]['cidr']
|
||||
|
||||
agent_utils.wait_until_true(_gw_vip_assigned)
|
||||
common_utils.wait_until_true(_gw_vip_assigned)
|
||||
|
||||
def __enter__(self):
|
||||
ip_lib.IPWrapper().netns.add(self.nsname)
|
||||
|
@ -33,6 +33,7 @@ import tempfile
|
||||
import time
|
||||
import uuid
|
||||
|
||||
import eventlet
|
||||
from eventlet.green import subprocess
|
||||
import netaddr
|
||||
from neutron_lib import constants as n_const
|
||||
@ -601,6 +602,22 @@ def transaction_guard(f):
|
||||
return inner
|
||||
|
||||
|
||||
def wait_until_true(predicate, timeout=60, sleep=1, exception=None):
|
||||
"""
|
||||
Wait until callable predicate is evaluated as True
|
||||
|
||||
:param predicate: Callable deciding whether waiting should continue.
|
||||
Best practice is to instantiate predicate with functools.partial()
|
||||
:param timeout: Timeout in seconds how long should function wait.
|
||||
:param sleep: Polling interval for results in seconds.
|
||||
:param exception: Exception class for eventlet.Timeout.
|
||||
(see doc for eventlet.Timeout for more information)
|
||||
"""
|
||||
with eventlet.timeout.Timeout(timeout, exception):
|
||||
while not predicate():
|
||||
eventlet.sleep(sleep)
|
||||
|
||||
|
||||
class _AuthenticBase(object):
|
||||
def __init__(self, addr, **kwargs):
|
||||
super(_AuthenticBase, self).__init__(addr, **kwargs)
|
||||
|
@ -13,7 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron.agent.linux import utils as agent_utils
|
||||
from neutron.common import utils as common_utils
|
||||
|
||||
|
||||
def extract_mod_nw_tos_action(flows):
|
||||
@ -36,7 +36,7 @@ def wait_until_bandwidth_limit_rule_applied(bridge, port_vif, rule):
|
||||
expected = rule.max_kbps, rule.max_burst_kbps
|
||||
return bw_rule == expected
|
||||
|
||||
agent_utils.wait_until_true(_bandwidth_limit_rule_applied)
|
||||
common_utils.wait_until_true(_bandwidth_limit_rule_applied)
|
||||
|
||||
|
||||
def wait_until_dscp_marking_rule_applied(bridge, port_vif, rule):
|
||||
@ -51,4 +51,4 @@ def wait_until_dscp_marking_rule_applied(bridge, port_vif, rule):
|
||||
expected = rule << 2
|
||||
return dscp_mark == expected
|
||||
|
||||
agent_utils.wait_until_true(_dscp_marking_rule_applied)
|
||||
common_utils.wait_until_true(_dscp_marking_rule_applied)
|
||||
|
@ -18,7 +18,7 @@ import functools
|
||||
import fixtures
|
||||
|
||||
from neutron.agent.linux import ip_lib
|
||||
from neutron.agent.linux import utils
|
||||
from neutron.common import utils
|
||||
from neutron.tests.common import net_helpers
|
||||
|
||||
|
||||
|
@ -38,6 +38,7 @@ from neutron.agent.linux import bridge_lib
|
||||
from neutron.agent.linux import interface
|
||||
from neutron.agent.linux import ip_lib
|
||||
from neutron.agent.linux import utils
|
||||
from neutron.common import utils as common_utils
|
||||
from neutron.db import db_base_plugin_common
|
||||
from neutron.plugins.ml2.drivers.linuxbridge.agent import \
|
||||
linuxbridge_neutron_agent as linuxbridge_agent
|
||||
@ -237,7 +238,7 @@ class RootHelperProcess(subprocess.Popen):
|
||||
poller = select.poll()
|
||||
poller.register(stream.fileno())
|
||||
poll_predicate = functools.partial(poller.poll, 1)
|
||||
utils.wait_until_true(poll_predicate, timeout, 0.1,
|
||||
common_utils.wait_until_true(poll_predicate, timeout, 0.1,
|
||||
RuntimeError(
|
||||
'No output in %.2f seconds' % timeout))
|
||||
return stream.readline()
|
||||
@ -254,7 +255,7 @@ class RootHelperProcess(subprocess.Popen):
|
||||
if utils.pid_invoked_with_cmdline(child_pid, self.cmd):
|
||||
return True
|
||||
|
||||
utils.wait_until_true(
|
||||
common_utils.wait_until_true(
|
||||
child_is_running,
|
||||
timeout,
|
||||
exception=RuntimeError("Process %s hasn't been spawned "
|
||||
@ -304,7 +305,7 @@ class Pinger(object):
|
||||
|
||||
def _wait_for_death(self):
|
||||
is_dead = lambda: self.proc.poll() is not None
|
||||
utils.wait_until_true(
|
||||
common_utils.wait_until_true(
|
||||
is_dead, timeout=self.TIMEOUT, exception=RuntimeError(
|
||||
"Ping command hasn't ended after %d seconds." % self.TIMEOUT))
|
||||
|
||||
|
@ -18,7 +18,6 @@ from neutronclient.common import exceptions as nc_exc
|
||||
from oslo_config import cfg
|
||||
|
||||
from neutron.agent.linux import ip_lib
|
||||
from neutron.agent.linux import utils
|
||||
from neutron.common import utils as common_utils
|
||||
from neutron.plugins.ml2.drivers.linuxbridge.agent import \
|
||||
linuxbridge_neutron_agent as lb_agent
|
||||
@ -284,7 +283,7 @@ class Environment(fixtures.Fixture):
|
||||
self.hosts = []
|
||||
|
||||
def wait_until_env_is_up(self):
|
||||
utils.wait_until_true(self._processes_are_ready)
|
||||
common_utils.wait_until_true(self._processes_are_ready)
|
||||
|
||||
def _processes_are_ready(self):
|
||||
try:
|
||||
|
@ -16,7 +16,7 @@ import netaddr
|
||||
|
||||
from neutron_lib import constants
|
||||
|
||||
from neutron.agent.linux import utils
|
||||
from neutron.common import utils
|
||||
from neutron.tests.common import machine_fixtures
|
||||
from neutron.tests.common import net_helpers
|
||||
|
||||
|
@ -118,7 +118,7 @@ class NeutronServerFixture(fixtures.Fixture):
|
||||
config_filenames=config_filenames,
|
||||
kill_signal=signal.SIGTERM))
|
||||
|
||||
utils.wait_until_true(self.server_is_live)
|
||||
common_utils.wait_until_true(self.server_is_live)
|
||||
|
||||
def server_is_live(self):
|
||||
try:
|
||||
|
@ -21,7 +21,6 @@ from oslo_utils import uuidutils
|
||||
from neutron.agent.l3 import agent as l3_agent
|
||||
from neutron.agent.l3 import namespaces
|
||||
from neutron.agent.linux import ip_lib
|
||||
from neutron.agent.linux import utils
|
||||
from neutron.common import utils as common_utils
|
||||
from neutron.tests.common.exclusive_resources import ip_network
|
||||
from neutron.tests.common import machine_fixtures
|
||||
@ -47,7 +46,7 @@ class TestL3Agent(base.BaseFullStackTestCase):
|
||||
def is_port_status_active():
|
||||
port = self.client.show_port(port_id)
|
||||
return port['port']['status'] == 'ACTIVE'
|
||||
utils.wait_until_true(lambda: is_port_status_active(), sleep=1)
|
||||
common_utils.wait_until_true(lambda: is_port_status_active(), sleep=1)
|
||||
|
||||
def _create_net_subnet_and_vm(self, tenant_id, subnet_cidrs, host, router):
|
||||
network = self.safe_client.create_network(tenant_id)
|
||||
@ -87,7 +86,7 @@ class TestLegacyL3Agent(TestL3Agent):
|
||||
|
||||
def _assert_namespace_exists(self, ns_name):
|
||||
ip = ip_lib.IPWrapper(ns_name)
|
||||
utils.wait_until_true(lambda: ip.netns.exists(ns_name))
|
||||
common_utils.wait_until_true(lambda: ip.netns.exists(ns_name))
|
||||
|
||||
def test_namespace_exists(self):
|
||||
tenant_id = uuidutils.generate_uuid()
|
||||
@ -173,7 +172,7 @@ class TestHAL3Agent(base.BaseFullStackTestCase):
|
||||
self.assertEqual(2, len(agents['agents']),
|
||||
'HA router must be scheduled to both nodes')
|
||||
|
||||
utils.wait_until_true(
|
||||
common_utils.wait_until_true(
|
||||
functools.partial(
|
||||
self._is_ha_router_active_on_one_agent,
|
||||
router['id']),
|
||||
|
@ -21,7 +21,7 @@ import testscenarios
|
||||
from neutron.agent.common import ovs_lib
|
||||
from neutron.agent.linux import bridge_lib
|
||||
from neutron.agent.linux import tc_lib
|
||||
from neutron.agent.linux import utils
|
||||
from neutron.common import utils
|
||||
from neutron.services.qos import qos_consts
|
||||
from neutron.tests.common.agents import l2_extensions
|
||||
from neutron.tests.fullstack import base
|
||||
|
@ -27,7 +27,6 @@ from neutron.agent.common import ovs_lib
|
||||
from neutron.agent.l2.extensions import manager as ext_manager
|
||||
from neutron.agent.linux import interface
|
||||
from neutron.agent.linux import polling
|
||||
from neutron.agent.linux import utils as agent_utils
|
||||
from neutron.common import config as common_config
|
||||
from neutron.common import utils
|
||||
from neutron.plugins.common import constants as p_const
|
||||
@ -156,7 +155,7 @@ class OVSAgentTestFramework(base.BaseOVSLinuxTestCase):
|
||||
self._mock_get_events(agent, polling_manager, ports)
|
||||
self.addCleanup(polling_manager.stop)
|
||||
polling_manager.start()
|
||||
agent_utils.wait_until_true(
|
||||
utils.wait_until_true(
|
||||
polling_manager._monitor.is_active)
|
||||
agent.check_ovs_status = mock.Mock(
|
||||
return_value=constants.OVS_NORMAL)
|
||||
@ -228,9 +227,9 @@ class OVSAgentTestFramework(base.BaseOVSLinuxTestCase):
|
||||
return agent.int_br.db_get_val(
|
||||
'Interface', port, 'options', check_error=True)
|
||||
|
||||
agent_utils.wait_until_true(
|
||||
utils.wait_until_true(
|
||||
lambda: get_peer(self.patch_int) == {'peer': self.patch_tun})
|
||||
agent_utils.wait_until_true(
|
||||
utils.wait_until_true(
|
||||
lambda: get_peer(self.patch_tun) == {'peer': self.patch_int})
|
||||
|
||||
def assert_bridge_ports(self):
|
||||
@ -361,7 +360,7 @@ class OVSAgentTestFramework(base.BaseOVSLinuxTestCase):
|
||||
|
||||
def wait_until_ports_state(self, ports, up, timeout=60):
|
||||
port_ids = [p['id'] for p in ports]
|
||||
agent_utils.wait_until_true(
|
||||
utils.wait_until_true(
|
||||
lambda: self._expected_plugin_rpc_call(
|
||||
self.agent.plugin_rpc.update_device_list, port_ids, up),
|
||||
timeout=timeout)
|
||||
|
@ -29,7 +29,6 @@ from neutron.agent.l3 import agent as neutron_l3_agent
|
||||
from neutron.agent import l3_agent as l3_agent_main
|
||||
from neutron.agent.linux import external_process
|
||||
from neutron.agent.linux import ip_lib
|
||||
from neutron.agent.linux import utils
|
||||
from neutron.common import config as common_config
|
||||
from neutron.common import constants as n_const
|
||||
from neutron.common import utils as common_utils
|
||||
@ -149,7 +148,7 @@ class L3AgentTestFramework(base.BaseSudoTestCase):
|
||||
n, len([line for line in out.strip().split('\n') if line]))
|
||||
|
||||
if ha:
|
||||
utils.wait_until_true(lambda: router.ha_state == 'master')
|
||||
common_utils.wait_until_true(lambda: router.ha_state == 'master')
|
||||
|
||||
with self.assert_max_execution_time(100):
|
||||
assert_num_of_conntrack_rules(0)
|
||||
@ -233,7 +232,7 @@ class L3AgentTestFramework(base.BaseSudoTestCase):
|
||||
interface_name = router.get_external_device_name(port['id'])
|
||||
self._assert_no_ip_addresses_on_interface(router.ns_name,
|
||||
interface_name)
|
||||
utils.wait_until_true(lambda: router.ha_state == 'master')
|
||||
common_utils.wait_until_true(lambda: router.ha_state == 'master')
|
||||
|
||||
# Keepalived notifies of a state transition when it starts,
|
||||
# not when it ends. Thus, we have to wait until keepalived finishes
|
||||
@ -245,10 +244,10 @@ class L3AgentTestFramework(base.BaseSudoTestCase):
|
||||
device,
|
||||
router.get_internal_device_name,
|
||||
router.ns_name)
|
||||
utils.wait_until_true(device_exists)
|
||||
common_utils.wait_until_true(device_exists)
|
||||
|
||||
self.assertTrue(self._namespace_exists(router.ns_name))
|
||||
utils.wait_until_true(
|
||||
common_utils.wait_until_true(
|
||||
lambda: self._metadata_proxy_exists(self.agent.conf, router))
|
||||
self._assert_internal_devices(router)
|
||||
self._assert_external_device(router)
|
||||
@ -408,7 +407,7 @@ class L3AgentTestFramework(base.BaseSudoTestCase):
|
||||
# then the devices and iptable rules have also been deleted,
|
||||
# so there's no need to check that explicitly.
|
||||
self.assertFalse(self._namespace_exists(router.ns_name))
|
||||
utils.wait_until_true(
|
||||
common_utils.wait_until_true(
|
||||
lambda: not self._metadata_proxy_exists(self.agent.conf, router))
|
||||
|
||||
def _assert_snat_chains(self, router):
|
||||
|
@ -25,8 +25,8 @@ from neutron.agent.l3 import dvr_snat_ns
|
||||
from neutron.agent.l3 import namespaces
|
||||
from neutron.agent.linux import ip_lib
|
||||
from neutron.agent.linux import iptables_manager
|
||||
from neutron.agent.linux import utils
|
||||
from neutron.common import constants as n_const
|
||||
from neutron.common import utils
|
||||
from neutron.extensions import portbindings
|
||||
from neutron.tests.common import l3_test_common
|
||||
from neutron.tests.common import machine_fixtures
|
||||
|
@ -22,7 +22,6 @@ import six
|
||||
from neutron.agent.l3 import agent as neutron_l3_agent
|
||||
from neutron.agent.l3 import namespaces
|
||||
from neutron.agent.linux import ip_lib
|
||||
from neutron.agent.linux import utils
|
||||
from neutron.common import constants
|
||||
from neutron.common import utils as common_utils
|
||||
from neutron.tests.common import l3_test_common
|
||||
@ -41,12 +40,12 @@ class L3HATestCase(framework.L3AgentTestFramework):
|
||||
self.agent, 'enqueue_state_change').start()
|
||||
router_info = self.generate_router_info(enable_ha=True)
|
||||
router = self.manage_router(self.agent, router_info)
|
||||
utils.wait_until_true(lambda: router.ha_state == 'master')
|
||||
common_utils.wait_until_true(lambda: router.ha_state == 'master')
|
||||
|
||||
self.fail_ha_router(router)
|
||||
utils.wait_until_true(lambda: router.ha_state == 'backup')
|
||||
common_utils.wait_until_true(lambda: router.ha_state == 'backup')
|
||||
|
||||
utils.wait_until_true(lambda: enqueue_mock.call_count == 3)
|
||||
common_utils.wait_until_true(lambda: enqueue_mock.call_count == 3)
|
||||
calls = [args[0] for args in enqueue_mock.call_args_list]
|
||||
self.assertEqual((router.router_id, 'backup'), calls[0])
|
||||
self.assertEqual((router.router_id, 'master'), calls[1])
|
||||
@ -71,9 +70,9 @@ class L3HATestCase(framework.L3AgentTestFramework):
|
||||
router_info = self.generate_router_info(enable_ha=True)
|
||||
router2 = self.manage_router(self.agent, router_info)
|
||||
|
||||
utils.wait_until_true(lambda: router1.ha_state == 'backup')
|
||||
utils.wait_until_true(lambda: router2.ha_state == 'master')
|
||||
utils.wait_until_true(
|
||||
common_utils.wait_until_true(lambda: router1.ha_state == 'backup')
|
||||
common_utils.wait_until_true(lambda: router2.ha_state == 'master')
|
||||
common_utils.wait_until_true(
|
||||
lambda: self._expected_rpc_report(
|
||||
{router1.router_id: 'standby', router2.router_id: 'active'}))
|
||||
|
||||
@ -151,7 +150,8 @@ class L3HATestCase(framework.L3AgentTestFramework):
|
||||
restarted_agent = neutron_l3_agent.L3NATAgentWithStateReport(
|
||||
self.agent.host, self.agent.conf)
|
||||
self.manage_router(restarted_agent, router1.router)
|
||||
utils.wait_until_true(lambda: self.floating_ips_configured(router1))
|
||||
common_utils.wait_until_true(
|
||||
lambda: self.floating_ips_configured(router1))
|
||||
self.assertIn(
|
||||
router1._get_primary_vip(),
|
||||
self._get_addresses_on_device(
|
||||
@ -161,8 +161,8 @@ class L3HATestCase(framework.L3AgentTestFramework):
|
||||
def test_ha_router_ipv6_radvd_status(self):
|
||||
router_info = self.generate_router_info(ip_version=6, enable_ha=True)
|
||||
router1 = self.manage_router(self.agent, router_info)
|
||||
utils.wait_until_true(lambda: router1.ha_state == 'master')
|
||||
utils.wait_until_true(lambda: router1.radvd.enabled)
|
||||
common_utils.wait_until_true(lambda: router1.ha_state == 'master')
|
||||
common_utils.wait_until_true(lambda: router1.radvd.enabled)
|
||||
|
||||
def _check_lla_status(router, expected):
|
||||
internal_devices = router.router[l3_constants.INTERFACE_KEY]
|
||||
@ -179,8 +179,9 @@ class L3HATestCase(framework.L3AgentTestFramework):
|
||||
ha_device = ip_lib.IPDevice(device_name, namespace=router1.ns_name)
|
||||
ha_device.link.set_down()
|
||||
|
||||
utils.wait_until_true(lambda: router1.ha_state == 'backup')
|
||||
utils.wait_until_true(lambda: not router1.radvd.enabled, timeout=10)
|
||||
common_utils.wait_until_true(lambda: router1.ha_state == 'backup')
|
||||
common_utils.wait_until_true(
|
||||
lambda: not router1.radvd.enabled, timeout=10)
|
||||
_check_lla_status(router1, False)
|
||||
|
||||
def test_ha_router_process_ipv6_subnets_to_existing_port(self):
|
||||
@ -202,7 +203,7 @@ class L3HATestCase(framework.L3AgentTestFramework):
|
||||
ip_version=6, ipv6_subnet_modes=[slaac_mode],
|
||||
interface_id=interface_id)
|
||||
router.process(self.agent)
|
||||
utils.wait_until_true(lambda: router.ha_state == 'master')
|
||||
common_utils.wait_until_true(lambda: router.ha_state == 'master')
|
||||
|
||||
# Verify that router internal interface is present and is configured
|
||||
# with IP address from both the subnets.
|
||||
@ -236,7 +237,7 @@ class L3HATestCase(framework.L3AgentTestFramework):
|
||||
router = self.manage_router(self.agent, router_info)
|
||||
|
||||
self.fail_ha_router(router)
|
||||
utils.wait_until_true(lambda: router.ha_state == 'backup')
|
||||
common_utils.wait_until_true(lambda: router.ha_state == 'backup')
|
||||
|
||||
# The purpose of the test is to simply make sure no exception is raised
|
||||
port = router.get_ex_gw_port()
|
||||
@ -248,7 +249,7 @@ class L3HATestCase(framework.L3AgentTestFramework):
|
||||
router = self.manage_router(self.agent, router_info)
|
||||
ex_gw_port = router.get_ex_gw_port()
|
||||
interface_name = router.get_external_device_interface_name(ex_gw_port)
|
||||
utils.wait_until_true(lambda: router.ha_state == 'master')
|
||||
common_utils.wait_until_true(lambda: router.ha_state == 'master')
|
||||
self._add_fip(router, '172.168.1.20', fixed_address='10.0.0.3')
|
||||
router.process(self.agent)
|
||||
router.router[l3_constants.FLOATINGIP_KEY] = []
|
||||
@ -294,10 +295,10 @@ class L3HATestFailover(framework.L3AgentTestFramework):
|
||||
self.NESTED_NAMESPACE_SEPARATOR, self.failover_agent.host)
|
||||
router2 = self.manage_router(self.failover_agent, router_info_2)
|
||||
|
||||
utils.wait_until_true(lambda: router1.ha_state == 'master')
|
||||
utils.wait_until_true(lambda: router2.ha_state == 'backup')
|
||||
common_utils.wait_until_true(lambda: router1.ha_state == 'master')
|
||||
common_utils.wait_until_true(lambda: router2.ha_state == 'backup')
|
||||
|
||||
self.fail_ha_router(router1)
|
||||
|
||||
utils.wait_until_true(lambda: router2.ha_state == 'master')
|
||||
utils.wait_until_true(lambda: router1.ha_state == 'backup')
|
||||
common_utils.wait_until_true(lambda: router2.ha_state == 'master')
|
||||
common_utils.wait_until_true(lambda: router1.ha_state == 'backup')
|
||||
|
@ -18,6 +18,7 @@ import six
|
||||
from neutron._i18n import _
|
||||
from neutron.agent.linux import async_process
|
||||
from neutron.agent.linux import utils
|
||||
from neutron.common import utils as common_utils
|
||||
from neutron.tests import base
|
||||
|
||||
|
||||
@ -72,7 +73,7 @@ class TestAsyncProcess(AsyncProcessTestFramework):
|
||||
self._check_stdout(proc)
|
||||
pid = proc.pid
|
||||
utils.execute(['kill', '-9', pid])
|
||||
utils.wait_until_true(
|
||||
common_utils.wait_until_true(
|
||||
lambda: proc.is_active() and pid != proc.pid,
|
||||
timeout=5,
|
||||
sleep=0.01,
|
||||
|
@ -19,6 +19,7 @@ from neutron._i18n import _
|
||||
from neutron.agent.linux import external_process
|
||||
from neutron.agent.linux import keepalived
|
||||
from neutron.agent.linux import utils
|
||||
from neutron.common import utils as common_utils
|
||||
from neutron.tests.functional.agent.linux import helpers
|
||||
from neutron.tests.functional import base
|
||||
from neutron.tests.unit.agent.linux import test_keepalived
|
||||
@ -42,7 +43,7 @@ class KeepalivedManagerTestCase(base.BaseLoggingTestCase,
|
||||
def _spawn_keepalived(self, keepalived_manager):
|
||||
keepalived_manager.spawn()
|
||||
process = keepalived_manager.get_process()
|
||||
utils.wait_until_true(
|
||||
common_utils.wait_until_true(
|
||||
lambda: process.active,
|
||||
timeout=5,
|
||||
sleep=0.01,
|
||||
@ -63,7 +64,7 @@ class KeepalivedManagerTestCase(base.BaseLoggingTestCase,
|
||||
# Exit the process, and see that when it comes back
|
||||
# It's indeed a different process
|
||||
utils.execute(['kill', exit_code, pid], run_as_root=True)
|
||||
utils.wait_until_true(
|
||||
common_utils.wait_until_true(
|
||||
lambda: process.active and pid != process.pid,
|
||||
timeout=5,
|
||||
sleep=0.01,
|
||||
|
@ -27,7 +27,7 @@ from oslo_config import cfg
|
||||
|
||||
from neutron.agent.common import ovs_lib
|
||||
from neutron.agent.linux import ovsdb_monitor
|
||||
from neutron.agent.linux import utils
|
||||
from neutron.common import utils
|
||||
from neutron.tests.common import net_helpers
|
||||
from neutron.tests.functional.agent.linux import base as linux_base
|
||||
from neutron.tests.functional import base as functional_base
|
||||
|
@ -18,7 +18,7 @@ from oslo_config import cfg
|
||||
from six import moves
|
||||
|
||||
from neutron.agent.linux import external_process
|
||||
from neutron.agent.linux import utils
|
||||
from neutron.common import utils
|
||||
from neutron.tests import base
|
||||
from neutron.tests.functional.agent.linux import simple_daemon
|
||||
|
||||
|
@ -14,11 +14,9 @@
|
||||
|
||||
import functools
|
||||
|
||||
import eventlet
|
||||
import testtools
|
||||
|
||||
from neutron.agent.linux import async_process
|
||||
from neutron.agent.linux import utils
|
||||
from neutron.common import utils as common_utils
|
||||
from neutron.tests.functional.agent.linux import test_async_process
|
||||
from neutron.tests.functional import base as functional_base
|
||||
|
||||
@ -35,13 +33,6 @@ class TestPIDHelpers(test_async_process.AsyncProcessTestFramework):
|
||||
self.assertTrue(utils.pid_invoked_with_cmdline(pid, cmd))
|
||||
self.assertEqual([], utils.get_cmdline_from_pid(-1))
|
||||
|
||||
def test_wait_until_true_predicate_succeeds(self):
|
||||
utils.wait_until_true(lambda: True)
|
||||
|
||||
def test_wait_until_true_predicate_fails(self):
|
||||
with testtools.ExpectedException(eventlet.timeout.Timeout):
|
||||
utils.wait_until_true(lambda: False, 2)
|
||||
|
||||
|
||||
class TestGetRootHelperChildPid(functional_base.BaseSudoTestCase):
|
||||
def _addcleanup_sleep_process(self, parent_pid):
|
||||
@ -83,7 +74,7 @@ class TestGetRootHelperChildPid(functional_base.BaseSudoTestCase):
|
||||
# don't want to use proc.start(block=True) as that uses
|
||||
# get_root_helper_child_pid (The method under test) internally.
|
||||
sudo_pid = proc._process.pid
|
||||
utils.wait_until_true(
|
||||
common_utils.wait_until_true(
|
||||
functools.partial(
|
||||
wait_for_sleep_is_spawned,
|
||||
sudo_pid),
|
||||
|
@ -201,7 +201,7 @@ class DHCPAgentOVSTestFramework(base.BaseSudoTestCase):
|
||||
|
||||
predicate = lambda: len(
|
||||
self._ip_list_for_vif(vif_name, network.namespace))
|
||||
utils.wait_until_true(predicate, 10)
|
||||
common_utils.wait_until_true(predicate, 10)
|
||||
|
||||
ip_list = self._ip_list_for_vif(vif_name, network.namespace)
|
||||
cidr = ip_list[0].get('cidr')
|
||||
@ -286,7 +286,7 @@ class DHCPAgentOVSTestCase(DHCPAgentOVSTestFramework):
|
||||
self.addCleanup(self.agent.disable_isolated_metadata_proxy, network)
|
||||
self.configure_dhcp_for_network(network=network)
|
||||
pm = self._get_metadata_proxy_process(network)
|
||||
utils.wait_until_true(
|
||||
common_utils.wait_until_true(
|
||||
lambda: pm.active,
|
||||
timeout=5,
|
||||
sleep=0.01,
|
||||
@ -298,7 +298,7 @@ class DHCPAgentOVSTestCase(DHCPAgentOVSTestFramework):
|
||||
old_pid = pm.pid
|
||||
|
||||
utils.execute(['kill', '-9', old_pid], run_as_root=True)
|
||||
utils.wait_until_true(
|
||||
common_utils.wait_until_true(
|
||||
lambda: pm.active and pm.pid != old_pid,
|
||||
timeout=5,
|
||||
sleep=0.1,
|
||||
@ -309,7 +309,7 @@ class DHCPAgentOVSTestCase(DHCPAgentOVSTestFramework):
|
||||
|
||||
self.conf.set_override('enable_isolated_metadata', False)
|
||||
self.configure_dhcp_for_network(network=network)
|
||||
utils.wait_until_true(
|
||||
common_utils.wait_until_true(
|
||||
lambda: not pm.active,
|
||||
timeout=5,
|
||||
sleep=0.1,
|
||||
@ -325,7 +325,7 @@ class DHCPAgentOVSTestCase(DHCPAgentOVSTestFramework):
|
||||
self.agent.start_ready_ports_loop()
|
||||
self.configure_dhcp_for_network(network)
|
||||
ports_to_send = {p.id for p in network.ports}
|
||||
utils.wait_until_true(
|
||||
common_utils.wait_until_true(
|
||||
lambda: self.mock_plugin_api.dhcp_ready_on_ports.called,
|
||||
timeout=1,
|
||||
sleep=0.1,
|
||||
|
@ -17,7 +17,8 @@
|
||||
import time
|
||||
|
||||
from eventlet.timeout import Timeout
|
||||
from neutron.agent.linux import utils as agent_utils
|
||||
|
||||
from neutron.common import utils
|
||||
from neutron.plugins.ml2.drivers.openvswitch.agent.common import constants
|
||||
from neutron.tests.common import net_helpers
|
||||
from neutron.tests.functional.agent.l2 import base
|
||||
@ -60,7 +61,7 @@ class TestOVSAgent(base.OVSAgentTestFramework):
|
||||
if port.port_name in portnames]
|
||||
|
||||
#wait until ports are marked dead, with drop flow
|
||||
agent_utils.wait_until_true(
|
||||
utils.wait_until_true(
|
||||
lambda: num_ports_with_drop_flows(
|
||||
ofports,
|
||||
self.agent.int_br.dump_flows(
|
||||
|
@ -10,8 +10,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import eventlet
|
||||
import os.path
|
||||
import stat
|
||||
import testtools
|
||||
|
||||
from neutron.common import utils
|
||||
from neutron.tests import base
|
||||
@ -49,3 +51,12 @@ class TestReplaceFile(base.BaseTestCase):
|
||||
file_mode = 0o777
|
||||
utils.replace_file(self.file_name, self.data, file_mode)
|
||||
self._verify_result(file_mode)
|
||||
|
||||
|
||||
class TestWaitUntilTrue(base.BaseTestCase):
|
||||
def test_wait_until_true_predicate_succeeds(self):
|
||||
utils.wait_until_true(lambda: True)
|
||||
|
||||
def test_wait_until_true_predicate_fails(self):
|
||||
with testtools.ExpectedException(eventlet.timeout.Timeout):
|
||||
utils.wait_until_true(lambda: False, 2)
|
||||
|
@ -24,7 +24,7 @@ import mock
|
||||
from oslo_config import cfg
|
||||
import psutil
|
||||
|
||||
from neutron.agent.linux import utils
|
||||
from neutron.common import utils
|
||||
from neutron import service
|
||||
from neutron.tests import base
|
||||
from neutron import worker as neutron_worker
|
||||
|
Loading…
x
Reference in New Issue
Block a user