示例#1
0
def test_get_ovs_info_with_ports_with_interfaces(
    nm_connection_mock, nm_device_mock, NM_mock
):
    bridge_device = mock.MagicMock()
    port_device = mock.MagicMock()
    bridge_active_con = mock.MagicMock()
    port_active_con = mock.MagicMock()
    nm_device_mock.get_device_by_name.return_value = port_device
    _mock_port_profile(nm_connection_mock)
    nm_connection_mock.get_device_active_connection = (
        lambda dev: bridge_active_con
        if dev == bridge_device
        else port_active_con
    )
    bridge_active_con.props.master = bridge_device
    port_active_con.props.master = port_device

    device_info = [(bridge_device, None), (port_device, None)]
    info = nm.ovs.get_ovs_info(bridge_device, device_info)

    assert len(info['port']) == 1
    assert 'name' in info['port'][0]
    assert 'type' in info['port'][0]
    assert 'vlan-mode' in info['port'][0]
    assert 'access-tag' in info['port'][0]
示例#2
0
def test_get_info_with_ipv6_config(NM_mock):
    act_con_mock = mock.MagicMock()
    config_mock = act_con_mock.get_ip6_config.return_value
    address_mock = mock.MagicMock()
    config_mock.get_addresses.return_value = [address_mock]
    remote_conn_mock = mock.MagicMock()
    act_con_mock.get_connection.return_value = remote_conn_mock
    set_ip_conf = mock.MagicMock()
    remote_conn_mock.get_setting_ip6_config.return_value = set_ip_conf
    set_ip_conf.get_method.return_value = (
        NM_mock.SETTING_IP6_CONFIG_METHOD_MANUAL)
    set_ip_conf.props.never_default = False
    set_ip_conf.props.ignore_auto_dns = False
    set_ip_conf.props.ignore_auto_routes = False

    info = nm.ipv6.get_info(active_connection=act_con_mock)

    assert info == {
        'enabled':
        True,
        'autoconf':
        False,
        'dhcp':
        False,
        'address': [{
            'ip': address_mock.get_address.return_value,
            'prefix-length': int(address_mock.get_prefix.return_value),
        }]
    }
示例#3
0
def test_get_info_with_ipv4_config(NM_mock):
    act_con_mock = mock.MagicMock()
    config_mock = act_con_mock.get_ip4_config.return_value
    address_mock = mock.MagicMock()
    config_mock.get_addresses.return_value = [address_mock]
    remote_conn_mock = mock.MagicMock()
    act_con_mock.get_connection.return_value = remote_conn_mock
    set_ip_conf = mock.MagicMock()
    remote_conn_mock.get_setting_ip4_config.return_value = set_ip_conf
    set_ip_conf.get_method.return_value = (
        NM_mock.SETTING_IP4_CONFIG_METHOD_MANUAL
    )
    set_ip_conf.props.never_default = False
    set_ip_conf.props.ignore_auto_dns = False
    set_ip_conf.props.ignore_auto_routes = False

    info = nm.ipv4.get_info(active_connection=act_con_mock)

    assert info == {
        InterfaceIPv4.ENABLED: True,
        InterfaceIPv4.DHCP: False,
        InterfaceIPv4.ADDRESS: [
            {
                InterfaceIPv4.ADDRESS_IP: (
                    address_mock.get_address.return_value
                ),
                InterfaceIPv4.ADDRESS_PREFIX_LENGTH: int(
                    address_mock.get_prefix.return_value
                ),
            }
        ],
    }
示例#4
0
def test_edit_existing_ifaces_with_profile(nm_device_mock, nm_connection_mock):
    con_profiles = [mock.MagicMock(), mock.MagicMock()]

    nm.applier.edit_existing_ifaces(con_profiles)

    nm_connection_mock.commit_profile.assert_has_calls(
        [mock.call(con_profiles[0]), mock.call(con_profiles[1])])
