mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
opennebula: new module one_host (#40041)
This commit is contained in:
20
test/integration/cloud-config-opennebula.yml.template
Normal file
20
test/integration/cloud-config-opennebula.yml.template
Normal file
@@ -0,0 +1,20 @@
|
||||
# This is the configuration template for ansible-test OpenNebula integration tests.
|
||||
#
|
||||
# You do not need this template if you are:
|
||||
#
|
||||
# 1) Running integration tests without using ansible-test.
|
||||
# 2) Running integration tests against previously recorded XMLRPC fixtures
|
||||
#
|
||||
# If you want to test against a Live OpenNebula platform,
|
||||
# fill in the values below and save this file without the .template extension.
|
||||
# This will cause ansible-test to use the given configuration.
|
||||
#
|
||||
# If you run with @FIXTURES enabled (true) then you can decide if you want to
|
||||
# run in @REPLAY mode (true) or, record mode (false).
|
||||
|
||||
|
||||
opennebula_url: @URL
|
||||
opennebula_username: @USERNAME
|
||||
opennebula_password: @PASSWORD
|
||||
opennebula_test_fixture: @FIXTURES
|
||||
opennebula_test_fixture_replay: @REPLAY
|
||||
2
test/integration/targets/one_host/aliases
Normal file
2
test/integration/targets/one_host/aliases
Normal file
@@ -0,0 +1,2 @@
|
||||
cloud/opennebula
|
||||
posix/ci/cloud/group4/opennebula
|
||||
Binary file not shown.
2
test/integration/targets/one_host/meta/main.yml
Normal file
2
test/integration/targets/one_host/meta/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
dependencies:
|
||||
- setup_opennebula
|
||||
235
test/integration/targets/one_host/tasks/main.yml
Normal file
235
test/integration/targets/one_host/tasks/main.yml
Normal file
@@ -0,0 +1,235 @@
|
||||
# test code for the one_host module
|
||||
|
||||
|
||||
# ENVIRONENT PREPARACTION
|
||||
|
||||
- set_fact: test_number= 0
|
||||
|
||||
- name: "test_{{test_number}}: copy fixtures to test host"
|
||||
copy:
|
||||
src: testhost/tmp/opennebula-fixtures.json.gz
|
||||
dest: /tmp
|
||||
when:
|
||||
- opennebula_test_fixture
|
||||
- opennebula_test_fixture_replay
|
||||
|
||||
|
||||
# SETUP INITIAL TESTING CONDITION
|
||||
|
||||
- set_fact: test_number={{ test_number | int + 1 }}
|
||||
|
||||
- name: "test_{{test_number}}: ensure the tests hosts are absent"
|
||||
one_host:
|
||||
name: "{{ item }}"
|
||||
state: absent
|
||||
api_endpoint: "{{ opennebula_url }}"
|
||||
api_username: "{{ opennebula_username }}"
|
||||
api_token: "{{ opennebula_password }}"
|
||||
validate_certs: false
|
||||
environment:
|
||||
ONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
|
||||
ONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
|
||||
ONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
|
||||
ONE_TEST_FIXTURE_UNIT: "test_{{test_number}}_{{ item }}"
|
||||
with_items: "{{opennebula_test.hosts}}"
|
||||
register: result
|
||||
|
||||
# NOT EXISTING HOSTS
|
||||
|
||||
- set_fact: test_number={{ test_number | int + 1 }}
|
||||
|
||||
- name: "test_{{test_number}}: attempt to enable a host that does not exists"
|
||||
one_host:
|
||||
name: badhost
|
||||
state: "{{item}}"
|
||||
api_url: "{{ opennebula_url }}"
|
||||
api_username: "{{ opennebula_username }}"
|
||||
api_password: "{{ opennebula_password }}"
|
||||
validate_certs: false
|
||||
environment:
|
||||
ONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
|
||||
ONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
|
||||
ONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
|
||||
ONE_TEST_FIXTURE_UNIT: "test_{{test_number}}_{{item}}"
|
||||
ignore_errors: true
|
||||
register: result
|
||||
with_items:
|
||||
- enabled
|
||||
- disabled
|
||||
- offline
|
||||
|
||||
- name: "assert test_{{test_number}} failed"
|
||||
assert:
|
||||
that:
|
||||
- result is failed
|
||||
- result.results[0].msg == 'invalid host state ERROR'
|
||||
|
||||
# ---
|
||||
|
||||
- set_fact: test_number={{ test_number | int + 1 }}
|
||||
|
||||
- name: "test_{{test_number}}: delete an unexisting host"
|
||||
one_host:
|
||||
name: badhost
|
||||
state: absent
|
||||
api_url: "{{ opennebula_url }}"
|
||||
api_username: "{{ opennebula_username }}"
|
||||
api_password: "{{ opennebula_password }}"
|
||||
validate_certs: false
|
||||
environment:
|
||||
ONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
|
||||
ONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
|
||||
ONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
|
||||
ONE_TEST_FIXTURE_UNIT: "test_{{test_number}}"
|
||||
register: result
|
||||
|
||||
- name: "assert test_{{test_number}} worked"
|
||||
assert:
|
||||
that:
|
||||
- result.changed
|
||||
|
||||
# HOST ENABLEMENT
|
||||
|
||||
- set_fact: test_number={{ test_number | int + 1 }}
|
||||
|
||||
|
||||
- name: "test_{{test_number}}: enable the test hosts"
|
||||
one_host:
|
||||
name: "{{ item }}"
|
||||
state: enabled
|
||||
api_url: "{{ opennebula_url }}"
|
||||
api_username: "{{ opennebula_username }}"
|
||||
api_password: "{{ opennebula_password }}"
|
||||
validate_certs: false
|
||||
environment:
|
||||
ONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
|
||||
ONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
|
||||
ONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
|
||||
ONE_TEST_FIXTURE_UNIT: "test_{{test_number}}_{{ item }}"
|
||||
with_items: "{{opennebula_test.hosts}}"
|
||||
register: result
|
||||
|
||||
- name: "assert test_{{test_number}} worked"
|
||||
assert:
|
||||
that:
|
||||
- result.changed
|
||||
|
||||
# TEMPLATE MANAGEMENT
|
||||
|
||||
- set_fact: test_number={{ test_number | int + 1 }}
|
||||
|
||||
- name: "test_{{test_number}}: setup template values on hosts"
|
||||
one_host:
|
||||
name: "{{ item }}"
|
||||
state: enabled
|
||||
api_url: "{{ opennebula_url }}"
|
||||
api_username: "{{ opennebula_username }}"
|
||||
api_password: "{{ opennebula_password }}"
|
||||
validate_certs: false
|
||||
template:
|
||||
LABELS:
|
||||
- test
|
||||
- custom
|
||||
TEST_VALUE: 2
|
||||
environment:
|
||||
ONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
|
||||
ONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
|
||||
ONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
|
||||
ONE_TEST_FIXTURE_UNIT: "test_{{test_number}}_{{ item }}"
|
||||
with_items: "{{opennebula_test.hosts}}"
|
||||
register: result
|
||||
|
||||
- name: "assert test_{{test_number}} worked"
|
||||
assert:
|
||||
that:
|
||||
- result.changed
|
||||
|
||||
# ---
|
||||
|
||||
- set_fact: test_number={{ test_number | int + 1 }}
|
||||
|
||||
- name: "test_{{test_number}}: setup equivalent template values on hosts"
|
||||
one_host:
|
||||
name: "{{ item }}"
|
||||
state: enabled
|
||||
api_url: "{{ opennebula_url }}"
|
||||
api_username: "{{ opennebula_username }}"
|
||||
api_password: "{{ opennebula_password }}"
|
||||
validate_certs: false
|
||||
labels:
|
||||
- test
|
||||
- custom
|
||||
attributes:
|
||||
TEST_VALUE: "2"
|
||||
environment:
|
||||
ONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
|
||||
ONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
|
||||
ONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
|
||||
ONE_TEST_FIXTURE_UNIT: "test_{{test_number}}_{{ item }}"
|
||||
with_items: "{{opennebula_test.hosts}}"
|
||||
register: result
|
||||
|
||||
- name: "assert test_{{test_number}} worked"
|
||||
assert:
|
||||
that:
|
||||
- result.changed == false
|
||||
|
||||
# HOST DISABLEMENT
|
||||
|
||||
- set_fact: test_number={{ test_number | int + 1 }}
|
||||
|
||||
- name: "test_{{test_number}}: disable the test hosts"
|
||||
one_host:
|
||||
name: "{{ item }}"
|
||||
state: disabled
|
||||
api_url: "{{ opennebula_url }}"
|
||||
api_username: "{{ opennebula_username }}"
|
||||
api_password: "{{ opennebula_password }}"
|
||||
validate_certs: false
|
||||
environment:
|
||||
ONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
|
||||
ONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
|
||||
ONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
|
||||
ONE_TEST_FIXTURE_UNIT: "test_{{test_number}}_{{ item }}"
|
||||
with_items: "{{opennebula_test.hosts}}"
|
||||
register: result
|
||||
|
||||
- name: "assert test_{{test_number}} worked"
|
||||
assert:
|
||||
that:
|
||||
- result.changed
|
||||
|
||||
# HOST OFFLINE
|
||||
|
||||
- set_fact: test_number={{ test_number | int + 1 }}
|
||||
|
||||
- name: "test_{{test_number}}: offline the test hosts"
|
||||
one_host:
|
||||
name: "{{ item }}"
|
||||
state: offline
|
||||
api_url: "{{ opennebula_url }}"
|
||||
api_username: "{{ opennebula_username }}"
|
||||
api_password: "{{ opennebula_password }}"
|
||||
validate_certs: false
|
||||
environment:
|
||||
ONE_TEST_FIXTURE: "{{ opennebula_test_fixture }}"
|
||||
ONE_TEST_FIXTURE_FILE: /tmp/opennebula-fixtures.json.gz
|
||||
ONE_TEST_FIXTURE_REPLAY: "{{ opennebula_test_fixture_replay }}"
|
||||
ONE_TEST_FIXTURE_UNIT: "test_{{test_number}}_{{ item }}"
|
||||
with_items: "{{opennebula_test.hosts}}"
|
||||
register: result
|
||||
|
||||
- name: "assert test_{{test_number}} worked"
|
||||
assert:
|
||||
that:
|
||||
- result.changed
|
||||
|
||||
# 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
|
||||
6
test/integration/targets/setup_opennebula/vars/main.yml
Normal file
6
test/integration/targets/setup_opennebula/vars/main.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
|
||||
opennebula_test:
|
||||
hosts:
|
||||
- hv1
|
||||
- hv2
|
||||
61
test/runner/lib/cloud/opennebula.py
Normal file
61
test/runner/lib/cloud/opennebula.py
Normal file
@@ -0,0 +1,61 @@
|
||||
"""OpenNebula plugin for integration tests."""
|
||||
|
||||
import os
|
||||
|
||||
from lib.cloud import (
|
||||
CloudProvider,
|
||||
CloudEnvironment
|
||||
)
|
||||
|
||||
from lib.util import (
|
||||
find_executable,
|
||||
ApplicationError,
|
||||
display,
|
||||
is_shippable,
|
||||
)
|
||||
|
||||
|
||||
class OpenNebulaCloudProvider(CloudProvider):
|
||||
"""Checks if a configuration file has been passed or fixtures are going to be used for testing"""
|
||||
|
||||
def filter(self, targets, exclude):
|
||||
""" no need to filter modules, they can either run from config file or from fixtures"""
|
||||
pass
|
||||
|
||||
def setup(self):
|
||||
"""Setup the cloud resource before delegation and register a cleanup callback."""
|
||||
super(OpenNebulaCloudProvider, self).setup()
|
||||
|
||||
if not self._use_static_config():
|
||||
self._setup_dynamic()
|
||||
|
||||
def _setup_dynamic(self):
|
||||
display.info('No config file provided, will run test from fixtures')
|
||||
|
||||
config = self._read_config_template()
|
||||
values = dict(
|
||||
URL="http://localhost/RPC2",
|
||||
USERNAME='oneadmin',
|
||||
PASSWORD='onepass',
|
||||
FIXTURES='true',
|
||||
REPLAY='true',
|
||||
)
|
||||
config = self._populate_config_template(config, values)
|
||||
self._write_config(config)
|
||||
|
||||
|
||||
class OpenNebulaCloudEnvironment(CloudEnvironment):
|
||||
"""
|
||||
Updates integration test environment after delegation. Will setup the config file as parameter.
|
||||
"""
|
||||
|
||||
def configure_environment(self, env, cmd):
|
||||
"""
|
||||
:type env: dict[str, str]
|
||||
:type cmd: list[str]
|
||||
"""
|
||||
cmd.append('-e')
|
||||
cmd.append('@%s' % self.config_path)
|
||||
|
||||
cmd.append('-e')
|
||||
cmd.append('resource_prefix=%s' % self.resource_prefix)
|
||||
@@ -0,0 +1 @@
|
||||
pyone
|
||||
Reference in New Issue
Block a user