Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F5057684
D2110.id5324.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D2110.id5324.diff
View Options
diff --git a/_tests/states/lint-sources.py b/_tests/states/lint-sources.py
new file mode 100755
--- /dev/null
+++ b/_tests/states/lint-sources.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python3
+
+import yaml
+
+MODULES = ["cmd", "file"]
+
+
+def flatten_args(args):
+ flatmap = {}
+
+ for entry in args:
+ if type(entry) is dict:
+ for key, value in entry.items():
+ flatmap[key] = value
+ else:
+ flatmap["__method__"] = entry
+
+ return flatmap
+
+
+def get_arg(args, key):
+ return flatten_args(args).get(key)
+
+
+class StateChecks:
+
+ def __init__(self, name, args):
+ self.name = name
+ self.args = args
+
+ def get_tests_to_run(self):
+ return [module for module in MODULES if module in self.args]
+
+ def test_state(self):
+ for module in self.get_tests_to_run():
+ print(f"Test {module} for {self.name}")
+ getattr(self, "check_" + module)(self.args[module])
+
+ def check_cmd(self, args):
+ self.check_source(args)
+
+ def check_file(self, args):
+ self.check_source(args)
+
+ def check_source(self, args):
+ source = get_arg(args, "source")
+ if not source:
+ return True
+
+ if source[0:7] == "salt://":
+ required_file = source[7:]
+ print(f" Check if file exists: {required_file}")
+
+ if source[0:4] == "http":
+ print(f" Check if URL is 200: {source}")
+
+ return True
+
+
+def run_demo_checks():
+ # To generate this file:
+ # salt --output=yaml windriver state.show_highstate \
+ # > /tmp/windriver-highstate.yaml
+ fd = open("/tmp/windriver-highstate.yaml")
+ states = yaml.safe_load(fd)
+ states = states["windriver"]
+
+ for state_name, state_args in states.items():
+ checks = StateChecks(state_name, state_args)
+ checks.test_state()
+
+
+if __name__ == "__main__":
+ run_demo_checks()
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Mar 5, 06:17 (19 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2461420
Default Alt Text
D2110.id5324.diff (1 KB)
Attached To
Mode
D2110: WIP: states test
Attached
Detach File
Event Timeline
Log In to Comment