urgent bug fixes for danube (2) 95/29795/2
authorRyota MIBU <r-mibu@cq.jp.nec.com>
Sun, 5 Mar 2017 03:48:38 +0000 (03:48 +0000)
committerRyota MIBU <r-mibu@cq.jp.nec.com>
Sun, 5 Mar 2017 04:41:21 +0000 (04:41 +0000)
- use relevant identity version estimated from OS_AUTH_URL

- (apex) unset OS_PROJECT_ID

Change-Id: I7e51c7d5510baaa4d14b16600f9efa6fcfc011b9
Signed-off-by: Ryota MIBU <r-mibu@cq.jp.nec.com>
tests/identity_auth.py [new file with mode: 0644]
tests/inspector.py
tests/lib/installers/apex
tests/monitor.py

diff --git a/tests/identity_auth.py b/tests/identity_auth.py
new file mode 100644 (file)
index 0000000..4726ca3
--- /dev/null
@@ -0,0 +1,34 @@
+##############################################################################
+# 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 os
+
+from keystoneauth1.identity import v2
+from keystoneauth1.identity import v3
+
+
+def get_identity_auth():
+    auth_url = os.environ['OS_AUTH_URL']
+    username = os.environ['OS_USERNAME']
+    password = os.environ['OS_PASSWORD']
+    user_domain_name = os.environ.get('OS_USER_DOMAIN_NAME')
+    project_name = os.environ.get('OS_PROJECT_NAME') or os.environ.get('OS_TENANT_NAME')
+    project_domain_name = os.environ.get('OS_PROJECT_DOMAIN_NAME')
+    if auth_url.endswith('v3'):
+        return v3.Password(auth_url=auth_url,
+                           username=username,
+                           password=password,
+                           user_domain_name=user_domain_name,
+                           project_name=project_name,
+                           project_domain_name=project_domain_name)
+    else:
+        return v2.Password(auth_url=auth_url,
+                           username=username,
+                           password=password,
+                           tenant_name=project_name)
index 27c969e..ba00f40 100644 (file)
@@ -17,10 +17,11 @@ import os
 import threading
 import time
 
-from keystoneauth1.identity import v3
 from keystoneauth1 import session
 import novaclient.client as novaclient
 
+import identity_auth
+
 LOG = doctor_log.Logger('doctor_inspector').getLogger()
 
 
@@ -49,12 +50,7 @@ class DoctorInspectorSample(object):
     def __init__(self):
         self.servers = collections.defaultdict(list)
         self.novaclients = list()
-        auth = v3.Password(auth_url=os.environ['OS_AUTH_URL'],
-                           username=os.environ['OS_USERNAME'],
-                           password=os.environ['OS_PASSWORD'],
-                           user_domain_name=os.environ['OS_USER_DOMAIN_NAME'],
-                           project_name=os.environ['OS_PROJECT_NAME'],
-                           project_domain_name=os.environ['OS_PROJECT_DOMAIN_NAME'])
+        auth=identity_auth.get_identity_auth()
         sess=session.Session(auth=auth)
         # Pool of novaclients for redundant usage
         for i in range(self.NUMBER_OF_CLIENTS):
index e353d25..d9c41f8 100644 (file)
@@ -28,6 +28,10 @@ function setup_installer {
     get_installer_ip
     installer_get_ssh_keys
     get_controller_ips
+
+    # 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 {
index 8d29dce..8e8aa7a 100644 (file)
@@ -18,8 +18,8 @@ import sys
 import time
 
 from congressclient.v1 import client
-from keystoneclient import session as ksc_session
-from keystoneclient.auth.identity import v2
+
+import identity_auth
 
 # NOTE: icmp message with all zero data (checksum = 0xf7ff)
 #       see https://tools.ietf.org/html/rfc792
@@ -29,6 +29,7 @@ SUPPORTED_INSPECTOR_TYPES = ['sample', 'congress']
 
 LOG = doctor_log.Logger('doctor_monitor').getLogger()
 
+
 class DoctorMonitorSample(object):
 
     interval = 0.1  # second
@@ -46,13 +47,9 @@ class DoctorMonitorSample(object):
         if self.inspector_type == 'sample':
             self.inspector_url = 'http://127.0.0.1:12345/events'
         elif self.inspector_type == 'congress':
-            auth = v2.Password(auth_url=os.environ['OS_AUTH_URL'],
-                               username=os.environ['OS_USERNAME'],
-                               password=os.environ['OS_PASSWORD'],
-                               tenant_name=os.environ['OS_TENANT_NAME'])
-            self.session = ksc_session.Session(auth=auth)
-
-            congress = client.Client(session=self.session, service_type='policy')
+            auth=identity_auth.get_identity_auth()
+            sess=session.Session(auth=auth)
+            congress = client.Client(session=sess, service_type='policy')
             ds = congress.list_datasources()['results']
             doctor_ds = next((item for item in ds if item['driver'] == 'doctor'),
                              None)