diff --git a/pytests/repo/tdnf-test-doc.spec b/pytests/repo/tdnf-test-doc.spec new file mode 100644 index 00000000..8b594769 --- /dev/null +++ b/pytests/repo/tdnf-test-doc.spec @@ -0,0 +1,39 @@ +# +# tdnf-test-doc spec file +# +Summary: basic install test file. +Name: tdnf-test-doc +Version: 1.0.1 +Release: 2 +Vendor: VMware, Inc. +Distribution: Photon +License: VMware +Url: http://www.vmware.com +Group: Applications/tdnftest + +%description +Part of tdnf test spec. Basic install/remove/upgrade test + +%prep + +%build + +%install +mkdir -p %_topdir/%buildroot/usr/share/doc/tdnf-test-doc +echo "hello" > %_topdir/%buildroot/usr/share/doc/tdnf-test-doc/README +mkdir -p %_topdir/%buildroot/lib/systemd/system/ +cat << EOF >> %_topdir/%buildroot/lib/systemd/system/tdnf-test-doc.service +[Unit] +Description=tdnf-test-doc.service for whatprovides test. + +EOF + +%files +%doc /usr/share/doc/tdnf-test-doc/README +/lib/systemd/system/tdnf-test-doc.service + +%changelog +* Tue Nov 15 2016 Xiaolin Li 1.0.1-2 +- Add a service file for whatprovides test. +* Tue Dec 15 2015 Priyesh Padmavilasom 1.0 +- Initial build. First version diff --git a/pytests/tests/test_baseurls.py b/pytests/tests/test_baseurls.py index c5de8f5d..df4bb6e5 100644 --- a/pytests/tests/test_baseurls.py +++ b/pytests/tests/test_baseurls.py @@ -23,12 +23,12 @@ def setup_test(utils): def teardown_test(utils): pkgname = utils.config["mulversion_pkgname"] - utils.erase_package(pkgname) if os.path.isdir(WORKDIR): shutil.rmtree(WORKDIR) filename = os.path.join(utils.config['repo_path'], "yum.repos.d", REPOFILENAME) if os.path.isfile(filename): os.remove(filename) + utils.erase_package(pkgname) def test_multiple_baseurls(utils): @@ -54,4 +54,34 @@ def test_multiple_baseurls(utils): '--disablerepo=*', '--enablerepo={}'.format(reponame), 'install', pkgname], cwd=workdir) + assert ret['retval'] == 0 + assert utils.check_package(pkgname) + + +def test_multiple_baseurls_setopt(utils): + reponame = REPONAME + workdir = WORKDIR + utils.makedirs(workdir) + + filename = os.path.join(utils.config['repo_path'], "yum.repos.d", REPOFILENAME) + # we should get a 404 for the first url and skip to the next one + baseurls = "http://localhost:8080/doesntexist" + utils.create_repoconf(filename, baseurls, reponame) + + ret = utils.run(['tdnf', + '--disablerepo=*', '--enablerepo={}'.format(reponame), + f'--setopt={reponame}.baseurl=http://localhost:8080/photon-test', + 'makecache'], + cwd=workdir) + assert ret['retval'] == 0 + + pkgname = utils.config["mulversion_pkgname"] + utils.erase_package(pkgname) + ret = utils.run(['tdnf', + '-y', '--nogpgcheck', + '--disablerepo=*', '--enablerepo={}'.format(reponame), + f'--setopt={reponame}.baseurl=http://localhost:8080/photon-test', + 'install', pkgname], + cwd=workdir) + assert ret['retval'] == 0 assert utils.check_package(pkgname) diff --git a/pytests/tests/test_noscripts.py b/pytests/tests/test_noscripts.py deleted file mode 100644 index 32e47d63..00000000 --- a/pytests/tests/test_noscripts.py +++ /dev/null @@ -1,34 +0,0 @@ -# -# Copyright (C) 2019 - 2022 VMware, Inc. All Rights Reserved. -# -# Licensed under the GNU General Public License v2 (the "License"); -# you may not use this file except in compliance with the License. The terms -# of the License are located in the COPYING file of this distribution. -# - -import pytest - - -@pytest.fixture(scope='module', autouse=True) -def setup_test(utils): - yield - teardown_test(utils) - - -def teardown_test(utils): - pkgname = 'tdnf-bad-pre' - utils.run(['tdnf', 'erase', '-y', pkgname]) - - -# Verify that the package is really bad: -def test_install_normal(utils): - pkgname = 'tdnf-bad-pre' - ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck', pkgname]) - assert ret['retval'] == 1525 - - -def test_install_noscripts(utils): - pkgname = 'tdnf-bad-pre' - ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck', - '--setopt=tsflags=noscripts', pkgname]) - assert ret['retval'] == 0 diff --git a/pytests/tests/test_tsflags.py b/pytests/tests/test_tsflags.py new file mode 100644 index 00000000..1726dc38 --- /dev/null +++ b/pytests/tests/test_tsflags.py @@ -0,0 +1,156 @@ +# +# Copyright (C) 2019 - 2022 VMware, Inc. All Rights Reserved. +# +# Licensed under the GNU General Public License v2 (the "License"); +# you may not use this file except in compliance with the License. The terms +# of the License are located in the COPYING file of this distribution. +# + +import os +import subprocess +import pytest +import shutil + + +WORKDIR = '/root/test_tsflags' +TEST_CONF_FILE = 'tdnf.conf' +TEST_CONF_PATH = os.path.join(WORKDIR, TEST_CONF_FILE) + + +@pytest.fixture(scope='function', autouse=True) +def setup_test(utils): + yield + teardown_test(utils) + + +def teardown_test(utils): + packages = ["tdnf-bad-pre", utils.config["mulversion_pkgname"], "tdnf-test-doc"] + utils.run(['tdnf', 'erase', '-y'] + packages) + + try: + os.remove(TEST_CONF_PATH) + except OSError: + pass + + +# Verify that the package is really bad: +def test_install_normal(utils): + pkgname = 'tdnf-bad-pre' + ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck', pkgname]) + assert ret['retval'] == 1525 + + +def test_install_noscripts(utils): + pkgname = 'tdnf-bad-pre' + ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck', + '--setopt=tsflags=noscripts', pkgname]) + assert ret['retval'] == 0 + + +def test_install_noscripts_nodocs(utils): + pkgname = 'tdnf-bad-pre' + ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck', + '--setopt=tsflags=noscripts', '--setopt=tsflags=nodocs', pkgname]) + assert ret['retval'] == 0 + + +def test_install_justdb(utils): + pkgname = utils.config["mulversion_pkgname"] + ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck', + '--setopt=tsflags=justdb', pkgname]) + assert ret['retval'] == 0 + + # package should look like it's installed, but no files should be installed + assert utils.check_package(pkgname) + process = subprocess.run(['rpm', '-ql', pkgname], stdout=subprocess.PIPE, text=True) + for f in process.stdout.split(): + assert not os.path.exists(f) + + +# opposite of --justdb +def test_install_nodb(utils): + pkgname = utils.config["mulversion_pkgname"] + utils.erase_package(pkgname) + + ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck', + '--setopt=tsflags=nodb', pkgname]) + assert ret['retval'] == 0 + + # package should appear to not be installed, but files should be there: + assert not utils.check_package(pkgname) + process = subprocess.run(['tdnf', 'repoquery', '--list', pkgname], stdout=subprocess.PIPE, text=True) + for f in process.stdout.split(): + if f.startswith("/"): + assert os.path.exists(f) + + +# opposite of --justdb +def test_install_nodocs(utils): + pkgname = "tdnf-test-doc" + utils.erase_package(pkgname) + + ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck', + '--setopt=tsflags=nodocs', pkgname]) + assert ret['retval'] == 0 + + # make sure packe is installed + assert utils.check_package(pkgname) + # but no doc file + assert not os.path.exists("/usr/share/doc/tdnf-test-doc/README") + + +def test_install_multiple(utils): + pkgname = utils.config["mulversion_pkgname"] + utils.erase_package(pkgname) + + ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck', + '--setopt=tsflags=nodb nodocs', pkgname]) + assert ret['retval'] == 0 + + # package should appear to not be installed, but files should be there: + assert not utils.check_package(pkgname) + process = subprocess.run(['tdnf', 'repoquery', '--list', pkgname], stdout=subprocess.PIPE, text=True) + for f in process.stdout.split(): + if f.startswith("/"): + assert os.path.exists(f) + + # no doc file + assert not os.path.exists("/usr/share/doc/tdnf-test-doc/README") + + +def test_install_multiple_from_config(utils): + pkgname = utils.config["mulversion_pkgname"] + utils.erase_package(pkgname) + + tdnf_conf = os.path.join(utils.config['repo_path'], 'tdnf.conf') + + utils.makedirs(WORKDIR) + shutil.copy(tdnf_conf, TEST_CONF_PATH) + utils.edit_config({'tsflags': "nodb nodocs"}, section='main', filename=TEST_CONF_PATH) + + ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck', + '-c', TEST_CONF_PATH, pkgname]) + assert ret['retval'] == 0 + + # package should appear to not be installed, but files should be there: + assert not utils.check_package(pkgname) + process = subprocess.run(['tdnf', 'repoquery', '--list', pkgname], stdout=subprocess.PIPE, text=True) + for f in process.stdout.split(): + if f.startswith("/"): + assert os.path.exists(f) + + # no doc file + assert not os.path.exists("/usr/share/doc/tdnf-test-doc/README") + + # do this again, but override config settings to "normal": + ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck', + '-c', TEST_CONF_PATH, '--setopt=tsflags=', pkgname]) + assert ret['retval'] == 0 + + assert utils.check_package(pkgname) + + # check all files exist - that includes doc files: + process = subprocess.run(['tdnf', 'repoquery', '--list', pkgname], stdout=subprocess.PIPE, text=True) + for f in process.stdout.split(): + if f.startswith("/"): + assert os.path.exists(f)