diff --git a/rrmngmnt/host.py b/rrmngmnt/host.py index 64d6e77..ac7feb0 100644 --- a/rrmngmnt/host.py +++ b/rrmngmnt/host.py @@ -59,7 +59,9 @@ def __init__(self, ip, service_provider=None): :type service_provider: class which implement SystemService interface """ super(Host, self).__init__() + self._fqdn = None if not netaddr.valid_ipv4(ip): + self._fqdn = ip ip = fqdn2ip(ip) self.ip = ip self.users = list() @@ -102,7 +104,7 @@ def add(self): @property def fqdn(self): - return socket.getfqdn(self.ip) + return socket.getfqdn(self.ip) if not self._fqdn else self._fqdn def add_power_manager(self, pm_type, **init_params): """ diff --git a/tests/test_host.py b/tests/test_host.py index 9e0116f..2d8975e 100644 --- a/tests/test_host.py +++ b/tests/test_host.py @@ -30,3 +30,16 @@ def test_executor_user(self): h.executor_user = user e = h.executor() e.user.name == 'lukas' + + +class TestHostFqdnIp(object): + + def test_host_ip(self): + h = Host('127.0.0.1') + assert h.ip == '127.0.0.1' + assert h.fqdn == 'localhost' + + def test_host_fqdn(self): + h = Host('localhost') + assert h.ip == '127.0.0.1' + assert h.fqdn == 'localhost'