summaryrefslogtreecommitdiffstats
path: root/ipatests/test_integration/host.py
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2013-12-11 19:36:46 +0100
committerPetr Viktorin <pviktori@redhat.com>2014-03-05 10:00:58 +0100
commitef0264f75fb55e08ef4d54c7fe5936123e35ef27 (patch)
tree80c114c11b9e1be60fe0813e7852732479390d71 /ipatests/test_integration/host.py
parent310d8254ed7659e39f61a7ff9f7eedc8a001be45 (diff)
downloadfreeipa-ef0264f75fb55e08ef4d54c7fe5936123e35ef27.tar.gz
freeipa-ef0264f75fb55e08ef4d54c7fe5936123e35ef27.tar.xz
freeipa-ef0264f75fb55e08ef4d54c7fe5936123e35ef27.zip
test_integration.config: Load/store from/to dicts
Part of the work for: https://fedorahosted.org/freeipa/ticket/3938 Reviewed-By: Tomas Babej <tbabej@redhat.com>
Diffstat (limited to 'ipatests/test_integration/host.py')
-rw-r--r--ipatests/test_integration/host.py37
1 files changed, 35 insertions, 2 deletions
diff --git a/ipatests/test_integration/host.py b/ipatests/test_integration/host.py
index 58f1fe4d9..f78933c0c 100644
--- a/ipatests/test_integration/host.py
+++ b/ipatests/test_integration/host.py
@@ -26,6 +26,8 @@ from ipapython.ipaldap import IPAdmin
from ipapython import ipautil
from ipapython.ipa_log_manager import log_mgr
from ipatests.test_integration import transport
+from ipatests.test_integration.util import check_config_dict_empty
+from ipatests.test_integration.util import TESTHOST_PREFIX
class BaseHost(object):
@@ -99,6 +101,10 @@ class BaseHost(object):
external_hostname = env.get(
'BEAKER%s%s_env%s' % (role.upper(), index, domain_index), None)
+ return cls._make_host(domain, hostname, role, ip, external_hostname)
+
+ @staticmethod
+ def _make_host(domain, hostname, role, ip, external_hostname):
# 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
# all Windows machine in a AD domain
@@ -108,8 +114,35 @@ class BaseHost(object):
else:
cls = Host
- self = cls(domain, hostname, role, ip, external_hostname)
- return self
+ return cls(domain, hostname, role, ip, external_hostname)
+
+ @classmethod
+ def from_dict(cls, dct, domain):
+ if isinstance(dct, basestring):
+ dct = {'name': dct}
+ try:
+ role = dct.pop('role').lower()
+ except KeyError:
+ role = domain.static_roles[0]
+
+ hostname = dct.pop('name')
+ if '.' not in hostname:
+ hostname = '.'.join((hostname, domain.name))
+
+ ip = dct.pop('ip', None)
+ external_hostname = dct.pop('external_hostname', None)
+
+ check_config_dict_empty(dct, 'host %s' % hostname)
+
+ return cls._make_host(domain, hostname, role, ip, external_hostname)
+
+ def to_dict(self):
+ return {
+ 'name': self.hostname,
+ 'ip': self.ip,
+ 'role': self.role,
+ 'external_hostname': self.external_hostname,
+ }
@property
def config(self):