Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: Add modules for Placement group #503

Conversation

yec-akamai
Copy link
Contributor

@yec-akamai yec-akamai commented May 6, 2024

📝 Description

This PR includes the following change for VM placement functionalities:

  1. Add new modules:

    • placement_group: accept both label and id as identifier
    • placement_group_info
    • placement_group_list
  2. In the instance module, allow to create a new linode instance under a placement group.

✔️ How to Test

Run pip install --force -r requirements.txt to install required dependencies.

Also, you need to set up environment variables to test against alpha:

export TEST_API_CA=$PWD/cacert.pem
export TEST_API_URL=https://.../
export LINODE_TOKEN=...

Integration tests:

make TEST_ARGS="-v placement_group" test
make TEST_ARGS="-v placement_group_info" test
make TEST_ARGS="-v placement_group_list" test
make TEST_ARGS="-v instance_basic" test

Manual Test:

  1. In a sandbox environment, i.e. dx-devenv, run the following ansible playbook
- name: ansible_linode Sandbox Playbook
  hosts: localhost
  tasks:
    - name: Create a Linode placement group
      linode.cloud.placement_group:
        label: my-ansible-test-pg
        region: us-east
        affinity_type: anti_affinity:local
        state: present
      register: pg_created

    - name: Get a Linode placement group info
      linode.cloud.placement_group_info:
        id: '{{ pg_created.placement_group.id }}'
      register: pg

    - name: Update a Linode placement group label
      linode.cloud.placement_group:
        id: '{{ pg.placement_group.id }}'
        label: '{{ pg.placement_group.label }}-updated'
        state: present
      register: pg_updated

    - name: List Linode placement groups for the current account
      linode.cloud.placement_group_list:
        filters:
          - name: label
            values: ['{{ pg_updated.placement_group.label }}']
      register: pg_list
  1. Observe no error is raised.

  2. Create an instance under the placement group

    - name: Create a Linode instance under a placement group
      linode.cloud.instance:
        label: 'ansible-test-pg-{{ r }}'
        type: g6-nanode-1
        region: us-east
        placement_group:
          id: '{{ pg_updated.placement_group.id }}'
          compliant_only: false
        state: present
      register: instance_pg
  1. Observe that the instance is created successfully.

  2. Clean up the resources created.

    - name: Delete a Linode instance
      linode.cloud.instance:
        label: '{{ instance_pg.instance.label }}'
        state: absent
      register: delete_instance_pg

    - name: Delete a placement group
      linode.cloud.placement_group:
        label: '{{ pg_updated.placement_group.label }}'
        state: absent
      register: pg_deleted

@yec-akamai yec-akamai added the new-feature for new features in the changelog. label May 6, 2024
@yec-akamai yec-akamai requested a review from a team as a code owner May 6, 2024 19:21
@yec-akamai yec-akamai requested review from lgarber-akamai and zliang-akamai and removed request for a team May 6, 2024 19:21
"failed to update instance {0}: placement_group.id is a "
"non-updatable field".format(self._instance.label)
)
if pg.get("compliant_only"):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lgarber-akamai The value of compliant_only is not returned from API and we don't have a state like tf to find its old value, so I'm thinking returning a warning here to remind user that compliant_only is not updatable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me!

Copy link
Contributor

@lgarber-akamai lgarber-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All E2E test are passing and everything works as expected in my manual testing, great work!

Copy link
Member

@zliang-akamai zliang-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tested and worked well. Nice work!

@yec-akamai yec-akamai merged commit e30efc1 into linode:proj/vm-placement May 21, 2024
4 checks passed
@yec-akamai yec-akamai deleted the TPT-2622/support-placement-groups branch May 21, 2024 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature for new features in the changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants