Verified Commit 815ef3f8 authored by Loïc Dachary's avatar Loïc Dachary Committed by Loïc Dachary

enough: implement Hosts.ensure

parent 41e0a021
......@@ -42,6 +42,14 @@ class Hosts(object):
def missings(self, names):
return [name for name in names if name not in self.hosts]
def ensure(self, name):
if name not in self.hosts:
self.hosts[name] = {}
return True
return False
def create_or_update(self, name, ipv4, port):
if self.get_ip(name) != ipv4:
self.hosts[name] = {'ansible_host': ipv4, 'ansible_port': port}
......@@ -28,6 +28,18 @@ def test_hosts_create_delete(tmpdir):
assert h.hosts == {}
def test_hosts_ensure(tmpdir):
config_dir = str(tmpdir)
h = Hosts(config_dir)
host = 'HOST'
assert h.ensure(host) is True
assert h.ensure(host) is False
assert os.path.exists(f'{config_dir}/inventory/hosts.yml')
h = Hosts(config_dir)
assert h.ensure(host) is False
assert h.hosts[host] == {}
# DotEnough
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment