mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Fix detection logic for api.env.in_tree
The logic to detect in-tree builds was broken and ipatests/conftest.py had hard-coded in_tree=True. IPA now considers an environment as in-tree when the parent directory of the ``ipalib`` package contains ``ipasetup.py.in``. This file is only present in source and never installed. API bootstrap() does not use ```self.site_packages in site.getsitepackages()`` because the function call can be expensive and would require path normalization, too. The function is also missing from venv site module. Fixes: https://pagure.io/freeipa/issue/8312 Signed-off-by: Christian Heimes <cheimes@redhat.com> Reviewed-By: Rob Crittenden <rcritten@redhat.com>
This commit is contained in:
@@ -457,11 +457,11 @@ class Env:
|
||||
# Merge in overrides:
|
||||
self._merge(**overrides)
|
||||
|
||||
# Determine if running in source tree:
|
||||
# Determine if running in source tree. The root directory of
|
||||
# IPA source directory contains ipasetup.py.in.
|
||||
if 'in_tree' not in self:
|
||||
self.in_tree = (
|
||||
self.bin == self.site_packages
|
||||
and path.isfile(path.join(self.bin, 'setup.py'))
|
||||
self.in_tree = os.path.isfile(
|
||||
os.path.join(self.site_packages, "ipasetup.py.in")
|
||||
)
|
||||
if self.in_tree and 'mode' not in self:
|
||||
self.mode = 'developer'
|
||||
|
||||
@@ -118,7 +118,7 @@ def pytest_addoption(parser):
|
||||
|
||||
def pytest_cmdline_main(config):
|
||||
kwargs = dict(
|
||||
context=u'cli', in_server=False, in_tree=True, fallback=False
|
||||
context=u'cli', in_server=False, fallback=False
|
||||
)
|
||||
if not os.path.isfile(os.path.expanduser('~/.ipa/default.conf')):
|
||||
# dummy domain/host for machines without ~/.ipa/default.conf
|
||||
|
||||
@@ -23,7 +23,9 @@ Test the `ipalib.config` module.
|
||||
"""
|
||||
|
||||
from os import path
|
||||
import site
|
||||
import sys
|
||||
|
||||
from ipatests.util import raises, delitem, ClassChecker
|
||||
from ipatests.util import getitem
|
||||
from ipatests.util import TempDir, TempHome
|
||||
@@ -447,23 +449,39 @@ class test_Env(ClassChecker):
|
||||
assert o.bin == path.dirname(path.abspath(sys.argv[0]))
|
||||
assert o.home == home.path
|
||||
assert o.dot_ipa == home.join('.ipa')
|
||||
assert o.in_tree is False
|
||||
assert o.context == 'default'
|
||||
if (
|
||||
# venv site module doesn't have getsitepackages()
|
||||
not hasattr(site, "getsitepackages")
|
||||
or o.site_packages in site.getsitepackages()
|
||||
):
|
||||
assert o.in_tree is False
|
||||
assert o.confdir == '/etc/ipa'
|
||||
assert o.conf == '/etc/ipa/default.conf'
|
||||
assert o.conf_default == o.conf
|
||||
else:
|
||||
assert o.in_tree is True
|
||||
assert o.confdir == o.dot_ipa
|
||||
assert o.conf == home.join('.ipa/default.conf')
|
||||
assert o.conf_default == o.conf
|
||||
|
||||
# Test overriding values created by _bootstrap()
|
||||
(o, home) = self.bootstrap(in_tree='True', context='server')
|
||||
assert o.in_tree is True
|
||||
assert o.context == 'server'
|
||||
assert o.conf == home.join('.ipa', 'server.conf')
|
||||
(o, home) = self.bootstrap(conf='/my/wacky/whatever.conf')
|
||||
|
||||
o, home = self.bootstrap(
|
||||
conf='/my/wacky/whatever.conf', in_tree=False
|
||||
)
|
||||
assert o.in_tree is False
|
||||
assert o.context == 'default'
|
||||
assert o.conf == '/my/wacky/whatever.conf'
|
||||
assert o.conf_default == '/etc/ipa/default.conf'
|
||||
(o, home) = self.bootstrap(conf_default='/my/wacky/default.conf')
|
||||
|
||||
o, home = self.bootstrap(
|
||||
conf_default='/my/wacky/default.conf', in_tree=False
|
||||
)
|
||||
assert o.in_tree is False
|
||||
assert o.context == 'default'
|
||||
assert o.conf == '/etc/ipa/default.conf'
|
||||
|
||||
Reference in New Issue
Block a user