Skip to content

Commit 024f083

Browse files
committed
feat: response error handling, SPS version, verbosity, plan debug
1 parent 6290717 commit 024f083

File tree

6 files changed

+55
-15
lines changed

6 files changed

+55
-15
lines changed

plugins/module_utils/sap_api_common.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,23 @@ def _request(url, **kwargs):
3737
method = 'POST' if kwargs.get('data') or kwargs.get('json') else 'GET'
3838
res = https_session.request(method, url, **kwargs)
3939

40-
if (res.status_code == 403
41-
and res.json()['errorMessage'].startswith('Account Temporarily Locked Out')):
42-
raise Exception('SAP ID Service has reported `Account Temporarily Locked Out`. Please reset password to regain access and try again.')
40+
# Validating against `res.text` can cause long execution time, because fuzzy search result can contain large `res.text`.
41+
# This can be prevented by validating `res.status_code` check before `res.text`.
42+
# Example: 'Two-Factor Authentication' is only in `res.text`, which can lead to long execution.
43+
44+
if res.status_code == 403:
45+
if 'You are not authorized to download this file' in res.text:
46+
raise Exception(f'You are not authorized to download this file.')
47+
elif 'Account Temporarily Locked Out' in res.text:
48+
raise Exception(f'Account Temporarily Locked Out. Please reset password to regain access and try again.')
49+
else:
50+
res.raise_for_status()
51+
52+
if res.status_code == 404:
53+
if 'The file you have requested cannot be found' in res.text:
54+
raise Exception(f'The file you have requested cannot be found.')
55+
else:
56+
res.raise_for_status()
4357

4458
res.raise_for_status()
4559

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
---
3+
galaxy_info:
4+
namespace: community
5+
author: SUSE, Marcel Mamula
6+
description: Downloads SAP Software Media from SAP using an S-User ID and password, supporting both direct file downloads and Maintenance Plan transactions.
7+
company: SUSE
8+
license: Apache-2.0
9+
min_ansible_version: 2.16
10+
platforms:
11+
- name: EL
12+
versions: ["7", "8", "9"]
13+
- name: SLES
14+
versions: ["15", "16"]
15+
galaxy_tags:
16+
- sap
17+
- download
18+
- suse
19+
- redhat
20+
dependencies: []

roles/sap_software_download/tasks/download_plan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
- name: Download - Maintenance Plan - Show failed results
5252
ansible.builtin.fail:
5353
msg: |
54-
Maintenance Plan file(s) not found: {{ __failed_items | map(attribute='Filename') | list | join(', ') }}
54+
Maintenance Plan file(s) not found: {{ __failed_items | map(attribute='item.Filename') | list | join(', ') }}
5555
Verify your Maintenance Plan on SAP Launchpad before retrying.
5656
vars:
5757
__failed_items: "{{ __sap_software_download_files_plan_results.results

roles/sap_software_download/tasks/pre_steps/03_validate_credentials.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
---
33
# This task attempts dry run to check SAPCAR file in order to validate provided credentials.
44

5-
- name: Validate Credentials - Dry run to download test file with Python venv
5+
- name: Validate Credentials - Dry run check user credentials and download privilege with Python venv
66
when: sap_software_download_use_venv | d(true)
77
community.sap_launchpad.software_center_download:
88
suser_id: "{{ sap_software_download_suser_id }}"
@@ -13,6 +13,8 @@
1313
deduplicate: "last"
1414
dry_run: true
1515
register: __sap_software_download_validate_credentials_venv
16+
retries: 1
17+
delay: 5
1618
environment:
1719
PATH: "{{ __sap_software_download_venv.path }}/bin:{{ ansible_env.PATH }}"
1820
PYTHONPATH: "{{ __sap_software_download_venv.path }}/lib/{{ sap_software_download_python_interpreter }}/site-packages"
@@ -21,7 +23,7 @@
2123
ansible_python_interpreter: "{{ __sap_software_download_venv.path ~ '/bin/' ~ sap_software_download_python_interpreter }}"
2224
ignore_errors: true # Errors are ignored and validated afterwards
2325

24-
- name: Validate Credentials - Dry run to download test file with Python system default
26+
- name: Validate Credentials - Dry run check user credentials and download privilege with Python system default
2527
when: not sap_software_download_use_venv | d(true)
2628
community.sap_launchpad.software_center_download:
2729
suser_id: "{{ sap_software_download_suser_id }}"
@@ -32,6 +34,8 @@
3234
deduplicate: "last"
3335
dry_run: true
3436
register: __sap_software_download_validate_credentials_default
37+
retries: 1
38+
delay: 5
3539
vars:
3640
ansible_python_interpreter: "{{ '/usr/bin/' ~ sap_software_download_python_interpreter }}"
3741
ignore_errors: true # Errors are ignored and validated afterwards

