mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
test_integration.config: Do not store the index in Domain and Host objects
The index is a detail of the environment variable method of configuration, it should only be used there. Reviewed-By: Tomas Babej <tbabej@redhat.com>
This commit is contained in:
parent
e1b73c18e3
commit
310d8254ed
@ -169,9 +169,10 @@ class Config(object):
|
|||||||
env[setting.var_name] = str(value)
|
env[setting.var_name] = str(value)
|
||||||
|
|
||||||
for domain in self.domains:
|
for domain in self.domains:
|
||||||
env['DOMAIN%s' % domain._env] = domain.name
|
env_suffix = '_env%s' % (self.domains.index(domain) + 1)
|
||||||
env['RELM%s' % domain._env] = domain.realm
|
env['DOMAIN%s' % env_suffix] = domain.name
|
||||||
env['BASEDN%s' % domain._env] = str(domain.basedn)
|
env['RELM%s' % env_suffix] = domain.realm
|
||||||
|
env['BASEDN%s' % env_suffix] = str(domain.basedn)
|
||||||
|
|
||||||
for role in domain.roles:
|
for role in domain.roles:
|
||||||
hosts = domain.hosts_by_role(role)
|
hosts = domain.hosts_by_role(role)
|
||||||
@ -180,13 +181,13 @@ class Config(object):
|
|||||||
else TESTHOST_PREFIX)
|
else TESTHOST_PREFIX)
|
||||||
|
|
||||||
hostnames = ' '.join(h.hostname for h in hosts)
|
hostnames = ' '.join(h.hostname for h in hosts)
|
||||||
env['%s%s%s' % (prefix, role.upper(), domain._env)] = hostnames
|
env['%s%s%s' % (prefix, role.upper(), env_suffix)] = hostnames
|
||||||
|
|
||||||
ext_hostnames = ' '.join(h.external_hostname for h in hosts)
|
ext_hostnames = ' '.join(h.external_hostname for h in hosts)
|
||||||
env['BEAKER%s%s' % (role.upper(), domain._env)] = ext_hostnames
|
env['BEAKER%s%s' % (role.upper(), env_suffix)] = ext_hostnames
|
||||||
|
|
||||||
ips = ' '.join(h.ip for h in hosts)
|
ips = ' '.join(h.ip for h in hosts)
|
||||||
env['BEAKER%s_IP%s' % (role.upper(), domain._env)] = ips
|
env['BEAKER%s_IP%s' % (role.upper(), env_suffix)] = ips
|
||||||
|
|
||||||
for i, host in enumerate(hosts, start=1):
|
for i, host in enumerate(hosts, start=1):
|
||||||
suffix = '%s%s' % (role.upper(), i)
|
suffix = '%s%s' % (role.upper(), i)
|
||||||
@ -195,9 +196,9 @@ class Config(object):
|
|||||||
|
|
||||||
ext_hostname = host.external_hostname
|
ext_hostname = host.external_hostname
|
||||||
env['%s%s%s' % (prefix, suffix,
|
env['%s%s%s' % (prefix, suffix,
|
||||||
domain._env)] = host.hostname
|
env_suffix)] = host.hostname
|
||||||
env['BEAKER%s%s' % (suffix, domain._env)] = ext_hostname
|
env['BEAKER%s%s' % (suffix, env_suffix)] = ext_hostname
|
||||||
env['BEAKER%s_IP%s' % (suffix, domain._env)] = host.ip
|
env['BEAKER%s_IP%s' % (suffix, env_suffix)] = host.ip
|
||||||
|
|
||||||
if simple:
|
if simple:
|
||||||
# Simple Vars for simplicity and backwards compatibility with older
|
# Simple Vars for simplicity and backwards compatibility with older
|
||||||
@ -272,16 +273,13 @@ def env_normalize(env):
|
|||||||
|
|
||||||
class Domain(object):
|
class Domain(object):
|
||||||
"""Configuration for an IPA / AD domain"""
|
"""Configuration for an IPA / AD domain"""
|
||||||
def __init__(self, config, name, index, domain_type):
|
def __init__(self, config, name, domain_type):
|
||||||
self.log = log_mgr.get_logger(self)
|
self.log = log_mgr.get_logger(self)
|
||||||
self.type = domain_type
|
self.type = domain_type
|
||||||
|
|
||||||
self.config = config
|
self.config = config
|
||||||
self.name = name
|
self.name = name
|
||||||
self.hosts = []
|
self.hosts = []
|
||||||
self.index = index
|
|
||||||
|
|
||||||
self._env = '_env%s' % index
|
|
||||||
|
|
||||||
self.realm = self.name.upper()
|
self.realm = self.name.upper()
|
||||||
self.basedn = DN(*(('dc', p) for p in name.split('.')))
|
self.basedn = DN(*(('dc', p) for p in name.split('.')))
|
||||||
@ -302,14 +300,14 @@ class Domain(object):
|
|||||||
def extra_roles(self):
|
def extra_roles(self):
|
||||||
return [role for role in self.roles if role not in self.static_roles]
|
return [role for role in self.roles if role not in self.static_roles]
|
||||||
|
|
||||||
def _roles_from_env(self, env):
|
def _roles_from_env(self, env, env_suffix):
|
||||||
for role in self.static_roles:
|
for role in self.static_roles:
|
||||||
yield role
|
yield role
|
||||||
|
|
||||||
# Extra roles are defined via env variables of form TESTHOST_key_envX
|
# Extra roles are defined via env variables of form TESTHOST_key_envX
|
||||||
roles = set()
|
roles = set()
|
||||||
for var in sorted(env):
|
for var in sorted(env):
|
||||||
if var.startswith(TESTHOST_PREFIX) and var.endswith(self._env):
|
if var.startswith(TESTHOST_PREFIX) and var.endswith(env_suffix):
|
||||||
variable_split = var.split('_')
|
variable_split = var.split('_')
|
||||||
role_name = '_'.join(variable_split[1:-1])
|
role_name = '_'.join(variable_split[1:-1])
|
||||||
if (role_name and not role_name[-1].isdigit()):
|
if (role_name and not role_name[-1].isdigit()):
|
||||||
@ -328,20 +326,23 @@ class Domain(object):
|
|||||||
else:
|
else:
|
||||||
master_role = 'AD'
|
master_role = 'AD'
|
||||||
|
|
||||||
master_env = '%s_env%s' % (master_role, index)
|
env_suffix = '_env%s' % index
|
||||||
|
|
||||||
|
master_env = '%s%s' % (master_role, env_suffix)
|
||||||
hostname, dot, domain_name = env[master_env].partition('.')
|
hostname, dot, domain_name = env[master_env].partition('.')
|
||||||
self = cls(config, domain_name, index, domain_type)
|
self = cls(config, domain_name, domain_type)
|
||||||
|
|
||||||
for role in self._roles_from_env(env):
|
for role in self._roles_from_env(env, env_suffix):
|
||||||
prefix = '' if role in self.static_roles else TESTHOST_PREFIX
|
prefix = '' if role in self.static_roles else TESTHOST_PREFIX
|
||||||
value = env.get('%s%s%s' % (prefix, role.upper(), self._env), '')
|
value = env.get('%s%s%s' % (prefix, role.upper(), env_suffix), '')
|
||||||
|
|
||||||
for index, hostname in enumerate(value.split(), start=1):
|
for host_index, hostname in enumerate(value.split(), start=1):
|
||||||
host = BaseHost.from_env(env, self, hostname, role, index)
|
host = BaseHost.from_env(env, self, hostname, role,
|
||||||
|
host_index, index)
|
||||||
self.hosts.append(host)
|
self.hosts.append(host)
|
||||||
|
|
||||||
if not self.hosts:
|
if not self.hosts:
|
||||||
raise ValueError('No hosts defined for %s' % self._env)
|
raise ValueError('No hosts defined for %s' % env_suffix)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
@ -32,11 +32,10 @@ class BaseHost(object):
|
|||||||
"""Representation of a remote IPA host"""
|
"""Representation of a remote IPA host"""
|
||||||
transport_class = None
|
transport_class = None
|
||||||
|
|
||||||
def __init__(self, domain, hostname, role, index, ip=None,
|
def __init__(self, domain, hostname, role, ip=None,
|
||||||
external_hostname=None):
|
external_hostname=None):
|
||||||
self.domain = domain
|
self.domain = domain
|
||||||
self.role = role
|
self.role = role
|
||||||
self.index = index
|
|
||||||
|
|
||||||
shortname, dot, ext_domain = hostname.partition('.')
|
shortname, dot, ext_domain = hostname.partition('.')
|
||||||
self.shortname = shortname
|
self.shortname = shortname
|
||||||
@ -94,11 +93,11 @@ class BaseHost(object):
|
|||||||
self.log_collectors.remove(collector)
|
self.log_collectors.remove(collector)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_env(cls, env, domain, hostname, role, index):
|
def from_env(cls, env, domain, hostname, role, index, domain_index):
|
||||||
ip = env.get('BEAKER%s%s_IP_env%s' %
|
ip = env.get('BEAKER%s%s_IP_env%s' %
|
||||||
(role.upper(), index, domain.index), None)
|
(role.upper(), index, domain_index), None)
|
||||||
external_hostname = env.get(
|
external_hostname = env.get(
|
||||||
'BEAKER%s%s_env%s' % (role.upper(), index, domain.index), None)
|
'BEAKER%s%s_env%s' % (role.upper(), index, domain_index), None)
|
||||||
|
|
||||||
# We need to determine the type of the host, this depends on the domain
|
# We need to determine the type of the host, this depends on the domain
|
||||||
# type, as we assume all Unix machines are in the Unix domain and
|
# type, as we assume all Unix machines are in the Unix domain and
|
||||||
@ -109,7 +108,7 @@ class BaseHost(object):
|
|||||||
else:
|
else:
|
||||||
cls = Host
|
cls = Host
|
||||||
|
|
||||||
self = cls(domain, hostname, role, index, ip, external_hostname)
|
self = cls(domain, hostname, role, ip, external_hostname)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -120,9 +119,12 @@ class BaseHost(object):
|
|||||||
"""Return environment variables specific to this host"""
|
"""Return environment variables specific to this host"""
|
||||||
env = self.domain.to_env(**kwargs)
|
env = self.domain.to_env(**kwargs)
|
||||||
|
|
||||||
|
index = self.domain.hosts.index(self) + 1
|
||||||
|
domain_index = self.config.domains.index(self.domain) + 1
|
||||||
|
|
||||||
role = self.role.upper()
|
role = self.role.upper()
|
||||||
if self.role != 'master':
|
if self.role != 'master':
|
||||||
role += str(self.index)
|
role += str(index)
|
||||||
|
|
||||||
env['MYHOSTNAME'] = self.hostname
|
env['MYHOSTNAME'] = self.hostname
|
||||||
env['MYBEAKERHOSTNAME'] = self.external_hostname
|
env['MYBEAKERHOSTNAME'] = self.external_hostname
|
||||||
@ -130,8 +132,9 @@ class BaseHost(object):
|
|||||||
|
|
||||||
prefix = ('' if self.role in self.domain.static_roles
|
prefix = ('' if self.role in self.domain.static_roles
|
||||||
else TESTHOST_PREFIX)
|
else TESTHOST_PREFIX)
|
||||||
env['MYROLE'] = '%s%s%s' % (prefix, role, self.domain._env)
|
env_suffix = '_env%s' % domain_index
|
||||||
env['MYENV'] = str(self.domain.index)
|
env['MYROLE'] = '%s%s%s' % (prefix, role, env_suffix)
|
||||||
|
env['MYENV'] = str(domain_index)
|
||||||
|
|
||||||
return env
|
return env
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user