Browse Source

Override rpm repos from override_rpm_repos.yaml

It is necessary for tests. Test framework is to
put rpm repos into file /root/override_rpm_repos.yaml
file and then install fuel-release package.

Change-Id: If8280af152608f86a5ea69f84abfaa1a0894b374
Vladimir Kozhukalov 2 years ago
parent
commit
8736f9c13e
2 changed files with 65 additions and 0 deletions
  1. 55
    0
      fuel-release/override_rpm_repos.py
  2. 10
    0
      specs/fuel-main.spec

+ 55
- 0
fuel-release/override_rpm_repos.py View File

@@ -0,0 +1,55 @@
1
+#!/usr/bin/env python
2
+#    Copyright 2016 Mirantis, Inc.
3
+#
4
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5
+#    not use this file except in compliance with the License. You may obtain
6
+#    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, WITHOUT
12
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+#    License for the specific language governing permissions and limitations
14
+#    under the License.
15
+
16
+import argparse
17
+import yaml
18
+
19
+
20
+def generate_yum_repos_config(repositories):
21
+    config = ""
22
+    for repo in repositories:
23
+        config += """
24
+[{name}]
25
+name={name}
26
+baseurl={uri}
27
+enabled=1
28
+gpgcheck=0
29
+priority={priority}
30
+skip_if_unavailable=1
31
+""".format(**repo)
32
+    return config
33
+
34
+
35
+def main():
36
+    parser = argparse.ArgumentParser()
37
+    parser.add_argument(
38
+        '--repositories-file', dest='repositories_file', action='store',
39
+        type=str, help='file where repositories are defined', required=True
40
+    )
41
+    parser.add_argument(
42
+        '--output-file', dest='outfile', action='store',
43
+        type=str, help='file where to write yum config', required=True
44
+    )
45
+    params, other_params = parser.parse_known_args()
46
+
47
+    with open(params.repositories_file) as f:
48
+        repositories = yaml.safe_load(f)
49
+
50
+    with open(params.outfile, 'wt') as f:
51
+        f.write(generate_yum_repos_config(repositories))
52
+
53
+
54
+if __name__ == "__main__":
55
+    main()

+ 10
- 0
specs/fuel-main.spec View File

@@ -49,6 +49,7 @@ for file in %{_builddir}/%{name}-%{version}/fuel-release/*.repo ; do
49 49
 done
50 50
 install -D -p -m 755 %{_builddir}/%{name}-%{version}/iso/bootstrap_admin_node.sh %{buildroot}%{_sbindir}/bootstrap_admin_node.sh
51 51
 install -D -p -m 755 %{_builddir}/%{name}-%{version}/iso/fix_default_repos.py %{buildroot}%{_sbindir}/fix_default_repos.py
52
+install -D -p -m 755 %{_builddir}/%{name}-%{version}/fuel-release/override_rpm_repos.py %{buildroot}%{_sbindir}/override_rpm_repos.py
52 53
 
53 54
 %clean
54 55
 rm -rf %{buildroot}
@@ -65,6 +66,8 @@ Release:   %{release}
65 66
 License:   GPLv2
66 67
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
67 68
 URL:       http://github.com/Mirantis
69
+Requires:  python
70
+Requires:  PyYAML >= 3.10
68 71
 
69 72
 %description -n fuel-release
70 73
 This packages provides /etc/fuel_release file
@@ -73,11 +76,18 @@ and Yum configuration for Fuel online repositories.
73 76
 %files -n fuel-release
74 77
 %defattr(-,root,root)
75 78
 %{_sysconfdir}/fuel_release
79
+%{_sbindir}/override_rpm_repos.py
76 80
 %config(noreplace) %attr(0644,root,root) /etc/yum/vars/fuelver
77 81
 %config(noreplace) %attr(0644,root,root) /etc/yum.repos.d/*
78 82
 %dir /etc/pki/fuel-gpg
79 83
 /etc/pki/fuel-gpg/*
80 84
 
85
+%post -n fuel-release
86
+if [[ -f /root/override_rpm_repos.yaml ]]; then
87
+    rm -f /etc/yum.repos.d/*.repo
88
+    override_rpm_repos.py --repositories-file /root/override_rpm_repos.yaml --output-file /etc/yum.repos.d/overriden.repo
89
+fi
90
+
81 91
 %package -n fuel-setup
82 92
 
83 93
 Summary:   Fuel deployment script package

Loading…
Cancel
Save