Add label-list webapp endpoint

This is useful for getting the list of all available labels.
Originally implemented in Iafff02d546abb34affa88310f6a97918166cbf47,
this is based on the new info available from
Icfb73fbe3b67321235a78ea7ed9bf4319567eb1a

Co-Authored-By: Tristan Cacqueray <tdecacqu@redhat.com>
Change-Id: I4b43ac0e2ba44516ff289e93dbf553033fc9e130
Depends-On: https://review.openstack.org/548376
This commit is contained in:
Ian Wienand 2018-02-28 14:40:51 +11:00
parent 2dcd79b987
commit 4074b0f0f9
4 changed files with 54 additions and 0 deletions

View File

@ -263,3 +263,12 @@ launchers, all will provide the same information.
:reqheader Accept: ``application/json`` or ``text/*``
:resheader Content-Type: ``application/json`` or ``text/plain``
depending on the :http:header:`Accept` header
.. http:get:: /label-list
All available labels as reported by all launchers
:query fields: comma-separated list of fields to display
:reqheader Accept: ``application/json`` or ``text/*``
:resheader Content-Type: ``application/json`` or ``text/plain``
depending on the :http:header:`Accept` header

View File

@ -244,3 +244,24 @@ def request_list(zk):
objs.append(dict(zip(headers_table.keys(),
values)))
return (objs, headers_table)
def label_list(zk):
headers_table = OrderedDict([
("label", "Label"),
])
objs = []
# Walk all launchers, find the labels they support and stick it
# all in a set.
# NOTE(ianw): maybe add to each entry a list of which
# launchers support the label?
labels = set()
launchers = zk.getRegisteredLaunchers()
for launcher in launchers:
labels.update(launcher.supported_labels)
for label in labels:
objs.append({'label': label})
return (objs, headers_table)

View File

@ -206,6 +206,28 @@ class TestWebApp(tests.DBTestCase):
'requestor': 'test_request_list', },
objs[0])
def test_label_list_json(self):
configfile = self.setup_config('node.yaml')
pool = self.useNodepool(configfile, watermark_sleep=1)
self.useBuilder(configfile)
pool.start()
webapp = self.useWebApp(pool, port=0)
webapp.start()
port = webapp.server.socket.getsockname()[1]
self.waitForImage('fake-provider', 'fake-image')
self.waitForNodes('fake-label')
req = request.Request(
"http://localhost:%s/label-list" % port)
req.add_header('Accept', 'application/json')
f = request.urlopen(req)
self.assertEqual(f.info().get('Content-Type'),
'application/json')
data = f.read()
objs = json.loads(data.decode('utf8'))
self.assertEqual([{'label': 'fake-label'}], objs)
def test_webapp_config(self):
configfile = self.setup_config('webapp.yaml')
config = yaml.safe_load(open(configfile))

View File

@ -99,6 +99,8 @@ class WebApp(threading.Thread):
node_id=params.get('node_id'))
elif path == '/request-list':
results = status.request_list(zk)
elif path == '/label-list':
results = status.label_list(zk)
else:
return None