Refactored server and server_info modules

Allow to update server attributes such as its description.

Changed default value of server attribute 'security_groups' from
['default'] to [] because the latter is the default in
python-openstackclient [1] and the former behavior causes issues
with existing servers [2]: Previously, when no 'security_groups'
parameter was given, the server module would change existing
servers to use the default security group, dropping all other
security groups assigned to the server.
Our (undocumented) guideline when writing modules is to only
add or change what has been requested by the user and to stick to
defaults from openstacksdk and python-openstackclient whenever
possible. Since we have to break backward compatibility with the
next release anyway, we take this opportunity to clean up this odd
behavior. Now, when no security groups are given, then security
groups of an existing server will not be touched.
Closes story #2007893 [2].
Note, Nova will create a server in the default security group,
if the security_groups parameter is omitted.

Dropped 'openstack' field from server module's results. This
variable expanded to additional server information which might
be useful for Ansible inventories and was filled from
openstacksdk's get_openstack_vars() function [3]. Variables in
this function can make additional cloud queries to retrieve
additional data, so calling this function can be expensive [4].
Users can use *_info modules to retrieve this data on-demand.

Dropped 'availabity_zone' attribute from generic OpenStackModule
arguments and inserted it into server and volume modules because
it is relevant to those two modules only. This is completes what
was started years ago [5] and is possible now since we have
breaking changes anyway.

Switched attribute name 'userdata' with its alias 'user_data' to
match openstacksdk's attribute names which are used e.g. in module
results. The previous attribute name 'userdata' is now used as an
alias and 'user_data' is used as the attribute name to keep backward
compatibility.

Wait for server to get into 'ACTIVE' state when creating a server
and attribute 'wait' has been set to true.

Sorted argument specs and documentation of the server module and
marked attributes which are not updatable. Changed unstable bash
script example in server module documentation.

Renamed server's module attribute 'delete_fip' to 'delete_ips' to
match openstacksdk and clarify that it includes all floating ip
addresses of the server.

Renamed server_info's module attribute 'server' to 'name' and added
the former as an alias to be consistent with other *_info modules.

Added RETURN fields documentation for the module results of both
server and server_info modules.

Added description and examples of how to use the 'filters' attribute
of the server_info module. Closes story #2007873 [6].

Removed 'openstack_' prefix from module results because the prefix is
not consistently used across modules, is more to type without any
benefit and removal of the prefix allows us to signal to users that
their code for handling module results has to be updated. Many modules
have different return values with openstacksdk >= 0.99.0 because it
consistently uses resource proxies now.

Added assertions for module results to catch future changes in the
openstacksdk and our Ansible modules.

Added integration tests to check the update mechanism of the server
module.

Fixed indentation in integration tests.

Ensure proper creation and deletion of resources such as networks,
subnets and servers in integration tests of server_action module.

Renamed ci/roles/server/defaults/main.yaml to main.yml, removing the
'a' in the file extension to be consistent with other filenames.

Dropped deprecated function openstack_find_nova_addresses() and
incorporated its code directly into the server module because it
is not used anywhere else.

[1] e49ad1795b/openstackclient/compute/v2/server.py (L1070)
[2] https://storyboard.openstack.org/#!/story/2007893
[3] 9e9fc98795/openstack/cloud/_compute.py (L1772)
[4] 9e9fc98795/openstack/cloud/meta.py (L482)
[5] 9bf33e56dd
[6] https://storyboard.openstack.org/#!/story/2007873

Signed-off-by: Jakob Meng <code@jakobmeng.de>
Change-Id: I2f955519a7e8c782b1dab8f94f7a019ed384b81d
This commit is contained in:
Jakob Meng
2022-07-11 08:40:53 +02:00
parent 3fdbd56a58
commit ac401bb354
12 changed files with 1702 additions and 642 deletions

View File

