initial changes to try and cleanup shell commands used within core

This commit is contained in:
Blake J. Harnden 2018-02-27 10:48:01 -08:00
parent 49a2f77f45
commit 6b8ee13f5d
22 changed files with 185 additions and 291 deletions

View file

@ -186,18 +186,18 @@ class Core(object):
def ping(self, from_name, to_name):
from_node = self.nodes[from_name]
to_ip = str(self.get_ip(to_name))
return from_node.cmd(["ping", "-c", "3", to_ip])
return from_node.client.cmd(["ping", "-c", "3", to_ip])
def ping_output(self, from_name, to_name):
from_node = self.nodes[from_name]
to_ip = str(self.get_ip(to_name))
vcmd, stdin, stdout, stderr = from_node.popen(["ping", "-i", "0.05", "-c", "3", to_ip])
vcmd, stdin, stdout, stderr = from_node.client.popen(["ping", "-i", "0.05", "-c", "3", to_ip])
return stdout.read().strip()
def iping(self, from_name, to_name):
from_node = self.nodes[from_name]
to_ip = str(self.get_ip(to_name))
from_node.icmd(["ping", "-i", "0.01", "-c", "10", to_ip])
from_node.client.icmd(["ping", "-i", "0.01", "-c", "10", to_ip])
def iperf(self, from_name, to_name):
from_node = self.nodes[from_name]
@ -205,9 +205,9 @@ class Core(object):
to_ip = str(self.get_ip(to_name))
# run iperf server, run client, kill iperf server
vcmd, stdin, stdout, stderr = to_node.popen(["iperf", "-s", "-u", "-y", "C"])
from_node.cmd(["iperf", "-u", "-t", "5", "-c", to_ip])
to_node.cmd(["killall", "-9", "iperf"])
vcmd, stdin, stdout, stderr = to_node.client.popen(["iperf", "-s", "-u", "-y", "C"])
from_node.client.cmd(["iperf", "-u", "-t", "5", "-c", to_ip])
to_node.client.cmd(["killall", "-9", "iperf"])
return stdout.read().strip()

View file

@ -3,13 +3,12 @@ Unit tests for testing basic CORE networks.
"""
import os
import stat
import threading
import time
import pytest
from xml.etree import ElementTree
import pytest
from mock import MagicMock
from conftest import EMANE_SERVICES
@ -18,6 +17,7 @@ from core.enumerations import MessageFlags
from core.mobility import BasicRangeModel
from core.netns import nodes
from core.netns import vnodeclient
from core.netns.vnodeclient import VnodeClient
from core.phys.pnodes import PhysicalNode
from core.service import ServiceManager
from core.xml import xmlsession
@ -29,6 +29,24 @@ _XML_VERSIONS = ["0.0", "1.0"]
_NODE_CLASSES = [nodes.PtpNet, nodes.HubNode, nodes.SwitchNode]
def createclients(sessiondir, clientcls=VnodeClient, cmdchnlfilterfunc=None):
"""
Create clients
:param str sessiondir: session directory to create clients
:param class clientcls: class to create clients from
:param func cmdchnlfilterfunc: command channel filter function
:return: list of created clients
:rtype: list
"""
direntries = map(lambda x: os.path.join(sessiondir, x), os.listdir(sessiondir))
cmdchnls = filter(lambda x: stat.S_ISSOCK(os.stat(x).st_mode), direntries)
if cmdchnlfilterfunc:
cmdchnls = filter(cmdchnlfilterfunc, cmdchnls)
cmdchnls.sort()
return map(lambda x: clientcls(os.path.basename(x), x), cmdchnls)
class TestCore:
def test_import_service(self, core):
"""
@ -145,7 +163,7 @@ class TestCore:
# get node client for testing
n1 = core.get_node("n1")
client = n1.vnodeclient
client = n1.client
# instantiate session
core.session.instantiate()
@ -178,7 +196,7 @@ class TestCore:
assert not client.shcmd(command[0])
# check module methods
assert vnodeclient.createclients(core.session.session_dir)
assert createclients(core.session.session_dir)
# check convenience methods for interface information
assert client.getaddr("eth0")