Skip to content

Commit

Permalink
block storage: enable test cases for attach/detach (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
resmo committed Sep 9, 2022
1 parent 5c96531 commit a3b5925
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
8 changes: 4 additions & 4 deletions plugins/modules/block_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@
description:
- Whether the volume should be attached/detached without restarting the instance.
type: bool
default: true
default: false
extends_documentation_fragment:
- vultr.cloud.vultr_v2
"""

EXAMPLES = """
---
- name: Ensure a block storage volume is present
vultr.cloud.block_storage:
name: myvolume
Expand Down Expand Up @@ -194,7 +194,7 @@ def present(self):
if instance_attached != instance_to_attach:
self.result["changed"] = True

mode = "detach" if instance_to_attach == "" else "attach"
mode = "detach" if not instance_to_attach else "attach"
self.result["diff"]["after"].update({"attached_to_instance": instance_to_attach})

data = {
Expand Down Expand Up @@ -222,7 +222,7 @@ def main():
region=dict(type="str"),
state=dict(type="str", choices=["present", "absent"], default="present"),
attached_to_instance=dict(type="str"),
live=dict(type="bool", default=True),
live=dict(type="bool", default=False),
) # type: ignore
)

Expand Down
8 changes: 4 additions & 4 deletions tests/integration/targets/block_storage/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ vultr_block_storage_name: "{{ vultr_resource_prefix }}-volume"
vultr_block_storage_size: 10
vultr_block_storage_size_2: 12
vultr_block_storage_size_3: 14

vultr_block_storage_region: ewr

vultr_server_name: "{{ vultr_resource_prefix }}_vm_for_attachment"
vultr_server_ssh_keys:
vultr_instance_name: "{{ vultr_resource_prefix }}_vm_for_attachment"
vultr_instance_ssh_keys:
- name: "{{ vultr_resource_prefix }}_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= [email protected]"
vultr_server_region: New Jersey

vultr_server_plan_1: 1024 MB RAM,25 GB SSD,1.00 TB BW
vultr_instance_plan: vc2-1c-1gb
3 changes: 1 addition & 2 deletions tests/integration/targets/block_storage/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
- block:
- ansible.builtin.import_tasks: failures.yml
- ansible.builtin.import_tasks: tests.yml
# TODO: to uncomment, replace the server instance task with a v2
# - ansible.builtin.import_tasks: tests_attach_to_server.yml
- ansible.builtin.import_tasks: tests_attach_to_server.yml
always:
- ansible.builtin.import_role:
name: cleanup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@
vultr.cloud.ssh_key:
name: "{{ item.name }}"
ssh_key: "{{ item.key }}"
loop: "{{ vultr_server_ssh_keys }}"
loop: "{{ vultr_instance_ssh_keys }}"

- name: setup create server
# TODO: subject of change
ngine_io.vultr.vultr_server:
name: "{{ vultr_server_name }}"
vultr.cloud.instance:
label: "{{ vultr_instance_name }}"
os: Debian 11 x64 (bullseye)
plan: "{{ vultr_server_plan_1 }}"
plan: "{{ vultr_instance_plan }}"
ssh_keys:
- "{{ vultr_resource_prefix }}_key1"
region: "{{ vultr_server_region }}"
state: started
region: "{{ vultr_block_storage_region }}"
register: result_server_setup

- name: wait some time
wait_for:
timeout: 20

- name: setup block storage volume unattached
vultr.cloud.block_storage:
label: "{{ vultr_block_storage_name }}"
Expand All @@ -40,7 +42,7 @@
label: "{{ vultr_block_storage_name }}"
size_gb: "{{ vultr_block_storage_size }}"
region: "{{ vultr_block_storage_region }}"
attached_to_instance: "{{ result_server_setup.vultr_server.id }}"
attached_to_instance: "{{ result_server_setup.vultr_instance.id }}"
register: result
check_mode: true
- name: verify test attach block volume in check mode
Expand All @@ -54,44 +56,51 @@
label: "{{ vultr_block_storage_name }}"
size_gb: "{{ vultr_block_storage_size }}"
region: "{{ vultr_block_storage_region }}"
attached_to_instance: "{{ result_server_setup.vultr_server.id }}"
attached_to_instance: "{{ result_server_setup.vultr_instance.id }}"
register: result
until: "'fetch_url_info' not in result or result.fetch_url_info.find('unable to attach') != -1"
retries: 3
delay: 10
- name: verify test attach block volume
ansible.builtin.assert:
that:
- result.changed
- result.vultr_block_storage.attached_to_instance == result_server_setup.vultr_server.id
- result.vultr_block_storage.attached_to_instance == result_server_setup.vultr_instance.id

- name: test attach block volume idempotency
vultr.cloud.block_storage:
label: "{{ vultr_block_storage_name }}"
size_gb: "{{ vultr_block_storage_size }}"
region: "{{ vultr_block_storage_region }}"
attached_to_instance: "{{ result_server_setup.vultr_server.id }}"
attached_to_instance: "{{ result_server_setup.vultr_instance.id }}"
register: result
- name: verify test attach block volume idempotency
ansible.builtin.assert:
that:
- not result.changed
- result.vultr_block_storage.attached_to_instance == result_server_setup.vultr_server.id
- result.vultr_block_storage.attached_to_instance == result_server_setup.vultr_instance.id

# volume size can only be modified every 60s
- name: wait about 60s before resizing volume
wait_for:
timeout: 61

- name: test resize block storage volume while attaching
- name: test resize block storage volume while attached
vultr.cloud.block_storage:
label: "{{ vultr_block_storage_name }}"
size_gb: "{{ vultr_block_storage_size_2 }}"
region: "{{ vultr_block_storage_region }}"
attached_to_instance: "{{ result_server_setup.vultr_server.id }}"
attached_to_instance: "{{ result_server_setup.vultr_instance.id }}"
register: result
- name: verify test resize block storage volume while attaching
- name: verify test resize block storage volume while attached
ansible.builtin.assert:
that:
- result is changed
- result.vultr_block_storage.attached_to_instance == result_server_setup.vultr_server.id
- result.vultr_block_storage.attached_to_instance == result_server_setup.vultr_instance.id

- name: wait about 60s
wait_for:
timeout: 61

- name: test detach block volume in check mode
vultr.cloud.block_storage:
Expand All @@ -105,7 +114,7 @@
ansible.builtin.assert:
that:
- result is changed
- not result.vultr_block_storage.attached_to_instance
- result.vultr_block_storage.attached_to_instance == result_server_setup.vultr_instance.id

- name: test detach block volume
vultr.cloud.block_storage:
Expand Down

0 comments on commit a3b5925

Please sign in to comment.