added vnodeclient testing, added a run tests script to make testing easier
This commit is contained in:
parent
ebe3b9e3e3
commit
6a875bcd8d
3 changed files with 63 additions and 4 deletions
|
@ -7,6 +7,7 @@ by invoking the vcmd shell command.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from core import constants
|
from core import constants
|
||||||
from core.misc import log
|
from core.misc import log
|
||||||
|
@ -17,8 +18,6 @@ USE_VCMD_MODULE = True
|
||||||
|
|
||||||
if USE_VCMD_MODULE:
|
if USE_VCMD_MODULE:
|
||||||
import vcmd
|
import vcmd
|
||||||
else:
|
|
||||||
import subprocess
|
|
||||||
|
|
||||||
VCMD = os.path.join(constants.CORE_SBIN_DIR, "vcmd")
|
VCMD = os.path.join(constants.CORE_SBIN_DIR, "vcmd")
|
||||||
|
|
||||||
|
|
|
@ -5,5 +5,5 @@ pytest.main([
|
||||||
"--cov-report",
|
"--cov-report",
|
||||||
"xml",
|
"xml",
|
||||||
"--cov=.",
|
"--cov=.",
|
||||||
"tests/test_core.py"
|
"tests"
|
||||||
])
|
])
|
||||||
|
|
|
@ -10,11 +10,71 @@ from conftest import EMANE_SERVICES
|
||||||
from core.enumerations import MessageFlags
|
from core.enumerations import MessageFlags
|
||||||
from core.mobility import BasicRangeModel
|
from core.mobility import BasicRangeModel
|
||||||
from core.netns import nodes
|
from core.netns import nodes
|
||||||
|
from core.netns import vnodeclient
|
||||||
from core.phys.pnodes import PhysicalNode
|
from core.phys.pnodes import PhysicalNode
|
||||||
|
|
||||||
|
|
||||||
class TestCore:
|
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):
|
def test_netif(self, core):
|
||||||
"""
|
"""
|
||||||
Test netif methods.
|
Test netif methods.
|
||||||
|
@ -326,7 +386,7 @@ class TestCore:
|
||||||
rtt_line = stdout.split("\n")[-1]
|
rtt_line = stdout.split("\n")[-1]
|
||||||
rtt_values = rtt_line.split("=")[1].split("ms")[0].strip()
|
rtt_values = rtt_line.split("=")[1].split("ms")[0].strip()
|
||||||
rtt_avg = float(rtt_values.split("/")[2])
|
rtt_avg = float(rtt_values.split("/")[2])
|
||||||
assert 0 <= rtt_avg <= 0.1
|
assert 0 <= rtt_avg <= 0.2
|
||||||
|
|
||||||
# change delay in microseconds
|
# change delay in microseconds
|
||||||
delay = 1000000
|
delay = 1000000
|
||||||
|
|
Loading…
Reference in a new issue