Skip to content

Commit 1a54fcc

Browse files
committed
Add callback_stdout and verbosity option and fix nits
* Fix nits in documentation, * Move listing.py and init.sh under /root in the container to be consistent with the location of the tripleo-validations location * Add option to overide the validation callback stdout in order to get something with much details if wanted or more verbose like the ansible default ones. * Improve de --debug option to add verbosity level at 4. For now hardcoded to4, but can be set with an option. * Provides the /root/validations.log file by default in init.sh The test -f with bash cause that if no file exist, the output is not logged.
1 parent d7b4802 commit 1a54fcc

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ You can of course edit the file with a text editor, too.
112112

113113
### Logging
114114

115-
If you want to have the validation results logged into a file you can use the `--log-path <local file path>` option. Instead of just outputting the validation results on stdout it will log the results to the given log file path. If the file already exists the entries will be appended to the file, otherwise the file will be created.
115+
If you want to have the validation results logged into a file you can use the `--log-path <local file path>` option. Instead of just outputting the validation results on stdout it will log the results to the given log file path. If the file already exists the entries will be appended to the file, otherwise the file will be created.
116116

117117

118118
### Options
@@ -134,7 +134,7 @@ Here's a step to step guide to test a new validation in container-validations:
134134

135135
For example if you want to test a new validation that runs on the host from
136136
which you're running container-validations your inventory file should look
137-
something like this:
137+
something like this:
138138

139139
```
140140
---
@@ -163,7 +163,7 @@ Please note that you can test all connections in your inventory file:
163163

164164
Usually you want to use a local repository for development. You can use the
165165
`--repository` option to define a path to a local repository (remember you can
166-
store the value in a config file):
166+
store the value in a config file):
167167

168168
```Bash
169169
./validations.py --repository /home/stack/tripleo-validations --validations my-validation
@@ -201,7 +201,7 @@ In order to build it on your own, you can run:
201201
In order to manually run the container, you can run:
202202
```Bash
203203
(podman|docker) run --rm -e "INVENTORY=localhost," \
204-
-e "VALIDATIONS=dns,no-op' \
204+
-e "VALIDATIONS=dns,no-op" \
205205
-v $(pwd)/.ssh/id_rsa:/home/my-user/.ssh/id_rsa \
206206
validations
207207
```
@@ -223,4 +223,3 @@ Set the keyfile manually (usually /home/<current user>/.ssh/id_rsa).
223223

224224
Install additional packages into your container image if they're needed by
225225
custom validations.
226-

init.sh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ INV=${INVENTORY:="/root/inventory.yaml"}
55
VALS=${VALIDATIONS:=""}
66

77
# Set logging env var to file mounted into the container.
8-
if [ -f "/root/validations.log" ]; then
9-
export ANSIBLE_LOG_PATH="/root/validations.log"
10-
fi
11-
8+
export ANSIBLE_LOG_PATH="/root/validations.log"
129

1310
# Run the inventory ping test
1411
if [ "${ACTION}" == "inventory_ping" ]; then
@@ -26,11 +23,11 @@ if [[ "${ACTION}" =~ ^(run|list)$ ]]; then
2623
val_dir=$(basename "${REPO}" .git)
2724
fi
2825
if [ "${GROUP}" != "" ]; then
29-
VALS_FROM_REPO=$(/usr/bin/python3 listing.py ${val_dir} --group ${GROUP})
26+
VALS_FROM_REPO=$(/usr/bin/python3 /root/listing.py ${val_dir} --group ${GROUP})
3027
elif [ "${HOST}" != "" ]; then
31-
VALS_FROM_REPO=$(/usr/bin/python3 listing.py ${val_dir} --host ${HOST})
28+
VALS_FROM_REPO=$(/usr/bin/python3 /root/listing.py ${val_dir} --host ${HOST})
3229
else
33-
VALS_FROM_REPO=$(/usr/bin/python3 listing.py ${val_dir})
30+
VALS_FROM_REPO=$(/usr/bin/python3 /root/listing.py ${val_dir})
3431
fi
3532
fi
3633

@@ -46,7 +43,7 @@ if [ "${ACTION}" == "list" ]; then
4643
echo ${VALS_FROM_REPO}
4744
fi
4845

49-
# Run a list of validations
46+
# Run a list of validations
5047
if [ "${ACTION}" == "run" ]; then
5148

5249
cd "${val_dir}"

validation.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
RUN yum install -y git ansible sudo gcc python3-devel python3-pip %(extra_pkgs)s
2323
RUN yum clean all
2424
25-
COPY init.sh /init.sh
26-
RUN chmod 0755 /init.sh
25+
COPY init.sh /root/init.sh
26+
RUN chmod 0755 /root/init.sh
2727
28-
COPY listing.py /listing.py
29-
RUN chmod 0755 /listing.py
28+
COPY listing.py /root/listing.py
29+
RUN chmod 0755 /root/listing.py
3030
3131
# Add user install path to Python path and install packages
3232
ENV PYTHONPATH ${PYTHONPATH}:/root/.local/lib/python3.7/site-packages
@@ -42,7 +42,7 @@
4242
4343
COPY %(inventory)s /root/inventory.yaml
4444
45-
CMD ["/init.sh"]
45+
CMD ["/root/init.sh"]
4646
''' # noqa: E501
4747

4848

@@ -107,6 +107,8 @@ def __setup(self):
107107
config.set('Validations', 'group', self.__args['group'])
108108
config.set('Validations', 'host', self.__args['host'])
109109
config.set('Validations', 'log_path', self.__args['log_path'])
110+
config.set('Validations', 'ansible_callback',
111+
self.__args['ansible_callback'])
110112

111113
if self.__args.get('create_config'):
112114
print('Generating config file')
@@ -132,6 +134,7 @@ def __setup(self):
132134
self.__params['host'] = self.__args['host']
133135
self.__params['inventory_ping'] = self.__args['inventory_ping']
134136
self.__params['log_path'] = self.__args['log_path']
137+
self.__params['ansible_callback'] = self.__args['ansible_callback']
135138

136139
validations = config.get('Validations', 'volumes').split(',')
137140
self.__params['volumes'] = validations
@@ -217,6 +220,17 @@ def __build_start_cmd(self):
217220
cmd.append('-v%s:/root/validations.log:z' %
218221
self.__params['log_path'])
219222

223+
# Callback
224+
if self.__params['ansible_callback']:
225+
cmd.append('--env=ANSIBLE_STDOUT_CALLBACK=%s' %
226+
self.__params['ansible_callback'])
227+
# Force color
228+
cmd.append('--env=ANSIBLE_FORCE_COLOR=true')
229+
230+
# Debug
231+
if self.__params['debug']:
232+
cmd.append('--env=ANSIBLE_VERBOSITY=4')
233+
220234
# Action to run
221235
cmd.append('--env=ACTION=%s' % self.__params.get('action'))
222236

@@ -322,6 +336,12 @@ def start(self):
322336
help='Run validations in host.')
323337
parser.add_argument('--log-path', type=str, default='',
324338
help='Local log path for validations output.')
339+
parser.add_argument('--ansible-callback', type=str,
340+
default=None,
341+
help='Define ansible stdout callback. Validations has '
342+
'its own stdout callback named: '
343+
'validation_output. The standard Ansible one is: '
344+
'default')
325345

326346
args = parser.parse_args()
327347

0 commit comments

Comments
 (0)