Revision 35ff270b
b/qa/ganeti-qa.py | ||
---|---|---|
49 | 49 |
from ganeti import utils |
50 | 50 |
from ganeti import rapi # pylint: disable=W0611 |
51 | 51 |
from ganeti import constants |
52 |
from ganeti import pathutils |
|
52 | 53 |
|
54 |
from ganeti.http.auth import ParsePasswordFile |
|
53 | 55 |
import ganeti.rapi.client # pylint: disable=W0611 |
54 | 56 |
from ganeti.rapi.client import UsesRapiClient |
55 | 57 |
|
... | ... | |
123 | 125 |
RunTestIf("env", qa_env.TestGanetiCommands) |
124 | 126 |
|
125 | 127 |
|
126 |
def SetupCluster(rapi_user, rapi_secret): |
|
128 |
def _LookupRapiSecret(rapi_user): |
|
129 |
"""Find the RAPI secret for the given user. |
|
130 |
|
|
131 |
@param rapi_user: Login user |
|
132 |
@return: Login secret for the user |
|
133 |
|
|
134 |
""" |
|
135 |
CTEXT = "{CLEARTEXT}" |
|
136 |
master = qa_config.GetMasterNode() |
|
137 |
cmd = ["cat", qa_utils.MakeNodePath(master, pathutils.RAPI_USERS_FILE)] |
|
138 |
file_content = qa_utils.GetCommandOutput(master.primary, |
|
139 |
utils.ShellQuoteArgs(cmd)) |
|
140 |
users = ParsePasswordFile(file_content) |
|
141 |
entry = users.get(rapi_user) |
|
142 |
if not entry: |
|
143 |
raise qa_error.Error("User %s not found in RAPI users file" % rapi_user) |
|
144 |
secret = entry.password |
|
145 |
if secret.upper().startswith(CTEXT): |
|
146 |
secret = secret[len(CTEXT):] |
|
147 |
elif secret.startswith("{"): |
|
148 |
raise qa_error.Error("Unsupported password schema for RAPI user %s:" |
|
149 |
" not a clear text password" % rapi_user) |
|
150 |
return secret |
|
151 |
|
|
152 |
|
|
153 |
def SetupCluster(rapi_user): |
|
127 | 154 |
"""Initializes the cluster. |
128 | 155 |
|
129 | 156 |
@param rapi_user: Login user for RAPI |
130 |
@param rapi_secret: Login secret for RAPI
|
|
157 |
@return: Login secret for RAPI
|
|
131 | 158 |
|
132 | 159 |
""" |
160 |
rapi_secret = utils.GenerateSecret() |
|
133 | 161 |
RunTestIf("create-cluster", qa_cluster.TestClusterInit, |
134 | 162 |
rapi_user, rapi_secret) |
135 | 163 |
if not qa_config.TestEnabled("create-cluster"): |
136 | 164 |
# If the cluster is already in place, we assume that exclusive-storage is |
137 | 165 |
# already set according to the configuration |
138 | 166 |
qa_config.SetExclusiveStorage(qa_config.get("exclusive-storage", False)) |
167 |
if qa_rapi.Enabled(): |
|
168 |
# To support RAPI on an existing cluster we have to find out the secret |
|
169 |
rapi_secret = _LookupRapiSecret(rapi_user) |
|
139 | 170 |
|
140 | 171 |
# Test on empty cluster |
141 | 172 |
RunTestIf("node-list", qa_node.TestNodeList) |
... | ... | |
162 | 193 |
|
163 | 194 |
RunTestIf("node-info", qa_node.TestNodeInfo) |
164 | 195 |
|
196 |
return rapi_secret |
|
197 |
|
|
165 | 198 |
|
166 | 199 |
def RunClusterTests(): |
167 | 200 |
"""Runs tests related to gnt-cluster. |
... | ... | |
718 | 751 |
|
719 | 752 |
""" |
720 | 753 |
rapi_user = "ganeti-qa" |
721 |
rapi_secret = utils.GenerateSecret() |
|
722 | 754 |
|
723 | 755 |
RunEnvTests() |
724 |
SetupCluster(rapi_user, rapi_secret)
|
|
756 |
rapi_secret = SetupCluster(rapi_user)
|
|
725 | 757 |
|
726 | 758 |
if qa_rapi.Enabled(): |
727 | 759 |
# Load RAPI certificate |
Also available in: Unified diff