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
47 changes: 47 additions & 0 deletions playbooks/test_vm_creation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
# OSAC E2E Test: VM Creation
# This playbook tests the creation and verification of virtual_machines

- name: OSAC VM Creation Test
hosts: localhost
gather_facts: true
vars:
test_name: VM Creation Test
test_description: Test creating and verifying a VM with fulfillment-cli
tasks:
- name: Display test information
ansible.builtin.debug:
msg: |
{{ test_name }}
==========================================
Description: {{ test_description }}
Namespace: {{ test_namespace }}
Timestamp: {{ ansible_date_time.iso8601 }}
==========================================

- name: Execute VM creation test
block:
- name: Run VM creation test
ansible.builtin.include_role:
name: test_vm_creation
vars:
vm_template: cloudkit.templates.ocp_virt_vm

rescue:
- name: Log test failure
ansible.builtin.lineinfile:
path: "{{ testing_workspace }}/test-execution.log"
line: "[{{ ansible_date_time.iso8601 }}] FAILED: VM creation test failed"
create: true
mode: "0644"

- name: Re-raise the error
ansible.builtin.fail:
msg: VM creation test failed

- name: Execute VM cleanup
ansible.builtin.include_role:
name: test_vm_creation
tasks_from: delete_vm
vars:
vm_id: "{{ test_vm_id }}"
18 changes: 18 additions & 0 deletions roles/test_vm_creation/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
cli_binary: cli_binary_path

# VM template and settings (reasonable defaults)
template: cloudkit.templates.ocp_virt_vm
cpu_cores: 2
memory_gb: 4
disk_size_gb: 20
network: default

# Test settings (reasonable defaults, defer to group_vars)
ready_timeout: 900 # 15 minutes for VM to become ready

# Temporary files
vm_config_file: "{{ testing_workspace }}/vm-config-{{ vm_id }}.yaml"

check_interval: 120
vm_ready_timeout: 600
21 changes: 21 additions & 0 deletions roles/test_vm_creation/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
# Meta information for test_vm_creation role

galaxy_info:
author: OSAC E2E Testing
description: Role for testing VM creation and lifecycle in OSAC
company: Red Hat
license: Apache-2.0
min_ansible_version: all
platforms:
- name: EL
versions:
- all

dependencies:
- role: fulfillment_cli_base
when: fulfillment_cli_base_required | default(true)

collections:
- ansible.builtin
- community.general
35 changes: 35 additions & 0 deletions roles/test_vm_creation/tasks/delete_vm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
- name: Create VM via fulfillment-cli (no-args)
ansible.builtin.command:
cmd: >
{{ fulfillment_cli_path }} delete virtualmachine
{{ vm_order_uuid }}
register: test_vm_creation_vm_creation_result
changed_when: test_vm_creation_vm_creation_result.rc == 0

# VM deletion tasks for test_vm_creation role

- name: Verify VM registration via gRPC call
ansible.builtin.command:
cmd: >
grpcurl -insecure
-H "Authorization: Bearer {{ fulfillment_cli_base_grpc_token_result.stdout }}"
{{ fulfillment_address }}
private.v1.VirtualMachines/List
register: test_vm_creation_vm_verification_result
changed_when: false

- name: Collect list of VM uuids
ansible.builtin.set_fact:
known_ids: "{{ test_vm_creation_vm_verification_result.stdout | from_json | json_query('items[].id') | map('trim') | list }}"

- name: Check if VM appears in gRPC response
ansible.builtin.assert:
that:
- vm_order_uuid not in known_ids
fail_msg: VM {{ vm_order_uuid }} failed
success_msg: VM {{ vm_order_uuid }} sucessfully deleted

- name: Log VM cleanup completion
ansible.builtin.debug:
msg: "Successfully cleaned up test vm for {{ vm_order_uuid }}"
63 changes: 63 additions & 0 deletions roles/test_vm_creation/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
- name: Create VM via fulfillment-cli (no-args)
ansible.builtin.command:
cmd: >
{{ fulfillment_cli_path }} create virtualmachine
--template {{ template }}
register: test_vm_creation_vm_creation_result
changed_when: test_vm_creation_vm_creation_result.rc == 0

- name: Save VM ID
ansible.builtin.set_fact:
vm_order_uuid: '{{ test_vm_creation_vm_creation_result.stdout | regex_findall("''([^'']+)''") | first }}'

- name: Verify VM registration via gRPC call
ansible.builtin.command:
cmd: >
grpcurl -insecure

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why no use fulfillment-cli for all?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exercises both the cli binary and the gRPC interface and provides an independent way to verify. I know the cli uses the gRPC calls.

-H "Authorization: Bearer {{ fulfillment_cli_base_grpc_token_result.stdout }}"
{{ fulfillment_address }}
private.v1.VirtualMachines/List
register: test_vm_creation_vm_verification_result
changed_when: false

- name: Collect list of VM uuids
ansible.builtin.set_fact:
known_ids: "{{ test_vm_creation_vm_verification_result.stdout | from_json | json_query('items[].id') | map('trim') | list }}"

- name: Check if VM appears in gRPC response
ansible.builtin.assert:
that:
- vm_order_uuid in known_ids
fail_msg: VM {{ test_vm_creation_vm_creation_result.stdout }} not found in gRPC VM list response
success_msg: VM {{ test_vm_creation_vm_creation_result.stdout }} successfully registered and verified via gRPC

- name: Collect VM list
ansible.builtin.command:
cmd: >
grpcurl -insecure
-H "Authorization: Bearer {{ fulfillment_cli_base_grpc_token_result.stdout }}"
{{ fulfillment_address }}
private.v1.VirtualMachines/List
register: vm_status_check
until:
- vm_status_check.rc == 0
- vm_status_check.stdout | from_json | json_query('status.conditions') is defined
- >
vm_status_check.stdout
| from_json
| json_query("items[?id=='%s']" % vm_order_uuid)
| map(attribute='status.state')
| list
| first
== "VIRTUAL_MACHINE_STATE_READY"
retries: "{{ (vm_ready_timeout / check_interval) | int }}"
delay: "{{ check_interval }}"
changed_when: false

- name: Log successful VM creation and verification
ansible.builtin.lineinfile:
path: "{{ testing_workspace }}/test-execution.log"
line: |
[{{ ansible_date_time.iso8601 }}] SUCCESS: VM {{ vm_order_uuid }} created and verified successfully
VM is ready and running