Repository navigation
VM creation and deletion testing. #6
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| -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 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.