Navigation Menu

Skip to content

Commit

Permalink
Change VerificationOpsSrv to use admin credentials for auth
Browse files Browse the repository at this point in the history
After changing default aaa mode to cloud-admin-only for contrail-analytics-api
we need to change VerificationOpsSrv to use admin credentials when
getting auth token to send to contrail-analytics-api instead of
stack user credentials.

Change-Id: I9692c57add27b2bacc3d0c05d59690c3e2c82b7f
Partial-Bug: #1599654
  • Loading branch information
Megh Bhatt committed Jul 26, 2016
1 parent 4f03b19 commit 1eb5678
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion tcutils/collector/opserver_introspect_utils.py
Expand Up @@ -17,7 +17,8 @@
class VerificationOpsSrv (VerificationUtilBase):

def __init__(self, ip, port=8081, logger=LOG, inputs=None):
super(VerificationOpsSrv, self).__init__(ip, port, logger=logger, args=inputs)
super(VerificationOpsSrv, self).__init__(ip, port, logger=logger, args=inputs,
use_admin_auth=True)


def get_ops_generator(self, generator=None,
Expand Down
14 changes: 8 additions & 6 deletions tcutils/verification_util.py
Expand Up @@ -14,11 +14,12 @@ class JsonDrv (object):
}
_DEFAULT_AUTHN_URL = "/v2.0/tokens"

def __init__(self, vub, logger=LOG, args=None):
def __init__(self, vub, logger=LOG, args=None, use_admin_auth=False):
self.log = logger
self._vub = vub
self._headers = None
self._args = args
self._use_admin_auth = use_admin_auth

def _auth(self):
if self._args:
Expand All @@ -33,8 +34,9 @@ def _auth(self):
verify = not insecure
self._authn_body = \
'{"auth":{"passwordCredentials":{"username": "%s", "password": "%s"}, "tenantName":"%s"}}' % (
self._args.stack_user, self._args.stack_password,
self._args.project_name)
self._args.admin_username if self._use_admin_auth else self._args.stack_user,
self._args.admin_password if self._use_admin_auth else self._args.stack_password,
self._args.admin_tenant if self._use_admin_auth else self._args.project_name)
response = requests.post(url, data=self._authn_body,
headers=self._DEFAULT_HEADERS,
verify=verify)
Expand Down Expand Up @@ -62,7 +64,7 @@ def load(self, url, retry=True):

class XmlDrv (object):

def __init__(self, vub, logger=LOG, args=None):
def __init__(self, vub, logger=LOG, args=None, use_admin_auth=False):
self.log = logger
self._vub = vub
if args:
Expand All @@ -80,11 +82,11 @@ def load(self, url):

class VerificationUtilBase (object):

def __init__(self, ip, port, drv=JsonDrv, logger=LOG, args=None):
def __init__(self, ip, port, drv=JsonDrv, logger=LOG, args=None, use_admin_auth=False):
self.log = logger
self._ip = ip
self._port = port
self._drv = drv(self, logger=logger, args=args)
self._drv = drv(self, logger=logger, args=args, use_admin_auth=use_admin_auth)
self._force_refresh = False

def get_force_refresh(self):
Expand Down

0 comments on commit 1eb5678

Please sign in to comment.