示例#5
0
def test_delete(con_profile_mock):
    dev = mock.MagicMock()
    dev.get_available_connections.return_value = [mock.MagicMock()]
    con_profile = con_profile_mock()

    nm.device.delete(dev)

    con_profile.delete.assert_called_once()
示例#6
0
def test_edit_existing_ifaces_without_profile(con_profile_mock,
                                              nm_device_mock):
    con_profiles = [mock.MagicMock(), mock.MagicMock()]
    con_profile_mock.return_value.profile = None

    nm.applier.edit_existing_ifaces(con_profiles)

    for con_profile in con_profiles:
        con_profile.add.assert_has_calls([mock.call(save_to_disk=True)])
示例#7
0
def test_edit_existing_ifaces_with_profile(nm_device_mock, nm_connection_mock):
    con_profiles = [mock.MagicMock(), mock.MagicMock()]

    nm.applier.edit_existing_ifaces(con_profiles)

    nm_connection_mock.commit_profile.assert_has_calls([
        mock.call(con_profiles[0],
                  nmdev=nm_device_mock.get_device_by_name.return_value),
        mock.call(con_profiles[1],
                  nmdev=nm_device_mock.get_device_by_name.return_value)
    ])
示例#8
0
def test_edit_existing_ifaces_without_profile(nm_device_mock,
                                              nm_connection_mock):
    con_profiles = [mock.MagicMock(), mock.MagicMock()]
    nm_connection_mock.get_device_connection.return_value = None

    nm.applier.edit_existing_ifaces(con_profiles)

    nm_connection_mock.add_profile.assert_has_calls([
        mock.call(con_profiles[0], save_to_disk=True),
        mock.call(con_profiles[1], save_to_disk=True)
    ])
示例#9
0
def test_delete(mainloop_mock):
    dev = mock.MagicMock()
    dev.get_available_connections.return_value = [mock.MagicMock()]
    mainloop_mock.push_action = lambda func, dev: func(dev)
    nm.device.delete(dev)

    dev.get_available_connections.assert_called_once()
    connections = dev.get_available_connections.return_value

    connections[0].delete_async.assert_called_once_with(
        mainloop_mock.cancellable, nm.device._delete_connection_callback,
        mainloop_mock)
示例#10
0
def test_create_setting_duplicate(NM_mock):
    base_profile = mock.MagicMock()

    setting = nm.wired.create_setting({'ethernet': {'speed': 1000}},
                                      base_profile)
    assert setting == \
        base_profile.get_setting_wired.return_value.duplicate.return_value
示例#11
0
def test_activate(con_profile_mock):
    dev = mock.MagicMock()
    con_profile = con_profile_mock()

    nm.device.activate(dev)

    con_profile.activate.assert_called_once()
示例#12
0
def test_get_info_with_ipv4_config():
    act_con_mock = mock.MagicMock()
    config_mock = act_con_mock.get_ip4_config.return_value
    address_mock = mock.MagicMock()
    config_mock.get_addresses.return_value = [address_mock]

    info = nm.ipv4.get_info(active_connection=act_con_mock)

    assert info == {
        'enabled':
        True,
        'address': [{
            'ip': address_mock.get_address.return_value,
            'prefix-length': int(address_mock.get_prefix.return_value),
        }]
    }
示例#13
0
def test_get_info_with_no_ipv4_config():
    con_mock = mock.MagicMock()
    con_mock.get_ip4_config.return_value = None

    info = nm.ipv4.get_info(active_connection=con_mock)

    assert info == {'enabled': False}
示例#14
0
def test_set_master_setting():
    con_setting_mock = mock.MagicMock()

    nm.connection.set_master_setting(con_setting_mock, 'master0', 'slave-type')

    assert con_setting_mock.props.master == 'master0'
    assert con_setting_mock.props.slave_type == 'slave-type'
示例#15
0
def test_deactivate(act_con_mock):
    dev = mock.MagicMock()
    act_con = act_con_mock()

    nm.device.deactivate(dev)

    assert act_con.nmdevice == dev
    act_con.deactivate.assert_called_once()