roles/sap_software_download/tasks/pre_steps/06_validate_sap_hana_1.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# 122 for IMDB_SERVER100_122_35-10009569.SAR
77
__sap_software_download_sap_hana_1_version:
88
"{{ __sap_software_download_sap_hana.split('_')[2] | regex_replace('[^0-9]', '') }}"
9-
9+
1010
# 35 for IMDB_SERVER100_122_35-10009569.SAR
1111
__sap_software_download_sap_hana_1_revision:
1212
"{{ __sap_software_download_sap_hana.split('_')[3].split('-')[0] | regex_replace('[^0-9]', '') }}"
@@ -21,8 +21,9 @@
2121
- name: Relationship Validation - SAP HANA 1.00 - IMDB_SERVER and IMDB_LCAPPS
2222
ansible.builtin.fail:
2323
msg: |
24-
Warning: Incompatible SAP HANA component LCAPPS files were found for detected SAP HANA DATABASE 1.0 {{
25-
__sap_software_download_sap_hana_1_version }}.{{ __sap_software_download_sap_hana_1_revision }}.
24+
Warning: Incompatible SAP HANA component LCAPPS files were found for detected SAP HANA DATABASE 1.0 SPS {{
25+
__sap_software_download_sap_hana_1_version[:2] }} Revision {{ __sap_software_download_sap_hana_1_version
26+
}}.{{ __sap_software_download_sap_hana_1_revision }}.
2627
2728
Expected file pattern: IMDB_LCAPPS_{{
2829
__sap_software_download_sap_hana_1_version }}*_{{__sap_software_download_sap_hana_1_revision }}*
@@ -48,8 +49,9 @@
4849
- name: Relationship Validation - SAP HANA 1.00 - IMDB_SERVER and IMDB_AFL
4950
ansible.builtin.fail:
5051
msg: |
51-
Warning: Incompatible SAP HANA component AFL files were found for detected SAP HANA DATABASE 1.0 {{
52-
__sap_software_download_sap_hana_1_version }}.{{ __sap_software_download_sap_hana_1_revision }}.
52+
Warning: Incompatible SAP HANA component AFL files were found for detected SAP HANA DATABASE 1.0 SPS {{
53+
__sap_software_download_sap_hana_1_version[:2] }} Revision {{ __sap_software_download_sap_hana_1_version
54+
}}.{{ __sap_software_download_sap_hana_1_revision }}.
5355
5456
Expected file pattern: IMDB_AFL100_{{ __sap_software_download_sap_hana_1_version }}*_{{ __sap_software_download_sap_hana_1_revision }}*
5557
Actual files detected: {{ __sap_software_download_sap_hana_1_afl_list | unique | join(', ') }}

roles/sap_software_download/tasks/pre_steps/07_validate_sap_hana_2.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
- name: Relationship Validation - SAP HANA 2.00 - IMDB_SERVER and IMDB_LCAPPS
1818
ansible.builtin.fail:
1919
msg: |
20-
Warning: Incompatible SAP HANA component LCAPPS files were found for detected SAP HANA DATABASE 2.0 Revision {{
21-
__sap_software_download_sap_hana_2_version }}.
20+
Warning: Incompatible SAP HANA component LCAPPS files were found for detected SAP HANA DATABASE 2.0 SPS {{
21+
__sap_software_download_sap_hana_2_version[:2] }} Revision {{ __sap_software_download_sap_hana_2_version }}.
2222
2323
Expected file pattern: IMDB_LCAPPS_2{{ __sap_software_download_sap_hana_2_version }}*
2424
Actual files detected: {{ __sap_software_download_sap_hana_2_lcapps_list | unique | join(', ') }}
@@ -42,8 +42,8 @@
4242
- name: Relationship Validation - SAP HANA 2.00 - IMDB_SERVER and IMDB_AFL
4343
ansible.builtin.fail:
4444
msg: |
45-
Warning: Incompatible SAP HANA component AFL files were found for detected SAP HANA DATABASE 2.0 Revision {{
46-
__sap_software_download_sap_hana_2_version }}.
45+
Warning: Incompatible SAP HANA component AFL files were found for detected SAP HANA DATABASE 2.0 SPS {{
46+
__sap_software_download_sap_hana_2_version[:2] }} Revision {{ __sap_software_download_sap_hana_2_version }}.
4747
4848
Expected file pattern: IMDB_AFL20_{{ __sap_software_download_sap_hana_2_version }}*
4949
Actual files detected: {{ __sap_software_download_sap_hana_2_afl_list | unique | join(', ') }}

0 commit comments

Comments
 (0)