Add initial code
[ta/build-tools.git] / tools / script / create_rpm_data_test_data.py
1 # -*- coding: utf-8 -*-
2 # Copyright 2019 Nokia
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # pylint: disable=invalid-name
17 from tools.rpm_test_data import cpp_expected
18
19 yum_installed_output = """Loaded plugins: fastestmirror, priorities
20 Loading mirror speeds from cached hostfile
21 Installed Packages
22 Name        : non-repo-pkg-1
23 Arch        : x86_64
24 Version     : 1
25 Release     : 1
26 Repo        : installed
27
28 Name        : non-repo-pkg-2
29 Arch        : noarch
30 Version     : 2
31 Release     : 2
32 Repo        : installed
33 Obsoletes   : (none)
34
35 Name        : base-image-pkg
36 Arch        : x86_64
37 Version     : 3
38 Release     : 3
39 Repo        : installed
40 From repo   : base
41
42 Name        : internal-pkg
43 Arch        : noarch
44 Version     : 4
45 Release     : 4
46 Repo        : installed
47 From repo   : localrepo
48
49 Name        : 3rdparty-pkg
50 Arch        : x86_64
51 Version     : 5
52 Release     : 5
53 Repo        : installed
54 From repo   : purkki-3rdparty
55 Obsoletes   : 2ndparty-pkg
56
57 """
58
59 rpm_info_output = """Name        : non-repo-pkg-1
60 Version     : 1
61 Release     : 1
62 Architecture: x86_64
63 Source RPM  : non-repo-pkg-1-1-1.src.rpm
64 Name        : non-repo-pkg-2
65 Version     : 2
66 Release     : 2
67 Architecture: noarch
68 Source RPM  : non-repo-pkg-2-2-2.src.rpm
69 Name        : base-image-pkg
70 Version     : 3
71 Release     : 3
72 Architecture: x86_64
73 Source RPM  : base-image-pkg-3-3.src.rpm
74 Name        : internal-pkg
75 Version     : 4
76 Release     : 4
77 Architecture: noarch
78 Source RPM  : internal-pkg-4-4.src.rpm
79 Name        : 3rdparty-pkg
80 Version     : 5
81 Release     : 5
82 Architecture: x86_64
83 Source RPM  : 3rdparty-pkg-5-5.src.rpm
84 """  # noqa, PEP-8 disabled because of example output has trailing spaces
85
86 yum_available_output_header = """Added tmprepo repo from http://url1/
87 Available Packages
88 """
89
90 yum_available_output_base = """
91 Name        : base-image-pkg
92 Arch        : x86_64
93 Epoch       : 0
94 Version     : 3
95 Release     : 3
96 Size        : 195 k
97 Repo        : base
98 """
99
100 yum_available_output_none2 = """
101 Name        : non-repo-pkg-1
102 Arch        : x86_64
103 Epoch       : 0
104 Version     : 1
105 Release     : 1
106 Size        : 195 k
107 Repo        : none2
108 """
109
110 yum_available_output_none1 = """
111 Name        : non-repo-pkg-2
112 Arch        : noarch
113 Version     : 2
114 Release     : 2
115 Size        : 195 k
116 Repo        : none1
117 """
118
119 yum_available_output_localrepo = """
120 Name        : internal-pkg
121 Arch        : x86_64
122 Epoch       : 0
123 Version     : 4
124 Release     : 4
125 Size        : 195 k
126 Repo        : localrepo
127 """
128
129 yum_available_output_purkki_3rdparty = """
130 Name        : 3rdparty-pkg
131 Arch        : x86_64
132 Epoch       : 0
133 Version     : 5
134 Release     : 5
135 Size        : 195 k
136 Repo        : purkki-3rdparty
137 """
138
139 yum_available_output = yum_available_output_header + yum_available_output_base + \
140                        yum_available_output_none1 + yum_available_output_none2 + \
141                        yum_available_output_localrepo + yum_available_output_purkki_3rdparty
142
143 internal_pkg_bom = [{'name': '@types/d3-axis',
144                      'version': '1.0.10',
145                      'foss': 'yes',
146                      'source-url': 'http://some.url/1',
147                      'crypto-capable': True},
148                     {'name': '@types/d3-array@*',
149                      'version': '1.2.1',
150                      'foss': 'Yes',
151                      'source-url': 'http://some.url/2'}]
152 boms_output = {'internal-pkg-4-4.noarch': {"bom": internal_pkg_bom}}
153
154 expected_output = [
155     {
156         'Name': 'non-repo-pkg-1',
157         'Architecture': 'x86_64',
158         'Version': '1',
159         'Release': '1',
160         'Repo': 'installed',
161         'Repo data': {'baseurl': 'test-url-for-none2', 'name': 'none2'},
162         'Obsoletes': 'N/A',
163         'Source RPM': 'non-repo-pkg-1-1-1.src.rpm',
164         'Crypto capable': False,
165         'BOM': '',
166     }, {
167         'Name': 'non-repo-pkg-2',
168         'Architecture': 'noarch',
169         'Version': '2',
170         'Release': '2',
171         'Repo': 'installed',
172         'Repo data': {'baseurl': 'test-url-for-none1', 'name': 'none1'},
173         'Obsoletes': 'N/A',
174         'Source RPM': 'non-repo-pkg-2-2-2.src.rpm',
175         'Crypto capable': False,
176         'BOM': '',
177     }, {
178         'Name': 'base-image-pkg',
179         'Architecture': 'x86_64',
180         'Version': '3',
181         'Release': '3',
182         'Repo': 'installed',
183         'From repo': 'base',
184         'Repo data': {'baseurl': 'test-url-for-base', 'name': 'base'},
185         'Obsoletes': 'N/A',
186         'Source RPM': 'base-image-pkg-3-3.src.rpm',
187         'Crypto capable': False,
188         'BOM': '',
189     }, {
190         'Name': 'internal-pkg',
191         'Architecture': 'noarch',
192         'Version': '4',
193         'Release': '4',
194         'Repo': 'installed',
195         'From repo': 'localrepo',
196         'Repo data': {'baseurl': 'test-url/artifact/results/repo',
197                       'name': 'localrepo'},
198         'Obsoletes': 'N/A',
199         'Source RPM': 'internal-pkg-4-4.src.rpm',
200         'Crypto capable': True,
201         'BOM': internal_pkg_bom,
202     }, {
203         'Name': '3rdparty-pkg',
204         'Architecture': 'x86_64',
205         'Version': '5',
206         'Release': '5',
207         'Repo': 'installed',
208         'From repo': 'purkki-3rdparty',
209         'Repo data': {'baseurl': 'test-url-for-purkki-3rdparty', 'name': 'purkki-3rdparty',
210                       'test-extra-option': 'test-value'},
211         'Obsoletes': '2ndparty-pkg',
212         'Source RPM': '3rdparty-pkg-5-5.src.rpm',
213         'Crypto capable': False,
214         'BOM': '',
215     }]
216
217 basesystem_combined = {
218     # From RPM info
219     'Name': 'basesystem',
220     'Version': '10.0',
221     'Release': '7.el7.centos',
222     'Architecture': 'noarch',
223     'Install Date': 'Fri 01 Apr 2016 11:47:25 AM EEST',
224     'Group': 'System Environment/Base',
225     'Size': '0',
226     'License': 'Public Domain',
227     'Signature': 'RSA/SHA256, Fri 04 Jul 2014 03:46:57 AM EEST, Key ID 24c6a8a7f4a80eb5',
228     'Source RPM': 'basesystem-10.0-7.el7.centos.src.rpm',
229     'Build Date': 'Fri 27 Jun 2014 01:37:10 PM EEST',
230     'Build Host': 'worker1.bsys.centos.org',
231     'Relocations': '(not relocatable)',
232     'Packager': 'CentOS BuildSystem <http://bugs.centos.org>',
233     'Vendor': 'CentOS',
234     'Summary': 'The skeleton package which defines a simple CentOS Linux system',
235     'Description': '\n'.join(
236         ['Basesystem defines the components of a basic CentOS Linux',
237          'system (for example, the package installation order to use during',
238          'bootstrapping). Basesystem should be in every installation of a system,',
239          'and it should never be removed.']),
240     # From yum info
241     'Repo': 'installed',
242 }
243
244 centos_logos_combined = {
245     'Name': 'centos-logos',
246     'Version': '70.0.6',
247     'Release': '3.el7.centos',
248     'Architecture': 'noarch',
249     'License': u'Copyright © 2014 The CentOS Project.  All rights reserved.',
250 }
251
252 cpp_combined = cpp_expected.copy()
253 cpp_combined.update({'Repo': 'installed',
254                      'From repo': 'purkki-centos-base'})
255
256 dejavu_fonts_common_combined = {
257     'Name': 'dejavu-fonts-common',
258     'Version': '2.33',
259     'Release': '6.el7',
260     'Architecture': 'noarch',
261     'Install Date': 'Wed Feb  7 13:49:27 2018',
262     'Group': 'User Interface/X',
263     'Size': '130455',
264     'License': 'Bitstream Vera and Public Domain',
265     'Signature': 'RSA/SHA256, Fri Jul  4 01:06:50 2014, Key ID 24c6a8a7f4a80eb5',
266     'Source RPM': 'dejavu-fonts-2.33-6.el7.src.rpm',
267     'Build Date': 'Mon Jun  9 21:34:30 2014',
268     'Build Host': 'worker1.bsys.centos.org',
269     'Relocations': '(not relocatable)',
270     'Packager': 'CentOS BuildSystem <http://bugs.centos.org>',
271     'Vendor': 'CentOS',
272     'URL': 'http://dejavu-fonts.org/',
273     'Summary': 'Common files for the Dejavu font set',
274     'Description': '\n'.join(
275         ['The DejaVu font set is based on the “Bitstream Vera” fonts, release 1.10. Its',
276          'purpose is to provide a wider range of characters, while maintaining the',
277          'original style, using an open collaborative development process.',
278          '',
279          'This package consists of files used by other DejaVu packages.']),
280     'Repo': 'installed',
281     'From repo': 'purkki-centos-base'
282 }
283
284 crypto_rpms_json = """
285 [
286     {
287         "name": "internal-pkg-4-4.noarch",
288         "requires": [
289             "libgssapi_krb5.so.2()(64bit)",
290             "libk5crypto.so.3()(64bit)",
291             "libkrb5.so.3()(64bit)",
292             "libcrypto.so.10()(64bit)",
293             "libcrypto.so.10(OPENSSL_1.0.1_EC)(64bit)",
294             "libcrypto.so.10(OPENSSL_1.0.2)(64bit)",
295             "libcrypto.so.10(libcrypto.so.10)(64bit)",
296             "libssl.so.10()(64bit)",
297             "libssl.so.10(libssl.so.10)(64bit)",
298             "openssl-libs(x86-64)",
299             "rtld(GNU_HASH)"
300         ]
301     }
302 ]
303 """