Skip to content

Commit

Permalink
First pass at generic emulab configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
anirajk committed Oct 13, 2016
1 parent 02ba5e6 commit 75670f6
Showing 1 changed file with 57 additions and 17 deletions.
74 changes: 57 additions & 17 deletions scripts/emulabconfig.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,46 @@
#!/usr/bin/env python
"""
This module defines an Emulab specific cluster hooks and exposes configuration information such as RAMCloud hosts and binaries
Expects EMULAB_HOST environment variable to point to node-0 in the emulab experiment and passwordless ssh access to the node
"""

import subprocess
import sys
import os
import re
import socket
import xml.etree.ElementTree as ET
import traceback

__all__ = ['getHosts', 'local_scripts_path', 'top_path', 'obj_path',
'default_disk1', 'default_disk2', 'EmulabClusterHooks', 'log']

hostname = socket.gethostname()

hosts = [
('pc813.emulab.net', '155.98.36.113', 0),
('pc806.emulab.net', '155.98.36.106', 1),
('pc807.emulab.net', '155.98.36.107', 2),
('pc805.emulab.net', '155.98.36.105', 3)
]
def log(msg):
print '[%s] %s' % (hostname, msg)

def getHosts():
nodeId = 0
serverList = []
try:
log("trying to get manifest locally")
out = subprocess.check_output("/usr/bin/geni-get manifest",shell=True, stderr=subprocess.STDOUT)
except:
log("trying EMULAB_HOST to get manifest")
if 'EMULAB_HOST' not in os.environ:
log("'EMULAB_HOST' not exported")
sys.exit(1)
out = subprocess.check_output("ssh %s /usr/bin/geni-get manifest" % os.environ['EMULAB_HOST'],
shell=True, stderr=subprocess.STDOUT)
root = ET.fromstring(out)
for child in root.getchildren():
if child.tag.endswith('node'):
for host in child.getchildren():
if host.tag.endswith('host'):
serverList.append((host.attrib['name'], host.attrib['ipv4'], nodeId))
nodeId += 1
return serverList

def ssh(server, cmd, checked=True):
if checked:
Expand All @@ -19,9 +50,6 @@ def ssh(server, cmd, checked=True):
return subprocess.call('ssh %s "%s"' % (server, cmd),
shell=True, stdout=sys.stdout)

hostname = socket.gethostname()
def log(msg):
print '[%s] %s' % (hostname, msg)

def captureSh(command, **kwargs):
"""Execute a local command and capture its output."""
Expand Down Expand Up @@ -58,10 +86,11 @@ def captureSh(command, **kwargs):
class EmulabClusterHooks:
def __init__(self):
self.remotewd = None

self.hosts = getHosts()

def get_remote_wd(self):
if self.remotewd is None:
self.remotewd = os.path.join(captureSh('ssh %s pwd' % hosts[0][0]),
self.remotewd = os.path.join(captureSh('ssh %s pwd' % self.hosts[0][0]),
'RAMCloud')
return self.remotewd

Expand All @@ -79,6 +108,13 @@ def send_code(self, server):
self.get_remote_wd()),
shell=True, stdout=sys.stdout)

#def write_local_config(self, server):
# log("Writing localconfig on %s" % server)
# hostlines = str(self.hosts).split("(")
# ssh(server, 'cd %s && echo hosts=[ | tee scripts/localconfig.py;' % self.get_remote_wd())
# for line in hostlines[1:]:
# ssh(server, 'cd %s && echo \(%s | tee -a scripts/localconfig.py;' %(self.get_remote_wd(), re.escape(line)))

def compile_code(self, server, clean=False):
log("Compiling code on %s" % server)
clean_cmd = ''
Expand All @@ -88,6 +124,10 @@ def compile_code(self, server, clean=False):
'(cd %s; (%s make -j 8) > ' % (self.get_remote_wd(), clean_cmd) +
'%s/build.log)' % self.get_remote_wd())

def kill_procs(self, server):
log("Killing existing RAMCloud processes")
ssh(server, 'sudo pkill -f RAMCloud')

def create_log_dir(self, server):
log("Creating %s on %s" % (self.cluster.log_subdir, server))
ssh(server,
Expand All @@ -105,15 +145,18 @@ def fix_disk_permissions(self, server):

def cluster_enter(self, cluster):
self.cluster = cluster
log('== Connecting to Emulab via %s ==' % hosts[0][0])
for host in hosts:
log('== Connecting to Emulab via %s ==' % self.hosts[0][0])
for host in self.hosts:
hostName = host[0]
log('-- Preparing host ' + hostName)
#self.write_local_config(hostName)
self.kill_procs(hostName)
self.send_code(hostName)
self.compile_code(hostName)
self.create_log_dir(hostName)
self.fix_disk_permissions(hostName)
log('== Emulab Cluster Configured ==')
log("If you are running clusterperf, it might take a while!")

def collect_logs(self, server):
log('Collecting logs from host ' + server)
Expand All @@ -124,16 +167,13 @@ def collect_logs(self, server):

def cluster_exit(self):
log('== Emulab Cluster Tearing Down ==')
for host in hosts:
for host in self.hosts:
hostName = host[0]
self.collect_logs(hostName)
log('== Emulab Cluster Torn Down ==')
pass

hooks = EmulabClusterHooks()

local_scripts_path = os.path.dirname(os.path.abspath(__file__))
top_path = os.path.abspath(local_scripts_path + '/..')

obj_path = os.path.join(top_path, obj_dir)

0 comments on commit 75670f6

Please sign in to comment.