Cloudscale volume (#49887)

* Cloudscale integration test setup

CloudProvider and CloudEnvironment classes for Cloudscale integration
tests. This also contains a cloudscale_common role with common
variables for all tests.

* cloudscale_volume module

New cloud module to manage volumes on the cloudscale.ch IaaS service.
This commit is contained in:
Gaudenz Steinlin
2019-01-07 22:29:01 +01:00
committed by René Moser
parent 48ffe2f3b2
commit 35f17bf4c2
13 changed files with 699 additions and 4 deletions

View File

@@ -0,0 +1,8 @@
# This is the configuration template for ansible-test cloudscale integration tests.
#
# You do not need this template if you are:
#
# 1) Running integration tests without using ansible-test.
#
[default]
cloudscale_api_token = @API_TOKEN

View File

@@ -0,0 +1 @@
hidden

View File

@@ -0,0 +1,10 @@
---
# The image to use for test servers
cloudscale_test_image: 'debian-9'
# The flavor to use for test servers
cloudscale_test_flavor: 'flex-2'
# SSH key to use for test servers
cloudscale_test_ssh_key: |
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDSPmiqkvDH1/+MDAVDZT8381aYqp73Odz8cnD5hegNhqtXajqtiH0umVg7HybX3wt1HjcrwKJovZURcIbbcDvzdH2bnYbF93T4OLXA0bIfuIp6M86x1iutFtXdpN3TTicINrmSXEE2Ydm51iMu77B08ZERjVaToya2F7vC+egfoPvibf7OLxE336a5tPCywavvNihQjL8sjgpDT5AAScjb3YqK/6VLeQ18Ggt8/ufINsYkb+9/Ji/3OcGFeflnDXq80vPUyF3u4iIylob6RSZenC38cXmQB05tRNxS1B6BXCjMRdy0v4pa7oKM2GA4ADKpNrr0RI9ed+peRFwmsclH test@ansible

View File

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

View File

@@ -0,0 +1,3 @@
---
dependencies:
- cloudscale_common

View File

@@ -0,0 +1,62 @@
---
- name: Create volume in check mode
cloudscale_volume:
name: '{{ cloudscale_resource_prefix }}-check-mode'
size_gb: 50
register: check_mode_vol
check_mode: True
- name: Delete volume created in check mode
cloudscale_volume:
name: '{{ cloudscale_resource_prefix }}-check-mode'
state: 'absent'
register: check_mode_delete
- name: 'VERIFY: Create volume in check mode'
assert:
that:
- check_mode_vol is successful
- check_mode_vol is changed
- check_mode_delete is successful
- check_mode_delete is not changed
- name: Create volume
cloudscale_volume:
name: '{{ cloudscale_resource_prefix }}-vol'
size_gb: 50
- name: Attach volume in check mode
cloudscale_volume:
name: '{{ cloudscale_resource_prefix }}-vol'
server_uuids:
- '{{ server.uuid }}'
check_mode: True
register: check_mode_attach
- name: Detach volume
cloudscale_volume:
name: '{{ cloudscale_resource_prefix }}-vol'
server_uuids: []
register: check_mode_detach
- name: 'VERIFY: Attach volume in check mode'
assert:
that:
- check_mode_attach is successful
- check_mode_attach is changed
- check_mode_detach is successful
- check_mode_detach is not changed
- name: Resize volume in check mode
cloudscale_volume:
name: '{{ cloudscale_resource_prefix }}-vol'
size_gb: 100
register: check_mode_resize
check_mode: True
- name: Get volume info
cloudscale_volume:
name: '{{ cloudscale_resource_prefix }}-vol'
register: check_mode_info
- name: 'VERIFY: Resize volume in check mode'
assert:
that:
- check_mode_resize is successful
- check_mode_resize is changed
- check_mode_info is successful
- check_mode_info is not changed
- check_mode_info.size_gb == 50

View File

@@ -0,0 +1,5 @@
---
- name: Remove test server
cloudscale_server:
uuid: '{{ server.uuid }}'
state: 'absent'

View File

@@ -0,0 +1,63 @@
---
- name: Create two volumes with the same name
uri:
url: 'https://api.cloudscale.ch/v1/volumes'
method: POST
headers:
Authorization: 'Bearer {{ lookup("env", "CLOUDSCALE_API_TOKEN") }}'
body:
name: '{{ cloudscale_resource_prefix }}-duplicate'
size_gb: 50
body_format: json
status_code: 201
register: duplicate
with_sequence: count=2
- name: Try access to duplicate name
cloudscale_volume:
name: '{{ cloudscale_resource_prefix }}-duplicate'
size_gb: 10
register: vol
ignore_errors: True
- name: 'VERIFY: Try access to duplicate name'
assert:
that:
- vol is failed
- name: Delete duplicate volumes by UUID
cloudscale_volume:
uuid: '{{ item.json.uuid }}'
state: 'absent'
with_items: '{{ duplicate.results }}'
- name: Fail volume creation with UUID
cloudscale_volume:
uuid: ea3b39a3-77a8-4d0b-881d-0bb00a1e7f48
size_gb: 10
register: vol
ignore_errors: True
- name: 'VERIFY: Fail volume creation with UUID'
assert:
that:
- vol is failed
- name: Create volume
cloudscale_volume:
name: '{{ cloudscale_resource_prefix }}-name-UUID'
size_gb: 50
register: vol
- name: Fail name and UUID
cloudscale_volume:
name: '{{ vol.name }}'
uuid: '{{ vol.uuid }}'
size_gb: 100
register: vol
ignore_errors: True
- name: 'VERIFY: Fail name and UUID'
assert:
that:
- vol is failed
- name: 'Delete volume'
cloudscale_volume:
name: '{{ cloudscale_resource_prefix }}-name-UUID'
state: 'absent'

View File

@@ -0,0 +1,158 @@
---
- import_tasks: setup.yml
- name: Create volume
cloudscale_volume:
name: '{{ cloudscale_resource_prefix }}-vol'
size_gb: 50
register: vol
- name: 'VERIFY: Create volume'
assert:
that:
- vol is successful
- vol is changed
- vol.size_gb == 50
- vol.name == '{{ cloudscale_resource_prefix }}-vol'
- name: Create volume indempotence
cloudscale_volume:
name: '{{ cloudscale_resource_prefix }}-vol'
size_gb: 50
register: vol
- name: 'VERIFY: Create volume indempotence'
assert:
that:
- vol is successful
- vol is not changed
- name: Attach existing volume by name to server
cloudscale_volume:
name: '{{ cloudscale_resource_prefix }}-vol'
server_uuids:
- '{{ server.uuid }}'
register: vol
- name: 'VERIFY: Attach existing volume by name to server'
assert:
that:
- vol is successful
- vol is changed
- server.uuid in vol.server_uuids
- name: Attach existing volume by name to server indempotence
cloudscale_volume:
name: '{{ cloudscale_resource_prefix }}-vol'
server_uuids:
- '{{ server.uuid }}'
register: vol
- name: 'VERIFY: Attach existing volume by name to server indempotence'
assert:
that:
- vol is successful
- vol is not changed
- server.uuid in vol.server_uuids
- name: Resize attached volume by UUID
cloudscale_volume:
uuid: '{{ vol.uuid }}'
size_gb: 100
register: vol
- name: 'VERIFY: Resize attached volume by UUID'
assert:
that:
- vol is successful
- vol is changed
- vol.size_gb == 100
- name: Resize attached volume by UUID indempotence
cloudscale_volume:
uuid: '{{ vol.uuid }}'
size_gb: 100
register: vol
- name: 'VERIFY: Resize attached volume by UUID indempotence'
assert:
that:
- vol is successful
- vol is not changed
- vol.size_gb == 100
- name: Delete attached volume by UUID
cloudscale_volume:
uuid: '{{ vol.uuid }}'
state: 'absent'
register: deleted
- name: 'VERIFY: Delete attached volume by UUID'
assert:
that:
- deleted is successful
- deleted is changed
- deleted.state == 'absent'
- name: Delete attached volume by UUID indempotence
cloudscale_volume:
uuid: '{{ vol.uuid }}'
state: 'absent'
register: deleted
- name: 'VERIFY: Delete attached volume by UUID indempotence'
assert:
that:
- deleted is successful
- deleted is not changed
- deleted.state == 'absent'
- name: Create bulk volume and attach
cloudscale_volume:
name: '{{ cloudscale_resource_prefix }}-bulk'
type: bulk
size_gb: 100
server_uuids:
- '{{ server.uuid }}'
register: bulk
- name: 'VERIFY: Create bulk volume and attach'
assert:
that:
- bulk is successful
- bulk is changed
- bulk.size_gb == 100
- server.uuid in bulk.server_uuids
- name: Detach volume by UUID
cloudscale_volume:
uuid: '{{ bulk.uuid }}'
server_uuids: []
register: bulk
- name: 'VERIFY: Detach volume by UUID'
assert:
that:
- bulk is successful
- bulk is changed
- bulk.server_uuids == []
- name: Resize detached volume by name
cloudscale_volume:
name: '{{ bulk.name }}'
size_gb: 200
register: bulk
- name: 'VERIFY: Resize detached volume by name'
assert:
that:
- bulk is successful
- bulk is changed
- bulk.size_gb == 200
- name: Delete volume by name
cloudscale_volume:
name: '{{ bulk.name }}'
state: 'absent'
register: bulk
- name: 'VERIFY: Delete volume by name'
assert:
that:
- bulk is successful
- bulk is changed
- bulk.state == 'absent'
- import_tasks: failures.yml
- import_tasks: check-mode.yml
- import_tasks: cleanup.yml

View File

@@ -0,0 +1,8 @@
---
- name: Create test instance
cloudscale_server:
name: '{{ cloudscale_resource_prefix }}-server'
flavor: '{{ cloudscale_test_flavor }}'
image: '{{ cloudscale_test_image }}'
ssh_keys: '{{ cloudscale_test_ssh_key }}'
register: server

View File

@@ -0,0 +1,73 @@
# -*- coding: utf-8 -*-
#
# (c) 2018, Gaudenz Steinlin <gaudenz.steinlin@cloudscale.ch>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
"""Cloudscale plugin for integration tests."""
from __future__ import absolute_import, print_function
from os.path import isfile
from lib.cloud import (
CloudProvider,
CloudEnvironment,
)
from lib.util import ConfigParser, display
class CloudscaleCloudProvider(CloudProvider):
"""Cloudscale cloud provider plugin. Sets up cloud resources before
delegation.
"""
def __init__(self, args):
"""
:type args: TestConfig
"""
super(CloudscaleCloudProvider, 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 isfile(self.config_static_path):
return
super(CloudscaleCloudProvider, self).filter(targets, exclude)
def setup(self):
super(CloudscaleCloudProvider, self).setup()
if isfile(self.config_static_path):
display.info('Using existing %s cloud config: %s'
% (self.platform, self.config_static_path),
verbosity=1)
self.config_path = self.config_static_path
self.managed = False
return True
return False
class CloudscaleCloudEnvironment(CloudEnvironment):
"""Cloudscale cloud environment plugin. Updates integration test environment
after delegation.
"""
def configure_environment(self, env, cmd):
"""
:type env: dict[str, str]
:type cmd: list[str]
"""
parser = ConfigParser()
parser.read(self.config_path)
changes = dict(
CLOUDSCALE_API_TOKEN=parser.get('default', 'cloudscale_api_token'),
)
env.update(changes)
cmd.append('-e')
cmd.append('cloudscale_resource_prefix=%s' % self.resource_prefix)