2013-05-24 12:55:21 -05:00
|
|
|
# Authors:
|
|
|
|
# Petr Viktorin <pviktori@redhat.com>
|
2013-09-04 07:12:28 -05:00
|
|
|
# Tomas Babej <tbabej@redhat.com>
|
2013-05-24 12:55:21 -05:00
|
|
|
#
|
|
|
|
# Copyright (C) 2013 Red Hat
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
"""Utilities for configuration of multi-master tests"""
|
|
|
|
|
2017-05-25 05:42:54 -05:00
|
|
|
import logging
|
2013-05-24 12:55:21 -05:00
|
|
|
import random
|
|
|
|
|
2018-07-10 07:18:25 -05:00
|
|
|
import pytest
|
2014-11-13 09:23:56 -06:00
|
|
|
import pytest_multihost.config
|
|
|
|
|
2013-05-24 12:55:21 -05:00
|
|
|
from ipapython.dn import DN
|
2015-11-02 04:51:34 -06:00
|
|
|
from ipalib.constants import MAX_DOMAIN_LEVEL
|
2013-12-11 12:06:31 -06:00
|
|
|
|
|
|
|
|
2014-11-13 09:23:56 -06:00
|
|
|
class Config(pytest_multihost.config.Config):
|
|
|
|
extra_init_args = {
|
|
|
|
'admin_name',
|
|
|
|
'admin_password',
|
|
|
|
'dirman_dn',
|
|
|
|
'dirman_password',
|
|
|
|
'nis_domain',
|
|
|
|
'ntp_server',
|
|
|
|
'ad_admin_name',
|
|
|
|
'ad_admin_password',
|
|
|
|
'dns_forwarder',
|
2015-11-02 04:51:34 -06:00
|
|
|
'domain_level',
|
2017-05-22 11:33:49 -05:00
|
|
|
'log_journal_since',
|
2019-11-13 09:29:51 -06:00
|
|
|
'fips_mode',
|
2014-11-13 09:23:56 -06:00
|
|
|
}
|
2013-12-11 12:06:31 -06:00
|
|
|
|
2013-05-24 12:55:21 -05:00
|
|
|
def __init__(self, **kwargs):
|
2014-11-13 09:23:56 -06:00
|
|
|
kwargs.setdefault('test_dir', '/root/ipatests')
|
|
|
|
super(Config, self).__init__(**kwargs)
|
2013-05-24 12:55:21 -05:00
|
|
|
|
|
|
|
admin_password = kwargs.get('admin_password') or 'Secret123'
|
|
|
|
|
|
|
|
self.admin_name = kwargs.get('admin_name') or 'admin'
|
|
|
|
self.admin_password = admin_password
|
|
|
|
self.dirman_dn = DN(kwargs.get('dirman_dn') or 'cn=Directory Manager')
|
|
|
|
self.dirman_password = kwargs.get('dirman_password') or admin_password
|
|
|
|
self.nis_domain = kwargs.get('nis_domain') or 'ipatest'
|
2014-01-06 03:38:24 -06:00
|
|
|
self.ntp_server = str(kwargs.get('ntp_server') or (
|
|
|
|
'%s.pool.ntp.org' % random.randint(0, 3)))
|
2013-09-04 07:12:28 -05:00
|
|
|
self.ad_admin_name = kwargs.get('ad_admin_name') or 'Administrator'
|
|
|
|
self.ad_admin_password = kwargs.get('ad_admin_password') or 'Secret123'
|
2015-11-02 04:51:34 -06:00
|
|
|
self.domain_level = kwargs.get('domain_level', MAX_DOMAIN_LEVEL)
|
2014-11-13 09:23:56 -06:00
|
|
|
# 8.8.8.8 is probably the best-known public DNS
|
|
|
|
self.dns_forwarder = kwargs.get('dns_forwarder') or '8.8.8.8'
|
|
|
|
self.debug = False
|
2017-05-22 11:33:49 -05:00
|
|
|
self.log_journal_since = kwargs.get('log_journal_since') or '-1h'
|
2015-11-02 04:51:34 -06:00
|
|
|
if self.domain_level is None:
|
|
|
|
self.domain_level = MAX_DOMAIN_LEVEL
|
2019-11-13 09:29:51 -06:00
|
|
|
self.fips_mode = kwargs.get('fips_mode', False)
|
2014-11-13 09:23:56 -06:00
|
|
|
|
|
|
|
def get_domain_class(self):
|
|
|
|
return Domain
|
2013-06-05 08:41:37 -05:00
|
|
|
|
2014-11-13 09:23:56 -06:00
|
|
|
def get_logger(self, name):
|
2017-11-06 06:06:33 -06:00
|
|
|
logger = logging.getLogger(name)
|
|
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
return logger
|
2013-05-24 12:55:21 -05:00
|
|
|
|
2013-09-04 07:12:28 -05:00
|
|
|
@property
|
|
|
|
def ad_domains(self):
|
2019-03-27 11:24:26 -05:00
|
|
|
return [d for d in self.domains if d.is_ad_type]
|
2013-09-04 07:12:28 -05:00
|
|
|
|
2014-11-13 09:23:56 -06:00
|
|
|
def get_all_hosts(self):
|
|
|
|
for domain in self.domains:
|
|
|
|
for host in domain.hosts:
|
|
|
|
yield host
|
2013-12-11 12:36:46 -06:00
|
|
|
|
|
|
|
def to_dict(self):
|
2014-11-13 09:23:56 -06:00
|
|
|
extra_args = self.extra_init_args - {'dirman_dn'}
|
|
|
|
result = super(Config, self).to_dict(extra_args)
|
|
|
|
result['dirman_dn'] = str(self.dirman_dn)
|
|
|
|
return result
|
2013-12-11 12:36:46 -06:00
|
|
|
|
2013-05-24 12:55:21 -05:00
|
|
|
@classmethod
|
|
|
|
def from_env(cls, env):
|
2018-08-02 06:45:19 -05:00
|
|
|
from ipatests.pytest_ipa.integration.env_config import config_from_env
|
2014-11-13 09:23:56 -06:00
|
|
|
return config_from_env(env)
|
2013-05-24 12:55:21 -05:00
|
|
|
|
2014-11-13 09:23:56 -06:00
|
|
|
def to_env(self, **kwargs):
|
2018-08-02 06:45:19 -05:00
|
|
|
from ipatests.pytest_ipa.integration.env_config import config_to_env
|
2014-11-13 09:23:56 -06:00
|
|
|
return config_to_env(self, **kwargs)
|
|
|
|
|
2018-07-10 07:18:25 -05:00
|
|
|
def filter(self, descriptions):
|
|
|
|
"""Destructively filters hosts and orders domains to fit description
|
|
|
|
|
|
|
|
By default make_multihost_fixture() skips a test case, when filter()
|
|
|
|
returns a FilterError. Let's turn FilterError into a fatal error
|
|
|
|
instead.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
super(Config, self).filter(descriptions)
|
|
|
|
except pytest_multihost.config.FilterError as e:
|
|
|
|
pytest.fail(str(e))
|
|
|
|
|
2014-11-13 09:23:56 -06:00
|
|
|
|
|
|
|
class Domain(pytest_multihost.config.Domain):
|
2013-09-04 07:24:41 -05:00
|
|
|
"""Configuration for an IPA / AD domain"""
|
2013-12-11 12:33:30 -06:00
|
|
|
def __init__(self, config, name, domain_type):
|
2014-01-06 03:38:24 -06:00
|
|
|
self.type = str(domain_type)
|
2013-05-24 12:55:21 -05:00
|
|
|
|
|
|
|
self.config = config
|
2014-01-06 03:38:24 -06:00
|
|
|
self.name = str(name)
|
2013-05-24 12:55:21 -05:00
|
|
|
self.hosts = []
|
|
|
|
|
2019-03-27 11:24:26 -05:00
|
|
|
assert self.is_ipa_type or self.is_ad_type
|
2013-05-24 12:55:21 -05:00
|
|
|
self.realm = self.name.upper()
|
|
|
|
self.basedn = DN(*(('dc', p) for p in name.split('.')))
|
|
|
|
|
2019-03-27 11:24:26 -05:00
|
|
|
@property
|
|
|
|
def is_ipa_type(self):
|
|
|
|
return self.type == 'IPA'
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_ad_type(self):
|
|
|
|
return self.type == 'AD' or self.type.startswith('AD_')
|
|
|
|
|
2013-10-16 06:54:26 -05:00
|
|
|
@property
|
|
|
|
def static_roles(self):
|
|
|
|
# Specific roles for each domain type are hardcoded
|
|
|
|
if self.type == 'IPA':
|
2013-12-11 11:31:10 -06:00
|
|
|
return ('master', 'replica', 'client', 'other')
|
2014-11-13 09:23:56 -06:00
|
|
|
elif self.type == 'AD':
|
2013-10-16 06:54:26 -05:00
|
|
|
return ('ad',)
|
2019-03-27 11:24:26 -05:00
|
|
|
elif self.type == 'AD_SUBDOMAIN':
|
|
|
|
return ('ad_subdomain',)
|
|
|
|
elif self.type == 'AD_TREEDOMAIN':
|
|
|
|
return ('ad_treedomain',)
|
2013-05-24 12:55:21 -05:00
|
|
|
else:
|
2014-11-13 09:23:56 -06:00
|
|
|
raise LookupError(self.type)
|
2013-09-04 07:24:41 -05:00
|
|
|
|
2014-11-13 09:23:56 -06:00
|
|
|
def get_host_class(self, host_dict):
|
2018-08-02 06:45:19 -05:00
|
|
|
from ipatests.pytest_ipa.integration.host import Host, WinHost
|
2013-05-24 12:55:21 -05:00
|
|
|
|
2019-03-27 11:24:26 -05:00
|
|
|
if self.is_ipa_type:
|
2014-11-13 09:23:56 -06:00
|
|
|
return Host
|
2019-03-27 11:24:26 -05:00
|
|
|
elif self.is_ad_type:
|
2014-11-13 09:23:56 -06:00
|
|
|
return WinHost
|
2013-10-16 06:54:26 -05:00
|
|
|
else:
|
2014-11-13 09:23:56 -06:00
|
|
|
raise LookupError(self.type)
|
2013-10-16 06:54:26 -05:00
|
|
|
|
2013-05-24 12:55:21 -05:00
|
|
|
@property
|
|
|
|
def master(self):
|
2013-10-16 06:54:26 -05:00
|
|
|
return self.host_by_role('master')
|
2013-05-24 12:55:21 -05:00
|
|
|
|
|
|
|
@property
|
|
|
|
def masters(self):
|
2013-10-16 06:54:26 -05:00
|
|
|
return self.hosts_by_role('master')
|
2013-05-24 12:55:21 -05:00
|
|
|
|
|
|
|
@property
|
|
|
|
def replicas(self):
|
2013-10-16 06:54:26 -05:00
|
|
|
return self.hosts_by_role('replica')
|
2013-05-24 12:55:21 -05:00
|
|
|
|
|
|
|
@property
|
|
|
|
def clients(self):
|
2013-10-16 06:54:26 -05:00
|
|
|
return self.hosts_by_role('client')
|
2013-05-24 12:55:21 -05:00
|
|
|
|
2013-09-04 07:24:41 -05:00
|
|
|
@property
|
|
|
|
def ads(self):
|
2013-10-16 06:54:26 -05:00
|
|
|
return self.hosts_by_role('ad')
|
2013-09-04 07:24:41 -05:00
|
|
|
|
2013-05-24 12:55:21 -05:00
|
|
|
@property
|
|
|
|
def other_hosts(self):
|
2013-10-16 06:54:26 -05:00
|
|
|
return self.hosts_by_role('other')
|
2013-05-24 12:55:21 -05:00
|
|
|
|
2014-11-13 09:23:56 -06:00
|
|
|
@classmethod
|
|
|
|
def from_env(cls, env, config, index, domain_type):
|
2018-08-02 06:45:19 -05:00
|
|
|
from ipatests.pytest_ipa.integration.env_config import domain_from_env
|
2014-11-13 09:23:56 -06:00
|
|
|
return domain_from_env(env, config, index, domain_type)
|
2013-05-24 12:55:21 -05:00
|
|
|
|
2014-11-13 09:23:56 -06:00
|
|
|
def to_env(self, **kwargs):
|
2018-08-02 06:45:19 -05:00
|
|
|
from ipatests.pytest_ipa.integration.env_config import domain_to_env
|
2014-11-13 09:23:56 -06:00
|
|
|
return domain_to_env(self, **kwargs)
|