summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-05-26 20:05:08 +0200
committerThomas Haller <thaller@redhat.com>2017-05-26 20:20:37 +0200
commitb60b885395cf1f1ac1776f7361b2d8d7fcaa26a3 (patch)
tree34cd727f6ee7812a1967e843ea85471bdf47298c
parent87da20d6847aae262ad1784fe9f79295f62193e9 (diff)
downloadNetworkManager-th/platform-tests.tar.gz
platform/tests: use nm_platform_link_veth_add() to create veth pair in testth/platform-tests
-rw-r--r--src/devices/tests/test-arping.c5
-rw-r--r--src/platform/tests/test-common.c30
-rw-r--r--src/platform/tests/test-common.h4
-rw-r--r--src/platform/tests/test-link.c5
4 files changed, 38 insertions, 6 deletions
diff --git a/src/devices/tests/test-arping.c b/src/devices/tests/test-arping.c
index 59223f11fd..6e29777619 100644
--- a/src/devices/tests/test-arping.c
+++ b/src/devices/tests/test-arping.c
@@ -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));
diff --git a/src/platform/tests/test-common.c b/src/platform/tests/test-common.c
index 661a4360ec..bf4786bdb3 100644
--- a/src/platform/tests/test-common.c
+++ b/src/platform/tests/test-common.c
@@ -977,6 +977,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,
const char *name)
diff --git a/src/platform/tests/test-common.h b/src/platform/tests/test-common.h
index b05e4b161a..373a1fe0da 100644
--- a/src/platform/tests/test-common.h
+++ b/src/platform/tests/test-common.h
@@ -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);
diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c
index ed435567f0..df204b4683 100644
--- a/src/platform/tests/test-link.c
+++ b/src/platform/tests/test-link.c
@@ -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));