@@ -162,11 +162,11 @@
# that no floating ip on public network is associated with "10.7.7.100" before running this role
assert:
that:
- info.openstack_servers|length == 1
- info.openstack_servers.0.public_v4|length == 0
- info.openstack_servers.0.public_v6|length == 0
- info.openstack_servers.0.addresses.ansible_internal|length == 1
- info.openstack_servers.0.addresses.ansible_internal|map(attribute="addr")|sort|list == ["10.7.7.100"]
- info.servers|length == 1
- info.servers.0.public_v4|length == 0
- info.servers.0.public_v6|length == 0
- info.servers.0.addresses.ansible_internal|length == 1
- info.servers.0.addresses.ansible_internal|map(attribute="addr")|sort|list == ["10.7.7.100"]
- name: Create server with two nics
openstack.cloud.server:
@@ -190,11 +190,11 @@
- name: Assert two internal ports and no floating ips on server 2
assert:
that:
- info.openstack_servers|length == 1
- info.openstack_servers.0.public_v4|length == 0
- info.openstack_servers.0.public_v6|length == 0
- info.openstack_servers.0.addresses.ansible_internal|length == 2
- info.openstack_servers.0.addresses.ansible_internal|map(attribute="addr")|sort|list ==
- info.servers|length == 1
- info.servers.0.public_v4|length == 0
- info.servers.0.public_v6|length == 0
- info.servers.0.addresses.ansible_internal|length == 2
- info.servers.0.addresses.ansible_internal|map(attribute="addr")|sort|list ==
["10.7.7.101", "10.7.7.102"]
# Tests
@@ -214,8 +214,8 @@
- name: Assert one internal port and one floating ip on server 1
assert:
that:
- info.openstack_servers.0.addresses.ansible_internal|length == 2
- info.openstack_servers.0.addresses.ansible_internal|map(attribute="OS-EXT-IPS:type")|sort|list ==
- info.servers.0.addresses.ansible_internal|length == 2
- info.servers.0.addresses.ansible_internal|map(attribute="OS-EXT-IPS:type")|sort|list ==
["fixed", "floating"]
- name: Detach floating IP from server
@@ -224,7 +224,7 @@
state: absent
server: ansible_server1
network: public
floating_ip_address: "{{ (info.openstack_servers.0.addresses.ansible_internal|
floating_ip_address: "{{ (info.servers.0.addresses.ansible_internal|
selectattr('OS-EXT-IPS:type', '==', 'floating')|map(attribute='addr')|list)[0] }}"
- name: Get info about server
@@ -233,16 +233,16 @@
server: ansible_server1
register: info
# When detaching a floating ip from an instance there might be a delay until openstack.cloud.server_info
# does not list it any more in info.openstack_servers.0.addresses.ansible_internal, so retry if necessary.
# does not list it any more in info.servers.0.addresses.ansible_internal, so retry if necessary.
retries: 10
delay: 3
until: info.openstack_servers.0.addresses.ansible_internal|length == 1
until: info.servers.0.addresses.ansible_internal|length == 1
- name: Assert one internal port on server 1
assert:
that:
- info.openstack_servers.0.addresses.ansible_internal|length == 1
- info.openstack_servers.0.addresses.ansible_internal|map(attribute="addr")|list == ["10.7.7.100"]
- info.servers.0.addresses.ansible_internal|length == 1
- info.servers.0.addresses.ansible_internal|map(attribute="addr")|list == ["10.7.7.100"]
- name: Assign floating IP to server
openstack.cloud.floating_ip:
@@ -263,8 +263,8 @@
- name: Assert two internal ports and one floating ip on server 2
assert:
that:
- info.openstack_servers.0.addresses.ansible_internal|length == 3
- info.openstack_servers.0.addresses.ansible_internal|map(attribute="OS-EXT-IPS:type")|sort|list ==
- info.servers.0.addresses.ansible_internal|length == 3
- info.servers.0.addresses.ansible_internal|map(attribute="OS-EXT-IPS:type")|sort|list ==
["fixed", "fixed", "floating"]
- name: Assign a second, specific floating IP to server
@@ -288,13 +288,13 @@
# retry because we cannot wait for second floating ip
retries: 10
delay: 3
until: info.openstack_servers.0.addresses.ansible_internal|length == 4
until: info.servers.0.addresses.ansible_internal|length == 4
- name: Assert two internal ports and two floating ips on server 2
assert:
that:
- info.openstack_servers.0.addresses.ansible_internal|length == 4
- ("10.6.6.150" in info.openstack_servers.0.addresses.ansible_internal|map(attribute="addr")|sort|list)
- info.servers.0.addresses.ansible_internal|length == 4
- ("10.6.6.150" in info.servers.0.addresses.ansible_internal|map(attribute="addr")|sort|list)
- name: Detach second floating IP from server
openstack.cloud.floating_ip:
@@ -310,15 +310,15 @@
server: ansible_server2
register: info
# When detaching a floating ip from an instance there might be a delay until openstack.cloud.server_info
# does not list it any more in info.openstack_servers.0.addresses.ansible_internal, so retry if necessary.
# does not list it any more in info.servers.0.addresses.ansible_internal, so retry if necessary.
retries: 10
delay: 3
until: info.openstack_servers.0.addresses.ansible_internal|length == 3
until: info.servers.0.addresses.ansible_internal|length == 3
- name: Assert two internal ports and one floating ip on server 2
assert:
that:
- info.openstack_servers.0.addresses.ansible_internal|length == 3
- info.servers.0.addresses.ansible_internal|length == 3
- name: Detach remaining floating IP from server
openstack.cloud.floating_ip:
@@ -326,7 +326,7 @@
state: absent
server: ansible_server2
network: public
floating_ip_address: "{{ (info.openstack_servers.0.addresses.ansible_internal|
floating_ip_address: "{{ (info.servers.0.addresses.ansible_internal|
selectattr('OS-EXT-IPS:type', '==', 'floating')|map(attribute='addr')|list)[0] }}"
- name: Get info about server
@@ -335,16 +335,16 @@
server: ansible_server2
register: info
# When detaching a floating ip from an instance there might be a delay until openstack.cloud.server_info
# does not list it any more in info.openstack_servers.0.addresses.ansible_internal, so retry if necessary.
# does not list it any more in info.servers.0.addresses.ansible_internal, so retry if necessary.
retries: 10
delay: 3
until: info.openstack_servers.0.addresses.ansible_internal|length == 2
until: info.servers.0.addresses.ansible_internal|length == 2
- name: Assert two internal ports on server 2
assert:
that:
- info.openstack_servers.0.addresses.ansible_internal|length == 2
- info.openstack_servers.0.addresses.ansible_internal|map(attribute="addr")|list == ["10.7.7.101", "10.7.7.102"]
- info.servers.0.addresses.ansible_internal|length == 2
- info.servers.0.addresses.ansible_internal|map(attribute="addr")|list == ["10.7.7.101", "10.7.7.102"]
# Clean environment
- name: Delete server with two nics