tests: vultr: convert legacy tests to targets (#50156)

This commit is contained in:
René Moser 2019-01-07 22:23:54 +01:00 committed by GitHub
parent 618caf2168
commit 48ffe2f3b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
78 changed files with 210 additions and 60 deletions

View file

@ -141,3 +141,39 @@ For example, this allows you to take action on nodes grouped by location or OS n
- name: Rebooting the machine
shell: reboot
become: True
Integration tests
-----------------
Ansible includes integration tests for all Vultr modules.
These tests are meant to run against the public Vultr API and that is why they require a valid key to access the API.
Prepare the test setup:
.. code-block:: shell
$ cd ansible # location the ansible source is
$ source ./hacking/env-setup
Set the Vultr API key:
.. code-block:: shell
$ cd test/integration
$ cp cloud-config-vultr.ini.template cloud-config-vultr.ini
$ vi cloud-config-vultr.ini
Run all Vultr tests:
.. code-block:: shell
$ ansible-test integration cloud/vultr/ -v --diff --allow-unsupported
To run a specific test, e.g. vultr_account_facts:
.. code-block:: shell
$ ansible-test integration cloud/vultr/vultr_account_facts -v --diff --allow-unsupported

View file

@ -0,0 +1,12 @@
# This is the configuration template for ansible-test Vultr integration tests.
#
# You do not need this template if you are:
#
# 1) Running integration tests without using ansible-test.
#
# If you want to test against the Vultr public API,
# fill in the values below and save this file without the .template extension.
# This will cause ansible-test to use the given configuration.
[default]
key = @KEY

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -0,0 +1,5 @@
---
vultr_resource_prefix: "vultr-test-prefix"
vultr_block_storage_name: "{{ vultr_resource_prefix }}-volume"
vultr_block_storage_size: 10
vultr_block_storage_region: New Jersey

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -0,0 +1,5 @@
---
vultr_resource_prefix: "vultr-test-prefix"
vultr_block_storage_name: "{{ vultr_resource_prefix }}-volume"
vultr_block_storage_size: 10
vultr_block_storage_region: New Jersey

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -1,4 +1,5 @@
# Copyright (c) 2018, René Moser <mail@renemoser.net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
vultr_user_name: john
vultr_resource_prefix: "vultr-test-prefix"
vultr_dns_domain_name: "{{ vultr_resource_prefix }}-example-ansible.com"

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -0,0 +1,4 @@
---
vultr_resource_prefix: "vultr-test-prefix"
dns_domain_name: "{{ vultr_resource_prefix }}-example-ansible.com"
dns_domain_server_ip: 104.24.16.59

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -1,7 +1,8 @@
# Copyright (c) 2018, René Moser <mail@renemoser.net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
vultr_dns_domain_name: example-ansible.com
vultr_resource_prefix: "vultr-test-prefix"
vultr_dns_domain_name: "{{ vultr_resource_prefix }}-example-ansible.com"
vultr_dns_record_items:
# Single A record
- name: test-www

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -1,4 +1,5 @@
# Copyright (c) 2018, René Moser <mail@renemoser.net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
vultr_firewall_group_name: ansible-firewall-group
vultr_resource_prefix: "vultr-test-prefix"
vultr_firewall_group_name: "{{ vultr_resource_prefix }}_firewall-group"

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -0,0 +1,3 @@
---
vultr_resource_prefix: "vultr-test-prefix"
firewall_group_name: "{{ vultr_resource_prefix }}_firewall-group"

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -1,4 +1,5 @@
# Copyright (c) 2018, René Moser <mail@renemoser.net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
vultr_dns_domain_name: example-ansible.com
vultr_resource_prefix: "vultr-test-prefix"
vultr_firewall_group_name: "{{ vultr_resource_prefix }}_firewall-group"

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -0,0 +1,5 @@
---
vultr_resource_prefix: "vultr-test-prefix"
vultr_network_name: "{{ vultr_resource_prefix }}_network"
vultr_network_cidr: 192.168.42.0/24
vultr_network_region: New Jersey

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -0,0 +1,5 @@
---
vultr_resource_prefix: "vultr_test_prefix"
vultr_network_name: "{{ vultr_resource_prefix }}_network"
vultr_network_cidr: 192.168.42.0/24
vultr_network_region: New Jersey

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -1,7 +1,8 @@
# Copyright (c) 2018, René Moser <mail@renemoser.net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
vultr_server_name: ansible-test-vm1
vultr_resource_prefix: "vultr-test-prefix"
vultr_server_name: "{{ vultr_resource_prefix }}_vm"
vultr_server_ssh_keys:
- name: key1
key: "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEAyWYItY+3w5b8PdGRoz0oY5mufqydW96naE+VM3JSvJFAUS08rAjQQpQ03ymoALeHQy6JVZbcgecxn6p0pAOINQdqufn4udPtOPCtMjNiPGpkSM9ah/6X5+kvyWMNrvlf+Ld4OOoszP5sAkgQzIbrFQAm41XknBUha0zkewZwfrVhain4pnDjV7wCcChId/Q/Gbi4xMtXkisznWcAJcueBs3EEZDKhJ5q0VeWSJEhYJDLFN1sOxF0AIUnMrOhfKQ/LjgREXPB6uCl899INUTXRNNjRpeMXyJ2wMMmOAbua2qEd1r13Bu1n+6A823Hzb33fyMXuqWnJwBJ4DCvMlGuEsfuOK+xk7DaBfLHbcM6fsPk0/4psTE6YLgC41remr6+u5ZWsY/faMtSnNPie8Z8Ov0DIYGdhbJjUXk1HomxRV9+ZfZ2Ob8iCwlaAQAyEUM6fs3Kxt8pBD8dx1HOkhsfBWPvuDr5y+kqE7H8/MuPDTc0QgH2pjUMpmw/XBwNDHshVEjrZvtICOjOLUJxcowLO1ivNYwPwowQxfisMy56LfYdjsOslBiqsrkAqvNGm1zu8wKHeqVN9w5l3yUELpvubfm9NKIvYcl6yWF36T0c5vE+g0DU/Jy4XpTj0hZG9QV2mRQcLJnd2pxQtJT7cPFtrn/+tgRxzjEtbDXummDV4sE= mail@renemoser.net"

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -1,4 +1,6 @@
vultr_server_name: ansibletest
---
vultr_resource_prefix: "vultr-test-prefix"
vultr_server_name: "{{ vultr_resource_prefix }}_vm"
vultr_server_os: CentOS 7 x64
vultr_server_plan: 1024 MB RAM,25 GB SSD,1.00 TB BW
vultr_server_region: Amsterdam

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -1,6 +1,7 @@
# Copyright (c) 2018, René Moser <mail@renemoser.net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
vultr_ssh_key_name: ansible-ssh-key
vultr_resource_prefix: "vultr-test-prefix"
vultr_ssh_key_name: "{{ vultr_resource_prefix }}_ansible-ssh-key"
vultr_ssh_key: "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEAyWYItY+3w5b8PdGRoz0oY5mufqydW96naE+VM3JSvJFAUS08rAjQQpQ03ymoALeHQy6JVZbcgecxn6p0pAOINQdqufn4udPtOPCtMjNiPGpkSM9ah/6X5+kvyWMNrvlf+Ld4OOoszP5sAkgQzIbrFQAm41XknBUha0zkewZwfrVhain4pnDjV7wCcChId/Q/Gbi4xMtXkisznWcAJcueBs3EEZDKhJ5q0VeWSJEhYJDLFN1sOxF0AIUnMrOhfKQ/LjgREXPB6uCl899INUTXRNNjRpeMXyJ2wMMmOAbua2qEd1r13Bu1n+6A823Hzb33fyMXuqWnJwBJ4DCvMlGuEsfuOK+xk7DaBfLHbcM6fsPk0/4psTE6YLgC41remr6+u5ZWsY/faMtSnNPie8Z8Ov0DIYGdhbJjUXk1HomxRV9+ZfZ2Ob8iCwlaAQAyEUM6fs3Kxt8pBD8dx1HOkhsfBWPvuDr5y+kqE7H8/MuPDTc0QgH2pjUMpmw/XBwNDHshVEjrZvtICOjOLUJxcowLO1ivNYwPwowQxfisMy56LfYdjsOslBiqsrkAqvNGm1zu8wKHeqVN9w5l3yUELpvubfm9NKIvYcl6yWF36T0c5vE+g0DU/Jy4XpTj0hZG9QV2mRQcLJnd2pxQtJT7cPFtrn/+tgRxzjEtbDXummDV4sE= ansible@example.com"
vultr_ssh_key2: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCoQ9S7V+CufAgwoehnf2TqsJ9LTsu8pUA3FgpS2mdVwcMcTs++8P5sQcXHLtDmNLpWN4k7NQgxaY1oXy5e25x/4VhXaJXWEt3luSw+Phv/PB2+aGLvqCUirsLTAD2r7ieMhd/pcVf/HlhNUQgnO1mupdbDyqZoGD/uCcJiYav8i/V7nJWJouHA8yq31XS2yqXp9m3VC7UZZHzUsVJA9Us5YqF0hKYeaGruIHR2bwoDF9ZFMss5t6/pzxMljU/ccYwvvRDdI7WX4o4+zLuZ6RWvsU6LGbbb0pQdB72tlV41fSefwFsk4JRdKbyV3Xjf25pV4IXOTcqhy+4JTB/jXxrF torwalds@github.com"

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -1,2 +1,4 @@
ssh_key_name: ansibletest-sshkey
---
vultr_resource_prefix: "vultr_test_prefix"
ssh_key_name: "{{ vultr_resource_prefix }}-sshkey"
ssh_key_content: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+ZFQv3MyjtL1BMpSA0o0gIkzLVVC711rthT29hBNeORdNowQ7FSvVWUdAbTq00U7Xzak1ANIYLJyn+0r7olsdG4XEiUR0dqgC99kbT/QhY5mLe5lpl7JUjW9ctn00hNmt+TswpatCKWPNwdeAJT2ERynZaqPobENgvIq7jfOFWQIVew7qrewtqwerqwrewUr2Cdq7Nb7U0XFXh3x1p0v0+MbL4tiJwPlMAGvFTKIMt+EaA+AsRIxiOo9CMk5ZuOl9pT8h5vNuEOcvS0qx4v44EAD2VOsCVCcrPNMcpuSzZP8dRTGU9wRREAWXngD0Zq9YJMH38VTxHiskoBw1NnPz ansibletest@sshkey

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -1,6 +1,7 @@
# Copyright (c) 2018, René Moser <mail@renemoser.net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
vultr_startup_script_name: ansible_test_script
vultr_resource_prefix: "vultr-test-prefix"
vultr_startup_script_name: "{{ vultr_resource_prefix }}_script"
vultr_startup_script: "#!/bin/bash\necho Hello World > /root/hello"
vultr_startup_script2: "#!/bin/bash\necho Hello to my World > /root/hello"

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -0,0 +1,4 @@
vultr_resource_prefix: "vultr_test_prefix"
startup_script_name: "{{ vultr_resource_prefix }}_script"
startup_script_type: boot
startup_script_content: "#!/bin/bash\necho Hello World > /root/hello"

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -1,4 +1,5 @@
# Copyright (c) 2018, René Moser <mail@renemoser.net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
vultr_firewall_group_name: ansible-firewall-group
vultr_resource_prefix: "vultr-test-prefix"
vultr_user_name: "{{ vultr_resource_prefix }}_user"

View file

@ -0,0 +1,2 @@
cloud/vultr
unsupported

View file

@ -1,4 +1,6 @@
user_name: mytestuser
---
vultr_resource_prefix: "vultr-test-prefix"
user_name: "{{ vultr_resource_prefix }}_user"
user_email: mytestuser@example.com
user_password: aP4ssw0rd!
user_acls:

View file

@ -1,4 +0,0 @@
---
vultr_block_storage_name: ansible-test-vm1
vultr_block_storage_size: 10
vultr_block_storage_region: New Jersey

View file

@ -1,3 +0,0 @@
vultr_block_storage_name: ansibletest-volume
vultr_block_storage_size: 10
vultr_block_storage_region: New Jersey

View file

@ -1,2 +0,0 @@
dns_domain_name: ansibletest.com
dns_domain_server_ip: 104.24.16.59

View file

@ -1 +0,0 @@
firewall_group_name: mytestfirewallgroup

View file

@ -1,4 +0,0 @@
---
vultr_network_name: ansible-test-network
vultr_network_cidr: 192.168.42.0/24
vultr_network_region: New Jersey

View file

@ -1,3 +0,0 @@
vultr_network_name: mytestnetwork
vultr_network_cidr: 192.168.42.0/24
vultr_network_region: New Jersey

View file

@ -1,3 +0,0 @@
startup_script_name: myteststartupscript
startup_script_type: boot
startup_script_content: "#!/bin/bash\necho Hello World > /root/hello"

View file

@ -1,29 +0,0 @@
# Copyright (c) 2018, René Moser <mail@renemoser.net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
- hosts: localhost
gather_facts: no
connection: local
roles:
- { role: vultr_account_facts, tags: test_vultr_account_facts }
- { role: vultr_block_storage, tags: test_vultr_block_storage }
- { role: vultr_block_storage_facts, tags: test_vultr_block_storage_facts }
- { role: vultr_dns_domain, tags: test_vultr_dns_domain }
- { role: vultr_dns_domain_facts, tags: test_vultr_dns_domain_facts }
- { role: vultr_dns_record, tags: test_vultr_dns_record }
- { role: vultr_firewall_group, tags: test_vultr_firewall_group }
- { role: vultr_firewall_group_facts, tags: test_vultr_firewall_group_facts }
- { role: vultr_firewall_rule, tags: test_vultr_firewall_rule }
- { role: vultr_network, tags: test_vultr_network }
- { role: vultr_network_facts, tags: test_vultr_network_facts }
- { role: vultr_os_facts, tags: test_vultr_os_facts }
- { role: vultr_plan_facts, tags: test_vultr_plan_facts }
- { role: vultr_region_facts, tags: test_vultr_region_facts }
- { role: vultr_server, tags: test_vultr_server }
- { role: vultr_server_facts, tags: test_vultr_server_facts }
- { role: vultr_ssh_key, tags: test_vultr_ssh_key }
- { role: vultr_ssh_key_facts, tags: test_vultr_ssh_key_facts }
- { role: vultr_startup_script, tags: test_vultr_startup_script }
- { role: vultr_startup_script_facts, tags: test_vultr_startup_script_facts }
- { role: vultr_user, tags: test_vultr_user }
- { role: vultr_user_facts, tags: test_vultr_user_facts }

View file

@ -0,0 +1,62 @@
"""Vultr plugin for integration tests."""
from __future__ import absolute_import, print_function
import os
from lib.cloud import (
CloudProvider,
CloudEnvironment
)
from lib.util import ConfigParser
class VultrCloudProvider(CloudProvider):
"""Checks if a configuration file has been passed or fixtures are going to be used for testing"""
def __init__(self, args):
"""
:type args: TestConfig
"""
super(VultrCloudProvider, self).__init__(args, config_extension='.ini')
def filter(self, targets, exclude):
"""Filter out the cloud tests when the necessary config and resources are not available.
:type targets: tuple[TestTarget]
:type exclude: list[str]
"""
if os.path.isfile(self.config_static_path):
return
super(VultrCloudProvider, self).filter(targets, exclude)
def setup(self):
super(VultrCloudProvider, self).setup()
if os.path.isfile(self.config_static_path):
self.config_path = self.config_static_path
self.managed = False
return True
return False
class VultrCloudEnvironment(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]
"""
parser = ConfigParser()
parser.read(self.config_path)
changes = dict(
VULTR_API_KEY=parser.get('default', 'key'),
)
env.update(changes)
cmd.append('-e')
cmd.append('vultr_resource_prefix=%s' % self.resource_prefix)