Skip to content

Commit

Permalink
Works on unicorn for both anaconda and non-anaconda
Browse files Browse the repository at this point in the history
  • Loading branch information
hschilling committed Apr 21, 2015
1 parent eaed2be commit 8b4d196
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 31 deletions.
4 changes: 2 additions & 2 deletions config/testhosts.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ test_branch: true
test_release: false

[win2008_32_py27_anaconda]
image_id: ami-6accf702
image_id: ami-dea993b6
instance_type: c1.medium
user: Administrator
security_groups: windows
platform: windows
anaconda: true
py: python2.7
py: python
test_branch: true
test_release: false
build_binaries: false
Expand Down
142 changes: 115 additions & 27 deletions openmdao.devtools/src/openmdao/devtools/loc_bld_tst.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,58 @@ def _run_gofile(startdir, gopath, args=()):
os.chdir(startdir)
return retcode

def _run_install_script(startdir, install_script_path, args=()):
import os
retcode = -1
install_script_dir, install_script_file = os.path.split(install_script_path)
os.chdir(install_script_dir)

outname = 'build.out'
f = open(outname, 'wb')
py = sys.executable.replace('\\','/')
envdict = os.environ.copy()

# import os
# os.environ['PATH'] = '/home/ubuntu/anaconda/bin:' + os.environ['PATH']

print 'inside _run_install_script PATH', os.environ['PATH']


# if we're running from inside of a virtualenv, we need to
# remove VIRTUAL_ENV from the environment before spawning the
# subprocess, else the build will end up inside of devenv
# instead of where it's supposed to be
# if 'VIRTUAL_ENV' in envdict:
# del envdict['VIRTUAL_ENV']
try:
print 'running install script with', '%s %s %s' % (py, install_script_file, ' '.join(args))
p = subprocess.Popen('%s %s %s' % (py, install_script_file, ' '.join(args)),
stdout=f, stderr=subprocess.STDOUT,
shell=True, env=envdict)
_wait(p)
retcode = p.returncode
finally:
f.close()
# in some cases there are some unicode characters in the
# output which cause fabric to barf, so strip out unicode
# before returning
if sys.platform.startswith('win'):
mode = 'r'
else:
mode = 'rt'
with codecs.open(outname, mode, encoding='ascii', errors='ignore') as f:
for line in f:
print line,
sys.stdout.flush()
os.chdir(startdir)
return retcode


def _run_sub(outname, cmd, env=None):
f = open(outname, 'wb')
try:
p = subprocess.Popen(cmd, stdout=f, stderr=subprocess.STDOUT,
shell=True, env=env)
shell=True, env=env, executable='/bin/bash')
_wait(p)
finally:
f.close()
Expand Down Expand Up @@ -107,7 +153,7 @@ def _wait(p):


