Skip to content

Commit

Permalink
tomk wanted python tests to report the h2o version to python stdout w…
Browse files Browse the repository at this point in the history
…hen running tests

now outputs this, before starting h2o again to run a test

Running h2o to get java version
04:48:17.194 main      INFO WATER: Build git branch: master
04:48:17.194 main      INFO WATER: Build git hash: fe2c27d
04:48:17.194 main      INFO WATER: Build git describe: fe2c27d-dirty
04:48:17.194 main      INFO WATER: Build project version: 99.80
04:48:17.194 main      INFO WATER: Built by: 'kevin'
04:48:17.195 main      INFO WATER: Built on: 'Thu Sep  5 14:09:20 PDT 2013'
  • Loading branch information
Kevin Normoyle committed Sep 5, 2013
1 parent fe2c27d commit 6d3abfb
Showing 1 changed file with 38 additions and 21 deletions.
59 changes: 38 additions & 21 deletions py/h2o.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# For checking ports in use, using netstat thru a subprocess.
from subprocess import Popen, PIPE


def sleep(secs):
if getpass.getuser()=='jenkins':
period = max(secs,120)
Expand Down Expand Up @@ -267,27 +266,31 @@ def get_ip_address():
verboseprint("get_ip_address:", ip)
return ip

def spawn_cmd(name, args, capture_output=True):
# can't have a list of cmds, because cmd is a list
# cmdBefore gets executed first, and we wait for it to complete
def spawn_cmd(name, cmd, capture_output=True, **kwargs):
if capture_output:
outfd,outpath = tmp_file(name + '.stdout.', '.log')
errfd,errpath = tmp_file(name + '.stderr.', '.log')
ps = psutil.Popen(args, stdin=None, stdout=outfd, stderr=errfd)
outfd, outpath = tmp_file(name + '.stdout.', '.log')
errfd, errpath = tmp_file(name + '.stderr.', '.log')
ps = psutil.Popen(cmd, stdin=None, stdout=outfd, stderr=errfd, **kwargs)
else:
outpath = '<stdout>'
errpath = '<stderr>'
ps = psutil.Popen(args)
ps = psutil.Popen(cmd, **kwargs)

comment = 'PID %d, stdout %s, stderr %s' % (
ps.pid, os.path.basename(outpath), os.path.basename(errpath))
log(' '.join(args), comment=comment)
log(' '.join(cmd), comment=comment)
return (ps, outpath, errpath)

def spawn_wait(ps, stdout, stderr, timeout=None):
def spawn_wait(ps, stdout, stderr, capture_output=True, timeout=None):
rc = ps.wait(timeout)
out = file(stdout).read()
err = file(stderr).read()
## print out
## print err
if capture_output:
out = file(stdout).read()
err = file(stderr).read()
else:
out = 'stdout not captured'
err = 'stderr not captured'

if rc is None:
ps.terminate()
Expand All @@ -297,9 +300,9 @@ def spawn_wait(ps, stdout, stderr, timeout=None):
raise Exception("%s %s failed.\nstdout:\n%s\n\nstderr:\n%s" % (ps.name, ps.cmdline, out, err))
return rc

def spawn_cmd_and_wait(name, args, timeout=None):
(ps, stdout, stderr) = spawn_cmd(name, args)
spawn_wait(ps, stdout, stderr, timeout=None)
def spawn_cmd_and_wait(name, cmd, capture_output=True, timeout=None, **kwargs):
(ps, stdout, stderr) = spawn_cmd(name, cmd, capture_output, **kwargs)
spawn_wait(ps, stdout, stderr, capture_output, timeout)

def kill_process_tree(pid, including_parent=True):
parent = psutil.Process(pid)
Expand Down Expand Up @@ -367,6 +370,16 @@ def check_port_group(base_port):
output = p2.communicate()[0]
print output

def check_h2o_version():
# assumes you want to know about 3 ports starting at base_port
command1Split = ['java', '-jar', find_file('target/h2o.jar'), '--version']
command2Split = ['egrep', '-v', '( Java | started)']
print "Running h2o to get java version"
p1 = Popen(command1Split, stdout=PIPE)
p2 = Popen(command2Split, stdin=p1.stdout, stdout=PIPE)
output = p2.communicate()[0]
print output

def default_hosts_file():
return 'pytest_config-{0}.json'.format(getpass.getuser())

Expand Down Expand Up @@ -404,6 +417,9 @@ def build_cloud(node_count=2, base_port=54321, hosts=None,
fake_cloud=False, conservative=False, **kwargs):
# moved to here from unit_main. so will run with nosetests too!
clean_sandbox()
# start up h2o to report the java version (once). output to python stdout
check_h2o_version()

# keep this param in kwargs, because we pass to the H2O node build, so state
# is created that polling and other normal things can check, to decide to dump
# info to benchmark.log
Expand Down Expand Up @@ -1646,10 +1662,9 @@ def sandbox_error_report(self, done=None):
return (self.sandbox_error_was_reported)

def get_args(self):
#! FIX! is this used for both local and remote?
# I guess it doesn't matter if we use flatfile for both now
args = [ 'java' ]
args = ['java']

# I guess it doesn't matter if we use flatfile for both now
# defaults to not specifying
# FIX! we need to check that it's not outside the limits of the dram of the machine it's running on?
if self.java_heap_GB is not None:
Expand Down Expand Up @@ -1869,7 +1884,7 @@ def __init__(self, *args, **kwargs):
if self.fake_cloud: # we use fake_cloud for when we run on externally built cloud like Hadoop
self.ps = None
else:
spawn = spawn_cmd(logPrefix, self.get_args(), capture_output=self.capture_output)
spawn = spawn_cmd(logPrefix, cmd=self.get_args(), capture_output=self.capture_output)
self.ps = spawn[0]

def get_h2o_jar(self):
Expand Down Expand Up @@ -2053,8 +2068,10 @@ def __init__(self, host, *args, **kwargs):
# This hack only works when the dest is /tmp/h2o*jar. It's okay to execute
# with pwd = /tmp. If /tmp/ isn't in the jar path, I guess things will be the same as
# normal.
self.channel.exec_command("cd /tmp; ls -ltr "+self.jar+"; "+ \
re.sub("/tmp/","",cmd)) # removing the /tmp/ we know is in there
cmdList = ["cd /tmp"] # separate by ;<space> when we join
cmdList += ["ls -ltr " + self.jar]
cmdList += [re.sub("/tmp/", "", cmd)]
self.channel.exec_command("; ".join(cmdList))

if self.capture_output:
if self.node_id is not None:
Expand Down

0 comments on commit 6d3abfb

Please sign in to comment.