Commit 6083e0a6 authored by Loïc Dachary's avatar Loïc Dachary

Merge branch 'wip-host' into 'master'

enough: host create adds non existent host to all

Closes #238

See merge request !298
parents 41e0a021 3adb3758
Pipeline #1029 passed with stage
in 17 minutes and 43 seconds
......@@ -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] = {}
self.save()
return True
else:
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}
......
......@@ -83,6 +83,7 @@ class HostOpenStack(Host):
self.dotenough.ensure()
def create_or_update(self):
dotenough.Hosts(self.config_dir).ensure(self.args['name'])
h = openstack.Heat(self.config_dir, **self.args)
s = openstack.Stack(self.config_dir, h.get_stack_definition(self.args['name']), **self.args)
s.set_public_key(f'{self.config_dir}/infrastructure_key.pub')
......
......@@ -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
#
......
......@@ -340,3 +340,20 @@ def test_volume_resize(tmpdir):
o = OpenStack(settings.CONFIG_DIR)
# comment out the following line to re-use the content of the regions and save time
o.destroy_everything(None)
#
# Host
#
@pytest.mark.skipif('SKIP_OPENSTACK_INTEGRATION_TESTS' in os.environ,
reason='skip integration test')
def test_host_create_or_update(tmpdir, openstack_name):
try:
enough = create_enough(tmpdir, 'host')
enough.set_args(name='new-host')
info = enough.host.create_or_update()
assert 'ipv4' in info
finally:
o = OpenStack(settings.CONFIG_DIR)
# comment out the following line to re-use the content of the regions and save time
o.destroy_everything(None)
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