mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-11-21 14:48:41 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
166db53fa4 | ||
|
|
aa949c09a6 | ||
|
|
6cd74f4749 | ||
|
|
2d02e7ac75 | ||
|
|
ac8cce11c7 | ||
|
|
896027d67e | ||
|
|
34a99f549b | ||
|
|
ee6e1e9741 | ||
|
|
4caa12c979 | ||
|
|
6482009c49 | ||
|
|
11a9430073 | ||
|
|
ad7205503e | ||
|
|
291d64adaa | ||
|
|
cfb7a39221 | ||
|
|
e433ee401b | ||
|
|
da4a211b2d | ||
|
|
6fccec65bc | ||
|
|
9a437e49bc | ||
|
|
74caf969b3 | ||
|
|
19a8bc6e05 | ||
|
|
8c95d5aba8 | ||
|
|
876823b88e | ||
|
|
6924032c86 | ||
|
|
463dda6549 | ||
|
|
ebacdde5a4 | ||
|
|
746e521d47 | ||
|
|
ee88cc15b8 | ||
|
|
9d53bf6403 | ||
|
|
209cf2d605 | ||
|
|
dc2bb8232e | ||
|
|
08686d1d9c |
+31
@@ -245,6 +245,19 @@
|
||||
vars:
|
||||
tox_envlist: ansible_2_20
|
||||
|
||||
- job:
|
||||
name: ansible-collections-openstack-functional-devstack-ansible-2.21
|
||||
parent: ansible-collections-openstack-functional-devstack-base
|
||||
branches: master
|
||||
description: |
|
||||
Run openstack collections functional tests against a master devstack
|
||||
using master of openstacksdk and stable 2.21 branch of ansible
|
||||
required-projects:
|
||||
- name: github.com/ansible/ansible
|
||||
override-checkout: stable-2.21
|
||||
vars:
|
||||
tox_envlist: ansible_2_21
|
||||
|
||||
- job:
|
||||
name: ansible-collections-openstack-functional-devstack-ansible-devel
|
||||
parent: ansible-collections-openstack-functional-devstack-base
|
||||
@@ -324,6 +337,19 @@
|
||||
python_version: "3.12"
|
||||
bindep_profile: test py312
|
||||
|
||||
- job:
|
||||
name: openstack-tox-linters-ansible-2.21
|
||||
parent: openstack-tox-linters-ansible
|
||||
description: |
|
||||
Run openstack collections linter tests using the 2.21 branch of ansible
|
||||
required-projects:
|
||||
- name: github.com/ansible/ansible
|
||||
override-checkout: stable-2.21
|
||||
vars:
|
||||
tox_envlist: linters_2_21
|
||||
python_version: "3.12"
|
||||
bindep_profile: test py312
|
||||
|
||||
# Cross-checks with other projects
|
||||
- job:
|
||||
name: bifrost-collections-src
|
||||
@@ -379,11 +405,13 @@
|
||||
- openstack-tox-linters-ansible-2.18
|
||||
- openstack-tox-linters-ansible-2.19
|
||||
- openstack-tox-linters-ansible-2.20
|
||||
- openstack-tox-linters-ansible-2.21
|
||||
- ansible-collections-openstack-functional-devstack
|
||||
- ansible-collections-openstack-functional-devstack-releases
|
||||
- ansible-collections-openstack-functional-devstack-ansible-2.18
|
||||
- ansible-collections-openstack-functional-devstack-ansible-2.19
|
||||
- ansible-collections-openstack-functional-devstack-ansible-2.20
|
||||
- ansible-collections-openstack-functional-devstack-ansible-2.21
|
||||
- ansible-collections-openstack-functional-devstack-ansible-devel
|
||||
- ansible-collections-openstack-functional-devstack-magnum
|
||||
- ansible-collections-openstack-functional-devstack-manila
|
||||
@@ -402,6 +430,7 @@
|
||||
- openstack-tox-linters-ansible-2.18
|
||||
- openstack-tox-linters-ansible-2.19
|
||||
- openstack-tox-linters-ansible-2.20
|
||||
- openstack-tox-linters-ansible-2.21
|
||||
- ansible-collections-openstack-functional-devstack-releases
|
||||
- ansible-collections-openstack-functional-devstack-magnum
|
||||
- ansible-collections-openstack-functional-devstack-manila
|
||||
@@ -413,11 +442,13 @@
|
||||
- openstack-tox-linters-ansible-2.18
|
||||
- openstack-tox-linters-ansible-2.19
|
||||
- openstack-tox-linters-ansible-2.20
|
||||
- openstack-tox-linters-ansible-2.21
|
||||
- ansible-collections-openstack-functional-devstack
|
||||
- ansible-collections-openstack-functional-devstack-releases
|
||||
- ansible-collections-openstack-functional-devstack-ansible-2.18
|
||||
- ansible-collections-openstack-functional-devstack-ansible-2.19
|
||||
- ansible-collections-openstack-functional-devstack-ansible-2.20
|
||||
- ansible-collections-openstack-functional-devstack-ansible-2.21
|
||||
- ansible-collections-openstack-functional-devstack-ansible-devel
|
||||
- bifrost-collections-src
|
||||
- bifrost-keystone-collections-src
|
||||
|
||||
+31
-1
@@ -4,6 +4,37 @@ Ansible OpenStack Collection Release Notes
|
||||
|
||||
.. contents:: Topics
|
||||
|
||||
v2.7.0
|
||||
======
|
||||
|
||||
Release Summary
|
||||
---------------
|
||||
|
||||
Bugfixes and minor changes.
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- baremetal_node - Add ``target_provision_state`` option.
|
||||
- baremetal_node - Allow registering nodes without NICs.
|
||||
- identity_user - Added an ``options`` parameter to set Keystone user resource options, e.g. ``ignore_password_expiry`` and ``ignore_change_password_upon_first_use``. On update, the provided options are merged with the user's existing options so options not managed by this module are preserved.
|
||||
- loadbalancer - Add option to specify the availability zone a loadbalancer should be created in.
|
||||
- server_action - Add ``live_migrate`` action.
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- application_credential - Handle ``cloud`` passed as a dict.
|
||||
- image - Do a web-download import when ``uri`` is given, instead of ignoring ``uri`` and ``import_method`` and attempting a direct upload with no data.
|
||||
- image - Remove the unimplemented ``glance-download`` choice for ``import_method``.
|
||||
- image - Stop storing ``uri``, ``import_method`` and ``use_import`` on the image as properties.
|
||||
- lb_pool - Fix use of an undefined variable.
|
||||
- neutron_rbac_policy - Include ``target_project_id`` on creation.
|
||||
- recordset - Look an existing recordset up by zone, name and type instead of by zone and name only. Recordsets sharing a name with recordsets of another type, e.g. an ``A`` recordset at the apex of a zone which shares its name with the ``SOA`` and ``NS`` recordsets created along with the zone, could not be created, updated or deleted because the lookup matched more than one recordset and failed with ``More than one Recordset exists with the name``.
|
||||
- router - Search for the network in the router's project first.
|
||||
- subnet - Fix regression when the subnet already exists.
|
||||
- volume_type_access - Fix failure when ``project_domain`` is set.
|
||||
|
||||
v2.6.0
|
||||
======
|
||||
|
||||
@@ -12,7 +43,6 @@ Release Summary
|
||||
|
||||
New modules for Bare Metal port groups and Neutron network segments, plus image/project enhancements and bugfixes.
|
||||
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
|
||||
@@ -665,3 +665,45 @@ releases:
|
||||
name: volume_retype
|
||||
namespace: ''
|
||||
release_date: '2026-06-10'
|
||||
2.7.0:
|
||||
changes:
|
||||
bugfixes:
|
||||
- application_credential - Handle ``cloud`` passed as a dict.
|
||||
- image - Do a web-download import when ``uri`` is given, instead of ignoring
|
||||
``uri`` and ``import_method`` and attempting a direct upload with no data.
|
||||
- image - Remove the unimplemented ``glance-download`` choice for ``import_method``.
|
||||
- image - Stop storing ``uri``, ``import_method`` and ``use_import`` on the
|
||||
image as properties.
|
||||
- lb_pool - Fix use of an undefined variable.
|
||||
- neutron_rbac_policy - Include ``target_project_id`` on creation.
|
||||
- recordset - Look an existing recordset up by zone, name and type instead of
|
||||
by zone and name only. Recordsets sharing a name with recordsets of another
|
||||
type, e.g. an ``A`` recordset at the apex of a zone which shares its name
|
||||
with the ``SOA`` and ``NS`` recordsets created along with the zone, could
|
||||
not be created, updated or deleted because the lookup matched more than one
|
||||
recordset and failed with ``More than one Recordset exists with the name``.
|
||||
- router - Search for the network in the router's project first.
|
||||
- subnet - Fix regression when the subnet already exists.
|
||||
- volume_type_access - Fix failure when ``project_domain`` is set.
|
||||
minor_changes:
|
||||
- baremetal_node - Add ``target_provision_state`` option.
|
||||
- baremetal_node - Allow registering nodes without NICs.
|
||||
- identity_user - Added an ``options`` parameter to set Keystone user resource
|
||||
options, e.g. ``ignore_password_expiry`` and ``ignore_change_password_upon_first_use``.
|
||||
On update, the provided options are merged with the user's existing options
|
||||
so options not managed by this module are preserved.
|
||||
- loadbalancer - Add option to specify the availability zone a loadbalancer
|
||||
should be created in.
|
||||
- server_action - Add ``live_migrate`` action.
|
||||
release_summary: Bugfixes and minor changes.
|
||||
fragments:
|
||||
- add_az_parameter_to_loadbalancer.yaml
|
||||
- baremetal_provision_state.yaml
|
||||
- bug_2167592.yaml
|
||||
- identity_user_options.yaml
|
||||
- image_web_download.yaml
|
||||
- rbac_target_project_id.yaml
|
||||
- recordset_find_by_type.yaml
|
||||
- router_network.yaml
|
||||
- undefined_variable.yaml
|
||||
release_date: '2026-10-26'
|
||||
|
||||
@@ -16,17 +16,21 @@
|
||||
# allow new fields to be introduced but prevent fields from being removed
|
||||
- expected_fields|difference(dns_zone.zone.keys())|length == 0
|
||||
|
||||
# NOTE(jed-preist): Update ttl as well, to work around
|
||||
# https://bugs.launchpad.net/designate/+bug/2171489
|
||||
- name: Update dns zone
|
||||
openstack.cloud.dns_zone:
|
||||
cloud: "{{ cloud }}"
|
||||
name: ansible.test.zone.
|
||||
description: "Another description"
|
||||
ttl: 1800
|
||||
register: dns_zone
|
||||
|
||||
- name: Assert return values of dns_zone module
|
||||
assert:
|
||||
that:
|
||||
- dns_zone.zone.description == "Another description"
|
||||
- dns_zone.zone.ttl == 1800
|
||||
|
||||
- name: Fetch all dns zones
|
||||
openstack.cloud.dns_zone_info:
|
||||
|
||||
@@ -63,3 +63,6 @@ expected_fields:
|
||||
- vm_mode
|
||||
- vmware_adaptertype
|
||||
- vmware_ostype
|
||||
|
||||
# Fetched by the Image service itself in the web-download test.
|
||||
image_web_download_uri: https://download.cirros-cloud.net/0.6.2/cirros-0.6.2-x86_64-disk.img
|
||||
|
||||
@@ -368,6 +368,53 @@
|
||||
name: "{{ tmp_file.path }}"
|
||||
state: absent
|
||||
|
||||
- name: Import an image with web-download
|
||||
openstack.cloud.image:
|
||||
cloud: "{{ cloud }}"
|
||||
state: present
|
||||
name: ansible_image_web_download
|
||||
container_format: bare
|
||||
disk_format: qcow2
|
||||
import_method: web-download
|
||||
uri: "{{ image_web_download_uri }}"
|
||||
register: web_download_image
|
||||
|
||||
- name: Assert the image was fetched by the Image service
|
||||
assert:
|
||||
that:
|
||||
- web_download_image is changed
|
||||
- web_download_image.image.status == 'active'
|
||||
- web_download_image.image.size > 0
|
||||
|
||||
- name: Assert import options were not stored as image properties
|
||||
assert:
|
||||
that:
|
||||
- "'uri' not in web_download_image.image.properties"
|
||||
- "'import_method' not in web_download_image.image.properties"
|
||||
- "'use_import' not in web_download_image.image.properties"
|
||||
|
||||
- name: Import the same image again
|
||||
openstack.cloud.image:
|
||||
cloud: "{{ cloud }}"
|
||||
state: present
|
||||
name: ansible_image_web_download
|
||||
container_format: bare
|
||||
disk_format: qcow2
|
||||
import_method: web-download
|
||||
uri: "{{ image_web_download_uri }}"
|
||||
register: web_download_image
|
||||
|
||||
- name: Assert the second import did not change anything
|
||||
assert:
|
||||
that:
|
||||
- web_download_image is not changed
|
||||
|
||||
- name: Delete the web-download image
|
||||
openstack.cloud.image:
|
||||
cloud: "{{ cloud }}"
|
||||
state: absent
|
||||
name: ansible_image_web_download
|
||||
|
||||
always:
|
||||
- name: Remove temporary image file
|
||||
ansible.builtin.file:
|
||||
|
||||
+1
-1
@@ -32,4 +32,4 @@ build_ignore:
|
||||
- .vscode
|
||||
- ansible_collections_openstack.egg-info
|
||||
- changelogs
|
||||
version: 2.6.0
|
||||
version: 2.7.0
|
||||
|
||||
@@ -298,7 +298,11 @@ class IdentityApplicationCredentialModule(OpenStackModule):
|
||||
return creds
|
||||
|
||||
def _get_cloud_config(self, creds):
|
||||
cloud_region = openstack.config.OpenStackConfig().get_one(self.cloud)
|
||||
if isinstance(self.cloud, str):
|
||||
cloud_region = openstack.config.OpenStackConfig().get_one(self.cloud)
|
||||
# If the cloud parameter is not a string, try to send it to kwargs
|
||||
else:
|
||||
cloud_region = openstack.config.OpenStackConfig().get_one(**self.cloud)
|
||||
|
||||
conf = cloud_region.config
|
||||
cloud_config = copy.deepcopy(conf)
|
||||
|
||||
@@ -75,7 +75,8 @@ options:
|
||||
description:
|
||||
- 'A list of network interface cards, eg, C( - mac: aa:bb:cc:aa:bb:cc)'
|
||||
- This node attribute cannot be updated.
|
||||
required: true
|
||||
required: false
|
||||
default: []
|
||||
type: list
|
||||
elements: dict
|
||||
suboptions:
|
||||
@@ -153,6 +154,18 @@ options:
|
||||
- Interface used for attaching and detaching volumes on this node, e.g.
|
||||
C(cinder).
|
||||
type: str
|
||||
target_provision_state:
|
||||
description:
|
||||
- Indicates desired provision state of the node.
|
||||
- This option is ignored if the node already exists.
|
||||
- If set to available, the node will go through cleaning. This may fail
|
||||
if the nics option has no interfaces specified.
|
||||
- try-available behaves the same as available if the nics option is
|
||||
set, and falls back to enroll if it is not.
|
||||
choices: ['enroll', 'manageable', 'available', 'try-available']
|
||||
default: try-available
|
||||
type: str
|
||||
version_added: 2.7.0
|
||||
timeout:
|
||||
description:
|
||||
- Number of seconds to wait for the newly created node to reach the
|
||||
@@ -508,7 +521,7 @@ class BaremetalNodeModule(OpenStackModule):
|
||||
management_interface=dict(),
|
||||
name=dict(),
|
||||
network_interface=dict(),
|
||||
nics=dict(type='list', required=True, elements='dict'),
|
||||
nics=dict(type='list', default=[], elements='dict'),
|
||||
power_interface=dict(),
|
||||
properties=dict(
|
||||
type='dict',
|
||||
@@ -531,6 +544,10 @@ class BaremetalNodeModule(OpenStackModule):
|
||||
),
|
||||
state=dict(default='present', choices=['present', 'absent']),
|
||||
storage_interface=dict(),
|
||||
target_provision_state=dict(
|
||||
default='try-available',
|
||||
choices=['enroll', 'manageable', 'available', 'try-available']
|
||||
),
|
||||
timeout=dict(default=1800, type='int'), # increased default value
|
||||
vendor_interface=dict(),
|
||||
)
|
||||
@@ -651,10 +668,22 @@ class BaremetalNodeModule(OpenStackModule):
|
||||
if properties:
|
||||
kwargs['properties'] = properties
|
||||
|
||||
provision_state = self.params['target_provision_state']
|
||||
if provision_state == 'available':
|
||||
if len(self.params['nics']) == 0:
|
||||
self.warn('Attempting to make node available with no NICs'
|
||||
' set. Node may fail cleaning.')
|
||||
elif provision_state == 'try-available':
|
||||
if len(self.params['nics']) == 0:
|
||||
provision_state = 'enroll'
|
||||
else:
|
||||
provision_state = 'available'
|
||||
|
||||
node = self.conn.register_machine(
|
||||
nics=self.params['nics'],
|
||||
wait=self.params['wait'],
|
||||
timeout=self.params['timeout'],
|
||||
provision_state=provision_state,
|
||||
**kwargs)
|
||||
|
||||
self.exit_json(changed=True, node=node.to_dict(computed=False))
|
||||
|
||||
@@ -40,6 +40,13 @@ options:
|
||||
- I(name) cannot be updated without deleting and re-creating the user.
|
||||
required: true
|
||||
type: str
|
||||
options:
|
||||
description:
|
||||
- A dictionary of Keystone user options to set on the user, e.g.
|
||||
C(ignore_password_expiry) or C(ignore_change_password_upon_first_use).
|
||||
- On update, the provided options are merged with the user's existing
|
||||
options, so options not specified here are preserved.
|
||||
type: dict
|
||||
password:
|
||||
description:
|
||||
- Password for the user.
|
||||
@@ -99,6 +106,17 @@ EXAMPLES = r'''
|
||||
email: demo@example.com
|
||||
domain: default
|
||||
default_project: demo
|
||||
|
||||
- name: Create a user with password policy options
|
||||
openstack.cloud.identity_user:
|
||||
cloud: mycloud
|
||||
state: present
|
||||
name: demouser
|
||||
password: secret
|
||||
domain: default
|
||||
options:
|
||||
ignore_password_expiry: true
|
||||
ignore_change_password_upon_first_use: true
|
||||
'''
|
||||
|
||||
RETURN = r'''
|
||||
@@ -138,6 +156,10 @@ user:
|
||||
description: Unique user name, within the owning domain
|
||||
type: str
|
||||
sample: "demouser"
|
||||
options:
|
||||
description: The resource options for the user (e.g.
|
||||
ignore_password_expiry).
|
||||
type: dict
|
||||
password:
|
||||
description: Credential used during authentication
|
||||
type: str
|
||||
@@ -159,6 +181,7 @@ class IdentityUserModule(OpenStackModule):
|
||||
email=dict(),
|
||||
is_enabled=dict(default=True, type='bool', aliases=['enabled']),
|
||||
name=dict(required=True),
|
||||
options=dict(type='dict'),
|
||||
password=dict(no_log=True),
|
||||
state=dict(default='present', choices=['absent', 'present']),
|
||||
update_password=dict(default='on_create',
|
||||
@@ -177,6 +200,16 @@ class IdentityUserModule(OpenStackModule):
|
||||
elif update_password == 'on_create' and 'password' in attributes:
|
||||
attributes.pop('password')
|
||||
|
||||
if 'options' in attributes:
|
||||
# Merge desired options with the user's existing options so
|
||||
# that options not managed by this module are preserved, and
|
||||
# so the update is idempotent when the desired options already
|
||||
# match the current values.
|
||||
current = self.get_function(resource['id'])
|
||||
merged = dict(current['options'] or {})
|
||||
merged.update(attributes['options'])
|
||||
attributes['options'] = merged
|
||||
|
||||
return super()._build_update(resource, attributes,
|
||||
updateable_attributes,
|
||||
non_updateable_attributes, **kwargs)
|
||||
@@ -202,7 +235,7 @@ class IdentityUserModule(OpenStackModule):
|
||||
kwargs['attributes'] = \
|
||||
dict((k, self.params[k])
|
||||
for k in ['description', 'email', 'is_enabled', 'name',
|
||||
'password']
|
||||
'options', 'password']
|
||||
if self.params[k] is not None)
|
||||
|
||||
domain_name_or_id = self.params['domain']
|
||||
|
||||
+47
-17
@@ -125,21 +125,29 @@ options:
|
||||
use_import:
|
||||
description:
|
||||
- Use the 'glance-direct' method of the interoperable image import mechanism.
|
||||
- Applies only to uploads from I(filename). I(import_method) does not
|
||||
affect it.
|
||||
- Should only be used when needed, such as when the user needs the cloud to
|
||||
transform image format.
|
||||
type: bool
|
||||
import_method:
|
||||
description:
|
||||
- Method to use for importing the image. Not all deployments support all methods.
|
||||
- Supports web-download or glance-download.
|
||||
- copy-image is not supported with create actions.
|
||||
- glance-direct is removed from the import method so use_import can be used in that case.
|
||||
- Interoperable image import method that the Image service uses to
|
||||
download the image data.
|
||||
- The only supported method is web-download. The Image service downloads
|
||||
the image data from I(uri).
|
||||
- If I(uri) is set and I(import_method) is not, the module uses
|
||||
web-download.
|
||||
- For glance-direct uploads from I(filename), use I(use_import).
|
||||
type: str
|
||||
choices: [web-download, glance-download]
|
||||
choices: [web-download]
|
||||
uri:
|
||||
description:
|
||||
- Required only if using the web-download import method.
|
||||
- This url is where the data is made available to the Image service.
|
||||
- URL the Image service downloads the image data from.
|
||||
- Requires I(import_method=web-download), which is the default when
|
||||
I(uri) is given, and a Glance with that import method enabled.
|
||||
- Mutually exclusive with I(filename) and I(volume). The image data
|
||||
never passes through the Ansible controller.
|
||||
type: str
|
||||
|
||||
extends_documentation_fragment:
|
||||
@@ -147,6 +155,15 @@ extends_documentation_fragment:
|
||||
'''
|
||||
|
||||
EXAMPLES = r'''
|
||||
- name: Have the Image service download an image itself
|
||||
openstack.cloud.image:
|
||||
cloud: devstack
|
||||
name: cirros
|
||||
container_format: bare
|
||||
disk_format: qcow2
|
||||
import_method: web-download
|
||||
uri: https://download.cirros-cloud.net/0.6.2/cirros-0.6.2-x86_64-disk.img
|
||||
|
||||
- name: Upload an image from a local file named cirros-0.3.0-x86_64-disk.img
|
||||
openstack.cloud.image:
|
||||
cloud: devstack-admin
|
||||
@@ -413,7 +430,7 @@ class ImageModule(OpenStackModule):
|
||||
visibility=dict(choices=['public', 'private', 'shared', 'community']),
|
||||
volume=dict(),
|
||||
use_import=dict(type='bool'),
|
||||
import_method=dict(choices=['web-download', 'glance-download']),
|
||||
import_method=dict(choices=['web-download']),
|
||||
uri=dict()
|
||||
)
|
||||
|
||||
@@ -422,13 +439,15 @@ class ImageModule(OpenStackModule):
|
||||
('filename', 'volume', 'uri'),
|
||||
('visibility', 'is_public'),
|
||||
],
|
||||
required_if=[
|
||||
('import_method', 'web-download', ['uri']),
|
||||
],
|
||||
)
|
||||
|
||||
# resource attributes obtainable directly from params
|
||||
attr_params = ('id', 'name', 'filename', 'disk_format',
|
||||
'container_format', 'wait', 'timeout', 'is_public',
|
||||
'is_protected', 'min_disk', 'min_ram', 'volume', 'tags',
|
||||
'use_import', 'import_method', 'uri')
|
||||
'is_protected', 'min_disk', 'min_ram', 'volume', 'tags')
|
||||
|
||||
def _resolve_visibility(self):
|
||||
"""resolve a visibility value to be compatible with older versions"""
|
||||
@@ -497,14 +516,13 @@ class ImageModule(OpenStackModule):
|
||||
wait=self.params['timeout'],
|
||||
attribute='status')
|
||||
|
||||
def _import_uploaded_image(self, image):
|
||||
def _import_image(self, image, method, **kwargs):
|
||||
if not hasattr(self.conn.image, 'import_image'):
|
||||
self.fail_json(
|
||||
msg="The installed openstacksdk library does not support "
|
||||
"image import operations required for images in the "
|
||||
"'uploading' state.")
|
||||
"image import operations.")
|
||||
|
||||
self.conn.image.import_image(image, method='glance-direct')
|
||||
self.conn.image.import_image(image, method=method, **kwargs)
|
||||
return self._wait_for_image_active(self.conn.get_image(image.id))
|
||||
|
||||
def run(self):
|
||||
@@ -536,15 +554,23 @@ class ImageModule(OpenStackModule):
|
||||
|
||||
changed = False
|
||||
if self.params['state'] == 'present':
|
||||
import_method = self.params['import_method']
|
||||
if self.params['uri'] and not import_method:
|
||||
import_method = 'web-download'
|
||||
|
||||
attrs = self._build_params(owner)
|
||||
if not image:
|
||||
# self.conn.image.create_image() cannot be used because it does
|
||||
# not provide self.conn.create_image()'s volume parameter [0].
|
||||
# [0] https://opendev.org/openstack/openstacksdk/src/commit/
|
||||
# a41d04ea197439c2f134ce3554995693933a46ac/openstack/cloud/_image.py#L306
|
||||
if import_method:
|
||||
# Without data, the image stays queued until the import
|
||||
# below starts. Waiting for it here times out.
|
||||
attrs['wait'] = False
|
||||
image = self.conn.create_image(**attrs)
|
||||
changed = True
|
||||
if not self.params['wait']:
|
||||
if not self.params['wait'] and not import_method:
|
||||
self.exit_json(changed=changed,
|
||||
image=self._return_value(image.id))
|
||||
|
||||
@@ -552,7 +578,11 @@ class ImageModule(OpenStackModule):
|
||||
self.conn.image.reactivate_image(image)
|
||||
changed = True
|
||||
elif image['status'] == 'queued':
|
||||
if (
|
||||
if import_method == 'web-download':
|
||||
image = self._import_image(
|
||||
image, import_method, uri=self.params['uri'])
|
||||
changed = True
|
||||
elif (
|
||||
self.params['filename']
|
||||
and hasattr(self.conn.image, 'stage_image')):
|
||||
self.conn.image.stage_image(
|
||||
@@ -570,7 +600,7 @@ class ImageModule(OpenStackModule):
|
||||
image = self.conn.get_image(image.id)
|
||||
|
||||
if image['status'] == 'uploading' and self.params['use_import']:
|
||||
image = self._import_uploaded_image(image)
|
||||
image = self._import_image(image, 'glance-direct')
|
||||
changed = True
|
||||
elif image['status'] == 'importing':
|
||||
image = self._wait_for_image_active(image)
|
||||
|
||||
@@ -235,7 +235,7 @@ class LoadBalancerPoolModule(OpenStackModule):
|
||||
loadbalancer_name_or_id, ignore_missing=False)
|
||||
# Field load_balancer_id is not returned from self.conn.\
|
||||
# load_balancer.find_load_balancer() so use load_balancers instead.
|
||||
if listener['load_balancers'] != [dict(id=loadbalancer.id)]:
|
||||
if pool['loadbalancers'] != [dict(id=loadbalancer.id)]:
|
||||
non_updateable_keys.append('loadbalancer_id')
|
||||
|
||||
if non_updateable_keys:
|
||||
|
||||
@@ -64,6 +64,10 @@ options:
|
||||
choices: [present, absent]
|
||||
default: present
|
||||
type: str
|
||||
availability_zone:
|
||||
description:
|
||||
- The availability zone, in which the load balancer will be deployed.
|
||||
type: str
|
||||
vip_address:
|
||||
description:
|
||||
- IP address of the load balancer virtual IP.
|
||||
@@ -279,6 +283,7 @@ class LoadBalancerModule(OpenStackModule):
|
||||
floating_ip_network=dict(aliases=['public_network']),
|
||||
name=dict(required=True),
|
||||
state=dict(default='present', choices=['absent', 'present']),
|
||||
availability_zone=dict(),
|
||||
vip_address=dict(),
|
||||
vip_network=dict(),
|
||||
vip_port=dict(),
|
||||
@@ -337,7 +342,7 @@ class LoadBalancerModule(OpenStackModule):
|
||||
def _build_update(self, load_balancer):
|
||||
update = {}
|
||||
|
||||
non_updateable_keys = [k for k in ['name', 'vip_address']
|
||||
non_updateable_keys = [k for k in ['name', 'vip_address', 'availability_zone']
|
||||
if self.params[k] is not None
|
||||
and self.params[k] != load_balancer[k]]
|
||||
|
||||
@@ -456,7 +461,7 @@ class LoadBalancerModule(OpenStackModule):
|
||||
|
||||
def _create(self):
|
||||
kwargs = dict((k, self.params[k])
|
||||
for k in ['description', 'name', 'vip_address']
|
||||
for k in ['description', 'name', 'vip_address', 'availability_zone']
|
||||
if self.params[k] is not None)
|
||||
|
||||
flavor_name_or_id = self.params['flavor']
|
||||
|
||||
@@ -252,7 +252,7 @@ class NeutronRBACPolicy(OpenStackModule):
|
||||
|
||||
matches = self._find_matches()
|
||||
if len(matches) > 1:
|
||||
self.fail_json(msg='Found more a single matching RBAC policy'
|
||||
self.fail_json(msg='Found more than a single matching RBAC policy'
|
||||
' which match the given parameters.')
|
||||
elif len(matches) == 1:
|
||||
return matches[0]
|
||||
@@ -269,7 +269,8 @@ class NeutronRBACPolicy(OpenStackModule):
|
||||
.format(', '.join(missing_keys)))
|
||||
|
||||
kwargs = dict((k, self.params[k])
|
||||
for k in ['action', 'object_type', 'project_id'])
|
||||
for k in ['action', 'object_type', 'project_id',
|
||||
'target_project_id'])
|
||||
|
||||
policies = self.conn.network.rbac_policies(**kwargs)
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@ options:
|
||||
name:
|
||||
description:
|
||||
- Name of the recordset. It must be ended with name of dns zone.
|
||||
- A recordset is identified by I(zone), I(name) and I(recordset_type)
|
||||
because DNS allows several recordsets to share a name as long as
|
||||
their types differ.
|
||||
required: true
|
||||
type: str
|
||||
records:
|
||||
@@ -33,6 +36,11 @@ options:
|
||||
description:
|
||||
- Recordset type
|
||||
- Required when I(state=present).
|
||||
- Used to identify the recordset, together with I(zone) and I(name).
|
||||
When I(state=absent) and this option is omitted, the recordset is
|
||||
looked up by name only, which fails when its name carries more than
|
||||
one type, e.g. at the apex of a zone where SOA and NS recordsets
|
||||
share the name of the zone.
|
||||
choices: ['a', 'aaaa', 'mx', 'cname', 'txt', 'ns', 'srv', 'ptr', 'caa']
|
||||
type: str
|
||||
state:
|
||||
@@ -76,12 +84,25 @@ EXAMPLES = '''
|
||||
records: ['10.1.1.1']
|
||||
ttl: 7200
|
||||
|
||||
# Delete recordset named "www.example.net."
|
||||
# Create a recordset at the apex of zone "example.net.", where the SOA and NS
|
||||
# recordsets created with the zone share its name
|
||||
- openstack.cloud.recordset:
|
||||
cloud: mycloud
|
||||
state: present
|
||||
zone: example.net.
|
||||
name: example.net.
|
||||
recordset_type: "a"
|
||||
records: ['10.1.1.1']
|
||||
ttl: 3600
|
||||
|
||||
# Delete the "a" recordset named "www.example.net.", leaving recordsets of
|
||||
# other types with that name untouched
|
||||
- openstack.cloud.recordset:
|
||||
cloud: mycloud
|
||||
state: absent
|
||||
zone: example.net.
|
||||
name: www.example.net.
|
||||
recordset_type: "a"
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
@@ -204,6 +225,18 @@ class DnsRecordsetModule(OpenStackModule):
|
||||
return True
|
||||
return False
|
||||
|
||||
def _find_recordset(self, zone, name):
|
||||
# A recordset is identified by zone, name and type: DNS allows several
|
||||
# recordsets to share a name as long as their types differ, e.g. at the
|
||||
# apex of a zone where the SOA and NS recordsets share the name of the
|
||||
# zone. Looking a recordset up by name only would match all of them and
|
||||
# fail with a DuplicateResource error.
|
||||
query = {}
|
||||
recordset_type = self.params['recordset_type']
|
||||
if recordset_type is not None:
|
||||
query['type'] = recordset_type.upper()
|
||||
return self.conn.dns.find_recordset(zone, name, **query)
|
||||
|
||||
def _build_params(self):
|
||||
recordset_type = self.params['recordset_type']
|
||||
records = self.params['records']
|
||||
@@ -224,7 +257,7 @@ class DnsRecordsetModule(OpenStackModule):
|
||||
ttl = self.params.get('ttl')
|
||||
|
||||
zone = self.conn.dns.find_zone(name_or_id=zone, ignore_missing=False)
|
||||
recordset = self.conn.dns.find_recordset(zone, name)
|
||||
recordset = self._find_recordset(zone, name)
|
||||
|
||||
if self.ansible.check_mode:
|
||||
self.exit_json(changed=self._system_state_change(state, recordset))
|
||||
|
||||
@@ -497,8 +497,15 @@ class RouterModule(OpenStackModule):
|
||||
if 'net' not in iface:
|
||||
self.fail(
|
||||
"Network name missing from interface definition")
|
||||
# First try to find a network in the specified project.
|
||||
net = self.conn.network.find_network(iface['net'],
|
||||
ignore_missing=False)
|
||||
ignore_missing=False,
|
||||
**filters)
|
||||
# Fall back to a global search for the network.
|
||||
if not net:
|
||||
net = self.conn.network.find_network(
|
||||
iface['net'],
|
||||
ignore_missing=False)
|
||||
|
||||
if 'portip' not in iface:
|
||||
# portip not set, add any ip from subnet
|
||||
|
||||
@@ -1228,10 +1228,13 @@ class ServerModule(OpenStackModule):
|
||||
if not isinstance(stringified_nets, list):
|
||||
self.fail_json(msg="The 'nics' parameter must be a list.")
|
||||
|
||||
nets = [(dict((nested_net.split('='),))
|
||||
for nested_net in net.split(','))
|
||||
if isinstance(net, str) else net
|
||||
for net in stringified_nets]
|
||||
nets = []
|
||||
for net in stringified_nets:
|
||||
if isinstance(net, str):
|
||||
for nested_net in net.split(','):
|
||||
nets.append(dict((nested_net.split('='),)))
|
||||
else:
|
||||
nets.append(net)
|
||||
|
||||
for net in nets:
|
||||
if not isinstance(net, dict):
|
||||
|
||||
@@ -17,9 +17,10 @@ options:
|
||||
- Action to perform.
|
||||
- By default, only server owners and administrators are allowed to
|
||||
perform actions C(pause), C(unpause), C(suspend), C(resume), C(lock),
|
||||
C(unlock) and C(shelve_offload).
|
||||
C(unlock), C(shelve_offload) and C(live_migrate).
|
||||
choices: [lock, pause, reboot_hard, reboot_soft, rebuild, resume, shelve,
|
||||
shelve_offload, start, stop, suspend, unlock, unpause, unshelve]
|
||||
shelve_offload, start, stop, suspend, unlock, unpause, unshelve,
|
||||
live_migrate]
|
||||
type: str
|
||||
required: true
|
||||
admin_password:
|
||||
@@ -42,6 +43,13 @@ options:
|
||||
required: true
|
||||
type: str
|
||||
aliases: ['server']
|
||||
host:
|
||||
description:
|
||||
- Target hypervisor host for C(live_migrate) action. If not specified, the server will be
|
||||
live migrated to a suitable host automatically selected by Nova scheduler.
|
||||
type: str
|
||||
required: false
|
||||
version_added: 2.7.0
|
||||
extends_documentation_fragment:
|
||||
- openstack.cloud.openstack
|
||||
'''
|
||||
@@ -53,6 +61,20 @@ EXAMPLES = r'''
|
||||
action: pause
|
||||
server: vm1
|
||||
timeout: 200
|
||||
|
||||
- name: Live migrate compute instance to an auto-selected hypervisor
|
||||
openstack.cloud.server_action:
|
||||
cloud: devstack-admin
|
||||
action: live_migrate
|
||||
server: vm1
|
||||
timeout: 200
|
||||
|
||||
- name: Live migrate compute instance to a specified hypervisor
|
||||
openstack.cloud.server_action:
|
||||
cloud: devstack-admin
|
||||
action: live_migrate
|
||||
server: vm1
|
||||
host: compute1
|
||||
'''
|
||||
|
||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
||||
@@ -64,9 +86,10 @@ class ServerActionModule(OpenStackModule):
|
||||
choices=['stop', 'start', 'pause', 'unpause',
|
||||
'lock', 'unlock', 'suspend', 'reboot_soft',
|
||||
'reboot_hard', 'resume', 'rebuild', 'shelve',
|
||||
'shelve_offload', 'unshelve']),
|
||||
'shelve_offload', 'unshelve', 'live_migrate']),
|
||||
admin_password=dict(no_log=True),
|
||||
all_projects=dict(type='bool', default=False),
|
||||
host=dict(type='str', default=None),
|
||||
image=dict(),
|
||||
name=dict(required=True, aliases=['server']),
|
||||
)
|
||||
@@ -116,7 +139,9 @@ class ServerActionModule(OpenStackModule):
|
||||
'rebuild': ['ACTIVE'],
|
||||
'shelve': ['SHELVED_OFFLOADED', 'SHELVED'],
|
||||
'shelve_offload': ['SHELVED_OFFLOADED'],
|
||||
'unshelve': ['ACTIVE']}
|
||||
'unshelve': ['ACTIVE'],
|
||||
'live_migrate': ['ACTIVE'],
|
||||
}
|
||||
|
||||
def run(self):
|
||||
# TODO: Replace with self.conn.compute.find_server(
|
||||
@@ -141,10 +166,17 @@ class ServerActionModule(OpenStackModule):
|
||||
or (action == 'reboot_soft')
|
||||
or (action == 'lock' and not server['is_locked'])
|
||||
or (action == 'unlock' and server['is_locked'])
|
||||
or (action == 'live_migrate' and not server.status.lower() == 'migrating')
|
||||
or server.status.lower() not in [a.lower()
|
||||
for a
|
||||
in self._action_map[action]])
|
||||
|
||||
# If live_migrate targets the same host the VM is already on, skip it
|
||||
if action == 'live_migrate' and self.params['host'] is not None:
|
||||
current_host = server.get('OS-EXT-SRV-ATTR:host') or server.get('hypervisor_hostname')
|
||||
if current_host and current_host == self.params['host']:
|
||||
self.exit_json(changed=False, msg='VM is already on target host {0}, skipping migration.'.format(self.params['host']))
|
||||
|
||||
if not will_change:
|
||||
self.exit_json(changed=False)
|
||||
elif self.ansible.check_mode:
|
||||
@@ -189,6 +221,11 @@ class ServerActionModule(OpenStackModule):
|
||||
func_name(server, 'SOFT')
|
||||
elif action == 'reboot_hard':
|
||||
func_name(server, 'HARD')
|
||||
elif action == 'live_migrate':
|
||||
kwargs = {}
|
||||
if self.params['host'] is not None:
|
||||
kwargs['host'] = self.params['host']
|
||||
func_name(server, **kwargs)
|
||||
else:
|
||||
func_name(server)
|
||||
|
||||
|
||||
@@ -361,14 +361,14 @@ class SubnetModule(OpenStackModule):
|
||||
self.fail_json(
|
||||
msg='Cannot update {0} in existing subnet'.format(attr))
|
||||
|
||||
def _system_state_change(self, subnet, network, project, subnet_pool):
|
||||
def _system_state_change(self, subnet, network, segment, project, subnet_pool):
|
||||
state = self.params['state']
|
||||
if state == 'absent':
|
||||
return subnet is not None
|
||||
# else state is present
|
||||
if not subnet:
|
||||
return True
|
||||
params = self._build_params(network, project, subnet_pool)
|
||||
params = self._build_params(network, segment, project, subnet_pool)
|
||||
updates = self._build_updates(subnet, params)
|
||||
self._validate_update(subnet, updates)
|
||||
return bool(updates)
|
||||
@@ -478,7 +478,7 @@ class SubnetModule(OpenStackModule):
|
||||
|
||||
if self.ansible.check_mode:
|
||||
self.exit_json(changed=self._system_state_change(
|
||||
subnet, network, project, subnet_pool))
|
||||
subnet, network, segment, project, subnet_pool))
|
||||
|
||||
changed = False
|
||||
if state == 'present':
|
||||
|
||||
@@ -114,7 +114,7 @@ class VolumeTypeAccess(OpenStackModule):
|
||||
|
||||
if project_name_or_id:
|
||||
project_id = self.conn.identity.find_project(
|
||||
project_name_or_id, ignore_missing=False, *kwargs).id
|
||||
project_name_or_id, ignore_missing=False, **kwargs).id
|
||||
else:
|
||||
project_id = None
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
ansible-core>=2.21.0,<2.22.0
|
||||
flake8
|
||||
galaxy-importer
|
||||
openstacksdk
|
||||
pycodestyle
|
||||
pylint
|
||||
rstcheck
|
||||
ruamel.yaml
|
||||
tox
|
||||
voluptuous
|
||||
yamllint
|
||||
setuptools
|
||||
@@ -0,0 +1,170 @@
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from ansible_collections.openstack.cloud.plugins.modules import identity_user
|
||||
from ansible_collections.openstack.cloud.tests.unit.modules.utils import (
|
||||
AnsibleExitJson,
|
||||
ModuleTestCase,
|
||||
set_module_args,
|
||||
)
|
||||
|
||||
|
||||
class FakeUser(dict):
|
||||
'''A dict-like stand-in for an openstacksdk identity.v3.user.User.'''
|
||||
|
||||
def to_dict(self, computed=False):
|
||||
return dict(self)
|
||||
|
||||
|
||||
class FakeSDK(object):
|
||||
class exceptions:
|
||||
class OpenStackCloudException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class TestIdentityUser(ModuleTestCase):
|
||||
|
||||
def _run_module(self, module_args, identity):
|
||||
set_module_args(module_args)
|
||||
conn = mock.Mock()
|
||||
conn.identity = identity
|
||||
with mock.patch.object(
|
||||
identity_user.IdentityUserModule,
|
||||
'openstack_cloud_from_module',
|
||||
return_value=(FakeSDK(), conn),
|
||||
):
|
||||
identity_user.main()
|
||||
|
||||
def _new_identity(self, existing_user=None):
|
||||
identity = mock.Mock()
|
||||
if existing_user is None:
|
||||
identity.find_user.return_value = None
|
||||
else:
|
||||
identity.find_user.return_value = existing_user
|
||||
identity.get_user.return_value = existing_user
|
||||
return identity
|
||||
|
||||
# -- create -----------------------------------------------------------
|
||||
|
||||
def test_create_user_with_options(self):
|
||||
identity = self._new_identity(existing_user=None)
|
||||
identity.create_user.return_value = FakeUser(
|
||||
id='1', name='demouser', is_enabled=True,
|
||||
options={'ignore_password_expiry': True,
|
||||
'ignore_change_password_upon_first_use': True},
|
||||
)
|
||||
|
||||
with self.assertRaises(AnsibleExitJson) as ex:
|
||||
self._run_module({
|
||||
'name': 'demouser',
|
||||
'options': {
|
||||
'ignore_password_expiry': True,
|
||||
'ignore_change_password_upon_first_use': True,
|
||||
},
|
||||
}, identity)
|
||||
|
||||
result = ex.exception.args[0]
|
||||
self.assertTrue(result['changed'])
|
||||
identity.create_user.assert_called_once()
|
||||
_, kwargs = identity.create_user.call_args
|
||||
self.assertEqual(
|
||||
{'ignore_password_expiry': True,
|
||||
'ignore_change_password_upon_first_use': True},
|
||||
kwargs['options'])
|
||||
identity.update_user.assert_not_called()
|
||||
|
||||
def test_create_user_without_options(self):
|
||||
identity = self._new_identity(existing_user=None)
|
||||
identity.create_user.return_value = FakeUser(
|
||||
id='1', name='demouser', is_enabled=True, options={})
|
||||
|
||||
with self.assertRaises(AnsibleExitJson) as ex:
|
||||
self._run_module({'name': 'demouser'}, identity)
|
||||
|
||||
result = ex.exception.args[0]
|
||||
self.assertTrue(result['changed'])
|
||||
identity.create_user.assert_called_once()
|
||||
_, kwargs = identity.create_user.call_args
|
||||
self.assertNotIn('options', kwargs)
|
||||
|
||||
# -- update -----------------------------------------------------------
|
||||
|
||||
def _existing_user(self, **options):
|
||||
return FakeUser(
|
||||
id='1', name='demouser', is_enabled=True, options=options)
|
||||
|
||||
def test_update_user_options_idempotent(self):
|
||||
user = self._existing_user(
|
||||
ignore_password_expiry=True,
|
||||
ignore_change_password_upon_first_use=True,
|
||||
)
|
||||
identity = self._new_identity(existing_user=user)
|
||||
|
||||
with self.assertRaises(AnsibleExitJson) as ex:
|
||||
self._run_module({
|
||||
'name': 'demouser',
|
||||
'options': {
|
||||
'ignore_password_expiry': True,
|
||||
'ignore_change_password_upon_first_use': True,
|
||||
},
|
||||
}, identity)
|
||||
|
||||
result = ex.exception.args[0]
|
||||
self.assertFalse(result['changed'])
|
||||
identity.update_user.assert_not_called()
|
||||
|
||||
def test_update_user_options_change(self):
|
||||
user = self._existing_user(ignore_password_expiry=False)
|
||||
identity = self._new_identity(existing_user=user)
|
||||
identity.update_user.return_value = FakeUser(
|
||||
id='1', name='demouser', is_enabled=True,
|
||||
options={'ignore_password_expiry': True})
|
||||
|
||||
with self.assertRaises(AnsibleExitJson) as ex:
|
||||
self._run_module({
|
||||
'name': 'demouser',
|
||||
'options': {'ignore_password_expiry': True},
|
||||
}, identity)
|
||||
|
||||
result = ex.exception.args[0]
|
||||
self.assertTrue(result['changed'])
|
||||
identity.update_user.assert_called_once_with(
|
||||
'1', options={'ignore_password_expiry': True})
|
||||
|
||||
def test_update_user_options_merge_preserves_existing(self):
|
||||
user = self._existing_user(
|
||||
lock_password=True,
|
||||
ignore_password_expiry=False,
|
||||
)
|
||||
identity = self._new_identity(existing_user=user)
|
||||
identity.update_user.return_value = FakeUser(
|
||||
id='1', name='demouser', is_enabled=True,
|
||||
options={'lock_password': True, 'ignore_password_expiry': True})
|
||||
|
||||
with self.assertRaises(AnsibleExitJson) as ex:
|
||||
self._run_module({
|
||||
'name': 'demouser',
|
||||
'options': {'ignore_password_expiry': True},
|
||||
}, identity)
|
||||
|
||||
result = ex.exception.args[0]
|
||||
self.assertTrue(result['changed'])
|
||||
identity.update_user.assert_called_once_with(
|
||||
'1',
|
||||
options={'lock_password': True, 'ignore_password_expiry': True})
|
||||
|
||||
def test_update_user_without_options_preserves_existing(self):
|
||||
# When no options are specified, existing options must not be touched.
|
||||
user = self._existing_user(ignore_password_expiry=True)
|
||||
identity = self._new_identity(existing_user=user)
|
||||
|
||||
with self.assertRaises(AnsibleExitJson) as ex:
|
||||
self._run_module({'name': 'demouser'}, identity)
|
||||
|
||||
result = ex.exception.args[0]
|
||||
self.assertFalse(result['changed'])
|
||||
identity.update_user.assert_not_called()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -16,13 +16,48 @@ class AnsibleExit(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class FakeSDK(object):
|
||||
class exceptions(object):
|
||||
class OpenStackCloudException(Exception):
|
||||
pass
|
||||
|
||||
class ResourceNotFound(OpenStackCloudException):
|
||||
pass
|
||||
|
||||
|
||||
class HelperServerModule(os_server.ServerModule):
|
||||
def __init__(self, params, conn, sdk):
|
||||
self.params = {}
|
||||
for k, v in self.argument_spec.items():
|
||||
if 'default' in v:
|
||||
self.params[k] = v['default']
|
||||
else:
|
||||
self.params[k] = None
|
||||
self.params.update(params)
|
||||
if ('floating_ips' in params or 'floating_ip_pools' in params) and 'auto_ip' not in params:
|
||||
self.params['auto_ip'] = False
|
||||
self.params = collections.defaultdict(str, self.params)
|
||||
|
||||
self.conn = conn
|
||||
self.sdk = sdk
|
||||
self.module_name = 'server'
|
||||
self.check_mode = False
|
||||
self.results = {'changed': False}
|
||||
self.ansible = mock.MagicMock()
|
||||
self.ansible.check_mode = False
|
||||
self.ansible.exit_json.side_effect = AnsibleExit
|
||||
self.ansible.fail_json.side_effect = AnsibleFail
|
||||
self.exit_json = self.ansible.exit_json
|
||||
self.fail_json = self.ansible.fail_json
|
||||
|
||||
|
||||
def params_from_doc(func):
|
||||
'''This function extracts the docstring from the specified function,
|
||||
parses it as a YAML document, and returns parameters for the openstack.cloud.server
|
||||
module.'''
|
||||
|
||||
doc = inspect.getdoc(func)
|
||||
cfg = yaml.load(doc)
|
||||
cfg = yaml.safe_load(doc)
|
||||
|
||||
for task in cfg:
|
||||
for module, params in task.items():
|
||||
@@ -95,15 +130,32 @@ class TestNetworkArgs(object):
|
||||
|
||||
def setup_method(self, method):
|
||||
self.cloud = FakeCloud()
|
||||
self.module = mock.MagicMock()
|
||||
self.module.params = params_from_doc(method)
|
||||
self.cloud.network = mock.MagicMock()
|
||||
|
||||
def find_network(name, ignore_missing=False):
|
||||
net = self.cloud.get_network(name)
|
||||
if net:
|
||||
return mock.MagicMock(id=net['id'])
|
||||
raise Exception("Network not found")
|
||||
|
||||
def find_port(name, ignore_missing=False):
|
||||
port = self.cloud.get_port(name)
|
||||
if port:
|
||||
return mock.MagicMock(id=port['id'])
|
||||
raise Exception("Port not found")
|
||||
|
||||
self.cloud.network.find_network.side_effect = find_network
|
||||
self.cloud.network.find_port.side_effect = find_port
|
||||
|
||||
self.params = params_from_doc(method)
|
||||
self.module = HelperServerModule(self.params, self.cloud, FakeSDK())
|
||||
|
||||
def test_nics_string_net_id(self):
|
||||
'''
|
||||
- openstack.cloud.server:
|
||||
nics: net-id=1234
|
||||
'''
|
||||
args = os_server._network_args(self.module, self.cloud)
|
||||
args = self.module._parse_nics()
|
||||
assert args[0]['net-id'] == '1234'
|
||||
|
||||
def test_nics_string_net_id_list(self):
|
||||
@@ -111,7 +163,7 @@ class TestNetworkArgs(object):
|
||||
- openstack.cloud.server:
|
||||
nics: net-id=1234,net-id=4321
|
||||
'''
|
||||
args = os_server._network_args(self.module, self.cloud)
|
||||
args = self.module._parse_nics()
|
||||
assert args[0]['net-id'] == '1234'
|
||||
assert args[1]['net-id'] == '4321'
|
||||
|
||||
@@ -120,7 +172,7 @@ class TestNetworkArgs(object):
|
||||
- openstack.cloud.server:
|
||||
nics: port-id=1234
|
||||
'''
|
||||
args = os_server._network_args(self.module, self.cloud)
|
||||
args = self.module._parse_nics()
|
||||
assert args[0]['port-id'] == '1234'
|
||||
|
||||
def test_nics_string_net_name(self):
|
||||
@@ -128,7 +180,7 @@ class TestNetworkArgs(object):
|
||||
- openstack.cloud.server:
|
||||
nics: net-name=network1
|
||||
'''
|
||||
args = os_server._network_args(self.module, self.cloud)
|
||||
args = self.module._parse_nics()
|
||||
assert args[0]['net-id'] == '5678'
|
||||
|
||||
def test_nics_string_port_name(self):
|
||||
@@ -136,7 +188,7 @@ class TestNetworkArgs(object):
|
||||
- openstack.cloud.server:
|
||||
nics: port-name=port1
|
||||
'''
|
||||
args = os_server._network_args(self.module, self.cloud)
|
||||
args = self.module._parse_nics()
|
||||
assert args[0]['port-id'] == '1234'
|
||||
|
||||
def test_nics_structured_net_id(self):
|
||||
@@ -145,7 +197,7 @@ class TestNetworkArgs(object):
|
||||
nics:
|
||||
- net-id: '1234'
|
||||
'''
|
||||
args = os_server._network_args(self.module, self.cloud)
|
||||
args = self.module._parse_nics()
|
||||
assert args[0]['net-id'] == '1234'
|
||||
|
||||
def test_nics_structured_mixed(self):
|
||||
@@ -156,7 +208,7 @@ class TestNetworkArgs(object):
|
||||
- port-name: port1
|
||||
- 'net-name=network1,port-id=4321'
|
||||
'''
|
||||
args = os_server._network_args(self.module, self.cloud)
|
||||
args = self.module._parse_nics()
|
||||
assert args[0]['net-id'] == '1234'
|
||||
assert args[1]['port-id'] == '1234'
|
||||
assert args[2]['net-id'] == '5678'
|
||||
@@ -166,10 +218,31 @@ class TestNetworkArgs(object):
|
||||
class TestCreateServer(object):
|
||||
def setup_method(self, method):
|
||||
self.cloud = FakeCloud()
|
||||
self.module = mock.MagicMock()
|
||||
self.module.params = params_from_doc(method)
|
||||
self.module.fail_json.side_effect = AnsibleFail()
|
||||
self.module.exit_json.side_effect = AnsibleExit()
|
||||
self.cloud.compute = mock.MagicMock()
|
||||
self.cloud.compute.find_server.return_value = None
|
||||
self.cloud.compute.get_server.return_value = mock.MagicMock()
|
||||
self.cloud.compute.get_server.return_value.to_dict.return_value = {'id': '1234'}
|
||||
|
||||
def find_flavor(name_or_id, ignore_missing=True):
|
||||
flavor = self.cloud.get_flavor(name_or_id)
|
||||
if flavor:
|
||||
return mock.MagicMock(id=flavor['id'])
|
||||
if not ignore_missing:
|
||||
raise FakeSDK.exceptions.ResourceNotFound("Could not find flavor {0}".format(name_or_id))
|
||||
return None
|
||||
self.cloud.compute.find_flavor.side_effect = find_flavor
|
||||
|
||||
self.cloud.network = mock.MagicMock()
|
||||
|
||||
def find_network(name, ignore_missing=False):
|
||||
net = self.cloud.get_network(name)
|
||||
if net:
|
||||
return mock.MagicMock(id=net['id'])
|
||||
raise Exception("Network not found")
|
||||
self.cloud.network.find_network.side_effect = find_network
|
||||
|
||||
self.params = params_from_doc(method)
|
||||
self.module = HelperServerModule(self.params, self.cloud, FakeSDK())
|
||||
|
||||
self.meta = mock.MagicMock()
|
||||
self.meta.gett_hostvars_from_server.return_value = {
|
||||
@@ -188,7 +261,7 @@ class TestCreateServer(object):
|
||||
- key: value
|
||||
'''
|
||||
with pytest.raises(AnsibleExit):
|
||||
os_server._create_server(self.module, self.cloud)
|
||||
self.module()
|
||||
|
||||
assert self.cloud.create_server.call_count == 1
|
||||
assert self.cloud.create_server.call_args[1]['image'] == self.cloud.get_image_id('cirros')
|
||||
@@ -204,7 +277,7 @@ class TestCreateServer(object):
|
||||
- net-name: network1
|
||||
'''
|
||||
with pytest.raises(AnsibleFail):
|
||||
os_server._create_server(self.module, self.cloud)
|
||||
self.module()
|
||||
|
||||
assert 'missing_flavor' in self.module.fail_json.call_args[1]['msg']
|
||||
|
||||
@@ -216,8 +289,12 @@ class TestCreateServer(object):
|
||||
nics:
|
||||
- net-name: missing_network
|
||||
'''
|
||||
def find_network_fail(name, ignore_missing=False):
|
||||
raise FakeSDK.exceptions.ResourceNotFound("missing_network")
|
||||
self.cloud.network.find_network.side_effect = find_network_fail
|
||||
|
||||
with pytest.raises(AnsibleFail):
|
||||
os_server._create_server(self.module, self.cloud)
|
||||
self.module()
|
||||
|
||||
assert 'missing_network' in self.module.fail_json.call_args[1]['msg']
|
||||
|
||||
@@ -231,7 +308,7 @@ class TestCreateServer(object):
|
||||
- net-name: network1
|
||||
'''
|
||||
with pytest.raises(AnsibleFail):
|
||||
os_server._create_server(self.module, self.cloud)
|
||||
self.module()
|
||||
|
||||
assert 'auto_ip' in self.module.fail_json.call_args[1]['msg']
|
||||
|
||||
@@ -245,7 +322,7 @@ class TestCreateServer(object):
|
||||
- net-name: network1
|
||||
'''
|
||||
with pytest.raises(AnsibleFail):
|
||||
os_server._create_server(self.module, self.cloud)
|
||||
self.module()
|
||||
|
||||
assert 'floating_ips' in self.module.fail_json.call_args[1]['msg']
|
||||
|
||||
@@ -259,6 +336,6 @@ class TestCreateServer(object):
|
||||
- net-name: network1
|
||||
'''
|
||||
with pytest.raises(AnsibleFail):
|
||||
os_server._create_server(self.module, self.cloud)
|
||||
self.module()
|
||||
|
||||
assert 'floating_ip_pools' in self.module.fail_json.call_args[1]['msg']
|
||||
|
||||
@@ -53,16 +53,59 @@ hostvars = {
|
||||
}
|
||||
|
||||
|
||||
try:
|
||||
from ansible._internal._templating._engine import TrustedAsTemplate
|
||||
has_trusted = True
|
||||
except ImportError:
|
||||
has_trusted = False
|
||||
|
||||
|
||||
def tag_trusted(val):
|
||||
if not has_trusted:
|
||||
return val
|
||||
if isinstance(val, dict):
|
||||
return {k: tag_trusted(v) for k, v in val.items()}
|
||||
elif isinstance(val, list):
|
||||
return [tag_trusted(v) for v in val]
|
||||
elif isinstance(val, str):
|
||||
return TrustedAsTemplate().tag(val)
|
||||
return val
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def inventory():
|
||||
inventory = InventoryModule()
|
||||
inventory._config_data = config_data
|
||||
inventory._config_data = tag_trusted(config_data)
|
||||
inventory.inventory = InventoryData()
|
||||
inventory.templar = Templar(loader=None)
|
||||
|
||||
for host in hostvars:
|
||||
inventory.inventory.add_host(host)
|
||||
|
||||
def _set_variables(hostvars, groups):
|
||||
for host in hostvars:
|
||||
try:
|
||||
inventory._set_composite_vars(
|
||||
inventory._config_data.get('compose'), hostvars[host], host, strict=True)
|
||||
except Exception as e:
|
||||
print("set_composite_vars error: %s" % e)
|
||||
raise
|
||||
for key in hostvars[host]:
|
||||
inventory.inventory.set_variable(host, key, hostvars[host][key])
|
||||
try:
|
||||
inventory._add_host_to_composed_groups(
|
||||
inventory._config_data.get('groups'), hostvars[host], host, strict=True)
|
||||
except Exception as e:
|
||||
print("add_host_to_composed_groups error: %s" % e)
|
||||
raise
|
||||
try:
|
||||
inventory._add_host_to_keyed_groups(
|
||||
inventory._config_data.get('keyed_groups'), hostvars[host], host, strict=True)
|
||||
except Exception as e:
|
||||
print("add_host_to_keyed_groups error: %s" % e)
|
||||
raise
|
||||
|
||||
inventory._set_variables = _set_variables
|
||||
return inventory
|
||||
|
||||
|
||||
|
||||
@@ -44,3 +44,7 @@ ansible-test sanity -v \
|
||||
--python ${PY_VER} \
|
||||
$SKIP_TESTS \
|
||||
plugins/ docs/ meta/
|
||||
|
||||
ansible-test units -v \
|
||||
--venv \
|
||||
--python ${PY_VER}
|
||||
|
||||
@@ -41,7 +41,7 @@ commands =
|
||||
ansible-galaxy collection build --force {toxinidir} --output-path {toxinidir}/build_artifact
|
||||
bash {toxinidir}/tools/check-import.sh {toxinidir}
|
||||
|
||||
[testenv:linters_{2_18,2_19,2_20,latest}]
|
||||
[testenv:linters_{2_18,2_19,2_20,2_21,latest}]
|
||||
allowlist_externals = bash
|
||||
commands =
|
||||
{[testenv:build]commands}
|
||||
@@ -55,6 +55,7 @@ deps =
|
||||
linters_2_18: -r{toxinidir}/tests/requirements-ansible-2.18.txt
|
||||
linters_2_19: -r{toxinidir}/tests/requirements-ansible-2.19.txt
|
||||
linters_2_20: -r{toxinidir}/tests/requirements-ansible-2.20.txt
|
||||
linters_2_21: -r{toxinidir}/tests/requirements-ansible-2.21.txt
|
||||
passenv = *
|
||||
|
||||
[flake8]
|
||||
@@ -68,7 +69,7 @@ ignore = W503,H4,E501,E402,H301
|
||||
show-source = True
|
||||
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,ansible_collections
|
||||
|
||||
[testenv:ansible_{2_18,2_19,2_20,latest}]
|
||||
[testenv:ansible_{2_18,2_19,2_20,2_21,latest}]
|
||||
allowlist_externals = bash
|
||||
commands =
|
||||
bash {toxinidir}/ci/run-ansible-tests-collection.sh -e {envdir} {posargs}
|
||||
@@ -78,6 +79,7 @@ deps =
|
||||
ansible_2_18: -r{toxinidir}/tests/requirements-ansible-2.18.txt
|
||||
ansible_2_19: -r{toxinidir}/tests/requirements-ansible-2.19.txt
|
||||
ansible_2_20: -r{toxinidir}/tests/requirements-ansible-2.20.txt
|
||||
ansible_2_21: -r{toxinidir}/tests/requirements-ansible-2.21.txt
|
||||
# Need to pass some env vars for the Ansible playbooks
|
||||
passenv =
|
||||
HOME
|
||||
|
||||
Reference in New Issue
Block a user