Skip to content

Change machine_type using vm or vm_params module #287

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 15 commits into from
Feb 26, 2024
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
76 changes: 9 additions & 67 deletions .github/workflows/integ-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ on:
List integration tests to exclude.
Use "*" to exclude all tests.
Use regex like 'node|^git_issue|^dns_config$' to exclude only a subset.
default: "^dns_config$|^cluster_shutdown$|^version_update$|^oidc_config$|^smtp$|^role_cluster_config$|^role_version_update_single_node$|^utils_login$|^certificate$"
default: "^dns_config$|^cluster_shutdown$|^version_update$|^oidc_config$|^smtp$|^role_cluster_config$|^role_version_update_single_node$|^version_update__shutdown_restart_vms$|^utils_login$|^certificate$"
integ_seq_tests_include:
type: string
description: |-
Expand All @@ -33,7 +33,7 @@ on:
# Some tests can be tested on VSNS - those are run on VSNS.
# Some cannot, those are run on test cluster 10.5.11.50.
# Some cannot be tested at all - shutdown and version update.
default: "^dns_config$|^oidc_config$|^smtp$|^role_cluster_config$|^utils_login$|^certificate$"
default: "^dns_config$|^oidc_config$|^smtp$|^role_cluster_config$|^version_update__shutdown_restart_vms$|^utils_login$|^certificate$"
integ_seq_tests_exclude:
type: string
description: |-
Expand All @@ -52,8 +52,8 @@ on:
default: ""
env:
INTEG_TESTS_INCLUDE_SCHEDULE: "*"
INTEG_TESTS_EXCLUDE_SCHEDULE: "^dns_config$|^cluster_shutdown$|^version_update$|^oidc_config$|^smtp$|^role_cluster_config$|^role_version_update_single_node$|^utils_login$|^certificate$"
INTEG_SEQ_TESTS_INCLUDE_SCHEDULE: "^dns_config$|^oidc_config$|^smtp$|^role_cluster_config$|^utils_login$|^certificate$"
INTEG_TESTS_EXCLUDE_SCHEDULE: "^dns_config$|^cluster_shutdown$|^version_update$|^oidc_config$|^smtp$|^role_cluster_config$|^role_version_update_single_node$|^version_update__shutdown_restart_vms$|^utils_login$|^certificate$"
INTEG_SEQ_TESTS_INCLUDE_SCHEDULE: "^dns_config$|^oidc_config$|^smtp$|^role_cluster_config$|^version_update__shutdown_restart_vms$|^utils_login$|^certificate$"
INTEG_SEQ_TESTS_EXCLUDE_SCHEDULE: ""
EXAMPLES_TESTS_INCLUDE_SCHEDULE: "*"
EXAMPLES_TESTS_EXCLUDE_SCHEDULE: ""
Expand Down Expand Up @@ -351,77 +351,19 @@ jobs:
- integ-seq-matrix
- integ-run
if: "(!cancelled()) && (needs.integ-seq-matrix.result=='success')"
runs-on: [ self-hosted2 ]
container: quay.io/justinc1_github/scale_ci_integ:9
env:
DEBIAN_FRONTEND: noninteractive
defaults:
run:
working-directory: ${{ env.WORKDIR }}
strategy:
fail-fast: false
# The max number of concurent jobs
max-parallel: 1
matrix:
test_name: ${{ fromJson(needs.integ-seq-matrix.outputs.matrix) }}
# "^dns_config$|^cluster_shutdown$|^version_update$|^oidc_config$|^smtp$|^role_cluster_config$|^role_version_update_single_node$|^utils_login$|^certificate$"
# Some tests can be tested on VSNS - those are run on VSNS.
# Some cannot, those are run on test cluster 10.5.11.50.
sc_host:
- https://10.5.11.200
- https://10.5.11.201
- https://10.5.11.203
- https://10.5.11.204
exclude:
# role cluster_config can be used with HC3 9.1, but you need to omit cluster_name setting.
# CI job role_cluster_config does try to set cluster_name, so it would fail.
- sc_host: https://10.5.11.200
test_name: role_cluster_config
# include: # change later to use env.INTEG_TESTS_TO_RUN_SEQUENTIALLY
# - sc_host: https://10.5.11.50
# test_name: dns_config
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: ${{ env.WORKDIR }}
- name: SKIP test if it succeeded before
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
X_GITHUB_JOB_NAME: "integ-seq-run (${{ matrix.test_name }}, ${{ matrix.sc_host }})"
run: |
if ! .github/job_retry_needed.py
then
echo SKIP test, job retry not needed
echo 'X_GITHUB_SKIP_TEST=1' >> $GITHUB_ENV
else
echo 'X_GITHUB_SKIP_TEST=0' >> $GITHUB_ENV
fi
- name: Install prerequisites
# We have ansible.cfg "for testing" in git repo
# (it is excluded in galaxy.yml, so it is not part of collection artifact)
# But it does affect ansible-galaxy and ansible-test commands.
shell: bash
run: |
[ "$X_GITHUB_SKIP_TEST" == "1" ] && exit 0
pip install ansible-core~=2.16.0
ansible-galaxy collection install community.crypto
ansible-galaxy collection list
# ${{ env.WORKDIR }} cannot be used in "uses:"
- uses: ./work-dir/ansible_collections/scale_computing/hypercore/.github/actions/make-integ-config
with:
sc_host: ${{ matrix.sc_host }}
sc_password_50: ${{ secrets.CI_CONFIG_HC_IP50_SC_PASSWORD }}
smb_password: ${{ secrets.CI_CONFIG_HC_IP50_SMB_PASSWORD }}
oidc_client_secret: ${{ secrets.OIDC_CLIENT_SECRET }}
oidc_users_0_password: ${{ secrets.OIDC_USERS_0_PASSWORD }}
working_directory: ${{ env.WORKDIR }}
- name: Run test
shell: bash
run: |
[ "$X_GITHUB_SKIP_TEST" == "1" ] && exit 0
ansible-test integration --local ${{ matrix.test_name }}
secrets: inherit
uses: ./.github/workflows/z_ansible-test.yml
with:
sc_host: ${{ matrix.sc_host }}
test_names: ${{ needs.integ-seq-matrix.outputs.matrix }}

