File venv-salt-minion.spec of Package venv-salt-minion

#
# spec file for package venv-salt-minion
#
# Copyright (c) 2021 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#

# Add conditional salt bundle testsuite build
%bcond_with salt_bundle_testsuite

# OBS directives (do not remove)
# needsbinariesforbuild

# Disable python bytecompile for all distros
# It's called explicitly in the spec
%global __brp_python_bytecompile %{nil}

%global __brp_check_rpaths %{nil}

%global _build_id_links none

%if 0%{?rhel} == 7
%undefine __debug_package
%else
%global debug_package %{nil}
%endif

%global salt_venv /usr/lib/
%global venv venv-salt-minion

Name:           venv-salt-minion
Version:        3006.0
Release:        0
Summary:        The venvjailed client component for Salt
License:        Apache-2.0
Group:          System/Management
URL:            http://saltstack.org/
Source:         v%{version}.tar.gz
%if "%_vendor" == "debbuild"
Source10:       exclude-deb
Source11:       include-deb
%else
Source10:       exclude-rpm
Source11:       include-rpm
%endif
Source12:       remove-file
Source13:       venv.py.src
Source14:       venv-startup
Source15:       venv-salt-minion.initd
Source20:       post_start_cleanup.sh
Source100:      venv-salt-minion-rpmlintrc
Source101:      filter-requires.sh
Source200:      venv-salt-minion-selinux.tar.gz

### SALT PATCHES LIST BEGIN
### IMPORTANT: The line above is used as a snippet marker. Do not touch it.

# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/commit/88f40fff3b81edaa55f37949f56c67112ca2dcad
Patch1:         run-salt-master-as-dedicated-salt-user.patch
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/commit/cdecbbdf5db3f1cb6b603916fecd80738f5fae9a
Patch2:         run-salt-api-as-user-salt-bsc-1064520.patch
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/commit/c44b897eb1305c6b9c341fc16f729d2293ab24e4
Patch3:         activate-all-beacons-sources-config-pillar-grains.patch
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/commit/3c83bab3da101223c99af1f9ee2f3bf5e97be3f8
Patch4:         avoid-excessive-syslogging-by-watchdog-cronjob-58.patch
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/commit/1b9a160f578cf446f5ae622a450d23022e7e3ca5
Patch5:         fix-bsc-1065792.patch
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/commit/fec7f65b4debede8cf0eef335182fce2206e200d
Patch6:         enable-passing-a-unix_socket-for-mysql-returners-bsc.patch
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/pull/90
Patch7:         add-environment-variable-to-know-if-yum-is-invoked-f.patch

#### SUSE CAPABILITIES - unified ####
# PATCH_FIX_OPENSUSE https://github.com/openSUSE/salt/commit/713ccfdc5c6733495d3ce7f26a8cfeddb8e9e9c4
# PATCH_FIX_OPENSUSE https://github.com/openSUSE/salt/commit/b713d0b3031faadc17cd9cf09977ccc19e50bef7
Patch8:         add-custom-suse-capabilities-as-grains.patch
###########

#### SUSE SLES-ES SUPPORT ####
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/57166
Patch9:         fix-for-suse-expanded-support-detection.patch
############

#### ADLER - unified ####
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/48812
# (closed upstream in favor of different solution - might affect server_id)
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/pull/159
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/commit/73e357d7eee19a73cade22becb30d9689cae27ba
Patch10:        use-adler32-algorithm-to-compute-string-checksums.patch
###########

#### X509 - unified ####
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/56819
Patch11:        x509-fixes-111.patch
###########

# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/58054
Patch12:        do-not-load-pip-state-if-there-is-no-3rd-party-depen.patch

#### SALT SUPPORT - unified ####
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/57054
Patch13:        early-feature-support-config.patch
###########

# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/57071
Patch14:        make-aptpkg.list_repos-compatible-on-enabled-disable.patch

### DEBIAN INFO_INSTALLED - unified ###
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/50453
# (master PR not yet created - codejam)
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/50453
#                     https://github.com/saltstack/salt/commit/e20362f6f053eaa4144583604e6aac3d62838419
# Can be dropped one pull/50453 is in released version.
Patch15:        debian-info_installed-compatibility-50453.patch
###########

# PATCH_FIX_OPENSUSE https://github.com/openSUSE/salt/pull/116 (missing upstream PR to master)
Patch16:        return-the-expected-powerpc-os-arch-bsc-1117995.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/51119 (master PR not yet created)
Patch17:        fix-issue-2068-test.patch
# PATCH_FIX_OPENSUSE Temporary fix allowing "id_" and "force" params while upstrem figures it out
Patch18:        temporary-fix-extend-the-whitelist-of-allowed-comman.patch

### FQDNS ####
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/51384 (master PR not yet created)
Patch19:        include-aliases-in-the-fqdns-grains.patch
###########

#### BATCH ASYNC - unified #####
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/60269
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/50546
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/51863
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/pull/139
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/pull/141
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/pull/144
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/52855
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/commit/6af07030a502c427781991fc9a2b994fa04ef32e
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/commit/002543df392f65d95dbc127dc058ac897f2035ed
# PATCH_FIX_OPENSUSE https://github.com/openSUSE/salt/commit/55d8a777d6a9b19c959e14a4060e5579e92cd106
# PATCH_FIX_OPENSUSE https://github.com/openSUSE/salt/commit/8378bb24a5a53973e8dba7658b8b3465d967329f
# PATCH_FIX_OPENSUSE https://github.com/openSUSE/salt/pull/182
# PATCH_FIX_OPENSUSE https://github.com/openSUSE/salt/pull/190
# PATCH_FIX_OPENSUSE https://github.com/openSUSE/salt/pull/217
# PATCH_FIX_OPENSUSE https://github.com/openSUSE/salt/commit/8a23030d347b7487328c0395f5e30ef29daf1455
# PATCH_FIX_OPENSUSE https://github.com/openSUSE/salt/commit/a38adfa2efe40c2b1508b685af0b5d28a6bbcfc8
# PATCH_FIX_OPENSUSE https://github.com/openSUSE/salt/commit/b4c401cfe6031b61e27f7795bfa1aca6e8341e52
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/pull/320
# PATCH_FIX_OPENSUSE https://github.com/openSUSE/salt/commit/25b4e3ea983b2606b2fb3d3c0e42f9840208bf84 (cleanup local code)
Patch20:        async-batch-implementation.patch
###########

# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/52743
Patch21:        switch-firewalld-state-to-use-change_interface.patch

