from nepi.core.attributes import Attribute
from nepi.util import validation
from nepi.util.constants import STATUS_NOT_STARTED, STATUS_RUNNING, \
- STATUS_FINISHED
+ STATUS_FINISHED, ATTR_NEPI_TESTBED_ENVIRONMENT_SETUP
import functools
import os
"flags": Attribute.DesignOnly,
"validation_function": validation.is_string
}),
+ ATTR_NEPI_TESTBED_ENVIRONMENT_SETUP: dict({
+ "name": ATTR_NEPI_TESTBED_ENVIRONMENT_SETUP,
+ "help": "Commands to set up the environment needed to run NEPI testbeds",
+ "type": Attribute.STRING,
+ "flags": Attribute.Invisible | Attribute.ReadOnly,
+ "validation_function": validation.is_string
+ }),
"netpipe_mode": dict({
"name": "mode",
"max_reliability",
"min_bandwidth",
"max_bandwidth",
+
+ # NEPI-in-NEPI attributes
+ ATTR_NEPI_TESTBED_ENVIRONMENT_SETUP,
],
"connector_types": ["devs", "apps", "pipes", "deps"]
}),
import time
import os
import collections
+import cStringIO
from nepi.util import server
# Those are filled when an actual node is allocated
self._node_id = None
+ @property
+ def _nepi_testbed_environment_setup(self):
+ command = cStringIO.StringIO()
+ command.write('PYTHONPATH=$PYTHONPATH:%s' % (
+ ':'.join(["${HOME}/"+server.shell_escape(s) for s in self.pythonpath])
+ ))
+ command.write(' PATH=$PATH:%s' % (
+ ':'.join(["${HOME}/"+server.shell_escape(s) for s in self.pythonpath])
+ ))
+ if self.node.env:
+ for envkey, envvals in self.node.env.iteritems():
+ for envval in envvals:
+ command.write(' %s=%s' % (envkey, envval))
+ command.write(self.command)
+ return command.getvalue()
+
def build_filters(self, target_filters, filter_map):
for attr, tag in filter_map.iteritems():
value = getattr(self, attr, None)
import base64
from nepi.core.attributes import AttributesMap, Attribute
from nepi.util import server, validation
-from nepi.util.constants import TIME_NOW
+from nepi.util.constants import TIME_NOW, ATTR_NEPI_TESTBED_ENVIRONMENT_SETUP
import getpass
import cPickle
import sys
else access_config.get_attribute_value("mode")
launch = True if not access_config \
else not access_config.get_attribute_value("recover")
+ environment_setup = access_config \
+ and access_config.has_attribute(ATTR_NEPI_TESTBED_ENVIRONMENT_SETUP) \
+ and access_config.get_attribute_value(ATTR_NEPI_TESTBED_ENVIRONMENT_SETUP) \
+ or ""
if not mode or mode == AccessConfiguration.MODE_SINGLE_PROCESS:
if not launch:
raise ValueError, "Unsupported instantiation mode: %s with lanch=False" % (mode,)
get_access_config_params(access_config)
return TestbedControllerProxy(root_dir, log_level, testbed_id = testbed_id,
testbed_version = testbed_version, host = host, port = port,
- user = user, agent = agent, launch = launch)
+ user = user, agent = agent, launch = launch,
+ environment_setup = environment_setup)
raise RuntimeError("Unsupported access configuration '%s'" % mode)
def _build_testbed_controller(testbed_id, testbed_version):
class TestbedControllerProxy(object):
def __init__(self, root_dir, log_level, testbed_id = None,
testbed_version = None, launch = True, host = None,
- port = None, user = None, agent = None):
+ port = None, user = None, agent = None,
+ environment_setup = ""):
if launch:
if testbed_id == None or testbed_version == None:
raise RuntimeError("To launch a TesbedInstance server a \
s.run()" % (root_dir, log_level, testbed_id,
testbed_version)
proc = server.popen_ssh_subprocess(python_code, host = host,
- port = port, user = user, agent = agent)
+ port = port, user = user, agent = agent,
+ environment_setup = environment_setup)
if proc.poll():
err = proc.stderr.read()
raise RuntimeError("Server could not be executed: %s" % \
class ExperimentControllerProxy(object):
def __init__(self, root_dir, log_level, experiment_xml = None,
launch = True, host = None, port = None, user = None,
- agent = None):
+ agent = None, environment_setup = ""):
if launch:
# launch server
if experiment_xml == None:
s = ExperimentControllerServer(%r, %r, %r);\
s.run()" % (root_dir, log_level, xml)
proc = server.popen_ssh_subprocess(python_code, host = host,
- port = port, user = user, agent = agent)
+ port = port, user = user, agent = agent,
+ environment_setup = environment_setup)
if proc.poll():
err = proc.stderr.read()
raise RuntimeError("Server could not be executed: %s" % \