Commit 56a2d7a4 authored by Jérome Perrin's avatar Jérome Perrin

slapos.cookbook test: use environment variables to pass eggs directories

slapos.cookbook recipe tests sometimes manipulate buildout eggs working set,
which will install packages from pypi. makeRecipe utilty function was
guessing buildout egg folders by parsing builout.cfg, but since a33844a2
(slapos-testing, slapos-sr-testing: Don't duplicate instance.cfg prologue
that is already provided by stack/nxdtest/instance.cfg, 2021-03-22),
these are defined in an extended profile, so this stopped working.

Instead of this fragile pattern, make the test software release pass the eggs
directories with an explicit environment variable.
parent 53f9c261
Pipeline #14511 failed with stage
in 0 seconds
"""Test helpers
"""
import os
import sys
import os.path
from zc.buildout.configparser import parse
import logging
def makeRecipe(recipe_class, options, name='test', slap_connection=None):
"""Instanciate a recipe of `recipe_class` with `options` with a buildout
mapping containing a python and an empty `slapos-connection` mapping, unless
provided as `slap_connection`.
If running tests in a buildout folder, the test recipe will reuse the
`eggs-directory` and `develop-eggs-directory` from this buildout so that the
This function expects the test suite to have set SLAPOS_TEST_EGGS_DIRECTORY
and SLAPOS_TEST_DEVELOP_EGGS_DIRECTORY environment variables, so that the
test recipe does not need to install eggs again when using working set.
To prevent test accidentally writing to the buildout's eggs repositories, we
set `newest` to false and `offline` to true in this case.
"""
buildout = {
'buildout': {
......@@ -39,39 +35,12 @@ def makeRecipe(recipe_class, options, name='test', slap_connection=None):
if slap_connection is not None:
buildout['slap-connection'] = slap_connection
# are we in buildout folder ?
# in SLAPOS-EGG-TEST the usual layout is
# ${buildout:directory}/parts/slapos-repository/slapos/test/utils.py in instance buildout, so try
# to find a buildout.cfg relative to this file.
# What can also happens is that this repository is used from software folder, this is the case in
# SLAPOS-SR-TEST. In this case, ${buildout:eggs} is not set in buildout.cfg and we can only assume
# it will be the standards eggs and develop-eggs folders.
buildout['buildout']['eggs-directory'] = os.environ['SLAPOS_TEST_EGGS_DIRECTORY']
buildout['buildout']['develop-eggs-directory'] = os.environ['SLAPOS_TEST_DEVELOP_EGGS_DIRECTORY']
# {BASE_DIRECTORY}/parts/slapos-repository/slapos/test/utils.py
base_directory = os.path.normpath(os.path.join(os.path.dirname(__file__), '..', '..', '..', '..'))
buildout_cfg = os.path.join(base_directory, 'buildout.cfg')
if os.path.exists(buildout_cfg):
with open(buildout_cfg) as f:
parsed_cfg = parse(f, buildout_cfg)
# When buildout_cfg is an instance buildout (like in SLAPOS-EGG-TEST),
# there's a ${buildout:eggs-directory} we can use.
# When buildout_cfg is a software buildout, we can only guess the
# standard eggs directories.
eggs_directory = parsed_cfg['buildout'].get(
'eggs-directory', os.path.join(base_directory, 'eggs'))
develop_eggs_directory = parsed_cfg['buildout'].get(
'develop-eggs-directory', os.path.join(base_directory, 'develop-eggs'))
logging.getLogger(__name__).info(
'Using eggs-directory (%s) and develop-eggs-directory (%s) from buildout at %s',
eggs_directory,
develop_eggs_directory,
buildout_cfg)
buildout['buildout']['eggs-directory'] = eggs_directory
buildout['buildout']['develop-eggs-directory'] = develop_eggs_directory
# Prevent test from accidentally writing to the buildout's eggs
buildout['buildout']['newest'] = False
buildout['buildout']['offline'] = True
return recipe_class(buildout=buildout, name=name, options=options)
......@@ -15,4 +15,4 @@
[template]
filename = instance.cfg
md5sum = a6091981a78cb2b10a97e431adc7615c
md5sum = 2a82b7d5163d042e85b14a645707a093
......@@ -80,6 +80,8 @@ template = inline:
export PATH=${coreutils:location}/bin:${curl:location}/bin:${openssl:location}/bin:${git:location}/bin:${libxslt:location}/bin:${socat:location}/bin:${lmsensors:location}/bin:${rsync:location}/bin/:${buildout:bin-directory}:$PATH
export SLAPOS_TEST_IPV4=$${slap-configuration:ipv4-random}
export SLAPOS_TEST_IPV6=$${slap-configuration:ipv6-random}
export SLAPOS_TEST_EGGS_DIRECTORY=$${buildout:eggs-directory}
export SLAPOS_TEST_DEVELOP_EGGS_DIRECTORY=$${buildout:develop-eggs-directory}
[slapos-test-runner-dot-nxdtest]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment