Skip to content

Commit

Permalink
tests: vultr: convert legacy tests to targets (#50156)
Browse files Browse the repository at this point in the history
  • Loading branch information
resmo committed Jan 7, 2019
1 parent 618caf2 commit 48ffe2f
Show file tree
Hide file tree
Showing 78 changed files with 210 additions and 60 deletions.
36 changes: 36 additions & 0 deletions docs/docsite/rst/scenario_guides/guide_vultr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions test/integration/cloud-config-vultr.ini.template
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_account_facts/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_block_storage/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_block_storage_facts/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_dns_domain/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_dns_domain_facts/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_dns_record/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_firewall_group/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_firewall_group_facts/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
vultr_resource_prefix: "vultr-test-prefix"
firewall_group_name: "{{ vultr_resource_prefix }}_firewall-group"
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_firewall_rule/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_network/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
5 changes: 5 additions & 0 deletions test/integration/targets/vultr_network/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_network_facts/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_os_facts/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_plan_facts/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_region_facts/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_server/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_server_facts/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_ssh_key/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_ssh_key_facts/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_startup_script/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_startup_script_facts/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_user/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
Original file line number Diff line number Diff line change
@@ -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"
File renamed without changes.
2 changes: 2 additions & 0 deletions test/integration/targets/vultr_user_facts/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cloud/vultr
unsupported
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 0 additions & 4 deletions test/legacy/roles/vultr_block_storage/defaults/main.yml

This file was deleted.

3 changes: 0 additions & 3 deletions test/legacy/roles/vultr_block_storage_facts/defaults/main.yml

This file was deleted.

2 changes: 0 additions & 2 deletions test/legacy/roles/vultr_dns_domain_facts/defaults/main.yml

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions test/legacy/roles/vultr_network/defaults/main.yml

This file was deleted.

3 changes: 0 additions & 3 deletions test/legacy/roles/vultr_network_facts/defaults/main.yml

This file was deleted.

This file was deleted.

29 changes: 0 additions & 29 deletions test/legacy/vultr.yml

This file was deleted.

62 changes: 62 additions & 0 deletions test/runner/lib/cloud/vultr.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 48ffe2f

Please sign in to comment.