Browse Source

enough: enable --driver libvirt

keep-around/36777ef767c48ca2458641418d4c3cfa6f2226df
Loïc Dachary 8 months ago
parent
commit
36777ef767
Signed by: dachary GPG Key ID: 992D23B392F9E4F2
  1. 22
      docs/release-notes.rst
  2. 1
      enough/common/data/base.dockerfile
  3. 10
      enough/common/dotenough.py
  4. 4
      enough/common/options.py
  5. 2
      enough/internal/data/install.sh
  6. 2
      inventory/group_vars/all/infrastructure.yml
  7. 2
      tests/enough/common/test_common_options.py
  8. 13
      tests/enough/common/test_dotenough.py
  9. 2
      tests/enough/internal/test_internal_install.py
  10. 1
      tests/tox.dockerfile

22
docs/release-notes.rst

@ -1,6 +1,28 @@
Release Notes
=============
2.1.16
------
* Hosts can now be provisionned using libvirt instead of OpenStack. For instance::
$ enough --domain example.com host create --driver libvirt bind
bind: building image
bind: preparing image
bind: creating host
bind: waiting for ipv4 to be allocated
bind: waiting for 10.23.10.164:22 to come up
Check if SSH is available on 10.23.10.164:22
bind: host is ready
+-------+--------------+
| Field | Value |
+-------+--------------+
| name | bind |
| user | debian |
| port | 22 |
| ip | 10.23.10.164 |
2.1.15
------

1
enough/common/data/base.dockerfile

@ -32,6 +32,7 @@ RUN groupadd --gid $KVM_GID kvm
# kvm will not be considered to be a system group.
#
RUN mv /etc/adduser.conf.backup /etc/adduser.conf
RUN apt-get install --quiet -y libguestfs-tools python-libvirt python-lxml pkg-config libvirt-dev virtinst
RUN if test $USER_NAME != root ; then useradd --no-create-home --home-dir /tmp --uid $USER_ID --groups $DOCKER_GID,$LIBVIRT_GID,$KVM_GID $USER_NAME && echo "$USER_NAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers ; fi
ENV REQUESTS_CA_BUNDLE /etc/ssl/certs

10
enough/common/dotenough.py

@ -108,6 +108,12 @@ class DotEnough(object):
production_domain: {self.domain}
"""))
if not os.path.exists(f'{d}/infrastructure.yml'):
open(f'{d}/infrastructure.yml', 'w').write(textwrap.dedent(f"""\
---
infrastructure_driver: {self.infrastructure_driver}
"""))
if not os.path.exists(f'{d}/certificate.yml'):
self.set_certificate(certificate_authority)
@ -139,6 +145,8 @@ class DotEnough(object):
class DotEnoughLibvirt(DotEnough):
infrastructure_driver = "libvirt"
def __init__(self, config_dir, domain):
super().__init__(config_dir, domain)
@ -153,6 +161,8 @@ class DotEnoughOpenStackUnknownProvider(Exception):
class DotEnoughOpenStack(DotEnough):
infrastructure_driver = "openstack"
def __init__(self, config_dir, domain):
super().__init__(config_dir, domain)
self.clouds_file = f'{self.config_dir}/inventory/group_vars/all/clouds.yml'

4
enough/common/options.py

@ -1,5 +1,7 @@
def set_options(parser):
parser.add_argument('--driver', default='openstack')
parser.add_argument('--driver',
default='openstack',
choices=['libvirt', 'openstack'])
parser.add_argument('--inventory', action='append')
o = parser.add_argument_group(title='OpenStack',
description='Only when --driver=openstack')

2
enough/internal/data/install.sh

@ -2,6 +2,8 @@
{{ this.tty }} \
-v $HOME/.enough:/root/.enough \
-v /etc/ssl/certs:/etc/ssl/certs:ro \
-v /run/libvirt/libvirt-sock:/run/libvirt/libvirt-sock \
-v /var/lib/libvirt/images/enough:/var/lib/libvirt/images/enough \
-v /usr/local/share/ca-certificates:/usr/local/share/ca-certificates:ro \
-v /var/run/docker.sock:/var/run/docker.sock \
--entrypoint enough \

2
inventory/group_vars/all/infrastructure.yml

@ -3,4 +3,4 @@
# Server provisioning infrastructure
#
# infrastructure_driver: libvirt
infrastructure_driver: openstack
# infrastructure_driver: openstack

2
tests/enough/common/test_common_options.py

@ -7,6 +7,6 @@ def test_set_options():
parser = argparse.ArgumentParser()
assert options.set_options(parser) == parser
args = parser.parse_args([])
driver = 'DRIVER'
driver = 'libvirt'
args = parser.parse_args(['--driver', driver])
assert args.driver == driver

13
tests/enough/common/test_dotenough.py

@ -8,6 +8,7 @@ from enough.common.dotenough import (
Hosts,
DotEnough,
DotEnoughOpenStack,
DotEnoughLibvirt,
DotEnoughOpenStackUnknownProvider,
)
@ -71,6 +72,18 @@ def test_service_add_to_group(tmpdir):
os.system(f'cat {tmpdir}/services.yml')
@pytest.mark.parametrize("cls,driver", (
(DotEnoughOpenStack, 'openstack'),
(DotEnoughLibvirt, 'libvirt'),
))
def test_dotenough_populate_infrastructure_driver(tmpdir, cls, driver):
d = cls(tmpdir, 'test.com')
d.populate_config('ownca')
all_dir = f'{d.config_dir}/inventory/group_vars/all'
v = yaml.safe_load(open(f'{all_dir}/infrastructure.yml').read())
assert v['infrastructure_driver'] == driver
#
# DotEnoughOpenStack
#

2
tests/enough/internal/test_internal_install.py

@ -9,6 +9,8 @@ def test_enough_install_script(capsys, mocker):
assert main(['--debug', 'install', 'internal/data/install.sh']) == 0
out, err = capsys.readouterr()
assert 'docker run' in out
assert 'libvirt' in out
assert 'docker.sock' in out
assert 'function()' not in out
assert __version__ in out

1
tests/tox.dockerfile

@ -6,7 +6,6 @@ RUN apt-get install -y python
# BEGIN dependencies of test/ssh
RUN apt-get install -y jq
RUN pip install tox yq
RUN apt-get install -y libguestfs-tools virtinst python-libvirt python-lxml pkg-config libvirt-dev # redundant with the libvirt role to speed up the run
RUN apt-get install -y python3-apt python3-libvirt python3-lxml # required because python3 is used not python2
# END dependencies of test/ssh
RUN git init

Loading…
Cancel
Save