Skip to content

Commit

Permalink
Add debian test scenario (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyphreak authored Oct 10, 2023
1 parent f65d405 commit 14c4e59
Show file tree
Hide file tree
Showing 10 changed files with 312 additions and 94 deletions.
26 changes: 23 additions & 3 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,31 @@ defaults:

jobs:

mirror:
name: mirror
runs-on: ubuntu-latest
steps:
- name: Check out the codebase.
uses: actions/checkout@v2
with:
path: 'nephelaiio.growfs'

- name: Test debian mirror access (http)
run: curl -sD- http://debian-archive.trafficmanager.net/debian/

- name: Test debian security mirror access (http)
run: curl -sD- http://debian-archive.trafficmanager.net/debian-security/

molecule:
name: molecule
runs-on: libvirt
strategy:
matrix:
include:
- scenario: default
net: '192.168.255.0/24'
- scenario: ubuntu
release: jammy
- scenario: debian
release: bullseye

steps:
- name: Check out the codebase.
Expand All @@ -43,6 +60,9 @@ jobs:
- name: Install dependencies
run: make install

- name: Disable firewall
run: sudo ufw disable

- name: Debug test environment
run: make debug

Expand All @@ -52,7 +72,7 @@ jobs:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
MOLECULE_SCENARIO: ${{ matrix.scenario }}
MOLECULE_NET: ${{ matrix.net }}
MOLECULE_DISTRO: "${{ matrix.release }}"
MOLECULE_OUTPUT_DIR: "/tmp/logs"

- name: Upload install logs
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# See: https://github.com/ansible/galaxy/issues/46

name: Release

on:
push:
tags:
Expand All @@ -18,7 +19,7 @@ defaults:
jobs:

release:
name: Release
name: release
runs-on: ubuntu-latest
steps:
- name: Check out the codebase.
Expand Down
4 changes: 3 additions & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ fileignoreconfig:
ignore_detectors: [filecontent]
- filename: tasks/lvm.yml
ignore_detectors: [filecontent]
- filename: molecule/default/molecule.yml
- filename: molecule/ubuntu/molecule.yml
ignore_detectors: [filecontent]
- filename: molecule/debian/molecule.yml
ignore_detectors: [filecontent]
- filename: molecule/common/create.yml
ignore_detectors: [filecontent]
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.PHONY: all ${MAKECMDGOALS}

MOLECULE_SCENARIO ?= default
MOLECULE_DOCKER_IMAGE ?= ubuntu2004
MOLECULE_SCENARIO ?= ubuntu
GALAXY_API_KEY ?=
GITHUB_REPOSITORY ?= $$(git config --get remote.origin.url | cut -d: -f 2 | cut -d. -f 1)
GITHUB_ORG = $$(echo ${GITHUB_REPOSITORY} | cut -d/ -f 1)
Expand Down Expand Up @@ -42,4 +41,5 @@ version:
@poetry run molecule --version

debug: version
sudo ufw status
@poetry export --dev --without-hashes
24 changes: 23 additions & 1 deletion molecule/common/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
url: "{{ iso_installer.url }}"
dest: "{{ iso_installer.dest | urlsplit('path') }}"

- name: Build guest installer isos
- name: Build ubuntu installer isos
ansible.builtin.include_role:
name: nephelaiio.ubuntu_installer
vars:
Expand All @@ -53,6 +53,28 @@
loop_var: guest
label: "{{ guest.installer_hostname }}"
loop: "{{ guest_info }}"
when: molecule_scenario == "ubuntu"

- name: Build debian installer isos
ansible.builtin.include_role:
name: nephelaiio.debian_installer
vars:
debian_installer_interface_name: enp1s0
debian_installer_target_dir: "{{ cache_dir }}"
debian_installer_image_url: "{{ iso_installer.dest }}"
debian_installer_hostname: "{{ guest.installer_hostname }}"
debian_installer_username: molecule
debian_installer_password: "{{ 'molecule' | password_hash('sha512') }}"
debian_installer_sshkey:
- "{{ lookup('file', kvm_keypair + '.pub') }}"
debian_installer_interface: "{{ guest.installer_interface }}"
debian_installer_partman_method: "{{ guest.installer_partitioning_method }}"
debian_installer_preseed_include: "{{ guest.installer_preseed_include | default('') }}"
loop_control:
loop_var: guest
label: "{{ guest.installer_hostname }}"
loop: "{{ guest_info }}"
when: molecule_scenario == "debian"

- name: Create KVM guest disks
ansible.builtin.command: "qemu-img create {{ guest_disk }} {{ guest_disk_size }}"
Expand Down
196 changes: 114 additions & 82 deletions molecule/common/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,103 +9,135 @@
become: true
pre_tasks:

- name: Query KVM guest info
community.libvirt.virt:
command: info
register: libvirt_info
delegate_to: localhost
run_once: true

- name: Shut down guest
when:
- inventory_hostname in libvirt_info
- libvirt_info[inventory_hostname].state == "running"
- name: Recofigure guest storage
block:

- name: Wait for connection
ansible.builtin.wait_for_connection:
timeout: 1200
- name: Query KVM guest info
community.libvirt.virt:
command: info
register: libvirt_info
delegate_to: localhost
run_once: true

- name: Shut down guest
community.general.shutdown:
when:
- inventory_hostname in libvirt_info
- libvirt_info[inventory_hostname].state == "running"
block:

- name: Wait for shutdown to complete
ansible.builtin.pause:
seconds: 30
- name: Wait for connection
ansible.builtin.wait_for_connection:
timeout: 1200

- name: Force kvm guest poweroff
ansible.builtin.shell: "virsh destroy {{ inventory_hostname }} >/dev/null 2>&1"
ignore_errors: true
failed_when: false
changed_when: false
delegate_to: localhost
- name: Shut down guest
community.general.shutdown:

- name: Wait for poweroff to complete
ansible.builtin.pause:
seconds: 30
- name: Wait for shutdown to complete
ansible.builtin.pause:
seconds: 30

- name: Reconfigure guest disks
delegate_to: localhost
block:
- name: Force kvm guest poweroff
ansible.builtin.shell: "virsh destroy {{ inventory_hostname }} >/dev/null 2>&1"
ignore_errors: true
failed_when: false
changed_when: false
delegate_to: localhost

- name: Stat kvm base disk
ansible.builtin.stat:
path: "{{ cache_dir }}/{{ inventory_hostname }}.img"
register: guest_disk_query
- name: Wait for poweroff to complete
ansible.builtin.pause:
seconds: 30

- name: Debug base disk info
ansible.builtin.debug:
msg: "{{ guest_disk_query.stat }}"
- name: Reconfigure guest disks
delegate_to: localhost
block:

- name: Stat kvm base disk
ansible.builtin.stat:
path: "{{ cache_dir }}/{{ inventory_hostname }}.img"
register: guest_disk_query

- name: Debug base disk info
ansible.builtin.debug:
msg: "{{ guest_disk_query.stat }}"

- name: Resize kvm base disks
ansible.builtin.command: "qemu-img resize -f raw {{ guest_disk }} {{ guest_disk_size }}"
vars:
guest_disk: "{{ cache_dir }}/{{ inventory_hostname }}.img"
guest_disk_size: "{{ 2 * (disk_size | int) }}"
when: (guest_disk_size | int) > (guest_disk_query.stat.size | int)

- name: Stat additional kvm disk
ansible.builtin.stat:
path: "{{ cache_dir }}/{{ inventory_hostname }}.add.img"
register: guest_addisk_query

- name: Create additional kvm disk for lvm instances
ansible.builtin.command: "qemu-img create -f raw {{ guest_disk }} {{ guest_disk_size }}"
args:
creates: "{{ guest_disk }}"
vars:
guest_disk: "{{ cache_dir }}/{{ inventory_hostname }}.add.img"
guest_disk_size: "{{ 2 * (disk_size | int) }}"
when:
- not guest_addisk_query.stat.exists
- partitioning_method == 'lvm'
notify: attach kvm guest disk

- name: Manage permissions for extra kvm guest disk
ansible.builtin.file:
path: "{{ guest_disk }}"
owner: libvirt-qemu
group: kvm
mode: 0660
vars:
guest_disk: "{{ cache_dir }}/{{ inventory_hostname }}.add.img"
when: partitioning_method == 'lvm'

- name: Flush handlers
ansible.builtin.meta: flush_handlers

- name: Start kvm guest
community.libvirt.virt:
name: "{{ inventory_hostname }}"
state: running

- name: Resize kvm base disks
ansible.builtin.command: "qemu-img resize -f raw {{ guest_disk }} {{ guest_disk_size }}"
vars:
guest_disk: "{{ cache_dir }}/{{ inventory_hostname }}.img"
guest_disk_size: "{{ 2 * (disk_size | int) }}"
when: (guest_disk_size | int) > (guest_disk_query.stat.size | int)

- name: Stat additional kvm disk
ansible.builtin.stat:
path: "{{ cache_dir }}/{{ inventory_hostname }}.add.img"
register: guest_addisk_query

- name: Create additional kvm disk for lvm instances
ansible.builtin.command: "qemu-img create -f raw {{ guest_disk }} {{ guest_disk_size }}"
args:
creates: "{{ guest_disk }}"
- name: Wait for connection
ansible.builtin.wait_for_connection:
timeout: 120

- name: Gather facts
ansible.builtin.setup:
tags: always

always:

- name: Set debug facts
ansible.builtin.set_fact:
debug_disk: "{{ disk_location }}.debug"
debug_hostdir: "{{ _hostdir }}"
debug_logfile: "{{ _logfile }}"
debug_crashdir: "{{ _crashdir }}"
debug_output_dir: "{{ output_dir }}"
debug_output_curtin: "{{ output_dir }}/{{ inventory_hostname }}.curtin.log"
debug_output_screenshot: "{{ output_dir }}/{{ inventory_hostname }}.png"
vars:
guest_disk: "{{ cache_dir }}/{{ inventory_hostname }}.add.img"
guest_disk_size: "{{ 2 * (disk_size | int) }}"
when:
- not guest_addisk_query.stat.exists
- partitioning_method == 'lvm'
notify: attach kvm guest disk
_hostdir: "{{ cache_dir }}/{{ inventory_hostname }}"
_logfile: "{{ _hostdir }}/var/log/installer/curtin-install.log"
_crashdir: "{{ _hostdir }}/var/crash/"

- name: Manage permissions for extra kvm guest disk
- name: Create output directory
ansible.builtin.file:
path: "{{ guest_disk }}"
owner: libvirt-qemu
group: kvm
mode: 0660
vars:
guest_disk: "{{ cache_dir }}/{{ inventory_hostname }}.add.img"
when: partitioning_method == 'lvm'

- name: Flush handlers
ansible.builtin.meta: flush_handlers

- name: Start kvm guest
community.libvirt.virt:
name: "{{ inventory_hostname }}"
state: running

- name: Wait for connection
ansible.builtin.wait_for_connection:
timeout: 120
state: directory
path: "{{ debug_output_dir }}"
delegate_to: localhost
run_once: true

- name: Gather facts
ansible.builtin.setup:
tags: always
- name: Take guest screenshot
ansible.builtin.command: "virsh screenshot {{ inventory_hostname }} {{ debug_output_screenshot }}"
delegate_to: localhost
when: molecule_debug
become: true

handlers:

Expand Down
6 changes: 3 additions & 3 deletions molecule/common/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@
installer_disk_size: "{{ installer_disk_device.size_total }}"
installer_disk_threshold: "{{ (1.5 * (disk_size | int)) | int }}"
when:
- (installer_disk_size | int) < (installer_disk_threshold | int)
- partitioning_method != 'lvm'
- (installer_disk_size | int) < (installer_disk_threshold | int)

- name: Check lvm root device size
ansible.builtin.fail:
msg: "{{ installer_disk_size }} < {{ installer_disk_threshold }} ({{ disk_size }})"
vars:
installer_disk_device: "{{ ansible_mounts | selectattr('mount', 'equalto', '/') | list | first }}"
installer_disk_size: "{{ installer_disk_device.size_total }}"
installer_disk_threshold: "{{ (3.5 * (disk_size | int)) | int }}"
installer_disk_threshold: "{{ (2.5 * (disk_size | int)) | int }}"
when:
- (installer_disk_size | int) < (installer_disk_threshold | int)
- partitioning_method == 'lvm'
- (installer_disk_size | int) < (installer_disk_threshold | int)
- growfs_lvs_mount is undefined

- name: Check lvs root device size
Expand Down
Loading

0 comments on commit 14c4e59

Please sign in to comment.