diff options
author | Zuul <zuul@review.openstack.org> | 2018-07-13 11:40:03 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2018-07-13 11:40:03 +0000 |
commit | bd5302f0ee917aaa354950ec26d96b79ef857395 (patch) | |
tree | 37279cd70d2507d9eec6b12ae2b54483a1b0b2ab | |
parent | 9f481aba248c92c91ffa945164e37a34bc0dbee6 (diff) | |
parent | 3a644f7764670b347d20caf680b35dfa0fdf2f03 (diff) |
Merge "Add CI script to retrieve info from build logs"
-rwxr-xr-x | tests/files/process_build_logs.py | 80 | ||||
-rw-r--r-- | tests/playbooks/post.yml | 3 |
2 files changed, 83 insertions, 0 deletions
diff --git a/tests/files/process_build_logs.py b/tests/files/process_build_logs.py new file mode 100755 index 0000000..f2d6817 --- /dev/null +++ b/tests/files/process_build_logs.py | |||
@@ -0,0 +1,80 @@ | |||
1 | #!/usr/bin/python | ||
2 | |||
3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
4 | # you may not use this file except in compliance with the License. | ||
5 | # You may obtain a copy of the License at | ||
6 | # | ||
7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
8 | # | ||
9 | # Unless required by applicable law or agreed to in writing, software | ||
10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
12 | # See the License for the specific language governing permissions and | ||
13 | # limitations under the License. | ||
14 | |||
15 | import argparse | ||
16 | import collections | ||
17 | import glob | ||
18 | import os | ||
19 | import re | ||
20 | import sys | ||
21 | |||
22 | parser = argparse.ArgumentParser( | ||
23 | description='Parse kolla build logs and extract useful information about ' | ||
24 | 'the installed packages.') | ||
25 | parser.add_argument('-l', '--logdir', | ||
26 | help='Path to the build log files', | ||
27 | required=True) | ||
28 | parser.add_argument('-b', '--base', | ||
29 | help='The kolla base_distro', | ||
30 | required=True) | ||
31 | args = vars(parser.parse_args()) | ||
32 | |||
33 | if args['base'] not in ['centos', 'rhel', 'oraclelinux']: | ||
34 | print("Non rpm-based distros are not yet supported.") | ||
35 | sys.exit() | ||
36 | |||
37 | obsolete = {} | ||
38 | pkg_installs = collections.defaultdict(set) | ||
39 | |||
40 | for filename in glob.glob(os.path.join(args['logdir'], '*.log')): | ||
41 | image = os.path.splitext(os.path.basename(filename))[0] | ||
42 | with open(filename) as f: | ||
43 | for line in f: | ||
44 | m = re.search(r"Package (.+) is obsoleted by (.+),", line) | ||
45 | if m: | ||
46 | if not m.group(1) in obsolete: | ||
47 | obsolete[m.group(1)] = {'obsoleted_by': m.group(2), | ||
48 | 'images': [image]} | ||
49 | else: | ||
50 | obsolete[m.group(1)]['images'].append(image) | ||
51 | |||
52 | m = re.search(r"Package (.+)\..+ .+ will be installed", line) | ||
53 | if m: | ||
54 | pkg_installs[m.group(1)].add(image) | ||
55 | |||
56 | m = re.search(r"Processing Dependency: (.+)\(", line) | ||
57 | if m: | ||
58 | pkg_installs[m.group(1)].add(image) | ||
59 | |||
60 | if obsolete: | ||
61 | print("Found %s obsolete(s) package(s):" % len(obsolete)) | ||
62 | for pkg in obsolete: | ||
63 | print("%s is obsoleted by %s (%s)" % | ||
64 | (pkg, | ||
65 | obsolete[pkg]['obsoleted_by'], | ||
66 | ', '.join(obsolete[pkg]['images']))) | ||
67 | print('') | ||
68 | |||
69 | move_to_base_candidates = [ | ||
70 | pkg for pkg in pkg_installs if len(pkg_installs[pkg]) > 10 | ||
71 | and not ('base' in pkg_installs[pkg] | ||
72 | or 'openstack-base' in pkg_installs[pkg]) | ||
73 | ] | ||
74 | |||
75 | if move_to_base_candidates: | ||
76 | print("Consider moving the following packages to a base image:") | ||
77 | for pkg in move_to_base_candidates: | ||
78 | print("%s (%s)" % | ||
79 | (pkg, | ||
80 | ', '.join(pkg_installs[pkg]))) | ||
diff --git a/tests/playbooks/post.yml b/tests/playbooks/post.yml index 574917e..577b12b 100644 --- a/tests/playbooks/post.yml +++ b/tests/playbooks/post.yml | |||
@@ -55,6 +55,9 @@ | |||
55 | # fix the permissions for logs folder | 55 | # fix the permissions for logs folder |
56 | sudo chmod -R 777 logs | 56 | sudo chmod -R 777 logs |
57 | 57 | ||
58 | # Parse build logs and extract pkg install info | ||
59 | tests/files/process_build_logs.py -l logs/build -b {{ base_distro }} > logs/packages-info.txt | ||
60 | |||
58 | # rename files to .txt; this is so that when displayed via | 61 | # rename files to .txt; this is so that when displayed via |
59 | # logs.openstack.org clicking results in the browser shows the | 62 | # logs.openstack.org clicking results in the browser shows the |
60 | # files, rather than trying to send it to another app or make you | 63 | # files, rather than trying to send it to another app or make you |