def create_pending_actions_db(): """Create database objects including a pending NetworkingAction. The first version of this function was used to create the dump 'pending-networking-actions.sql'. """ # At a minimum we need a project, node, nic, switch, port, and network: api.project_create('runway') api.node_register( 'node-1', obm={ 'type': MOCK_OBM_TYPE, 'user': '******', 'host': 'host', 'password': '******', }, ) api.node_register_nic('node-1', 'pxe', 'de:ad:be:ef:20:16') api.switch_register( 'sw0', type=MOCK_SWITCH_TYPE, username='******', hostname='host', password='******', ) api.switch_register_port('sw0', 'gi1/0/4') api.port_connect_nic('sw0', 'gi1/0/4', 'node-1', 'pxe') api.project_connect_node('runway', 'node-1') api.network_create('runway_pxe', 'runway', 'runway', '') # Queue up a networking action. Importantly, we do *not* call # deferred.apply_networking, as that would flush the action and # remove it from the database. api.node_connect_network('node-1', 'pxe', 'runway_pxe')
def allocate_nodes(): layout_json_data = open('site-layout.json') layout = json.load(layout_json_data) layout_json_data.close() netmap = {} for node in layout['nodes']: api.node_register(node['name'], node['ipmi']['host'], node['ipmi']['user'], node['ipmi']['pass']) for nic in node['nics']: api.node_register_nic(node['name'], nic['name'], nic['mac']) api.port_register(nic['port']) api.port_connect_nic(nic['port'], node['name'], nic['name']) netmap[nic['port']] = None # Now ensure that all of these ports are turned off driver_name = cfg.get('general', 'driver') driver = importlib.import_module('haas.drivers.' + driver_name) driver.apply_networking(netmap)
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. """ # NOTE: Now that the session is managed by Flask-SQLAlchemy, failures here # are unlikely to be regressions of the issue that #454 fixed; we're no # longer managing the lifecycle of the session ourselves. It's not obvious # that this is more than clutter now, but let's not be too trigger happy # about deleting tests. with rest.app.test_request_context(): rest.init_auth() 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') client = rest.app.test_client() 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 = client.get(path) assert resp.status_code == 200 for node in json.loads(resp.get_data()): resp = client.get('/nodes/%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('/nodes/free') resp = client.get('/projects') assert resp.status_code == 200 for project in json.loads(resp.get_data()): _show_nodes('/project/%s/nodes' % project)
def site_layout(): """Load the file site-layout.json, and populate the database accordingly. This is meant to be used as a pytest fixture, but isn't declared here as such; individual modules should declare it as a fixture. Full documentation for the site-layout.json file format is located in ``docs/testing.md``. """ layout_json_data = open('site-layout.json') layout = json.load(layout_json_data) layout_json_data.close() for switch in layout['switches']: api.switch_register(**switch) for node in layout['nodes']: api.node_register(node['name'],obm=node['obm']) for nic in node['nics']: api.node_register_nic(node['name'], nic['name'], nic['mac']) api.switch_register_port(nic['switch'], nic['port']) api.port_connect_nic(nic['switch'], nic['port'], node['name'], nic['name'])
def site_layout(): """Load the file site-layout.json, and populate the database accordingly. This is meant to be used as a pytest fixture, but isn't declared here as such; individual modules should declare it as a fixture. Full documentation for the site-layout.json file format is located in ``docs/testing.md``. """ layout_json_data = open('site-layout.json') layout = json.load(layout_json_data) layout_json_data.close() for switch in layout['switches']: api.switch_register(**switch) for node in layout['nodes']: api.node_register(node['name'], obm=node['obm']) for nic in node['nics']: api.node_register_nic(node['name'], nic['name'], nic['mac']) api.switch_register_port(nic['switch'], nic['port']) api.port_connect_nic(nic['switch'], nic['port'], node['name'], nic['name'])
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)
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. """ # NOTE: Now that the session is managed by Flask-SQLAlchemy, failures here # are unlikely to be regressions of the issue that #454 fixed; we're no # longer managing the lifecycle of the session ourselves. It's not obvious # that this is more than clutter now, but let's not be too trigger happy # about deleting tests. with rest.app.test_request_context(): rest.init_auth() 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') client = rest.app.test_client() 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 = client.get(path) assert resp.status_code == 200 for node in json.loads(resp.get_data()): resp = client.get('/nodes/%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('/nodes/free') resp = client.get('/projects') assert resp.status_code == 200 for project in json.loads(resp.get_data()): _show_nodes('/project/%s/nodes' % project)