summaryrefslogtreecommitdiffstats
path: root/testapi
diff options
context:
space:
mode:
authorSerena Feng <feng.xiaowei@zte.com.cn>2018-03-14 13:10:17 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-03-14 13:10:17 +0000
commit15e1434ea6509f5ef286e23be2b8bcbd891ff0a5 (patch)
tree90976bd724972a1ea5e2d55907bbfeb77206c3b2 /testapi
parentf06577aec659c50521ff7f69321aec604b936749 (diff)
parentb195125202e028287b94ddffbf5be50911dbd20b (diff)
Merge "save authentication with save auth_complete"
Diffstat (limited to 'testapi')
-rw-r--r--testapi/testapi-client/testapiclient/main.py2
-rw-r--r--testapi/testapi-client/testapiclient/utils/clientmanager.py27
2 files changed, 23 insertions, 6 deletions
diff --git a/testapi/testapi-client/testapiclient/main.py b/testapi/testapi-client/testapiclient/main.py
index 22a8fbd..a448146 100644
--- a/testapi/testapi-client/testapiclient/main.py
+++ b/testapi/testapi-client/testapiclient/main.py
@@ -36,7 +36,7 @@ class TestAPIClient(app.App):
def prepare_to_run_command(self, cmd):
self.LOG.debug('prepare_to_run_command %s', cmd.__class__.__name__)
- if self.options.u:
+ if self.client_manager.auth_required:
self.client_manager.auth()
def clean_up(self, cmd, result, err):
diff --git a/testapi/testapi-client/testapiclient/utils/clientmanager.py b/testapi/testapi-client/testapiclient/utils/clientmanager.py
index 7e4e630..4401231 100644
--- a/testapi/testapi-client/testapiclient/utils/clientmanager.py
+++ b/testapi/testapi-client/testapiclient/utils/clientmanager.py
@@ -2,9 +2,12 @@ import httplib
import json
import os
import urllib
+import logging
import requests
+LOG = logging.getLogger(__name__)
+
class ClientManager(object):
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
@@ -12,19 +15,33 @@ class ClientManager(object):
def __init__(self, cli_options=None):
self.cli_options = cli_options
self.session = requests.Session()
+ self._auth_completed = False
+
+ @property
+ def auth_required(self):
+ return self._auth()
+
+ def _auth(self):
+ return {
+ 'name': self.cli_options.u,
+ 'pass': self.cli_options.p
+ } if self.cli_options.u else None
def auth(self):
+
+ if self._auth_completed:
+ return
+
hostname = '{}{}{}'.format(os.environ.get('testapi_cas_auth_url'),
urllib.quote(os.environ.get('testapi_url')),
os.environ.get('testapi_cas_signin_return'))
- data = {
- 'name': self.cli_options.u,
- 'pass': self.cli_options.p,
- 'form_id': 'user_login'
- }
+ data = self._auth()
+ data.update({'form_id': 'user_login'})
+ LOG.debug('authenticating.....')
response = self.session.post(hostname, data)
if "login" in response.text:
raise Exception('Authenticate failed')
+ self._auth_completed = True
def get(self, url):
return self._parse_response('Get',