Skip to content

Commit 0e754d4

Browse files
authored
Sync-up changes - Syslog support, '-plugins' json/yaml, python library to invoke PM (#24)
Sync-up changes - Update default log location - Add syslog support - Add a python library to invoke plugin manager - Add '-plugins' option to specify plugins info as a json string or in a file in json/yaml format. - Add option for specifying Log Level; Generate log file inside specified dir.
1 parent ef2a4d1 commit 0e754d4

20 files changed

Lines changed: 2062 additions & 767 deletions

Makefile

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ GOSRC=$(TOP)
1414

1515
# Set GOBIN to where binaries get picked up while creating RPM/ISO.
1616
GOBIN?=$(TOP)/bin
17-
GOCOVER=$(GOSRC)/cover
17+
GOCOVERDIR=$(GOSRC)/cover
1818
GOTOOLSBIN=$(TOP)/tools/go/
1919

2020
.SILENT:
@@ -32,7 +32,7 @@ clean: ## Clean Plugin Manager go build & test artifacts
3232
-@rm $(GOSRC)/{,.}*{dot,html,log,svg,xml};
3333
-@rm $(GOSRC)/cmd/pm/{,.}*{dot,log,svg};
3434
-@rm -rf $(GOSRC)/plugins/
35-
-@rm -rf $(GOCOVER);
35+
-@rm -rf $(GOCOVERDIR);
3636

3737
.PHONY: build
3838
build: ## Build source code
@@ -75,24 +75,25 @@ govet: ## Run go vet
7575
.PHONY: test
7676
test: ## Run all tests
7777
echo "Running Plugin Manager Go Unit Tests...";
78-
mkdir -p $(GOCOVER);
78+
mkdir -p $(GOCOVERDIR);
79+
export GOCOVERDIR=$(GOCOVERDIR); \
7980
export INTEG_TEST_BIN=$(GOSRC); \
8081
export PM_CONF_FILE=$(GOSRC)/sample/pm.config.yaml; \
8182
export INTEGRATION_TEST=START; \
8283
cd $(GOSRC); \
8384
test_failed=0; \
8485
d=pm; \
85-
go test -mod=vendor -v --cover -covermode=count -coverprofile=$(GOCOVER)/$${d}.out ./... | \
86+
go test -mod=vendor -v --cover -covermode=count -coverprofile=$(GOCOVERDIR)/$${d}.out ./... | \
8687
$(GOTOOLSBIN)/go-junit-report > TEST-$${d}.xml; \
8788
ret=$${PIPESTATUS[0]}; \
8889
if [ $${ret} -ne 0 ]; then \
8990
echo "Go unit test failed for $${d}."; \
9091
test_failed=1; \
9192
fi ; \
92-
awk -f $(TOP)/tools/gocoverage-collate.awk $(GOCOVER)/* > $(GOCOVER)/cover.out; \
93-
go tool cover -html=$(GOCOVER)/cover.out -o go-coverage-$${d}.html; \
94-
$(GOTOOLSBIN)/gocov convert $(GOCOVER)/cover.out | $(GOTOOLSBIN)/gocov-xml > go-coverage-$${d}.xml; \
95-
rm -rf $(GOCOVER)/*; \
93+
awk -f $(TOP)/tools/gocoverage-collate.awk $(GOCOVERDIR)/* > $(GOCOVERDIR)/cover.out; \
94+
go tool cover -html=$(GOCOVERDIR)/cover.out -o go-coverage-$${d}.html; \
95+
$(GOTOOLSBIN)/gocov convert $(GOCOVERDIR)/cover.out | $(GOTOOLSBIN)/gocov-xml > go-coverage-$${d}.xml; \
96+
rm -rf $(GOCOVERDIR)/*; \
9697
export INTEGRATION_TEST=DONE; \
9798
if [ $${test_failed} -ne 0 ]; then \
9899
echo "Go unit tests failed."; \
@@ -104,7 +105,8 @@ go-race: ## Run Go tests with race detector enabled
104105
echo "Checking Go code for race conditions...";
105106
# NOTE: COVER directory should be present, along with INTEGRATION_TEST
106107
# value being set to "START" for integ_test.go to succeed.
107-
mkdir -p $(GOCOVER);
108+
mkdir -p $(GOCOVERDIR);
109+
export GOCOVERDIR=$(GOCOVERDIR); \
108110
export INTEGRATION_TEST=START; \
109111
export INTEG_TEST_BIN=$(GOSRC); \
110112
cd $(GOSRC); \

README.md

Lines changed: 101 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ systemd.
1616
- [Example: Plugin Manager (PM) `list`](#example-plugin-manager-pm-list)
1717
- [Configuring Plugin Manager](#configuring-plugin-manager)
1818
- [Running Plugins](#running-plugins)
19-
- [Example: Plugin Manager (PM) `run`](#example-plugin-manager-pm-run)
19+
- [Example: Plugin Manager (PM) `run -plugins`](#example-plugin-manager-pm-run--plugins)
20+
- [Specify `-plugins` details as a json string](#specify--plugins-details-as-a-json-string)
21+
- [Specify `-plugins` details via json file](#specify--plugins-details-via-json-file)
22+
- [Example: Plugin Manager (PM) `run -type`](#example-plugin-manager-pm-run--type)
2023
- [Example: Plugin Manager (PM) with `sequential` flag](#example-plugin-manager-pm-with-sequential-flag)
2124
- [Example: Overriding Plugin Manager (PM) configuration - `library`, `log-dir` and `log-file`](#example-overriding-plugin-manager-pm-configuration---library-log-dir-and-log-file)
2225
- [Example: Writing plugins result to a `output-file` in `output-format` {json, yaml} format](#example-writing-plugins-result-to-a-output-file-in-output-format-json-yaml-format)
@@ -87,6 +90,7 @@ The PM list command syntax / usage is as shown below:
8790
```bash
8891
pm list -type <PluginType>
8992
[-library=<PluginsLibraryPath>]
93+
[-log-tag=<TagOfSysLog>]
9094
[-log-dir=<LogDirectory>]
9195
[-log-file=<NameOfLogFile>]
9296
```
@@ -96,6 +100,9 @@ where
96100
- **`type`**: Indicates the plugin type.
97101
- **`library`**: Indicates the location of plugins library.
98102
**Overrides** value present in PM configuration.
103+
- **`log-tag`**: Indicates the log tag written by rsyslog.
104+
Note: rsyslog is used as default logger for both main and plugin logs.
105+
It will be overwritten if `log-file` option set.
99106
- **`log-dir`**: Indicates the log directory path.
100107
**Overrides** value present in PM configuration.
101108
- **`log-file`**: Indicates the name of the log file.
@@ -113,7 +120,7 @@ The list of plugins are mapped in .//preupgrade.2020-01-13T15:56:46.725348-08:00
113120

114121
Plugin Manager can be configured to look for plugins at a specific location,
115122
and to write logs to a specific file by specifying those details in the
116-
Plugin Manager configuration file `/etc/asum/pm.config.yml`.
123+
Plugin Manager configuration file `/opt/veritas/appliance/asum/pm.config.yml`.
117124

118125
Instead of updating the default config file, one can choose to provide his/her
119126
own custom config file.
@@ -138,7 +145,7 @@ PluginManager:
138145
# The timestamp and '.log' extension would be appended to this name.
139146
# I.e., The format of the log file generated would be: "<log file>.<timestamp>.log"
140147
# Example: The below value results in following log file: pm.2020-01-13T16:11:58.6006565-08:00.log
141-
log file: "pm"
148+
log file: "pm.log"
142149
...
143150
```
144151

@@ -156,9 +163,11 @@ exit value of plugins, the PM exits with 1.
156163
The PM run command syntax / usage is as shown below:
157164

158165
```bash
159-
pm run -type <PluginType>
166+
pm run [-plugins <PluginInformation>]
167+
[-type <PluginType>]
160168
[-library=<PluginsLibraryPath>]
161169
[-sequential[={true|1|false|0}]]
170+
[-log-tag=<TagOfSysLog>]
162171
[-log-dir=<LogDirectory>]
163172
[-log-file=<NameOfLogFile>]
164173
[-output={json|yaml}]
@@ -167,13 +176,16 @@ pm run -type <PluginType>
167176
168177
where
169178
179+
- **`plugins`**: A json string or a json file containing plugins and its dependencies.
170180
- **`type`**: Indicates the plugin type.
171181
- **`library`**: Indicates the location of plugins library.
172182
**Overrides** value present in PM configuration.
183+
**NOTE** The specified value gets set as an environment variable `PM_LIBRARY` for the plugins being run. The plugin file can access any scripts in the same folder via `PM_LIBRARY` variable.
173184
- **`-sequential`**: Indicates PM to execute only one plugin at a time
174185
regardless of how many plugins' dependencies are met.
175186
**Default: Disabled**. To enable, specify `-sequential=true` or just
176187
`-sequential` while running PM.
188+
- **`log-tag`**: Indicates the log tag written by rsyslog. The `log-tag` option will supercede `log-dir` and `log-file` options.
177189
- **`log-dir`**: Indicates the log directory path.
178190
**Overrides** value present in PM configuration.
179191
- **`log-file`**: Indicates the name of the log file.
@@ -185,7 +197,86 @@ where
185197
If `output` format is specified, and `output-file` is not specified,
186198
then result will be displayed on console.
187199
188-
### Example: Plugin Manager (PM) `run`
200+
### Example: Plugin Manager (PM) `run -plugins`
201+
202+
```json
203+
$ jq -n "$plugins" | tee sample/plugins-prereboot.json
204+
{
205+
"Plugins": [
206+
{
207+
"Name": "A/a.prereboot",
208+
"Description": "Applying \"A\" settings",
209+
"ExecStart": "/usr/bin/ls -l -t",
210+
"Requires": [
211+
"C/c.prereboot",
212+
"D/d.prereboot"
213+
]
214+
},
215+
{
216+
"Name": "B/b.prereboot",
217+
"Description": "Applying \"B\" settings...",
218+
"ExecStart": "/bin/echo \"Running B...\"",
219+
"RequiredBy": [
220+
"D/d.prereboot"
221+
]
222+
},
223+
{
224+
"Name": "C/c.prereboot",
225+
"Description": "Applying \"C\" settings...",
226+
"ExecStart": "/bin/echo \"Running C...\"",
227+
"RequiredBy": [
228+
"A/a.prereboot"
229+
]
230+
},
231+
{
232+
"Name": "D/d.prereboot",
233+
"Description": "Applying \"D\" settings...",
234+
"ExecStart": "/bin/echo 'Running D...!'",
235+
"RequiredBy": [
236+
"A/a.prereboot"
237+
],
238+
"Requires": [
239+
"B/b.prereboot"
240+
]
241+
}
242+
]
243+
}
244+
$
245+
```
246+
247+
#### Specify `-plugins` details as a json string
248+
249+
```bash
250+
$ $GOBIN/pm run -plugins "$plugins"
251+
Applying "B" settings...: Starting
252+
Applying "C" settings...: Starting
253+
Applying "B" settings...: Succeeded
254+
Applying "D" settings...: Starting
255+
Applying "C" settings...: Succeeded
256+
Applying "D" settings...: Succeeded
257+
Applying "A" settings: Starting
258+
Applying "A" settings: Succeeded
259+
Running plugins: Succeeded
260+
bash-5.1$
261+
```
262+
263+
#### Specify `-plugins` details via json file
264+
265+
```bash
266+
$ $GOBIN/pm run -plugins "./sample/plugins-prereboot.json" -library sample/library/
267+
Applying "C" settings...: Starting
268+
Applying "B" settings...: Starting
269+
Applying "C" settings...: Succeeded
270+
Applying "B" settings...: Succeeded
271+
Applying "D" settings...: Starting
272+
Applying "D" settings...: Succeeded
273+
Applying "A" settings: Starting
274+
Applying "A" settings: Succeeded
275+
Running plugins: Succeeded
276+
$
277+
```
278+
279+
### Example: Plugin Manager (PM) `run -type`
189280
190281
```bash
191282
$ $GOBIN/pm run -type=prereboot
@@ -253,7 +344,7 @@ $
253344
254345
```bash
255346
$ $GOBIN/pm run -type preupgrade -output-format=json -output-file=a.json -library ./sample/library/
256-
Log: /log/asum/pm.2021-01-29T17:46:57.6904918-08:00.log
347+
Log: /var/log/asum/pm.2021-01-29T17:46:57.6904918-08:00.log
257348
258349
Checking for "D" settings...: Starting
259350
Checking for "D" settings...: Succeeded
@@ -271,7 +362,7 @@ $ cat a.json
271362
"Plugins": [
272363
{
273364
"Description": "Checking for \"D\" settings...",
274-
"FileName": "D/d.preupgrade",
365+
"Name": "D/d.preupgrade",
275366
"ExecStart": "$PM_LIBRARY/D/preupgrade.sh",
276367
"RequiredBy": [
277368
"A/a.preupgrade"
@@ -282,7 +373,7 @@ $ cat a.json
282373
},
283374
{
284375
"Description": "Checking for \"A\" settings",
285-
"FileName": "A/a.preupgrade",
376+
"Name": "A/a.preupgrade",
286377
"ExecStart": "/bin/echo \"Checking A...\"",
287378
"RequiredBy": null,
288379
"Requires": [
@@ -299,7 +390,7 @@ $ cat a.json
299390
300391
```bash
301392
$ $GOBIN/pm run -type preupgrade -output-format=yaml -output-file=a.yaml -library ./sample/library/
302-
Log: /log/asum/pm.2021-01-29T17:53:15.8128937-08:00.log
393+
Log: /var/log/asum/pm.2021-01-29T17:53:15.8128937-08:00.log
303394
304395
Checking for "D" settings...: Starting
305396
Checking for "D" settings...: Failed
@@ -312,7 +403,7 @@ $ cat a.yaml
312403
type: preupgrade
313404
plugins:
314405
- description: Checking for "D" settings...
315-
filename: D/d.preupgrade
406+
name: D/d.preupgrade
316407
execstart: $PM_LIBRARY/D/preupgrade.sh
317408
requiredby:
318409
- A/a.preupgrade

0 commit comments

Comments
 (0)