def bond_nics(prefix, api):
    engine = api.system_service()

    def _bond_nics(number, host):
        slaves = [HostNic(name=nic) for nic in _host_vm_nics(  # eth2, eth3
                    prefix, host.name, LIBVIRT_NETWORK_FOR_BONDING)]

        options = [
            Option(name='mode', value='active-backup'),
            Option(name='miimon', value='200'),
            ]

        bond = HostNic(
            name=BOND_NAME,
            bonding=Bonding(slaves=slaves, options=options))

        ip_configuration = network_utils_v4.create_static_ip_configuration(
            MIGRATION_NETWORK_IPv4_ADDR.format(number),
            MIGRATION_NETWORK_IPv4_MASK,
            MIGRATION_NETWORK_IPv6_ADDR.format(number),
            MIGRATION_NETWORK_IPv6_MASK)

        host_service = engine.hosts_service().host_service(id=host.id)
        network_utils_v4.attach_network_to_host(
            host_service, BOND_NAME, MIGRATION_NETWORK, ip_configuration,
            [bond])

    hosts = test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME)
    utils.invoke_in_parallel(_bond_nics, range(1, len(hosts) + 1), hosts)

    for host in test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME):
        host_service = engine.hosts_service().host_service(id=host.id)
        nt.assert_true(_host_is_attached_to_network(
            engine, host_service, MIGRATION_NETWORK, nic_name=BOND_NAME))
def bond_nics(prefix, api):
    engine = api.system_service()

    def _bond_nics(number, host):
        slaves = [HostNic(name=nic) for nic in _host_vm_nics(  # eth2, eth3
                    prefix, host.name, LIBVIRT_NETWORK_FOR_BONDING)]

        options = [
            Option(name='mode', value='active-backup'),
            Option(name='miimon', value='200'),
            ]

        bond = HostNic(
            name=BOND_NAME,
            bonding=Bonding(slaves=slaves, options=options))

        ip_configuration = network_utils_v4.create_static_ip_configuration(
            MIGRATION_NETWORK_IPv4_ADDR.format(number),
            MIGRATION_NETWORK_IPv4_MASK,
            MIGRATION_NETWORK_IPv6_ADDR.format(number),
            MIGRATION_NETWORK_IPv6_MASK)

        host_service = engine.hosts_service().host_service(id=host.id)
        network_utils_v4.attach_network_to_host(
            host_service, BOND_NAME, MIGRATION_NETWORK, ip_configuration,
            [bond])

    hosts = test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME)
    utils.invoke_in_parallel(_bond_nics, range(1, len(hosts) + 1), hosts)

    for host in test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME):
        host_service = engine.hosts_service().host_service(id=host.id)
        nt.assert_true(_host_is_attached_to_network(
            engine, host_service, MIGRATION_NETWORK, nic_name=BOND_NAME))
Beispiel #3
0
def assign_hosts_network_label(api):
    """
    Assigns NETWORK_LABEL to first network interface of every host in cluster
    """
    engine = api.system_service()

    def _assign_host_network_label(host):
        host_service = engine.hosts_service().host_service(id=host.id)
        nics_service = host_service.nics_service()
        nics = sorted(nics_service.list(),
                      key=lambda n: n.name)
        nt.assert_greater_equal(len(nics), 1)
        nic = nics[0]
        nic_service = nics_service.nic_service(id=nic.id)
        labels_service = nic_service.network_labels_service()
        return labels_service.add(
                NetworkLabel(
                    id=NETWORK_LABEL,
                    host_nic=nic
                )
            )

    hosts = test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME)
    vec = utils.func_vector(_assign_host_network_label, [(h,) for h in hosts])
    vt = utils.VectorThread(vec)
    vt.start_all()
    nt.assert_true(all(vt.join_all()))