### STANDALONE FORMULA CONFIGURATION ###
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/commit/8ad65d6fa39edc7fc1967e2df1f3db0aa7df4d11
Patch22:        add-standalone-configuration-file-for-enabling-packa.patch
#############

# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/pull/177
# (deviation from upstream - we should probably port this)
Patch23:        restore-default-behaviour-of-pkg-list-return.patch
# PATCH_FIX_OPENSUSE https://github.com/openSUSE/salt/pull/186 (missing upstream PR to master)
Patch24:        read-repo-info-without-using-interpolation-bsc-11356.patch
# PATCH_FIX_OPENSUSE https://github.com/openSUSE/salt/pull/191 (missing upstream PR to master)
Patch25:        let-salt-ssh-use-platform-python-binary-in-rhel8-191.patch
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/commit/a18ac47b75550bd55f4ca91dc221ed408881984c
Patch26:        make-setup.py-script-to-not-require-setuptools-9.1.patch
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/pull/228 (missing upstream PR)
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/commit/da936daeebd701e147707ad814c07bfc259d4be (not yet upstream PR)
Patch27:        add-publish_batch-to-clearfuncs-exposed-methods.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/57779
Patch28:        info_installed-works-without-status-attr-now.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/58552
Patch29:        zypperpkg-ignore-retcode-104-for-search-bsc-1176697-.patch

# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/pull/275 (missing upstream PR)
Patch30:        bsc-1176024-fix-file-directory-user-and-group-owners.patch

#### NO VENDOR CHANGE ####
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/60421
Patch31:        allow-vendor-change-option-with-zypper.patch
###########

# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/58784
Patch32:        add-migrated-state-and-gpg-key-management-functions-.patch

### BEACON CONFIG ###
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/commit/5ea2f10b15684dd417bad858642faafc92cd382
# (revert https://github.com/saltstack/salt/pull/58655)
Patch33:        revert-fixing-a-use-case-when-multiple-inotify-beaco.patch
###########

# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/pull/298 (missing upstream PR)
Patch34:        fix-salt.utils.stringutils.to_str-calls-to-make-it-w.patch

# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/pull/307 (missing upstream PR)
Patch35:        add-sleep-on-exception-handling-on-minion-connection.patch

### SALT-SSH PROCESSING TARGETS ###
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/pull/336 (missing upstream PR)
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/pull/353 (missing upstream PR)
Patch36:        update-target-fix-for-salt-ssh-to-process-targets-li.patch
############

# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/58503
Patch37:        fix-missing-minion-returns-in-batch-mode-360.patch

#### OPENSCAP ENHANCE ####
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/59756
Patch38:        enhance-openscap-module-add-xccdf_eval-call-386.patch
###############

# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/pull/413 (missing upstream PR)
Patch39:        don-t-use-shell-sbin-nologin-in-requisites.patch
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/pull/432 (missing upstream PR)
Patch40:        fix-traceback.print_exc-calls-for-test_pip_state-432.patch
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/pull/415 (missing upstream PR)
Patch41:        prevent-pkg-plugins-errors-on-missing-cookie-path-bs.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/61180
Patch42:        dnfnotify-pkgset-plugin-implementation-3002.2-450.patch
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/pull/456 (missing upstream PR)
Patch43:        fix-the-regression-for-yumnotify-plugin-456.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/482
Patch44:        drop-serial-from-event.unpack-in-cli.batch_async.patch

### SALT-SSH WITH SALT BUNDLE ###
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/61715 (ssh_pre_flight_args)
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/493
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/497
Patch45:        add-salt-ssh-support-with-venv-salt-minion-3004-493.patch
Patch46:        prevent-shell-injection-via-pre_flight_script_args-4.patch
###############

# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/501
Patch47:        fix-salt-ssh-opts-poisoning-bsc-1197637-3004-501.patch

# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/505
Patch48:        prevent-affection-of-ssh.opts-with-lazyloader-bsc-11.patch

# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/506
Patch49:        fix-regression-with-depending-client.ssh-on-psutil-b.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/62109
Patch50:        use-salt-bundle-in-dockermod.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/61984
Patch51:        save-log-to-logfile-with-docker.build.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/534
Patch52:        fix-ownership-of-salt-thin-directory-when-using-the-.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/62209
Patch53:        add-support-for-gpgautoimport-539.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/62519
Patch54:        change-the-delimeters-to-prevent-possible-tracebacks.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/62898
Patch55:        pass-the-context-to-pillar-ext-modules.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/commit/c6be36eeea49ee0d0641da272087305f79c32c99 (not yet upstream)
# Fix problem caused by: https://github.com/openSUSE/salt/pull/493 (Patch47) affecting only 3005.1.
Patch56:        use-rlock-to-avoid-deadlocks-in-salt-ssh.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/61064
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/commit/5e3ff4d662321c237ddd5b2c5c83f35a84af594c (not PR to master yet)
Patch57:        fixes-for-python-3.10-502.patch
# PATCH-FIX-OPENSUSE: https://github.com/openSUSE/salt/pull/571
Patch58:        control-the-collection-of-lvm-grains-via-config.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/63460
Patch59:        3005.1-implement-zypper-removeptf-573.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/63460
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/578
Patch60:        skip-package-names-without-colon-bsc-1208691-578.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/commit/c0fae09e5a4f6997a60007d970c7c6a5614d9102
Patch61:        fix-version-detection-and-avoid-building-and-testing.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/64113
Patch62:        make-sure-the-file-client-is-destroyed-upon-used.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/581
Patch63:        avoid-conflicts-with-dependencies-versions-bsc-12116.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/64369
Patch64:        define-__virtualname__-for-transactional_update-modu.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/587
Patch65:        make-master_tops-compatible-with-salt-3000-and-older.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/583
Patch66:        tornado-fix-an-open-redirect-in-staticfilehandler-cv.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/580
Patch67:        fix-some-issues-detected-in-salt-support-cli-module-.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/64510
Patch68:        3006.0-prevent-_pygit2.giterror-error-loading-known_.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/64300
Patch69:        fix-utf8-handling-in-pass-renderer-and-make-it-more-.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/63403
Patch70:        zypper-pkgrepo-alreadyconfigured-585.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/64530
Patch71:        fix-the-regression-of-user.present-state-when-group-.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/64179
Patch72:        fix-regression-multiple-values-for-keyword-argument-.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/64554
Patch73:        mark-salt-3006-as-released-586.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/64599
Patch74:        prevent-possible-exceptions-on-salt.utils.user.get_g.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/592
Patch75:        fix-tests-to-make-them-running-with-salt-testsuite.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/commit/f82860b8ad3ee786762fa02fa1a6eaf6e24dc8d4
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/65020
Patch76:        do-not-fail-on-bad-message-pack-message-bsc-1213441-.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/64510 (dropped at patch 91)
Patch77:        make-sure-configured-user-is-properly-set-by-salt-bs.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/64959
Patch78:        fixed-gitfs-cachedir_basename-to-avoid-hash-collisio.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/600
Patch79:        revert-usage-of-long-running-req-channel-bsc-1213960.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/65238
Patch80:        write-salt-version-before-building-when-using-with-s.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/65036
Patch81:        fix-calculation-of-sls-context-vars-when-trailing-do.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/594
Patch82:        implement-the-calling-for-batch-async-from-the-salt-.patch
# PATCH-FIX_UPSTREAM: https://github.com/tornadoweb/tornado/pull/2277
Patch83:        only-call-native_str-on-curl_debug-message-in-tornad.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/65204
Patch84:        use-salt-call-from-salt-bundle-with-transactional_up.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/65181
Patch85:        improve-salt.utils.json.find_json-bsc-1213293.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/65266
Patch86:        fix-optimization_order-opt-to-prevent-test-fails.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/65232
Patch87:        allow-all-primitive-grain-types-for-autosign_grains-.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/65482
Patch88:        fix-cve-2023-34049-bsc-1215157.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/65017
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/65136
Patch89:        fix-gitfs-__env__-and-improve-cache-cleaning-bsc-119.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/65435
Patch90:        dereference-symlinks-to-set-proper-__cli-opt-bsc-121.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/614 (revert patch 77)
Patch91:        revert-make-sure-configured-user-is-properly-set-by-.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/65488
Patch92:        enable-keepalive-probes-for-salt-ssh-executions-bsc-.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/65644
Patch93:        prefer-unittest.mock-for-python-versions-that-are-su.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/620
Patch94:        fix-the-aptpkg.py-unit-test-failure.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/65092
Patch95:        update-__pillar__-during-pillar_refresh.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/65969
Patch96:        fix-cve-2024-22231-and-cve-2024-22232-bsc-1219430-bs.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/65009
Patch97:        fixed-keyerror-in-logs-when-running-a-state-that-fai.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/65562
Patch98:        improve-pip-target-override-condition-with-venv_pip_.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/65819
Patch99:        allow-kwargs-for-fileserver-roots-update-bsc-1218482.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/66048
Patch100:       discover-both-.yml-and-.yaml-playbooks-bsc-1211888.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/66130
Patch101:       fix-problematic-tests-and-allow-smooth-tests-executi.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/628
Patch102:       make-importing-seco.range-thread-safe-bsc-1211649.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/66130
Patch103:       fix-tests-failures-and-errors-when-detected-on-vm-ex.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/66234 (modified at Patch106)
Patch104:       decode-oscap-byte-stream-to-string-bsc-1219001.patch
### Commits to make Salt compatible with Python 3.11 (and 3.6)
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/commit/d92b5423464f93da6e3feb47d05a9acef8da75f9
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/commit/60b36489225f958772b6a2f99d8fe6ae33ee9d73
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/commit/eee0eca5e48922e5e404f812ced08ca7484bb568
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/commit/991f7cf0a7baf08a31194ce52f4ec08290db8e52
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/commit/2688c86f45eea9f8a6b916fcdf8eb94b3f5e185b
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/commit/a1873a1d6d50d1769ddef528d7442e38aba9de23
# PATCH-FIX_OPENSUSE https://github.com/openSUSE/salt/commit/c7ecccb0a080ca9cca097f760ef0992ab34f82df
Patch105:       fix-salt-warnings-and-testuite-for-python-3.11-635.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/639
Patch106:       switch-oscap-encoding-to-utf-8-639.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/65982
Patch107:       remove-unused-import-causing-delays-on-starting-salt.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/66024
Patch108:       make-logging-calls-lighter.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/66034
Patch109:       improve-broken-events-catching-and-reporting.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/633
Patch110:       make-salt-master-self-recoverable-on-killing-eventpu.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/66158
Patch111:       make-reactor-engine-less-blocking-the-eventpublisher.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/638
Patch112:       prevent-possible-exception-in-tornado.concurrent.fut.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/66455
Patch113:       remove-redundant-_file_find-call-to-the-master.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/646
Patch114:       skip-tests-for-unsupported-algorithm-on-old-openssl-.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/652
Patch115:       add-missing-contextvars-dependency-in-salt.version.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/640
Patch116:       prevent-oom-with-high-amount-of-batch-async-calls-bs.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/65983
Patch117:       do-not-call-the-async-wrapper-calls-with-the-separat.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/66494
Patch118:       speed-up-salt.matcher.confirm_top-by-using-__context.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/66593
Patch119:       several-fixes-for-tests-to-avoid-errors-and-failures.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/656
Patch120:       provide-systemd-timer-unit.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/66630
Patch121:       skip-certain-tests-if-necessary-and-mark-some-flaky-.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/66647
Patch122:       fix-status.diskusage-and-exclude-some-tests-to-run-w.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/65077
Patch123:       fix-user.list_groups-omits-remote-groups.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/66695
Patch124:       some-more-small-tests-fixes-enhancements-661.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/666
Patch125:       test_vultrpy-adjust-test-expectation-to-prevent-fail.patch
# PATCH-FIX_UPSTREAM https://github.com/saltstack/salt/pull/66698
Patch126:       firewalld-normalize-new-rich-rules-before-comparing-.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/669
Patch127:       skip-more-tests-related-to-old-openssl-algorithms.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/662
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/66730
Patch128:       make-tests-compatible-with-venv-bundle.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/66743
Patch129:       replace-use-of-pygit2-deprecated-and-removed-1.15.0-.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/671
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/64173
Patch130:       join-masters-if-it-is-a-list-671.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/66509
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/commit/0c3ebc0795f9c2adec90118281343cae3070e0f6
Patch131:       remove-redundant-run_func-from-salt.master.mworker._.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/66818
Patch132:       improve-error-handling-with-different-openssl-versio.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/66856
Patch133:       avoid-crash-on-wrong-output-of-systemctl-version-bsc.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/66861
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/675
Patch134:       fix-test_system-flaky-setup_teardown-fn.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/676
Patch135:       fix-test_debian-to-work-in-our-infrastructure-676.patch
# PATCH-FIX_OPENSUSE: https://github.com/openSUSE/salt/pull/677
Patch136:       fix-deprecated-code-677.patch
# PATCH-FIX_UPSTREAM: https://github.com/saltstack/salt/pull/66780
Patch137:       fix-the-selinux-context-for-salt-minion-service-bsc-.patch

