2018-04-30 18:34:48 +00:00
|
|
|
#
|
|
|
|
# Copyright (C) 2018 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import tempfile
|
|
|
|
import unittest
|
|
|
|
|
2018-04-30 18:48:38 +00:00
|
|
|
import configparser
|
2018-04-30 18:34:48 +00:00
|
|
|
|
2018-04-30 22:38:28 +00:00
|
|
|
from pylorax.api.config import configure, make_dnf_dirs
|
2018-12-03 23:38:59 +00:00
|
|
|
from pylorax.api.dnfbase import get_base_object, check_repos
|
|
|
|
from pylorax.api.projects import source_to_repo
|
2018-04-30 18:34:48 +00:00
|
|
|
|
|
|
|
|
2018-05-02 16:58:29 +00:00
|
|
|
class DnfbaseNoSystemReposTest(unittest.TestCase):
|
2018-04-30 18:34:48 +00:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(self):
|
2018-04-30 22:38:28 +00:00
|
|
|
self.tmp_dir = tempfile.mkdtemp(prefix="lorax.test.dnfbase.")
|
2018-04-30 18:34:48 +00:00
|
|
|
conf_file = os.path.join(self.tmp_dir, 'test.conf')
|
|
|
|
open(conf_file, 'w').write("""[composer]
|
|
|
|
# releasever different from the current default
|
|
|
|
releasever = 6
|
2018-04-30 22:38:28 +00:00
|
|
|
[dnf]
|
2018-04-30 18:34:48 +00:00
|
|
|
proxy = https://proxy.example.com
|
|
|
|
sslverify = False
|
|
|
|
[repos]
|
|
|
|
use_system_repos = False
|
|
|
|
""")
|
|
|
|
|
|
|
|
# will read the above configuration
|
|
|
|
config = configure(conf_file=conf_file, root_dir=self.tmp_dir)
|
2018-04-30 22:38:28 +00:00
|
|
|
make_dnf_dirs(config)
|
2018-04-30 18:34:48 +00:00
|
|
|
|
2018-04-30 22:38:28 +00:00
|
|
|
# will read composer config and store a dnf config file
|
|
|
|
self.dbo = get_base_object(config)
|
2018-04-30 18:34:48 +00:00
|
|
|
|
2018-04-30 22:38:28 +00:00
|
|
|
# will read the stored dnf config file
|
|
|
|
self.dnfconf = configparser.ConfigParser()
|
|
|
|
self.dnfconf.read([config.get("composer", "dnf_conf")])
|
2018-04-30 18:34:48 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(self):
|
|
|
|
shutil.rmtree(self.tmp_dir)
|
|
|
|
|
2018-04-30 22:38:28 +00:00
|
|
|
def test_stores_dnf_proxy_from_composer_config(self):
|
|
|
|
self.assertEqual('https://proxy.example.com', self.dnfconf.get('main', 'proxy'))
|
2018-04-30 18:34:48 +00:00
|
|
|
|
|
|
|
def test_disables_sslverify_if_composer_disables_it(self):
|
2018-04-30 22:38:28 +00:00
|
|
|
self.assertEqual(False, self.dnfconf.getboolean('main', 'sslverify'))
|
2018-04-30 18:34:48 +00:00
|
|
|
|
|
|
|
def test_sets_releasever_from_composer(self):
|
2018-04-30 22:38:28 +00:00
|
|
|
self.assertEqual('6', self.dbo.conf.releasever)
|
2018-04-30 18:34:48 +00:00
|
|
|
|
|
|
|
def test_doesnt_use_system_repos(self):
|
|
|
|
# no other repos defined for this test
|
2018-04-30 22:38:28 +00:00
|
|
|
self.assertEqual({}, self.dbo.repos)
|
2018-04-30 18:34:48 +00:00
|
|
|
|
|
|
|
|
2018-05-02 16:58:29 +00:00
|
|
|
class DnfbaseSystemReposTest(unittest.TestCase):
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(self):
|
|
|
|
self.tmp_dir = tempfile.mkdtemp(prefix="lorax.test.dnfbase.")
|
|
|
|
|
|
|
|
# will read the above configuration
|
|
|
|
config = configure(root_dir=self.tmp_dir)
|
|
|
|
make_dnf_dirs(config)
|
|
|
|
|
|
|
|
# will read composer config and store a dnf config file
|
|
|
|
self.dbo = get_base_object(config)
|
|
|
|
|
|
|
|
# will read the stored dnf config file
|
|
|
|
self.dnfconf = configparser.ConfigParser()
|
|
|
|
self.dnfconf.read([config.get("composer", "dnf_conf")])
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(self):
|
|
|
|
shutil.rmtree(self.tmp_dir)
|
|
|
|
|
|
|
|
def test_uses_system_repos(self):
|
|
|
|
# no other repos defined for this test
|
|
|
|
self.assertTrue(len(self.dbo.repos) > 0)
|
|
|
|
|
|
|
|
|
|
|
|
class CreateDnfDirsTest(unittest.TestCase):
|
2018-04-30 18:34:48 +00:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(self):
|
2018-04-30 22:38:28 +00:00
|
|
|
self.tmp_dir = tempfile.mkdtemp(prefix="lorax.test.dnfbase.")
|
2018-04-30 18:34:48 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(self):
|
|
|
|
shutil.rmtree(self.tmp_dir)
|
|
|
|
|
2018-04-30 22:38:28 +00:00
|
|
|
def test_creates_missing_dnf_root_directory(self):
|
2018-04-30 18:34:48 +00:00
|
|
|
config = configure(test_config=True, root_dir=self.tmp_dir)
|
|
|
|
|
|
|
|
# will create the above directory if missing
|
2018-04-30 22:38:28 +00:00
|
|
|
make_dnf_dirs(config)
|
2018-04-30 18:34:48 +00:00
|
|
|
|
2018-04-30 22:38:28 +00:00
|
|
|
self.assertTrue(os.path.exists(self.tmp_dir + '/var/tmp/composer/dnf/root'))
|
2018-12-03 23:38:59 +00:00
|
|
|
|
|
|
|
class DnfbaseCDNTest(unittest.TestCase):
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(self):
|
|
|
|
self.tmp_dir = tempfile.mkdtemp(prefix="lorax.test.dnfbase.")
|
|
|
|
conf_file = os.path.join(self.tmp_dir, 'test.conf')
|
|
|
|
open(conf_file, 'w').write("""[composer]
|
|
|
|
[repos]
|
|
|
|
use_system_repos = False
|
|
|
|
""")
|
|
|
|
|
|
|
|
# will read the above configuration
|
|
|
|
config = configure(conf_file=conf_file, root_dir=self.tmp_dir)
|
|
|
|
make_dnf_dirs(config)
|
|
|
|
|
|
|
|
# will read composer config and store a dnf config file
|
|
|
|
self.dbo = get_base_object(config)
|
|
|
|
|
|
|
|
# will read the stored dnf config file
|
|
|
|
self.dnfconf = configparser.ConfigParser()
|
|
|
|
self.dnfconf.read([config.get("composer", "dnf_conf")])
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(self):
|
|
|
|
shutil.rmtree(self.tmp_dir)
|
|
|
|
|
|
|
|
def test_check_repos_no_cdn(self, check_empty=True):
|
|
|
|
"""Test that no cdn.redhat.com returns True"""
|
|
|
|
repo = source_to_repo({"name": "no-cdn",
|
|
|
|
"type": "yum-baseurl",
|
|
|
|
"check_ssl": True,
|
|
|
|
"check_gpg": True,
|
|
|
|
"url": "https://repo.example.com"}, self.dbo.conf)
|
|
|
|
self.dbo.repos.add(repo)
|
|
|
|
self.assertTrue(check_repos(self.dbo))
|
|
|
|
del self.dbo.repos["no-cdn"]
|
|
|
|
|
|
|
|
repo = source_to_repo({"name": "no-cdn-metalink",
|
|
|
|
"type": "yum-metalink",
|
|
|
|
"check_ssl": True,
|
|
|
|
"check_gpg": True,
|
|
|
|
"url": "https://repo.example.com"}, self.dbo.conf)
|
|
|
|
self.dbo.repos.add(repo)
|
|
|
|
self.assertTrue(check_repos(self.dbo))
|
|
|
|
del self.dbo.repos["no-cdn-metalink"]
|
|
|
|
|
|
|
|
repo = source_to_repo({"name": "no-cdn-mirrorlist",
|
|
|
|
"type": "yum-mirrorlist",
|
|
|
|
"check_ssl": True,
|
|
|
|
"check_gpg": True,
|
|
|
|
"url": "https://repo.example.com"}, self.dbo.conf)
|
|
|
|
self.dbo.repos.add(repo)
|
|
|
|
self.assertTrue(check_repos(self.dbo))
|
|
|
|
del self.dbo.repos["no-cdn-mirrorlist"]
|
|
|
|
|
|
|
|
if check_empty:
|
|
|
|
self.assertTrue(self.dbo.repos == {})
|
|
|
|
|
|
|
|
def test_check_repos_only_cdn(self):
|
|
|
|
"""Test that only cdn.redhat.com returns False"""
|
|
|
|
repo = source_to_repo({"name": "only-cdn",
|
|
|
|
"type": "yum-baseurl",
|
|
|
|
"check_ssl": True,
|
|
|
|
"check_gpg": True,
|
|
|
|
"url": "https://cdn.redhat.com"}, self.dbo.conf)
|
|
|
|
self.dbo.repos.add(repo)
|
|
|
|
self.assertFalse(check_repos(self.dbo), self.dbo.repos)
|
|
|
|
del self.dbo.repos["only-cdn"]
|
|
|
|
|
|
|
|
repo = source_to_repo({"name": "only-cdn-metalink",
|
|
|
|
"type": "yum-metalink",
|
|
|
|
"check_ssl": True,
|
|
|
|
"check_gpg": True,
|
|
|
|
"url": "https://cdn.redhat.com"}, self.dbo.conf)
|
|
|
|
self.dbo.repos.add(repo)
|
|
|
|
self.assertFalse(check_repos(self.dbo), self.dbo.repos)
|
|
|
|
del self.dbo.repos["only-cdn-metalink"]
|
|
|
|
|
|
|
|
repo = source_to_repo({"name": "only-cdn-mirrorlist",
|
|
|
|
"type": "yum-mirrorlist",
|
|
|
|
"check_ssl": True,
|
|
|
|
"check_gpg": True,
|
|
|
|
"url": "https://cdn.redhat.com"}, self.dbo.conf)
|
|
|
|
self.dbo.repos.add(repo)
|
|
|
|
self.assertFalse(check_repos(self.dbo), self.dbo.repos)
|
|
|
|
del self.dbo.repos["only-cdn-mirrorlist"]
|
|
|
|
|
|
|
|
self.assertTrue(self.dbo.repos == {})
|
|
|
|
|
|
|
|
def test_check_repos_with_cdn(self):
|
|
|
|
"""Test that adding a non-cdn repo to a cdn one returns True"""
|
|
|
|
repo = source_to_repo({"name": "cdn",
|
|
|
|
"type": "yum-baseurl",
|
|
|
|
"check_ssl": True,
|
|
|
|
"check_gpg": True,
|
|
|
|
"url": "https://cdn.redhat.com"}, self.dbo.conf)
|
|
|
|
self.dbo.repos.add(repo)
|
|
|
|
|
|
|
|
# Use the no-cdn tests with a pre-populated dbo.repos
|
|
|
|
self.test_check_repos_no_cdn(check_empty=False)
|
|
|
|
del self.dbo.repos["cdn"]
|
|
|
|
|
|
|
|
self.assertTrue(self.dbo.repos == {})
|
|
|
|
|