def _attach_vm_network_to_host_static_config(prefix, api, host_num):
    engine = api.system_service()
    host = test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME)[host_num]
    host_service = engine.hosts_service().host_service(id=host.id)
    nic_name = _host_vm_nics(prefix, host.name,
                             LIBVIRT_NETWORK_FOR_MANAGEMENT)[0]  # eth0

    ip_configuration = network_utils_v4.create_static_ip_configuration(
        VM_NETWORK_IPv4_ADDR.format(host_num+1),
        VM_NETWORK_IPv4_MASK,
        VM_NETWORK_IPv6_ADDR.format(host_num+1),
        VM_NETWORK_IPv6_MASK)

    network_utils_v4.attach_network_to_host(
        host_service,
        nic_name,
        VM_NETWORK,
        ip_configuration)

    host_nic = next(nic for nic in host_service.nics_service().list() if
                    nic.name == '{}.{}'.format(nic_name, VM_NETWORK_VLAN_ID))
    nt.assert_equals(IPAddress(host_nic.ip.address),
                     IPAddress(VM_NETWORK_IPv4_ADDR.format(host_num+1)))
    nt.assert_equals(IPAddress(host_nic.ipv6.address),
                     IPAddress(VM_NETWORK_IPv6_ADDR.format(host_num+1)))
def add_fence_agent(api):
    # TODO: This just adds a fence agent to host, does not enable it.
    # Of course, we need to find a fence agents that can work on
    # VMs via the host libvirt, etc...
    engine = api.system_service()
    host = test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME)[0]
    host_service = engine.hosts_service().host_service(id=host.id)

    fence_agents_service = host_service.fence_agents_service()
    nt.assert_true(
        fence_agents_service.add(
            sdk4.types.Agent(
                address='1.2.3.4',
                type='ipmilan',
                username='******',
                password='******',
                options=[
                    sdk4.types.Option(
                        name='myname',
                        value='myvalue',
                    ),
                ],
                order=0,
            )
        )
    )
Beispiel #6
0
def _attach_vm_network_to_host_static_config(api, network_name, host_num):
    engine = api.system_service()

    host = test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME)[host_num]
    host_service = engine.hosts_service().host_service(id=host.id)

    nic_name = backend.default_backend().ifaces_for(host.name,
                                                    network_name)[0]  # eth0
    ip_configuration = network_utils_v4.create_static_ip_configuration(
        VM_NETWORK_IPv4_ADDR.format(host_num + 1), VM_NETWORK_IPv4_MASK,
        VM_NETWORK_IPv6_ADDR.format(host_num + 1), VM_NETWORK_IPv6_MASK)

    network_utils_v4.attach_network_to_host(host_service, nic_name, VM_NETWORK,
                                            ip_configuration)

    host_nic = next(
        nic for nic in host_service.nics_service().list()
        if nic.name == '{}.{}'.format(nic_name, VM_NETWORK_VLAN_ID))

    assert (ipaddress.ip_address(host_nic.ip.address) == ipaddress.ip_address(
        VM_NETWORK_IPv4_ADDR.format(host_num + 1)))

    assert (ipaddress.ip_address(
        host_nic.ipv6.address) == ipaddress.ip_address(
            VM_NETWORK_IPv6_ADDR.format(host_num + 1)))
def add_fence_agent(api):
    # TODO: This just adds a fence agent to host, does not enable it.
    # Of course, we need to find a fence agents that can work on
    # VMs via the host libvirt, etc...
    engine = api.system_service()
    host = test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME)[0]
    host_service = engine.hosts_service().host_service(id=host.id)

    fence_agents_service = host_service.fence_agents_service()
    nt.assert_true(
        fence_agents_service.add(
            sdk4.types.Agent(
                address='1.2.3.4',
                type='ipmilan',
                username='******',
                password='******',
                options=[
                    sdk4.types.Option(
                        name='myname',
                        value='myvalue',
                    ),
                ],
                order=0,
            )
        )
    )
def _attach_vm_network_to_host_static_config(prefix, api, host_num):
    engine = api.system_service()

    host = test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME)[host_num]
    host_service = engine.hosts_service().host_service(id=host.id)

    nic_name = _host_vm_nics(prefix, host.name,
                             LIBVIRT_NETWORK_FOR_MANAGEMENT)[0]  # eth0
    ip_configuration = network_utils_v4.create_static_ip_configuration(
        VM_NETWORK_IPv4_ADDR.format(host_num+1),
        VM_NETWORK_IPv4_MASK,
        VM_NETWORK_IPv6_ADDR.format(host_num+1),
        VM_NETWORK_IPv6_MASK)

    network_utils_v4.attach_network_to_host(
        host_service,
        nic_name,
        VM_NETWORK,
        ip_configuration)

    host_nic = next(nic for nic in host_service.nics_service().list() if
                    nic.name == '{}.{}'.format(nic_name, VM_NETWORK_VLAN_ID))
    nt.assert_equals(IPAddress(host_nic.ip.address),
                     IPAddress(VM_NETWORK_IPv4_ADDR.format(host_num+1)))
    nt.assert_equals(IPAddress(host_nic.ipv6.address),
                     IPAddress(VM_NETWORK_IPv6_ADDR.format(host_num+1)))
