test: fix bugs (ssh args and force-down in cleanup) 25/10325/1
authorRyota MIBU <r-mibu@cq.jp.nec.com>
Sat, 20 Feb 2016 04:08:30 +0000 (13:08 +0900)
committerRyota Mibu <r-mibu@cq.jp.nec.com>
Sat, 20 Feb 2016 04:17:46 +0000 (04:17 +0000)
This patch fixes two bugs:

- ssh target hostname is wrong (it trailing by ':')

- novaclient cannot execute 'force-down' since it tries
  to use v2.0 endpoint which doesn't spport the new API,

Change-Id: I5ef3a8eda5fa7a6730b4eb456d0441d40718a010
Signed-off-by: Ryota MIBU <r-mibu@cq.jp.nec.com>
(cherry picked from commit e891316ac35f062c66b15a7ee7981016c6edcc9e)

tests/clean.py [new file with mode: 0644]
tests/run.sh

diff --git a/tests/clean.py b/tests/clean.py
new file mode 100644 (file)
index 0000000..af966ae
--- /dev/null
@@ -0,0 +1,45 @@
+##############################################################################
+# 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
+
+import novaclient.client as novaclient
+
+
+nova_api_version = 2.11
+
+def enable_compute_host(hostname):
+    self.nova = novaclient.Client(self.nova_api_version,
+                                  os.environ['OS_USERNAME'],
+                                  os.environ['OS_PASSWORD'],
+                                  os.environ['OS_TENANT_NAME'],
+                                  os.environ['OS_AUTH_URL'],
+                                  connection_pool=True)
+    opts = {'all_tenants': True, 'host': hostname}
+    for server in self.nova.servers.list(detailed=False, search_opts=opts):
+        self.nova.servers.reset_state(server, 'active')
+    self.nova.services.force_down(hostname, 'nova-compute', False)
+
+
+def get_args():
+    parser = argparse.ArgumentParser(description='Doctor Test Cleaner')
+    parser.add_argument('hostname', metavar='HOSTNAME', type=str, nargs='?',
+                        help='a hostname to be re-enable')
+    return parser.parse_args()
+
+
+def main():
+    args = get_args()
+    enable_compute_host(args.hostname)
+
+
+if __name__ == '__main__':
+    main()
index 80d94b3..9bd6573 100755 (executable)
@@ -144,7 +144,7 @@ sleep 1
 END_TXT
     chmod +x disable_network.sh
     scp $ssh_opts_cpu disable_network.sh "heat-admin@$COMPUTE_IP:"
-    ssh $ssh_opts_cpu "heat-admin@$COMPUTE_IP:" 'nohup ./disable_network.sh > disable_network.log 2>&1 &'
+    ssh $ssh_opts_cpu "heat-admin@$COMPUTE_IP" 'nohup ./disable_network.sh > disable_network.log 2>&1 &'
 }
 
 calculate_notification_time() {
@@ -164,7 +164,7 @@ cleanup() {
     ssh $ssh_opts_cpu "heat-admin@$COMPUTE_IP" \
         "[ -e disable_network.log ] && cat disable_network.log"
 
-    nova service-force-down --unset "$COMPUTE_HOST" nova-compute
+    python ./clean.py
     sleep 1
     nova delete "$VM_NAME"
     sleep 1