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