summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/inspector.py12
-rw-r--r--tests/nova_force_down.py60
-rwxr-xr-xtests/run.sh2
3 files changed, 72 insertions, 2 deletions
diff --git a/tests/inspector.py b/tests/inspector.py
index c643210..c796283 100644
--- a/tests/inspector.py
+++ b/tests/inspector.py
@@ -15,6 +15,8 @@ import os
import novaclient.client as novaclient
+import nova_force_down
+
class DoctorInspectorSample(object):
@@ -34,7 +36,15 @@ class DoctorInspectorSample(object):
opts = {'all_tenants': True, 'host': hostname}
for server in self.nova.servers.list(detailed=False, search_opts=opts):
self.nova.servers.reset_state(server, 'error')
- self.nova.services.force_down(hostname, 'nova-compute', True)
+
+ # NOTE: We use our own client here instead of this novaclient for a
+ # workaround. Once keystone provides v2.1 nova api endpoint
+ # in the service catalog which is configured by OpenStack
+ # installer, we can use this:
+ #
+ # self.nova.services.force_down(hostname, 'nova-compute', True)
+ #
+ nova_force_down.force_down(hostname)
app = Flask(__name__)
diff --git a/tests/nova_force_down.py b/tests/nova_force_down.py
new file mode 100644
index 0000000..bb10e9e
--- /dev/null
+++ b/tests/nova_force_down.py
@@ -0,0 +1,60 @@
+##############################################################################
+# 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
+import json
+import os
+
+from keystoneclient.v2_0 import client
+import requests
+
+
+def force_down(hostname, force_down=True):
+ keystone = client.Client(username=os.environ['OS_USERNAME'],
+ password=os.environ['OS_PASSWORD'],
+ tenant_name=os.environ['OS_TENANT_NAME'],
+ auth_url=os.environ['OS_AUTH_URL'])
+
+ for service in keystone.auth_ref['serviceCatalog']:
+ if service['type'] == 'compute':
+ base_url = service['endpoints'][0]['internalURL']
+ break
+
+ url = '%s/os-services/force-down' % base_url.replace('/v2/', '/v2.1/')
+ data = {
+ 'forced_down': force_down,
+ 'binary': 'nova-compute',
+ 'host': hostname,
+ }
+ headers = {
+ 'Content-Type': 'application/json',
+ 'Accept': 'application/json',
+ 'X-Auth-Token': keystone.auth_ref['token']['id'],
+ 'X-OpenStack-Nova-API-Version': 2.11,
+ }
+
+ print requests.put(url, data=json.dumps(data), headers=headers)
+
+
+def get_args():
+ parser = argparse.ArgumentParser(description='Doctor Test Cleaner')
+ parser.add_argument('hostname', metavar='HOSTNAME', type=str, nargs='?',
+ help='a nova-compute hostname to force down')
+ parser.add_argument('--unset', action='store_true', default=False,
+ help='unset force_down flag')
+ return parser.parse_args()
+
+
+def main():
+ args = get_args()
+ force_down(args.hostname, not(args.unset))
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/run.sh b/tests/run.sh
index 9bd6573..167a16b 100755
--- a/tests/run.sh
+++ b/tests/run.sh
@@ -164,7 +164,7 @@ cleanup() {
ssh $ssh_opts_cpu "heat-admin@$COMPUTE_IP" \
"[ -e disable_network.log ] && cat disable_network.log"
- python ./clean.py
+ python ./nova_force_down.py "$COMPUTE_HOST" --unset
sleep 1
nova delete "$VM_NAME"
sleep 1