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 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 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))
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 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)