Add SDK logging option for openstack ansible collections.

The solution is based on implementation of logging option
in Open Telekom Cloud collections.

Change-Id: Ie8b309d2aaa8da57794888848fc5414de207e54f
(cherry picked from commit 19cd6262cf)
This commit is contained in:
Vladimir Hasko 2022-06-03 08:09:08 +00:00 committed by Jakob Meng
parent e8bba38e2e
commit c435002734
5 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1 @@
sdk_log_file_path: "{{ playbook_dir }}/sdk.log"

View File

@ -0,0 +1,20 @@
---
- name: Trigger flavor listing
openstack.cloud.compute_flavor_info:
cloud: "{{ cloud }}"
sdk_log_path: "{{ sdk_log_file_path }}"
sdk_log_level: "DEBUG"
- name: Check log file presence
ansible.builtin.stat:
path: "{{ sdk_log_file_path }}"
register: sdk_log_file
- name: Assert
ansible.builtin.assert:
that:
- "sdk_log_file.stat.exists"
- name: Debug log file content
ansible.builtin.debug:
msg: "{{ lookup('ansible.builtin.file', sdk_log_file_path) }}"

View File

@ -38,6 +38,7 @@
- role: keystone_federation_protocol
tags: keystone_federation_protocol
when: sdk_version is version(0.44, '>=')
- { role: logging, tags: logging }
- { role: network, tags: network }
- role: neutron_rbac
tags:

View File

@ -89,6 +89,15 @@ options:
description:
- Ignored. Present for backwards compatibility
type: str
sdk_log_path:
description:
- Path to the logfile of the OpenStackSDK. If empty no log is written
type: str
sdk_log_level:
description: Log level of the OpenStackSDK
type: str
default: INFO
choices: [INFO, DEBUG]
requirements:
- python >= 3.6
- openstacksdk >= 0.36, < 0.99.0

View File

@ -173,6 +173,9 @@ def openstack_full_argument_spec(**kwargs):
interface=dict(
default='public', choices=['public', 'internal', 'admin'],
aliases=['endpoint_type']),
sdk_log_path=dict(default=None, type='str'),
sdk_log_level=dict(
default='INFO', type='str', choices=['INFO', 'DEBUG']),
)
# Filter out all our custom parameters before passing to AnsibleModule
kwargs_copy = copy.deepcopy(kwargs)
@ -303,6 +306,7 @@ class OpenStackModule:
self.warn = self.ansible.warn
self.sdk, self.conn = self.openstack_cloud_from_module()
self.check_deprecated_names()
self.setup_sdk_logging()
def log(self, msg):
"""Prints log message to system log.
@ -322,6 +326,16 @@ class OpenStackModule:
self.ansible.log(
" ".join(['[DEBUG]', msg]))
def setup_sdk_logging(self):
log_path = self.params.get('sdk_log_path')
if log_path is not None:
log_level = self.params.get('sdk_log_level')
self.sdk.enable_logging(
debug=True if log_level == 'DEBUG' else False,
http_debug=True if log_level == 'DEBUG' else False,
path=log_path
)
def check_deprecated_names(self):
"""Check deprecated module names if `deprecated_names` variable is set.
"""