示例#16
0
def test_get_info_with_no_ipv4_config():
    con_mock = mock.MagicMock()
    con_mock.get_ip4_config.return_value = None
    con_mock.get_connection.return_value = None

    info = nm.ipv4.get_info(active_connection=con_mock)

    assert info == {InterfaceIPv4.ENABLED: False}
示例#17
0
def test_update_profile():
    base_profile = nm.connection.ConnectionProfile('p')

    profile = mock.MagicMock()
    con_profile = nm.connection.ConnectionProfile(profile)
    con_profile.update(base_profile)

    profile.replace_settings_from_connection.assert_called_once_with('p')
示例#18
0
def test_get_info_with_invalid_duplex(ethtool_mock, NM_mock):
    dev_mock = mock.MagicMock()
    dev_mock.get_iface.return_value = 'nmstate_test'
    dev_mock.get_mtu.return_value = 1500
    dev_mock.get_device_type.return_value = NM_mock.DeviceType.ETHERNET

    info = nm.wired.get_info(dev_mock)

    assert info == {'mtu': dev_mock.get_mtu.return_value}
示例#19
0
def test_create_setting_duplicate(NM_mock):
    base_profile = mock.MagicMock()

    setting = nm.user.create_setting({'description': 'test_interface'},
                                     base_profile)
    base_profile.get_setting_by_name.assert_called_with(
        NM_mock.SETTING_USER_SETTING_NAME)
    assert setting == \
        base_profile.get_setting_by_name.return_value.duplicate.return_value
示例#20
0
def test_get_device_connection():
    dev_mock = mock.MagicMock()

    con = nm.connection.ConnectionProfile()
    con.import_by_device(dev_mock)

    assert (
        dev_mock.get_active_connection.return_value.props.connection
        == con.profile
    )
示例#21
0
def test_nm2api_bond_info():
    slaves_mock = [mock.MagicMock(), mock.MagicMock()]
    bondinfo = {
        'slaves': slaves_mock,
        'options': {'mode': 'balance-rr', 'miimon': 120},
    }
    info = nm.translator.Nm2Api.get_bond_info(bondinfo)

    expected_info = {
        'link-aggregation': {
            'mode': 'balance-rr',
            'slaves': [
                slaves_mock[0].props.interface,
                slaves_mock[1].props.interface,
            ],
            'options': {'miimon': 120},
        }
    }
    assert expected_info == info
示例#22
0
def test_create_setting_duplicate(NM_mock):
    base_profile = mock.MagicMock()

    setting = nm.wired.create_setting(
        {schema.Ethernet.CONFIG_SUBTREE: {schema.Ethernet.SPEED: 1000}},
        base_profile,
    )
    assert (
        setting
        == base_profile.get_setting_wired.return_value.duplicate.return_value
    )
示例#23
0
def test_commit_profile(mainloop_mock):
    con_profile = mock.MagicMock()
    save_to_disk = True
    nm.connection.commit_profile(con_profile, save_to_disk)

    mainloop_mock.push_action.assert_called_once_with(
        con_profile.commit_changes_async,
        save_to_disk,
        mainloop_mock.cancellable,
        nm.connection._commit_changes_callback,
        mainloop_mock,
    )
示例#24
0
def test_get_ovs_info_with_ports_without_interfaces(nm_connection_mock,
                                                    nm_device_mock, NM_mock):
    bridge_device = mock.MagicMock()
    port_device = mock.MagicMock()
    _mock_port_profile(nm_connection_mock)
    active_con = nm_connection_mock.get_device_active_connection.return_value
    active_con.props.master = bridge_device

    device_info = [(bridge_device, None), (port_device, None)]
    info = nm.ovs.get_ovs_info(bridge_device, device_info)

    expected_info = {
        'port': [],
        'options': {
            'fail-mode': '',
            'mcast-snooping-enable': False,
            'rstp': False,
            'stp': False
        },
    }
    assert expected_info == info
