mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-08 14:20:04 -07:00
opennebula: add one_template module (#2046)
* opennebula: add one_template module A basic module for maintaining VM templates which should be flexible enough for most needs ... * fixup! opennebula: add one_template module * fixup! fixup! opennebula: add one_template module
This commit is contained in:
parent
e7a0a12c3f
commit
cdc415ea1f
6 changed files with 527 additions and 3 deletions
2
tests/integration/targets/one_template/aliases
Normal file
2
tests/integration/targets/one_template/aliases
Normal file
|
@ -0,0 +1,2 @@
|
|||
cloud/opennebula
|
||||
shippable/cloud/group1
|
Binary file not shown.
243
tests/integration/targets/one_template/tasks/main.yml
Normal file
243
tests/integration/targets/one_template/tasks/main.yml
Normal file
|
@ -0,0 +1,243 @@
|
|||
####################################################################
|
||||
# WARNING: These are designed specifically for Ansible tests #
|
||||
# and should not be used as examples of how to write Ansible roles #
|
||||
####################################################################
|
||||
|
||||
# test code for the one_template module
|
||||
|
||||
|
||||
# ENVIRONMENT PREPARATION
|
||||
|
||||
- name: "copy fixtures to test host"
|
||||
copy:
|
||||
src: testhost/tmp/opennebula-fixtures.json.gz
|
||||
dest: /tmp
|
||||
when:
|
||||
- opennebula_test_fixture
|
||||
- opennebula_test_fixture_replay
|
||||
|
||||
|
||||
# Create a new template
|
||||
|
||||
- name: "Create a new TEMPLATE"
|
||||
one_template:
|
||||
api_url: "{{ opennebula_url }}"
|
||||
api_username: "{{ opennebula_username }}"
|
||||
api_password: "{{ opennebula_password }}"
|
||||
name: ansible-onetemplate-test
|
||||
template: |
|
||||
CONTEXT = [
|
||||
HOSTNAME = "ansible-onetemplate",
|
||||
NETWORK = "YES",
|
||||
SSH_PUBLIC_KEY = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKAQwTkU84eEnhX3r60Mn5TPh99BDxyCNJu12OB5sfMu foxy@FoxPad",
|
||||
USERNAME = "root" ]
|
||||
CPU = "1"
|
||||
CUSTOM_ATTRIBUTE = ""
|
||||
DISK = [
|
||||
CACHE = "writeback",
|
||||
DEV_PREFIX = "sd",
|
||||
DISCARD = "unmap",
|
||||
IMAGE = "ansible-onetemplate",
|
||||
IMAGE_UNAME = "oneadmin",
|
||||
IO = "threads",
|
||||
SIZE = "" ]
|
||||
FEATURES = [
|
||||
VIRTIO_SCSI_QUEUES = "2" ]
|
||||
GRAPHICS = [
|
||||
KEYMAP = "de",
|
||||
LISTEN = "0.0.0.0",
|
||||
TYPE = "VNC" ]
|
||||
MEMORY = "2048"
|
||||
NIC = [
|
||||
MODEL = "virtio",
|
||||
NETWORK = "tf-prd-centos",
|
||||
NETWORK_UNAME = "oneadmin" ]
|
||||
OS = [
|
||||
ARCH = "x86_64",
|
||||
BOOT = "disk0" ]
|
||||
SCHED_REQUIREMENTS = "CLUSTER_ID=\"100\""
|
||||
VCPU = "2"
|
||||
environment:
|
||||
PYONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
|
||||
PYONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
|
||||
PYONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
|
||||
PYONE_TEST_FIXTURE_UNIT: test_create_template
|
||||
register: result
|
||||
|
||||
- name: "assert that creation worked"
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
|
||||
# Updating a template
|
||||
|
||||
- name: "Update an existing TEMPLATE"
|
||||
one_template:
|
||||
api_url: "{{ opennebula_url }}"
|
||||
api_username: "{{ opennebula_username }}"
|
||||
api_password: "{{ opennebula_password }}"
|
||||
name: ansible-onetemplate-test
|
||||
template: |
|
||||
CONTEXT = [
|
||||
HOSTNAME = "ansible-onetemplate",
|
||||
NETWORK = "YES",
|
||||
SSH_PUBLIC_KEY = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKAQwTkU84eEnhX3r60Mn5TPh99BDxyCNJu12OB5sfMu foxy@FoxPad",
|
||||
USERNAME = "root" ]
|
||||
CPU = "1"
|
||||
CUSTOM_ATTRIBUTE = ""
|
||||
DISK = [
|
||||
CACHE = "writeback",
|
||||
DEV_PREFIX = "sd",
|
||||
DISCARD = "unmap",
|
||||
IMAGE = "ansible-onetemplate",
|
||||
IMAGE_UNAME = "oneadmin",
|
||||
IO = "threads",
|
||||
SIZE = "" ]
|
||||
FEATURES = [
|
||||
VIRTIO_SCSI_QUEUES = "2" ]
|
||||
GRAPHICS = [
|
||||
KEYMAP = "de",
|
||||
LISTEN = "0.0.0.0",
|
||||
TYPE = "VNC" ]
|
||||
MEMORY = "4096"
|
||||
NIC = [
|
||||
MODEL = "virtio",
|
||||
NETWORK = "tf-prd-centos",
|
||||
NETWORK_UNAME = "oneadmin" ]
|
||||
OS = [
|
||||
ARCH = "x86_64",
|
||||
BOOT = "disk0" ]
|
||||
SCHED_REQUIREMENTS = "CLUSTER_ID=\"100\""
|
||||
VCPU = "2"
|
||||
environment:
|
||||
PYONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
|
||||
PYONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
|
||||
PYONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
|
||||
PYONE_TEST_FIXTURE_UNIT: test_update_existing_template
|
||||
register: result
|
||||
|
||||
- name: "assert that it updated the template"
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
- name: "Update an existing TEMPLATE with the same changes again"
|
||||
one_template:
|
||||
api_url: "{{ opennebula_url }}"
|
||||
api_username: "{{ opennebula_username }}"
|
||||
api_password: "{{ opennebula_password }}"
|
||||
name: ansible-onetemplate-test
|
||||
template: |
|
||||
CONTEXT = [
|
||||
HOSTNAME = "ansible-onetemplate",
|
||||
NETWORK = "YES",
|
||||
SSH_PUBLIC_KEY = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKAQwTkU84eEnhX3r60Mn5TPh99BDxyCNJu12OB5sfMu foxy@FoxPad",
|
||||
USERNAME = "root" ]
|
||||
CPU = "1"
|
||||
CUSTOM_ATTRIBUTE = ""
|
||||
DISK = [
|
||||
CACHE = "writeback",
|
||||
DEV_PREFIX = "sd",
|
||||
DISCARD = "unmap",
|
||||
IMAGE = "ansible-onetemplate",
|
||||
IMAGE_UNAME = "oneadmin",
|
||||
IO = "threads",
|
||||
SIZE = "" ]
|
||||
FEATURES = [
|
||||
VIRTIO_SCSI_QUEUES = "2" ]
|
||||
GRAPHICS = [
|
||||
KEYMAP = "de",
|
||||
LISTEN = "0.0.0.0",
|
||||
TYPE = "VNC" ]
|
||||
MEMORY = "4096"
|
||||
NIC = [
|
||||
MODEL = "virtio",
|
||||
NETWORK = "tf-prd-centos",
|
||||
NETWORK_UNAME = "oneadmin" ]
|
||||
OS = [
|
||||
ARCH = "x86_64",
|
||||
BOOT = "disk0" ]
|
||||
SCHED_REQUIREMENTS = "CLUSTER_ID=\"100\""
|
||||
VCPU = "2"
|
||||
environment:
|
||||
PYONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
|
||||
PYONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
|
||||
PYONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
|
||||
PYONE_TEST_FIXTURE_UNIT: test_update_existing_and_already_updated_template
|
||||
register: result
|
||||
|
||||
- name: "assert that there was no change"
|
||||
assert:
|
||||
that:
|
||||
- result is not changed
|
||||
|
||||
|
||||
# Deletion of templates
|
||||
|
||||
- name: "Delete a nonexisting TEMPLATE"
|
||||
one_template:
|
||||
api_url: "{{ opennebula_url }}"
|
||||
api_username: "{{ opennebula_username }}"
|
||||
api_password: "{{ opennebula_password }}"
|
||||
name: ansible-onetemplate-test-nonexisting
|
||||
state: absent
|
||||
environment:
|
||||
PYONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
|
||||
PYONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
|
||||
PYONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
|
||||
PYONE_TEST_FIXTURE_UNIT: test_delete_nonexisting_template
|
||||
register: result
|
||||
|
||||
- name: "assert that there was no change"
|
||||
assert:
|
||||
that:
|
||||
- result is not changed
|
||||
|
||||
- name: "Delete an existing TEMPLATE"
|
||||
one_template:
|
||||
api_url: "{{ opennebula_url }}"
|
||||
api_username: "{{ opennebula_username }}"
|
||||
api_password: "{{ opennebula_password }}"
|
||||
name: ansible-onetemplate-test
|
||||
state: absent
|
||||
environment:
|
||||
PYONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
|
||||
PYONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
|
||||
PYONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
|
||||
PYONE_TEST_FIXTURE_UNIT: test_delete_existing_template
|
||||
register: result
|
||||
|
||||
- name: "assert that there was a change"
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
|
||||
# Usage without `template` parameter
|
||||
|
||||
- name: "Try to create use one_template with state=present and without the template parameter"
|
||||
one_template:
|
||||
api_url: "{{ opennebula_url }}"
|
||||
api_username: "{{ opennebula_username }}"
|
||||
api_password: "{{ opennebula_password }}"
|
||||
name: ansible-onetemplate-test
|
||||
state: present
|
||||
register: result
|
||||
ignore_errors: true
|
||||
|
||||
- name: "assert that it failed because template is missing"
|
||||
assert:
|
||||
that:
|
||||
- result is failed
|
||||
|
||||
|
||||
# TEARDOWN
|
||||
|
||||
- name: "fetch fixtures"
|
||||
fetch:
|
||||
src: /tmp/opennebula-fixtures.json.gz
|
||||
dest: targets/one_host/files
|
||||
when:
|
||||
- opennebula_test_fixture
|
||||
- not opennebula_test_fixture_replay
|
Loading…
Add table
Add a link
Reference in a new issue