Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TECH DEBT] Python Client API can't be used together with Tiamat-bundled Salt #62381

Closed
lukasraska opened this issue Jul 26, 2022 · 3 comments
Closed
Labels
Regression The issue is a bug that breaks functionality known to work in previous releases. tech-debt Tiamat

Comments

@lukasraska
Copy link
Contributor

Description of the tech debt to be addressed, include links and screenshots

While documentations claims that Salt provides several entry points for interfacing with Python applications. (https://docs.saltproject.io/en/latest/ref/clients/index.html ), with the new Tiamat-bundled masters / minions, users are no longer able to interact directly with the Python runtime as there is no entrypoint to expose "execute python scripts" functionality.

This means that for example following simple script

import salt.version

print("\n".join(salt.version.versions_report()))

is not working anymore, because Python executable is the bundled application:

root@ip-172-31-45-201:~# /tmp/tmpj6_f5pdr/salt/dist/salt call --local grains.get pythonexecutable --out=txt
local: /tmp/tmpj6_f5pdr/salt/dist/salt

Versions Report

Salt Version:
          Salt: 3005+0na.e256236
 
Dependency Versions:
          cffi: 1.14.6
      cherrypy: 18.6.1
      dateutil: 2.8.1
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 3.1.0
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: 2.17
      pycrypto: Not Installed
  pycryptodome: 3.9.8
        pygit2: Not Installed
        Python: 3.10.4 (main, Jul 19 2022, 11:24:48) [GCC 11.2.0]
  python-gnupg: 0.4.8
        PyYAML: 5.4.1
         PyZMQ: Not Installed
         smmap: Not Installed
       timelib: 0.2.4
       Tornado: 4.5.3
           ZMQ: Not Installed
 
System Versions:
          dist: ubuntu 22.04 jammy
        locale: utf-8
       machine: x86_64
       release: 5.15.0-1011-aws
        system: Linux
       version: Ubuntu 22.04 jammy
@lukasraska
Copy link
Contributor Author

With following quick patch to run.py it's possible to reuse the bundled Python to execute arbitrary scripts

diff --git a/run.py b/run.py
index 1d48a59..ca200a6 100755
--- a/run.py
+++ b/run.py
@@ -30,6 +30,7 @@ AVAIL = (
     "ssh",
     "support",
     "syndic",
+    "python",
 )
 
 
@@ -55,6 +56,10 @@ def py_shell():
     shell = code.InteractiveConsole(variables)
     shell.interact()
 
+def python_runtime():
+    sys.argv = sys.argv[2:]
+    exec(open(sys.argv[0]).read())
+
 
 def redirect(argv):
     """
@@ -70,6 +75,9 @@ def redirect(argv):
     if cmd == "shell":
         py_shell()
         return
+    if cmd == "python":
+        python_runtime()
+        return
     if tiamatpip.cli.should_redirect_argv(argv):
         tiamatpip.cli.process_pip_argv(argv)
         return 

so /tmp/tmpj6_f5pdr/salt/dist/salt python ~/test_salt.py or even the usage with shebang

root@ip-172-31-45-201:~# cat test_salt_shebang.py 
#!/tmp/tmpj6_f5pdr/salt/dist/salt python
import salt.version

print("\n".join(salt.version.versions_report()))

Is working, however it might not be systematic solution. But if it is, I can create PR to include this into the codebase.

@OrangeDog OrangeDog added Regression The issue is a bug that breaks functionality known to work in previous releases. Tiamat labels Jul 26, 2022
@Ch3LL
Copy link
Contributor

Ch3LL commented Jul 26, 2022

Can you please create a PR. Thanks

@Ch3LL
Copy link
Contributor

Ch3LL commented Aug 8, 2022

Closed by #62388

@Ch3LL Ch3LL closed this as completed Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Regression The issue is a bug that breaks functionality known to work in previous releases. tech-debt Tiamat
Projects
None yet
Development

No branches or pull requests

3 participants