| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
import functools |
| 13 |
import os |
| 14 |
|
| 15 |
from os_vif.tests.functional import base as os_vif_base |
| 16 |
|
| 17 |
|
| 18 |
wait_until_true = os_vif_base.wait_until_true |
| 19 |
|
| 20 |
|
| 21 |
class VifPlugOvsBaseFunctionalTestCase(os_vif_base.BaseFunctionalTestCase): |
| 22 |
"""Base class for vif_plug_ovs functional tests.""" |
| 23 |
|
| 24 |
COMPONENT_NAME = 'vif_plug_ovs' |
| 25 |
PRIVILEGED_GROUP = 'vif_plug_ovs_privileged' |
| 26 |
|
| 27 |
def _check_bridge(self, name): |
| 28 |
return self._ovsdb.br_exists(name).execute() |
| 29 |
|
| 30 |
def _check_port(self, name, bridge): |
| 31 |
return self.ovs.port_exists(name, bridge) |
| 32 |
|
| 33 |
@functools.cache |
| 34 |
def _get_timeout(self): |
| 35 |
return int(os.environ.get('OS_VIF_CHECK_PARAMETER_TIMEOUT', '10')) |
| 36 |
|
| 37 |
def _check_parameter(self, table, port, parameter, expected_value): |
| 38 |
def get_value(): |
| 39 |
return self._ovsdb.db_get(table, port, parameter).execute() |
| 40 |
|
| 41 |
def check_value(): |
| 42 |
val = get_value() |
| 43 |
return val == expected_value |
| 44 |
self.assertTrue( |
| 45 |
wait_until_true( |
| 46 |
check_value, timeout=self._get_timeout(), sleep=0.5), |
| 47 |
f"Parameter {parameter} of {table} {port} is {get_value()} " |
| 48 |
f"not {expected_value}" |
| 49 |
) |
| 50 |
|
| 51 |
def _add_bridge(self, name, may_exist=True, datapath_type=None): |
| 52 |
self._ovsdb.add_br(name, may_exist=may_exist, |
| 53 |
datapath_type=datapath_type).execute() |
| 54 |
self.assertTrue(self._check_bridge(name)) |
| 55 |
|
| 56 |
def _del_bridge(self, name): |
| 57 |
self._ovsdb.del_br(name).execute() |