### IMPORTANT: The line below is used as a snippet marker. Do not touch it.
### SALT PATCHES LIST END

BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  binutils
BuildRequires:  fdupes
BuildRequires:  logrotate
BuildRequires:  saltbundlepy-rpm-macros
BuildRequires:  saltbundlepy-setuptools
BuildRequires:  saltbundlepy-venvjail
# --- [venvjail - BuildRequires] START ---
BuildRequires:  saltbundle-libsodium
BuildRequires:  saltbundle-libzmq
BuildRequires:  saltbundle-libffi8

BuildRequires:  saltbundlepy-base
BuildRequires:  saltbundlepy-dateutil
BuildRequires:  saltbundlepy-distro
BuildRequires:  saltbundlepy-looseversion
BuildRequires:  saltbundlepy-jinja2
BuildRequires:  saltbundlepy-m2crypto
BuildRequires:  saltbundlepy-markupsafe
BuildRequires:  saltbundlepy-msgpack > 0.3
BuildRequires:  saltbundlepy-packaging
BuildRequires:  saltbundlepy-pyzmq >= 2.2.0

BuildRequires:  saltbundlepy-psutil
BuildRequires:  saltbundlepy-pyyaml
BuildRequires:  saltbundlepy-requests >= 1.0.0

BuildRequires:  saltbundlepy-netaddr
BuildRequires:  saltbundlepy-pyinotify

BuildRequires:  saltbundlepy-pycurl
BuildRequires:  saltbundlepy-tornado
BuildRequires:  saltbundlepy-jmespath

BuildRequires:  saltbundlepy-passlib

# Include python devel to the bundle
BuildRequires:  saltbundlepy-devel

%if 0%{?suse_version} || 0%{?fedora} || 0%{?rhel} || 0%{?openeuler_version}
BuildRequires:  saltbundlepy-rpm-vercmp
%endif

%if 0%{?fedora} || 0%{?rhel} || 0%{?openeuler_version}
%if 0%{?fedora} >= 22 || 0%{?rhel} >= 8 || 0%{?openeuler_version} >= 2203
%if 0%{?rhel} >= 8
BuildRequires:  platform-python
%else
%if 0%{?fedora} < 35
BuildRequires:  python3
%endif
%endif
%else
BuildRequires:  python
%endif
%endif

# SELinux dependencies
%if 0%{?fedora} >= 22 || 0%{?rhel} >= 7 || 0%{?openeuler_version} >= 2203
Requires(post): policycoreutils
%endif

%if 0%{?debian} || 0%{?raspbian} || 0%{?ubuntu}
BuildRequires:  saltbundlepy-apt
%endif

# --- [venvjail - BuildRequires] END ---
# --- [venvjail - Requires] START ---
# --- [venvjail - Requires] END ---

%if 0%{?suse_version}
# required for zypper.py
%if 0%{?suse_version} != 1110
Requires(pre):  libzypp(plugin:system) >= 0
%endif
BuildRequires:  saltbundlepy-zypp-plugin
# required for virtualisation hosts (libvirt)
%if 0%{?suse_version} != 1110
BuildRequires:  saltbundlepy-libvirt
%endif
%endif
%if 0%{?suse_version} != 1110
BuildRequires:  saltbundlepy-docker
%endif
BuildRequires:  saltbundlepy-pip

%if "%_vendor" == "debbuild"
BuildRequires:  debbuild-macros
Requires:       gnupg
%endif
Requires:       logrotate
%if 0%{?suse_version} != 1110
Requires:       systemd
%endif

%if "%_vendor" == "debbuild"
AutoReqProv:    0
%else
AutoProv:       0

Provides:       config(%{name}) = %{version}-%{release}

# Use custom filter to prevent wrong requires
%define _use_internal_dependency_generator 0
%define __find_requires sh %{SOURCE101}
%endif

%description
Virtual environment jail for Salt minion.
Salt minion is queried and controlled from the master.
Listens to the salt master and execute the commands.

%if %{with salt_bundle_testsuite}
%package testsuite
Summary:        The the testsuite for the venvjailed client component of Salt
Requires:       venv-salt-minion = %{version}-%{release}
BuildRequires:  saltbundlepy-pytest >= 7.2.0
BuildRequires:  saltbundlepy-pytest-shell-utilities
BuildRequires:  saltbundlepy-pytest-skip-markers
BuildRequires:  saltbundlepy-pytest-subtests
BuildRequires:  saltbundlepy-pytest-httpserver
BuildRequires:  saltbundlepy-typing-extensions
BuildRequires:  saltbundlepy-mock
BuildRequires:  saltbundlepy-pytest-salt-factories
BuildRequires:  saltbundlepy-cherrypy
BuildRequires:  saltbundlepy-salt-test
BuildRequires:  saltbundlepy-yamllint
# update-alternatives is part of dpkg
%if "%_vendor" != "debbuild"
Requires(post):    /usr/sbin/update-alternatives
Requires(postun):  /usr/sbin/update-alternatives
%endif

%description testsuite
The testsuite for running inside virtual environment jail of Salt minion.
%endif

%prep
%autosetup -n salt-%{version}-suse -p1

cp %{S:10} %{S:11} %{S:12} .

%if 0%{?suse_version} == 1110
# Include ssl/crypto related files to the bundle for SLE11
echo "saltbundle-libopenssl1_0_0.rpm\$" >> include-rpm
# Filter out ssl/crypto related libraries from the dependencies
# as these libraries should be included to the bundle for SLE11
sed -i -r 's# /libzmq.so/d;# /libzmq.so/d; /libcrypto.so/d; /libssl.so/d;#' %{S:101}
%endif

# Expand SELinux policy files
tar zxvf %{S:200}

