2686359b2c
- Update to Salt release version 3006.0 (jsc#PED-3139) * See release notes: https://docs.saltproject.io/en/latest/topics/releases/3006.0.html - Add python3-looseversion as new dependency for salt - Add python3-packaging as new dependency for salt - Drop conflictive patch dicarded from upstream - Fix SLS rendering error when Jinja macros are used - Fix version detection and avoid building and testing failures - Added: * fix-version-detection-and-avoid-building-and-testing.patch * make-sure-the-file-client-is-destroyed-upon-used.patch - Modified: * 3005.1-implement-zypper-removeptf-573.patch * activate-all-beacons-sources-config-pillar-grains.patch * add-custom-suse-capabilities-as-grains.patch * add-environment-variable-to-know-if-yum-is-invoked-f.patch * add-migrated-state-and-gpg-key-management-functions-.patch * add-publish_batch-to-clearfuncs-exposed-methods.patch * add-salt-ssh-support-with-venv-salt-minion-3004-493.patch * add-sleep-on-exception-handling-on-minion-connection.patch * add-standalone-configuration-file-for-enabling-packa.patch * add-support-for-gpgautoimport-539.patch * allow-vendor-change-option-with-zypper.patch * async-batch-implementation.patch * avoid-excessive-syslogging-by-watchdog-cronjob-58.patch * bsc-1176024-fix-file-directory-user-and-group-owners.patch * change-the-delimeters-to-prevent-possible-tracebacks.patch * control-the-collection-of-lvm-grains-via-config.patch * debian-info_installed-compatibility-50453.patch * dnfnotify-pkgset-plugin-implementation-3002.2-450.patch * do-not-load-pip-state-if-there-is-no-3rd-party-depen.patch * don-t-use-shell-sbin-nologin-in-requisites.patch * drop-serial-from-event.unpack-in-cli.batch_async.patch * early-feature-support-config.patch * enable-passing-a-unix_socket-for-mysql-returners-bsc.patch * enhance-openscap-module-add-xccdf_eval-call-386.patch * fix-bsc-1065792.patch * fix-for-suse-expanded-support-detection.patch * fix-issue-2068-test.patch * fix-missing-minion-returns-in-batch-mode-360.patch * fix-ownership-of-salt-thin-directory-when-using-the-.patch * fix-regression-with-depending-client.ssh-on-psutil-b.patch * fix-salt-ssh-opts-poisoning-bsc-1197637-3004-501.patch * fix-salt.utils.stringutils.to_str-calls-to-make-it-w.patch * fix-the-regression-for-yumnotify-plugin-456.patch * fix-traceback.print_exc-calls-for-test_pip_state-432.patch * fixes-for-python-3.10-502.patch * include-aliases-in-the-fqdns-grains.patch * info_installed-works-without-status-attr-now.patch * let-salt-ssh-use-platform-python-binary-in-rhel8-191.patch * make-aptpkg.list_repos-compatible-on-enabled-disable.patch * make-setup.py-script-to-not-require-setuptools-9.1.patch * pass-the-context-to-pillar-ext-modules.patch * prevent-affection-of-ssh.opts-with-lazyloader-bsc-11.patch * prevent-pkg-plugins-errors-on-missing-cookie-path-bs.patch * prevent-shell-injection-via-pre_flight_script_args-4.patch * read-repo-info-without-using-interpolation-bsc-11356.patch * restore-default-behaviour-of-pkg-list-return.patch * return-the-expected-powerpc-os-arch-bsc-1117995.patch * revert-fixing-a-use-case-when-multiple-inotify-beaco.patch * run-salt-api-as-user-salt-bsc-1064520.patch * run-salt-master-as-dedicated-salt-user.patch * save-log-to-logfile-with-docker.build.patch * skip-package-names-without-colon-bsc-1208691-578.patch * switch-firewalld-state-to-use-change_interface.patch * temporary-fix-extend-the-whitelist-of-allowed-comman.patch * update-target-fix-for-salt-ssh-to-process-targets-li.patch * use-adler32-algorithm-to-compute-string-checksums.patch * use-rlock-to-avoid-deadlocks-in-salt-ssh.patch * use-salt-bundle-in-dockermod.patch * x509-fixes-111.patch * zypperpkg-ignore-retcode-104-for-search-bsc-1176697-.patch - Removed: * add-amazon-ec2-detection-for-virtual-grains-bsc-1195.patch * add-support-for-name-pkgs-and-diff_attr-parameters-t.patch * align-amazon-ec2-nitro-grains-with-upstream-pr-bsc-1.patch * allow-entrypoint-compatibility-for-importlib-metadat.patch * clarify-pkg.installed-pkg_verify-documentation.patch * detect-module.run-syntax.patch * fix-salt.states.file.managed-for-follow_symlinks-tru.patch * fix-state.apply-in-test-mode-with-file-state-module-.patch * fix-test_ipc-unit-tests.patch * fixes-pkg.version_cmp-on-openeuler-systems-and-a-few.patch * fopen-workaround-bad-buffering-for-binary-mode-563.patch * ignore-erros-on-reading-license-files-with-dpkg_lowp.patch * ignore-extend-declarations-from-excluded-sls-files.patch * ignore-non-utf8-characters-while-reading-files-with-.patch * include-stdout-in-error-message-for-zypperpkg-559.patch * make-pass-renderer-configurable-other-fixes-532.patch * make-sure-saltcacheloader-use-correct-fileclient-519.patch * normalize-package-names-once-with-pkg.installed-remo.patch * retry-if-rpm-lock-is-temporarily-unavailable-547.patch * set-default-target-for-pip-from-venv_pip_target-envi.patch * state.apply-don-t-check-for-cached-pillar-errors.patch * state.orchestrate_single-does-not-pass-pillar-none-4.patch OBS-URL: https://build.opensuse.org/request/show/1084999 OBS-URL: https://build.opensuse.org/package/show/systemsmanagement:saltstack/salt?expand=0&rev=210
352 lines
12 KiB
Diff
352 lines
12 KiB
Diff
From 2fbc5b580661b094cf79cc5da0860745b72088e4 Mon Sep 17 00:00:00 2001
|
|
From: Alexander Graul <agraul@suse.com>
|
|
Date: Tue, 25 Jan 2022 17:08:57 +0100
|
|
Subject: [PATCH] Debian info_installed compatibility (#50453)
|
|
|
|
Remove unused variable
|
|
|
|
Get unit ticks installation time
|
|
|
|
Pass on unix ticks installation date time
|
|
|
|
Implement function to figure out package build time
|
|
|
|
Unify arch attribute
|
|
|
|
Add 'attr' support.
|
|
|
|
Use attr parameter in aptpkg
|
|
|
|
Add 'all_versions' output structure backward compatibility
|
|
|
|
Fix docstring
|
|
|
|
Add UT for generic test of function 'info'
|
|
|
|
Add UT for 'info' function with the parameter 'attr'
|
|
|
|
Add UT for info_installed's 'attr' param
|
|
|
|
Fix docstring
|
|
|
|
Add returned type check
|
|
|
|
Add UT for info_installed with 'all_versions=True' output structure
|
|
|
|
Refactor UT for 'owner' function
|
|
|
|
Refactor UT: move to decorators, add more checks
|
|
|
|
Schedule TODO for next refactoring of UT 'show' function
|
|
|
|
Refactor UT: get rid of old assertion way, flatten tests
|
|
|
|
Refactor UT: move to native assertions, cleanup noise, flatten complexity for better visibility what is tested
|
|
|
|
Lintfix: too many empty lines
|
|
|
|
Adjust architecture getter according to the lowpkg info
|
|
|
|
Fix wrong Git merge: missing function signature
|
|
|
|
Reintroducing reverted changes
|
|
|
|
Reintroducing changes from commit e20362f6f053eaa4144583604e6aac3d62838419
|
|
that got partially reverted by this commit:
|
|
https://github.com/openSUSE/salt/commit/d0ef24d113bdaaa29f180031b5da384cffe08c64#diff-820e6ce667fe3afddbc1b9cf1682fdef
|
|
---
|
|
salt/modules/aptpkg.py | 24 ++++-
|
|
salt/modules/dpkg_lowpkg.py | 110 ++++++++++++++++++----
|
|
tests/pytests/unit/modules/test_aptpkg.py | 52 ++++++++++
|
|
3 files changed, 167 insertions(+), 19 deletions(-)
|
|
|
|
diff --git a/salt/modules/aptpkg.py b/salt/modules/aptpkg.py
|
|
index 8e89744b5e..938e37cc9e 100644
|
|
--- a/salt/modules/aptpkg.py
|
|
+++ b/salt/modules/aptpkg.py
|
|
@@ -3440,6 +3440,15 @@ def info_installed(*names, **kwargs):
|
|
|
|
.. versionadded:: 2016.11.3
|
|
|
|
+ attr
|
|
+ Comma-separated package attributes. If no 'attr' is specified, all available attributes returned.
|
|
+
|
|
+ Valid attributes are:
|
|
+ version, vendor, release, build_date, build_date_time_t, install_date, install_date_time_t,
|
|
+ build_host, group, source_rpm, arch, epoch, size, license, signature, packager, url, summary, description.
|
|
+
|
|
+ .. versionadded:: Neon
|
|
+
|
|
CLI Example:
|
|
|
|
.. code-block:: bash
|
|
@@ -3450,11 +3459,19 @@ def info_installed(*names, **kwargs):
|
|
"""
|
|
kwargs = salt.utils.args.clean_kwargs(**kwargs)
|
|
failhard = kwargs.pop("failhard", True)
|
|
+ kwargs.pop("errors", None) # Only for compatibility with RPM
|
|
+ attr = kwargs.pop("attr", None) # Package attributes to return
|
|
+ all_versions = kwargs.pop(
|
|
+ "all_versions", False
|
|
+ ) # This is for backward compatible structure only
|
|
+
|
|
if kwargs:
|
|
salt.utils.args.invalid_kwargs(kwargs)
|
|
|
|
ret = dict()
|
|
- for pkg_name, pkg_nfo in __salt__["lowpkg.info"](*names, failhard=failhard).items():
|
|
+ for pkg_name, pkg_nfo in __salt__["lowpkg.info"](
|
|
+ *names, failhard=failhard, attr=attr
|
|
+ ).items():
|
|
t_nfo = dict()
|
|
if pkg_nfo.get("status", "ii")[1] != "i":
|
|
continue # return only packages that are really installed
|
|
@@ -3475,7 +3492,10 @@ def info_installed(*names, **kwargs):
|
|
else:
|
|
t_nfo[key] = value
|
|
|
|
- ret[pkg_name] = t_nfo
|
|
+ if all_versions:
|
|
+ ret.setdefault(pkg_name, []).append(t_nfo)
|
|
+ else:
|
|
+ ret[pkg_name] = t_nfo
|
|
|
|
return ret
|
|
|
|
diff --git a/salt/modules/dpkg_lowpkg.py b/salt/modules/dpkg_lowpkg.py
|
|
index eefd852c51..4d716c8772 100644
|
|
--- a/salt/modules/dpkg_lowpkg.py
|
|
+++ b/salt/modules/dpkg_lowpkg.py
|
|
@@ -234,6 +234,44 @@ def file_dict(*packages, **kwargs):
|
|
return {"errors": errors, "packages": ret}
|
|
|
|
|
|
+def _get_pkg_build_time(name):
|
|
+ """
|
|
+ Get package build time, if possible.
|
|
+
|
|
+ :param name:
|
|
+ :return:
|
|
+ """
|
|
+ iso_time = iso_time_t = None
|
|
+ changelog_dir = os.path.join("/usr/share/doc", name)
|
|
+ if os.path.exists(changelog_dir):
|
|
+ for fname in os.listdir(changelog_dir):
|
|
+ try:
|
|
+ iso_time_t = int(os.path.getmtime(os.path.join(changelog_dir, fname)))
|
|
+ iso_time = (
|
|
+ datetime.datetime.utcfromtimestamp(iso_time_t).isoformat() + "Z"
|
|
+ )
|
|
+ break
|
|
+ except OSError:
|
|
+ pass
|
|
+
|
|
+ # Packager doesn't care about Debian standards, therefore Plan B: brute-force it.
|
|
+ if not iso_time:
|
|
+ for pkg_f_path in __salt__["cmd.run"](
|
|
+ "dpkg-query -L {}".format(name)
|
|
+ ).splitlines():
|
|
+ if "changelog" in pkg_f_path.lower() and os.path.exists(pkg_f_path):
|
|
+ try:
|
|
+ iso_time_t = int(os.path.getmtime(pkg_f_path))
|
|
+ iso_time = (
|
|
+ datetime.datetime.utcfromtimestamp(iso_time_t).isoformat() + "Z"
|
|
+ )
|
|
+ break
|
|
+ except OSError:
|
|
+ pass
|
|
+
|
|
+ return iso_time, iso_time_t
|
|
+
|
|
+
|
|
def _get_pkg_info(*packages, **kwargs):
|
|
"""
|
|
Return list of package information. If 'packages' parameter is empty,
|
|
@@ -257,7 +295,7 @@ def _get_pkg_info(*packages, **kwargs):
|
|
cmd = (
|
|
"dpkg-query -W -f='package:" + bin_var + "\\n"
|
|
"revision:${binary:Revision}\\n"
|
|
- "architecture:${Architecture}\\n"
|
|
+ "arch:${Architecture}\\n"
|
|
"maintainer:${Maintainer}\\n"
|
|
"summary:${Summary}\\n"
|
|
"source:${source:Package}\\n"
|
|
@@ -299,10 +337,17 @@ def _get_pkg_info(*packages, **kwargs):
|
|
key, value = pkg_info_line.split(":", 1)
|
|
if value:
|
|
pkg_data[key] = value
|
|
- install_date = _get_pkg_install_time(pkg_data.get("package"))
|
|
- if install_date:
|
|
- pkg_data["install_date"] = install_date
|
|
- pkg_data["description"] = pkg_descr
|
|
+ install_date, install_date_t = _get_pkg_install_time(
|
|
+ pkg_data.get("package"), pkg_data.get("arch")
|
|
+ )
|
|
+ if install_date:
|
|
+ pkg_data["install_date"] = install_date
|
|
+ pkg_data["install_date_time_t"] = install_date_t # Unix ticks
|
|
+ build_date, build_date_t = _get_pkg_build_time(pkg_data.get("package"))
|
|
+ if build_date:
|
|
+ pkg_data["build_date"] = build_date
|
|
+ pkg_data["build_date_time_t"] = build_date_t
|
|
+ pkg_data["description"] = pkg_descr.split(":", 1)[-1]
|
|
ret.append(pkg_data)
|
|
|
|
return ret
|
|
@@ -327,24 +372,34 @@ def _get_pkg_license(pkg):
|
|
return ", ".join(sorted(licenses))
|
|
|
|
|
|
-def _get_pkg_install_time(pkg):
|
|
+def _get_pkg_install_time(pkg, arch):
|
|
"""
|
|
Return package install time, based on the /var/lib/dpkg/info/<package>.list
|
|
|
|
:return:
|
|
"""
|
|
- iso_time = None
|
|
+ iso_time = iso_time_t = None
|
|
+ loc_root = "/var/lib/dpkg/info"
|
|
if pkg is not None:
|
|
- location = "/var/lib/dpkg/info/{}.list".format(pkg)
|
|
- if os.path.exists(location):
|
|
- iso_time = (
|
|
- datetime.datetime.utcfromtimestamp(
|
|
- int(os.path.getmtime(location))
|
|
- ).isoformat()
|
|
- + "Z"
|
|
- )
|
|
+ locations = []
|
|
+ if arch is not None and arch != "all":
|
|
+ locations.append(os.path.join(loc_root, "{}:{}.list".format(pkg, arch)))
|
|
|
|
- return iso_time
|
|
+ locations.append(os.path.join(loc_root, "{}.list".format(pkg)))
|
|
+ for location in locations:
|
|
+ try:
|
|
+ iso_time_t = int(os.path.getmtime(location))
|
|
+ iso_time = (
|
|
+ datetime.datetime.utcfromtimestamp(iso_time_t).isoformat() + "Z"
|
|
+ )
|
|
+ break
|
|
+ except OSError:
|
|
+ pass
|
|
+
|
|
+ if iso_time is None:
|
|
+ log.debug('Unable to get package installation time for package "%s".', pkg)
|
|
+
|
|
+ return iso_time, iso_time_t
|
|
|
|
|
|
def _get_pkg_ds_avail():
|
|
@@ -394,6 +449,15 @@ def info(*packages, **kwargs):
|
|
|
|
.. versionadded:: 2016.11.3
|
|
|
|
+ attr
|
|
+ Comma-separated package attributes. If no 'attr' is specified, all available attributes returned.
|
|
+
|
|
+ Valid attributes are:
|
|
+ version, vendor, release, build_date, build_date_time_t, install_date, install_date_time_t,
|
|
+ build_host, group, source_rpm, arch, epoch, size, license, signature, packager, url, summary, description.
|
|
+
|
|
+ .. versionadded:: Neon
|
|
+
|
|
CLI Example:
|
|
|
|
.. code-block:: bash
|
|
@@ -408,6 +472,10 @@ def info(*packages, **kwargs):
|
|
|
|
kwargs = salt.utils.args.clean_kwargs(**kwargs)
|
|
failhard = kwargs.pop("failhard", True)
|
|
+ attr = kwargs.pop("attr", None) or None
|
|
+ if attr:
|
|
+ attr = attr.split(",")
|
|
+
|
|
if kwargs:
|
|
salt.utils.args.invalid_kwargs(kwargs)
|
|
|
|
@@ -435,6 +503,14 @@ def info(*packages, **kwargs):
|
|
lic = _get_pkg_license(pkg["package"])
|
|
if lic:
|
|
pkg["license"] = lic
|
|
- ret[pkg["package"]] = pkg
|
|
+
|
|
+ # Remove keys that aren't in attrs
|
|
+ pkg_name = pkg["package"]
|
|
+ if attr:
|
|
+ for k in list(pkg.keys())[:]:
|
|
+ if k not in attr:
|
|
+ del pkg[k]
|
|
+
|
|
+ ret[pkg_name] = pkg
|
|
|
|
return ret
|
|
diff --git a/tests/pytests/unit/modules/test_aptpkg.py b/tests/pytests/unit/modules/test_aptpkg.py
|
|
index b69402578a..4226957eeb 100644
|
|
--- a/tests/pytests/unit/modules/test_aptpkg.py
|
|
+++ b/tests/pytests/unit/modules/test_aptpkg.py
|
|
@@ -360,6 +360,58 @@ def test_info_installed(lowpkg_info_var):
|
|
assert len(aptpkg.info_installed()) == 1
|
|
|
|
|
|
+def test_info_installed_attr(lowpkg_info_var):
|
|
+ """
|
|
+ Test info_installed 'attr'.
|
|
+ This doesn't test 'attr' behaviour per se, since the underlying function is in dpkg.
|
|
+ The test should simply not raise exceptions for invalid parameter.
|
|
+
|
|
+ :return:
|
|
+ """
|
|
+ expected_pkg = {
|
|
+ "url": "http://www.gnu.org/software/wget/",
|
|
+ "packager": "Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>",
|
|
+ "name": "wget",
|
|
+ "install_date": "2016-08-30T22:20:15Z",
|
|
+ "description": "retrieves files from the web",
|
|
+ "version": "1.15-1ubuntu1.14.04.2",
|
|
+ "architecture": "amd64",
|
|
+ "group": "web",
|
|
+ "source": "wget",
|
|
+ }
|
|
+ mock = MagicMock(return_value=lowpkg_info_var)
|
|
+ with patch.dict(aptpkg.__salt__, {"lowpkg.info": mock}):
|
|
+ ret = aptpkg.info_installed("wget", attr="foo,bar")
|
|
+ assert ret["wget"] == expected_pkg
|
|
+
|
|
+
|
|
+def test_info_installed_all_versions(lowpkg_info_var):
|
|
+ """
|
|
+ Test info_installed 'all_versions'.
|
|
+ Since Debian won't return same name packages with the different names,
|
|
+ this should just return different structure, backward compatible with
|
|
+ the RPM equivalents.
|
|
+
|
|
+ :return:
|
|
+ """
|
|
+ expected_pkg = {
|
|
+ "url": "http://www.gnu.org/software/wget/",
|
|
+ "packager": "Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>",
|
|
+ "name": "wget",
|
|
+ "install_date": "2016-08-30T22:20:15Z",
|
|
+ "description": "retrieves files from the web",
|
|
+ "version": "1.15-1ubuntu1.14.04.2",
|
|
+ "architecture": "amd64",
|
|
+ "group": "web",
|
|
+ "source": "wget",
|
|
+ }
|
|
+ mock = MagicMock(return_value=lowpkg_info_var)
|
|
+ with patch.dict(aptpkg.__salt__, {"lowpkg.info": mock}):
|
|
+ ret = aptpkg.info_installed("wget", all_versions=True)
|
|
+ assert isinstance(ret, dict)
|
|
+ assert ret["wget"] == [expected_pkg]
|
|
+
|
|
+
|
|
def test_owner():
|
|
"""
|
|
Test - Return the name of the package that owns the file.
|
|
--
|
|
2.39.2
|
|
|
|
|