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

[BUG] saltclass tops state list is incomplete for nested classes #58969

Open
cheribral opened this issue Nov 18, 2020 · 0 comments
Open

[BUG] saltclass tops state list is incomplete for nested classes #58969

cheribral opened this issue Nov 18, 2020 · 0 comments
Assignees
Labels
Bug broken, incorrect, or confusing behavior Pending-Discussion The issue or pull request needs more discussion before it can be closed or merged
Milestone

Comments

@cheribral
Copy link

cheribral commented Nov 18, 2020

Description
When using saltclass with multiple levels of classes, all of which define states, the resulting state list only comes back with states for the top level classes. Looking at the code, it appears that it is ignoring the state lists returned from the recursive calls of expand_classes_in_order

Setup

Node: 
  classes: [A,L]

Class A:
  states: [1,2]
  classes: [B]
Class B:
  states: [3,4]
  classes: [C]
Class C:
  states: [5,6]
 
Class: L
  states: [7]
  classes: [M]
Class M:
  states: [8]

Expected behavior
Running state.show_top with the above classes, one would expect a state list of [1,2,3,4,5,6,7,8], but what comes back instead is [1,2,7]

Versions Report

salt --versions-report
Salt Version:
           Salt: 3002.1
 
Dependency Versions:
           cffi: 1.14.2
       cherrypy: Not Installed
       dateutil: 2.8.1
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
         Jinja2: 2.11.1
        libgit2: 0.28.2
       M2Crypto: 0.35.2
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.6.2
   mysql-python: Not Installed
      pycparser: 2.20
       pycrypto: 2.6.1
   pycryptodome: 3.9.7
         pygit2: 0.28.2
         Python: 3.6.8 (default, Oct 13 2020, 16:18:22)
   python-gnupg: Not Installed
         PyYAML: 3.13
          PyZMQ: 17.0.0
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.1.4
 
System Versions:
           dist: centos 7 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-1160.2.2.el7.x86_64
         system: Linux
        version: CentOS Linux 7 Core

Additional context
Without knowing exactly what was intended, this is my rough guess as to what might have been meant to happen:

--- salt/utils/saltclass.py        2020-11-18 04:04:34.890045089 +0000
+++ -   2020-11-18 04:04:47.691585445 +0000
@@ -311,7 +311,7 @@
             if expanded_classes[klass].get("classes"):
                 l_id = classes_to_expand.index(klass)
                 classes_to_expand[l_id:l_id] = expanded_classes[klass]["classes"]
-                expand_classes_in_order(
+                _,_,minion_dict["states"] = expand_classes_in_order(
                     minion_dict,
                     salt_data,
                     seen_classes,
@@ -319,7 +319,7 @@
                     classes_to_expand,
                 )
             else:
-                expand_classes_in_order(
+                _,_,minion_dict["states"] = expand_classes_in_order(
                     minion_dict,
                     salt_data,
                     seen_classes,
@@ -347,7 +347,7 @@
             "states" in expanded_classes[ord_klass]
             and expanded_classes[ord_klass]["states"] is None
         ):
-            expanded_classes[ord_klass]["states"] = {}
+            expanded_classes[ord_klass]["states"] = []
 
         if "states" in expanded_classes[ord_klass]:
             ord_expanded_states.extend(expanded_classes[ord_klass]["states"])
@@ -357,7 +357,9 @@
         minion_dict["states"] = []
 
     if "states" in minion_dict:
-        ord_expanded_states.extend(minion_dict["states"])
+        for state in minion_dict["states"]:
+            if state not in ord_expanded_states:
+                ord_expanded_states.append(state)
 
     ord_expanded_classes.append(minion_dict)

@cheribral cheribral added the Bug broken, incorrect, or confusing behavior label Nov 18, 2020
@sagetherage sagetherage self-assigned this Feb 16, 2021
@sagetherage sagetherage added this to the Blocked milestone Feb 16, 2021
@sagetherage sagetherage added the Pending-Discussion The issue or pull request needs more discussion before it can be closed or merged label Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior Pending-Discussion The issue or pull request needs more discussion before it can be closed or merged
Projects
None yet
Development

No branches or pull requests

5 participants