def _show_nodes(path): """Helper for the loop below. This does a GET on path, which must return a json list of names of nodes. It will then query the state of each node. If any request does not return 200 or has a body which is not valid json, the test will fail. """ resp = do_request('GET', path) assert resp.status_code == 200 for node in json.loads(resp.get_data()): resp = do_request('GET', '/node/%s' % node) assert resp.status_code == 200 # At least make sure the body parses: json.loads(resp.get_data())
def test_require_auth(): """require_authenticate=True should deny calls with "no special access." This is the default setting. We use list_free_nodes as an example here. """ auth_backend = get_auth_backend() auth_backend.set_auth_success(False) resp = do_request('GET', '/free_nodes') assert resp.status_code == 401
def test_many_http_queries(): """Put a few objects in the db, then bombard the api with queries. This is intended to shake out problems like the resource leak discussed in issue #454. """ with rest.RequestContext(): api.node_register('node-99', obm={ "type": "http://schema.massopencloud.org/haas/v0/obm/ipmi", "host": "ipmihost", "user": "******", "password": "******"}) api.node_register('node-98', obm={ "type": "http://schema.massopencloud.org/haas/v0/obm/ipmi", "host": "ipmihost", "user": "******", "password": "******"}) api.node_register('node-97', obm={ "type": "http://schema.massopencloud.org/haas/v0/obm/ipmi", "host": "ipmihost", "user": "******", "password": "******"}) api.node_register_nic('node-99', 'eth0', 'DE:AD:BE:EF:20:14') api.node_register_nic('node-98', 'eth0', 'DE:AD:BE:EF:20:15') api.node_register_nic('node-97', 'eth0', 'DE:AD:BE:EF:20:16') api.project_create('anvil-nextgen') api.project_create('anvil-legacy') api.project_connect_node('anvil-nextgen', 'node-99') api.project_connect_node('anvil-legacy', 'node-98') def _show_nodes(path): """Helper for the loop below. This does a GET on path, which must return a json list of names of nodes. It will then query the state of each node. If any request does not return 200 or has a body which is not valid json, the test will fail. """ resp = do_request('GET', path) assert resp.status_code == 200 for node in json.loads(resp.get_data()): resp = do_request('GET', '/node/%s' % node) assert resp.status_code == 200 # At least make sure the body parses: json.loads(resp.get_data()) for i in range(100): _show_nodes('/free_nodes') resp = do_request('GET', '/projects') assert resp.status_code == 200 for project in json.loads(resp.get_data()): _show_nodes('/project/%s/nodes' % project)