%build
%global python_ver_short python%(%{__saltbundlepy} -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
%if 0%{?fedora} || 0%{?rhel} || 0%{?openeuler_version}
export PATH=/usr/bin:$PATH
%endif
%{__saltbundlepy} setup.py --with-salt-version=%{version} --salt-transport=both build

%install
venvjail create %{venv} \
%if "%_vendor" == "debbuild"
  -i include-deb \
  -e exclude-deb \
%endif
  --python-version %{saltbundlepy_version} \
  --relocate %{salt_venv} \
  --version %{version} \
  --track ../../OTHER/%{name}-%{_arch}-%{version}-%{release}.noarch.rpm.packages

mkdir -p %{buildroot}%{salt_venv}
mv %{venv} %{buildroot}%{salt_venv}

# Install salt right into virtual environment
%{__saltbundlepy} setup.py --salt-transport=both \
    --salt-config-dir=%{_sysconfdir}/%{venv} \
    --salt-cache-dir=%{_localstatedir}/cache/%{venv} \
    --salt-logs-dir=%{_localstatedir}/log \
    install --prefix=%{_prefix} --root=%{buildroot}%{salt_venv}%{venv} --no-compile

%if %{with salt_bundle_testsuite}
# Install Salt tests
install -Dd %{buildroot}%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/salt-testsuite
cp -a tests %{buildroot}%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/salt-testsuite/
# Remove runtests.py which is not used as deprecated method of running the tests
rm %{buildroot}%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/salt-testsuite/tests/runtests.py
# Copy conf files to the testsuite as they are used by the tests
cp -a conf %{buildroot}%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/salt-testsuite/
%endif

# Remove packages.log
rm -f %{buildroot}%{salt_venv}%{venv}/packages.log

# Remove not used activate scripts
rm -f %{buildroot}%{salt_venv}%{venv}/bin/Activate.ps1 \
      %{buildroot}%{salt_venv}%{venv}/bin/activate.csh \
      %{buildroot}%{salt_venv}%{venv}/bin/activate.fish

# Fix links for python interpreter files
sed -i '4 i export VENV_PIP_TARGET="${VENV_PIP_TARGET:-/var/lib/venv-salt-minion/local}"' "%{buildroot}%{salt_venv}%{venv}/bin/python"
sed -i '8 i export PYTHONSTARTUP="$VIRTUAL_ENV/bin/venv-startup"' "%{buildroot}%{salt_venv}%{venv}/bin/python"
sed -i '9 i export PYTHONPATH="$VENV_PIP_TARGET"' "%{buildroot}%{salt_venv}%{venv}/bin/python"
sed -i '10 i export SALT_CONFIG_DIR="%{_sysconfdir}/%{venv}"' "%{buildroot}%{salt_venv}%{venv}/bin/python"
sed -i '11 i export CPATH="${CPATH:-%{salt_venv}%{venv}/usr/include/%{python_ver_short}}"' "%{buildroot}%{salt_venv}%{venv}/bin/python"
sed -i 's=^exec %{salt_venv}%{venv}/bin/python.original =exec "$VIRTUAL_ENV/bin/python.original" =' "%{buildroot}%{salt_venv}%{venv}/bin/python"
rm -f %{buildroot}%{salt_venv}%{venv}/bin/python3 \
      %{buildroot}%{salt_venv}%{venv}/bin/python%{saltbundlepy_version} \
      %{buildroot}%{salt_venv}%{venv}/bin/python3.original \
      %{buildroot}%{salt_venv}%{venv}/bin/python%{saltbundlepy_version}.original
ln -s python %{buildroot}%{salt_venv}%{venv}/bin/python3
ln -s python %{buildroot}%{salt_venv}%{venv}/bin/python%{saltbundlepy_version}
ln -s python.original %{buildroot}%{salt_venv}%{venv}/bin/python3.original
ln -s python.original %{buildroot}%{salt_venv}%{venv}/bin/python%{saltbundlepy_version}.original

# Fix salt scripts
find %{buildroot}%{salt_venv}%{venv}/bin/ -type f -name 'salt*' ! -name 'salt-factories*' ! -name 'salt-test*' -delete
for script in build/scripts-*/salt-minion build/scripts-*/salt-call \
              build/scripts-*/salt-support build/scripts-*/spm; do
  SCRIPT_NAME=$(basename $script)
  install -m 0755 $script %{buildroot}%{salt_venv}%{venv}/bin
  sed -i '1s=^#!/usr/bin/\(python\|env python\)[0-9.]*=#!%{salt_venv}%{venv}/bin/python=' %{buildroot}%{salt_venv}%{venv}/bin/$SCRIPT_NAME
done

# Fix salt scripts to bindir with venv- prefix
install -Dd -m 0755 %{buildroot}%{_bindir}
find "%{buildroot}%{salt_venv}%{venv}/bin/" -type f -name 'salt-*'  ! -name 'salt-factories*' ! -name 'salt-test*' | while read _FILE; do
  FILE_NAME=$(basename "${_FILE}")
  ln -s "%{salt_venv}%{venv}/bin/${FILE_NAME}" "%{buildroot}%{_bindir}/venv-${FILE_NAME}"
done

# Remove some of the files
rm -rf %{buildroot}%{salt_venv}%{venv}/usr/share/man
find %{buildroot}%{salt_venv}%{venv}%{saltbundlepy_sitelib}/salt/cloud/deploy/ -name '*.sh' -delete

# Copy venv executor in place
cp %{S:13} %{buildroot}%{salt_venv}%{venv}/lib/python%{saltbundlepy_version}/site-packages/salt/executors/venv.py

# Copy venv-exec wrapper script
cp %{S:14} %{buildroot}%{salt_venv}%{venv}/bin/venv-startup

%if 0%{?suse_version} != 1110
# Create systemd service file: venv-salt-minion.service
%if 0%{?suse_version}
install -Dpm 0644 pkg/old/suse/salt-minion.service %{buildroot}%{_unitdir}/venv-salt-minion.service
%else
install -Dpm 0644 pkg/old/suse/salt-minion.service.rhel7 %{buildroot}%{_unitdir}/venv-salt-minion.service
%endif
install -Dpm 0644 pkg/common/venv-salt-minion-postinstall.service %{buildroot}%{_unitdir}/venv-salt-minion-postinstall.service
install -Dpm 0644 pkg/common/venv-salt-minion-postinstall.timer %{buildroot}%{_unitdir}/venv-salt-minion-postinstall.timer
sed -i 's/^After=.*/After=network.target/; s/^Description=.*/Description=The venvjailed Salt Minion/; s#^ExecStart=.*#ExecStart=%{salt_venv}%{venv}/bin/salt-minion#' \
    %{buildroot}%{_unitdir}/venv-salt-minion.service

sed -i -r 's|VENV_LOCATION_PLACEHOLDER|%{salt_venv}%{venv}|g' %{S:20}
install -Dm 0755 %{S:20} "%{buildroot}%{salt_venv}%{venv}/bin/post_start_cleanup.sh"

install -Dd -m 0755 %{buildroot}%{_sbindir}
ln -s service %{buildroot}%{_sbindir}/rcvenv-salt-minion
%else
# For SLE11
install -Dpm 0755 %{S:15} %{buildroot}%{_initddir}/venv-salt-minion
install -Dd -m 0755 %{buildroot}%{_sbindir}
ln -s %{_initddir}/venv-salt-minion %{buildroot}%{_sbindir}/rcvenv-salt-minion
%endif

install -Dd -m 0750 %{buildroot}%{_sysconfdir}/%{venv}/minion.d
install -Dd -m 0750 %{buildroot}%{_sysconfdir}/%{venv}/pki/minion

install -Dpm 0640 conf/minion %{buildroot}%{_sysconfdir}/%{venv}/minion
touch -m 0640 -r conf/minion  %{buildroot}%{_sysconfdir}/%{venv}/minion_id # ghost file

# Create default minion config file: 00-venv.conf
cat <<EOF > "%{buildroot}%{_sysconfdir}/%{venv}/minion.d/00-venv.conf"
pki_dir: %{_sysconfdir}/%{venv}/pki/minion
%if 0%{?suse_version} == 1110
pidfile: /var/run/%{venv}.pid
sock_dir: /var/run/%{venv}
%else
pidfile: /run/%{venv}.pid
sock_dir: /run/%{venv}
%endif
log_file: /var/log/%{venv}.log
cachedir: /var/cache/%{venv}
module_executors: [venv]

server_id_use_crc: adler32
enable_legacy_startup_events: False
enable_fqdns_grains: False
start_event_grains: [machine_id, saltboot_initrd, susemanager]
EOF

mkdir -p "%{buildroot}%{_sysconfdir}/logrotate.d"
cat <<EOF > "%{buildroot}%{_sysconfdir}/logrotate.d/venv-salt-minion"
/var/log/%{venv}.log {
    weekly
    missingok
    rotate 7
    compress
    notifempty
}
EOF

%if 0%{?suse_version} != 1110
mkdir -p "%{buildroot}/usr/lib/tmpfiles.d"
cat <<EOF > "%{buildroot}/usr/lib/tmpfiles.d/venv-salt-minion.conf"
# Type Path                         Mode UID  GID     Age Argument
d      /run/venv-salt-minion        0750 root root

EOF
%endif

mkdir -p "%{buildroot}/var/cache/%{venv}"

rm -rf "%{buildroot}%{salt_venv}%{venv}/etc" "%{buildroot}%{salt_venv}%{venv}/var" \
       "%{buildroot}%{salt_venv}%{venv}/srv" "%{buildroot}%{salt_venv}%{venv}/usr/share"

find "%{buildroot}%{salt_venv}%{venv}/lib/" -type d -name 'test*' | grep -v salt-testsuite | while read _DIR; do
  rm -rf "${_DIR}"
done

# Remove build IDs
rm -rf "%{buildroot}%{salt_venv}%{venv}/lib/.build-id"

# Recompile python sources
find %{buildroot}%{salt_venv}%{venv} -name '*.pyc' -delete
%{__saltbundlepy} -m compileall -d %{salt_venv}%{venv} %{buildroot}%{salt_venv}%{venv}
%{__saltbundlepy} -O -m compileall -d %{salt_venv}%{venv} %{buildroot}%{salt_venv}%{venv}

## Install Zypper plugins only on SUSE machines
%if 0%{?suse_version}
install -Dd -m 0750 %{buildroot}%{_prefix}/lib/zypp/plugins/commit
%{__install} scripts/suse/zypper/plugins/commit/zyppnotify %{buildroot}%{_prefix}/lib/zypp/plugins/commit/venv-zyppnotify
sed -i '1s=^#!/usr/bin/\(python\|env python\)[0-9.]*=#!%{salt_venv}%{venv}/bin/python=' %{buildroot}%{_prefix}/lib/zypp/plugins/commit/venv-zyppnotify
sed -i \
%if 0%{?suse_version} == 1110
    -r \
%else
    -E \
%endif
    's#self.ck_path = ".*#self.ck_path = "/var/cache/%{venv}/rpmdb.cookie"#' \
    %{buildroot}%{_prefix}/lib/zypp/plugins/commit/venv-zyppnotify
%endif

# Install DNF plugins only on RH machines
%if 0%{?fedora} || 0%{?rhel} || 0%{?openeuler_version}
%if 0%{?fedora} >= 22 || 0%{?rhel} >= 8 || 0%{?openeuler_version} >= 2203
%if 0%{?fedora} >= 33
%if 0%{?fedora} < 35
%define __platform_python python3
%else
%define __platform_python %{__saltbundlepy}
%define python3_sitelib %{saltbundlepy_sitelib}
%endif
%else
%if 0%{?rhel} >= 8
%define __platform_python /usr/libexec/platform-python
%else
%define __platform_python python3
%endif
%endif
%define python3_sitelib %(%{__platform_python} -c "import sysconfig as s; print(s.get_paths().get('purelib'))")
install -Dd %{buildroot}%{python3_sitelib}/dnf-plugins
install -Dd %{buildroot}%{_sysconfdir}/dnf/plugins
%{__install} scripts/suse/dnf/plugins/dnfnotify.py %{buildroot}%{python3_sitelib}/dnf-plugins/venv-dnfnotify.py
sed -i -E 's#self\.cookie_file = ".*#self.cookie_file = "/var/cache/%{venv}/rpmdb.cookie"#' \
          %{buildroot}%{python3_sitelib}/dnf-plugins/venv-dnfnotify.py
%{__platform_python} -m compileall -d %{python3_sitelib}/dnf-plugins %{buildroot}%{python3_sitelib}/dnf-plugins
%{__platform_python} -O -m compileall -d %{python3_sitelib}/dnf-plugins %{buildroot}%{python3_sitelib}/dnf-plugins
%fdupes %{buildroot}%{python3_sitelib}/dnf-plugins
%{__install} scripts/suse/dnf/plugins/dnfnotify.conf %{buildroot}%{_sysconfdir}/dnf/plugins/venv-dnfnotify.conf
%else
install -Dd %{buildroot}%{_prefix}/share/yum-plugins
install -Dd %{buildroot}%{_sysconfdir}/yum/pluginconf.d
%{__install} -m 0644 scripts/suse/yum/plugins/yumnotify.py %{buildroot}%{_prefix}/share/yum-plugins/venv-yumnotify.py
sed -i -E 's#CK_PATH = ".*#CK_PATH = "/var/cache/%{venv}/rpmdb.cookie"#' \
          %{buildroot}%{_prefix}/share/yum-plugins/venv-yumnotify.py
python -m compileall -d %{_prefix}/share/yum-plugins %{buildroot}%{_prefix}/share/yum-plugins
python -O -m compileall -d %{_prefix}/share/yum-plugins %{buildroot}%{_prefix}/share/yum-plugins
%fdupes %{buildroot}%{_prefix}/share/yum-plugins
%{__install} -m 0644 scripts/suse/yum/plugins/yumnotify.conf %{buildroot}%{_sysconfdir}/yum/pluginconf.d/venv-yumnotify.conf
%endif
%endif

# Install DPkg plugins only on Debian machines
%if "%_vendor" == "debbuild"
install -Dd %{buildroot}%{_sysconfdir}/apt/apt.conf.d
%{__install} scripts/suse/dpkg/99dpkgnotify %{buildroot}%{_sysconfdir}/apt/apt.conf.d/99dpkgnotify-venv
%{__install} scripts/suse/dpkg/dpkgnotify %{buildroot}%{_bindir}/venv-dpkgnotify
sed -i -E 's#/usr/bin/dpkgnotify#%{_bindir}/venv-dpkgnotify#g' \
          %{buildroot}%{_sysconfdir}/apt/apt.conf.d/99dpkgnotify-venv
sed -i -E 's#CK_PATH = ".*#CK_PATH = "%{_localstatedir}/cache/%{venv}/dpkg.cookie"#' \
          %{buildroot}%{_bindir}/venv-dpkgnotify
sed -i '1s=^#!/usr/bin/\(python\|env python\)[0-9.]*=#!%{salt_venv}%{venv}/bin/python=' %{buildroot}%{_bindir}/venv-dpkgnotify
%endif

# Install SELinux profile
install -Dd -m 0755 %{buildroot}%{salt_venv}%{venv}/selinux
%{__install} -m 0644 venv-salt-minion-selinux/venv-salt-minion.pp %{buildroot}%{salt_venv}%{venv}/selinux/venv-salt-minion.pp

%fdupes %{buildroot}%{salt_venv}%{venv}

# Strip debuginfo
strip %{buildroot}%{salt_venv}%{venv}/bin/python.original
find "%{buildroot}%{salt_venv}%{venv}" -type f -name '*.so*' | while read _FILE; do
  strip $_FILE
done

%pre
%if 0%{?suse_version} && 0%{?suse_version} != 1110
%service_add_pre venv-salt-minion.service
%service_add_pre venv-salt-minion-postinstall.service
%service_add_pre venv-salt-minion-postinstall.timer
%endif

# Remove prev env if present before installing this env
if [ -f %{salt_venv}%{venv}/bin/post_start_cleanup.sh ]; then
  %{salt_venv}%{venv}/bin/post_start_cleanup.sh || :
fi

%if "%_vendor" == "debbuild"
if [ "$1" == "upgrade" ] && [ ! -d "%{salt_venv}%{venv}/lib/%{python_ver_short}" ]; then
%else
if [ $1 -gt 1 ] && [ ! -d "%{salt_venv}%{venv}/lib/%{python_ver_short}" ]; then
%endif
  # Upgrading python version; save the previous environment
  prev_python_ver_short="$(find %{salt_venv}%{venv}/lib/python* -maxdepth 0 -type d | xargs basename || :)"
  rm -rf %{salt_venv}%{venv}/lib/prev_env
  if [ ! -z "$prev_python_ver_short" ]; then 
    cp -r "%{salt_venv}%{venv}/lib/$prev_python_ver_short" "%{salt_venv}%{venv}/lib/prev_env"
    echo $prev_python_ver_short > "%{salt_venv}%{venv}/lib/prev_env/prev_python_ver_short"
  fi
fi

%post
if test -f %{salt_venv}%{venv}/selinux/venv-salt-minion.pp ; then
  if which semodule > /dev/null 2>&1 ; then
    semodule -n -i %{salt_venv}%{venv}/selinux/venv-salt-minion.pp 2> /dev/null || :
    if /usr/sbin/selinuxenabled ; then
      /usr/sbin/load_policy
      restorecon -R %{salt_venv}%{venv}/bin || :
    fi;
  fi;
fi;
if [ -f "%{salt_venv}%{venv}/lib/prev_env/prev_python_ver_short" ]; then
  prev_python_ver_short="$(cat %{salt_venv}%{venv}/lib/prev_env/prev_python_ver_short)"
  sed -i "s/PLACEHOLDER/$prev_python_ver_short/g" %{salt_venv}%{venv}/bin/post_start_cleanup.sh
fi

%if 0%{?suse_version} != 1110
%if 0%{?suse_version}
%service_add_post venv-salt-minion.service
%service_add_post venv-salt-minion-postinstall.service
%service_add_post venv-salt-minion-postinstall.timer
%else
%systemd_post venv-salt-minion.service
%systemd_post venv-salt-minion-postinstall.service
%systemd_post venv-salt-minion-postinstall.timer
%endif
%endif

%posttrans
if [ -f "%{salt_venv}%{venv}/lib/prev_env/prev_python_ver_short" ]; then
  # Linking previous env
  prev_python_ver_short="$(cat %{salt_venv}%{venv}/lib/prev_env/prev_python_ver_short)"
  if [ -d "%{salt_venv}%{venv}/lib/$prev_python_ver_short" ]; then
    # Dangling files from the previous env; remove it before creating symlink
    rm -r "%{salt_venv}%{venv}/lib/$prev_python_ver_short"
  fi
  if [ -L "/usr/lib/venv-salt-minion/lib/$prev_python_ver_short" ]; then
    # Dangling symlink from previous env
    unlink "/usr/lib/venv-salt-minion/lib/$prev_python_ver_short" || :
  fi
  ln -s "prev_env" "%{salt_venv}%{venv}/lib/$prev_python_ver_short"
  # Start timer to remove previous env 
  systemctl restart venv-salt-minion-postinstall.timer || :
fi;

%if %{with salt_bundle_testsuite}
%post testsuite
# FIXME: check if it's possible use macro for path
# TODO: use macro for priority (should be same as version_nodot)
update-alternatives --install /usr/bin/salt-test salt-test /usr/lib/venv-salt-minion/bin/salt-test 311
%endif

%preun
%if 0%{?suse_version} != 1110
%if 0%{?suse_version}
%service_del_preun venv-salt-minion.service
%service_del_preun venv-salt-minion-postinstall.service
%service_del_preun venv-salt-minion-postinstall.timer
%else
%systemd_preun venv-salt-minion.service
%systemd_preun venv-salt-minion-postinstall.service
%systemd_preun venv-salt-minion-postinstall.timer
%endif
%endif
# Remove possibly dangling prev_env files
%if "%_vendor" == "debbuild"
if [ "$1" = "remove" ] || [ "$1" = "purge" ]; then
%else
if [ $1 -eq 0 ]; then
%endif
  %{salt_venv}%{venv}/bin/post_start_cleanup.sh || :
fi


%postun
%if 0%{?suse_version} != 1110
%if 0%{?suse_version}
%service_del_postun venv-salt-minion.service
%service_del_postun venv-salt-minion-postinstall.service
%service_del_postun venv-salt-minion-postinstall.timer
%else
%systemd_postun_with_restart venv-salt-minion.service
%systemd_postun venv-salt-minion-postinstall.service
%systemd_postun_with_restart venv-salt-minion-postinstall.timer
%endif
%endif

%if "%_vendor" == "debbuild"
if [ "$1" = "remove" ] || [ "$1" = "purge" ]; then
%else
if [ $1 -eq 0 ]; then
%endif
  if which semodule > /dev/null 2>&1 ; then
    semodule -n -r venv-salt-minion 2> /dev/null || :
    if /usr/sbin/selinuxenabled ; then
      /usr/sbin/load_policy
    fi;
  fi;
fi;

%if %{with salt_bundle_testsuite}
%postun testsuite
update-alternatives --remove salt-test /usr/lib/venv-salt-minion/bin/salt-test
%endif

%files
%defattr(-,root,root)
%{salt_venv}%{venv}
%ghost %{salt_venv}%{venv}/lib/prev_env
%if %{with salt_bundle_testsuite}
# Exclude testsuite files
%exclude %{salt_venv}%{venv}/bin/pytest*
%exclude %{salt_venv}%{venv}/bin/py.test*
%exclude %{salt_venv}%{venv}/bin/salt-factories*
%exclude %{salt_venv}%{venv}/bin/salt-test*
%exclude %{salt_venv}%{venv}/bin/cherryd*
%exclude %{salt_venv}%{venv}/bin/yamllint*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/salt-testsuite
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/pytest*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/_pytest*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/__pycache__/pytest*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/py.py
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/__pycache__/py.cpython*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/attr*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/exceptiongroup*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/iniconfig*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/pluggy*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/tomli*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/typing_extensions*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/__pycache__/typing_extensions.cpython*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/mock*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/saltfactories*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/CherryPy*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/cherrypy*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/more_itertools*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/zc*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/cheroot*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/portend*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/__pycache__/portend*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/tempora*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/werkzeug*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/Werkzeug*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/salt_test*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/pathspec*
%exclude %{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/yamllint*
%endif
%{_bindir}/venv-salt-*
%{_sbindir}/rcvenv-salt-minion
%dir               %attr(0750, root, root) %{_sysconfdir}/%{venv}
%dir               %attr(0750, root, root) %{_sysconfdir}/%{venv}/pki
%config(noreplace) %attr(0640, root, root) %{_sysconfdir}/%{venv}/minion
%config(noreplace) %attr(0640, root, root) %ghost %{_sysconfdir}/%{venv}/minion_id
%dir               %attr(0750, root, root) %{_sysconfdir}/%{venv}/minion.d/
%config            %attr(0640, root, root) %{_sysconfdir}/%{venv}/minion.d/00-venv.conf
%dir               %attr(0750, root, root) %{_sysconfdir}/%{venv}/pki/minion/
%dir               %attr(0750, root, root) %{_localstatedir}/cache/%{venv}/

# Install plugin only on SUSE machines
%if 0%{?suse_version}
%if 0%{?suse_version} == 1110
%dir %{_prefix}/lib/zypp
%dir %{_prefix}/lib/zypp/plugins
%dir %{_prefix}/lib/zypp/plugins/commit
%endif
%{_prefix}/lib/zypp/plugins/commit/venv-zyppnotify
%endif

# Install DNF plugins only on RH machines
%if 0%{?fedora} || 0%{?rhel} || 0%{?openeuler_version}
%if 0%{?fedora} >= 22 || 0%{?rhel} >= 8 || 0%{?openeuler_version} >= 2203
%{python3_sitelib}/dnf-plugins/venv-dnfnotify.py
%{python3_sitelib}/dnf-plugins/__pycache__/venv-dnfnotify.*
%{_sysconfdir}/dnf/plugins/venv-dnfnotify.conf
%else
%{_prefix}/share/yum-plugins/venv-yumnotify.*
%{_sysconfdir}/yum/pluginconf.d/venv-yumnotify.conf
%endif
%endif

# Install DPkg plugins only on Debian machines
%if "%_vendor" == "debbuild"
%{_sysconfdir}/apt/apt.conf.d/99dpkgnotify-venv
/usr/bin/venv-dpkgnotify
%endif

%if 0%{?suse_version} == 1110
%{_initddir}/venv-salt-minion
%else
%{_unitdir}/venv-salt-minion.service
%{_unitdir}/venv-salt-minion-postinstall.service
%{_unitdir}/venv-salt-minion-postinstall.timer
%endif

%config(noreplace) %{_sysconfdir}/logrotate.d/venv-salt-minion
%if 0%{?suse_version} != 1110
%{_prefix}/lib/tmpfiles.d/venv-salt-minion.conf
%endif

%if %{with salt_bundle_testsuite}
%files testsuite
%ghost %{_sysconfdir}/alternatives/salt-test
%{salt_venv}%{venv}/bin/pytest*
%{salt_venv}%{venv}/bin/py.test*
%{salt_venv}%{venv}/bin/salt-factories*
%{salt_venv}%{venv}/bin/salt-test*
%{salt_venv}%{venv}/bin/yamllint*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/salt-testsuite
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/pytest*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/_pytest*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/__pycache__/pytest*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/py.py
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/__pycache__/py.cpython*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/attr*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/exceptiongroup*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/iniconfig*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/pluggy*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/tomli*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/typing_extensions*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/__pycache__/typing_extensions.cpython*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/mock*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/saltfactories*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/CherryPy*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/cherrypy*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/more_itertools*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/zc*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/cheroot*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/portend*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/__pycache__/portend*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/tempora*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/werkzeug*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/Werkzeug*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/salt_test*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/pathspec*
%{salt_venv}%{venv}/lib/%{python_ver_short}/site-packages/yamllint*
%endif

%changelog
openSUSE Build Service is sponsored by