root / qa / qa_rapi.py @ 231db3a5
History | View | Annotate | Download (4.8 kB)
1 | a47f574c | Oleksiy Mishchenko | #
|
---|---|---|---|
2 | a47f574c | Oleksiy Mishchenko | |
3 | a47f574c | Oleksiy Mishchenko | # Copyright (C) 2007, 2008 Google Inc.
|
4 | a47f574c | Oleksiy Mishchenko | #
|
5 | a47f574c | Oleksiy Mishchenko | # This program is free software; you can redistribute it and/or modify
|
6 | a47f574c | Oleksiy Mishchenko | # it under the terms of the GNU General Public License as published by
|
7 | a47f574c | Oleksiy Mishchenko | # the Free Software Foundation; either version 2 of the License, or
|
8 | a47f574c | Oleksiy Mishchenko | # (at your option) any later version.
|
9 | a47f574c | Oleksiy Mishchenko | #
|
10 | a47f574c | Oleksiy Mishchenko | # This program is distributed in the hope that it will be useful, but
|
11 | a47f574c | Oleksiy Mishchenko | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 | a47f574c | Oleksiy Mishchenko | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13 | a47f574c | Oleksiy Mishchenko | # General Public License for more details.
|
14 | a47f574c | Oleksiy Mishchenko | #
|
15 | a47f574c | Oleksiy Mishchenko | # You should have received a copy of the GNU General Public License
|
16 | a47f574c | Oleksiy Mishchenko | # along with this program; if not, write to the Free Software
|
17 | a47f574c | Oleksiy Mishchenko | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
18 | a47f574c | Oleksiy Mishchenko | # 02110-1301, USA.
|
19 | a47f574c | Oleksiy Mishchenko | |
20 | a47f574c | Oleksiy Mishchenko | |
21 | a47f574c | Oleksiy Mishchenko | """Remote API QA tests.
|
22 | a47f574c | Oleksiy Mishchenko |
|
23 | a47f574c | Oleksiy Mishchenko | """
|
24 | a47f574c | Oleksiy Mishchenko | |
25 | a47f574c | Oleksiy Mishchenko | import urllib2 |
26 | a47f574c | Oleksiy Mishchenko | |
27 | a47f574c | Oleksiy Mishchenko | from ganeti import utils |
28 | a47f574c | Oleksiy Mishchenko | from ganeti import constants |
29 | a47f574c | Oleksiy Mishchenko | from ganeti import errors |
30 | a47f574c | Oleksiy Mishchenko | from ganeti import serializer |
31 | a47f574c | Oleksiy Mishchenko | |
32 | a47f574c | Oleksiy Mishchenko | import qa_config |
33 | a47f574c | Oleksiy Mishchenko | import qa_utils |
34 | a47f574c | Oleksiy Mishchenko | import qa_error |
35 | a47f574c | Oleksiy Mishchenko | |
36 | a47f574c | Oleksiy Mishchenko | from qa_utils import AssertEqual, AssertNotEqual, AssertIn, StartSSH |
37 | a47f574c | Oleksiy Mishchenko | |
38 | a47f574c | Oleksiy Mishchenko | |
39 | a47f574c | Oleksiy Mishchenko | # Create opener which doesn't try to look for proxies.
|
40 | a47f574c | Oleksiy Mishchenko | NoProxyOpener = urllib2.build_opener(urllib2.ProxyHandler({})) |
41 | a47f574c | Oleksiy Mishchenko | |
42 | a47f574c | Oleksiy Mishchenko | |
43 | a47f574c | Oleksiy Mishchenko | INSTANCE_FIELDS = ("name", "os", "pnode", "snodes", |
44 | a5b9d725 | Iustin Pop | "admin_state",
|
45 | a5b9d725 | Iustin Pop | "disk_template", "disk.sizes", |
46 | 22482387 | Iustin Pop | "nic.ips", "nic.macs", "nic.modes", "nic.links", |
47 | a5b9d725 | Iustin Pop | "beparams", "hvparams", |
48 | a5b9d725 | Iustin Pop | "oper_state", "oper_ram", "status", "tags") |
49 | a47f574c | Oleksiy Mishchenko | |
50 | a47f574c | Oleksiy Mishchenko | NODE_FIELDS = ("name", "dtotal", "dfree", |
51 | a47f574c | Oleksiy Mishchenko | "mtotal", "mnode", "mfree", |
52 | a47f574c | Oleksiy Mishchenko | "pinst_cnt", "sinst_cnt", "tags") |
53 | a47f574c | Oleksiy Mishchenko | |
54 | 68289c75 | Iustin Pop | LIST_FIELDS = ("id", "uri") |
55 | a47f574c | Oleksiy Mishchenko | |
56 | a47f574c | Oleksiy Mishchenko | |
57 | a47f574c | Oleksiy Mishchenko | def Enabled(): |
58 | a47f574c | Oleksiy Mishchenko | """Return whether remote API tests should be run.
|
59 | a47f574c | Oleksiy Mishchenko |
|
60 | a47f574c | Oleksiy Mishchenko | """
|
61 | e1876432 | Guido Trotter | return qa_config.TestEnabled('rapi') |
62 | a47f574c | Oleksiy Mishchenko | |
63 | a47f574c | Oleksiy Mishchenko | |
64 | a47f574c | Oleksiy Mishchenko | def _DoTests(uris): |
65 | a47f574c | Oleksiy Mishchenko | master = qa_config.GetMasterNode() |
66 | a47f574c | Oleksiy Mishchenko | host = master["primary"]
|
67 | 8c96d01f | Guido Trotter | port = qa_config.get("rapi-port", default=constants.DEFAULT_RAPI_PORT)
|
68 | a47f574c | Oleksiy Mishchenko | |
69 | a47f574c | Oleksiy Mishchenko | for uri, verify in uris: |
70 | a47f574c | Oleksiy Mishchenko | assert uri.startswith("/") |
71 | a47f574c | Oleksiy Mishchenko | |
72 | 49b1d36e | Iustin Pop | url = "https://%s:%s%s" % (host, port, uri)
|
73 | a47f574c | Oleksiy Mishchenko | |
74 | a47f574c | Oleksiy Mishchenko | print "Testing %s ..." % url |
75 | a47f574c | Oleksiy Mishchenko | |
76 | a47f574c | Oleksiy Mishchenko | response = NoProxyOpener.open(url) |
77 | a47f574c | Oleksiy Mishchenko | |
78 | a47f574c | Oleksiy Mishchenko | AssertEqual(response.info()["Content-type"], "application/json") |
79 | a47f574c | Oleksiy Mishchenko | |
80 | a47f574c | Oleksiy Mishchenko | data = serializer.LoadJson(response.read()) |
81 | a47f574c | Oleksiy Mishchenko | |
82 | a47f574c | Oleksiy Mishchenko | if verify is not None: |
83 | a47f574c | Oleksiy Mishchenko | if callable(verify): |
84 | a47f574c | Oleksiy Mishchenko | verify(data) |
85 | a47f574c | Oleksiy Mishchenko | else:
|
86 | a47f574c | Oleksiy Mishchenko | AssertEqual(data, verify) |
87 | a47f574c | Oleksiy Mishchenko | |
88 | a47f574c | Oleksiy Mishchenko | |
89 | a47f574c | Oleksiy Mishchenko | def TestVersion(): |
90 | a47f574c | Oleksiy Mishchenko | """Testing remote API version.
|
91 | a47f574c | Oleksiy Mishchenko |
|
92 | a47f574c | Oleksiy Mishchenko | """
|
93 | a47f574c | Oleksiy Mishchenko | _DoTests([ |
94 | a47f574c | Oleksiy Mishchenko | ("/version", constants.RAPI_VERSION),
|
95 | a47f574c | Oleksiy Mishchenko | ]) |
96 | a47f574c | Oleksiy Mishchenko | |
97 | a47f574c | Oleksiy Mishchenko | |
98 | a47f574c | Oleksiy Mishchenko | def TestEmptyCluster(): |
99 | a47f574c | Oleksiy Mishchenko | """Testing remote API on an empty cluster.
|
100 | a47f574c | Oleksiy Mishchenko |
|
101 | a47f574c | Oleksiy Mishchenko | """
|
102 | a47f574c | Oleksiy Mishchenko | master_name = qa_config.GetMasterNode()["primary"]
|
103 | a47f574c | Oleksiy Mishchenko | |
104 | a47f574c | Oleksiy Mishchenko | def _VerifyInfo(data): |
105 | a47f574c | Oleksiy Mishchenko | AssertIn("name", data)
|
106 | a47f574c | Oleksiy Mishchenko | AssertIn("master", data)
|
107 | a47f574c | Oleksiy Mishchenko | AssertEqual(data["master"], master_name)
|
108 | a47f574c | Oleksiy Mishchenko | |
109 | a47f574c | Oleksiy Mishchenko | def _VerifyNodes(data): |
110 | a47f574c | Oleksiy Mishchenko | master_entry = { |
111 | a5b9d725 | Iustin Pop | "id": master_name,
|
112 | a5b9d725 | Iustin Pop | "uri": "/2/nodes/%s" % master_name, |
113 | a47f574c | Oleksiy Mishchenko | } |
114 | a47f574c | Oleksiy Mishchenko | AssertIn(master_entry, data) |
115 | a47f574c | Oleksiy Mishchenko | |
116 | a47f574c | Oleksiy Mishchenko | def _VerifyNodesBulk(data): |
117 | a47f574c | Oleksiy Mishchenko | for node in data: |
118 | a47f574c | Oleksiy Mishchenko | for entry in NODE_FIELDS: |
119 | a47f574c | Oleksiy Mishchenko | AssertIn(entry, node) |
120 | a47f574c | Oleksiy Mishchenko | |
121 | a47f574c | Oleksiy Mishchenko | _DoTests([ |
122 | a47f574c | Oleksiy Mishchenko | ("/", None), |
123 | a5b9d725 | Iustin Pop | ("/2/info", _VerifyInfo),
|
124 | a5b9d725 | Iustin Pop | ("/2/tags", None), |
125 | a5b9d725 | Iustin Pop | ("/2/nodes", _VerifyNodes),
|
126 | a5b9d725 | Iustin Pop | ("/2/nodes?bulk=1", _VerifyNodesBulk),
|
127 | a5b9d725 | Iustin Pop | ("/2/instances", []),
|
128 | a5b9d725 | Iustin Pop | ("/2/instances?bulk=1", []),
|
129 | a5b9d725 | Iustin Pop | ("/2/os", None), |
130 | a47f574c | Oleksiy Mishchenko | ]) |
131 | a47f574c | Oleksiy Mishchenko | |
132 | a47f574c | Oleksiy Mishchenko | |
133 | a47f574c | Oleksiy Mishchenko | def TestInstance(instance): |
134 | a47f574c | Oleksiy Mishchenko | """Testing getting instance(s) info via remote API.
|
135 | a47f574c | Oleksiy Mishchenko |
|
136 | a47f574c | Oleksiy Mishchenko | """
|
137 | a47f574c | Oleksiy Mishchenko | def _VerifyInstance(data): |
138 | a47f574c | Oleksiy Mishchenko | for entry in INSTANCE_FIELDS: |
139 | a47f574c | Oleksiy Mishchenko | AssertIn(entry, data) |
140 | c85d3b64 | Michael Hanselmann | |
141 | a47f574c | Oleksiy Mishchenko | def _VerifyInstancesList(data): |
142 | a47f574c | Oleksiy Mishchenko | for instance in data: |
143 | c85d3b64 | Michael Hanselmann | for entry in LIST_FIELDS: |
144 | a47f574c | Oleksiy Mishchenko | AssertIn(entry, instance) |
145 | c85d3b64 | Michael Hanselmann | |
146 | a47f574c | Oleksiy Mishchenko | def _VerifyInstancesBulk(data): |
147 | a47f574c | Oleksiy Mishchenko | for instance_data in data: |
148 | a47f574c | Oleksiy Mishchenko | _VerifyInstance(instance_data) |
149 | a47f574c | Oleksiy Mishchenko | |
150 | a47f574c | Oleksiy Mishchenko | _DoTests([ |
151 | a5b9d725 | Iustin Pop | ("/2/instances/%s" % instance["name"], _VerifyInstance), |
152 | a5b9d725 | Iustin Pop | ("/2/instances", _VerifyInstancesList),
|
153 | a5b9d725 | Iustin Pop | ("/2/instances?bulk=1", _VerifyInstancesBulk),
|
154 | a47f574c | Oleksiy Mishchenko | ]) |
155 | a47f574c | Oleksiy Mishchenko | |
156 | a47f574c | Oleksiy Mishchenko | |
157 | a47f574c | Oleksiy Mishchenko | def TestNode(node): |
158 | a47f574c | Oleksiy Mishchenko | """Testing getting node(s) info via remote API.
|
159 | a47f574c | Oleksiy Mishchenko |
|
160 | a47f574c | Oleksiy Mishchenko | """
|
161 | a47f574c | Oleksiy Mishchenko | def _VerifyNode(data): |
162 | a47f574c | Oleksiy Mishchenko | for entry in NODE_FIELDS: |
163 | a47f574c | Oleksiy Mishchenko | AssertIn(entry, data) |
164 | c85d3b64 | Michael Hanselmann | |
165 | a47f574c | Oleksiy Mishchenko | def _VerifyNodesList(data): |
166 | a47f574c | Oleksiy Mishchenko | for node in data: |
167 | c85d3b64 | Michael Hanselmann | for entry in LIST_FIELDS: |
168 | a47f574c | Oleksiy Mishchenko | AssertIn(entry, node) |
169 | c85d3b64 | Michael Hanselmann | |
170 | a47f574c | Oleksiy Mishchenko | def _VerifyNodesBulk(data): |
171 | a47f574c | Oleksiy Mishchenko | for node_data in data: |
172 | a47f574c | Oleksiy Mishchenko | _VerifyNode(node_data) |
173 | a47f574c | Oleksiy Mishchenko | |
174 | a47f574c | Oleksiy Mishchenko | _DoTests([ |
175 | a5b9d725 | Iustin Pop | ("/2/nodes/%s" % node["primary"], _VerifyNode), |
176 | a5b9d725 | Iustin Pop | ("/2/nodes", _VerifyNodesList),
|
177 | a5b9d725 | Iustin Pop | ("/2/nodes?bulk=1", _VerifyNodesBulk),
|
178 | a47f574c | Oleksiy Mishchenko | ]) |
179 | a47f574c | Oleksiy Mishchenko | |
180 | a47f574c | Oleksiy Mishchenko | |
181 | a47f574c | Oleksiy Mishchenko | def TestTags(kind, name, tags): |
182 | a47f574c | Oleksiy Mishchenko | """Tests .../tags resources.
|
183 | a47f574c | Oleksiy Mishchenko |
|
184 | a47f574c | Oleksiy Mishchenko | """
|
185 | a47f574c | Oleksiy Mishchenko | if kind == constants.TAG_CLUSTER:
|
186 | a5b9d725 | Iustin Pop | uri = "/2/tags"
|
187 | a47f574c | Oleksiy Mishchenko | elif kind == constants.TAG_NODE:
|
188 | a5b9d725 | Iustin Pop | uri = "/2/nodes/%s/tags" % name
|
189 | a47f574c | Oleksiy Mishchenko | elif kind == constants.TAG_INSTANCE:
|
190 | a5b9d725 | Iustin Pop | uri = "/2/instances/%s/tags" % name
|
191 | a47f574c | Oleksiy Mishchenko | else:
|
192 | a47f574c | Oleksiy Mishchenko | raise errors.ProgrammerError("Unknown tag kind") |
193 | a47f574c | Oleksiy Mishchenko | |
194 | a47f574c | Oleksiy Mishchenko | def _VerifyTags(data): |
195 | a47f574c | Oleksiy Mishchenko | # Create copies to modify
|
196 | a47f574c | Oleksiy Mishchenko | should = tags[:] |
197 | a47f574c | Oleksiy Mishchenko | should.sort() |
198 | a47f574c | Oleksiy Mishchenko | |
199 | a47f574c | Oleksiy Mishchenko | returned = data[:] |
200 | a47f574c | Oleksiy Mishchenko | returned.sort() |
201 | a47f574c | Oleksiy Mishchenko | AssertEqual(should, returned) |
202 | a47f574c | Oleksiy Mishchenko | |
203 | a47f574c | Oleksiy Mishchenko | _DoTests([ |
204 | a47f574c | Oleksiy Mishchenko | (uri, _VerifyTags), |
205 | a47f574c | Oleksiy Mishchenko | ]) |