black: Cover tests/integration/nm
Signed-off-by: Edward Haas <edwardh@redhat.com>
This commit is contained in:
parent
dd3ae4227b
commit
01519c12f0
@ -30,7 +30,7 @@ ETH1 = 'eth1'
|
||||
def test_create_and_remove_bond(eth1_up):
|
||||
bond_options = {
|
||||
schema.Bond.MODE: schema.BondMode.ROUND_ROBIN,
|
||||
'miimon': '140'
|
||||
'miimon': '140',
|
||||
}
|
||||
|
||||
with _bond_interface(BOND0, bond_options):
|
||||
@ -38,7 +38,7 @@ def test_create_and_remove_bond(eth1_up):
|
||||
|
||||
bond_desired_state = {
|
||||
schema.Bond.SLAVES: [],
|
||||
schema.Bond.OPTIONS_SUBTREE: bond_options
|
||||
schema.Bond.OPTIONS_SUBTREE: bond_options,
|
||||
}
|
||||
assert bond_desired_state == bond_current_state
|
||||
|
||||
@ -74,7 +74,8 @@ def _create_bond(name, options):
|
||||
|
||||
con_profile = nm.connection.ConnectionProfile()
|
||||
con_profile.create(
|
||||
(con_setting.setting, bond_setting, ipv4_setting, ipv6_setting))
|
||||
(con_setting.setting, bond_setting, ipv4_setting, ipv6_setting)
|
||||
)
|
||||
con_profile.add(save_to_disk=False)
|
||||
nm.device.activate(connection_id=name)
|
||||
|
||||
|
@ -33,9 +33,7 @@ def test_interface_ipv4_change(eth1_up):
|
||||
ipv4_state={
|
||||
'enabled': True,
|
||||
'dhcp': False,
|
||||
'address': [
|
||||
{'ip': IPV4_ADDRESS1, 'prefix-length': 24}
|
||||
]
|
||||
'address': [{'ip': IPV4_ADDRESS1, 'prefix-length': 24}],
|
||||
}
|
||||
)
|
||||
|
||||
@ -45,9 +43,7 @@ def test_interface_ipv4_change(eth1_up):
|
||||
ip4_expected_state = {
|
||||
'enabled': True,
|
||||
'dhcp': False,
|
||||
'address': [
|
||||
{'ip': IPV4_ADDRESS1, 'prefix-length': 24}
|
||||
]
|
||||
'address': [{'ip': IPV4_ADDRESS1, 'prefix-length': 24}],
|
||||
}
|
||||
assert ip4_expected_state == ipv4_current_state
|
||||
|
||||
|
@ -31,11 +31,7 @@ ETH1 = 'eth1'
|
||||
|
||||
@pytest.fixture
|
||||
def bridge_minimum_config():
|
||||
return {
|
||||
LB.CONFIG_SUBTREE: {
|
||||
LB.PORT_SUBTREE: []
|
||||
}
|
||||
}
|
||||
return {LB.CONFIG_SUBTREE: {LB.PORT_SUBTREE: []}}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -51,10 +47,10 @@ def bridge_default_config():
|
||||
LB.STP_FORWARD_DELAY: 15,
|
||||
LB.STP_HELLO_TIME: 2,
|
||||
LB.STP_MAX_AGE: 20,
|
||||
LB.STP_PRIORITY: 32768
|
||||
}
|
||||
LB.STP_PRIORITY: 32768,
|
||||
},
|
||||
},
|
||||
LB.PORT_SUBTREE: []
|
||||
LB.PORT_SUBTREE: [],
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,7 +74,7 @@ def test_create_and_remove_bridge(eth1_up, bridge_default_config):
|
||||
LB.PORT_NAME: 'eth1',
|
||||
LB.PORT_STP_PRIORITY: 32,
|
||||
LB.PORT_STP_HAIRPIN_MODE: False,
|
||||
LB.PORT_STP_PATH_COST: 100
|
||||
LB.PORT_STP_PATH_COST: 100,
|
||||
}
|
||||
|
||||
bridge_desired_state[LB.CONFIG_SUBTREE][LB.PORT_SUBTREE].append(eth1_port)
|
||||
@ -124,8 +120,9 @@ def _attach_port_to_bridge(port_state):
|
||||
eth1_nmdev = nm.device.get_device_by_name(port_state['name'])
|
||||
curr_port_con_profile = nm.connection.ConnectionProfile()
|
||||
curr_port_con_profile.import_by_device(eth1_nmdev)
|
||||
iface_port_settings = _get_iface_port_settings(port_state,
|
||||
curr_port_con_profile)
|
||||
iface_port_settings = _get_iface_port_settings(
|
||||
port_state, curr_port_con_profile
|
||||
)
|
||||
port_con_profile = nm.connection.ConnectionProfile()
|
||||
port_con_profile.create(iface_port_settings)
|
||||
|
||||
@ -147,7 +144,8 @@ def _get_iface_port_settings(port_state, port_con_profile):
|
||||
con_setting.set_master(BRIDGE0, 'bridge')
|
||||
|
||||
bridge_port_setting = nm.bridge.create_port_setting(
|
||||
port_state, port_con_profile.profile)
|
||||
port_state, port_con_profile.profile
|
||||
)
|
||||
return con_setting.setting, bridge_port_setting
|
||||
|
||||
|
||||
@ -165,8 +163,9 @@ def _get_iface_bridge_settings(bridge_options):
|
||||
iface_name=BRIDGE0,
|
||||
iface_type=nm.nmclient.NM.SETTING_BRIDGE_SETTING_NAME,
|
||||
)
|
||||
bridge_setting = nm.bridge.create_setting(bridge_options,
|
||||
base_con_profile=None)
|
||||
bridge_setting = nm.bridge.create_setting(
|
||||
bridge_options, base_con_profile=None
|
||||
)
|
||||
ipv4_setting = nm.ipv4.create_setting({}, None)
|
||||
ipv6_setting = nm.ipv6.create_setting({}, None)
|
||||
return con_setting.setting, bridge_setting, ipv4_setting, ipv6_setting
|
||||
|
@ -32,11 +32,7 @@ ETH1 = 'eth1'
|
||||
|
||||
@pytest.fixture
|
||||
def bridge_minimum_config():
|
||||
return {
|
||||
OB.CONFIG_SUBTREE: {
|
||||
OB.PORT_SUBTREE: []
|
||||
}
|
||||
}
|
||||
return {OB.CONFIG_SUBTREE: {OB.PORT_SUBTREE: []}}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -47,15 +43,16 @@ def bridge_default_config():
|
||||
OB.FAIL_MODE: '',
|
||||
OB.MCAST_SNOOPING_ENABLED: False,
|
||||
OB.RSTP: False,
|
||||
OB.STP: False
|
||||
OB.STP: False,
|
||||
},
|
||||
OB.PORT_SUBTREE: []
|
||||
OB.PORT_SUBTREE: [],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def test_create_and_remove_minimum_config_bridge(bridge_minimum_config,
|
||||
bridge_default_config):
|
||||
def test_create_and_remove_minimum_config_bridge(
|
||||
bridge_minimum_config, bridge_default_config
|
||||
):
|
||||
bridge_desired_state = bridge_minimum_config
|
||||
|
||||
with _bridge_interface(bridge_desired_state):
|
||||
@ -89,10 +86,7 @@ def test_bridge_with_system_port(eth1_up, bridge_default_config):
|
||||
def test_bridge_with_internal_interface(eth1_up, bridge_default_config):
|
||||
bridge_desired_state = bridge_default_config
|
||||
|
||||
ovs_port = {
|
||||
OB.PORT_NAME: 'ovs0',
|
||||
OB.PORT_TYPE: OBPortType.INTERNAL,
|
||||
}
|
||||
ovs_port = {OB.PORT_NAME: 'ovs0', OB.PORT_TYPE: OBPortType.INTERNAL}
|
||||
|
||||
bridge_desired_state[OB.CONFIG_SUBTREE][OB.PORT_SUBTREE].append(ovs_port)
|
||||
|
||||
@ -120,8 +114,10 @@ def _get_bridge_current_state():
|
||||
state = {}
|
||||
nmdev = nm.device.get_device_by_name(BRIDGE0)
|
||||
if nmdev:
|
||||
devices_info = [(dev, nm.device.get_device_common_info(dev))
|
||||
for dev in nm.device.list_devices()]
|
||||
devices_info = [
|
||||
(dev, nm.device.get_device_common_info(dev))
|
||||
for dev in nm.device.list_devices()
|
||||
]
|
||||
state = nm.ovs.get_bridge_info(nmdev, devices_info)
|
||||
return state
|
||||
|
||||
@ -149,8 +145,7 @@ def _attach_port_to_bridge(port_state):
|
||||
|
||||
|
||||
def _create_internal_interface(iface_name, master_name):
|
||||
iface_settings = _create_internal_iface_setting(iface_name,
|
||||
master_name)
|
||||
iface_settings = _create_internal_iface_setting(iface_name, master_name)
|
||||
iface_con_profile = nm.connection.ConnectionProfile()
|
||||
iface_con_profile.create(iface_settings)
|
||||
iface_con_profile.add(save_to_disk=False)
|
||||
@ -161,8 +156,9 @@ def _connect_interface(port_profile_name, port_state):
|
||||
iface_nmdev = nm.device.get_device_by_name(port_state[OB.PORT_NAME])
|
||||
curr_iface_con_profile = nm.connection.ConnectionProfile()
|
||||
curr_iface_con_profile.import_by_device(iface_nmdev)
|
||||
slave_iface_settings = _create_iface_settings(curr_iface_con_profile,
|
||||
port_profile_name)
|
||||
slave_iface_settings = _create_iface_settings(
|
||||
curr_iface_con_profile, port_profile_name
|
||||
)
|
||||
iface_con_profile = nm.connection.ConnectionProfile()
|
||||
iface_con_profile.create(slave_iface_settings)
|
||||
curr_iface_con_profile.update(iface_con_profile)
|
||||
@ -197,7 +193,7 @@ def _create_port_setting(port_state, port_profile_name):
|
||||
iface_con_setting.create(
|
||||
con_name=port_profile_name,
|
||||
iface_name=port_profile_name,
|
||||
iface_type=nm.ovs.PORT_TYPE
|
||||
iface_type=nm.ovs.PORT_TYPE,
|
||||
)
|
||||
iface_con_setting.set_master(BRIDGE0, nm.ovs.BRIDGE_TYPE)
|
||||
port_options = nm.ovs.translate_port_options(port_state)
|
||||
@ -210,7 +206,7 @@ def _create_internal_iface_setting(iface_name, master_name):
|
||||
iface_con_setting.create(
|
||||
con_name=iface_name,
|
||||
iface_name=iface_name,
|
||||
iface_type=nm.ovs.INTERNAL_INTERFACE_TYPE
|
||||
iface_type=nm.ovs.INTERNAL_INTERFACE_TYPE,
|
||||
)
|
||||
iface_con_setting.set_master(master_name, nm.ovs.PORT_TYPE)
|
||||
bridge_internal_iface_setting = nm.ovs.create_interface_setting()
|
||||
@ -220,7 +216,7 @@ def _create_internal_iface_setting(iface_name, master_name):
|
||||
iface_con_setting.setting,
|
||||
bridge_internal_iface_setting,
|
||||
ipv4_setting,
|
||||
ipv6_setting
|
||||
ipv6_setting,
|
||||
)
|
||||
|
||||
|
||||
@ -230,9 +226,10 @@ def _delete_iface(devname):
|
||||
if nmdev:
|
||||
nm.device.delete(nmdev)
|
||||
if nmdev.get_device_type() in (
|
||||
nm.nmclient.NM.DeviceType.OVS_BRIDGE,
|
||||
nm.nmclient.NM.DeviceType.OVS_PORT,
|
||||
nm.nmclient.NM.DeviceType.OVS_INTERFACE):
|
||||
nm.nmclient.NM.DeviceType.OVS_BRIDGE,
|
||||
nm.nmclient.NM.DeviceType.OVS_PORT,
|
||||
nm.nmclient.NM.DeviceType.OVS_INTERFACE,
|
||||
):
|
||||
nm.device.delete_device(nmdev)
|
||||
else:
|
||||
con_profile = nm.connection.ConnectionProfile()
|
||||
|
@ -39,4 +39,5 @@ def mainloop_run(func):
|
||||
def wrapper_mainloop(*args, **kwargs):
|
||||
with mainloop():
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return wrapper_mainloop
|
||||
|
@ -60,14 +60,16 @@ def _create_vlan(vlan_desired_state):
|
||||
iface_name=ifname,
|
||||
iface_type=nm.nmclient.NM.SETTING_VLAN_SETTING_NAME,
|
||||
)
|
||||
vlan_setting = nm.vlan.create_setting(vlan_desired_state,
|
||||
base_con_profile=None)
|
||||
vlan_setting = nm.vlan.create_setting(
|
||||
vlan_desired_state, base_con_profile=None
|
||||
)
|
||||
ipv4_setting = nm.ipv4.create_setting({}, None)
|
||||
ipv6_setting = nm.ipv6.create_setting({}, None)
|
||||
with mainloop():
|
||||
con_profile = nm.connection.ConnectionProfile()
|
||||
con_profile.create(
|
||||
(con_setting.setting, vlan_setting, ipv4_setting, ipv6_setting))
|
||||
(con_setting.setting, vlan_setting, ipv4_setting, ipv6_setting)
|
||||
)
|
||||
con_profile.add(save_to_disk=False)
|
||||
nm.device.activate(connection_id=ifname)
|
||||
|
||||
|
@ -42,15 +42,17 @@ def test_interface_mtu_change_with_modify(eth1_up):
|
||||
def _test_interface_mtu_change(apply_operation):
|
||||
wired_base_state = _get_wired_current_state(ETH1)
|
||||
with mainloop():
|
||||
_modify_interface(wired_state={schema.Interface.MTU: MTU0},
|
||||
apply_operation=apply_operation)
|
||||
_modify_interface(
|
||||
wired_state={schema.Interface.MTU: MTU0},
|
||||
apply_operation=apply_operation,
|
||||
)
|
||||
|
||||
nm.nmclient.client(refresh=True)
|
||||
wired_current_state = _get_wired_current_state(ETH1)
|
||||
|
||||
assert wired_current_state == {
|
||||
schema.Interface.MAC: wired_base_state[schema.Interface.MAC],
|
||||
schema.Interface.MTU: MTU0
|
||||
schema.Interface.MTU: MTU0,
|
||||
}
|
||||
|
||||
|
||||
@ -66,15 +68,17 @@ def test_interface_mac_change_with_modify(eth1_up):
|
||||
def _test_interface_mac_change(apply_operation):
|
||||
wired_base_state = _get_wired_current_state(ETH1)
|
||||
with mainloop():
|
||||
_modify_interface(wired_state={schema.Interface.MAC: MAC0},
|
||||
apply_operation=apply_operation)
|
||||
_modify_interface(
|
||||
wired_state={schema.Interface.MAC: MAC0},
|
||||
apply_operation=apply_operation,
|
||||
)
|
||||
|
||||
nm.nmclient.client(refresh=True)
|
||||
wired_current_state = _get_wired_current_state(ETH1)
|
||||
|
||||
assert wired_current_state == {
|
||||
schema.Interface.MAC: MAC0,
|
||||
schema.Interface.MTU: wired_base_state[schema.Interface.MTU]
|
||||
schema.Interface.MTU: wired_base_state[schema.Interface.MTU],
|
||||
}
|
||||
|
||||
|
||||
@ -100,8 +104,7 @@ def _create_iface_settings(wired_state, con_profile):
|
||||
con_setting = nm.connection.ConnectionSetting()
|
||||
con_setting.import_by_profile(con_profile)
|
||||
|
||||
wired_setting = nm.wired.create_setting(wired_state,
|
||||
con_profile.profile)
|
||||
wired_setting = nm.wired.create_setting(wired_state, con_profile.profile)
|
||||
ipv4_setting = nm.ipv4.create_setting({}, None)
|
||||
ipv6_setting = nm.ipv6.create_setting({}, None)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user