Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
1.9 kB
0
Indexable
Never
@pytest.mark.env("HGW")
def test_remove_and_add_existing_port(sut, bus_path):
    """
    Add a port: Will add a disabled port to the bridge
    """
    connection = pamx.bus.connect(bus_path)
    con = sut.dm.Bridging.Bridge.connection()
    instance_path = "Bridging.Bridge.guest.Port"
    instances = con.call("Bridging.Bridge.guest.Port.[ManagementPort == '0'].", "_get")
    port = list(instances[0].values())[0]
    logging.info(port)
    port_alias = port["Alias"]
    port_path = f"Bridging.Bridge.guest.Port.{port_alias}."
    params = {
        "Name": port["Name"],
        "Alias": port_alias,
        "WirelessSectionName": port["WirelessSectionName"]
    }
 
    try:
        logging.info(f"Deleting Port: {params}")
        with Wait(sut).until_instance_deleted(sut.dm.Bridging.Bridge.guest.Port[port_alias]):
            _delete_instance(bus_path, port_path)
        time.sleep(3)
 
        logging.info(f"Adding port: {params}")
        with Wait(sut).until_instance_added(sut.dm.Bridging.Bridge.guest.Port[port_alias]):
            _add_instance(bus_path, instance_path, params)
 
        port_values = _get_instance_parameters(bus_path, port_path)
        assert port_values["Status"] == "Down"
        assert port_values["Alias"] == port_alias
 
        with Wait(sut).until_parameter_value_equals(
                f"{port_path}Status.",
                "Enabled"):
            connection.set(port_path, {'isWireless': '1'})
            connection.set(port_path, {'Enable': '1'})
 
        assert len(check_ports_linux(sut, "br-guest", "guest")) == 0
 
    finally:
        logging.info(f"Adding port: {params}")
        if object_does_not_exist(sut.dm.Bridging.Bridge.guest.Port[port_alias]):
            with Wait(sut).until_instance_added(sut.dm.Bridging.Bridge.guest.Port[port_alias]):
                _add_instance(bus_path, instance_path, params)