summaryrefslogtreecommitdiffstats
path: root/ipatests
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2013-12-11 19:33:30 +0100
committerPetr Viktorin <pviktori@redhat.com>2014-03-05 10:00:58 +0100
commit310d8254ed7659e39f61a7ff9f7eedc8a001be45 (patch)
treedf3463e0f0696a778281d79639b882fb7e3a7f80 /ipatests
parente1b73c18e3bcbd63a67636cdb3a64bb96eab1c52 (diff)
downloadfreeipa-310d8254ed7659e39f61a7ff9f7eedc8a001be45.tar.gz
freeipa-310d8254ed7659e39f61a7ff9f7eedc8a001be45.tar.xz
freeipa-310d8254ed7659e39f61a7ff9f7eedc8a001be45.zip
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>
Diffstat (limited to 'ipatests')
-rw-r--r--ipatests/test_integration/config.py45
-rw-r--r--ipatests/test_integration/host.py21
2 files changed, 35 insertions, 31 deletions
diff --git a/ipatests/test_integration/config.py b/ipatests/test_integration/config.py
index bf4d870bb..aa3fd5e3b 100644
--- a/ipatests/test_integration/config.py
+++ b/ipatests/test_integration/config.py
@@ -169,9 +169,10 @@ class Config(object):
env[setting.var_name] = str(value)
for domain in self.domains:
- env['DOMAIN%s' % domain._env] = domain.name
- env['RELM%s' % domain._env] = domain.realm
- env['BASEDN%s' % domain._env] = str(domain.basedn)
+ env_suffix = '_env%s' % (self.domains.index(domain) + 1)
+ env['DOMAIN%s' % env_suffix] = domain.name
+ env['RELM%s' % env_suffix] = domain.realm
+ env['BASEDN%s' % env_suffix] = str(domain.basedn)
for role in domain.roles:
hosts = domain.hosts_by_role(role)
@@ -180,13 +181,13 @@ class Config(object):
else TESTHOST_PREFIX)
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)
- 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)
- 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):
suffix = '%s%s' % (role.upper(), i)
@@ -195,9 +196,9 @@ class Config(object):
ext_hostname = host.external_hostname
env['%s%s%s' % (prefix, suffix,
- domain._env)] = host.hostname
- env['BEAKER%s%s' % (suffix, domain._env)] = ext_hostname
- env['BEAKER%s_IP%s' % (suffix, domain._env)] = host.ip
+ env_suffix)] = host.hostname
+ env['BEAKER%s%s' % (suffix, env_suffix)] = ext_hostname
+ env['BEAKER%s_IP%s' % (suffix, env_suffix)] = host.ip
if simple:
# Simple Vars for simplicity and backwards compatibility with older
@@ -272,16 +273,13 @@ def env_normalize(env):
class Domain(object):
"""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.type = domain_type
self.config = config
self.name = name
self.hosts = []
- self.index = index
-
- self._env = '_env%s' % index
self.realm = self.name.upper()
self.basedn = DN(*(('dc', p) for p in name.split('.')))
@@ -302,14 +300,14 @@ class Domain(object):
def extra_roles(self):
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:
yield role
# Extra roles are defined via env variables of form TESTHOST_key_envX
roles = set()
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('_')
role_name = '_'.join(variable_split[1:-1])
if (role_name and not role_name[-1].isdigit()):
@@ -328,20 +326,23 @@ class Domain(object):
else:
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('.')
- 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
- 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):
- host = BaseHost.from_env(env, self, hostname, role, index)
+ for host_index, hostname in enumerate(value.split(), start=1):
+ host = BaseHost.from_env(env, self, hostname, role,
+ host_index, index)
self.hosts.append(host)
if not self.hosts:
- raise ValueError('No hosts defined for %s' % self._env)
+ raise ValueError('No hosts defined for %s' % env_suffix)
return self
diff --git a/ipatests/test_integration/host.py b/ipatests/test_integration/host.py
index a35602a97..58f1fe4d9 100644
--- a/ipatests/test_integration/host.py
+++ b/ipatests/test_integration/host.py
@@ -32,11 +32,10 @@ class BaseHost(object):
"""Representation of a remote IPA host"""
transport_class = None
- def __init__(self, domain, hostname, role, index, ip=None,
+ def __init__(self, domain, hostname, role, ip=None,
external_hostname=None):
self.domain = domain
self.role = role
- self.index = index
shortname, dot, ext_domain = hostname.partition('.')
self.shortname = shortname
@@ -94,11 +93,11 @@ class BaseHost(object):
self.log_collectors.remove(collector)
@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' %
- (role.upper(), index, domain.index), None)
+ (role.upper(), index, domain_index), None)
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
# type, as we assume all Unix machines are in the Unix domain and
@@ -109,7 +108,7 @@ class BaseHost(object):
else:
cls = Host
- self = cls(domain, hostname, role, index, ip, external_hostname)
+ self = cls(domain, hostname, role, ip, external_hostname)
return self
@property
@@ -120,9 +119,12 @@ class BaseHost(object):
"""Return environment variables specific to this host"""
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()
if self.role != 'master':
- role += str(self.index)
+ role += str(index)
env['MYHOSTNAME'] = self.hostname
env['MYBEAKERHOSTNAME'] = self.external_hostname
@@ -130,8 +132,9 @@ class BaseHost(object):
prefix = ('' if self.role in self.domain.static_roles
else TESTHOST_PREFIX)
- env['MYROLE'] = '%s%s%s' % (prefix, role, self.domain._env)
- env['MYENV'] = str(self.domain.index)
+ env_suffix = '_env%s' % domain_index
+ env['MYROLE'] = '%s%s%s' % (prefix, role, env_suffix)
+ env['MYENV'] = str(domain_index)
return env