xref: /openbmc/openbmc-test-automation/ffdc/docs/plugin.md (revision 66c2f33f3d951c6d356404648058db3082a5e441)
1### Plugin
2
3Plugin feature for the log collector is to load a user python functions at runtime by the engine and execute it.
4
5The design infrastructure allows user to extend or call their existing python scripts without needing to expose
6the implementation.  This enriches the log collection and mechanize the work flow as per user driven as per
7their requirement,
8
9### Understanding Plugin
10The plugin works like any stand-alone piece of python script or library function.
11
12The main components in plugin infrastructure are:
13
14- plugin directory
15- plugin directive in YAML
16- plugin parser in the collector engine
17
18### Plugin Directory
19Python module script are added or copied to `plugins` directory and the log engine loads these plugins during
20runtime and on demand from the YAML else they are not invoked automatically.
21
22Example:
23```
24plugins/
25├── foo_func.py
26├── ssh_execution.py
27└── telnet_execution.py
28
29```
30
31### Plugin Template Example
32
33plugins/foo_func.py
34```
35# Sample for documentation plugin
36
37def print_vars(var):
38    print(var)
39
40def return_vars():
41    return 1
42```
43
44You can add your own plugin modules to extend further.
45
46Test your plugin:
47```
48python3 plugins/foo_func.py
49```
50
51### YAML Syntax
52
53Plugin function without return statement.
54```
55    - plugin:
56        - plugin_name: plugin.foo_func.print_vars
57        - plugin_args:
58            - "Hello plugin"
59```
60
61Plugin function with return statement.
62```
63    - plugin:
64        - plugin_name: return_value = plugin.foo_func.return_vars
65        - plugin_args:
66```
67
68when the return directive is used by implying "=" , the `return_value`
69can be accessed within the same block by another following plugins
70by using the variable name directly.
71
72Example:
73```
74    - plugin:
75        - plugin_name: plugin.foo_func.print_vars
76        - plugin_args:
77            - return_value
78```
79
80To accept multiple return values by using coma  "," separated statement
81```
82     -plugin_name:  return_value1,return_value2 = plugin.foo_func.print_vars
83```
84
85### Plugin execution output for sample
86
87
88```
89        [PLUGIN-START]
90        Call func: plugin.foo_func.print_vars("Hello plugin")
91        Hello plugin
92        return: None
93        [PLUGIN-END]
94
95        [PLUGIN-START]
96        Call func: plugin.foo_func.return_vars()
97        return: 1
98        [PLUGIN-END]
99```
100