summaryrefslogtreecommitdiffstats
path: root/tests/lib/inspectors/congress
diff options
context:
space:
mode:
authorCarlos Goncalves <carlos.goncalves@neclab.eu>2016-11-30 13:08:20 +0000
committerCarlos Goncalves <carlos.goncalves@neclab.eu>2016-12-14 16:12:13 +0000
commit18651c07b942abf0060e6478758050dd365619eb (patch)
tree201428ea4fc2a2f1eeb2e5dda0ffd5f0b050a904 /tests/lib/inspectors/congress
parent40cba233d16e355b078e368772ad4aadbb5f91b1 (diff)
Refactor inspectors support code
JIRA: DOCTOR-71 Change-Id: I0913d4d0390325cc0cc715572b7525a6bbb795d3 Signed-off-by: Carlos Goncalves <carlos.goncalves@neclab.eu>
Diffstat (limited to 'tests/lib/inspectors/congress')
-rw-r--r--tests/lib/inspectors/congress69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/lib/inspectors/congress b/tests/lib/inspectors/congress
new file mode 100644
index 00000000..04825252
--- /dev/null
+++ b/tests/lib/inspectors/congress
@@ -0,0 +1,69 @@
+#!/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
+}