| 1 |
--- |
| 2 |
#################################################################### |
| 3 |
# WARNING: These are designed specifically for Ansible tests # |
| 4 |
# and should not be used as examples of how to write Ansible roles # |
| 5 |
#################################################################### |
| 6 |
|
| 7 |
# test code for the one_template module |
| 8 |
# Copyright (c) Ansible Project |
| 9 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 10 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 11 |
|
| 12 |
# ENVIRONMENT PREPARATION |
| 13 |
|
| 14 |
- name: "copy fixtures to test host" |
| 15 |
copy: |
| 16 |
src: testhost/tmp/opennebula-fixtures.json.gz |
| 17 |
dest: /tmp |
| 18 |
when: |
| 19 |
- opennebula_test_fixture |
| 20 |
- opennebula_test_fixture_replay |
| 21 |
|
| 22 |
|
| 23 |
# Create a new template |
| 24 |
|
| 25 |
- name: "Create a new TEMPLATE" |
| 26 |
one_template: |
| 27 |
api_url: "{{ opennebula_url }}" |
| 28 |
api_username: "{{ opennebula_username }}" |
| 29 |
api_password: "{{ opennebula_password }}" |
| 30 |
name: ansible-onetemplate-test |
| 31 |
template: | |
| 32 |
CONTEXT = [ |
| 33 |
HOSTNAME = "ansible-onetemplate", |
| 34 |
NETWORK = "YES", |
| 35 |
SSH_PUBLIC_KEY = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKAQwTkU84eEnhX3r60Mn5TPh99BDxyCNJu12OB5sfMu foxy@FoxPad", |
| 36 |
USERNAME = "root" ] |
| 37 |
CPU = "1" |
| 38 |
CUSTOM_ATTRIBUTE = "" |
| 39 |
DISK = [ |
| 40 |
CACHE = "writeback", |
| 41 |
DEV_PREFIX = "sd", |
| 42 |
DISCARD = "unmap", |
| 43 |
IMAGE = "ansible-onetemplate", |
| 44 |
IMAGE_UNAME = "oneadmin", |
| 45 |
IO = "threads", |
| 46 |
SIZE = "" ] |
| 47 |
FEATURES = [ |
| 48 |
VIRTIO_SCSI_QUEUES = "2" ] |
| 49 |
GRAPHICS = [ |
| 50 |
KEYMAP = "de", |
| 51 |
LISTEN = "0.0.0.0", |
| 52 |
TYPE = "VNC" ] |
| 53 |
MEMORY = "2048" |
| 54 |
NIC = [ |
| 55 |
MODEL = "virtio", |
| 56 |
NETWORK = "tf-prd-centos", |
| 57 |
NETWORK_UNAME = "oneadmin" ] |
| 58 |
OS = [ |
| 59 |
ARCH = "x86_64", |
| 60 |
BOOT = "disk0" ] |
| 61 |
SCHED_REQUIREMENTS = "CLUSTER_ID=\"100\"" |
| 62 |
VCPU = "2" |
| 63 |
environment: |
| 64 |
PYONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}" |
| 65 |
PYONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz |
| 66 |
PYONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}" |
| 67 |
PYONE_TEST_FIXTURE_UNIT: test_create_template |
| 68 |
register: result |
| 69 |
|
| 70 |
- name: "assert that creation worked" |
| 71 |
assert: |
| 72 |
that: |
| 73 |
- result is changed |
| 74 |
|
| 75 |
|
| 76 |
# Updating a template |
| 77 |
|
| 78 |
- name: "Update an existing TEMPLATE" |
| 79 |
one_template: |
| 80 |
api_url: "{{ opennebula_url }}" |
| 81 |
api_username: "{{ opennebula_username }}" |
| 82 |
api_password: "{{ opennebula_password }}" |
| 83 |
name: ansible-onetemplate-test |
| 84 |
template: | |
| 85 |
CONTEXT = [ |
| 86 |
HOSTNAME = "ansible-onetemplate", |
| 87 |
NETWORK = "YES", |
| 88 |
SSH_PUBLIC_KEY = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKAQwTkU84eEnhX3r60Mn5TPh99BDxyCNJu12OB5sfMu foxy@FoxPad", |
| 89 |
USERNAME = "root" ] |
| 90 |
CPU = "1" |
| 91 |
CUSTOM_ATTRIBUTE = "" |
| 92 |
DISK = [ |
| 93 |
CACHE = "writeback", |
| 94 |
DEV_PREFIX = "sd", |
| 95 |
DISCARD = "unmap", |
| 96 |
IMAGE = "ansible-onetemplate", |
| 97 |
IMAGE_UNAME = "oneadmin", |
| 98 |
IO = "threads", |
| 99 |
SIZE = "" ] |
| 100 |
FEATURES = [ |
| 101 |
VIRTIO_SCSI_QUEUES = "2" ] |
| 102 |
GRAPHICS = [ |
| 103 |
KEYMAP = "de", |
| 104 |
LISTEN = "0.0.0.0", |
| 105 |
TYPE = "VNC" ] |
| 106 |
MEMORY = "4096" |
| 107 |
NIC = [ |
| 108 |
MODEL = "virtio", |
| 109 |
NETWORK = "tf-prd-centos", |
| 110 |
NETWORK_UNAME = "oneadmin" ] |
| 111 |
OS = [ |
| 112 |
ARCH = "x86_64", |
| 113 |
BOOT = "disk0" ] |
| 114 |
SCHED_REQUIREMENTS = "CLUSTER_ID=\"100\"" |
| 115 |
VCPU = "2" |
| 116 |
environment: |
| 117 |
PYONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}" |
| 118 |
PYONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz |
| 119 |
PYONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}" |
| 120 |
PYONE_TEST_FIXTURE_UNIT: test_update_existing_template |
| 121 |
register: result |
| 122 |
|
| 123 |
- name: "assert that it updated the template" |
| 124 |
assert: |
| 125 |
that: |
| 126 |
- result is changed |
| 127 |
|
| 128 |
- name: "Update an existing TEMPLATE with the same changes again" |
| 129 |
one_template: |
| 130 |
api_url: "{{ opennebula_url }}" |
| 131 |
api_username: "{{ opennebula_username }}" |
| 132 |
api_password: "{{ opennebula_password }}" |
| 133 |
name: ansible-onetemplate-test |
| 134 |
template: | |
| 135 |
CONTEXT = [ |
| 136 |
HOSTNAME = "ansible-onetemplate", |
| 137 |
NETWORK = "YES", |
| 138 |
SSH_PUBLIC_KEY = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKAQwTkU84eEnhX3r60Mn5TPh99BDxyCNJu12OB5sfMu foxy@FoxPad", |
| 139 |
USERNAME = "root" ] |
| 140 |
CPU = "1" |
| 141 |
CUSTOM_ATTRIBUTE = "" |
| 142 |
DISK = [ |
| 143 |
CACHE = "writeback", |
| 144 |
DEV_PREFIX = "sd", |
| 145 |
DISCARD = "unmap", |
| 146 |
IMAGE = "ansible-onetemplate", |
| 147 |
IMAGE_UNAME = "oneadmin", |
| 148 |
IO = "threads", |
| 149 |
SIZE = "" ] |
| 150 |
FEATURES = [ |
| 151 |
VIRTIO_SCSI_QUEUES = "2" ] |
| 152 |
GRAPHICS = [ |
| 153 |
KEYMAP = "de", |
| 154 |
LISTEN = "0.0.0.0", |
| 155 |
TYPE = "VNC" ] |
| 156 |
MEMORY = "4096" |
| 157 |
NIC = [ |
| 158 |
MODEL = "virtio", |
| 159 |
NETWORK = "tf-prd-centos", |
| 160 |
NETWORK_UNAME = "oneadmin" ] |
| 161 |
OS = [ |
| 162 |
ARCH = "x86_64", |
| 163 |
BOOT = "disk0" ] |
| 164 |
SCHED_REQUIREMENTS = "CLUSTER_ID=\"100\"" |
| 165 |
VCPU = "2" |
| 166 |
environment: |
| 167 |
PYONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}" |
| 168 |
PYONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz |
| 169 |
PYONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}" |
| 170 |
PYONE_TEST_FIXTURE_UNIT: test_update_existing_and_already_updated_template |
| 171 |
register: result |
| 172 |
|
| 173 |
- name: "assert that there was no change" |
| 174 |
assert: |
| 175 |
that: |
| 176 |
- result is not changed |
| 177 |
|
| 178 |
|
| 179 |
# Deletion of templates |
| 180 |
|
| 181 |
- name: "Delete a nonexisting TEMPLATE" |
| 182 |
one_template: |
| 183 |
api_url: "{{ opennebula_url }}" |
| 184 |
api_username: "{{ opennebula_username }}" |
| 185 |
api_password: "{{ opennebula_password }}" |
| 186 |
name: ansible-onetemplate-test-nonexisting |
| 187 |
state: absent |
| 188 |
environment: |
| 189 |
PYONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}" |
| 190 |
PYONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz |
| 191 |
PYONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}" |
| 192 |
PYONE_TEST_FIXTURE_UNIT: test_delete_nonexisting_template |
| 193 |
register: result |
| 194 |
|
| 195 |
- name: "assert that there was no change" |
| 196 |
assert: |
| 197 |
that: |
| 198 |
- result is not changed |
| 199 |
|
| 200 |
- name: "Delete an existing TEMPLATE" |
| 201 |
one_template: |
| 202 |
api_url: "{{ opennebula_url }}" |
| 203 |
api_username: "{{ opennebula_username }}" |
| 204 |
api_password: "{{ opennebula_password }}" |
| 205 |
name: ansible-onetemplate-test |
| 206 |
state: absent |
| 207 |
environment: |
| 208 |
PYONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}" |
| 209 |
PYONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz |
| 210 |
PYONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}" |
| 211 |
PYONE_TEST_FIXTURE_UNIT: test_delete_existing_template |
| 212 |
register: result |
| 213 |
|
| 214 |
- name: "assert that there was a change" |
| 215 |
assert: |
| 216 |
that: |
| 217 |
- result is changed |
| 218 |
|
| 219 |
|
| 220 |
# Usage without `template` parameter |
| 221 |
|
| 222 |
- name: "Try to create use one_template with state=present and without the template parameter" |
| 223 |
one_template: |
| 224 |
api_url: "{{ opennebula_url }}" |
| 225 |
api_username: "{{ opennebula_username }}" |
| 226 |
api_password: "{{ opennebula_password }}" |
| 227 |
name: ansible-onetemplate-test |
| 228 |
state: present |
| 229 |
register: result |
| 230 |
ignore_errors: true |
| 231 |
|
| 232 |
- name: "assert that it failed because template is missing" |
| 233 |
assert: |
| 234 |
that: |
| 235 |
- result is failed |
| 236 |
|
| 237 |
|
| 238 |
# TEARDOWN |
| 239 |
|
| 240 |
- name: "fetch fixtures" |
| 241 |
fetch: |
| 242 |
src: /tmp/opennebula-fixtures.json.gz |
| 243 |
dest: targets/one_host/files |
| 244 |
when: |
| 245 |
- opennebula_test_fixture |
| 246 |
- not opennebula_test_fixture_replay |