diff --git a/.zuul.yaml b/.zuul.yaml index e4c41a11..571fdf3d 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -87,6 +87,7 @@ keystone_federation_protocol keystone_idp keystone_mapping + logging loadbalancer network nova_flavor diff --git a/ci/roles/logging/defaults/main.yaml b/ci/roles/logging/defaults/main.yaml new file mode 100644 index 00000000..e7a2e703 --- /dev/null +++ b/ci/roles/logging/defaults/main.yaml @@ -0,0 +1 @@ +sdk_log_file_path: "{{ playbook_dir }}/sdk.log" diff --git a/ci/roles/logging/tasks/main.yaml b/ci/roles/logging/tasks/main.yaml new file mode 100644 index 00000000..56263e97 --- /dev/null +++ b/ci/roles/logging/tasks/main.yaml @@ -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) }}" diff --git a/ci/run-collection.yml b/ci/run-collection.yml index be4337e8..b900e1c0 100644 --- a/ci/run-collection.yml +++ b/ci/run-collection.yml @@ -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: diff --git a/plugins/doc_fragments/openstack.py b/plugins/doc_fragments/openstack.py index 57d68302..6dc62376 100644 --- a/plugins/doc_fragments/openstack.py +++ b/plugins/doc_fragments/openstack.py @@ -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 diff --git a/plugins/module_utils/openstack.py b/plugins/module_utils/openstack.py index 80c89b1f..003e6a64 100644 --- a/plugins/module_utils/openstack.py +++ b/plugins/module_utils/openstack.py @@ -131,6 +131,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) @@ -278,6 +281,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. @@ -297,6 +301,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. """