blob: 02c269b4c3c53dd5a686577df1d55be41de48b44 [file] [log] [blame]
Victor Morales89ce3212017-06-16 18:32:48 -05001#!/bin/bash
2
3set -o xtrace
4
Victor Moralesdd074802017-07-26 16:06:35 -05005source /var/onap/commons
6
Victor Morales158c18c2017-08-06 11:23:15 -05007# asserts_process() - Function that verifies if a specific process is running
8function asserts_process {
9 local process=$1
10 local error_msg=${2:-"There is no $process running process"}
11
12 if [[ "ps -ef | grep $process" == "" ]]; then
13 raise_error $error_msg
14 fi
15}
16
17# asserts_java_process() - Function that verifies if a specific java process is running
18function asserts_java_process {
19 local process=$1
20 local error_msg=${2:-"There is no $process java running process"}
21
22 install_java
23 if [[ "jps | grep $process" == "" ]]; then
24 raise_error $error_msg
25 fi
26}
27
28# asserts_image_running() - Function that verifies if a specific image is running
29function asserts_image_running {
30 local image=$1
31 local error_msg=${2:-"There is no process with $image image running"}
32
33 asserts_image $image
34 if [[ "$(docker ps -q --filter=ancestor=$image 2> /dev/null)" == "" ]]; then
35 raise_error $error_msg
36 fi
37}
38
Victor Morales89ce3212017-06-16 18:32:48 -050039# asserts_image() - Function that verifies if a specific image was created
40function asserts_image {
Victor Moralesdd074802017-07-26 16:06:35 -050041 local image=$1
42 local error_msg=${2:-"There is no $image image"}
43
Victor Morales158c18c2017-08-06 11:23:15 -050044 install_docker
Victor Moralesdd074802017-07-26 16:06:35 -050045 if [[ "$(docker images -q $image 2> /dev/null)" == "" ]]; then
46 raise_error $error_msg
Victor Morales89ce3212017-06-16 18:32:48 -050047 fi
48}
Victor Moralesdd074802017-07-26 16:06:35 -050049
50# asserts_installed_package() - Function that verifies if a specific package was installed.
51function asserts_installed_package {
52 local package=$1
53 local error_msg=${2:-"$package wasn't installed"}
54
55 if ! is_package_installed $package; then
56 raise_error $error_msg
57 fi
58}
59
60# asserts_file_exist() - Function that verifies if a specific file exists
61function asserts_file_exist {
62 local file=$1
63 local error_msg=${2:-"$file doesn't exist"}
64
65 if [ ! -f $file ]; then
66 raise_error $error_msg
67 fi
68}
69
70# raise_error() - Function that prints and exits the execution
71function raise_error {
72 echo $@
73 exit 1
74}