From ed046b956607a45b4913210ce2a609fdebd84575 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sun, 13 Oct 2019 23:15:36 +0200 Subject: [PATCH] add systemd after list --- defaults/main.yml | 3 +++ defaults/tests/test_default.py | 26 ------------------- molecule/default/tests/test_default.py | 22 ++++++++++++---- .../systemd/system/homeassistant.service.j2 | 4 ++- 4 files changed, 23 insertions(+), 32 deletions(-) delete mode 100644 defaults/tests/test_default.py diff --git a/defaults/main.yml b/defaults/main.yml index 719a0fa..b3835ba 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -10,6 +10,9 @@ homeassistant_extra_groups: - tty - dialout +homeassistant_systemd_after: + - network-online.target + homeassistant_base_dir: /opt/homeassistant homeassistant_conf_dir: "{{ homeassistant_base_dir }}/config" diff --git a/defaults/tests/test_default.py b/defaults/tests/test_default.py deleted file mode 100644 index 40300ab..0000000 --- a/defaults/tests/test_default.py +++ /dev/null @@ -1,26 +0,0 @@ -import os -import time - -import testinfra.utils.ansible_runner - -import warnings -warnings.filterwarnings("ignore", category=DeprecationWarning) - -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') - - -def test_hassio_running_and_enabled(host): - hassio = host.service("homeassistant") - assert hassio.is_running - assert hassio.is_enabled - - -def test_hassio_socket(host): - # Verify the socket is listening for HTTP traffic - for _ in range(30): - if host.socket("tcp://0.0.0.0:8123").is_listening: - break - time.sleep(1) - - assert host.socket("tcp://0.0.0.0:8123").is_listening diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py index eedd64a..40300ab 100644 --- a/molecule/default/tests/test_default.py +++ b/molecule/default/tests/test_default.py @@ -1,14 +1,26 @@ import os +import time import testinfra.utils.ansible_runner +import warnings +warnings.filterwarnings("ignore", category=DeprecationWarning) + testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') -def test_hosts_file(host): - f = host.file('/etc/hosts') +def test_hassio_running_and_enabled(host): + hassio = host.service("homeassistant") + assert hassio.is_running + assert hassio.is_enabled - assert f.exists - assert f.user == 'root' - assert f.group == 'root' + +def test_hassio_socket(host): + # Verify the socket is listening for HTTP traffic + for _ in range(30): + if host.socket("tcp://0.0.0.0:8123").is_listening: + break + time.sleep(1) + + assert host.socket("tcp://0.0.0.0:8123").is_listening diff --git a/templates/etc/systemd/system/homeassistant.service.j2 b/templates/etc/systemd/system/homeassistant.service.j2 index 862f180..690a7e6 100644 --- a/templates/etc/systemd/system/homeassistant.service.j2 +++ b/templates/etc/systemd/system/homeassistant.service.j2 @@ -3,7 +3,9 @@ [Unit] Description=Home Assistant Wants=network-online.target -After=network-online.target +{% for item in homeassistant_systemd_after %} +After={{ item }} +{% endfor %} [Service] Type=simple