add more tests for enable_repos template method
- CentOS single, multiple and one with missing repo - Debian single, multiple and one with missing repo - TripleO Change-Id: Ide4868d031bd84b1a6935aada7d0e7627f11bf37
This commit is contained in:
parent
308e85aa41
commit
540b0cf6d7
|
@ -16,7 +16,6 @@ import os
|
|||
import yaml
|
||||
|
||||
from jinja2 import contextfunction
|
||||
from jinja2.runtime import Undefined
|
||||
|
||||
|
||||
def debian_package_install(packages, clean_package_cache=True):
|
||||
|
@ -79,6 +78,7 @@ def enable_repos(context, reponames):
|
|||
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.
|
||||
Distro/arch are not required to have all entries - we ignore missing ones.
|
||||
"""
|
||||
repofile = os.path.dirname(os.path.realpath(__file__)) + '/repos.yaml'
|
||||
with open(repofile, 'r') as repos_file:
|
||||
|
@ -86,24 +86,13 @@ def enable_repos(context, reponames):
|
|||
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:
|
||||
|
@ -116,12 +105,23 @@ def enable_repos(context, reponames):
|
|||
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
|
||||
commands += '>/etc/apt/sources.list.d/%s.list && ' % repo
|
||||
except KeyError:
|
||||
# NOTE(hrw): we ignore missing repositories for a given
|
||||
# distro/arch
|
||||
pass
|
||||
# NOTE(hrw): tripleo builds have empty repolist
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
if base_package_type == 'rpm' and commands:
|
||||
# NOTE(hrw): if commands is empty then no repos are enabled
|
||||
# otherwise we need to add command to handle repositories
|
||||
if distro_package_manager == 'yum':
|
||||
commands = 'yum-config-manager %s' % commands
|
||||
elif distro_package_manager == 'dnf':
|
||||
# NOTE(hrw) dnf errors out if we enable unknown repo
|
||||
commands = 'dnf config-manager %s || true' % commands
|
||||
elif base_package_type == 'deb':
|
||||
# NOTE(hrw): Debian commands end with '&&'
|
||||
commands = commands[0:-4]
|
||||
|
||||
if commands:
|
||||
commands = "RUN %s" % commands
|
||||
|
|
|
@ -25,7 +25,8 @@ centos-ppc64le:
|
|||
nfs-ganesha: "centos-nfs-ganesha28"
|
||||
rabbitmq: "rabbitmq_rabbitmq-server"
|
||||
|
||||
rhel:
|
||||
# NOTE(hrw): empty dict to avoid TypeError
|
||||
rhel: {}
|
||||
|
||||
debian:
|
||||
elasticsearch: "deb [arch=amd64] https://artifacts.elastic.co/packages/5.x/apt stable main"
|
||||
|
|
|
@ -22,7 +22,19 @@ class MethodsTest(base.TestCase):
|
|||
expectCmd = 'apt-get -y install --no-install-recommends package2.deb'
|
||||
self.assertEqual(expectCmd, result.split("&&")[1].strip())
|
||||
|
||||
def test_enable_repos(self):
|
||||
def test_enable_repos_rhel(self):
|
||||
template_vars = {
|
||||
'base_arch': 'x86_64',
|
||||
'base_distro': 'rhel',
|
||||
'base_package_type': 'rpm',
|
||||
'distro_package_manager': 'yum'
|
||||
}
|
||||
|
||||
result = methods.enable_repos(template_vars, ['grafana'])
|
||||
expectCmd = ''
|
||||
self.assertEqual(expectCmd, result)
|
||||
|
||||
def test_enable_repos_centos(self):
|
||||
template_vars = {
|
||||
'base_arch': 'x86_64',
|
||||
'base_distro': 'centos',
|
||||
|
@ -33,3 +45,66 @@ class MethodsTest(base.TestCase):
|
|||
result = methods.enable_repos(template_vars, ['grafana'])
|
||||
expectCmd = 'RUN yum-config-manager --enable grafana'
|
||||
self.assertEqual(expectCmd, result)
|
||||
|
||||
def test_enable_repos_centos_missing_repo(self):
|
||||
template_vars = {
|
||||
'base_arch': 'x86_64',
|
||||
'base_distro': 'centos',
|
||||
'base_package_type': 'rpm',
|
||||
'distro_package_manager': 'yum'
|
||||
}
|
||||
|
||||
result = methods.enable_repos(template_vars, ['missing_repo'])
|
||||
expectCmd = ''
|
||||
self.assertEqual(expectCmd, result)
|
||||
|
||||
def test_enable_repos_centos_multiple(self):
|
||||
template_vars = {
|
||||
'base_arch': 'x86_64',
|
||||
'base_distro': 'centos',
|
||||
'base_package_type': 'rpm',
|
||||
'distro_package_manager': 'yum'
|
||||
}
|
||||
|
||||
result = methods.enable_repos(template_vars, ['grafana', 'ceph'])
|
||||
expectCmd = 'RUN yum-config-manager --enable grafana '
|
||||
expectCmd += '--enable centos-ceph-nautilus'
|
||||
self.assertEqual(expectCmd, result)
|
||||
|
||||
def test_enable_repos_debian(self):
|
||||
template_vars = {
|
||||
'base_arch': 'x86_64',
|
||||
'base_distro': 'debian',
|
||||
'base_package_type': 'deb'
|
||||
}
|
||||
|
||||
result = methods.enable_repos(template_vars, ['grafana'])
|
||||
expectCmd = 'RUN echo "deb https://packages.grafana.com/oss/deb '
|
||||
expectCmd += 'stable main" >/etc/apt/sources.list.d/grafana.list'
|
||||
self.assertEqual(expectCmd, result)
|
||||
|
||||
def test_enable_repos_debian_missing_repo(self):
|
||||
template_vars = {
|
||||
'base_arch': 'x86_64',
|
||||
'base_distro': 'debian',
|
||||
'base_package_type': 'deb'
|
||||
}
|
||||
|
||||
result = methods.enable_repos(template_vars, ['missing_repo'])
|
||||
expectCmd = ''
|
||||
self.assertEqual(expectCmd, result)
|
||||
|
||||
def test_enable_repos_debian_multiple(self):
|
||||
template_vars = {
|
||||
'base_arch': 'x86_64',
|
||||
'base_distro': 'debian',
|
||||
'base_package_type': 'deb'
|
||||
}
|
||||
|
||||
result = methods.enable_repos(template_vars, ['grafana', 'kibana'])
|
||||
expectCmd = 'RUN echo "deb https://packages.grafana.com/oss/deb '
|
||||
expectCmd += 'stable main" >/etc/apt/sources.list.d/grafana.list && '
|
||||
expectCmd += 'echo "deb [arch=amd64] '
|
||||
expectCmd += 'https://artifacts.elastic.co/packages/5.x/apt stable '
|
||||
expectCmd += 'main" >/etc/apt/sources.list.d/kibana.list'
|
||||
self.assertEqual(expectCmd, result)
|
||||
|
|
Loading…
Reference in New Issue