Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch: Add ceems_lb molecule tests #7

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions roles/ceems_lb/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
ceems_lb_version: "0.1.0-rc.4"
ceems_lb_version: "0.1.0-rc.5"
ceems_lb_binary_local_dir: ""
ceems_lb_binary_url: https://github.com/{{ _ceems_lb_repo }}/releases/download/v{{ ceems_lb_version }}/ceems-{{ ceems_lb_version }}.linux-{{ go_arch }}.tar.gz
ceems_lb_checksums_url: https://github.com/{{ _ceems_lb_repo }}/releases/download/v{{ ceems_lb_version }}/sha256sums.txt
Expand All @@ -17,5 +17,5 @@ ceems_lb_db_path: ""
ceems_lb_cli_args: []
ceems_lb_env_vars: {}
ceems_lb_binary_install_dir: /usr/local/bin
ceems_lb_system_group: ceemslb
ceems_lb_system_group: ceems
ceems_lb_system_user: "{{ ceems_lb_system_group }}"
3 changes: 2 additions & 1 deletion roles/ceems_lb/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ argument_specs:
- Each element is a dict with url and skip_tls_verify keys.
type: list
elements: dict
required: true
ceems_lb_strategy:
description:
- Load Balancer strategy.
Expand Down Expand Up @@ -67,7 +68,7 @@ argument_specs:
ceems_lb_system_group:
description:
- I(Advanced)
- System group for batch job stats server
- System group for CEEMS load balancer
default: ceemslb
ceems_lb_system_user:
description:
Expand Down
26 changes: 12 additions & 14 deletions roles/ceems_lb/molecule/alternative/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@ provisioner:
inventory:
group_vars:
all:
ceems_api_server_web_listen_address: 127.0.0.1:8080

ceems_api_server_tls_server_config:
cert_file: /etc/ceems_api_server/tls.cert
key_file: /etc/ceems_api_server/tls.key
ceems_api_server_http_server_config:
ceems_lb_web_listen_address: 127.0.0.1:8080
ceems_lb_backends:
- url: http://localhost:9090
skip_tls_verify: true
ceems_lb_tls_server_config:
cert_file: /etc/ceems_lb/tls.cert
key_file: /etc/ceems_lb/tls.key
ceems_lb_http_server_config:
http2: true
ceems_api_server_basic_auth_users:
ceems_lb_basic_auth_users:
randomuser: examplepassword
go_arch: amd64
ceems_api_server_data_backup_path: /tmp/ceems_api_server
ceems_api_server_admin_users:
- adm1
- adm2
ceems_api_server_cli_args:
- --web.max.query.period=30d
ceems_api_server_env_vars:
ceems_lb_cli_args:
- --log.level=debug
ceems_lb_env_vars:
foo: bar
8 changes: 4 additions & 4 deletions roles/ceems_lb/molecule/alternative/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
hosts: all
any_errors_fatal: true
tasks:
- name: Create ceems_api_server cert dir
- name: Create ceems_lb cert dir
ansible.builtin.file:
path: "{{ ceems_api_server_tls_server_config.cert_file | dirname }}"
path: "{{ ceems_lb_tls_server_config.cert_file | dirname }}"
state: directory
owner: root
group: root
Expand All @@ -42,6 +42,6 @@
mode: "{{ item.mode | default('0644') }}"
loop:
- src: /tmp/tls.cert
dest: "{{ ceems_api_server_tls_server_config.cert_file }}"
dest: "{{ ceems_lb_tls_server_config.cert_file }}"
- src: /tmp/tls.key
dest: "{{ ceems_api_server_tls_server_config.key_file }}"
dest: "{{ ceems_lb_tls_server_config.key_file }}"
14 changes: 7 additions & 7 deletions roles/ceems_lb/molecule/alternative/tests/test_alternative.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@


@pytest.mark.parametrize("dir", [
"/var/lib/ceems_lb",
"/tmp/ceems_lb"
"/etc/ceems_lb",
])
def test_directories(host, dir):
d = host.file(dir)
Expand All @@ -22,6 +21,7 @@ def test_directories(host, dir):
@pytest.mark.parametrize("file", [
"/etc/systemd/system/ceems_lb.service",
"/etc/ceems_lb/config.yaml",
"/etc/ceems_lb/web-config.yaml",
"/usr/local/bin/ceems_lb"
])
def test_files(host, file):
Expand All @@ -45,10 +45,10 @@ def test_permissions_didnt_change(host, file):


def test_user(host):
assert host.group("ceemslb").exists
assert "ceemslb" in host.user("ceemslb").groups
assert host.user("ceemslb").shell == "/usr/sbin/nologin"
assert host.user("ceemslb").home == "/"
assert host.group("ceems").exists
assert "ceems" in host.user("ceems").groups
assert host.user("ceems").shell == "/usr/sbin/nologin"
assert host.user("ceems").home == "/"