def build_and_test(fname=None, workdir='.', keep=False,
branch=None, testargs=()):
branch=None, anaconda=False, testargs=()):
"""Builds OpenMDAO, either a dev build or a release build, and runs
the test suite on it.
"""
Expand Down Expand Up @@ -139,7 +185,8 @@ def build_and_test(fname=None, workdir='.', keep=False,
if build_type == 'release':
envdir, retcode = install_release(fname)
else: # dev test
envdir, retcode = install_dev_env(fname, branch=options.branch)
# envdir, retcode = install_dev_env(fname, branch=options.branch)
envdir, retcode = install_dev_env(fname, branch=branch, anaconda=anaconda)
finally:
os.chdir(workdir)

Expand All @@ -160,7 +207,7 @@ def build_and_test(fname=None, workdir='.', keep=False,
sys.stdout.flush()

try:
retcode = activate_and_test(envdir, testargs)
retcode = activate_and_test(envdir, testargs=testargs, anaconda=anaconda)
print "test return code =", retcode
finally:
sys.stdout.flush()
Expand Down Expand Up @@ -209,7 +256,7 @@ def install_release(url):
return (releasedir, retcode)


def install_dev_env(url, branch=None):
def install_dev_env(url, branch=None, anaconda=False):
"""
Installs an OpenMDAO dev environment given an OpenMDAO source
tree.
Expand Down Expand Up @@ -267,41 +314,81 @@ def install_dev_env(url, branch=None):

print "building openmdao development environment in %s" % treedir

gopath = os.path.join(treedir, 'go-openmdao-dev.py')
# gopath = os.path.join(treedir, 'go-openmdao-dev.py')

# retcode = _run_gofile(startdir, gopath)

install_script_path = os.path.join(treedir, 'install_openmdao_dev.py')

print 'calling _run_install_script'
retcode = _run_install_script(startdir, install_script_path)



if anaconda:
envdir = treedir
else:
envdir = os.path.join(treedir, 'devenv')



# envdir = treedir # qqq in the new version





retcode = _run_gofile(startdir, gopath)

envdir = os.path.join(treedir, 'devenv')
print 'new openmdao environment built in %s' % envdir

return (envdir, retcode)


def activate_and_test(envdir, testargs=()):
def activate_and_test(envdir, testargs=(), anaconda=False):
"""
Runs the test suite on an OpenMDAO virtual environment located
in the specified directory.
Returns the return code of the process that runs the test suite.
"""
if sys.platform.startswith('win'):
devbindir = 'Scripts'
command = 'activate.bat && openmdao test %s' % ' '.join(testargs)

if anaconda:
if sys.platform.startswith('win'):
command = 'activate openmdao-dev && openmdao test %s' % ' '.join(testargs)
else:
command = 'source activate openmdao-dev && openmdao test %s 2>&1 | tee ../test.out' \
% ' '.join(testargs)

# activate the environment and run tests
# devbinpath = os.path.join(envdir, devbindir)
os.chdir(envdir)
print "running tests from %s" % envdir
# print "running tests from %s" % devbinpath
env = os.environ.copy()
# for name in ['VIRTUAL_ENV', '_OLD_VIRTUAL_PATH', '_OLD_VIRTUAL_PROMPT']:
# if name in env:
# del env[name]
print "command = ", command
return _run_sub('test.out', command, env=env)
else:
devbindir = 'bin'
command = '. ./activate && openmdao test %s 2>&1 | tee ../../test.out' \
% ' '.join(testargs)

# activate the environment and run tests
devbinpath = os.path.join(envdir, devbindir)
os.chdir(devbinpath)
print "running tests from %s" % devbinpath
env = os.environ.copy()
for name in ['VIRTUAL_ENV', '_OLD_VIRTUAL_PATH', '_OLD_VIRTUAL_PROMPT']:
if name in env:
del env[name]
print "command = ", command
return _run_sub('test.out', command, env=env)
if sys.platform.startswith('win'):
devbindir = 'Scripts'
command = 'activate.bat && openmdao test %s' % ' '.join(testargs)
else:
devbindir = 'bin'
command = '. ./activate && openmdao test %s 2>&1 | tee ../../test.out' \
% ' '.join(testargs)

# activate the environment and run tests
devbinpath = os.path.join(envdir, devbindir)
os.chdir(devbinpath)
print "running tests from %s" % devbinpath
env = os.environ.copy()
for name in ['VIRTUAL_ENV', '_OLD_VIRTUAL_PATH', '_OLD_VIRTUAL_PROMPT']:
if name in env:
del env[name]
print "command = ", command
return _run_sub('test.out', command, env=env)


if __name__ == '__main__':
Expand All @@ -321,6 +408,7 @@ def activate_and_test(envdir, testargs=()):
parser.add_option("--testargs", action="store", type='string',
dest='testargs', default='',
help="args to pass to openmdao test")
parser.add_option("--anaconda", action="store_true", dest="anaconda", default=False)

# Handle quoting problem that happens on Windows (at least).
# (--testargs="-v --gui" gets split into: '--testargs="-v', '--gui', '"')
Expand All @@ -338,6 +426,6 @@ def activate_and_test(envdir, testargs=()):
(options, args) = parser.parse_args(args)

sys.exit(build_and_test(fname=options.fname, workdir=options.directory,
branch=options.branch,
branch=options.branch,anaconda=options.anaconda,
testargs=shlex.split(options.testargs)))

8 changes: 6 additions & 2 deletions openmdao.devtools/src/openmdao/devtools/remotetst.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ def _remote_build_and_test(fname=None, pyversion='python', keep=False,
remote_mkdir(remotedir)

if cfg and cfg.has_option(hostname, 'anaconda') :
locbldtstfile = os.path.join(os.path.dirname(__file__), 'loc_bld_tst_anaconda.py')
# locbldtstfile = os.path.join(os.path.dirname(__file__), 'loc_bld_tst_anaconda.py')
anaconda = cfg.getboolean(hostname, 'anaconda')
else:
locbldtstfile = os.path.join(os.path.dirname(__file__), 'loc_bld_tst.py')
# locbldtstfile = os.path.join(os.path.dirname(__file__), 'loc_bld_tst.py')
anaconda = False
locbldtstfile = os.path.join(os.path.dirname(__file__), 'loc_bld_tst.py')

pushfiles = [locbldtstfile]

Expand Down Expand Up @@ -70,6 +71,9 @@ def _remote_build_and_test(fname=None, pyversion='python', keep=False,
if testargs:
remoteargs.append('--testargs="%s"' % testargs)

if anaconda:
remoteargs.append('--anaconda' )

try:
result = push_and_run(pushfiles, runner=pyversion,
remotedir=remotedir,
Expand Down

0 comments on commit 8b4d196

Please sign in to comment.