mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-22 01:13:00 +02:00
test: iface_enable_disable: Simplify test
This commit is contained in:
@@ -13,26 +13,6 @@ import infamy.iface as iface
|
||||
|
||||
from infamy import until
|
||||
|
||||
def print_error_message(iface, param, exp_val, act_val):
|
||||
return f"'{param}' failure for interface '{iface}'. Expected '{exp_val}', Actual: '{act_val}'"
|
||||
|
||||
def assert_param(target, interface, parameter, expected_value):
|
||||
def check_param():
|
||||
actual_value = iface.get_param(target, interface, parameter)
|
||||
if actual_value is None:
|
||||
raise ValueError(f"Failed to retrieve '{parameter}' for interface '{interface}'")
|
||||
return actual_value == expected_value
|
||||
|
||||
until(check_param)
|
||||
|
||||
actual_value = iface.get_param(target, interface, parameter)
|
||||
assert (expected_value == actual_value), print_error_message(
|
||||
iface=interface,
|
||||
param = parameter,
|
||||
exp_val = expected_value,
|
||||
act_val = actual_value
|
||||
)
|
||||
|
||||
def configure_interface(target, iface_name, iface_type=None, enabled=True, ip_address=None, bridge=None):
|
||||
|
||||
interface_config = {
|
||||
@@ -47,7 +27,7 @@ def configure_interface(target, iface_name, iface_type=None, enabled=True, ip_ad
|
||||
interface_config["ipv4"] = {
|
||||
"address": [
|
||||
{
|
||||
"ip": ip_address,
|
||||
"ip": ip_address,
|
||||
"prefix-length": 24
|
||||
}]}
|
||||
|
||||
@@ -76,7 +56,7 @@ with infamy.Test() as test:
|
||||
_bridge = "br_0"
|
||||
|
||||
target_address = "10.10.10.2"
|
||||
host_address = "10.10.10.1"
|
||||
host_address = "10.10.10.1"
|
||||
|
||||
with test.step("Configure bridge and associated interfaces in target1"):
|
||||
configure_interface(target1, _bridge, enabled=True, iface_type="infix-if-type:bridge")
|
||||
@@ -87,19 +67,19 @@ with infamy.Test() as test:
|
||||
configure_interface(target2, iface_under_test, enabled=False)
|
||||
|
||||
with test.step("Verify the interface is disabled"):
|
||||
assert_param(target2, iface_under_test, "admin-status", "down")
|
||||
assert_param(target2, iface_under_test, "oper-status", "down")
|
||||
until(lambda: iface.get_param(target2, iface_under_test, "admin-status") == "down")
|
||||
until(lambda: iface.get_param(target2, iface_under_test, "oper-status") == "down")
|
||||
|
||||
with test.step("Enable the interface and assign an IP address"):
|
||||
configure_interface(target2, iface_under_test, enabled=True, ip_address=target_address)
|
||||
|
||||
|
||||
with test.step("Verify the interface is enabled"):
|
||||
assert_param(target2, iface_under_test, "admin-status", "up")
|
||||
assert_param(target2, iface_under_test, "oper-status", "up")
|
||||
until(lambda: iface.get_param(target2, iface_under_test, "admin-status") == "up")
|
||||
until(lambda: iface.get_param(target2, iface_under_test, "oper-status") == "up")
|
||||
|
||||
with infamy.IsolatedMacVlan(host_send_iface) as send_ns:
|
||||
with test.step("Verify it is possible to ping the interface"):
|
||||
send_ns.addip(host_address)
|
||||
send_ns.must_reach(target_address)
|
||||
|
||||
|
||||
test.succeed()
|
||||
|
||||
Reference in New Issue
Block a user