Skip to content

Commit 1669305

Browse files
authored
Merge pull request #1 from stackabletech/add-tests
Add tests
2 parents 8265c25 + 31eba0e commit 1669305

File tree

15 files changed

+655
-4
lines changed

15 files changed

+655
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ tmp/
55
/target
66
roles/create-vm/files/guest-files/spice-guest-tools.exe
77
/.direnv
8+
_work/

nix/sources.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
{
2+
"beku.py": {
3+
"branch": "main",
4+
"description": "Test suite expander for Stackable Kuttl tests.",
5+
"homepage": null,
6+
"owner": "stackabletech",
7+
"repo": "beku.py",
8+
"rev": "1ebc9e7b70fb8ee11dfb569ae45b3bcd63666d0e",
9+
"sha256": "1zg24h5wdis7cysa08r8vvbw2rpyx6fgv148i1lg54dwd3sa0h0d",
10+
"type": "tarball",
11+
"url": "https://github.com/stackabletech/beku.py/archive/1ebc9e7b70fb8ee11dfb569ae45b3bcd63666d0e.tar.gz",
12+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
13+
},
214
"nixpkgs": {
315
"branch": "nixos-unstable",
416
"description": "Nix Packages collection",

roles/create-vm/defaults/main.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ vm_disk_format: qcow2
1010

1111
vm_network_hostnet_name: stackable-adds-test-hostnet
1212
vm_network_hostnet_subnet: 192.168.197.0/24
13-
vm_network_internet_name: default
13+
vm_network_internet_name: stackable-adds-test-internet
14+
vm_network_internet_subnet: 192.168.196.0/24
1415

1516
install_iso_windows: "{{ lookup('first_found', 'target') }}/Windows Server 2022 EVAL.iso"
1617

roles/create-vm/tasks/main.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
path: "{{ install_iso_windows }}"
99
get_checksum: false
1010
register: install_iso_windows_stat
11+
1112
- name: Complain about missing Windows ISO
1213
ansible.builtin.fail:
1314
msg: "Windows ISO could not be found, please download it from https://www.microsoft.com/en-us/evalcenter/download-windows-server-2022 and put it at {{ install_iso_windows }} (or modify install_iso_windows to point at the correct path)"
@@ -18,6 +19,7 @@
1819
dest: "{{ install_iso_virtio_win }}"
1920
url: "{{ install_iso_virtio_win_url }}"
2021
checksum: "{{ install_iso_virtio_win_checksum }}"
22+
2123
- name: Download SPICE guest tools
2224
ansible.builtin.get_url:
2325
dest: "{{ install_exe_spice_guest_tools }}"
@@ -30,11 +32,26 @@
3032
command: define
3133
xml: "{{ lookup('template', 'windows-vm-network.xml.j2') }}"
3234
uri: "{{ libvirt_uri }}"
35+
3336
- name: Start VM Network
3437
community.libvirt.virt_net:
3538
name: "{{ vm_network_hostnet_name }}"
3639
state: active
3740
uri: "{{ libvirt_uri }}"
41+
42+
- name: Create VM Network (Internet)
43+
community.libvirt.virt_net:
44+
name: "{{ vm_network_internet_name }}"
45+
command: define
46+
xml: "{{ lookup('template', 'windows-vm-network-internet.xml.j2') }}"
47+
uri: "{{ libvirt_uri }}"
48+
49+
- name: Start VM Network (Internet)
50+
community.libvirt.virt_net:
51+
name: "{{ vm_network_internet_name }}"
52+
state: active
53+
uri: "{{ libvirt_uri }}"
54+
3855
- name: Create VM
3956
community.libvirt.virt:
4057
command: define
@@ -43,6 +60,7 @@
4360
- ADD_UUID
4461
- ADD_MAC_ADDRESSES
4562
uri: "{{ libvirt_uri }}"
63+
4664
- name: Check if VM Volume already exists
4765
# Ansible has no idempotent way to define libvirt volumes,
4866
# so instead try to check whether it exists.
@@ -52,29 +70,34 @@
5270
# Errors should cause the create step to fail anyway
5371
failed_when: False
5472
changed_when: result_check_vm_disk.rc != 0
73+
5574
- name: Create VM Volume
5675
when: result_check_vm_disk is changed
5776
ansible.builtin.command:
5877
cmd: virsh --connect "{{ libvirt_uri }}" vol-create --pool "{{ vm_disk_pool }}" --file /dev/stdin
5978
stdin: "{{ lookup('template', 'windows-vm-volume.xml.j2') }}"
79+
6080
- name: Start VM
6181
community.libvirt.virt:
6282
name: "{{ vm_name }}"
6383
state: running
6484
uri: "{{ libvirt_uri }}"
85+
6586
- name: Get VM Metadata
6687
community.libvirt.virt:
6788
name: "{{ vm_name }}"
6889
command: get_xml
6990
uri: "{{ libvirt_uri }}"
7091
register: created_vm
92+
7193
# VM can have multiple NICs, extract the one we care about so we can match it against the IP address of the guest later
7294
- name: Extract VM's MAC address
7395
community.general.xml:
7496
xmlstring: "{{ created_vm.get_xml }}"
7597
xpath: /domain/devices/interface[alias/@name="ua-net-hostnet"]/mac
7698
content: attribute
7799
register: vm_network_mac_xml
100+
78101
- set_fact:
79102
vm_network_mac: "{{ vm_network_mac_xml.matches[0].mac.address }}"
80103
delegate_to: sble-addc
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<network connections="1">
2+
<name>{{ vm_network_internet_name }}</name>
3+
<forward mode="nat"/>
4+
<bridge stp='on' delay='0'/>
5+
<ip
6+
address="{{ vm_network_internet_subnet | ansible.utils.ipaddr('next_usable') }}"
7+
netmask="{{ vm_network_internet_subnet | ansible.utils.ipaddr('netmask') }}">
8+
<dhcp>
9+
<range
10+
start="{{ vm_network_internet_subnet | ansible.utils.next_nth_usable(2) }}"
11+
end="{{ vm_network_internet_subnet | ansible.utils.ipaddr('last_usable') }}"/>
12+
</dhcp>
13+
</ip>
14+
</network>

0 commit comments

Comments
 (0)