Skip to content

Commit

Permalink
fix: Account for implicit disk_resize event during disk creation (#471
Browse files Browse the repository at this point in the history
)

* Account for implicit disk_resize event during disk creation

* make format
  • Loading branch information
lgarber-akamai authored Mar 5, 2024
1 parent 0fa7577 commit 0760dd6
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
7 changes: 7 additions & 0 deletions plugins/modules/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,13 @@ def _delete_config_register(self, config: Config) -> None:
def _create_disk_register(self, **kwargs: Any) -> None:
size = kwargs.pop("size")

# Workaround for race condition on implicit events
# See: TPT-2738
self.client.polling.wait_for_entity_free(
entity_type="disks",
entity_id=self._instance.id,
)

create_poller = self.client.polling.event_poller_create(
"disks", "disk_create", entity_id=self._instance.id
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
- name: instance_config_disk_private
block:
- set_fact:
r: "{{ 1000000000 | random }}"
file_content: 'H4sIAAAAAAAAA6vML1UozsgvzUlRKC1OVShJLSpKTMsvyuUCAMhLS4gZAAAA='

- name: Create temporary image file
tempfile:
state: file
suffix: .img.gz
register: source_file

- copy:
dest: '{{ source_file.path }}'
content: '{{ file_content | b64decode }}'

- name: Create a private image from the image file
linode.cloud.image:
label: 'ansible-test-{{ r }}'
source_file: '{{ source_file.path }}'
state: present
register: image_create

- assert:
that:
- image_create.image.status == 'available'

- name: Provision an instance consuming the new image
linode.cloud.instance:
label: 'ansible-test-{{ r }}'
type: g6-nanode-1
region: us-mia
boot_config_label: boot-config
disks:
- label: boot
filesystem: raw
image: '{{ image_create.image.id }}'
size: 5000
- label: swap
filesystem: swap
size: 4000
configs:
- label: 'boot-config'
root_device: '/dev/sda'
run_level: 'default'
kernel: 'linode/direct-disk'
devices:
sda:
disk_label: boot
sdb:
disk_label: swap
state: present
register: instance_create

- assert:
that:
- instance_create.changed
- instance_create.disks | length == 2

always:
- ignore_errors: yes
block:
- linode.cloud.instance:
label: '{{ instance_create.instance.label }}'
state: absent

- linode.cloud.image:
label: '{{ image_create.image.label }}'
state: absent

environment:
LINODE_UA_PREFIX: '{{ ua_prefix }}'
LINODE_API_TOKEN: '{{ api_token }}'
LINODE_API_URL: '{{ api_url }}'
LINODE_API_VERSION: '{{ api_version }}'
LINODE_CA: '{{ ca_file or "" }}'

0 comments on commit 0760dd6

Please sign in to comment.