def remove_bonding(api):
    engine = api.system_service()

    def _remove_bonding(host):
        host_service = engine.hosts_service().host_service(id=host.id)
        network_utils_v4.detach_network_from_host(
            engine, host_service, MIGRATION_NETWORK, BOND_NAME)

    network_utils_v4.set_network_required_in_cluster(engine, MIGRATION_NETWORK,
                                                     CLUSTER_NAME, False)
    utils.invoke_in_parallel(
        _remove_bonding, test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME))

    for host in test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME):
        host_service = engine.hosts_service().host_service(id=host.id)
        nt.assert_false(_host_is_attached_to_network(engine, host_service,
                                                     MIGRATION_NETWORK))
Beispiel #10
0
def test_remove_bonding(engine_api):
    engine = engine_api.system_service()

    def _remove_bonding(host):
        host_service = engine.hosts_service().host_service(id=host.id)
        network_utils_v4.detach_network_from_host(engine, host_service,
                                                  MIGRATION_NETWORK, BOND_NAME)

    network_utils_v4.set_network_required_in_cluster(engine, MIGRATION_NETWORK,
                                                     CLUSTER_NAME, False)
    utils.invoke_in_parallel(
        _remove_bonding, test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME))

    for host in test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME):
        host_service = engine.hosts_service().host_service(id=host.id)
        assert not _host_is_attached_to_network(engine, host_service,
                                                MIGRATION_NETWORK)
def modify_host_ip_to_dhcp(api):
    engine = api.system_service()

    host = test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME)[0]
    host_service = engine.hosts_service().host_service(id=host.id)
    ip_configuration = network_utils_v4.create_dhcp_ip_configuration()

    network_utils_v4.modify_ip_config(engine, host_service, VM_NETWORK,
                                      ip_configuration)
def modify_host_0_ip_to_dhcp(api):
    engine = api.system_service()

    host = test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME)[0]
    host_service = engine.hosts_service().host_service(id=host.id)
    ip_configuration = network_utils_v4.create_dhcp_ip_configuration()

    network_utils_v4.modify_ip_config(engine, host_service, VM_NETWORK,
                                      ip_configuration)
Beispiel #13
0
def test_detach_vm_network_from_host_0(engine_api):
    engine = engine_api.system_service()

    host = test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME)[0]
    host_service = engine.hosts_service().host_service(id=host.id)

    network_utils_v4.set_network_required_in_cluster(engine, VM_NETWORK,
                                                     CLUSTER_NAME, False)
    network_utils_v4.detach_network_from_host(engine, host_service, VM_NETWORK)

    assert not _host_is_attached_to_network(engine, host_service, VM_NETWORK)
def detach_vm_network_from_host_0(api):
    engine = api.system_service()

    host = test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME)[0]
    host_service = engine.hosts_service().host_service(id=host.id)

    network_utils_v4.set_network_required_in_cluster(
        engine, VM_NETWORK, CLUSTER_NAME, False)
    network_utils_v4.detach_network_from_host(engine, host_service, VM_NETWORK)

    nt.assert_false(_host_is_attached_to_network(engine, host_service,
                                                 VM_NETWORK))
Beispiel #15
0
def test_bond_nics(engine_api, bonding_network_name):
    engine = engine_api.system_service()

    def _bond_nics(number, host):
        slaves = [
            HostNic(name=nic)
            for nic in backend.ifaces_for(host.name, bonding_network_name)
        ]

        options = [
            Option(name='mode', value='active-backup'),
            Option(name='miimon', value='200'),
        ]

        bond = HostNic(name=BOND_NAME,
                       bonding=Bonding(slaves=slaves, options=options))

        ip_configuration = network_utils_v4.create_static_ip_configuration(
            MIGRATION_NETWORK_IPv4_ADDR.format(number),
            MIGRATION_NETWORK_IPv4_MASK,
            MIGRATION_NETWORK_IPv6_ADDR.format(number),
            MIGRATION_NETWORK_IPv6_MASK)

        host_service = engine.hosts_service().host_service(id=host.id)
        network_utils_v4.attach_network_to_host(host_service, BOND_NAME,
                                                MIGRATION_NETWORK,
                                                ip_configuration, [bond])

    hosts = test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME)
    utils.invoke_in_parallel(_bond_nics, list(range(1, len(hosts) + 1)), hosts)

    for host in test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME):
        host_service = engine.hosts_service().host_service(id=host.id)
        assert _host_is_attached_to_network(engine,
                                            host_service,
                                            MIGRATION_NETWORK,
                                            nic_name=BOND_NAME)
