Skip to content

Commit 856541a

Browse files
committed
reworked for new repo list structure
1 parent aedd0ec commit 856541a

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

ansible/ci/library/latest_timestamps.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
# Pass in a message
2424
- name: Get latest timestamps
2525
latest_timestamps:
26-
current_timestamps_dict: "{{ appliances_repo_timestamps }}"
27-
sources_dict: "{{ appliances_repo_timestamp_sources }}"
26+
repos_dict: "{{ appliances_repo_timestamp_sources }}"
27+
content_url: "https://ark.stackhpc.com/pulp/content"
2828
register: result
2929
3030
'''
@@ -44,11 +44,12 @@
4444
from ansible.module_utils.basic import AnsibleModule
4545
import requests
4646
from bs4 import BeautifulSoup
47+
from copy import deepcopy
4748

4849
def run_module():
4950
module_args = dict(
50-
current_timestamps_dict=dict(type='dict', required=True),
51-
sources_dict=dict(type='dict', required=True)
51+
repos_dict=dict(type='dict', required=True),
52+
content_url=dict(type='str', required=True)
5253
)
5354

5455
result = dict(
@@ -62,17 +63,23 @@ def run_module():
6263
supports_check_mode=True
6364
)
6465

65-
latest_timestamps = {}
66+
original_timestamps = dict(module.params['repos_dict'])
67+
latest_timestamps = deepcopy(original_timestamps)
6668
changed_timestamps = []
67-
for repo in module.params['sources_dict']:
68-
latest_timestamps[repo] = module.params['sources_dict'][repo]
69-
for version in module.params['sources_dict'][repo]:
70-
html_txt = requests.get(url=module.params['sources_dict'][repo][version]).text
71-
timestamp_link_list = BeautifulSoup(html_txt,features="html.parser").body.find('pre').find_all()
72-
timestamp_link_list = map(lambda x: x.string,timestamp_link_list) # xml tags
73-
latest_timestamps[repo][version] = list(timestamp_link_list)[-1][:-1] # last timestamp in list with trailing / removed
74-
if module.params['sources_dict'][repo][version] != module.params['current_timestamps_dict'][repo][version]:
75-
changed_timestamps.append(repo+' '+version)
69+
70+
for repo in original_timestamps:
71+
for version in original_timestamps[repo]:
72+
73+
html_txt = requests.get(
74+
url= module.params['content_url'] + '/' + original_timestamps[repo][version]['path']
75+
).text
76+
timestamp_link_list = BeautifulSoup(html_txt,features="html.parser").body.find('pre').find_all() # getting raw list of timestamps from html
77+
timestamp_link_list = map(lambda x: x.string,timestamp_link_list) # stripping xml tags
78+
latest_timestamp = list(timestamp_link_list)[-1][:-1] # last timestamp in list with trailing / removed
79+
80+
latest_timestamps[repo][version]['timestamp'] = latest_timestamp
81+
if original_timestamps[repo][version]['timestamp'] != latest_timestamp:
82+
changed_timestamps.append(repo+' '+version+': '+original_timestamps[repo][version]['timestamp']+' -> '+latest_timestamp)
7683

7784
result['latest_dict'] = latest_timestamps
7885
result['changed_timestamps'] = changed_timestamps

ansible/ci/update_timestamps.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
- hosts: localhost
22
tasks:
3-
- name: Check sources are defined for all repos
4-
ansible.builtin.assert:
5-
that: appliances_repo_timestamps[item].keys() == appliances_repo_timestamp_sources[item].keys()
6-
fail_msg: "'appliances_repo_timestamps.{{ item }}' is missing a source definition in 'appliances_repo_timestamp_sources'"
7-
loop: "{{ appliances_repo_timestamps.keys() }}"
8-
93
- name: Get latest timestamps from sources
104
latest_timestamps:
11-
sources_dict: "{{ appliances_repo_timestamp_sources }}"
12-
current_timestamps_dict: "{{ appliances_repo_timestamps }}"
5+
repos_dict: "{{ appliances_pulp_repos }}"
6+
content_url: "https://ark.stackhpc.com/pulp/content"
137
register: _result
148

159
- name: Print updated timestamps

0 commit comments

Comments
 (0)