platform/tests: use nm_platform_link_veth_add() to create veth pair in test

This commit is contained in:
Thomas Haller
2017-05-26 20:05:08 +02:00
parent 6ab2288c28
commit d3c71ce4da
4 changed files with 38 additions and 6 deletions

View File

@@ -40,9 +40,8 @@ static void
fixture_setup (test_fixture *fixture, gconstpointer user_data)
{
/* create veth pair. */
nmtstp_run_command_check ("ip link add dev %s type veth peer name %s", IFACE_VETH0, IFACE_VETH1);
fixture->ifindex0 = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, IFACE_VETH0, NM_LINK_TYPE_VETH, 100)->ifindex;
fixture->ifindex1 = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, IFACE_VETH1, NM_LINK_TYPE_VETH, 100)->ifindex;
fixture->ifindex0 = nmtstp_link_veth_add (NM_PLATFORM_GET, -1, IFACE_VETH0, IFACE_VETH1)->ifindex;
fixture->ifindex1 = nmtstp_link_get_typed (NM_PLATFORM_GET, -1, IFACE_VETH1, NM_LINK_TYPE_VETH)->ifindex;
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, fixture->ifindex0, NULL));
g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, fixture->ifindex1, NULL));

View File

@@ -976,6 +976,36 @@ nmtstp_ip6_address_del (NMPlatform *platform,
} \
} G_STMT_END
const NMPlatformLink *
nmtstp_link_veth_add (NMPlatform *platform,
gboolean external_command,
const char *name,
const char *peer)
{
const NMPlatformLink *pllink = NULL;
gboolean success;
g_assert (nm_utils_is_valid_iface_name (name, NULL));
external_command = nmtstp_run_command_check_external (external_command);
_init_platform (&platform, external_command);
if (external_command) {
success = !nmtstp_run_command ("ip link add dev %s type veth peer name %s",
name, peer);
if (success) {
pllink = nmtstp_assert_wait_for_link (platform, name, NM_LINK_TYPE_VETH, 100);
nmtstp_assert_wait_for_link (platform, peer, NM_LINK_TYPE_VETH, 10);
}
} else
success = nm_platform_link_veth_add (platform, name, peer, &pllink) == NM_PLATFORM_ERROR_SUCCESS;
g_assert (success);
_assert_pllink (platform, success, pllink, name, NM_LINK_TYPE_VETH);
return pllink;
}
const NMPlatformLink *
nmtstp_link_dummy_add (NMPlatform *platform,
gboolean external_command,

View File

@@ -197,6 +197,10 @@ void nmtstp_link_set_updown (NMPlatform *platform,
int ifindex,
gboolean up);
const NMPlatformLink *nmtstp_link_veth_add (NMPlatform *platform,
gboolean external_command,
const char *name,
const char *peer);
const NMPlatformLink *nmtstp_link_dummy_add (NMPlatform *platform,
gboolean external_command,
const char *name);

View File

@@ -1713,9 +1713,8 @@ test_nl_bugs_veth (void)
NMTstpNamespaceHandle *ns_handle = NULL;
/* create veth pair. */
nmtstp_run_command_check ("ip link add dev %s type veth peer name %s", IFACE_VETH0, IFACE_VETH1);
ifindex_veth0 = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, IFACE_VETH0, NM_LINK_TYPE_VETH, 100)->ifindex;
ifindex_veth1 = nmtstp_assert_wait_for_link (NM_PLATFORM_GET, IFACE_VETH1, NM_LINK_TYPE_VETH, 100)->ifindex;
ifindex_veth0 = nmtstp_link_veth_add (NM_PLATFORM_GET, -1, IFACE_VETH0, IFACE_VETH1)->ifindex;
ifindex_veth1 = nmtstp_link_get_typed (NM_PLATFORM_GET, -1, IFACE_VETH1, NM_LINK_TYPE_VETH)->ifindex;
/* assert that nm_platform_link_veth_get_properties() returns the expected peer ifindexes. */
g_assert (nm_platform_link_veth_get_properties (NM_PLATFORM_GET, ifindex_veth0, &i));