saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
13.98k stars 5.47k forks source link

[BUG] [Regression] yaml output broken in 3006.8 #66594

Open SaherH opened 1 month ago

SaherH commented 1 month ago

Description Yaml output is not working (e.g. when using show_sls --out=yaml), and it's returning NULL.

Setup

Steps to Reproduce the behavior Create any SLS file, and run show_sls with --out=yaml

[root@0b379b6cb0ba /]# cat /srv/salt/test.sls
test:
  cmd.run:
    - name: echo hello
[root@0b379b6cb0ba /]# salt-call --local state.show_sls --out=yaml test
local: NULL

Expected behavior Working output from 3006.7

[root@0b379b6cb0ba /]# salt-call --local state.show_sls --out=yaml test
local:
  test:
    cmd:
    - name: echo hello
    - run
    - order: 10000
    __sls__: test
    __env__: base

Versions Report

salt --versions-report ```yaml Salt Version: Salt: 3006.8 Python Version: Python: 3.10.14 (main, Apr 3 2024, 21:30:09) [GCC 11.2.0] 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.3 libgit2: Not Installed looseversion: 1.0.2 M2Crypto: Not Installed Mako: Not Installed msgpack: 1.0.2 msgpack-pure: Not Installed mysql-python: Not Installed packaging: 22.0 pycparser: 2.21 pycrypto: Not Installed pycryptodome: 3.19.1 pygit2: Not Installed python-gnupg: 0.4.8 PyYAML: 6.0.1 PyZMQ: 23.2.0 relenv: 0.16.0 smmap: Not Installed timelib: 0.2.4 Tornado: 4.5.3 ZMQ: 4.3.4 System Versions: dist: rocky 8.9 Green Obsidian locale: utf-8 machine: x86_64 release: 4.18.0-513.24.1.el8_9.x86_64 system: Linux version: Rocky Linux 8.9 Green Obsidian ```

Additional context Root cause is missing yaml dumper logic. In https://github.com/saltstack/salt/commit/b9be2dec1b33a654da7cb73e39a5b35ff78fef57, OrderedDict was replaced with HashableOrderedDict. The former had custom yaml dumper logic defined that hasn't been applied to the latter. https://github.com/saltstack/salt/blob/41ef07843354c5d99ca09415de2db43c913cd59e/salt/utils/yamldumper.py#L73-L74

achalupa-ptc commented 1 month ago

I'm also facing this problem and it's a killer because we can't render runnable code w/ this broken. makes it very difficult to resume an orchestration.

doesitblend commented 1 month ago

@achalupa-ptc @SaherH As a quick workaround for this issue you can pipe the output from JSON to a simple Python script to convert the data to YAML.

# salt-run state.orch_show_sls testing.orch --output=json | ./converter.py 

https://gist.github.com/doesitblend/6e63caf909235c4875bbf38b172b382f

achalupa-ptc commented 1 month ago

@doesitblend : thanks for the workaround it works but unfortunately it's not enough to reduce the pain for my use case. I'm typically rendering an orchestration or state using --out=yaml to resume an orchestration from where it failed. With the workaround it accurately renders the code as yaml but it does so in a random order. It's very time consuming to pick through the randomly ordered code to pick out the steps that haven't run yet.

First salt broke the ability to pass test=true -l debug as a way of rendering code. using --out=yaml was the workaround for this breakage and now this is broken :(.