def bond_nics(prefix, api): def _bond_nics(number, host): slaves = params.Slaves(host_nic=[ params.HostNIC(name=nic) for nic in _nics_to_bond(prefix, host.name) ]) options = params.Options(option=[ params.Option(name='mode', value='active-backup'), params.Option(name='miimon', value='200'), ]) bond = params.HostNIC(name=BOND_NAME, bonding=params.Bonding(slaves=slaves, options=options)) ip_configuration = network_utils.create_static_ip_configuration( VLAN200_NET_IPv4_ADDR % number, VLAN200_NET_IPv4_MASK, VLAN200_NET_IPv6_ADDR % number, VLAN200_NET_IPv6_MASK) network_utils.attach_network_to_host(api, host, BOND_NAME, VLAN200_NET, ip_configuration, [bond]) hosts = test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME) utils.invoke_in_parallel(_bond_nics, range(1, len(hosts) + 1), hosts) for host in test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME): nt.assert_true( _host_is_attached_to_network(api, host, VLAN200_NET, nic_name=BOND_NAME))
def bond_nics(prefix, api): def _bond_nics(number, host): slaves = params.Slaves(host_nic=[ params.HostNIC(name=nic) for nic in _host_vm_nics( prefix, host.name, LIBVIRT_NETWORK_FOR_BONDING)]) # eth2, eth3 options = params.Options(option=[ params.Option(name='mode', value='active-backup'), params.Option(name='miimon', value='200'), ]) bond = params.HostNIC( name=BOND_NAME, bonding=params.Bonding(slaves=slaves, options=options)) ip_configuration = network_utils_v3.create_static_ip_configuration( MIGRATION_NETWORK_IPv4_ADDR.format(number), MIGRATION_NETWORK_IPv4_MASK, MIGRATION_NETWORK_IPv6_ADDR.format(number), MIGRATION_NETWORK_IPv6_MASK) network_utils_v3.attach_network_to_host( api, host, BOND_NAME, MIGRATION_NETWORK, ip_configuration, [bond]) hosts = test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME) utils.invoke_in_parallel(_bond_nics, range(1, len(hosts) + 1), hosts) for host in test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME): nt.assert_true(_host_is_attached_to_network( api, host, MIGRATION_NETWORK, nic_name=BOND_NAME))
def remove_bonding(api): def _remove_bonding(host): network_utils.detach_network_from_host(api, host, VLAN200_NET, BOND_NAME) network_utils.set_network_required_in_cluster(api, VLAN200_NET, CLUSTER_NAME, False) utils.invoke_in_parallel(_remove_bonding, test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME)) for host in test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME): nt.assert_false(_host_is_attached_to_network(api, host, VLAN200_NET))
def remove_bonding(api): def _remove_bonding(host): network_utils_v3.detach_network_from_host(api, host, MIGRATION_NETWORK, BOND_NAME) network_utils_v3.set_network_required_in_cluster(api, MIGRATION_NETWORK, CLUSTER_NAME, False) utils.invoke_in_parallel(_remove_bonding, test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME)) for host in test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME): nt.assert_false(_host_is_attached_to_network(api, host, MIGRATION_NETWORK))
def detach_vm_network_from_host(api): host = test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME)[0] network_utils_v3.set_network_required_in_cluster( api, VM_NETWORK, CLUSTER_NAME, False) network_utils_v3.detach_network_from_host(api, host, VM_NETWORK) nt.assert_false(_host_is_attached_to_network(api, host, VM_NETWORK))
def detach_vm_network_from_host(api): host = test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME)[0] network_utils.set_network_required_in_cluster(api, VM_NETWORK, CLUSTER_NAME, False) network_utils.detach_network_from_host(api, host, VM_NETWORK) nt.assert_false(_host_is_attached_to_network(api, host, VM_NETWORK))
def attach_vlan_to_host_static_config(api): host = test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME)[0] ip_configuration = _create_static_ip_configuration() _attach_vlan_to_host(api, host, ip_configuration) # TODO: currently ost uses v3 SDK that doesn't report ipv6. once available, # verify ipv6 as well. nt.assert_equals( host.nics.list(name='eth0.100')[0].ip.address, VLAN100_NET_IPv4_ADDR)
def attach_vm_network_to_host_static_config(api): host = test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME)[0] ip_configuration = network_utils.create_static_ip_configuration( VM_NETWORK_IPv4_ADDR, VM_NETWORK_IPv4_MASK, VM_NETWORK_IPv6_ADDR, VM_NETWORK_IPv6_MASK) network_utils.attach_network_to_host(api, host, NIC_NAME, VM_NETWORK, ip_configuration) # TODO: currently ost uses v3 SDK that doesn't report ipv6. once available, # verify ipv6 as well. nt.assert_equals( host.nics.list(name=VLAN_IF_NAME)[0].ip.address, VM_NETWORK_IPv4_ADDR)
def prepare_migration_attachments_ipv4(api): for index, host in enumerate(test_utils.hosts_in_cluster_v3( api, CLUSTER_NAME), start=1): ip_address = VLAN200_NET_IPv4_ADDR.format(index) ip_configuration = network_utils.create_static_ip_configuration( ipv4_addr=ip_address, ipv4_mask=VLAN200_NET_IPv4_MASK) network_utils.attach_network_to_host(api, host, NIC_NAME, VLAN200_NET, ip_configuration) nt.assert_equals( host.nics.list(name=VLAN200_IF_NAME)[0].ip.address, ip_address)
def assign_hosts_network_label(api): """ Assigns NETWORK_LABEL to first network interface of every host in cluster """ def _assign_host_network_label(host): nics = sorted(host.nics.list(), key=lambda n: n.get_name()) nt.assert_greater_equal(len(nics), 1) nic = nics[0] return nic.labels.add(params.Label(id=NETWORK_LABEL, host_nic=nic)) hosts = test_utils.hosts_in_cluster_v3(api, 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 prepare_migration_attachments_ipv4(api): for index, host in enumerate( test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME), start=1): ip_address = MIGRATION_NETWORK_IPv4_ADDR.format(index) ip_configuration = network_utils_v3.create_static_ip_configuration( ipv4_addr=ip_address, ipv4_mask=MIGRATION_NETWORK_IPv4_MASK) network_utils_v3.attach_network_to_host( api, host, NIC_NAME, MIGRATION_NETWORK, ip_configuration) nt.assert_equals( host.nics.list(name=VLAN200_IF_NAME)[0].ip.address, ip_address)
def assign_labeled_network(api): """ Adds the labeled network to the cluster and asserts the hosts are attached """ labeled_net = api.networks.get(name=LABELED_NET_NAME) def _host_is_in_labeled_network(): for networkattachment in host.networkattachments.list(): network = api.networks.get(id=networkattachment.network.get_id()) if network.name == LABELED_NET_NAME: return True return False # the logical network will be automatically assigned to all host network # interfaces with that label asynchronously nt.assert_true(api.clusters.get(CLUSTER_NAME).networks.add(labeled_net)) for host in test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME): testlib.assert_true_within_short(_host_is_in_labeled_network)
def attach_vm_network_to_host_static_config(api): host = test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME)[0] ip_configuration = network_utils_v3.create_static_ip_configuration( VM_NETWORK_IPv4_ADDR, VM_NETWORK_IPv4_MASK, VM_NETWORK_IPv6_ADDR, VM_NETWORK_IPv6_MASK) network_utils_v3.attach_network_to_host( api, host, NIC_NAME, VM_NETWORK, ip_configuration) # TODO: currently ost uses v3 SDK that doesn't report ipv6. once available, # verify ipv6 as well. nt.assert_equals( host.nics.list(name=VLAN_IF_NAME)[0].ip.address, VM_NETWORK_IPv4_ADDR)
def assign_hosts_network_label(api): """ Assigns NETWORK_LABEL to first network interface of every host in cluster """ def _assign_host_network_label(host): nics = sorted(host.nics.list(), key=lambda n: n.get_name()) nt.assert_greater_equal(len(nics), 1) nic = nics[0] return nic.labels.add( params.Label( id=NETWORK_LABEL, host_nic=nic ) ) hosts = test_utils.hosts_in_cluster_v3(api, 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 assign_labeled_network(api): """ Adds the labeled network to the cluster and asserts the hosts are attached """ labeled_net = api.networks.get(name=LABELED_NET_NAME) def _host_is_in_labeled_network(): for networkattachment in host.networkattachments.list(): network = api.networks.get(id=networkattachment.network.get_id()) if network.name == LABELED_NET_NAME: return True return False # the logical network will be automatically assigned to all host network # interfaces with that label asynchronously nt.assert_true( api.clusters.get(CLUSTER_NAME).networks.add(labeled_net) ) for host in test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME): testlib.assert_true_within_short(_host_is_in_labeled_network)
def detach_vlan_from_host(api): network_id = api.networks.get(name=VLAN100_NET).id host = test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME)[0] def _detach_vlan_from_host(): attachment = _get_networkattachment_by_network_id(host, network_id) removal_action = params.Action( removed_network_attachments=params.NetworkAttachments( network_attachment=[params.NetworkAttachment( id=attachment.id)])) host.setupnetworks(removal_action) def _host_is_detached_from_vlan_network(): with nt.assert_raises(IndexError): _get_networkattachment_by_network_id(host, network_id) return True _set_network_required_in_cluster(api, VLAN100_NET, CLUSTER_NAME, False) _detach_vlan_from_host() nt.assert_true(_host_is_detached_from_vlan_network())
def modify_host_ip_to_dhcp(api): host = test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME)[0] ip_configuration = network_utils_v3.create_dhcp_ip_configuration() network_utils_v3.modify_ip_config(api, host, VM_NETWORK, ip_configuration)
def modify_host_ip_to_dhcp(api): host = test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME)[0] ip_configuration = _create_dhcp_ip_configuration() _modify_ip_config(api, host, ip_configuration)
def modify_host_ip_to_dhcp(api): host = test_utils.hosts_in_cluster_v3(api, CLUSTER_NAME)[0] ip_configuration = network_utils.create_dhcp_ip_configuration() network_utils.modify_ip_config(api, host, VM_NETWORK, ip_configuration)