diff --git a/.github/workflows/mgrpush-unit-tests.yml b/.github/workflows/mgrpush-unit-tests.yml deleted file mode 100644 index 64d5e69718ab..000000000000 --- a/.github/workflows/mgrpush-unit-tests.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Run unit tests for mgr-push - -on: - pull_request: - paths: 'client/tools/mgr-push/*' - -jobs: - mgrpush_tests: - runs-on: ubuntu-20.04 - strategy: - matrix: - python-version: ['3.6', '3.7', '3.8', '3.9', '3.10'] - steps: - - name: Check out repository code - uses: actions/checkout@v3 - - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - - name: Install Python dependencies - run: | - python3 -m pip install --upgrade pip - pip install pytest pyyaml pyOpenSSL python-debian - - - name: Run mgr-push unit tests - run: | - export PYTHONPATH=python/:client/rhel/spacewalk-client-tools/src/ - pytest client/tools/mgr-push/test - diff --git a/client/tools/mgr-push/Makefile.python b/client/tools/mgr-push/Makefile.python index 761331c79540..dd7febcfea1d 100644 --- a/client/tools/mgr-push/Makefile.python +++ b/client/tools/mgr-push/Makefile.python @@ -2,27 +2,12 @@ THIS_MAKEFILE := $(realpath $(lastword $(MAKEFILE_LIST))) CURRENT_DIR := $(dir $(THIS_MAKEFILE)) include $(CURRENT_DIR)../../../rel-eng/Makefile.python -MGRPUSH_ROOT_DIR := $(shell mktemp -d) -RHNPUSH_PACKAGE_DIR := $(MGRPUSH_ROOT_DIR)/rhnpush -PYTHONPATH := /manager/python/:/manager/client/rhel/spacewalk-client-tools/src/ - # Docker tests variables -DOCKER_REF = $(DOCKER_REGISTRY)/$(DOCKER_IMAGE) DOCKER_CONTAINER_BASE = systemsmanagement/uyuni/master/docker/containers/uyuni-master DOCKER_REGISTRY = registry.opensuse.org DOCKER_RUN_EXPORT = "PYTHONPATH=$PYTHONPATH" DOCKER_VOLUMES = -v "$(CURDIR)/../../../:/manager" -define setup_structure - mkdir $(RHNPUSH_PACKAGE_DIR) - cd /manager/client/tools/mgr-push/src/rhnpush && cp archive.py connection.py rhnpush_cache.py rhnpush_config.py rhnpush_confmanager.py rhnpush_main.py rhnpush_v2.py rpm2mpm.py uploadLib.py utils.py $(RHNPUSH_PACKAGE_DIR) - touch $(RHNPUSH_PACKAGE_DIR)/__init__.py -endef - -__pytest :: - $(call setup_structure) - export PYTHONPATH=$(MGRPUSH_ROOT_DIR):$(PYTHONPATH) && pytest --disable-warnings --tb=native --color=yes -v - __pylint :: $(call update_pip_env) pylint --rcfile=pylintrc $(shell find -name '*.py') > reports/pylint.log || true @@ -30,9 +15,5 @@ __pylint :: docker_pylint :: docker run --rm -e $(DOCKER_RUN_EXPORT) $(DOCKER_VOLUMES) $(DOCKER_REGISTRY)/$(DOCKER_CONTAINER_BASE)-pgsql /bin/sh -c "cd /manager/client/tools/mgr-push; make -f Makefile.python __pylint" -docker_pytest :: - docker pull $(DOCKER_REF) - docker run -e $(DOCKER_RUN_EXPORT) $(DOCKER_VOLUMES) $(DOCKER_REF) /bin/sh -c "cd /manager/client/tools/mgr-push; make -f Makefile.python __pytest" - docker_shell :: docker run -t -i --rm -e $(DOCKER_RUN_EXPORT) $(DOCKER_VOLUMES) $(DOCKER_REGISTRY)/$(DOCKER_CONTAINER_BASE)-pgsql /bin/bash diff --git a/client/tools/mgr-push/Makefile.rhnpush b/client/tools/mgr-push/Makefile.rhnpush index 375e7d219f67..bf6a3b4540b6 100644 --- a/client/tools/mgr-push/Makefile.rhnpush +++ b/client/tools/mgr-push/Makefile.rhnpush @@ -14,7 +14,7 @@ FILES = rhnpush_main rhnpush_v2 uploadLib __init__ connection \ RHN_CONF_DIR = /etc/sysconfig/rhn RHNPUSHRC = rhnpushrc -PYFILES := $(addprefix src/rhnpush/, $(addsuffix .py, $(FILES))) +PYFILES := $(addsuffix .py, $(FILES)) OBJECTS := $(PYFILES) ROOT ?= /usr/share/rhn @@ -36,7 +36,7 @@ install-conf : $(RHNPUSHRC) %.inst: rhnpush.inst -all : $(MANS) $(PYFILES) +all : $(MANS) $(OBJECTS) install : all install-conf $(INSTALL_DIR) $(PREFIX)$(MANDIR)/man8 $(INSTALL_DATA) $(MANS) $(PREFIX)$(MANDIR)/man8 @@ -44,7 +44,7 @@ install : all install-conf $(INSTALL_DIR) $(PREFIX)$(ROOT)/rhnpush $(INSTALL_DATA) $(PYFILES) $(PREFIX)$(ROOT)/rhnpush - $(INSTALL_BIN) bin/rhnpush $(PREFIX)$(BINDIR)/rhnpush-$(PYTHON_VERSION) + $(INSTALL_BIN) rhnpush $(PREFIX)$(BINDIR)/rhnpush-$(PYTHON_VERSION) @ln -sfv rhnpush $(PREFIX)$(BINDIR)/rpm2mpm %.8 : %.sgml diff --git a/client/tools/mgr-push/src/rhnpush/__init__.py b/client/tools/mgr-push/__init__.py similarity index 100% rename from client/tools/mgr-push/src/rhnpush/__init__.py rename to client/tools/mgr-push/__init__.py diff --git a/client/tools/mgr-push/src/rhnpush/archive.py b/client/tools/mgr-push/archive.py similarity index 100% rename from client/tools/mgr-push/src/rhnpush/archive.py rename to client/tools/mgr-push/archive.py diff --git a/client/tools/mgr-push/src/rhnpush/connection.py b/client/tools/mgr-push/connection.py similarity index 100% rename from client/tools/mgr-push/src/rhnpush/connection.py rename to client/tools/mgr-push/connection.py diff --git a/client/tools/mgr-push/mgr-push.changes b/client/tools/mgr-push/mgr-push.changes index b2971f760515..1553e195047f 100644 --- a/client/tools/mgr-push/mgr-push.changes +++ b/client/tools/mgr-push/mgr-push.changes @@ -1,5 +1,3 @@ -- Allow rhnpush to handle Debian packages - ------------------------------------------------------------------- Wed Sep 28 11:18:45 CEST 2022 - jgonzalez@suse.com diff --git a/client/tools/mgr-push/mgr-push.spec b/client/tools/mgr-push/mgr-push.spec index 76e970f875d7..5c932cbb3a7f 100644 --- a/client/tools/mgr-push/mgr-push.spec +++ b/client/tools/mgr-push/mgr-push.spec @@ -84,7 +84,6 @@ BuildRequires: python-devel Requires: python2-rhn-client-tools Requires: python2-uyuni-common-libs Requires: rhnlib >= 2.8.3 -Requires: python-debian BuildRequires: python2-rhn-client-tools BuildRequires: python2-uyuni-common-libs @@ -107,7 +106,6 @@ Requires: rpm-python3 Requires: python3-rhn-client-tools Requires: python3-rhnlib >= 2.8.3 Requires: python3-uyuni-common-libs -Requires: python3-debian BuildRequires: python3-devel BuildRequires: python3-rhn-client-tools BuildRequires: python3-rpm-macros @@ -131,7 +129,7 @@ make -f Makefile.rhnpush install PREFIX=$RPM_BUILD_ROOT ROOT=%{python_sitelib} \ %endif %if 0%{?build_py3} -sed -i 's|#!/usr/bin/python|#!/usr/bin/python3|' bin/rhnpush +sed -i 's|#!/usr/bin/python|#!/usr/bin/python3|' rhnpush install -d $RPM_BUILD_ROOT/%{python3_sitelib} make -f Makefile.rhnpush install PREFIX=$RPM_BUILD_ROOT ROOT=%{python3_sitelib} \ MANDIR=%{_mandir} PYTHON_VERSION=%{python3_version} diff --git a/client/tools/mgr-push/pytest.ini b/client/tools/mgr-push/pytest.ini deleted file mode 100644 index ab1b8adf8eec..000000000000 --- a/client/tools/mgr-push/pytest.ini +++ /dev/null @@ -1,3 +0,0 @@ -[pytest] -pythonpath = src - diff --git a/client/tools/mgr-push/bin/rhnpush b/client/tools/mgr-push/rhnpush similarity index 100% rename from client/tools/mgr-push/bin/rhnpush rename to client/tools/mgr-push/rhnpush diff --git a/client/tools/mgr-push/src/rhnpush/rhnpush_cache.py b/client/tools/mgr-push/rhnpush_cache.py similarity index 100% rename from client/tools/mgr-push/src/rhnpush/rhnpush_cache.py rename to client/tools/mgr-push/rhnpush_cache.py diff --git a/client/tools/mgr-push/src/rhnpush/rhnpush_config.py b/client/tools/mgr-push/rhnpush_config.py similarity index 100% rename from client/tools/mgr-push/src/rhnpush/rhnpush_config.py rename to client/tools/mgr-push/rhnpush_config.py diff --git a/client/tools/mgr-push/src/rhnpush/rhnpush_confmanager.py b/client/tools/mgr-push/rhnpush_confmanager.py similarity index 100% rename from client/tools/mgr-push/src/rhnpush/rhnpush_confmanager.py rename to client/tools/mgr-push/rhnpush_confmanager.py diff --git a/client/tools/mgr-push/src/rhnpush/rhnpush_main.py b/client/tools/mgr-push/rhnpush_main.py similarity index 100% rename from client/tools/mgr-push/src/rhnpush/rhnpush_main.py rename to client/tools/mgr-push/rhnpush_main.py diff --git a/client/tools/mgr-push/src/rhnpush/rhnpush_v2.py b/client/tools/mgr-push/rhnpush_v2.py similarity index 100% rename from client/tools/mgr-push/src/rhnpush/rhnpush_v2.py rename to client/tools/mgr-push/rhnpush_v2.py diff --git a/client/tools/mgr-push/src/rhnpush/rpm2mpm.py b/client/tools/mgr-push/rpm2mpm.py similarity index 100% rename from client/tools/mgr-push/src/rhnpush/rpm2mpm.py rename to client/tools/mgr-push/rpm2mpm.py diff --git a/client/tools/mgr-push/test/test_RhnpushCache.py b/client/tools/mgr-push/test/testRhnpushCache.py similarity index 97% rename from client/tools/mgr-push/test/test_RhnpushCache.py rename to client/tools/mgr-push/test/testRhnpushCache.py index 8004259eb839..e2491484422a 100644 --- a/client/tools/mgr-push/test/test_RhnpushCache.py +++ b/client/tools/mgr-push/test/testRhnpushCache.py @@ -14,11 +14,10 @@ # import unittest -from rhnpush import rhnpush_cache +import rhnpush_cache import time -@unittest.skip("skipping UserInfoTestCase") class UserInfoTestCase(unittest.TestCase): def setUp(self): @@ -67,7 +66,6 @@ def testGetTimeLeft(self): assert self.userinfo.getTimeLeft() >= 7.98 and self.userinfo.getTimeLeft() <= 8.002 -@unittest.skip("skipping CacheManagerTestCase") class CacheManagerTestCase(unittest.TestCase): def setUp(self): diff --git a/client/tools/mgr-push/test/test_RhnpushConfig.py b/client/tools/mgr-push/test/testRhnpushConfig.py similarity index 69% rename from client/tools/mgr-push/test/test_RhnpushConfig.py rename to client/tools/mgr-push/test/testRhnpushConfig.py index 31e176b8ac13..3d5ddc76c4e7 100644 --- a/client/tools/mgr-push/test/test_RhnpushConfig.py +++ b/client/tools/mgr-push/test/testRhnpushConfig.py @@ -13,8 +13,7 @@ # in this software or its documentation. # -from rhnpush import rhnpush_config -from unittest.mock import patch, mock_open +import rhnpush_config import unittest @@ -35,10 +34,9 @@ def testReadConfigFiles(self): assert self.userconfig.settings != None and self.defaultconfig.settings != None def testGetOption(self): - with patch('configparser.ConfigParser.get', return_value='0'): - a = self.userconfig.get_option('usage') - b = self.defaultconfig.get_option('usage') - assert a == '0' and b == '0' + a = self.userconfig.get_option('usage') + b = self.defaultconfig.get_option('usage') + assert a != None and b != None and a == '0' and b == '0' def testKeys(self): a = list(self.userconfig.keys()) @@ -54,12 +52,9 @@ def testGetItem(self): pass def testAddConfigAsAttr(self): - with patch('configparser.ConfigParser.has_section', return_value='0'), \ - patch('configparser.ConfigParser.get', return_value='0'), \ - patch('configparser.ConfigParser.options', return_value=['usage']): - self.userconfig._add_config_as_attr() - self.defaultconfig._add_config_as_attr() - assert self.userconfig.usage != None and self.defaultconfig.usage != None + self.userconfig._add_config_as_attr() + self.userconfig._add_config_as_attr() + assert self.userconfig.usage != None and self.defaultconfig.usage != None if __name__ == "__main__": unittest.main() diff --git a/client/tools/mgr-push/test/test_Utils.py b/client/tools/mgr-push/test/testUtils.py similarity index 98% rename from client/tools/mgr-push/test/test_Utils.py rename to client/tools/mgr-push/test/testUtils.py index d3cfc2a26fa8..7bc039c15d0a 100644 --- a/client/tools/mgr-push/test/test_Utils.py +++ b/client/tools/mgr-push/test/testUtils.py @@ -14,7 +14,7 @@ # import unittest -from rhnpush import utils +import utils class TestObj1: diff --git a/client/tools/mgr-push/test/test_archive.py b/client/tools/mgr-push/test/test_archive.py index 38722e1a5fac..102a26bc5a72 100644 --- a/client/tools/mgr-push/test/test_archive.py +++ b/client/tools/mgr-push/test/test_archive.py @@ -18,7 +18,7 @@ import zipfile # test import -from rhnpush import archive +import archive # globals ---------------------------------------------------------------- @@ -37,7 +37,7 @@ # test case -------------------------------------------------------------- -@unittest.skip("skipping ArchiveTest") + class ArchiveTest(unittest.TestCase): def setUp(self): diff --git a/client/tools/mgr-push/test/test_uploadclass.py b/client/tools/mgr-push/test/test_uploadclass.py deleted file mode 100644 index bb0d823ef541..000000000000 --- a/client/tools/mgr-push/test/test_uploadclass.py +++ /dev/null @@ -1,318 +0,0 @@ -from unittest.mock import Mock, patch, MagicMock -import sys - -# In order to run the tests in a system where the rpm-python package is not available we can mock its -# import by overwriting the sys.modules dictionary. Same reasoning applies to the platform module. -sys.modules['platform'] = MagicMock() -sys.modules['rpm'] = MagicMock() - -from http.client import HTTPMessage - -from unittest import TestCase -from email.policy import Compat32 -from rhnpush import rhnpush_main -from rhnpush import rhnpush_config - - -class TestUpload(TestCase): - - config = { - "options_defaults": { - "newest": "0", - "usage": "0", - "header": "0", - "test": "0", - "nullorg": "0", - "source": "0", - "stdin": "0", - "verbose": "0", - "force": "0", - "nosig": "0", - "list": "0", - "exclude": "", - "files": "", - "orgid": "", - "reldir": "", - "count": "", - "dir": "", - "server": "http://rhn.redhat.com/APP", - "channel": "", - "cache_lifetime": "600", - "new_cache": "0", - "extended_test": "0", - "no_session_caching": "0", - "proxy": "", - "tolerant": "0", - "ca_chain": "/usr/share/rhn/RHN-ORG-TRUSTED-SSL-CERT", - "timeout": None, - }, - "settings": Mock(), - "section": "rhnpush", - "username": None, - "password": None, - "newest": True, - "usage": None, - "header": None, - "test": None, - "nullorg": None, - "source": None, - "stdin": None, - "verbose": 0, - "force": None, - "nosig": None, - "list": None, - "exclude": [""], - "files": [], - "orgid": "", - "reldir": "", - "count": "", - "dir": "/opt/mytools/", - "server": "uyuni-srv-2206", - "channel": ["custom-deb-tools"], - "cache_lifetime": 600, - "new_cache": None, - "extended_test": None, - "no_session_caching": None, - "proxy": "", - "tolerant": None, - "ca_chain": "/etc/pki/trust/anchors/LOCAL-RHN-ORG-TRUSTED-SSL-CERT", - "timeout": 300, - } - - headerinfo = { - "policy": Compat32(), - "_headers": [ - ("Date", "Mon, 25 Jul 2022 10:48:01 GMT"), - ("Server", "Apache"), - ("X-Frame-Options", "SAMEORIGIN"), - ("Content-Length", "0"), - ("X-RHN-Check-Package-Exists", "1"), - ("Cache-Control", "no-cache,no-store,must-revalidate,private"), - ("Pragma", "no-cache"), - ("Expires", "0"), - ( - "Content-Security-Policy", - "default-src 'self' https: wss: ; " - "script-src 'self' https: 'unsafe-inline' 'unsafe-eval'; " - "img-src 'self' https: data: ;" - "style-src 'self' https: 'unsafe-inline' ", - ), - ("X-XSS-Protection", "1; mode=block"), - ("X-Content-Type-Options", "nosniff"), - ("X-Permitted-Cross-Domain-Policies", "master-only"), - ("Content-Type", "text/xml"), - ], - "_unixfrom": None, - "_payload": "", - "_charset": None, - "preamble": None, - "epilogue": None, - "defects": [], - "_default_type": "text/plain", - } - http_headers = HTTPMessage() - http_headers.__dict__ = headerinfo - - def setUp(self): - self._upload = rhnpush_main.UploadClass(None) - - @patch( - "rhnpush.rhnpush_v2.PingPackageUpload.ping", - Mock(return_value=[200, "OK", http_headers]), - ) - @patch("rhnpush.rhnpush_cache.RHNPushSession", Mock()) - @patch("up2date_client.rhnserver.RhnServer", Mock()) - @patch("rhnpush.uploadLib.call", Mock(side_effect=["123", 0])) - def test_packages(self): - server_digest_hash = { - "existentPackage_1.0-1_amd64.deb": [ - "sha256", - "cd5b4348e7b76c2287a9476f3f3ef3911480fe8e872ac541ffb598186a9e9607", - ], - "newPackage_2.0-1_amd64.deb": "", - } - - pkgs_info = { - "existentPackage_1.0-1_amd64.deb": { - "name": "existentPackage", - "version": "1.0", - "release": "1", - "epoch": "", - "arch": "amd64-deb", - "checksum_type": "sha256", - "checksum": "cd5b4348e7b76c2287a9476f3f3ef3911480fe8e872ac541ffb598186a9e9607", - }, - "newPackage_2.0-1_amd64.deb": { - "name": "newPackage", - "version": "2.0", - "release": "1", - "epoch": "", - "arch": "amd64-deb", - "checksum_type": "sha256", - "checksum": "ece4eedf7a5c65396d136b5765226e2c8b10f268c744b0ab1fa2625e35384a00", - }, - } - - digest_hash = { - "existentPackage_1.0-1_amd64.deb": ( - "sha256", - "cd5b4348e7b76c2287a9476f3f3ef3911480fe8e872ac541ffb598186a9e9607", - ), - "newPackage_2.0-1_amd64.deb": ( - "sha256", - "ece4eedf7a5c65396d136b5765226e2c8b10f268c744b0ab1fa2625e35384a00", - ), - } - - with patch( - "rhnpush.rhnpush_main.UploadClass.package", Mock(return_value=0) - ) as package, patch( - "rhnpush.rhnpush_main.UploadClass.check_package_exists", - Mock(return_value=(server_digest_hash, pkgs_info, digest_hash)), - ), patch( - "rhnpush.uploadLib.listdir", - Mock(return_value=["newPackage_2.0-1_amd64.deb"]), - ): - config_parser = rhnpush_config.rhnpushConfigParser() - with (patch.dict(config_parser.__dict__, TestUpload.config)): - self._upload.options = config_parser - self._upload.directory() - - self._upload.packages() - package.assert_called_with( - "newPackage_2.0-1_amd64.deb", - "sha256", - "ece4eedf7a5c65396d136b5765226e2c8b10f268c744b0ab1fa2625e35384a00", - ) - - class FakePackageHeader: - def hdr(self): - return TestUpload.mocked_deb_pkg_header_cadabra - - is_source = False - is_signed = True - packaging = "deb" - - @staticmethod - def is_signed(cls): - return cls.is_signed - - class FakeRHNPushSession: - def __init__(self): - self.session = ( - "90xbad6b03797f6a640472463247de4604cc986c551af54e4f04284268bb0ced287" - ) - self.location = "/var/lib/wwwrun/.rhnpushcache" - - def readSession(self): - pass - - def writeSession(self): - pass - - def getSessionString(self): - return self.session - - @patch( - "rhnpush.rhnpush_v2.PingPackageUpload.ping", - Mock(return_value=[200, "OK", http_headers]), - ) - @patch("rhnpush.uploadLib.UploadClass.checkSession", Mock(return_value=1)) - @patch("rhnpush.uploadLib.call", Mock(return_value=0)) - @patch("rhnpush.rhnpush_cache.RHNPushSession", FakeRHNPushSession) - def test_newest(self): - - mocked_deb_pkg_header = { - "name": "existentPackage", - "arch": "amd64-deb", - "epoch": "", - "version": "1.0", - "release": "1+a", - } - - mocked_deb_pkg = { - "header": mocked_deb_pkg_header, - "header_start": 0, - "header_end": 602736, - "input_stream": None, - "checksum_type": "sha256", - "checksum": "cd5b4348e7b76c2287a9476f3f3ef3911480fe8e872ac541ffb598186a9e9607", - "payload_stream": None, - "payload_size": 602736, - "header_data": None, - } - - mocked_pkg_info = { - "header": mocked_deb_pkg_header, - "checksum_type": "sha256", - "checksum": "cd5b4348e7b76c2287a9476f3f3ef3911480fe8e872ac541ffb598186a9e9607", - "packageSize": 602736, - "header_start": 0, - "header_end": 602736, - "nvrea": ("existentPackage", "1.0", "1+a", "", "amd64-deb"), - } - - pkgs_info_new = { - "existentPackage_1.0-1+a_amd64.deb": { - "name": "existentPackage", - "version": "1.0b", - "release": "1", - "epoch": "", - "arch": "amd64-deb", - "checksum_type": "sha256", - "checksum": "cd5b4348e7b76c2287a9476f3f3ef3911480fe8e872ac541ffb598186a9e9607", - } - } - - digest_hash_new = { - "existentPackage_1.0-1+a_amd64.deb": ( - "sha256", - "cd5b4348e7b76c2287a9476f3f3ef3911480fe8e872ac541ffb598186a9e9607", - ) - } - - - with patch( - "rhnpush.uploadLib.listdir", - Mock(return_value=["existentPackage_1.0-1+a_amd64.deb"]), - ), patch("os.access", Mock(return_value=True)), patch( - "rhnpush.rhnpush_main.UploadClass.check_package_exists", - Mock( - return_value=( - {"existentPackage_1.0-1+a_amd64.deb": ""}, - pkgs_info_new, - digest_hash_new, - ) - ), - ), patch( - "rhnpush.uploadLib.package_from_filename", - Mock(return_value=mocked_deb_pkg), - ), patch( - "rhnpush.uploadLib.UploadClass._processFile", - Mock(return_value=mocked_pkg_info), - ), patch( - "rhnpush.uploadLib.get_package_header", - Mock(return_value=TestUpload.FakePackageHeader), - ), patch( - "rhnpush.uploadLib.UploadClass._listChannel", - Mock( - return_value=[ - ["existentPackage", "1.0", "1+1", "", "amd64-deb", "custom-deb-tools"] - ] - ), - ), patch( - "rhnpush.rhnpush_main.UploadClass._push_package_v2", - Mock(return_value=(200, "OK")), - ) as push_package: - - config_parser = rhnpush_config.rhnpushConfigParser() - with (patch.dict(config_parser.__dict__, TestUpload.config)): - self._upload.options = config_parser - self._upload.directory() - self._upload.newest() - self._upload.packages() - push_package.assert_called_with( - "existentPackage_1.0-1+a_amd64.deb", - "sha256", - "cd5b4348e7b76c2287a9476f3f3ef3911480fe8e872ac541ffb598186a9e9607", - ) diff --git a/client/tools/mgr-push/src/rhnpush/uploadLib.py b/client/tools/mgr-push/uploadLib.py similarity index 96% rename from client/tools/mgr-push/src/rhnpush/uploadLib.py rename to client/tools/mgr-push/uploadLib.py index 5d0acbce52de..05b013020b1f 100644 --- a/client/tools/mgr-push/src/rhnpush/uploadLib.py +++ b/client/tools/mgr-push/uploadLib.py @@ -26,7 +26,7 @@ # pylint: disable=W0702,W0703 import inspect -from uyuni.common import rhn_mpm, rhn_deb, rhn_rpm +from uyuni.common import rhn_mpm from uyuni.common.rhn_pkg import package_from_filename, get_package_header from uyuni.common.usix import raise_with_tb from up2date_client import rhnserver @@ -177,7 +177,7 @@ def directory(self): for filename in listdir(self.options.dir): # only add packages - if filename[-3:] in ("rpm", "mpm", "deb"): + if filename[-3:] in ("rpm", "mpm"): self.files.append(filename) def filter_excludes(self): @@ -264,7 +264,6 @@ def get_newest_binary_packages(self): # Loop through the args and only keep the newest ones localPackagesHash = {} for filename in self.files: - pkgtype = filename[-3:] nvrea = self._processFile(filename, nosig=1)['nvrea'] name = nvrea[0] if name not in localPackagesHash: @@ -278,7 +277,9 @@ def get_newest_binary_packages(self): continue skip_rpm = 0 for local_nvrea in same_names_hash.keys(): - ret = packageCompare(local_nvrea, nvrea, pkgtype) + # XXX is_mpm should be set accordingly + ret = packageCompare(local_nvrea, nvrea, + is_mpm=0) if ret == 0 and local_nvrea[4] == nvrea[4]: # Weird case, we've already compared the two skip_rpm = 1 @@ -305,7 +306,6 @@ def get_newest_binary_packages(self): pkglist = self._listChannel() for p in pkglist: - pkgtype = filename[-3:] name = p[0] if name not in localPackagesHash: # Not in the local list @@ -318,7 +318,9 @@ def get_newest_binary_packages(self): continue for local_nvrea in list(same_names_hash.keys()): - ret = packageCompare(local_nvrea, remote_nvrea, pkgtype) + # XXX is_mpm sould be set accordingly + ret = packageCompare(local_nvrea, remote_nvrea, + is_mpm=0) if ret < 0: # The remote package is newer than the local one del same_names_hash[local_nvrea] @@ -558,14 +560,7 @@ def _processFile(filename, relativeDir=None, source=None, nosig=None): lh.append(sstr(a_pkg.header['arch'])) # Build the header hash to be sent - if filename.endswith("deb"): - # The `header` data in the returned dictionary `info` is used with the `--headers` option for mgr-push. - # This option is not useful anymore as it was needed by `up2date`. - hdr = None - if filename.endswith("rpm") or filename.endswith("npm"): - hdr = Binary(a_pkg.header.unload()) - - info = {'header': hdr, + info = {'header': Binary(a_pkg.header.unload()), 'checksum_type': a_pkg.checksum_type, 'checksum': a_pkg.checksum, 'packageSize': size, @@ -786,7 +781,7 @@ def exists_getPackageChecksumBySession(rpc_server): # compare two package [n,v,r,e] tuples -def packageCompare(pkg1, pkg2, pkgtype): +def packageCompare(pkg1, pkg2, is_mpm=None): if pkg1[0] != pkg2[0]: raise ValueError("You should only compare packages with the same name") packages = [] @@ -798,14 +793,11 @@ def packageCompare(pkg1, pkg2, pkgtype): e = str(e) evr = (e, str(pkg[1]), str(pkg[2])) packages.append(evr) - if pkgtype == "mpm": + if is_mpm: func = rhn_mpm.labelCompare - elif pkgtype == "deb": - func = rhn_deb.labelCompare - elif pkgtype == "rpm": - func = rhn_rpm.labelCompare else: - raise ValueError("Unknown package type") + from uyuni.common import rhn_rpm + func = rhn_rpm.labelCompare return func(packages[0], packages[1]) diff --git a/client/tools/mgr-push/src/rhnpush/utils.py b/client/tools/mgr-push/utils.py similarity index 100% rename from client/tools/mgr-push/src/rhnpush/utils.py rename to client/tools/mgr-push/utils.py diff --git a/python/uyuni/common/rhn_deb.py b/python/uyuni/common/rhn_deb.py index 6dbb1eb152c0..1830e0030737 100644 --- a/python/uyuni/common/rhn_deb.py +++ b/python/uyuni/common/rhn_deb.py @@ -20,7 +20,7 @@ import sys import tempfile -from debian import debfile, debian_support +from debian import debfile from uyuni.common.usix import raise_with_tb from uyuni.common import checksum @@ -141,10 +141,3 @@ def save_payload(self, output_stream): if output_stream: self.payload_stream = output_stream self.payload_size = output_stream.tell() - output_start - - -def labelCompare(t1, t2): - label1 = t1[1] + '-' + t1[2] - label2 = t2[1] + '-' + t2[2] - return debian_support.version_compare(label1, label2) - diff --git a/susemanager-utils/testing/automation/mgr-push-unittest.sh b/susemanager-utils/testing/automation/mgr-push-unittest.sh deleted file mode 100644 index d3c476161c43..000000000000 --- a/susemanager-utils/testing/automation/mgr-push-unittest.sh +++ /dev/null @@ -1,33 +0,0 @@ -#! /bin/sh -SCRIPT=$(basename ${0}) - -if [ -z ${PRODUCT+x} ];then - VPRODUCT="VERSION.Uyuni" -else - VPRODUCT="VERSION.${PRODUCT}" -fi - -while getopts 'P:h' option -do - case ${option} in - P) VPRODUCT="VERSION.${OPTARG}" ;; - h) echo "Usage ${SCRIPT} [-P PRODUCT]";exit 2;; - esac -done - -HERE=`dirname $0` - -if [ ! -f ${HERE}/${VPRODUCT} ];then - echo "${VPRODUCT} does not exist" - exit 3 -fi - -echo "Loading ${VPRODUCT}" -. ${HERE}/${VPRODUCT} -GITROOT=`readlink -f ${HERE}/../../../` - -cd $GITROOT/client/tools/mgr-push -make DOCKER_REGISTRY="${REGISTRY}" DOCKER_IMAGE="${PGSQL_CONTAINER}" -f Makefile.python docker_pytest - -exit $? -