import time
import socket
import threading
+import logging
from nepi.util.constants import ApplicationStatus as AS
self._build_pid = None
self._build_ppid = None
+ # Logging
+ self._logger = logging.getLogger('nepi.testbeds.planetlab')
+
def __str__(self):
return "%s<%s>" % (
return local_path
def setup(self):
- print >>sys.stderr, "Setting up", self
+ self._logger.info("Setting up %s", self)
self._make_home()
self._launch_build()
self._finish_build()
def async_setup_wait(self):
if not self._setup:
- print >>sys.stderr, "Waiting for", self, "to be setup"
+ self._logger.info("Waiting for %s to be setup", self)
if self._setuper:
self._setuper.join()
if not self._setup:
buildscript = self._do_build_master()
if buildscript is not None:
- print >>sys.stderr, "Building", self
+ self._logger.info("Building %s", self)
# upload build script
try:
else:
raise RuntimeError, "Failed to set up build slave %s: cannot get pid" % (self.home_path,)
- print >>sys.stderr, "Deploying", self
+ self._logger.info("Deploying %s", self)
def _do_wait_build(self):
pid = self._build_pid
break
else:
if first:
- print >>sys.stderr, "Waiting for", self, "to finish building",
- if self._master is not None:
- print >>sys.stderr, "(build slave)"
- else:
- print >>sys.stderr, "(build master)"
+ self._logger.info("Waiting for %s to finish building %s", self,
+ "(build slave)" if self._master is not None else "(build master)")
first = False
time.sleep(delay*(0.5+random.random()))
"(expected %r, got %r), see buildlog: %s" % (
self.home_path, pid, ppid, self._master_token, slave_token, buildlog)
- print >>sys.stderr, "Built", self
+ self._logger.info("Built %s", self)
def _do_kill_build(self):
pid = self._build_pid
ppid = self._build_ppid
if pid and ppid:
- print >>sys.stderr, "Killing build of", self
+ self._logger.info("Killing build of %s", self)
rspawn.remote_kill(
pid, ppid,
host = self.node.hostname,
def _do_install(self):
if self.install:
- print >>sys.stderr, "Installing", self
+ self._logger.info("Installing %s", self)
# Install application
try:
)
def start(self):
- print >>sys.stderr, "Starting", self
+ self._logger.info("Starting %s", self)
# Create shell script with the command
# This way, complex commands and scripts can be ran seamlessly
ident_key = self.node.ident_path,
server_key = self.node.server_key
)
- print >>sys.stderr, "Killed", self
+ self._logger.info("Killed %s", self)
class NepiDependency(Dependency):
import subprocess
import random
import shutil
+import logging
class TempKeyError(Exception):
pass
self._just_provisioned = set()
self._load_blacklist()
+
+ self._logger = logging.getLogger('nepi.testbeds.planetlab')
@property
def home_directory(self):
get_attribute_value("plcHost")
self.plcUrl = self._attributes.\
get_attribute_value("plcUrl")
+ self.logLevel = self._attributes.\
+ get_attribute_value("plLogLevel")
+
+ self._logger.setLevel(getattr(logging,self.logLevel))
+
super(TestbedController, self).do_setup()
def do_post_asynclaunch(self, guid):
node.slicename = self.slicename
# Show the magic
- print >>sys.stderr, "PlanetLab Node", guid, "configured at", node.hostname
+ self._logger.info("PlanetLab Node %s configured at %s", guid, node.hostname)
try:
for guid, node in self._elements.iteritems():
if isinstance(node, self._node.Node):
- print >>sys.stderr, "Waiting for Node", guid, "configured at", node.hostname,
- sys.stdout.flush()
+ self._logger.info("Waiting for Node %s configured at %s", guid, node.hostname)
node.wait_provisioning(
(20*60 if node._node_id in self._just_provisioned else 60)
)
- print >>sys.stderr, "READY"
+ self._logger.info("READY Node %s at %s", guid, node.hostname)
except self._node.UnresponsiveNodeError:
# Uh...
- print >>sys.stderr, "UNRESPONSIVE"
+ self._logger.warn("UNRESPONSIVE Node %s", node.hostname)
# Mark all dead nodes (which are unresponsive) on the blacklist
# and re-raise
for guid, node in self._elements.iteritems():
if isinstance(node, self._node.Node):
if not node.is_alive():
- print >>sys.stderr, "Blacklisting", node.hostname, "for unresponsiveness"
+ self._logger.warn("Blacklisting %s for unresponsiveness", node.hostname)
self._blacklist.add(node._node_id)
node.unassign_node()
"flags": Attribute.ExecReadOnly | Attribute.ExecImmutable | Attribute.NoDefaultValue,
"validation_function": validation.is_string
}),
+ "pl_log_level": dict({
+ "name": "plLogLevel",
+ "help": "Verbosity of logging of planetlab events.",
+ "value": "ERROR",
+ "type": Attribute.ENUM,
+ "allowed": ["DEBUG",
+ "INFO",
+ "WARNING",
+ "ERROR",
+ "CRITICAL"],
+ "validation_function": validation.is_enum,
+ }),
})
class MetadataInfo(metadata.MetadataInfo):
import resourcealloc
import socket
import sys
+import logging
from nepi.util import server
from nepi.util import parallel
# Those are filled when an actual node is allocated
self._node_id = None
+
+ # Logging
+ self._logger = logging.getLogger('nepi.testbeds.planetlab')
@property
def _nepi_testbed_environment_setup(self):
)
def find_candidates(self, filter_slice_id=None):
- print >>sys.stderr, "Finding candidates for", self.make_filter_description()
+ self._logger.info("Finding candidates for %s", self.make_filter_description())
fields = ('node_id',)
replacements = {'timeframe':self.timeframe}
# make sure hostnames are resolvable
if candidates:
- print >>sys.stderr, " Found", len(candidates), "candidates. Checking for reachability..."
+ self._logger.info(" Found %s candidates. Checking for reachability...", len(candidates))
hostnames = dict(map(operator.itemgetter('node_id','hostname'),
self._api.GetNodes(list(candidates), ['node_id','hostname'])
candidates = set(parallel.pfilter(resolvable, candidates,
maxthreads = 16))
- print >>sys.stderr, " Found", len(candidates), "reachable candidates."
+ self._logger.info(" Found %s reachable candidates.", len(candidates))
return candidates
raise RuntimeError, "Route %s cannot be bound to any virtual interface " \
"- PL can only handle rules over virtual interfaces. Candidates are: %s" % (route,devs)
- print >>sys.stderr, "Setting up routes for", self.hostname
+ self._logger.info("Setting up routes for %s", self.hostname)
(out,err),proc = server.popen_ssh_command(
"( sudo -S bash -c 'cat /vsys/vroute.out >&2' & ) ; sudo -S bash -c 'cat > /vsys/vroute.in' ; sleep 0.1" % dict(
import time
import re
import sys
+import logging
from nepi.util import server
self._pid = None
self._ppid = None
self._if_name = None
+
+ # Logging
+ self._logger = logging.getLogger('nepi.testbeds.planetlab')
def __str__(self):
local = self.local()
if not listen and check_proto != 'fd':
args.append(str(peer_addr))
- print >>sys.stderr, "Starting", self
+ self._logger.info("Starting %s", self)
self._make_home()
self._install_scripts()
# Wait for the connection to be established
for spin in xrange(30):
if self.status() != rspawn.RUNNING:
- print >>sys.stderr, "FAILED TO CONNECT! ", self
+ self._logger.warn("FAILED TO CONNECT! %s", self)
break
(out,err),proc = server.eintr_retry(server.popen_ssh_command)(
time.sleep(1.0)
else:
- print >>sys.stderr, "FAILED TO CONNECT! ", self
+ self._logger.warn("FAILED TO CONNECT! %s", self)
@property
def if_name(self):
else:
raise RuntimeError, "Failed to launch TUN forwarder"
elif not self._started:
- print >>sys.stderr, "SYNC",
self.launch()
def checkpid(self):
status = self.status()
if status == rspawn.RUNNING:
- print >>sys.stderr, "Stopping", self
+ self._logger.info("Stopping %s", self)
# kill by ppid+pid - SIGTERM first, then try SIGKILL
rspawn.remote_kill(
for i in xrange(30):
status = self.status()
if status != rspawn.RUNNING:
- print >>sys.stderr, "Stopped", self
+ self._logger.info("Stopped %s", self)
break
time.sleep(interval)
interval = min(30.0, interval * 1.1)