Make the tox py27 environment prepare a venv of all the things

This will make sure that anvil prepare works and that anvils
functionalities continues to work at least at a basic level
under ubuntu (which is what the gate runs).

Change-Id: I1bdd387a6a75b37cecf5e8c63e4d86a34e3cd8ff
This commit is contained in:
Joshua Harlow 2015-07-08 23:48:43 -07:00
parent bbbc83d568
commit 0e2ad319b5
7 changed files with 54 additions and 33 deletions

View File

@ -94,7 +94,17 @@ def run(args):
# !!
# Ensure the anvil dirs are there if others are about to use it...
ensure_anvil_dirs(root_dir)
if not sh.isdir(root_dir):
LOG.info("Creating anvil root directory at path: %s", root_dir)
sh.mkdir(root_dir)
try:
for d in ANVIL_DIRS:
if sh.isdir(d):
continue
LOG.info("Creating anvil auxiliary directory at path: %s", d)
sh.mkdir(d)
except OSError as e:
LOG.warn("Failed ensuring auxiliary directories due to %s", e)
# Load the origins...
origins = _origins.load(args['origins_fn'],
@ -159,32 +169,21 @@ def load_previous_settings():
return settings_prev
def ensure_anvil_dirs(root_dir):
wanted_dirs = list(ANVIL_DIRS)
if root_dir and root_dir not in wanted_dirs:
wanted_dirs.append(root_dir)
for d in wanted_dirs:
if sh.isdir(d):
continue
LOG.info("Creating anvil directory at path: %s", d)
sh.mkdir(d)
def store_current_settings(c_settings):
# Remove certain keys that just shouldn't be saved
to_save = dict(c_settings)
for k in ['action', 'verbose']:
if k in c_settings:
to_save.pop(k, None)
buf = six.StringIO()
buf.write("# Anvil last used settings\n")
buf.write(utils.add_header(SETTINGS_FILE,
utils.prettify_yaml(to_save),
adjusted=sh.isfile(SETTINGS_FILE)))
try:
# Remove certain keys that just shouldn't be saved
to_save = dict(c_settings)
for k in ['action', 'verbose']:
if k in c_settings:
to_save.pop(k, None)
buf = six.StringIO()
buf.write("# Anvil last used settings\n")
buf.write(utils.add_header(SETTINGS_FILE,
utils.prettify_yaml(to_save),
adjusted=sh.isfile(SETTINGS_FILE)))
sh.write_file(SETTINGS_FILE, buf.getvalue())
except Exception as e:
LOG.debug("Failed writing to %s due to %s", SETTINGS_FILE, e)
except OSError as e:
LOG.warn("Failed writing to %s due to %s", SETTINGS_FILE, e)
def ensure_perms():
@ -209,7 +208,7 @@ def main():
log_level = logging.INFO
if args['verbose']:
log_level = logging.DEBUG
logging.setupLogging(log_level)
logging.setupLogging(log_level, tee_filename=args['tee_file'])
LOG.debug("Log level is: %s" % (logging.getLevelName(log_level)))
def print_exc(exc):

View File

@ -102,18 +102,19 @@ class TermAdapter(logging.LoggerAdapter):
def setupLogging(log_level,
format='%(levelname)s: @%(name)s : %(message)s',
log_name='/var/log/anvil.log'):
term_format='%(levelname)s: @%(name)s : %(message)s',
tee_filename='/var/log/anvil.log',
tee_format='%(asctime)s : %(levelname)s: @%(name)s : %(message)s'):
root_logger = getLogger().logger
console_formatter = TermFormatter(format)
console_formatter = TermFormatter(term_format)
console_logger = StreamHandler(sys.stdout)
console_logger.setLevel(log_level)
console_logger.setFormatter(console_formatter)
root_logger.addHandler(console_logger)
file_formatter = logging.Formatter('%(asctime)s : ' + format)
file_logger = FileHandler(log_name)
file_formatter = logging.Formatter(tee_format)
file_logger = FileHandler(tee_filename)
file_logger.setFormatter(file_formatter)
file_logger.setLevel(DEBUG)
root_logger.addHandler(file_logger)

View File

@ -160,6 +160,13 @@ def parse(previous_settings=None):
metavar="DIR",
default=_get_default_dir(),
help=("empty root DIR or DIR with existing components (default: %default)"))
base_group.add_option("--tee-file",
action="store",
type="string",
dest="tee_file",
metavar="FILE",
default='/var/log/anvil.log',
help=("location to store tee of output (default: %default)"))
parser.add_option_group(base_group)
build_group = OptionGroup(parser, "Build specific options")
@ -194,6 +201,7 @@ def parse(previous_settings=None):
values['origins_fn'] = options.origins_fn
values['verbose'] = options.verbose
values['usr_only'] = options.usr_only
values['tee_file'] = options.tee_file
if options.origins_patch_fn:
with open(options.origins_patch_fn) as fp:
values['origins_patch'] = json.load(fp)

View File

@ -34,5 +34,5 @@ class TestLog(test.TestCase):
super(TestLog, self).tearDown()
def test_logger_has_two_handlers(self):
log.setupLogging(log.INFO, log_name=self.log_name)
log.setupLogging(log.INFO, tee_filename=self.log_name)
self.assertEqual(len(self.test_logger.handlers), 2)

3
smithy
View File

@ -236,6 +236,9 @@ puke()
needs_bootstrap()
{
# Checks if we need to perform the bootstrap phase.
if [ "$SKIP_BOOTSTRAP" == "yes" ]; then
return 1
fi
if [ "$BOOTSTRAP" == "true" ]; then
return 0
fi

View File

@ -6,7 +6,7 @@ MIN_RELEASE=14.04
STEPS="apt_packages virtualenv"
# Ensure anvil python gets access to this...
VENV_CMD="virtualenv-2.7"
VENV_CMD="virtualenv"
export VENV_CMD
REQUIRES='

12
tox.ini
View File

@ -12,11 +12,21 @@ setenv = VIRTUAL_ENV={envdir}
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands = nosetests {posargs}
{toxinidir}/tools/verify_yaml
[tox:jenkins]
downloadcache = ~/cache/pip
[testenv:py27]
setenv = VIRTUAL_ENV={envdir}
SKIP_BOOTSTRAP=yes
PYTHONHASHSEED=0
commands = nosetests {posargs}
{toxinidir}/tools/verify_yaml
{toxinidir}/smithy -a prepare \
-p {toxinidir}/conf/personas/in-a-box/venv-all.yaml \
-o {toxinidir}/conf/origins/kilo-venv-2015.1.0.yaml \
--tee-file {toxinidir}/tee.out -v -j1
[testenv:pep8]
commands = flake8 {posargs}