Skip to content

Commit

Permalink
suma_minion: prevent issues when calling Salt runners (bsc#1228232)
Browse files Browse the repository at this point in the history
Do not store connection object inside the Salt __context__ when
execution is driven by a Salt runner, as it can cause issues as the
object cannot be pickled and it causes crashes when having multiple
ext_pillar modules enabled

Failed to load ext_pillar git: can't pickle psycopg2.extensions.connection objects
  • Loading branch information
meaksh committed Oct 2, 2024
1 parent 0cee34c commit 95d2ff4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
17 changes: 10 additions & 7 deletions susemanager-utils/susemanager-sls/modules/pillar/suma_minion.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ def __virtual__():
return HAS_POSTGRES


def _is_salt_ssh(opts):
"""Check if this pillar is computed for Salt SSH.
def _is_salt_ssh_or_runner(opts):
"""Check if this pillar is computed for Salt SSH or Salt Runner execution
Only in salt/client/ssh/__init__.py, the master_opts are moved into
opts[__master_opts__], which we use to detect Salt SSH usage.
During a Salt Runner execution, the "_master" suffix is appended to the
master_minion id.
"""
return "__master_opts__" in opts
return "__master_opts__" in opts or opts.get("id").endswith("_master")


def _get_cursor(func):
Expand Down Expand Up @@ -105,7 +108,7 @@ def _connect_db():
cnx = _connect_db()
log.debug("Connected to the DB")
# pylint: disable-next=undefined-variable
if not _is_salt_ssh(__opts__):
if not _is_salt_ssh_or_runner(__opts__):
# pylint: disable-next=undefined-variable
__context__["suma_minion_cnx"] = cnx
except psycopg2.OperationalError as err:
Expand All @@ -119,7 +122,7 @@ def _connect_db():
cnx = _connect_db()
log.debug("Reconnected to the DB")
# pylint: disable-next=undefined-variable
if not _is_salt_ssh(__opts__):
if not _is_salt_ssh_or_runner(__opts__):
# pylint: disable-next=undefined-variable
__context__["suma_minion_cnx"] = cnx
cursor = cnx.cursor()
Expand All @@ -134,7 +137,7 @@ def _connect_db():
cnx = _connect_db()
log.debug("Reconnected to the DB")
# pylint: disable-next=undefined-variable
if not _is_salt_ssh(__opts__):
if not _is_salt_ssh_or_runner(__opts__):
# pylint: disable-next=undefined-variable
__context__["suma_minion_cnx"] = cnx
cursor = cnx.cursor()
Expand All @@ -152,7 +155,7 @@ def _connect_db():
)
finally:
# pylint: disable-next=undefined-variable
if _is_salt_ssh(__opts__):
if _is_salt_ssh_or_runner(__opts__):
cnx.close()


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- suma_minion: prevent issues when calling Salt runners (bsc#1228232)

0 comments on commit 95d2ff4

Please sign in to comment.