Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -o xtrace |
| 4 | |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 5 | source /var/onap/commons |
| 6 | |
Victor Morales | 158c18c | 2017-08-06 11:23:15 -0500 | [diff] [blame] | 7 | # asserts_process() - Function that verifies if a specific process is running |
| 8 | function 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 |
| 18 | function 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 |
| 29 | function 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 Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 39 | # asserts_image() - Function that verifies if a specific image was created |
| 40 | function asserts_image { |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 41 | local image=$1 |
| 42 | local error_msg=${2:-"There is no $image image"} |
| 43 | |
Victor Morales | 158c18c | 2017-08-06 11:23:15 -0500 | [diff] [blame] | 44 | install_docker |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 45 | if [[ "$(docker images -q $image 2> /dev/null)" == "" ]]; then |
| 46 | raise_error $error_msg |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 47 | fi |
| 48 | } |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 49 | |
| 50 | # asserts_installed_package() - Function that verifies if a specific package was installed. |
| 51 | function 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 |
| 61 | function 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 |
| 71 | function raise_error { |
| 72 | echo $@ |
| 73 | exit 1 |
| 74 | } |