def test_assign_hosts_network_label(
        system_service, hosts_service, ost_cluster_name):
    """
    Assigns NETWORK_LABEL to first network interface of every host in cluster
    """
    def _assign_host_network_label(host):
        host_service = hosts_service.host_service(id=host.id)
        nics_service = host_service.nics_service()
        nics = sorted(nics_service.list(), key=lambda n: n.name)
        assert len(nics) >= 1
        nic = nics[0]
        nic_service = nics_service.nic_service(id=nic.id)
        labels_service = nic_service.network_labels_service()
        return labels_service.add(NetworkLabel(id=NETWORK_LABEL, host_nic=nic))

    hosts = test_utils.hosts_in_cluster_v4(system_service, ost_cluster_name)
    vec = utils.func_vector(_assign_host_network_label, [(h,) for h in hosts])
    vt = utils.VectorThread(vec)
    vt.start_all()
    assert all(vt.join_all())
Beispiel #17
0
def prepare_migration_attachments_ipv6(system_service):
    hosts_service = system_service.hosts_service()

    for index, host in enumerate(test_utils.hosts_in_cluster_v4(
            system_service, CLUSTER_NAME),
                                 start=1):
        host_service = hosts_service.host_service(id=host.id)

        ip_address = MIGRATION_NETWORK_IPv6_ADDR.format(index)

        ip_configuration = network_utils_v4.create_static_ip_configuration(
            ipv6_addr=ip_address, ipv6_mask=MIGRATION_NETWORK_IPv6_MASK)

        network_utils_v4.modify_ip_config(system_service, host_service,
                                          MIGRATION_NETWORK, ip_configuration)

        actual_address = next(nic
                              for nic in host_service.nics_service().list()
                              if nic.name == VLAN200_IF_NAME).ipv6.address
        assert IPAddress(actual_address) == IPAddress(ip_address)
def test_assign_labeled_network(system_service, networks_service,
                                hosts_service, ost_dc_name, ost_cluster_name):
    """
    Adds the labeled network to the cluster and asserts the hosts are attached
    """
    labeled_net = networks_service.list(search=f'name={LABELED_NET_NAME}')[0]

    # the logical network will be automatically assigned to all host network
    # interfaces with that label asynchronously

    cluster_service = test_utils.get_cluster_service(
        system_service, ost_cluster_name)
    assert cluster_service.networks_service().add(labeled_net)

    for host in test_utils.hosts_in_cluster_v4(system_service,
                                               ost_cluster_name):
        host_service = hosts_service.host_service(id=host.id)
        assertions.assert_true_within_short(
            functools.partial(_host_is_attached_to_network, system_service,
                              host_service, LABELED_NET_NAME, ost_dc_name))
def prepare_migration_attachments_ipv4(api):
    engine = api.system_service()
    hosts_service = engine.hosts_service()

    for index, host in enumerate(
            test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME),
            start=1):
        host_service = hosts_service.host_service(id=host.id)

        ip_address = MIGRATION_NETWORK_IPv4_ADDR.format(index)

        ip_configuration = network_utils_v4.create_static_ip_configuration(
            ipv4_addr=ip_address,
            ipv4_mask=MIGRATION_NETWORK_IPv4_MASK)

        network_utils_v4.attach_network_to_host(
            host_service, NIC_NAME, MIGRATION_NETWORK, ip_configuration)

        actual_address = next(nic for nic in host_service.nics_service().list()
                              if nic.name == VLAN200_IF_NAME).ip.address
        nt.assert_equals(IPAddress(actual_address), IPAddress(ip_address))
