ovn-bgp-agent/ovn_bgp_agent/tests/utils.py
Rodolfo Alonso Hernandez 1cbfe7823c Add new privileged method implementations
This patch add the following new privileged methods implementations:
* create_interface: this method will be used to create dummy, vlan,
  vxlan, bridge and vrf interfaces.
* delete_interface: to delete a interface
* set_link_attribute: to set UP the interface
* add_ip_address: to add an IP address on a interface
* delete_ip_address: to delete an IP address on a interface
* set_master_for_device: defines a master device for a second one

These new method use pyroute2 IPRoute class, replacing the use of the
NDB class.

This patch is creating the functional test framework, in order to
test these new methods.

This patch is also adding a new CI job to the gate (to be defined).

Partial-Bug: #2022357
Change-Id: I40d70829bfccb2df98b822afacbdab7da5a5ab7f
2023-06-15 12:12:08 +02:00

48 lines
1.7 KiB
Python

# Copyright 2022 Red Hat, 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.
import eventlet
class WaitTimeout(Exception):
"""Default exception coming from wait_until_true() function."""
def create_row(**kwargs):
return type('FakeRow', (object,), kwargs)
def wait_until_true(predicate, timeout=60, sleep=1, exception=None):
"""Wait until callable predicate is evaluated as True
Imported from ``neutron.common.utils``.
: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 instance to raise on timeout. If None is passed
(default) then WaitTimeout exception is raised.
"""
try:
with eventlet.Timeout(timeout):
while not predicate():
eventlet.sleep(sleep)
except eventlet.Timeout:
if exception is not None:
# pylint: disable=raising-bad-type
raise exception
raise WaitTimeout('Timed out after %d seconds' % timeout)