def test_service(host):
Expand All @@ -72,7 +72,7 @@ def test_systemd_properties(host):


@pytest.mark.parametrize("socket", [
"tcp://127.0.0.1:9030",
"tcp://127.0.0.1:8080",
])
def test_socket(host, socket):
s = host.socket(socket)
Expand Down
5 changes: 4 additions & 1 deletion roles/ceems_lb/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ provisioner:
inventory:
group_vars:
all:
ceems_api_server_web_listen_address: 127.0.0.1:9020
ceems_lb_web_listen_address: 127.0.0.1:9030
ceems_lb_backends:
- url: http://localhost:9090
skip_tls_verify: true
10 changes: 5 additions & 5 deletions roles/ceems_lb/molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


@pytest.mark.parametrize("dir", [
"/var/lib/ceems_lb",
"/etc/ceems_lb",
])
def test_directories(host, dir):
d = host.file(dir)
Expand Down Expand Up @@ -44,10 +44,10 @@ def test_permissions_didnt_change(host, file):


def test_user(host):
assert host.group("ceemslb").exists
assert "ceemslb" in host.user("ceemslb").groups
assert host.user("ceemslb").shell == "/usr/sbin/nologin"
assert host.user("ceemslb").home == "/"
assert host.group("ceems").exists
assert "ceems" in host.user("ceems").groups
assert host.user("ceems").shell == "/usr/sbin/nologin"
assert host.user("ceems").home == "/"


def test_service(host):
Expand Down
5 changes: 4 additions & 1 deletion roles/ceems_lb/molecule/latest/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ provisioner:
inventory:
group_vars:
all:
ceems_api_server_version: latest
ceems_lb_version: latest
ceems_lb_backends:
- url: http://localhost:9090
skip_tls_verify: true
18 changes: 9 additions & 9 deletions roles/ceems_lb/molecule/latest/tests/test_latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


@pytest.mark.parametrize("dir", [
"/var/lib/ceems_lb",
"/etc/ceems_lb",
])
def test_directories(host, dir):
d = host.file(dir)
Expand All @@ -29,25 +29,25 @@ def test_files(host, file):
assert f.is_file


@pytest.mark.parametrize("dir", [
@pytest.mark.parametrize("file", [
"/etc",
"/root",
"/usr",
"/var"
])
def test_permissions_didnt_change(host, dir):
f = host.file(dir)
def test_permissions_didnt_change(host, file):
f = host.file(file)
assert f.exists
assert f.is_directory
assert f.user == "root"
assert f.group == "root"


def test_user(host):
assert host.group("ceemslb").exists
assert "ceemslb" in host.user("ceemslb").groups
assert host.user("ceemslb").shell == "/usr/sbin/nologin"
assert host.user("ceemslb").home == "/"
assert host.group("ceems").exists
assert "ceems" in host.user("ceems").groups
assert host.user("ceems").shell == "/usr/sbin/nologin"
assert host.user("ceems").home == "/"


def test_service(host):
Expand All @@ -70,7 +70,7 @@ def test_protecthome_property(host):


@pytest.mark.parametrize("socket", [
"tcp://127.0.0.1:9030",
"tcp://127.0.0.1:9030"
])
def test_socket(host, socket):
s = host.socket(socket)
Expand Down
9 changes: 1 addition & 8 deletions roles/ceems_lb/templates/ceems_lb.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,13 @@ Restart=always
RestartSec=1
StartLimitInterval=0

{% set ns = namespace(protect_home = 'yes', caps = ['CAP_SETUID', 'CAP_SETGID']) %}
{% set ns = namespace(protect_home = 'yes') %}
{% for m in ansible_mounts if m.mount.startswith('/home') %}
{% set ns.protect_home = 'read-only' %}
{% endfor %}
ProtectHome={{ ns.protect_home }}
ReadWritePaths={{ ceems_lb_data_path }} {{ ceems_lb_data_backup_path }}
WorkingDirectory={{ ceems_lb_data_path }}

{% if ns.caps %}
AmbientCapabilities={{ ns.caps | unique | join(' ') }}
CapabilityBoundingSet={{ ns.caps | unique | join(' ') }}
{% else %}
NoNewPrivileges=yes
{% endif %}

{% if ceems_lb_env_vars | length > 0 %}
{% for k, v in ceems_lb_env_vars.items() %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+")
source "$collection_root/tests/integration/molecule.sh"
4 changes: 4 additions & 0 deletions tests/integration/targets/molecule-ceems_lb-default/runme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+")
source "$collection_root/tests/integration/molecule.sh"
Loading