def prepare_migration_attachments_ipv4(api):
    engine = api.system_service()
    hosts_service = engine.hosts_service()

    for index, host in enumerate(
            test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME),
            start=1):
        host_service = hosts_service.host_service(id=host.id)

        ip_address = MIGRATION_NETWORK_IPv4_ADDR.format(index)

        ip_configuration = network_utils_v4.create_static_ip_configuration(
            ipv4_addr=ip_address,
            ipv4_mask=MIGRATION_NETWORK_IPv4_MASK)

        network_utils_v4.attach_network_to_host(
            host_service, NIC_NAME, MIGRATION_NETWORK, ip_configuration)

        actual_address = next(nic for nic in host_service.nics_service().list()
                              if nic.name == VLAN200_IF_NAME).ip.address
        nt.assert_equals(IPAddress(actual_address), IPAddress(ip_address))
Beispiel #21
0
def assign_labeled_network(api):
    """
    Adds the labeled network to the cluster and asserts the hosts are attached
    """
    engine = api.system_service()

    labeled_net = engine.networks_service().list(
        search='name={}'.format(LABELED_NET_NAME))[0]

    # the logical network will be automatically assigned to all host network
    # interfaces with that label asynchronously

    cluster_service = test_utils.get_cluster_service(engine, CLUSTER_NAME)
    nt.assert_true(cluster_service.networks_service().add(labeled_net))

    hosts_service = engine.hosts_service()
    for host in test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME):
        host_service = hosts_service.host_service(id=host.id)
        testlib.assert_true_within_short(
            functools.partial(_host_is_attached_to_network, engine,
                              host_service, LABELED_NET_NAME))
def prepare_migration_attachments_ipv6(api):
    raise SkipTest('Test is failing from time to time, skipping.')
    engine = api.system_service()
    hosts_service = engine.hosts_service()

    for index, host in enumerate(
            test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME),
            start=1):
        host_service = hosts_service.host_service(id=host.id)

        ip_address = MIGRATION_NETWORK_IPv6_ADDR.format(index)

        ip_configuration = network_utils_v4.create_static_ip_configuration(
            ipv6_addr=ip_address,
            ipv6_mask=MIGRATION_NETWORK_IPv6_MASK)

        network_utils_v4.modify_ip_config(
            engine, host_service, MIGRATION_NETWORK, ip_configuration)

        actual_address = next(nic for nic in host_service.nics_service().list()
                              if nic.name == VLAN200_IF_NAME).ipv6.address
        nt.assert_equals(IPAddress(actual_address), IPAddress(ip_address))
Beispiel #23
0
def prepare_migration_attachments_ipv6(api):
    raise SkipTest('Test is failing from time to time, skipping.')
    engine = api.system_service()
    hosts_service = engine.hosts_service()

    for index, host in enumerate(test_utils.hosts_in_cluster_v4(
            engine, CLUSTER_NAME),
                                 start=1):
        host_service = hosts_service.host_service(id=host.id)

        ip_address = MIGRATION_NETWORK_IPv6_ADDR.format(index)

        ip_configuration = network_utils_v4.create_static_ip_configuration(
            ipv6_addr=ip_address, ipv6_mask=MIGRATION_NETWORK_IPv6_MASK)

        network_utils_v4.modify_ip_config(engine, host_service,
                                          MIGRATION_NETWORK, ip_configuration)

        actual_address = next(nic
                              for nic in host_service.nics_service().list()
                              if nic.name == VLAN200_IF_NAME).ipv6.address
        nt.assert_equals(IPAddress(actual_address), IPAddress(ip_address))
def assign_labeled_network(api):
    """
    Adds the labeled network to the cluster and asserts the hosts are attached
    """
    engine = api.system_service()

    labeled_net = engine.networks_service().list(
        search='name={}'.format(LABELED_NET_NAME))[0]

    # the logical network will be automatically assigned to all host network
    # interfaces with that label asynchronously

    cluster_service = test_utils.get_cluster_service(engine, CLUSTER_NAME)
    nt.assert_true(
        cluster_service.networks_service().add(labeled_net)
    )

    hosts_service = engine.hosts_service()
    for host in test_utils.hosts_in_cluster_v4(engine, CLUSTER_NAME):
        host_service = hosts_service.host_service(id=host.id)
        testlib.assert_true_within_short(
            functools.partial(_host_is_attached_to_network, engine,
                              host_service, LABELED_NET_NAME))