Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ build/
foremanctl-*.tar.gz

.var
.tmp
35 changes: 24 additions & 11 deletions development/playbooks/test/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,32 @@
hosts:
- localhost
tasks:
- name: Capture vagrant ssh-config
ansible.builtin.command:
cmd: vagrant ssh-config
args:
chdir: "{{ inventory_dir }}/../"
register: ssh_config
changed_when: false
- name: Ensure .tmp directory exists
ansible.builtin.file:
path: "{{ inventory_dir }}/../.tmp"
state: directory
mode: "0755"

- name: Write ssh_config
- name: Generate ssh_config from ansible inventory
ansible.builtin.copy:
dest: "{{ inventory_dir }}/../.vagrant/ssh-config"
content: "{{ ssh_config.stdout }}"
mode: "0755"
dest: "{{ inventory_dir }}/../.tmp/ssh-config"
content: |
{% for host in groups['all'] %}
Host {{ host }}
HostName {{ hostvars[host]['ansible_host'] | default(host) }}
User {{ hostvars[host]['ansible_user'] | default('vagrant') }}
Port {{ hostvars[host]['ansible_port'] | default('22') }}
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
{% if hostvars[host]['ansible_ssh_private_key_file'] is defined %}
IdentityFile {{ hostvars[host]['ansible_ssh_private_key_file'] }}
{% endif %}
IdentitiesOnly yes
LogLevel FATAL

{% endfor %}
mode: "0644"

- name: Run pytest
ansible.builtin.command:
Expand Down
8 changes: 4 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from jinja2 import Environment, FileSystemLoader, select_autoescape


VAGRANT_SSH_CONFIG='./.vagrant/ssh-config'
SSH_CONFIG='./.tmp/ssh-config'


def pytest_addoption(parser):
Expand Down Expand Up @@ -44,17 +44,17 @@ def certificates(pytestconfig, server_fqdn):

@pytest.fixture(scope="module")
def server(server_hostname):
yield testinfra.get_host(f'paramiko://{server_hostname}', sudo=True, ssh_config=VAGRANT_SSH_CONFIG)
yield testinfra.get_host(f'paramiko://{server_hostname}', sudo=True, ssh_config=SSH_CONFIG)


@pytest.fixture(scope="module")
def client():
yield testinfra.get_host('paramiko://client', sudo=True, ssh_config=VAGRANT_SSH_CONFIG)
yield testinfra.get_host('paramiko://client', sudo=True, ssh_config=SSH_CONFIG)


@pytest.fixture(scope="module")
def ssh_config(server_hostname):
config = paramiko.SSHConfig.from_path(VAGRANT_SSH_CONFIG)
config = paramiko.SSHConfig.from_path(SSH_CONFIG)
return config.lookup(server_hostname)


Expand Down