Skip to content

Commit

Permalink
Fix when FQDN is not resolved by socket.getfqdn(ip) (#62)
Browse files Browse the repository at this point in the history
* Set FQDN if host created qith FQDN

Sometime socket.getfqdn(ip) return IP and not the host FQDN so if Host
was created with FQDN we will use it as FQDN

* Set FQDN if host created qith FQDN

Sometime socket.getfqdn(ip) return IP and not the host FQDN so if Host
was created with FQDN we will use it as FQDN

* Set FQDN if host created qith FQDN

Sometime socket.getfqdn(ip) return IP and not the host FQDN so if Host
was created with FQDN we will use it as FQDN

* Set FQDN if host created qith FQDN

Sometime socket.getfqdn(ip) return IP and not the host FQDN so if Host
was created with FQDN we will use it as FQDN
  • Loading branch information
myakove authored and lukas-bednar committed Jun 7, 2016
1 parent da13aac commit ede0c96
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion rrmngmnt/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
"""
Expand Down
13 changes: 13 additions & 0 deletions tests/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit ede0c96

Please sign in to comment.