From 74a50d0ac7486896ea461dbd1249a23e08ab75f6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Wed, 28 Aug 2019 09:04:24 +0200
Subject: [PATCH] test.utils.makeRecipe: support running from software folder

Now that we also run slapos.cookbook tests from SLAPOS-SR-TEST we cannot
simply examine buildout.cfg, because unlike SLAPOS-EGG-TEST this
repository is now checked out in parts of the software folder, not the
instance folder.
So that trick of looking up the egg directories in buildout does not
work, because this is a software buildout.cfg ... instead, we assume
that the standard eggs and develop-eggs directories are used.
---
 slapos/test/utils.py | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/slapos/test/utils.py b/slapos/test/utils.py
index d605bab9d..da156b3aa 100644
--- a/slapos/test/utils.py
+++ b/slapos/test/utils.py
@@ -40,15 +40,30 @@ def makeRecipe(recipe_class, options, name='test', slap_connection=None):
     buildout['slap-connection'] = slap_connection
 
   # are we in buildout folder ?
-  # the usual layout is
-  # ${buildout:directory}/parts/slapos-repository/slapos/test/utils.py , so try
-  # to find a buildout relative to this file.
-  buildout_cfg = os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', 'buildout.cfg')
+  # 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.
+
+  # {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):
     parser = ConfigParser()
     parser.readfp(open(buildout_cfg))
-    eggs_directory = parser.get('buildout', 'eggs-directory')
-    develop_eggs_directory = parser.get('buildout', 'develop-eggs-directory')
+    eggs_directory = parser.get(
+        'buildout',
+        'eggs-directory',
+        # default, for the case when buildout_cfg is a software buildout
+        # like with SLAPOS-SR-TEST.
+        vars={'eggs-directory': os.path.join(base_directory, 'eggs')})
+    develop_eggs_directory = parser.get(
+        'buildout',
+        'develop-eggs-directory',
+        vars={'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,
-- 
2.30.9