From 17e138735d78e7e0aedc8338cd92b4ff20454874 Mon Sep 17 00:00:00 2001 From: Bryan Sullivan Date: Wed, 12 Oct 2016 22:52:10 -0700 Subject: Add random traffic, traffic rate report, etc JIRA: VES-1 Change-Id: I831dc57d8d42e4582c2db0d1cf6e811c543e5eb4 Signed-off-by: Bryan Sullivan --- tests/blueprints/tosca-vnfd-hello-ves/evel_demo.c | 119 +++++++++++++++++++--- tests/blueprints/tosca-vnfd-hello-ves/start.sh | 29 +++--- tests/utils/setenv.sh | 14 +-- tests/vHello_VES.sh | 38 ++++--- utils/setenv.sh | 16 +-- 5 files changed, 163 insertions(+), 53 deletions(-) diff --git a/tests/blueprints/tosca-vnfd-hello-ves/evel_demo.c b/tests/blueprints/tosca-vnfd-hello-ves/evel_demo.c index 5286bca..b63acfa 100644 --- a/tests/blueprints/tosca-vnfd-hello-ves/evel_demo.c +++ b/tests/blueprints/tosca-vnfd-hello-ves/evel_demo.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "evel.h" #include "evel_demo.h" @@ -37,6 +38,7 @@ *****************************************************************************/ static const struct option long_options[] = { {"help", no_argument, 0, 'h'}, + {"id", required_argument, 0, 'i'}, {"fqdn", required_argument, 0, 'f'}, {"port", required_argument, 0, 'n'}, {"username", required_argument, 0, 'u'}, @@ -48,18 +50,18 @@ static const struct option long_options[] = { /**************************************************************************//** * Definition of short options to the program. *****************************************************************************/ -static const char* short_options = "hf:n:p:t:sc:"; +static const char* short_options = "h:i:f:n:u:p:v:"; /**************************************************************************//** * Basic user help text describing the usage of the application. *****************************************************************************/ static const char* usage_text = "evel_demo [--help]\n" +" --id \n" " --fqdn \n" " --port \n" " --username \n" " --password \n" -" --vmid \n" " [--verbose]\n" "\n" "Agent for the OPNFV VNF Event Stream (VES) vHello_VES test.\n" @@ -67,6 +69,9 @@ static const char* usage_text = " -h Display this usage message.\n" " --help\n" "\n" +" -i The ID of the agent host.\n" +" --id\n" +"\n" " -f The FQDN or IP address to the RESTful API.\n" " --fqdn\n" "\n" @@ -79,9 +84,6 @@ static const char* usage_text = " -p Password for authentication to the RESTful API.\n" " --password\n" "\n" -" -i UUID of the agent host VM.\n" -" --vmid\n" -"\n" " -v Generate much chattier logs.\n" " --verbose\n"; @@ -127,20 +129,20 @@ void report_app_statechange(char *change) EVEL_ERROR("Post failed %d (%s)", evel_rc, evel_error_string()); } else { - EVEL_ERROR("New fault failed"); + EVEL_ERROR("Unable to send new fault report"); } } } /**************************************************************************//** - * Check status of the nginx container. + * Check status of the app container. * * Checks and reports any change in app state. * * param[in] none *****************************************************************************/ -void check_nginx_contaner_state() { - printf("Checking status of nginx container\n"); +void check_app_container_state() { + printf("Checking status of app container\n"); FILE *fp; int status; const int JSON_MAX = 1000; @@ -176,6 +178,92 @@ void check_nginx_contaner_state() { } } +/**************************************************************************//** + * Measure app traffic + * + * Reports transactions per second in the last second. + * + * param[in] none + *****************************************************************************/ +void measure_traffic() { + + printf("Checking app traffic\n"); + EVENT_FAULT * fault = NULL; + EVEL_ERR_CODES evel_rc = EVEL_SUCCESS; + EVENT_MEASUREMENT * measurement = NULL; + FILE *fp; + int status; + char count[10]; + time_t rawtime; + struct tm * timeinfo; + char period [9]; + char cmd [100]; + int concurrent_sessions = 0; + int configured_entities = 0; + double mean_request_latency = 0; + double measurement_interval = 1; + double memory_configured = 0; + double memory_used = 0; + int request_rate; + + time (&rawtime); + timeinfo = localtime (&rawtime); + strftime (period,9,"%H:%M:$S",timeinfo); + + strcpy(cmd, "sudo docker logs vHello | grep -c "); + strncat(cmd, period, 100); + + fp = popen(cmd, "r"); + if (fp == NULL) { + EVEL_ERROR("popen failed to execute command"); + } + + if (fgets(count, 10, fp) != NULL) { + request_rate = atoi(count); + measurement = evel_new_measurement(concurrent_sessions, + configured_entities, mean_request_latency, measurement_interval, + memory_configured, memory_used, request_rate); + + if (measurement != NULL) { + evel_measurement_type_set(measurement, "HTTP request rate"); + evel_measurement_agg_cpu_use_set(measurement, 8.8); + evel_measurement_cpu_use_add(measurement, "cpu1", 11.11); + evel_measurement_cpu_use_add(measurement, "cpu2", 22.22); + evel_measurement_fsys_use_add(measurement,"00-11-22",100.11, 100.22, 33, + 200.11, 200.22, 44); + evel_measurement_fsys_use_add(measurement,"33-44-55",300.11, 300.22, 55, + 400.11, 400.22, 66); + + evel_measurement_latency_add(measurement, 0.0, 10.0, 20); + evel_measurement_latency_add(measurement, 10.0, 20.0, 30); + + evel_measurement_vnic_use_add(measurement, "eth0", 1, 2, + 3, 4, + 5, 6, + 7, 8); + evel_measurement_vnic_use_add(measurement, "eth1", 11, 12, + 13, 14, + 15, 16, + 17, 18); + + evel_rc = evel_post_event((EVENT_HEADER *)measurement); + if (evel_rc != EVEL_SUCCESS) { + EVEL_ERROR("Post Measurement failed %d (%s)", + evel_rc, + evel_error_string()); + } + } + else { + EVEL_ERROR("New Measurement failed"); + } + printf("Processed measurement\n"); + } + status = pclose(fp); + if (status == -1) { + EVEL_ERROR("pclose returned an error"); + } +} + /**************************************************************************//** * Main function. * @@ -190,11 +278,11 @@ int main(int argc, char ** argv) pthread_t thread_id; int option_index = 0; int param = 0; + char * api_vmid = NULL; char * api_fqdn = NULL; int api_port = 0; char * api_username = NULL; char * api_password = NULL; - char * api_vmid = NULL; char * api_path = NULL; char * api_topic = NULL; int api_secure = 0; @@ -228,6 +316,10 @@ int main(int argc, char ** argv) exit(0); break; + case 'i': + api_vmid = optarg; + break; + case 'f': api_fqdn = optarg; break; @@ -244,10 +336,6 @@ int main(int argc, char ** argv) api_password = optarg; break; - case 'i': - api_vmid = optarg; - break; - case 'v': verbose_mode = 1; break; @@ -360,7 +448,8 @@ int main(int argc, char ** argv) EVEL_ERROR("New heartbeat failed"); } - check_nginx_contaner_state(); + check_app_container_state(); + measure_traffic(); /*************************************************************************/ /* MAIN RETRY LOOP. Loop every 10 secs. */ diff --git a/tests/blueprints/tosca-vnfd-hello-ves/start.sh b/tests/blueprints/tosca-vnfd-hello-ves/start.sh index eeaf887..b8f6e14 100755 --- a/tests/blueprints/tosca-vnfd-hello-ves/start.sh +++ b/tests/blueprints/tosca-vnfd-hello-ves/start.sh @@ -19,10 +19,11 @@ # Status: this is a work in progress, under test. # # How to use: -# $ bash start.sh IP ID -# IP: IP address of the collector +# $ bash start.sh ID IP username password # ID: username:password to use in REST -# +# IP: IP address of the collector +# username: Username for Collector RESTful API authentication +# password: Password for Collector RESTful API authentication setup_agent () { echo "$0: Install prerequisites" @@ -36,19 +37,21 @@ setup_agent () { git clone https://github.com/att/evel-library.git echo "$0: Build agent demo" - sed -i -- '/api_secure,/{n;s/.*/ "hello",/}' evel-library/code/evel_demo/evel_demo.c - sed -i -- '/"hello",/{n;s/.*/ "world",/}' evel-library/code/evel_demo/evel_demo.c + sed -i -- "/api_secure,/{n;s/.*/ \"$username\",/}" evel-library/code/evel_demo/evel_demo.c + sed -i -- "/\"hello\",/{n;s/.*/ \"$password\",/}" evel-library/code/evel_demo/evel_demo.c echo "$0: Build agent demo" cd evel-library/bldjobs make export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/ubuntu/evel-library/libs/x86_64 - echo "$0: Start agent demo, repeat every minute" - crontab -l > /tmp/cron - echo "* * * * 1-5 /home/ubuntu/evel-library/output/x86_64/evel_demo --fqdn $COL_IP --port 30000 -v" >> /tmp/cron - crontab /tmp/cron - rm /tmp/cron + nohup ..output/x86_64/evel_demo --id $agent_id --fqdn $collector_ip --port 30000 --username $username --password $password & + +# echo "$0: Start agent demo, repeat every minute" +# crontab -l > /tmp/cron +# echo "* * * * 1-5 /home/ubuntu/evel-library/output/x86_64/evel_demo --id $agent_id --fqdn $collector_ip --port 30000 --username $username --password $password" >> /tmp/cron +# crontab /tmp/cron +# rm /tmp/cron } echo "$0: Setup website and dockerfile" @@ -100,7 +103,9 @@ echo "$0: setup VES event delivery for the nginx server" # id=$(sudo ls /var/lib/docker/containers) # sudo tail -f /var/lib/docker/containers/$id/$id-json.log -export COL_IP=$1 -export COL_ID=$2 +agent_id=$1 +collector_ip=$2 +username=$3 +password=$4 setup_agent diff --git a/tests/utils/setenv.sh b/tests/utils/setenv.sh index 94c0b0b..12df153 100644 --- a/tests/utils/setenv.sh +++ b/tests/utils/setenv.sh @@ -31,8 +31,11 @@ dist=`grep DISTRIB_ID /etc/*-release | awk -F '=' '{print $2}'` +mkdir $1 + +echo "$0: Setup admin-openrc.sh" + if [ "$dist" == "Ubuntu" ]; then - # Ubuntu: assumes JOID-based install, and that this script is being run on the jumphost. echo "$0: Ubuntu-based install" echo "$0: Create the environment file" KEYSTONE_HOST=$(juju status --format=short | awk "/keystone\/0/ { print \$3 }") @@ -45,7 +48,7 @@ export CINDER_HOST=$(juju status --format=short | awk "/cinder\/0/ { print \$3 } export GLANCE_HOST=$(juju status --format=short | awk "/glance\/0/ { print \$3 }") export NEUTRON_HOST=$(juju status --format=short | awk "/neutron-api\/0/ { print \$3 }") export NOVA_HOST=$(juju status --format=short | awk "/nova-cloud-controller\/0/ { print \$3 }") -export JUMPHOST=$(ifconfig brAdm | awk "/inet addr/ { print \$2 }" | sed 's/addr://g') +export HEAT_HOST=$(juju status --format=short | awk "/heat\/0/ { print \$3 }") export OS_USERNAME=admin export OS_PASSWORD=openstack export OS_TENANT_NAME=admin @@ -53,7 +56,7 @@ export OS_AUTH_URL=http://$KEYSTONE_HOST:5000/v2.0 export OS_REGION_NAME=RegionOne EOF else - # Centos: assumes Apex-based install, and that this script is being run on the Undercloud controller VM. + # Centos echo "$0: Centos-based install" echo "$0: Setup undercloud environment so we can get overcloud Controller server address" source ~/stackrc @@ -61,7 +64,6 @@ else export CONTROLLER_HOST1=$(openstack server list | awk "/overcloud-controller-0/ { print \$8 }" | sed 's/ctlplane=//g') echo "$0: Create the environment file" cat <$1/admin-openrc.sh -export HORIZON_HOST=$CONTROLLER_HOST1 export CONGRESS_HOST=$CONTROLLER_HOST1 export KEYSTONE_HOST=$CONTROLLER_HOST1 export CEILOMETER_HOST=$CONTROLLER_HOST1 @@ -69,13 +71,13 @@ export CINDER_HOST=$CONTROLLER_HOST1 export GLANCE_HOST=$CONTROLLER_HOST1 export NEUTRON_HOST=$CONTROLLER_HOST1 export NOVA_HOST=$CONTROLLER_HOST1 -export JUMPHOST=$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1) +export HEAT_HOST=$CONTROLLER_HOST1 EOF cat ~/overcloudrc >>$1/admin-openrc.sh source ~/overcloudrc export OS_REGION_NAME=$(openstack endpoint list | awk "/ nova / { print \$4 }") # sed command below is a workaound for a bug - region shows up twice for some reason - cat <>$1/admin-openrc.sh export OS_REGION_NAME=$OS_REGION_NAME EOF fi diff --git a/tests/vHello_VES.sh b/tests/vHello_VES.sh index 32ac092..5b096c1 100644 --- a/tests/vHello_VES.sh +++ b/tests/vHello_VES.sh @@ -29,8 +29,6 @@ # clean: cleanup after test # collector: attach to the collector VM and run the collector -set -x - trap 'fail' ERR pass() { @@ -228,7 +226,7 @@ EOF echo "$0: start vHello web server in VDU1" ssh -i /tmp/tacker/vHello.pem -x -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$VDU1_IP "sudo chown ubuntu /home/ubuntu" scp -i /tmp/tacker/vHello.pem -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/tacker/blueprints/tosca-vnfd-hello-ves/start.sh ubuntu@$VDU1_IP:/home/ubuntu/start.sh - ssh -i /tmp/tacker/vHello.pem -x -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$VDU1_IP "bash /home/ubuntu/start.sh $VDU2_IP hello:world" + ssh -i /tmp/tacker/vHello.pem -x -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$VDU1_IP "bash /home/ubuntu/start.sh $VDU1_ID $VDU2_IP hello world" echo "$0: verify vHello server is running" apt-get install -y curl @@ -247,16 +245,11 @@ collector () { source /tmp/tacker/admin-openrc.sh echo "$0: find Collector VM IP" - HEAT_ID=$(tacker vnf-show hello-ves | awk "/instance_id/ { print \$4 }") - VDU2_ID=$(openstack stack resource list $HEAT_ID | awk "/VDU2 / { print \$4 }") - VDU2_IP=$(openstack server show $VDU2_ID | awk "/ addresses / { print \$6 }") - VDU2_URL="http://$VUD2_IP:30000" + VDU2_IP=$(openstack server list | awk "/VDU2/ { print \$10 }") - echo "$0: Stop the VES Collector in VDU2 if running" - ssh -i /tmp/tacker/vHello.pem -x -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$VDU2_IP "sudo kill $(ps -ef | grep evel-test-collector | awk '{print $2}')" - - echo "$0: Start the VES Collector in VDU2" - ssh -i /tmp/tacker/vHello.pem -x -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$VDU2_IP << EOF + echo "$0: Start the VES Collector in VDU2 - Stop first if running" + ssh -i /tmp/tacker/vHello.pem -x -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@$VDU2_IP << 'EOF' +sudo kill $(ps -ef | grep evel-test-collector | awk '{print $2}') cd /home/ubuntu/ python evel-test-collector/code/collector/collector.py \ --config evel-test-collector/config/collector.conf \ @@ -265,6 +258,21 @@ python evel-test-collector/code/collector/collector.py \ EOF } +traffic () { + echo "$0: setup OpenStack CLI environment" + source /tmp/tacker/admin-openrc.sh + + echo "$0: find Agent VM IP" + VDU1_IP=$(openstack server list | awk "/VDU1/ { print \$10 }") + + echo "$0: Generate some traffic, somewhat randomly" + while true + do + sleep .0$[ ( $RANDOM % 10 ) + 1 ]s + curl -s http://$VDU1_IP > /dev/null + done +} + stop() { echo "$0: setup OpenStack CLI environment" source /tmp/tacker/admin-openrc.sh @@ -296,7 +304,7 @@ case "$1" in forward_to_container start pass ;; - start|stop|collector) + start|stop) if [[ $# -eq 1 ]]; then forward_to_container $1 else # running inside the tacker container, ready to go @@ -304,6 +312,10 @@ case "$1" in fi pass ;; + collector|traffic) + $1 + pass + ;; clean) echo "$0: Uninstall Tacker and test environment" bash /tmp/tacker/tacker-setup.sh $1 clean diff --git a/utils/setenv.sh b/utils/setenv.sh index 5247b7f..12df153 100644 --- a/utils/setenv.sh +++ b/utils/setenv.sh @@ -31,8 +31,11 @@ dist=`grep DISTRIB_ID /etc/*-release | awk -F '=' '{print $2}'` +mkdir $1 + +echo "$0: Setup admin-openrc.sh" + if [ "$dist" == "Ubuntu" ]; then - # Ubuntu: assumes JOID-based install, and that this script is being run on the jumphost. echo "$0: Ubuntu-based install" echo "$0: Create the environment file" KEYSTONE_HOST=$(juju status --format=short | awk "/keystone\/0/ { print \$3 }") @@ -45,7 +48,7 @@ export CINDER_HOST=$(juju status --format=short | awk "/cinder\/0/ { print \$3 } export GLANCE_HOST=$(juju status --format=short | awk "/glance\/0/ { print \$3 }") export NEUTRON_HOST=$(juju status --format=short | awk "/neutron-api\/0/ { print \$3 }") export NOVA_HOST=$(juju status --format=short | awk "/nova-cloud-controller\/0/ { print \$3 }") -export JUMPHOST=$(ifconfig brAdm | awk "/inet addr/ { print \$2 }" | sed 's/addr://g') +export HEAT_HOST=$(juju status --format=short | awk "/heat\/0/ { print \$3 }") export OS_USERNAME=admin export OS_PASSWORD=openstack export OS_TENANT_NAME=admin @@ -53,15 +56,14 @@ export OS_AUTH_URL=http://$KEYSTONE_HOST:5000/v2.0 export OS_REGION_NAME=RegionOne EOF else - # Centos: assumes Apex-based install, and that this script is being run on the Undercloud controller VM. + # Centos echo "$0: Centos-based install" echo "$0: Setup undercloud environment so we can get overcloud Controller server address" source ~/stackrc echo "$0: Get address of Controller node" export CONTROLLER_HOST1=$(openstack server list | awk "/overcloud-controller-0/ { print \$8 }" | sed 's/ctlplane=//g') echo "$0: Create the environment file" - cat </tmp/VES/admin-openrc.sh -export HORIZON_HOST=$CONTROLLER_HOST1 + cat <$1/admin-openrc.sh export CONGRESS_HOST=$CONTROLLER_HOST1 export KEYSTONE_HOST=$CONTROLLER_HOST1 export CEILOMETER_HOST=$CONTROLLER_HOST1 @@ -69,13 +71,13 @@ export CINDER_HOST=$CONTROLLER_HOST1 export GLANCE_HOST=$CONTROLLER_HOST1 export NEUTRON_HOST=$CONTROLLER_HOST1 export NOVA_HOST=$CONTROLLER_HOST1 -export JUMPHOST=$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1) +export HEAT_HOST=$CONTROLLER_HOST1 EOF cat ~/overcloudrc >>$1/admin-openrc.sh source ~/overcloudrc export OS_REGION_NAME=$(openstack endpoint list | awk "/ nova / { print \$4 }") # sed command below is a workaound for a bug - region shows up twice for some reason - cat <>$1/admin-openrc.sh export OS_REGION_NAME=$OS_REGION_NAME EOF fi -- cgit 1.2.3-korg