Revision 725ec2f1

b/qa/ganeti-qa.py
38 38
import qa_tags
39 39
import qa_utils
40 40

  
41
from ganeti import utils
42

  
41 43

  
42 44
def RunTest(fn, *args):
43 45
  """Runs a test after printing a header.
......
70 72
  RunTest(qa_env.TestGanetiCommands)
71 73

  
72 74

  
73
def SetupCluster():
75
def SetupCluster(rapi_user, rapi_secret):
74 76
  """Initializes the cluster.
75 77

  
78
  @param rapi_user: Login user for RAPI
79
  @param rapi_secret: Login secret for RAPI
80

  
76 81
  """
77 82
  if qa_config.TestEnabled('create-cluster'):
78
    RunTest(qa_cluster.TestClusterInit)
83
    RunTest(qa_cluster.TestClusterInit, rapi_user, rapi_secret)
79 84
    RunTest(qa_node.TestNodeAddAll)
80 85
  else:
81 86
    # consider the nodes are already there
......
274 279

  
275 280
  qa_config.Load(config_file)
276 281

  
282
  rapi_user = "ganeti-qa"
283
  rapi_secret = utils.GenerateSecret()
284
  qa_rapi.OpenerFactory.SetCredentials(rapi_user, rapi_secret)
285

  
277 286
  RunEnvTests()
278
  SetupCluster()
287
  SetupCluster(rapi_user, rapi_secret)
279 288
  RunClusterTests()
280 289
  RunOsTests()
281 290

  
b/qa/qa_cluster.py
56 56
                content)
57 57

  
58 58

  
59
def TestClusterInit():
59
def TestClusterInit(rapi_user, rapi_secret):
60 60
  """gnt-cluster init"""
61 61
  master = qa_config.GetMasterNode()
62 62

  
63
  # First create the RAPI credentials
64
  cred_string = "%s %s write" % (rapi_user, rapi_secret)
65
  cmd = ("echo %s > %s" %
66
         (utils.ShellQuote(cred_string),
67
          utils.ShellQuote(constants.RAPI_USERS_FILE)))
68
  AssertEqual(StartSSH(master['primary'], cmd).wait(), 0)
69

  
63 70
  cmd = ['gnt-cluster', 'init']
64 71

  
65 72
  if master.get('secondary', None):
......
79 86
  AssertEqual(StartSSH(master['primary'],
80 87
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
81 88

  
82
  # Create RAPI credentials
83
  rapi_user = qa_config.get("rapi-user", default=None)
84
  rapi_pass = qa_config.get("rapi-pass", default=None)
85

  
86
  if rapi_user and rapi_pass:
87
    cmds = []
88

  
89
    cred_string = "%s %s write" % (rapi_user, rapi_pass)
90
    cmds.append(("echo %s >> %s" %
91
                 (utils.ShellQuote(cred_string),
92
                  utils.ShellQuote(constants.RAPI_USERS_FILE))))
93
    cmds.append("%s stop-master" % constants.DAEMON_UTIL)
94
    cmds.append("%s start-master" % constants.DAEMON_UTIL)
95
    AssertEqual(StartSSH(master['primary'], ' && '.join(cmds)).wait(), 0)
96

  
97 89

  
98 90
def TestClusterRename():
99 91
  """gnt-cluster rename"""
b/qa/qa_rapi.py
44 44

  
45 45
  """
46 46
  _opener = None
47
  _rapi_user = None
48
  _rapi_secret = None
49

  
50
  @classmethod
51
  def SetCredentials(cls, rapi_user, rapi_secret):
52
    """Set the credentials for authorized access.
53

  
54
    """
55
    cls._rapi_user = rapi_user
56
    cls._rapi_secret = rapi_secret
47 57

  
48 58
  @classmethod
49 59
  def Opener(cls):
......
51 61

  
52 62
    """
53 63
    if not cls._opener:
64
      if not cls._rapi_user or not cls._rapi_secret:
65
        raise errors.ProgrammerError("SetCredentials was never called.")
66

  
54 67
      # Create opener which doesn't try to look for proxies and does auth
55 68
      master = qa_config.GetMasterNode()
56 69
      host = master["primary"]
57 70
      port = qa_config.get("rapi-port", default=constants.DEFAULT_RAPI_PORT)
58 71
      passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
59 72
      passman.add_password(None, 'https://%s:%s' % (host, port),
60
                           qa_config.get("rapi-user", default=""),
61
                           qa_config.get("rapi-pass", default=""))
73
                           cls._rapi_user,
74
                           cls._rapi_secret)
62 75
      authhandler = urllib2.HTTPBasicAuthHandler(passman)
63 76
      cls._opener = urllib2.build_opener(urllib2.ProxyHandler({}), authhandler)
64 77

  

Also available in: Unified diff