本文整理汇总了Python中nepi.execution.ec.ExperimentController.get_resource方法的典型用法代码示例。如果您正苦于以下问题:Python ExperimentController.get_resource方法的具体用法?Python ExperimentController.get_resource怎么用?Python ExperimentController.get_resource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nepi.execution.ec.ExperimentController
的用法示例。
在下文中一共展示了ExperimentController.get_resource方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_stop_with_condition
# 需要导入模块: from nepi.execution.ec import ExperimentController [as 别名]
# 或者: from nepi.execution.ec.ExperimentController import get_resource [as 别名]
def test_stop_with_condition(self):
from nepi.execution.resource import ResourceFactory
ResourceFactory.register_type(Application)
ResourceFactory.register_type(Node)
ResourceFactory.register_type(Interface)
ec = ExperimentController()
node = ec.register_resource("Node")
app1 = ec.register_resource("Application")
ec.register_connection(app1, node)
app2 = ec.register_resource("Application")
ec.register_connection(app2, node)
ec.register_condition(app2, ResourceAction.START, app1,
ResourceState.STOPPED)
ec.deploy()
ec.wait_finished([app1, app2])
rmapp1 = ec.get_resource(app1)
rmapp2 = ec.get_resource(app2)
self.assertTrue(rmapp2.start_time > rmapp1.stop_time)
ec.shutdown()
示例2: t_real_time
# 需要导入模块: from nepi.execution.ec import ExperimentController [as 别名]
# 或者: from nepi.execution.ec.ExperimentController import get_resource [as 别名]
def t_real_time(self, host, user = None, identity = None):
ec = ExperimentController(exp_id = "test-ns3-real-time")
node = ec.register_resource("linux::Node")
if host == "localhost":
ec.set(node, "hostname", "localhost")
else:
ec.set(node, "hostname", host)
ec.set(node, "username", user)
ec.set(node, "identity", identity)
ec.set(node, "cleanProcesses", True)
#ec.set(node, "cleanHome", True)
simu = ec.register_resource("linux::ns3::Simulation")
ec.set(simu, "simulatorImplementationType", "ns3::RealtimeSimulatorImpl")
ec.set(simu, "checksumEnabled", True)
ec.set(simu, "verbose", True)
ec.register_connection(simu, node)
nsnode1 = add_ns3_node(ec, simu)
dev1 = add_point2point_device(ec, nsnode1, "10.0.0.1", "30")
nsnode2 = add_ns3_node(ec, simu)
dev2 = add_point2point_device(ec, nsnode2, "10.0.0.2", "30")
# Create channel
chan = ec.register_resource("ns3::PointToPointChannel")
ec.set(chan, "Delay", "0s")
ec.register_connection(chan, dev1)
ec.register_connection(chan, dev2)
### create pinger
ping = ec.register_resource("ns3::V4Ping")
ec.set (ping, "Remote", "10.0.0.2")
ec.set (ping, "Interval", "1s")
ec.set (ping, "Verbose", True)
ec.set (ping, "StartTime", "0s")
ec.set (ping, "StopTime", "20s")
ec.register_connection(ping, nsnode1)
ec.deploy()
ec.wait_finished([ping])
stdout = ec.trace(simu, "stdout")
expected = "20 packets transmitted, 20 received, 0% packet loss"
self.assertTrue(stdout.find(expected) > -1)
rm = ec.get_resource(ping)
start_time = rm.start_time
stop_time = rm.stop_time
delta = stop_time - start_time
self.assertTrue(delta.seconds >= 20, "Time elapsed %d" % delta.seconds)
self.assertTrue(delta.seconds < 25, "Time elapsed %d" % delta.seconds)
ec.shutdown()
示例3: t_concurrency
# 需要导入模块: from nepi.execution.ec import ExperimentController [as 别名]
# 或者: from nepi.execution.ec.ExperimentController import get_resource [as 别名]
def t_concurrency(self, host, user):
ec = ExperimentController(exp_id="test-concurrency")
node = ec.register_resource("linux::Node")
ec.set(node, "hostname", host)
ec.set(node, "username", user)
ec.set(node, "cleanExperiment", True)
ec.set(node, "cleanProcesses", True)
apps = list()
for i in xrange(50):
app = ec.register_resource("linux::Application")
cmd = "ping -c5 %s" % self.target
ec.set(app, "command", cmd)
ec.register_connection(app, node)
apps.append(app)
ec.deploy()
ec.wait_finished(apps)
self.assertTrue(ec.state(node) == ResourceState.STARTED)
self.assertTrue(
all([ec.state(guid) == ResourceState.STOPPED \
for guid in apps])
)
for app in apps:
stdout = ec.trace(app, 'stdout')
size = ec.trace(app, 'stdout', attr = TraceAttr.SIZE)
self.assertEquals(len(stdout), size)
block = ec.trace(app, 'stdout', attr = TraceAttr.STREAM, block = 5, offset = 1)
self.assertEquals(block, stdout[5:10])
path = ec.trace(app, 'stdout', attr = TraceAttr.PATH)
rm = ec.get_resource(app)
p = os.path.join(rm.run_home, 'stdout')
self.assertEquals(path, p)
ec.shutdown()
示例4: OMFVLCWrongCaseWithNonCritical
# 需要导入模块: from nepi.execution.ec import ExperimentController [as 别名]
# 或者: from nepi.execution.ec.ExperimentController import get_resource [as 别名]
class OMFVLCWrongCaseWithNonCritical(unittest.TestCase):
id = 2000
def setUp(self):
self.ec = ExperimentController(exp_id = str(OMFVLCWrongCaseWithNonCritical.id))
OMFVLCWrongCaseWithNonCritical.id += 1
self.node1 = self.ec.register_resource("omf::Node")
self.ec.set(self.node1, 'hostname', 'omf.plexus.wlab17')
self.ec.set(self.node1, 'xmppUser', "nepi")
self.ec.set(self.node1, 'xmppServer', "xmpp-plexus.onelab.eu")
self.ec.set(self.node1, 'xmppPort', "5222")
self.ec.set(self.node1, 'xmppPassword', "1234")
self.ec.set(self.node1, 'version', "5")
self.iface1 = self.ec.register_resource("omf::WifiInterface")
self.ec.set(self.iface1, 'name', "wlan0")
self.ec.set(self.iface1, 'mode', "adhoc")
self.ec.set(self.iface1, 'hw_mode', "g")
self.ec.set(self.iface1, 'essid', "vlcexp")
self.ec.set(self.iface1, 'ip', "10.0.0.17/24")
self.ec.set(self.iface1, 'version', "5")
self.app1 = self.ec.register_resource("omf::Application")
self.ec.set(self.app1, 'appid', 'Kill#1')
self.ec.set(self.app1, 'command', "/usr/bin/test -1")
self.ec.set(self.app1, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
self.ec.set(self.app1, 'version', "5")
self.ec.register_connection(self.app1, self.node1)
self.ec.register_connection(self.node1, self.iface1)
def test_deploy_with_node_nc(self):
self.node2 = self.ec.register_resource("omf::Node")
self.ec.set(self.node2, "critical", False)
self.ec.set(self.node2, 'version', "5")
self.iface2 = self.ec.register_resource("omf::WifiInterface")
self.ec.set(self.iface2, 'name', "wlan0")
self.ec.set(self.iface2, 'mode', "adhoc")
self.ec.set(self.iface2, 'hw_mode', "g")
self.ec.set(self.iface2, 'essid', "vlcexp")
self.ec.set(self.iface2, 'ip', "10.0.0.37/24")
self.ec.set(self.iface2, 'version', "5")
self.channel = self.ec.register_resource("omf::Channel")
self.ec.set(self.channel, 'channel', "6")
self.ec.set(self.channel, 'xmppUser', "nepi")
self.ec.set(self.channel, 'xmppServer', "xmpp-plexus.onelab.eu")
self.ec.set(self.channel, 'xmppPort', "5222")
self.ec.set(self.channel, 'xmppPassword', "1234")
self.ec.set(self.channel, 'version', "5")
self.ec.register_connection(self.iface1, self.channel)
self.ec.register_connection(self.node2, self.iface2)
self.ec.register_connection(self.iface2, self.channel)
self.ec.register_condition([self.app1], ResourceAction.STOP, self.app1, ResourceState.STARTED , "5s")
self.ec.deploy()
self.ec.wait_finished([self.app1])
self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.FAILED)
self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.FAILED)
self.ec.shutdown()
self.assertEquals(self.ec.get_resource(self.node1).state, ResourceState.RELEASED)
self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.RELEASED)
self.assertEquals(self.ec.get_resource(self.iface1).state, ResourceState.RELEASED)
self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.RELEASED)
self.assertEquals(self.ec.get_resource(self.channel).state, ResourceState.RELEASED)
self.assertEquals(self.ec.get_resource(self.app1).state, ResourceState.RELEASED)
def test_deploy_with_node_and_iface_nc(self):
self.node2 = self.ec.register_resource("omf::Node")
self.ec.set(self.node2, "critical", False)
self.ec.set(self.node2, 'version', "5")
self.iface2 = self.ec.register_resource("omf::WifiInterface")
self.ec.set(self.node2, "critical", False)
self.ec.set(self.iface2, 'name', "wlan0")
self.ec.set(self.iface2, 'mode', "adhoc")
self.ec.set(self.iface2, 'hw_mode', "g")
self.ec.set(self.iface2, 'essid', "vlcexp")
self.ec.set(self.iface2, 'ip', "10.0.0.37/24")
self.ec.set(self.iface2, 'version', "5")
self.channel = self.ec.register_resource("omf::Channel")
self.ec.set(self.channel, 'channel', "6")
self.ec.set(self.channel, 'xmppUser', "nepi")
self.ec.set(self.channel, 'xmppServer', "xmpp-plexus.onelab.eu")
self.ec.set(self.channel, 'xmppPort', "5222")
self.ec.set(self.channel, 'xmppPassword', "1234")
self.ec.set(self.channel, 'version', "5")
self.ec.register_connection(self.iface1, self.channel)
self.ec.register_connection(self.node2, self.iface2)
#.........这里部分代码省略.........
示例5: compute_estimator
# 需要导入模块: from nepi.execution.ec import ExperimentController [as 别名]
# 或者: from nepi.execution.ec.ExperimentController import get_resource [as 别名]
n,m,std = compute_estimator(cpu_usage_start)
cpu_start = "%d,%0.2f,%0.2f" % (n,m,std)
n,m,std = compute_estimator(mem_usage_deploy)
mem_deploy = "%d,%0.2f,%0.2f" % (n,m,std)
n,m,std = compute_estimator(mem_usage_start)
mem_start = "%d,%0.2f,%0.2f" % (n,m,std)
rm_ttd_list = list()
rm_ttr_list = list()
rm_ttrel_list = list()
for guid in ec.resources:
rm = ec.get_resource(guid)
rm_d = rm.ready_time - zero_time
d = (rm_d.microseconds + ((rm_d.seconds + rm_d.days * 24 * 3600) * s2us)) / s2ms
rm_ttd_list.append(d)
try:
rm_r = rm.start_time - zero_time
r = (rm_r.microseconds + ((rm_r.seconds + rm_r.days * 24 * 3600) * s2us)) / s2ms
except:
r = 0
rm_ttr_list.append(r)
rm_rel = rm.release_time - zero_time
rel = (rm_rel.microseconds + ((rm_rel.seconds + rm_rel.days * 24 * 3600) * s2us)) / s2ms
rm_ttrel_list.append(rel)
示例6: OMFEachTestCase
# 需要导入模块: from nepi.execution.ec import ExperimentController [as 别名]
# 或者: from nepi.execution.ec.ExperimentController import get_resource [as 别名]
class OMFEachTestCase(unittest.TestCase):
def setUp(self):
self.ec = ExperimentController(exp_id = "99999")
self.node1 = self.ec.register_resource("omf::Node")
self.ec.set(self.node1, 'hostname', 'wlab12')
self.ec.set(self.node1, 'xmppUser', "nepi")
self.ec.set(self.node1, 'xmppServer', "xmpp-plexus.onelab.eu")
self.ec.set(self.node1, 'xmppPort', "5222")
self.ec.set(self.node1, 'xmppPassword', "1234")
self.iface1 = self.ec.register_resource("omf::WifiInterface")
self.ec.set(self.iface1, 'name', "wlan0")
self.ec.set(self.iface1, 'mode', "adhoc")
self.ec.set(self.iface1, 'hw_mode', "g")
self.ec.set(self.iface1, 'essid', "vlcexp")
self.ec.set(self.iface1, 'ip', "10.0.0.17/24")
self.channel = self.ec.register_resource("omf::Channel")
self.ec.set(self.channel, 'channel', "6")
self.ec.set(self.channel, 'xmppUser', "nepi")
self.ec.set(self.channel, 'xmppServer', "xmpp-plexus.onelab.eu")
self.ec.set(self.channel, 'xmppPort', "5222")
self.ec.set(self.channel, 'xmppPassword', "1234")
self.app1 = self.ec.register_resource("omf::Application")
self.ec.set(self.app1, 'appid', 'Vlc#1')
self.ec.set(self.app1, 'command', "/opt/vlc-1.1.13/cvlc /opt/10-by-p0d.avi --sout '#rtp{dst=10.0.0.37,port=1234,mux=ts}'")
self.ec.set(self.app1, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
self.app2 = self.ec.register_resource("omf::Application")
self.app3 = self.ec.register_resource("omf::Application")
self.app4 = self.ec.register_resource("omf::Application")
self.app5 = self.ec.register_resource("omf::Application")
self.ec.register_connection(self.app1, self.node1)
self.ec.register_connection(self.app2, self.node1)
self.ec.register_connection(self.app3, self.node1)
self.ec.register_connection(self.app4, self.node1)
self.ec.register_connection(self.app5, self.node1)
self.ec.register_connection(self.node1, self.iface1)
self.ec.register_connection(self.iface1, self.channel)
self.ec.register_condition(self.app2, ResourceAction.START, self.app1, ResourceState.STARTED , "3s")
self.ec.register_condition(self.app3, ResourceAction.START, self.app2, ResourceState.STARTED , "2s")
self.ec.register_condition(self.app4, ResourceAction.START, self.app3, ResourceState.STARTED , "3s")
self.ec.register_condition(self.app5, ResourceAction.START, [self.app3, self.app2], ResourceState.STARTED , "2s")
self.ec.register_condition(self.app5, ResourceAction.START, self.app1, ResourceState.STARTED , "25s")
self.ec.register_condition([self.app1, self.app2, self.app3,self.app4, self.app5], ResourceAction.STOP, self.app5, ResourceState.STARTED , "1s")
def tearDown(self):
self.ec.shutdown()
def test_creation_and_configuration_node(self):
self.assertEquals(self.ec.get(self.node1, 'hostname'), 'wlab12')
self.assertEquals(self.ec.get(self.node1, 'xmppUser'), 'nepi')
self.assertEquals(self.ec.get(self.node1, 'xmppServer'), 'xmpp-plexus.onelab.eu')
self.assertEquals(self.ec.get(self.node1, 'xmppPort'), '5222')
self.assertEquals(self.ec.get(self.node1, 'xmppPassword'), '1234')
self.assertEquals(self.ec.get(self.node1, 'version'), '6')
def test_creation_and_configuration_interface(self):
self.assertEquals(self.ec.get(self.iface1, 'name'), 'wlan0')
self.assertEquals(self.ec.get(self.iface1, 'mode'), 'adhoc')
self.assertEquals(self.ec.get(self.iface1, 'hw_mode'), 'g')
self.assertEquals(self.ec.get(self.iface1, 'essid'), 'vlcexp')
self.assertEquals(self.ec.get(self.iface1, 'ip'), '10.0.0.17/24')
self.assertEquals(self.ec.get(self.iface1, 'version'), '6')
def test_creation_and_configuration_channel(self):
self.assertEquals(self.ec.get(self.channel, 'channel'), '6')
self.assertEquals(self.ec.get(self.channel, 'xmppUser'), 'nepi')
self.assertEquals(self.ec.get(self.channel, 'xmppServer'), 'xmpp-plexus.onelab.eu')
self.assertEquals(self.ec.get(self.channel, 'xmppPort'), '5222')
self.assertEquals(self.ec.get(self.channel, 'xmppPassword'), '1234')
self.assertEquals(self.ec.get(self.channel, 'version'), '6')
def test_creation_and_configuration_application(self):
self.assertEquals(self.ec.get(self.app1, 'appid'), 'Vlc#1')
self.assertEquals(self.ec.get(self.app1, 'command'), "/opt/vlc-1.1.13/cvlc /opt/10-by-p0d.avi --sout '#rtp{dst=10.0.0.37,port=1234,mux=ts}'")
self.assertEquals(self.ec.get(self.app1, 'env'), 'DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority')
self.assertEquals(self.ec.get(self.app1, 'version'), '6')
def test_connection(self):
self.assertEquals(len(self.ec.get_resource(self.node1).connections), 6)
self.assertEquals(len(self.ec.get_resource(self.iface1).connections), 2)
self.assertEquals(len(self.ec.get_resource(self.channel).connections), 1)
self.assertEquals(len(self.ec.get_resource(self.app1).connections), 1)
self.assertEquals(len(self.ec.get_resource(self.app2).connections), 1)
def test_condition(self):
self.assertEquals(len(self.ec.get_resource(self.app1).conditions[ResourceAction.STOP]), 1)
self.assertEquals(len(self.ec.get_resource(self.app2).conditions[ResourceAction.START]), 1)
self.assertEquals(len(self.ec.get_resource(self.app3).conditions[ResourceAction.START]), 1)
#.........这里部分代码省略.........
示例7: test_deploy
# 需要导入模块: from nepi.execution.ec import ExperimentController [as 别名]
# 或者: from nepi.execution.ec.ExperimentController import get_resource [as 别名]
def test_deploy(self):
ec = ExperimentController(exp_id = "5421" )
self.node1 = ec.register_resource("omf::Node")
ec.set(self.node1, 'hostname', 'wlab12')
ec.set(self.node1, 'xmppUser', "nepi")
ec.set(self.node1, 'xmppServer', "xmpp-plexus.onelab.eu")
ec.set(self.node1, 'xmppPort', "5222")
ec.set(self.node1, 'xmppPassword', "1234")
self.iface1 = ec.register_resource("omf::WifiInterface")
ec.set(self.iface1, 'name', "wlan0")
ec.set(self.iface1, 'mode', "adhoc")
ec.set(self.iface1, 'hw_mode', "g")
ec.set(self.iface1, 'essid', "vlcexp")
ec.set(self.iface1, 'ip', "10.0.0.17/24")
self.channel = ec.register_resource("omf::Channel")
ec.set(self.channel, 'channel', "6")
ec.set(self.channel, 'xmppUser', "nepi")
ec.set(self.channel, 'xmppServer', "xmpp-plexus.onelab.eu")
ec.set(self.channel, 'xmppPort', "5222")
ec.set(self.channel, 'xmppPassword', "1234")
self.app1 = ec.register_resource("omf::Application")
ec.set(self.app1, 'appid', 'Vlc#1')
ec.set(self.app1, 'command', "/opt/vlc-1.1.13/cvlc /opt/10-by-p0d.avi --sout '#rtp{dst=10.0.0.37,port=1234,mux=ts}'")
ec.set(self.app1, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
self.app2 = ec.register_resource("omf::Application")
ec.set(self.app2, 'appid', 'Test#1')
ec.set(self.app2, 'command', "/usr/bin/test -1")
ec.set(self.app2, 'env', " ")
self.app3 = ec.register_resource("omf::Application")
ec.set(self.app3, 'appid', 'Test#2')
ec.set(self.app3, 'command', "/usr/bin/test -2")
ec.set(self.app3, 'env', " ")
self.app4 = ec.register_resource("omf::Application")
ec.set(self.app4, 'appid', 'Test#3')
ec.set(self.app4, 'command', "/usr/bin/test -3")
ec.set(self.app4, 'env', " ")
self.app5 = ec.register_resource("omf::Application")
ec.set(self.app5, 'appid', 'Kill#2')
ec.set(self.app5, 'command', "/usr/bin/killall vlc")
ec.set(self.app5, 'env', " ")
ec.register_connection(self.app1, self.node1)
ec.register_connection(self.app2, self.node1)
ec.register_connection(self.app3, self.node1)
ec.register_connection(self.app4, self.node1)
ec.register_connection(self.app5, self.node1)
ec.register_connection(self.node1, self.iface1)
ec.register_connection(self.iface1, self.channel)
ec.register_condition(self.app2, ResourceAction.START, self.app1, ResourceState.STARTED , "3s")
ec.register_condition(self.app3, ResourceAction.START, self.app2, ResourceState.STARTED , "2s")
ec.register_condition(self.app4, ResourceAction.START, self.app3, ResourceState.STARTED , "3s")
ec.register_condition(self.app5, ResourceAction.START, [self.app3, self.app2], ResourceState.STARTED , "2s")
ec.register_condition(self.app5, ResourceAction.START, self.app1, ResourceState.STARTED , "25s")
ec.register_condition([self.app1, self.app2, self.app3,self.app4, self.app5], ResourceAction.STOP, self.app5, ResourceState.STARTED , "1s")
ec.deploy()
ec.wait_finished([self.app1, self.app2, self.app3,self.app4, self.app5])
self.assertGreaterEqual(round(tdiffsec(ec.get_resource(self.app2).start_time, ec.get_resource(self.app1).start_time),0), 3.0)
self.assertGreaterEqual(round(tdiffsec(ec.get_resource(self.app3).start_time, ec.get_resource(self.app2).start_time),0), 2.0)
self.assertGreaterEqual(round(tdiffsec(ec.get_resource(self.app4).start_time, ec.get_resource(self.app3).start_time),0), 3.0)
self.assertGreaterEqual(round(tdiffsec(ec.get_resource(self.app5).start_time, ec.get_resource(self.app3).start_time),0), 2.0)
self.assertGreaterEqual(round(tdiffsec(ec.get_resource(self.app5).start_time, ec.get_resource(self.app1).start_time),0), 25.0)
self.assertEquals(ec.get_resource(self.node1).state, ResourceState.STARTED)
self.assertEquals(ec.get_resource(self.iface1).state, ResourceState.STARTED)
self.assertEquals(ec.get_resource(self.channel).state, ResourceState.STARTED)
self.assertEquals(ec.get_resource(self.app1).state, ResourceState.STOPPED)
self.assertEquals(ec.get_resource(self.app2).state, ResourceState.STOPPED)
self.assertEquals(ec.get_resource(self.app3).state, ResourceState.STOPPED)
self.assertEquals(ec.get_resource(self.app4).state, ResourceState.STOPPED)
self.assertEquals(ec.get_resource(self.app5).state, ResourceState.STOPPED)
ec.shutdown()
self.assertEquals(ec.get_resource(self.node1).state, ResourceState.RELEASED)
self.assertEquals(ec.get_resource(self.iface1).state, ResourceState.RELEASED)
self.assertEquals(ec.get_resource(self.channel).state, ResourceState.RELEASED)
self.assertEquals(ec.get_resource(self.app1).state, ResourceState.RELEASED)
self.assertEquals(ec.get_resource(self.app2).state, ResourceState.RELEASED)
self.assertEquals(ec.get_resource(self.app3).state, ResourceState.RELEASED)
self.assertEquals(ec.get_resource(self.app4).state, ResourceState.RELEASED)
self.assertEquals(ec.get_resource(self.app5).state, ResourceState.RELEASED)
示例8: OMFVLCWrongCaseWithNonCriticalDep
# 需要导入模块: from nepi.execution.ec import ExperimentController [as 别名]
# 或者: from nepi.execution.ec.ExperimentController import get_resource [as 别名]
class OMFVLCWrongCaseWithNonCriticalDep(unittest.TestCase):
id = 3000
def setUp(self):
self.ec = ExperimentController(exp_id = str(OMFVLCWrongCaseWithNonCriticalDep.id))
OMFVLCWrongCaseWithNonCriticalDep.id += 1
self.node1 = self.ec.register_resource("omf::Node")
self.ec.set(self.node1, 'hostname', 'wlab12')
self.ec.set(self.node1, 'xmppUser', "nepi")
self.ec.set(self.node1, 'xmppServer', "xmpp-plexus.onelab.eu")
self.ec.set(self.node1, 'xmppPort', "5222")
self.ec.set(self.node1, 'xmppPassword', "1234")
self.iface1 = self.ec.register_resource("omf::WifiInterface")
self.ec.set(self.iface1, 'name', "wlan0")
self.ec.set(self.iface1, 'mode', "adhoc")
self.ec.set(self.iface1, 'hw_mode', "g")
self.ec.set(self.iface1, 'essid', "vlcexp")
self.ec.set(self.iface1, 'ip', "10.0.0.12/24")
self.app1 = self.ec.register_resource("omf::Application")
self.ec.set(self.app1, 'appid', 'Kill#1')
self.ec.set(self.app1, 'command', "/usr/bin/test -1")
self.ec.set(self.app1, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
self.ec.register_connection(self.app1, self.node1)
self.ec.register_connection(self.node1, self.iface1)
def test_deploy_with_app_nc_and_critical_wrong(self):
self.node2 = self.ec.register_resource("omf::Node")
self.ec.set(self.node2, 'hostname', 'wlab49')
self.ec.set(self.node2, 'xmppUser', "nepi")
self.ec.set(self.node2, 'xmppServer', "xmpp-plexus.onelab.eu")
self.ec.set(self.node2, 'xmppPort', "5222")
self.ec.set(self.node2, 'xmppPassword', "1234")
self.iface2 = self.ec.register_resource("omf::WifiInterface")
self.ec.set(self.iface2, 'name', "wlan0")
self.ec.set(self.iface2, 'mode', "adhoc")
self.ec.set(self.iface2, 'hw_mode', "g")
self.ec.set(self.iface2, 'essid', "vlcexp")
self.ec.set(self.iface2, 'ip', "10.0.0.49/24")
self.channel = self.ec.register_resource("omf::Channel")
self.ec.set(self.channel, 'channel', "6")
self.app2 = self.ec.register_resource("omf::Application")
self.ec.set(self.app2, "critical", False)
self.ec.set(self.app2, 'appid', 'Kill#32')
self.app3 = self.ec.register_resource("omf::Application")
self.ec.set(self.app3, 'appid', 'Kill#33')
self.ec.register_connection(self.iface1, self.channel)
self.ec.register_connection(self.node2, self.iface2)
self.ec.register_connection(self.iface2, self.channel)
self.ec.register_connection(self.app2, self.node2)
self.ec.register_connection(self.app3, self.node2)
self.ec.register_condition(self.app2, ResourceAction.START, self.app1, ResourceState.STARTED , "5s")
self.ec.register_condition(self.app3, ResourceAction.START, self.app2, ResourceState.STARTED , "5s")
self.ec.register_condition([self.app1, self.app2, self.app3], ResourceAction.STOP, self.app1, ResourceState.STARTED , "15s")
self.ec.deploy()
self.ec.wait_finished([self.app1, self.app2, self.app3])
self.assertEquals(self.ec.get_resource(self.app2).state, ResourceState.FAILED)
self.assertEquals(self.ec.get_resource(self.app3).state, ResourceState.FAILED)
self.ec.shutdown()
self.assertEquals(self.ec.get_resource(self.node1).state, ResourceState.RELEASED)
self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.RELEASED)
self.assertEquals(self.ec.get_resource(self.iface1).state, ResourceState.RELEASED)
self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.RELEASED)
self.assertEquals(self.ec.get_resource(self.channel).state, ResourceState.RELEASED)
self.assertEquals(self.ec.get_resource(self.app1).state, ResourceState.RELEASED)
self.assertEquals(self.ec.get_resource(self.app2).state, ResourceState.RELEASED)
self.assertEquals(self.ec.get_resource(self.app3).state, ResourceState.RELEASED)
def test_deploy_with_app_nc_and_critical_right(self):
self.node2 = self.ec.register_resource("omf::Node")
self.ec.set(self.node2, 'hostname', 'wlab49')
self.ec.set(self.node2, 'xmppUser', "nepi")
self.ec.set(self.node2, 'xmppServer', "xmpp-plexus.onelab.eu")
self.ec.set(self.node2, 'xmppPort', "5222")
self.ec.set(self.node2, 'xmppPassword', "1234")
self.iface2 = self.ec.register_resource("omf::WifiInterface")
self.ec.set(self.iface2, 'name', "wlan0")
self.ec.set(self.iface2, 'mode', "adhoc")
self.ec.set(self.iface2, 'hw_mode', "g")
self.ec.set(self.iface2, 'essid', "vlcexp")
self.ec.set(self.iface2, 'ip', "10.0.0.49/24")
self.channel = self.ec.register_resource("omf::Channel")
self.ec.set(self.channel, 'channel', "6")
#.........这里部分代码省略.........
示例9: test_deploy_in_order
# 需要导入模块: from nepi.execution.ec import ExperimentController [as 别名]
# 或者: from nepi.execution.ec.ExperimentController import get_resource [as 别名]
def test_deploy_in_order(self):
"""
Test scenario: 2 applications running one on 1 node each.
Nodes are connected to Interfaces which are connected
through a channel between them.
- Application needs to wait until Node is ready to be ready
- Node needs to wait until Interface is ready to be ready
- Interface needs to wait until Node is provisioned to be ready
- Interface needs to wait until Channel is ready to be ready
- The channel doesn't wait for any other resource to be ready
"""
from nepi.execution.resource import ResourceFactory
ResourceFactory.register_type(Application)
ResourceFactory.register_type(Node)
ResourceFactory.register_type(Interface)
ResourceFactory.register_type(Channel)
ec = ExperimentController()
app1 = ec.register_resource("Application")
app2 = ec.register_resource("Application")
node1 = ec.register_resource("Node")
node2 = ec.register_resource("Node")
iface1 = ec.register_resource("Interface")
iface2 = ec.register_resource("Interface")
chan = ec.register_resource("Channel")
ec.register_connection(app1, node1)
ec.register_connection(app2, node2)
ec.register_connection(iface1, node1)
ec.register_connection(iface2, node2)
ec.register_connection(iface1, chan)
ec.register_connection(iface2, chan)
ec.deploy()
guids = [app1, app2]
ec.wait_finished(guids)
ec.shutdown()
rmapp1 = ec.get_resource(app1)
rmapp2 = ec.get_resource(app2)
rmnode1 = ec.get_resource(node1)
rmnode2 = ec.get_resource(node2)
rmiface1 = ec.get_resource(iface1)
rmiface2 = ec.get_resource(iface2)
rmchan = ec.get_resource(chan)
## Validate deploy order
# - Application needs to wait until Node is ready to be ready
self.assertTrue(rmnode1.ready_time < rmapp1.ready_time)
self.assertTrue(rmnode2.ready_time < rmapp2.ready_time)
# - Node needs to wait until Interface is ready to be ready
self.assertTrue(rmnode1.ready_time > rmiface1.ready_time)
self.assertTrue(rmnode2.ready_time > rmiface2.ready_time)
# - Interface needs to wait until Node is provisioned to be ready
self.assertTrue(rmnode1.provision_time < rmiface1.ready_time)
self.assertTrue(rmnode2.provision_time < rmiface2.ready_time)
# - Interface needs to wait until Channel is ready to be ready
self.assertTrue(rmchan.ready_time < rmiface1.ready_time)
self.assertTrue(rmchan.ready_time < rmiface2.ready_time)
示例10: t_traces
# 需要导入模块: from nepi.execution.ec import ExperimentController [as 别名]
# 或者: from nepi.execution.ec.ExperimentController import get_resource [as 别名]
def t_traces(self, host, user = None, identity = None):
ec = ExperimentController(exp_id = "test-ns3-traces")
node = ec.register_resource("linux::Node")
if host == "localhost":
ec.set(node, "hostname", "localhost")
else:
ec.set(node, "hostname", self.fedora_host)
ec.set(node, "username", self.fedora_user)
ec.set(node, "identity", self.fedora_identity)
ec.set(node, "cleanProcesses", True)
#ec.set(node, "cleanHome", True)
simu = ec.register_resource("linux::ns3::Simulation")
ec.set(simu, "verbose", True)
ec.register_connection(simu, node)
nsnode1 = add_ns3_node(ec, simu)
dev1 = add_point2point_device(ec, nsnode1, "10.0.0.1", "30")
nsnode2 = add_ns3_node(ec, simu)
dev2 = add_point2point_device(ec, nsnode2, "10.0.0.2", "30")
# Create channel
chan = ec.register_resource("ns3::PointToPointChannel")
ec.set(chan, "Delay", "0s")
ec.register_connection(chan, dev1)
ec.register_connection(chan, dev2)
### create pinger
ping = ec.register_resource("ns3::V4Ping")
ec.set (ping, "Remote", "10.0.0.2")
ec.set (ping, "Interval", "1s")
ec.set (ping, "Verbose", True)
ec.set (ping, "StartTime", "0s")
ec.set (ping, "StopTime", "20s")
ec.register_connection(ping, nsnode1)
# enable traces
ec.enable_trace(dev1, "pcap")
ec.enable_trace(dev1, "promiscPcap")
ec.enable_trace(dev1, "ascii")
ec.enable_trace(dev2, "pcap")
ec.enable_trace(dev2, "promiscPcap")
ec.enable_trace(dev2, "ascii")
ec.deploy()
ec.wait_finished([ping])
# Trace verification
rm_simu = ec.get_resource(simu)
# TODO: Fix this in ns-3: pcap traces do not flush until the Simulator
# process is ended, so we can't get the traces of the 'pcap' and
# 'promiscPcap' traces.
#
#for trace in ["pcap", "promiscPcap", "ascii"]:
for trace in ["ascii"]:
for guid in [dev1, dev2]:
output = ec.trace(guid, trace)
size = ec.trace(guid, trace, attr = TraceAttr.SIZE)
self.assertEquals(size, len(output))
self.assertTrue(size > 100)
block = ec.trace(guid, trace, attr = TraceAttr.STREAM, block = 5, offset = 1)
self.assertEquals(block, output[5:10])
trace_path = ec.trace(guid, trace, attr = TraceAttr.PATH)
rm = ec.get_resource(guid)
path = os.path.join(rm_simu.run_home, rm._trace_filename.get(trace))
self.assertEquals(trace_path, path)
ec.shutdown()
示例11: test_deploy
# 需要导入模块: from nepi.execution.ec import ExperimentController [as 别名]
# 或者: from nepi.execution.ec.ExperimentController import get_resource [as 别名]
def test_deploy(self):
ec = ExperimentController(exp_id = "5421" )
self.node1 = ec.register_resource("omf::Node")
ec.set(self.node1, 'hostname', 'wlab12')
ec.set(self.node1, 'xmppUser', "nepi")
ec.set(self.node1, 'xmppServer', "xmpp-plexus.onelab.eu")
ec.set(self.node1, 'xmppPort', "5222")
ec.set(self.node1, 'xmppPassword', "1234")
self.iface1 = ec.register_resource("omf::WifiInterface")
ec.set(self.iface1, 'name', "wlan0")
ec.set(self.iface1, 'mode', "adhoc")
ec.set(self.iface1, 'hw_mode', "g")
ec.set(self.iface1, 'essid', "vlcexp")
ec.set(self.iface1, 'ip', "10.0.0.17/24")
self.channel = ec.register_resource("omf::Channel")
ec.set(self.channel, 'channel', "6")
ec.set(self.channel, 'xmppUser', "nepi")
ec.set(self.channel, 'xmppServer', "xmpp-plexus.onelab.eu")
ec.set(self.channel, 'xmppPort', "5222")
ec.set(self.channel, 'xmppPassword', "1234")
self.app1 = ec.register_resource("omf::Application")
ec.set(self.app1, 'appid', 'Vlc#1')
ec.set(self.app1, 'command', "ping -c5 10.0.0.17")
ec.register_connection(self.app1, self.node1)
ec.register_connection(self.node1, self.iface1)
ec.register_connection(self.iface1, self.channel)
ec.register_condition(self.app1, ResourceAction.STOP, self.app1, ResourceState.STARTED , "10s")
ec.deploy()
ec.wait_finished(self.app1)
stdout_1 = ec.trace(self.app1, "stdout")
stderr_1 = ec.trace(self.app1, "stderr")
if stdout_1:
f = open("app1_out.txt", "w")
f.write(stdout_1)
f.close()
if stderr_1:
f = open("app1_err.txt", "w")
f.write(stderr_1)
f.close()
self.assertEquals(ec.get_resource(self.node1).state, ResourceState.STARTED)
self.assertEquals(ec.get_resource(self.iface1).state, ResourceState.STARTED)
self.assertEquals(ec.get_resource(self.channel).state, ResourceState.STARTED)
self.assertEquals(ec.get_resource(self.app1).state, ResourceState.STOPPED)
ec.shutdown()
self.assertEquals(ec.get_resource(self.node1).state, ResourceState.RELEASED)
self.assertEquals(ec.get_resource(self.iface1).state, ResourceState.RELEASED)
self.assertEquals(ec.get_resource(self.channel).state, ResourceState.RELEASED)
self.assertEquals(ec.get_resource(self.app1).state, ResourceState.RELEASED)
t = open("app1_out.txt", "r")
l = t.readlines()
self.assertEquals(l[0], "PING 10.0.0.17 (10.0.0.17) 56(84) bytes of data.\n")
self.assertIn("5 packets transmitted, 5 received, 0% packet loss, time", l[-2])
self.assertIn("rtt min/avg/max/mdev = ", l[-1])
t.close()
os.remove("app1_out.txt")
示例12: OMFVLCWrongCaseAllCritical
# 需要导入模块: from nepi.execution.ec import ExperimentController [as 别名]
# 或者: from nepi.execution.ec.ExperimentController import get_resource [as 别名]
class OMFVLCWrongCaseAllCritical(unittest.TestCase):
id = 1000
def setUp(self):
self.ec = ExperimentController(exp_id = str(OMFVLCWrongCaseAllCritical.id))
OMFVLCWrongCaseAllCritical.id += 1
self.node1 = self.ec.register_resource("omf::Node")
self.ec.set(self.node1, 'hostname', 'wlab12')
self.ec.set(self.node1, 'xmppUser', "nepi")
self.ec.set(self.node1, 'xmppServer', "xmpp-plexus.onelab.eu")
self.ec.set(self.node1, 'xmppPort', "5222")
self.ec.set(self.node1, 'xmppPassword', "1234")
self.iface1 = self.ec.register_resource("omf::WifiInterface")
self.ec.set(self.iface1, 'name', "wlan0")
self.ec.set(self.iface1, 'mode', "adhoc")
self.ec.set(self.iface1, 'hw_mode', "g")
self.ec.set(self.iface1, 'essid', "vlcexp")
self.ec.set(self.iface1, 'ip', "10.0.0.12/24")
self.app1 = self.ec.register_resource("omf::Application")
self.ec.set(self.app1, 'appid', 'Vlc#1')
self.ec.set(self.app1, 'command', "/opt/vlc-1.1.13/cvlc /opt/10-by-p0d.avi --sout '#rtp{dst=10.0.0.49,port=1234,mux=ts}'")
self.ec.set(self.app1, 'env', "DISPLAY=localhost:10.0 XAUTHORITY=/root/.Xauthority")
self.ec.register_connection(self.app1, self.node1)
self.ec.register_connection(self.node1, self.iface1)
def test_deploy_wo_node(self):
self.node2 = self.ec.register_resource("omf::Node")
self.iface2 = self.ec.register_resource("omf::WifiInterface")
self.ec.set(self.iface2, 'name', "wlan0")
self.ec.set(self.iface2, 'mode', "adhoc")
self.ec.set(self.iface2, 'hw_mode', "g")
self.ec.set(self.iface2, 'essid', "vlcexp")
self.ec.set(self.iface2, 'ip', "10.0.0.49/24")
self.channel = self.ec.register_resource("omf::Channel")
self.ec.set(self.channel, 'channel', "6")
self.ec.register_connection(self.iface1, self.channel)
self.ec.register_connection(self.node2, self.iface2)
self.ec.register_connection(self.iface2, self.channel)
self.ec.register_condition([self.app1], ResourceAction.STOP, self.app1, ResourceState.STARTED , "2s")
self.ec.deploy()
self.ec.wait_finished([self.app1])
self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.FAILED)
self.ec.shutdown()
self.assertEquals(self.ec.get_resource(self.node1).state, ResourceState.RELEASED)
self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.RELEASED)
self.assertEquals(self.ec.get_resource(self.iface1).state, ResourceState.RELEASED)
self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.RELEASED)
self.assertEquals(self.ec.get_resource(self.channel).state, ResourceState.RELEASED)
self.assertEquals(self.ec.get_resource(self.app1).state, ResourceState.RELEASED)
def test_deploy_wo_hostname(self):
self.node2 = self.ec.register_resource("omf::Node")
self.ec.set(self.node2, 'xmppUser', "nepi")
self.ec.set(self.node2, 'xmppServer', "xmpp-plexus.onelab.eu")
self.ec.set(self.node2, 'xmppPort', "5222")
self.ec.set(self.node2, 'xmppPassword', "1234")
self.iface2 = self.ec.register_resource("omf::WifiInterface")
self.ec.set(self.iface2, 'name', "wlan0")
self.ec.set(self.iface2, 'mode', "adhoc")
self.ec.set(self.iface2, 'hw_mode', "g")
self.ec.set(self.iface2, 'essid', "vlcexp")
self.ec.set(self.iface2, 'ip', "10.0.0.49/24")
self.channel = self.ec.register_resource("omf::Channel")
self.ec.set(self.channel, 'channel', "6")
self.ec.register_connection(self.iface1, self.channel)
self.ec.register_connection(self.node2, self.iface2)
self.ec.register_connection(self.iface2, self.channel)
self.ec.register_condition([self.app1], ResourceAction.STOP, self.app1, ResourceState.STARTED , "2s")
self.ec.deploy()
self.ec.wait_finished([self.app1])
self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.FAILED)
self.ec.shutdown()
self.assertEquals(self.ec.get_resource(self.node1).state, ResourceState.RELEASED)
self.assertEquals(self.ec.get_resource(self.node2).state, ResourceState.RELEASED)
self.assertEquals(self.ec.get_resource(self.iface1).state, ResourceState.RELEASED)
self.assertEquals(self.ec.get_resource(self.iface2).state, ResourceState.RELEASED)
#.........这里部分代码省略.........