summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authordongwenjuan <dong.wenjuan@zte.com.cn>2018-01-10 09:42:05 +0800
committerdongwenjuan <dong.wenjuan@zte.com.cn>2018-01-10 09:42:05 +0800
commitf106c5a12724c684d747cf7f309f0ccc8b86cc61 (patch)
tree43ec5c5aebd19c9ce0838033f5821d89c93f4194 /tests/lib
parent9fd701278bf7d8c5b9451491bcb1a92580adc780 (diff)
remove useless bash code
Change-Id: I530ef7fcdc4f9539517c5a2718e596f77de772a6 Signed-off-by: dongwenjuan <dong.wenjuan@zte.com.cn>
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/inspector32
-rw-r--r--tests/lib/inspectors/congress69
-rw-r--r--tests/lib/inspectors/sample18
-rw-r--r--tests/lib/installer39
-rw-r--r--tests/lib/installers/apex114
-rw-r--r--tests/lib/installers/fuel197
-rw-r--r--tests/lib/installers/local87
-rw-r--r--tests/lib/monitor31
-rw-r--r--tests/lib/monitors/collectd/collectd101
-rw-r--r--tests/lib/monitors/collectd/collectd_plugin.py167
-rw-r--r--tests/lib/monitors/sample/monitor.py124
-rw-r--r--tests/lib/monitors/sample/sample18
12 files changed, 0 insertions, 997 deletions
diff --git a/tests/lib/inspector b/tests/lib/inspector
deleted file mode 100644
index 24221642..00000000
--- a/tests/lib/inspector
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/bash
-
-INSPECTOR_TYPE=${INSPECTOR_TYPE:-sample}
-
-function is_inspector_supported {
- local inspector="$1"
- [[ -f $TOP_DIR/lib/inspectors/$inspector ]]
-}
-
-function is_inspector {
- local inspector="$1"
- [[ $inspector == $INSPECTOR_TYPE ]]
-}
-
-function start_inspector {
- start_inspector_$INSPECTOR_TYPE
-}
-
-function stop_inspector {
- stop_inspector_$INSPECTOR_TYPE
-}
-
-function cleanup_inspector {
- cleanup_inspector_$INSPECTOR_TYPE
-}
-
-
-if ! is_inspector_supported $INSPECTOR_TYPE; then
- die $LINENO "INSPECTOR_TYPE=$INSPECTOR_TYPE is not supported."
-fi
-
-source $TOP_DIR/lib/inspectors/$INSPECTOR_TYPE
diff --git a/tests/lib/inspectors/congress b/tests/lib/inspectors/congress
deleted file mode 100644
index 04825252..00000000
--- a/tests/lib/inspectors/congress
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/bin/bash
-
-function _congress_add_rule {
- name=$1
- policy=$2
- rule=$3
-
- if ! openstack congress policy rule list $policy | grep -q -e "// Name: $name$" ; then
- openstack congress policy rule create --name $name $policy "$rule"
- fi
-}
-
-function _congress_del_rule {
- name=$1
- policy=$2
-
- if openstack congress policy rule list $policy | grep -q -e "^// Name: $name$" ; then
- openstack congress policy rule delete $policy $name
- fi
-}
-
-function _congress_add_rules {
- _congress_add_rule host_down classification \
- 'host_down(host) :-
- doctor:events(hostname=host, type="compute.host.down", status="down")'
-
- _congress_add_rule active_instance_in_host classification \
- 'active_instance_in_host(vmid, host) :-
- nova:servers(id=vmid, host_name=host, status="ACTIVE")'
-
- _congress_add_rule host_force_down classification \
- 'execute[nova:services.force_down(host, "nova-compute", "True")] :-
- host_down(host)'
-
- _congress_add_rule error_vm_states classification \
- 'execute[nova:servers.reset_state(vmid, "error")] :-
- host_down(host),
- active_instance_in_host(vmid, host)'
-}
-
-function start_inspector_congress {
- nova_api_min_version="2.11"
- nova_api_version=$(openstack congress datasource list | \
- grep nova | grep -Po "(?<='api_version': ')[^']*")
- [[ -z $nova_api_version ]] && nova_api_version="2.0"
- if [[ "$nova_api_version" < "$nova_api_min_version" ]]; then
- echo "ERROR: Congress Nova datasource API version < $nova_api_min_version ($nova_api_version)"
- exit 1
- fi
- openstack congress driver list | grep -q " doctor "
- openstack congress datasource list | grep -q " doctor " || {
- openstack congress datasource create doctor doctor
- }
- _congress_add_rules
-
-}
-
-function stop_inspector_congress {
- _congress_del_rule host_force_down classification
- _congress_del_rule error_vm_states classification
- _congress_del_rule active_instance_in_host classification
- _congress_del_rule host_down classification
-
-}
-
-function cleanup_inspector_congress {
- # Noop
- return
-}
diff --git a/tests/lib/inspectors/sample b/tests/lib/inspectors/sample
deleted file mode 100644
index 75d5c022..00000000
--- a/tests/lib/inspectors/sample
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/bash
-
-INSPECTOR_PORT=${INSPECTOR_PORT:-12345}
-
-function start_inspector_sample {
- pgrep -f "python inspector.py" && return 0
- python inspector.py "$INSPECTOR_PORT" > inspector.log 2>&1 &
-}
-
-function stop_inspector_sample {
- pgrep -f "python inspector.py" || return 0
- kill $(pgrep -f "python inspector.py")
-}
-
-function cleanup_inspector_sample {
- # Noop
- return
-}
diff --git a/tests/lib/installer b/tests/lib/installer
deleted file mode 100644
index 13953d28..00000000
--- a/tests/lib/installer
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/bin/bash
-
-INSTALLER_TYPE=${INSTALLER_TYPE:-local}
-ssh_opts="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
-
-function is_installer_supported {
- local installer="$1"
- [[ -f $TOP_DIR/lib/installers/$installer ]]
-}
-
-function is_installer {
- local installer="$1"
- [[ $installer == $INSTALLER_TYPE ]]
-}
-
-function validate_installer_lib {
- local xtrace
- xtrace=$(set +o | grep xtrace)
- set +o xtrace
- for p in COMPUTE_USER ssh_opts_cpu
- do
- die_if_not_set $LINENO $p \
- "Parameter $p for $INSTALLER_TYPE is missing."
- done
- for f in setup_installer get_compute_ip_from_hostname cleanup_installer
- do
- die_if_not_defined $LINENO $f \
- "Mandatory function ${f}() for $INSTALLER_TYPE is missing."
- done
- $xtrace
-}
-
-if ! is_installer_supported $INSTALLER_TYPE; then
- die $LINENO "INSTALLER_TYPE=$INSTALLER_TYPE is not supported."
-fi
-
-source $TOP_DIR/lib/installers/$INSTALLER_TYPE
-
-validate_installer_lib
diff --git a/tests/lib/installers/apex b/tests/lib/installers/apex
deleted file mode 100644
index f7b9624e..00000000
--- a/tests/lib/installers/apex
+++ /dev/null
@@ -1,114 +0,0 @@
-#!/bin/bash
-
-COMPUTE_USER=${COMPUTE_USER:-heat-admin}
-ssh_opts_cpu="$ssh_opts -i instack_key"
-
-function get_installer_ip {
- is_set INSTALLER_IP && return
- INSTALLER_IP=$(get_first_vnic_ip undercloud)
-}
-
-function installer_get_ssh_keys {
- sudo scp $ssh_opts "root@$INSTALLER_IP:/home/stack/.ssh/id_rsa" instack_key
- sudo chown $(whoami):$(whoami) instack_key
- chmod 400 instack_key
-}
-
-function get_controller_ips {
- is_set CONTROLLER_IPS && return
- get_installer_ip
- CONTROLLER_IPS=$(sudo ssh $ssh_opts $INSTALLER_IP \
- "source stackrc
- nova list | grep ' overcloud-controller-[0-9] ' | \
- sed -e 's/^.*ctlplane=//' -e 's/ *|\$//'")
- die_if_not_set $LINENO CONTROLLER_IPS "No controller IPs"
-}
-
-function installer_apply_patches {
- # TODO(r-mibu): fix the followings in upstream (apex)
- for node in $CONTROLLER_IPS;do
- echo "check controller configuration for doctor ($node)"
- ssh $ssh_opts_cpu "heat-admin@$node" '
- set -x
- date
- echo "### apply patches (installer=apex)"
-
- ep_conf=/etc/ceilometer/event_pipeline.yaml
- ep_entry="- notifier://?topic=alarm.all"
- if sudo grep -e "$ep_entry" $ep_conf; then
- echo "NOTE: ceilometer is configured as we needed"
- else
- echo "modify the ceilometer config"
- sudo sed -i -e "$ a \ \ \ \ \ \ \ \ \ \ $ep_entry # added by doctor script" $ep_conf
- sudo systemctl restart openstack-ceilometer-notification.service
- fi
-
- co_conf=/etc/congress/congress.conf
- co_conf_bak=/etc/congress/congress.conf.bak
- co_entry="congress.datasources.doctor_driver.DoctorDriver"
- if sudo grep -e "^drivers.*$co_entry" $co_conf; then
- echo "NOTE: congress is configured as we needed"
- else
- echo "modify the congress config"
- sudo cp $co_conf $co_conf_bak
- sudo sed -i -e "/^drivers/s/$/,$co_entry/" $co_conf
- sudo systemctl restart openstack-congress-server.service
- fi
- ' > installer_apply_patches_$node.log 2>&1
- done
-}
-
-function setup_installer {
- get_installer_ip
- installer_get_ssh_keys
- get_controller_ips
- installer_apply_patches
-
- # NOTE: while executing command as doctor user,
- # 'OS_PROJECT_ID' env parameter make openstack clients confused.
- unset OS_PROJECT_ID
-}
-
-function get_compute_ip_from_hostname {
- local compute_host=$1
-
- compute_host_in_undercloud=${compute_host%%.*}
- COMPUTE_IP=$(sudo ssh $ssh_opts $INSTALLER_IP \
- "source stackrc;
- nova show $compute_host_in_undercloud | \
- awk '/ ctlplane network /{print \$5}'")
- die_if_not_set $LINENO COMPUTE_IP "Could get IP address of $compute_host."
-}
-
-function installer_revert_patches {
- # TODO(r-mibu): fix the followings in upstream (apex)
- get_controller_ips
- for node in $CONTROLLER_IPS;do
- echo "restore controller configuration if touched ($node)"
- ssh $ssh_opts_cpu "heat-admin@$node" '
- set -x
- echo "### revert patches (installer=apex)"
- date
-
- co_conf=/etc/congress/congress.conf
- co_conf_bak=/etc/congress/congress.conf.bak
- if [ -e $co_conf_bak ]; then
- echo "restore the congress config"
- sudo mv $co_conf_bak $co_conf
- sudo systemctl restart openstack-congress-server.service
- fi
-
- ep_conf=/etc/ceilometer/event_pipeline.yaml
- if sudo grep -q -e "# added by doctor script" $ep_conf; then
- echo "modify the ceilometer config"
- sudo sed -ie "/# added by doctor script/d" $ep_conf
- sudo systemctl restart openstack-ceilometer-notification.service
- fi
- ' >> installer_apply_patches_$node.log 2>&1
- done
-}
-
-function cleanup_installer {
- installer_revert_patches
- return
-}
diff --git a/tests/lib/installers/fuel b/tests/lib/installers/fuel
deleted file mode 100644
index 85865720..00000000
--- a/tests/lib/installers/fuel
+++ /dev/null
@@ -1,197 +0,0 @@
-#!/bin/bash
-
-if [[ "congress " == "$INSPECTOR_TYPE" ]]; then
- die $LINENO "fuel does not support congress yet..."
-fi
-
-COMPUTE_USER=${COMPUTE_USER:-root}
-ssh_opts_cpu="$ssh_opts -i instack_key"
-
-function get_installer_ip {
- is_set INSTALLER_IP && return
- INSTALLER_IP=$(get_first_vnic_ip fuel-master)
-}
-
-function get_controller_ips {
- is_set CONTROLLER_IPS && return
- CONTROLLER_IPS=$(ssh $ssh_opts_cpu root@$INSTALLER_IP \
- "fuel node | grep controller | cut -d '|' -f 5|xargs")
- die_if_not_set $LINENO CONTROLLER_IPS "No controller IPs"
-}
-
-function installer_get_ssh_keys {
- if [[ -e instack_key ]]; then
- echo "test existing instack_key..."
- ssh $ssh_opts_cpu root@${INSTALLER_IP} "hostname" && return
- fi
- echo "getting instack_key from fuel node..."
- sshpass -p r00tme scp $ssh_opts root@${INSTALLER_IP}:.ssh/id_rsa instack_key
- sudo chown $(whoami):$(whoami) instack_key
- chmod 400 instack_key
-}
-
-function installer_apply_patches {
- # TODO(r-mibu): fix the followings in upstream (fuel)
- for node in $CONTROLLER_IPS;do
- echo "check controller configuration for doctor ($node)"
- ssh $ssh_opts_cpu "root@$node" '
- set -x
- date
- echo "### apply patches (installer=fuel)"
-
- ep_conf=/etc/ceilometer/event_pipeline.yaml
- entry="- notifier://?topic=alarm.all"
- if ! grep -q -e "$entry" $ep_conf; then
- echo "modify the ceilometer config"
- echo " $entry # added by doctor script" >> $ep_conf
- service ceilometer-agent-notification restart
- fi
-
- # TODO(r-mibu): enable this section once congress 4.0.0 is available
- if false; then
- co_conf=/etc/congress/congress.conf
- entry="congress.datasources.doctor_driver.DoctorDriver"
- if ! grep -q -e "^drivers.*$entry" $co_conf; then
- echo "modify the congress config"
- sed -i -e "/^drivers/s/$/,$entry # added by doctor script/" \
- $co_conf
- service congress-server restart
- fi
-
- rule="-m multiport -p tcp --dports 1789"
- rule+=" -m comment --comment doctor-congress"
- rule+=" -j ACCEPT"
- if ! iptables -C INPUT $rule; then
- iptables -I INPUT $rule
- fi
-
- ha_conf=/etc/haproxy/conf.d/180-congress.cfg
- if [[ ! -e $ha_conf ]]; then
- sed -e "1i# generated by doctor script" \
- -e "s/9696/1789/" \
- -e "s/neutron/congress/" \
- /etc/haproxy/conf.d/085-neutron.cfg > $ha_conf
- ip netns exec haproxy /usr/lib/ocf/resource.d/fuel/ns_haproxy restart
- fi
- fi
-
- np_conf=/etc/nova/policy.json
- if [ -e $np_conf ]; then
- entry="os_compute_api:servers:show:host_status"
- new="rule:admin_or_owner"
- np_backup="${np_conf}-doctor-saved"
- if grep -q "${entry}.*${new}" $np_conf; then
- echo "Not modifying nova policy"
- elif grep -q "${entry}" $np_conf; then
- echo "modify nova policy"
- cp $np_conf $np_backup
- oldline=$(grep "$entry" $np_conf)
- newline=$(echo "$oldline" | sed "s/rule.*\"/$new\"/")
- sed -i "s/$oldline/$newline/" $np_conf
- service nova-api restart
- else
- echo "add nova policy"
- cp $np_conf $np_backup
- sed -i "/{/a \ \"${entry}\": \"$new\"" $np_conf
- service nova-api restart
- fi
- else
- # policy.json does not exist in Ocata.
- echo "$np_conf does not exist. Creating new one."
- echo -e "{\n \"context_is_admin\": \"role:admin\"," > $np_conf
- echo -e " \"owner\" : \"user_id:%(user_id)s\"," >> $np_conf
- echo -e " \"admin_or_owner\": \"rule:context_is_admin or rule:owner\"," >> $np_conf
- echo -e " \"os_compute_api:servers:show:host_status\": \"rule:admin_or_owner\" \n}" >> $np_conf
- np_rm="${np_conf}-doctor-rm"
- cp $np_conf $np_rm
- service nova-api restart
- fi
- ' > installer_apply_patches_$node.log 2>&1
- done
-}
-
-function setup_installer {
- get_installer_ip
- installer_get_ssh_keys
- get_controller_ips
- installer_apply_patches
- #Might take a moment for nova-api to restart
- sleep 20
- if ! openstack flavor show $VM_FLAVOR ; then
- openstack flavor create --ram 512 --disk 1 $VM_FLAVOR \
- && touch created_doctor_flavor
- fi
-}
-
-function get_compute_ip_from_hostname {
- local compute_host=$1
-
- compute_host_in_undercloud=${compute_host%%.*}
- node_id=$(echo $compute_host_in_undercloud | cut -d "-" -f 2)
- COMPUTE_IP=$(sshpass -p r00tme ssh 2>/dev/null $ssh_opts root@${INSTALLER_IP} \
- "fuel node|awk -F '|' -v id=$node_id '{if (\$1 == id) print \$5}' |xargs")
- die_if_not_set $LINENO COMPUTE_IP "Could get IP address of $compute_host."
-}
-
-function installer_revert_patches {
- # TODO(r-mibu): fix the followings in upstream (fuel)
- get_controller_ips
- for node in $CONTROLLER_IPS;do
- echo "restore controller configuration if touched ($node)"
- ssh $ssh_opts_cpu "root@$node" '
- set -x
- echo "### revert patches (installer=fuel)"
- date
-
- # TODO(r-mibu): enable this section once congress 4.0.0 is available
- if false; then
- ha_conf=/etc/haproxy/conf.d/180-congress.cfg
- if grep -q "# generated by doctor script" $ha_conf; then
- rm -f $ha_conf
- ip netns exec haproxy /usr/lib/ocf/resource.d/fuel/ns_haproxy restart
- fi
-
- rule="-m multiport -p tcp --dports 1789"
- rule+=" -m comment --comment doctor-congress"
- rule+=" -j ACCEPT"
- if iptables -C INPUT $rule; then
- iptables -D INPUT $rule
- fi
-
- co_conf=/etc/congress/congress.conf
- entry="congress.datasources.doctor_driver.DoctorDriver"
- if grep -q -e "^drivers.*$entry # added by doctor script" $co_conf; then
- echo "modify the congress config"
- sed -i -e "/^drivers/s/^\(.*\),$entry/\1/" $co_conf
- service congress-server restart
- fi
- fi
-
- ep_conf=/etc/ceilometer/event_pipeline.yaml
- if grep -q "# added by doctor script" $ep_conf; then
- sed -ie "/# added by doctor script/d" $ep_conf
- service ceilometer-agent-notification restart
- fi
-
- np_conf=/etc/nova/policy.json
- np_backup="${np_conf}-doctor-saved"
- np_rm="${np_conf}-doctor-rm"
- if [ -e $np_backup ]; then
- cp -f $np_backup $np_conf
- rm $np_backup
- service nova-api restart
- elif [ -e $np_rm ]; then
- rm $np_conf
- rm $np_rm
- service nova-api restart
- fi
- ' >> installer_apply_patches_$node.log 2>&1
- done
-}
-
-function cleanup_installer {
- if [[ -e created_doctor_flavor ]] && openstack flavor show $VM_FLAVOR ; then
- openstack flavor delete $VM_FLAVOR && rm -f created_doctor_flavor
- fi
- installer_revert_patches
-}
diff --git a/tests/lib/installers/local b/tests/lib/installers/local
deleted file mode 100644
index d628867a..00000000
--- a/tests/lib/installers/local
+++ /dev/null
@@ -1,87 +0,0 @@
-#!/bin/bash
-
-COMPUTE_USER=${COMPUTE_USER:-$(whoami)}
-ssh_opts_cpu="$ssh_opts"
-
-function installer_get_ssh_keys {
- echo "INSTALLER_TYPE set to 'local'. Assuming SSH keys already exchanged with $COMPUTE_HOST"
- return
-}
-
-function installer_apply_patches {
- set -x
- date
- echo "### apply patches (installer=local)"
- np_conf=/etc/nova/policy.json
- if [ -e $np_conf ]; then
- entry="os_compute_api:servers:show:host_status"
- new="rule:admin_or_owner"
- np_backup="${np_conf}-doctor-saved"
- if grep -q "${entry}.*${new}" $np_conf; then
- echo "Not modifying nova policy"
- elif grep -q "${entry}" $np_conf; then
- echo "modify nova policy"
- cp $np_conf $np_backup
- oldline=$(grep "$entry" $np_conf)
- newline=$(echo "$oldline" | sed "s/rule.*\"/$new\"/")
- sed -i "s/$oldline/$newline/" $np_conf
- # TODO(umar): Update to systemd when screen is no more used for devstack
- screen -S stack -p n-api -X stuff "^C^M^[[A^M" # restart n-api service
- else
- echo "add nova policy"
- cp $np_conf $np_backup
- sed -i "/{/a \ \"${entry}\": \"$new\"" $np_conf
- screen -S stack -p n-api -X stuff "^C^M^[[A^M"
- fi
- else
- # policy.json does not exist in Ocata.
- echo "$np_conf does not exist. Creating a new one"
- echo -e '{\n "context_is_admin": "role:admin",' > $np_conf
- echo -e ' "owner" : "user_id:%(user_id)s",' >> $np_conf
- echo -e ' "admin_or_owner": "rule:context_is_admin or rule:owner",' >> $np_conf
- echo -e ' "os_compute_api:servers:show:host_status": "rule:admin_or_owner"\n}' >> $np_conf
- np_rm="${np_conf}-doctor-rm"
- cp $np_conf $np_rm
- screen -S stack -p n-api -X stuff "^C^M^[[A^M"
- fi
-
- return
-}
-
-function setup_installer {
- installer_get_ssh_keys
- installer_apply_patches
-}
-
-function get_compute_ip_from_hostname {
- local compute_host=$1
-
- if is_set COMPUTE_IP; then
- echo "Using pre-configured COMPUTE_IP=$COMPUTE_IP ..."
- return
- fi
- COMPUTE_IP=$(getent hosts "$compute_host" | awk '{ print $1 }')
- die_if_not_set $LINENO COMPUTE_IP \
- "Could not resolve $compute_host. Either manually set COMPUTE_IP or enable DNS resolution."
-}
-
-function cleanup_installer {
- set -x
- echo "### revert patches (installer=local)"
- date
-
- np_conf=/etc/nova/policy.json
- np_backup="${np_conf}-doctor-saved"
- np_rm="${np_conf}-doctor-rm"
- if [ -e $np_backup ]; then
- cp -f $np_backup $np_conf
- rm $np_backup
- screen -S stack -p n-api -X stuff "^C^M^[[A^M"
- elif [ -e $np_rm ]; then
- rm $np_conf
- rm $np_rm
- screen -S stack -p n-api -X stuff "^C^M^[[A^M"
- fi
-
- return
-}
diff --git a/tests/lib/monitor b/tests/lib/monitor
deleted file mode 100644
index 6b804ec2..00000000
--- a/tests/lib/monitor
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/bin/bash
-
-MONITOR_TYPE=${MONITOR_TYPE:-sample}
-
-function is_monitor_supported {
- local monitor="$1"
- [[ -f $TOP_DIR/lib/monitors/$monitor/$monitor ]]
-}
-
-function is_monitor {
- local monitor="$1"
- [[ $monitor == $MONITOR_TYPE ]]
-}
-
-function start_monitor {
- start_monitor_$MONITOR_TYPE
-}
-
-function stop_monitor {
- stop_monitor_$MONITOR_TYPE
-}
-
-function cleanup_monitor {
- cleanup_monitor_$MONITOR_TYPE
-}
-
-if ! is_monitor_supported $MONITOR_TYPE; then
- die $LINENO "MONITOR_TYPE=$MONITOR_TYPE is not supported."
-fi
-
-source $TOP_DIR/lib/monitors/$MONITOR_TYPE/$MONITOR_TYPE
diff --git a/tests/lib/monitors/collectd/collectd b/tests/lib/monitors/collectd/collectd
deleted file mode 100644
index f5096658..00000000
--- a/tests/lib/monitors/collectd/collectd
+++ /dev/null
@@ -1,101 +0,0 @@
-#!/bin/bash
-
-function start_monitor_collectd {
- ## CONTROL_IP is the IP of primary interface of control node i.e.
- ## eth0, eno1. It is used by collectd monitor to communicate with
- ## sample inspector.
- ## @TODO (umar) see if mgmt IP of control is a better option. Also
- ## primary interface may not be the right option
- CONTROL_IP="$(ip a | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p' | sed -n 1p)"
- #CONTROL_IP=192.168.98.6
-
- echo "
-Hostname \"$COMPUTE_HOST\"
-FQDNLookup false
-Interval 1
-MaxReadInterval 2
-
-<LoadPlugin python>
- Globals true
-</LoadPlugin>
-LoadPlugin ovs_events
-LoadPlugin logfile
-
-<Plugin logfile>
- File \"/var/log/collectd.log\"
- Timestamp true
- LogLevel \"info\"
-</Plugin>
-
-<Plugin python>
- ModulePath \"/home/$COMPUTE_USER\"
- LogTraces true
- Interactive false
- Import \"collectd_plugin\"
- <Module \"collectd_plugin\">
- control_ip \"$CONTROL_IP\"
- compute_ip \"$COMPUTE_IP\"
- compute_host \"$COMPUTE_HOST\"
- compute_user \"$COMPUTE_USER\"
- inspector_type \"$INSPECTOR_TYPE\"
- os_auth_url \"$OS_AUTH_URL\"
- os_username \"$OS_USERNAME\"
- os_password \"$OS_PASSWORD\"
- os_project_name \"$OS_PROJECT_NAME\"
- os_user_domain_name \"$OS_USER_DOMAIN_NAME\"
- os_user_domain_id \"$OS_USER_DOMAIN_ID\"
- os_project_domain_name \"$OS_PROJECT_DOMAIN_NAME\"
- os_project_domain_id \"$OS_PROJECT_DOMAIN_ID\"
- </Module>
-</Plugin>
-
-<Plugin ovs_events>
- Port 6640
- Socket \"/var/run/openvswitch/db.sock\"
- Interfaces \"@INTERFACE_NAME@\"
- SendNotification true
- DispatchValues false
-</Plugin>
-
-" > $TOP_DIR/lib/monitors/collectd.conf
-
- scp $ssh_opts_cpu $TOP_DIR/lib/monitors/collectd.conf $COMPUTE_USER@$COMPUTE_IP:
- ## @TODO (umar) Always assuming that the interface is assigned an IP if
- ## interface name is not provided. See if there is a better approach
- ssh $ssh_opts_cpu "$COMPUTE_USER@$COMPUTE_IP" "
- if [ -n \"$INTERFACE_NAME\" ]; then
- dev=$INTERFACE_NAME
- else
- dev=\$(sudo ip a | awk '/ $COMPUTE_IP\//{print \$NF}')
- fi
- sed -i -e \"s/@INTERFACE_NAME@/\$dev/\" collectd.conf
- collectd_conf=/opt/collectd/etc/collectd.conf
- if [ -e \$collectd_conf ]; then
- sudo cp \$collectd_conf \${collectd_conf}-doctor-saved
- else
- sudo touch \${collectd_conf}-doctor-created
- fi
- sudo mv collectd.conf /opt/collectd/etc/collectd.conf"
-
- scp $ssh_opts_cpu $TOP_DIR/lib/monitors/collectd/collectd_plugin.py $COMPUTE_USER@$COMPUTE_IP:collectd_plugin.py
- ssh $ssh_opts_cpu "$COMPUTE_USER@$COMPUTE_IP" "sudo pkill collectd
- sudo /opt/collectd/sbin/collectd"
-}
-
-function stop_monitor_collectd {
- ssh $ssh_opts_cpu "$COMPUTE_USER@$COMPUTE_IP" 'sudo pkill collectd'
-}
-
-function cleanup_monitor_collectd {
- ssh $ssh_opts_cpu "$COMPUTE_USER@$COMPUTE_IP" "
- collectd_conf=/opt/collectd/etc/collectd.conf
- if [ -e \"\${collectd_conf}-doctor-created\" ]; then
- sudo rm \"\${collectd_conf}-doctor-created\"
- sudo rm \$collectd_conf
- elif [ -e \"\${collectd_conf}-doctor-saved\" ]; then
- sudo cp -f \"\${collectd_conf}-doctor-saved\" \$collectd_conf
- sudo rm \"\${collectd_conf}-doctor-saved\"
- fi"
-
- rm $TOP_DIR/lib/monitors/collectd.conf
-}
diff --git a/tests/lib/monitors/collectd/collectd_plugin.py b/tests/lib/monitors/collectd/collectd_plugin.py
deleted file mode 100644
index 70fcf26e..00000000
--- a/tests/lib/monitors/collectd/collectd_plugin.py
+++ /dev/null
@@ -1,167 +0,0 @@
-##############################################################################
-# Copyright (c) 2017 NEC Corporation and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-import collectd
-import sys
-from netifaces import interfaces, ifaddresses, AF_INET
-from datetime import datetime
-import json
-import requests
-import time
-from requests.exceptions import ConnectionError
-
-from keystoneauth1 import loading
-from keystoneauth1 import session
-from congressclient.v1 import client
-
-
-def write_debug(str_write, write_type, compute_user):
- file_name = ('/home/%s/monitor.log' % compute_user)
- file_tmp = open(file_name, write_type)
- file_tmp.write( "%s" % str_write)
- file_tmp.close()
-
-
-class DoctorMonitorCollectd(object):
- def __init__(self):
- self.control_ip = ''
- self.compute_user = ''
- self.compute_ip = ''
- self.host_name = ''
- self.inspector_type = ''
- self.inspector_url = ''
- self.os_auth_url = ''
- self.os_username = ''
- self.os_password = ''
- self.os_project_name = ''
- self.os_user_domain_name = ''
- self.os_user_domain_id = ''
- self.os_project_domain_name = ''
- self.os_project_domain_id = ''
- self.sess = ''
- self.auth = ''
- self.inspector_notified = 0
- self.start_notifications = 0
- self.monitor_type = 'sample'
-
- def config_func(self, config):
- for node in config.children:
- key = node.key.lower()
- val = node.values[0]
-
- if key == 'compute_host':
- self.host_name = val
- elif key == 'control_ip':
- self.control_ip = val
- elif key == 'compute_ip':
- self.compute_ip = val
- elif key == 'compute_user':
- self.compute_user = val
- elif key == 'inspector_type':
- self.inspector_type = val
- elif key == 'os_auth_url':
- self.os_auth_url = val
- elif key == 'os_username':
- self.os_username = val
- elif key == 'os_password':
- self.os_password = val
- elif key == 'os_project_name':
- self.os_project_name = val
- elif key == 'os_user_domain_name':
- self.os_user_domain_name = val
- elif key == 'os_user_domain_id':
- self.os_user_domain_id = val
- elif key == 'os_project_domain_name':
- self.os_project_domain_name = val
- elif key == 'os_project_domain_id':
- self.os_project_domain_id = val
- else:
- collectd.info('Unknown config key "%s"' % key)
-
- def init_collectd(self):
- write_debug("Compute node collectd monitor start at %s\n\n" % datetime.now().isoformat(), "w", self.compute_user)
-
- if self.inspector_type == 'sample':
- self.inspector_url = ('http://%s:12345/events' % self.control_ip)
- elif self.inspector_type == 'congress':
- loader = loading.get_plugin_loader('password')
- self.auth = loader.load_from_options(auth_url=self.os_auth_url,
- username=self.os_username,
- password=self.os_password,
- project_name=self.os_project_name,
- user_domain_name=self.os_user_domain_name,
- user_domain_id=self.os_user_domain_id,
- project_domain_name=self.os_project_domain_name,
- project_domain_id=self.os_project_domain_id)
- self.sess=session.Session(auth=self.auth)
- congress = client.Client(session=self.sess, service_type='policy')
- ds = congress.list_datasources()['results']
- doctor_ds = next((item for item in ds if item['driver'] == 'doctor'),
- None)
-
- congress_endpoint = congress.httpclient.get_endpoint(auth=self.auth)
- self.inspector_url = ('%s/v1/data-sources/%s/tables/events/rows' %
- (congress_endpoint, doctor_ds['id']))
- else:
- sys.exit()
- self.start_notifications = 1
-
-
- def notify_inspector(self):
- event_type = "compute.host.down"
- payload = [
- {
- 'id': ("monitor_%s_id1" % self.monitor_type),
- 'time': datetime.now().isoformat(),
- 'type': event_type,
- 'details': {
- 'hostname': self.host_name,
- 'status': 'down',
- 'monitor': ("monitor_%s" % self.monitor_type),
- 'monitor_event_id': ("monitor_%s_event1" % self.monitor_type)
- },
- },
- ]
- data = json.dumps(payload)
- self.inspector_notified = 1
-
- if self.inspector_type == 'sample':
- headers = {'content-type': 'application/json'}
- try:
- requests.post(self.inspector_url, data=data, headers=headers)
- except ConnectionError as err:
- print err
- elif self.inspector_type == 'congress':
- # TODO(umar) enhance for token expiry case
- headers = {
- 'Content-Type': 'application/json',
- 'Accept': 'application/json',
- 'X-Auth-Token': self.sess.get_token()
- }
- requests.put(self.inspector_url, data=data, headers=headers)
-
-
- def handle_notif(self, notification, data=None):
- if (notification.severity == collectd.NOTIF_FAILURE or
- notification.severity == collectd.NOTIF_WARNING):
- if (self.start_notifications == 1 and self.inspector_notified == 0):
- write_debug("Received down notification: doctor monitor detected at %s\n" % time.time(), "a", self.compute_user)
- self.notify_inspector()
-
- elif notification.severity == collectd.NOTIF_OKAY:
- collectd.info("Interface status: UP again %s\n" % time.time())
- else:
- collectd.info("Unknown notification severity %s\n" % notification.severity)
-
-
-monitor = DoctorMonitorCollectd()
-
-collectd.register_config(monitor.config_func)
-collectd.register_init(monitor.init_collectd)
-collectd.register_notification(monitor.handle_notif)
diff --git a/tests/lib/monitors/sample/monitor.py b/tests/lib/monitors/sample/monitor.py
deleted file mode 100644
index 7450c534..00000000
--- a/tests/lib/monitors/sample/monitor.py
+++ /dev/null
@@ -1,124 +0,0 @@
-##############################################################################
-# Copyright (c) 2016 NEC Corporation and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-import argparse
-from datetime import datetime
-import json
-import logger as doctor_log
-import requests
-import socket
-import time
-
-from keystoneauth1 import session
-from congressclient.v1 import client
-
-import identity_auth
-
-# NOTE: icmp message with all zero data (checksum = 0xf7ff)
-# see https://tools.ietf.org/html/rfc792
-ICMP_ECHO_MESSAGE = '\x08\x00\xf7\xff\x00\x00\x00\x00'
-
-SUPPORTED_INSPECTOR_TYPES = ['sample', 'congress']
-
-LOG = doctor_log.Logger('doctor_monitor').getLogger()
-
-
-class DoctorMonitorSample(object):
-
- interval = 0.1 # second
- timeout = 0.1 # second
- event_type = "compute.host.down"
-
- def __init__(self, args):
- if args.inspector_type not in SUPPORTED_INSPECTOR_TYPES:
- raise Exception("Inspector type '%s' not supported", args.inspector_type)
-
- self.hostname = args.hostname
- self.inspector_type = args.inspector_type
- self.ip_addr = args.ip or socket.gethostbyname(self.hostname)
-
- if self.inspector_type == 'sample':
- self.inspector_url = 'http://127.0.0.1:12345/events'
- elif self.inspector_type == 'congress':
- auth=identity_auth.get_identity_auth()
- self.session=session.Session(auth=auth)
- congress = client.Client(session=self.session, service_type='policy')
- ds = congress.list_datasources()['results']
- doctor_ds = next((item for item in ds if item['driver'] == 'doctor'),
- None)
-
- congress_endpoint = congress.httpclient.get_endpoint(auth=auth)
- self.inspector_url = ('%s/v1/data-sources/%s/tables/events/rows' %
- (congress_endpoint, doctor_ds['id']))
-
- def start_loop(self):
- LOG.debug("start ping to host %(h)s (ip=%(i)s)" % {'h': self.hostname,
- 'i': self.ip_addr})
- sock = socket.socket(socket.AF_INET, socket.SOCK_RAW,
- socket.IPPROTO_ICMP)
- sock.settimeout(self.timeout)
- while True:
- try:
- sock.sendto(ICMP_ECHO_MESSAGE, (self.ip_addr, 0))
- data = sock.recv(4096)
- except socket.timeout:
- LOG.info("doctor monitor detected at %s" % time.time())
- self.report_error()
- LOG.info("ping timeout, quit monitoring...")
- return
- time.sleep(self.interval)
-
- def report_error(self):
- payload = [
- {
- 'id': 'monitor_sample_id1',
- 'time': datetime.now().isoformat(),
- 'type': self.event_type,
- 'details': {
- 'hostname': self.hostname,
- 'status': 'down',
- 'monitor': 'monitor_sample',
- 'monitor_event_id': 'monitor_sample_event1'
- },
- },
- ]
- data = json.dumps(payload)
-
- if self.inspector_type == 'sample':
- headers = {'content-type': 'application/json'}
- requests.post(self.inspector_url, data=data, headers=headers)
- elif self.inspector_type == 'congress':
- headers = {
- 'Content-Type': 'application/json',
- 'Accept': 'application/json',
- 'X-Auth-Token':self.session.get_token(),
- }
- requests.put(self.inspector_url, data=data, headers=headers)
-
-
-def get_args():
- parser = argparse.ArgumentParser(description='Doctor Sample Monitor')
- parser.add_argument('hostname', metavar='HOSTNAME', type=str, nargs='?',
- help='a hostname to monitor connectivity')
- parser.add_argument('ip', metavar='IP', type=str, nargs='?',
- help='an IP address to monitor connectivity')
- parser.add_argument('inspector_type', metavar='INSPECTOR_TYPE', type=str, nargs='?',
- help='inspector to report',
- default='sample')
- return parser.parse_args()
-
-
-def main():
- args = get_args()
- monitor = DoctorMonitorSample(args)
- monitor.start_loop()
-
-
-if __name__ == '__main__':
- main()
diff --git a/tests/lib/monitors/sample/sample b/tests/lib/monitors/sample/sample
deleted file mode 100644
index 1d310333..00000000
--- a/tests/lib/monitors/sample/sample
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/bash
-
-function start_monitor_sample {
- cp $TOP_DIR/lib/monitors/sample/monitor.py $TOP_DIR/monitor.py
- pgrep -f "python monitor.py" && return 0
- sudo -E python monitor.py "$COMPUTE_HOST" "$COMPUTE_IP" "$INSPECTOR_TYPE" \
- > monitor.log 2>&1 &
-}
-
-function stop_monitor_sample {
- pgrep -f "python monitor.py" || return 0
- sudo kill $(pgrep -f "python monitor.py")
-}
-
-function cleanup_monitor_sample {
- rm monitor.py
- return
-}