示例#25
0
def test_get_device_common_info():
    dev = mock.MagicMock()

    info = nm.device.get_device_common_info(dev)

    expected_info = {
        'name': dev.get_iface.return_value,
        'type_id': dev.get_device_type.return_value,
        'type_name': dev.get_type_description.return_value,
        'state': dev.get_state.return_value,
    }
    assert expected_info == info
示例#26
0
def test_commit_profile(mainloop_mock):
    profile = mock.MagicMock()
    save_to_disk = True
    con_profile = nm.connection.ConnectionProfile(profile)
    con_profile.commit(save_to_disk)

    mainloop_mock.push_action.assert_called_once_with(
        profile.commit_changes_async,
        save_to_disk,
        mainloop_mock.cancellable,
        nm.connection.ConnectionProfile._commit_changes_callback,
        (mainloop_mock, None),
    )
示例#27
0
def test_get_info_with_invalid_duplex(ethtool_mock, NM_mock):
    dev_mock = mock.MagicMock()
    dev_mock.get_iface.return_value = 'nmstate_test'
    dev_mock.get_hw_address.return_value = 'ab:cd:ef:01:23:45'
    dev_mock.get_mtu.return_value = 1500
    dev_mock.get_device_type.return_value = NM_mock.DeviceType.ETHERNET

    info = nm.wired.get_info(dev_mock)

    assert info == {
        schema.Interface.MAC: dev_mock.get_hw_address.return_value,
        schema.Interface.MTU: dev_mock.get_mtu.return_value,
    }
示例#28
0
    def test_set_ifaces_admin_state_up(self, nm_device_mock):
        ifaces_desired_state = [{
            'name': 'eth0',
            'type': 'ethernet',
            'state': 'up'
        }]
        con_profile = mock.MagicMock()
        con_profile.devname = ifaces_desired_state[0]['name']
        nm.applier.set_ifaces_admin_state(ifaces_desired_state, [con_profile])

        nm_device_mock.modify.assert_called_once_with(
            nm_device_mock.get_device_by_name.return_value,
            con_profile.profile)
示例#29
0
def test_deactivate(client_mock, mainloop_mock):
    dev = mock.MagicMock()
    nm.device.deactivate(dev)

    dev.get_active_connection.assert_called_once()

    mainloop_mock.push_action.assert_called_once_with(
        client_mock.deactivate_connection_async,
        dev.get_active_connection.return_value,
        mainloop_mock.cancellable,
        nm.device._deactivate_connection_callback,
        mainloop_mock,
    )
示例#30
0
    def test_set_bond_and_its_slaves_admin_state_up(self, nm_device_mock,
                                                    nm_bond_mock):
        ifaces_desired_state = [
            {
                'name': 'bond0',
                'type': 'bond',
                'state': 'up',
                'link-aggregation': {
                    'mode': '802.3ad',
                    'slaves': ['eth0']
                },
            },
            {
                'name': 'eth0',
                'type': 'ethernet',
                'state': 'up'
            },
        ]

        nm_device_mock.get_device_by_name = lambda devname: devname
        bond = ifaces_desired_state[0]['name']
        slaves = ifaces_desired_state[0]['link-aggregation']['slaves']
        nm_bond_mock.BOND_TYPE = nm.bond.BOND_TYPE
        nm_bond_mock.get_slaves.return_value = slaves

        bond_con_profile = mock.MagicMock()
        bond_con_profile.devname = ifaces_desired_state[0]['name']
        slave_con_profile = mock.MagicMock()
        slave_con_profile.devname = ifaces_desired_state[1]['name']

        nm.applier.set_ifaces_admin_state(
            ifaces_desired_state, [bond_con_profile, slave_con_profile])

        expected_calls = [
            mock.call(bond, bond_con_profile.profile),
            mock.call(slaves[0], slave_con_profile.profile),
        ]
        actual_calls = nm_device_mock.modify.mock_calls
        assert sorted(expected_calls) == sorted(actual_calls)