replica_cleanup:
needs: []
Expand Down
76 changes: 76 additions & 0 deletions .github/workflows/z_ansible-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# called from other workflows
name: _ansible-test

env:
WORKDIR: work-dir/ansible_collections/scale_computing/hypercore

on:
workflow_call:
inputs:
sc_host:
type: string
required: true
description: HyperCore host
test_names:
type: string
required: true
description: List of tests to run. JSON encoded.

jobs:
ansible_test:
name: ansible-test
runs-on: [ self-hosted2 ]
container: quay.io/justinc1_github/scale_ci_integ:9
env:
DEBIAN_FRONTEND: noninteractive
defaults:
run:
working-directory: ${{ env.WORKDIR }}
strategy:
fail-fast: false
max-parallel: 1
matrix:
test_name: ${{ fromJson(inputs.test_names) }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: ${{ env.WORKDIR }}
- name: SKIP test if it succeeded before
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
X_GITHUB_JOB_NAME: "integ-seq-run (${{ inputs.sc_host }}), ansible-test (${{ matrix.test_name }})"
run: |
if ! .github/job_retry_needed.py
then
echo SKIP test, job retry not needed
echo 'X_GITHUB_SKIP_TEST=1' >> $GITHUB_ENV
else
echo 'X_GITHUB_SKIP_TEST=0' >> $GITHUB_ENV
fi
- name: Install prerequisites
# We have ansible.cfg "for testing" in git repo
# (it is excluded in galaxy.yml, so it is not part of collection artifact)
# But it does affect ansible-galaxy and ansible-test commands.
shell: bash
run: |
[ "$X_GITHUB_SKIP_TEST" == "1" ] && exit 0
pip install ansible-core~=2.16.0
ansible-galaxy collection install community.crypto
ansible-galaxy collection list
# ${{ env.WORKDIR }} cannot be used in "uses:"
- uses: ./work-dir/ansible_collections/scale_computing/hypercore/.github/actions/make-integ-config
with:
sc_host: ${{ inputs.sc_host }}
sc_password_50: ${{ secrets.CI_CONFIG_HC_IP50_SC_PASSWORD }}
smb_password: ${{ secrets.CI_CONFIG_HC_IP50_SMB_PASSWORD }}
oidc_client_secret: ${{ secrets.OIDC_CLIENT_SECRET }}
oidc_users_0_password: ${{ secrets.OIDC_USERS_0_PASSWORD }}
working_directory: ${{ env.WORKDIR }}
- name: Run test
shell: bash
run: |
[ "$X_GITHUB_SKIP_TEST" == "1" ] && exit 0
ansible-test integration --local ${{ matrix.test_name }}
9 changes: 9 additions & 0 deletions changelogs/fragments/20240226-change-machine-type.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
major_changes:
- Allow changing VM `machine_type` using vm and vm_param modules.
(https://github.com/ScaleComputing/HyperCoreAnsibleCollection/pull/287)
minor_changes:
- Fix `vm_rebooted` output value.
The meaning needs to be "was VM rebooted".
Some modules were still returning "VM needs to be rebooted (if it is running) to apply (some) changes".
- vm_nic module fails with descriptive message (no crash) if VM is missing.
56 changes: 56 additions & 0 deletions examples/vm_bios_to_uefi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
- name: Create VM
hosts: localhost
connection: local
gather_facts: false
vars:
vm_name: demo-vm-bios-uefi

tasks:
- name: Create VM {{ vm_name }}
scale_computing.hypercore.vm:
vm_name: "{{ vm_name }}"
memory: "{{ '1 GB' | human_to_bytes }}"
vcpu: 2
disks:
- type: virtio_disk
disk_slot: 0
size: "{{ '10 GB' | human_to_bytes }}"
nics:
- type: virtio
vlan: 10
state: present
power_state: stop
# os_other or os_windows_server_2012
operating_system: os_other
machine_type: BIOS
register: vm_result

- name: Show the info about BIOS VM {{ vm_name }}
ansible.builtin.debug:
var: vm_result

- name: Change BIOS VM to UEFI, NVRAM disk is needed too
scale_computing.hypercore.vm:
vm_name: "{{ vm_name }}"
memory: "{{ '1 GB' | human_to_bytes }}"
vcpu: 2
disks:
- type: virtio_disk
disk_slot: 0
size: "{{ '10 GB' | human_to_bytes }}"
- type: nvram
disk_slot: -1
size: 540672
nics:
- type: virtio
vlan: 10
state: present
# os_other or os_windows_server_2012
operating_system: os_other
machine_type: UEFI
register: vm_result

- name: Show the info about UEFI VM {{ vm_name }}
ansible.builtin.debug:
var: vm_result
26 changes: 26 additions & 0 deletions plugins/doc_fragments/machine_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Copyright: (c) 2022, XLAB Steampunk <steampunk@xlab.si>
#
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function

__metaclass__ = type


class ModuleDocFragment(object):
# language=yaml
DOCUMENTATION = r"""
options:
machine_type:
description:
- Changes VM machine type.
- Before this is utilized, a shutdown request is sent.
- |
The UEFI machine types require NVRAM disk attached to VM.
The vTPM machine types require vTPM disk attached to VM.
If such disk is not present, module will reject machine type change and fail with error.
type: str
choices: ["BIOS", "UEFI", "vTPM+UEFI", "vTPM+UEFI-compatible"]
"""
4 changes: 4 additions & 0 deletions plugins/module_utils/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
),
required_together=[("username", "password")],
),
machine_type=dict(
type="str",
choices=["BIOS", "UEFI", "vTPM+UEFI", "vTPM+UEFI-compatible"],
),
)


Expand Down
Loading