aboutsummaryrefslogtreecommitdiff
path: root/kolla/template/methods.py
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2019-12-04 17:45:50 +0000
committerGerrit Code Review <review@openstack.org>2019-12-04 17:45:50 +0000
commitfb74313d7df98aabaa2fd3f8fb606110aa042d27 (patch)
tree50a9075da44a9c01788a02b686a357cba00e569e /kolla/template/methods.py
parent59c881d85c4c9154a459c8c695f10243b387f047 (diff)
parentcf11cd6f3d1f0f0d9e1bb948672be12171a4099b (diff)
downloadkolla-fb74313d7df98aabaa2fd3f8fb606110aa042d27.tar.gz
kolla-fb74313d7df98aabaa2fd3f8fb606110aa042d27.zip
Merge "Enable repos only when needed"
Diffstat (limited to 'kolla/template/methods.py')
-rw-r--r--kolla/template/methods.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/kolla/template/methods.py b/kolla/template/methods.py
index 017b219c7..1217547bf 100644
--- a/kolla/template/methods.py
+++ b/kolla/template/methods.py
@@ -12,6 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import os
+import yaml
+
+from jinja2 import contextfunction
+from jinja2.runtime import Undefined
+
def debian_package_install(packages, clean_package_cache=True):
"""Jinja utility method for building debian-based package install command.
@@ -64,3 +70,60 @@ def debian_package_install(packages, clean_package_cache=True):
# return the list of commands
return ' && '.join(cmds)
+
+
+@contextfunction
+def enable_repos(context, reponames):
+ """NOTE(hrw): we need to handle CentOS, Debian and Ubuntu with one macro.
+
+ Repo names have to be simple names mapped to proper ones. So 'ceph' ==
+ 'centos-ceph-nautilus' for CentOS, UCA for Ubuntu (enabled by default) and
+ something else for Debian.
+ """
+ repofile = os.path.dirname(os.path.realpath(__file__)) + '/repos.yaml'
+ with open(repofile, 'r') as repos_file:
+ repo_data = {}
+ for name, params in yaml.safe_load(repos_file).items():
+ repo_data[name] = params
+
+ # TODO(hrw): add checks for isinstance() and raise proper exception
+ base_package_type = context.get('base_package_type')
+ if isinstance(base_package_type, Undefined):
+ raise
+
+ base_distro = context.get('base_distro')
+ base_arch = context.get('base_arch')
+ distro_package_manager = context.get('distro_package_manager')
+
+ commands = ''
+
+ if base_package_type == 'rpm':
+ # NOTE(hrw): we enable all repos with one call
+ if distro_package_manager == 'yum':
+ commands = 'yum-config-manager '
+ elif distro_package_manager == 'dnf':
+ commands = 'dnf config-manager '
+
+ try:
+ repo_list = repo_data['%s-%s' % (base_distro, base_arch)]
+ except KeyError:
+ # NOTE(hrw): Fallback to distro list
+ repo_list = repo_data[base_distro]
+
+ for repo in reponames:
+ try:
+ if base_package_type == 'rpm':
+ commands += ' --enable %s' % repo_list[repo]
+ elif base_package_type == 'deb':
+ commands += 'echo "%s" ' % repo_list[repo]
+ commands += '>/etc/apt/sources.list.d/%s.list; ' % repo
+ except KeyError:
+ pass
+ # NOTE(hrw): tripleo builds have empty repolist
+ except TypeError:
+ pass
+
+ if commands:
+ commands = "RUN %s" % commands
+
+ return commands