Commit 725ec2f1 authored by René Nussbaumer's avatar René Nussbaumer
Browse files

QA: Make the rapi credential handling less involving


Signed-off-by: default avatarRené Nussbaumer <rn@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 33ea43b6
...@@ -38,6 +38,8 @@ import qa_rapi ...@@ -38,6 +38,8 @@ import qa_rapi
import qa_tags import qa_tags
import qa_utils import qa_utils
from ganeti import utils
def RunTest(fn, *args): def RunTest(fn, *args):
"""Runs a test after printing a header. """Runs a test after printing a header.
...@@ -70,12 +72,15 @@ def RunEnvTests(): ...@@ -70,12 +72,15 @@ def RunEnvTests():
RunTest(qa_env.TestGanetiCommands) RunTest(qa_env.TestGanetiCommands)
def SetupCluster(): def SetupCluster(rapi_user, rapi_secret):
"""Initializes the cluster. """Initializes the cluster.
@param rapi_user: Login user for RAPI
@param rapi_secret: Login secret for RAPI
""" """
if qa_config.TestEnabled('create-cluster'): if qa_config.TestEnabled('create-cluster'):
RunTest(qa_cluster.TestClusterInit) RunTest(qa_cluster.TestClusterInit, rapi_user, rapi_secret)
RunTest(qa_node.TestNodeAddAll) RunTest(qa_node.TestNodeAddAll)
else: else:
# consider the nodes are already there # consider the nodes are already there
...@@ -274,8 +279,12 @@ def main(): ...@@ -274,8 +279,12 @@ def main():
qa_config.Load(config_file) qa_config.Load(config_file)
rapi_user = "ganeti-qa"
rapi_secret = utils.GenerateSecret()
qa_rapi.OpenerFactory.SetCredentials(rapi_user, rapi_secret)
RunEnvTests() RunEnvTests()
SetupCluster() SetupCluster(rapi_user, rapi_secret)
RunClusterTests() RunClusterTests()
RunOsTests() RunOsTests()
......
...@@ -56,10 +56,17 @@ def _CheckFileOnAllNodes(filename, content): ...@@ -56,10 +56,17 @@ def _CheckFileOnAllNodes(filename, content):
content) content)
def TestClusterInit(): def TestClusterInit(rapi_user, rapi_secret):
"""gnt-cluster init""" """gnt-cluster init"""
master = qa_config.GetMasterNode() master = qa_config.GetMasterNode()
# First create the RAPI credentials
cred_string = "%s %s write" % (rapi_user, rapi_secret)
cmd = ("echo %s > %s" %
(utils.ShellQuote(cred_string),
utils.ShellQuote(constants.RAPI_USERS_FILE)))
AssertEqual(StartSSH(master['primary'], cmd).wait(), 0)
cmd = ['gnt-cluster', 'init'] cmd = ['gnt-cluster', 'init']
if master.get('secondary', None): if master.get('secondary', None):
...@@ -79,21 +86,6 @@ def TestClusterInit(): ...@@ -79,21 +86,6 @@ def TestClusterInit():
AssertEqual(StartSSH(master['primary'], AssertEqual(StartSSH(master['primary'],
utils.ShellQuoteArgs(cmd)).wait(), 0) utils.ShellQuoteArgs(cmd)).wait(), 0)
# Create RAPI credentials
rapi_user = qa_config.get("rapi-user", default=None)
rapi_pass = qa_config.get("rapi-pass", default=None)
if rapi_user and rapi_pass:
cmds = []
cred_string = "%s %s write" % (rapi_user, rapi_pass)
cmds.append(("echo %s >> %s" %
(utils.ShellQuote(cred_string),
utils.ShellQuote(constants.RAPI_USERS_FILE))))
cmds.append("%s stop-master" % constants.DAEMON_UTIL)
cmds.append("%s start-master" % constants.DAEMON_UTIL)
AssertEqual(StartSSH(master['primary'], ' && '.join(cmds)).wait(), 0)
def TestClusterRename(): def TestClusterRename():
"""gnt-cluster rename""" """gnt-cluster rename"""
......
...@@ -44,6 +44,16 @@ class OpenerFactory: ...@@ -44,6 +44,16 @@ class OpenerFactory:
""" """
_opener = None _opener = None
_rapi_user = None
_rapi_secret = None
@classmethod
def SetCredentials(cls, rapi_user, rapi_secret):
"""Set the credentials for authorized access.
"""
cls._rapi_user = rapi_user
cls._rapi_secret = rapi_secret
@classmethod @classmethod
def Opener(cls): def Opener(cls):
...@@ -51,14 +61,17 @@ class OpenerFactory: ...@@ -51,14 +61,17 @@ class OpenerFactory:
""" """
if not cls._opener: if not cls._opener:
if not cls._rapi_user or not cls._rapi_secret:
raise errors.ProgrammerError("SetCredentials was never called.")
# Create opener which doesn't try to look for proxies and does auth # Create opener which doesn't try to look for proxies and does auth
master = qa_config.GetMasterNode() master = qa_config.GetMasterNode()
host = master["primary"] host = master["primary"]
port = qa_config.get("rapi-port", default=constants.DEFAULT_RAPI_PORT) port = qa_config.get("rapi-port", default=constants.DEFAULT_RAPI_PORT)
passman = urllib2.HTTPPasswordMgrWithDefaultRealm() passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, 'https://%s:%s' % (host, port), passman.add_password(None, 'https://%s:%s' % (host, port),
qa_config.get("rapi-user", default=""), cls._rapi_user,
qa_config.get("rapi-pass", default="")) cls._rapi_secret)
authhandler = urllib2.HTTPBasicAuthHandler(passman) authhandler = urllib2.HTTPBasicAuthHandler(passman)
cls._opener = urllib2.build_opener(urllib2.ProxyHandler({}), authhandler) cls._opener = urllib2.build_opener(urllib2.ProxyHandler({}), authhandler)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment