Revision fcd2359a

b/qa/ganeti-qa.py
53 53
from ganeti import rapi # pylint: disable=W0611
54 54
from ganeti import constants
55 55
from ganeti import netutils
56
from ganeti import pathutils
57 56

  
58
from ganeti.http.auth import ParsePasswordFile
59 57
import ganeti.rapi.client # pylint: disable=W0611
60 58
from ganeti.rapi.client import UsesRapiClient
61 59

  
......
165 163
  RunTestIf("env", qa_env.TestGanetiCommands)
166 164

  
167 165

  
168
def _LookupRapiSecret(rapi_user):
169
  """Find the RAPI secret for the given user.
170

  
171
  @param rapi_user: Login user
172
  @return: Login secret for the user
173

  
174
  """
175
  CTEXT = "{CLEARTEXT}"
176
  master = qa_config.GetMasterNode()
177
  cmd = ["cat", qa_utils.MakeNodePath(master, pathutils.RAPI_USERS_FILE)]
178
  file_content = qa_utils.GetCommandOutput(master.primary,
179
                                           utils.ShellQuoteArgs(cmd))
180
  users = ParsePasswordFile(file_content)
181
  entry = users.get(rapi_user)
182
  if not entry:
183
    raise qa_error.Error("User %s not found in RAPI users file" % rapi_user)
184
  secret = entry.password
185
  if secret.upper().startswith(CTEXT):
186
    secret = secret[len(CTEXT):]
187
  elif secret.startswith("{"):
188
    raise qa_error.Error("Unsupported password schema for RAPI user %s:"
189
                         " not a clear text password" % rapi_user)
190
  return secret
191

  
192

  
193 166
def SetupCluster(rapi_user):
194 167
  """Initializes the cluster.
195 168

  
......
206 179
    qa_config.SetExclusiveStorage(qa_config.get("exclusive-storage", False))
207 180
    if qa_rapi.Enabled():
208 181
      # To support RAPI on an existing cluster we have to find out the secret
209
      rapi_secret = _LookupRapiSecret(rapi_user)
182
      rapi_secret = qa_rapi.LookupRapiSecret(rapi_user)
210 183

  
211 184
  qa_group.ConfigureGroups()
212 185

  
b/qa/qa_rapi.py
39 39
from ganeti import qlang
40 40
from ganeti import pathutils
41 41

  
42
from ganeti.http.auth import ParsePasswordFile
42 43
import ganeti.rapi.client        # pylint: disable=W0611
43 44
import ganeti.rapi.client_utils
44 45

  
......
103 104
    print "RAPI protocol version: %s" % _rapi_client.GetVersion()
104 105

  
105 106

  
107
def LookupRapiSecret(rapi_user):
108
  """Find the RAPI secret for the given user.
109

  
110
  @param rapi_user: Login user
111
  @return: Login secret for the user
112

  
113
  """
114
  CTEXT = "{CLEARTEXT}"
115
  master = qa_config.GetMasterNode()
116
  cmd = ["cat", qa_utils.MakeNodePath(master, pathutils.RAPI_USERS_FILE)]
117
  file_content = qa_utils.GetCommandOutput(master.primary,
118
                                           utils.ShellQuoteArgs(cmd))
119
  users = ParsePasswordFile(file_content)
120
  entry = users.get(rapi_user)
121
  if not entry:
122
    raise qa_error.Error("User %s not found in RAPI users file" % rapi_user)
123
  secret = entry.password
124
  if secret.upper().startswith(CTEXT):
125
    secret = secret[len(CTEXT):]
126
  elif secret.startswith("{"):
127
    raise qa_error.Error("Unsupported password schema for RAPI user %s:"
128
                         " not a clear text password" % rapi_user)
129
  return secret
130

  
131

  
106 132
INSTANCE_FIELDS = ("name", "os", "pnode", "snodes",
107 133
                   "admin_state",
108 134
                   "disk_template", "disk.sizes", "disk.spindles",

Also available in: Unified diff