52f0bce924026d19610338ebecda197e748fd758
[integration.git] / bootstrap / vagrant-onap / tests / asserts
1 #!/bin/bash
2
3 source /var/onap/commons
4
5 # asserts_process() - Function that verifies if a specific process is running
6 function 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
16 function 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
27 function 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
37 # asserts_image() - Function that verifies if a specific image was created
38 function asserts_image {
39     local image=$1
40     local error_msg=${2:-"There is no $image image"}
41
42     install_docker
43     if [[ "$(docker images -q $image 2> /dev/null)" == "" ]]; then
44         raise_error $error_msg
45     fi
46 }
47
48 # asserts_installed_package() - Function that verifies if a specific package was installed.
49 function 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
59 function 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
69 function raise_error {
70     echo $@
71     exit 1
72 }