Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 3 | source /var/onap/commons |
| 4 | |
Victor Morales | 88d193e | 2017-11-16 10:50:28 -0800 | [diff] [blame] | 5 | # asserts_http_status_code() - Function that determines if a HTTP status code is retrieved from URL |
| 6 | function asserts_http_status_code { |
| 7 | local url=$1 |
| 8 | local expected_code=${2:-"200"} |
| 9 | |
| 10 | code=$(curl -I $url | head -n 1 | cut -d$' ' -f2) |
| 11 | local error_msg=${3:-"The URL $url responded with $code status code"} |
Victor Morales | 9d205bc | 2017-12-01 17:52:07 -0800 | [diff] [blame] | 12 | if [[ "$code" != "$expected_code" ]]; then |
Victor Morales | 88d193e | 2017-11-16 10:50:28 -0800 | [diff] [blame] | 13 | raise_error $error_msg |
| 14 | fi |
| 15 | } |
| 16 | |
Victor Morales | 158c18c | 2017-08-06 11:23:15 -0500 | [diff] [blame] | 17 | # asserts_process() - Function that verifies if a specific process is running |
| 18 | function asserts_process { |
| 19 | local process=$1 |
| 20 | local error_msg=${2:-"There is no $process running process"} |
| 21 | |
| 22 | if [[ "ps -ef | grep $process" == "" ]]; then |
| 23 | raise_error $error_msg |
| 24 | fi |
| 25 | } |
| 26 | |
| 27 | # asserts_java_process() - Function that verifies if a specific java process is running |
| 28 | function asserts_java_process { |
| 29 | local process=$1 |
| 30 | local error_msg=${2:-"There is no $process java running process"} |
| 31 | |
| 32 | install_java |
| 33 | if [[ "jps | grep $process" == "" ]]; then |
| 34 | raise_error $error_msg |
| 35 | fi |
| 36 | } |
| 37 | |
| 38 | # asserts_image_running() - Function that verifies if a specific image is running |
| 39 | function asserts_image_running { |
| 40 | local image=$1 |
| 41 | local error_msg=${2:-"There is no process with $image image running"} |
| 42 | |
| 43 | asserts_image $image |
| 44 | if [[ "$(docker ps -q --filter=ancestor=$image 2> /dev/null)" == "" ]]; then |
| 45 | raise_error $error_msg |
| 46 | fi |
| 47 | } |
| 48 | |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 49 | # asserts_image() - Function that verifies if a specific image was created |
| 50 | function asserts_image { |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 51 | local image=$1 |
| 52 | local error_msg=${2:-"There is no $image image"} |
| 53 | |
Victor Morales | 158c18c | 2017-08-06 11:23:15 -0500 | [diff] [blame] | 54 | install_docker |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 55 | if [[ "$(docker images -q $image 2> /dev/null)" == "" ]]; then |
| 56 | raise_error $error_msg |
Victor Morales | 89ce321 | 2017-06-16 18:32:48 -0500 | [diff] [blame] | 57 | fi |
| 58 | } |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 59 | |
| 60 | # asserts_installed_package() - Function that verifies if a specific package was installed. |
| 61 | function asserts_installed_package { |
| 62 | local package=$1 |
| 63 | local error_msg=${2:-"$package wasn't installed"} |
| 64 | |
| 65 | if ! is_package_installed $package; then |
| 66 | raise_error $error_msg |
| 67 | fi |
| 68 | } |
| 69 | |
| 70 | # asserts_file_exist() - Function that verifies if a specific file exists |
| 71 | function asserts_file_exist { |
| 72 | local file=$1 |
| 73 | local error_msg=${2:-"$file doesn't exist"} |
| 74 | |
| 75 | if [ ! -f $file ]; then |
| 76 | raise_error $error_msg |
| 77 | fi |
| 78 | } |
| 79 | |
Nate Potter | fdf88f3 | 2018-01-17 09:29:35 -0800 | [diff] [blame^] | 80 | # asserts_env_set() - Function that verities that an environment variable is set |
| 81 | function asserts_env_set { |
| 82 | local variable=$1 |
| 83 | local error_msg=${2:-"$variable wasn't set"} |
| 84 | |
| 85 | if [ -z ${variable+x} ]; then |
| 86 | raise_error $error_msg |
| 87 | fi |
| 88 | } |
| 89 | |
Victor Morales | dd07480 | 2017-07-26 16:06:35 -0500 | [diff] [blame] | 90 | # raise_error() - Function that prints and exits the execution |
| 91 | function raise_error { |
| 92 | echo $@ |
| 93 | exit 1 |
| 94 | } |