From 6a875bcd8d3c3a571a1ec314250b6850d8a5acb6 Mon Sep 17 00:00:00 2001 From: "Blake J. Harnden" Date: Thu, 27 Jul 2017 11:57:01 -0700 Subject: [PATCH] added vnodeclient testing, added a run tests script to make testing easier --- daemon/core/netns/vnodeclient.py | 3 +- daemon/test.py | 2 +- daemon/tests/test_core.py | 62 +++++++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/daemon/core/netns/vnodeclient.py b/daemon/core/netns/vnodeclient.py index 114415e9..e597a009 100644 --- a/daemon/core/netns/vnodeclient.py +++ b/daemon/core/netns/vnodeclient.py @@ -7,6 +7,7 @@ by invoking the vcmd shell command. import os import stat +import subprocess from core import constants from core.misc import log @@ -17,8 +18,6 @@ USE_VCMD_MODULE = True if USE_VCMD_MODULE: import vcmd -else: - import subprocess VCMD = os.path.join(constants.CORE_SBIN_DIR, "vcmd") diff --git a/daemon/test.py b/daemon/test.py index 9274613a..8981473a 100644 --- a/daemon/test.py +++ b/daemon/test.py @@ -5,5 +5,5 @@ pytest.main([ "--cov-report", "xml", "--cov=.", - "tests/test_core.py" + "tests" ]) diff --git a/daemon/tests/test_core.py b/daemon/tests/test_core.py index ab1d721e..07166ed3 100644 --- a/daemon/tests/test_core.py +++ b/daemon/tests/test_core.py @@ -10,11 +10,71 @@ from conftest import EMANE_SERVICES from core.enumerations import MessageFlags from core.mobility import BasicRangeModel from core.netns import nodes +from core.netns import vnodeclient from core.phys.pnodes import PhysicalNode class TestCore: + def test_vnode_client(self, core): + """ + Test vnode client methods. + + :param conftest.Core core: core fixture to test with + """ + + # create ptp + ptp_node = core.session.add_object(cls=nodes.PtpNet) + + # create nodes + core.create_node("n1") + core.create_node("n2") + + # add interfaces + core.add_interface(ptp_node, "n1") + core.add_interface(ptp_node, "n2") + + # get node client for testing + n1 = core.get_node("n1") + client = n1.vnodeclient + + # instantiate session + core.session.instantiate() + + # assert node directories created + core.assert_nodes() + + # check we are connected + assert client.connected() + + # check various command using vcmd module + command = ["ls"] + assert not client.cmd(command) + status, output = client.cmdresult(command) + assert not status + p, stdin, stdout, stderr = client.popen(command) + assert not p.status() + assert not client.icmd(command) + assert not client.redircmd(MagicMock(), MagicMock(), MagicMock(), command) + assert not client.shcmd(command[0]) + + # check various command using command line + vnodeclient.USE_VCMD_MODULE = False + assert not client.cmd(command) + status, output = client.cmdresult(command) + assert not status + p, stdin, stdout, stderr = client.popen(command) + assert not p.wait() + assert not client.icmd(command) + assert not client.shcmd(command[0]) + + # check module methods + assert vnodeclient.createclients(core.session.session_dir) + + # check convenience methods for interface information + assert client.getaddr("eth0") + assert client.netifstats() + def test_netif(self, core): """ Test netif methods. @@ -326,7 +386,7 @@ class TestCore: rtt_line = stdout.split("\n")[-1] rtt_values = rtt_line.split("=")[1].split("ms")[0].strip() rtt_avg = float(rtt_values.split("/")[2]) - assert 0 <= rtt_avg <= 0.1 + assert 0 <= rtt_avg <= 0.2 # change delay in microseconds delay = 1000000