def test_power_operations(mock_node): """Test the power-related obm api calls. i.e. power_off, power_cycle, set_bootdev, power_status """ # Obm is disabled; these should all fail: with pytest.raises(errors.BlockedError): api.node_power_off(mock_node) with pytest.raises(errors.BlockedError): api.node_power_on(mock_node) with pytest.raises(errors.BlockedError): api.node_set_bootdev(mock_node, 'A') with pytest.raises(errors.BlockedError): api.node_power_cycle(mock_node, force=True) with pytest.raises(errors.BlockedError): api.node_power_cycle(mock_node, force=False) with pytest.raises(errors.BlockedError): api.node_power_status(mock_node) with pytest.raises(errors.BlockedError): api.show_console(mock_node) # Now let's enable it and try again. api.node_enable_disable_obm(mock_node, enabled=True) def _power_cycle(force): _follow_redirect( 'POST', api.node_power_cycle(mock_node, force=force), data=json.dumps({ 'force': force, })) _follow_redirect('POST', api.node_power_off(mock_node)) resp = _follow_redirect('GET', api.node_power_status(mock_node)) assert json.loads(resp.content) == {'power_status': 'Mock Status'} _follow_redirect('POST', api.node_power_on(mock_node)) _follow_redirect( 'PUT', api.node_set_bootdev(mock_node, 'A'), data=json.dumps({'bootdev': 'A'}), ) _power_cycle(True) _power_cycle(False) resp = _follow_redirect('GET', api.show_console(mock_node), stream=True) # Read the first chunk of the output from the console to make sure it # looks right: i = 0 for line in resp.iter_lines(): assert line == str(i) if i >= 10: break i += 1
def test_enable_disable_obm(obmd_cfg): """Test enabling and disabling the obm of a node via the api.""" obmd_uri = 'http://localhost' + obmd_cfg['ListenAddr'] + '/node/node-99' # register a node with obmd: requests.put( obmd_uri, auth=('admin', obmd_cfg['AdminToken']), data=json.dumps({ "type": "ipmi", "info": { "addr": "10.0.0.4", "user": "******", "pass": "******", }, })) # and then with hil: api.node_register( node='node-99', obm={ "type": 'http://schema.massopencloud.org/haas/v0/obm/mock', "host": "ipmihost", "user": "******", "password": "******", }, obmd={ 'uri': obmd_uri, 'admin_token': obmd_cfg['AdminToken'], }, ) # Then create a project, and attach the node. api.project_create('anvil-nextgen') api.project_connect_node('anvil-nextgen', 'node-99') # now the test proper: # First, enable the obm api.node_enable_disable_obm('node-99', enabled=True) # Obm is enabled; we shouldn't be able to detach the node: with pytest.raises(errors.BlockedError): api.project_detach_node('anvil-nextgen', 'node-99') # ...so disable it first: api.node_enable_disable_obm('node-99', enabled=False) # ...and then it should work: api.project_detach_node('anvil-nextgen', 'node-99')
def test_enable_disable_obm(mock_node): """Test enabling and disabling the obm of a node via the api.""" # First, enable the obm api.node_enable_disable_obm(mock_node, enabled=True) # Obm is enabled; we shouldn't be able to detach the node: with pytest.raises(errors.BlockedError): api.project_detach_node('anvil-nextgen', mock_node) # ...so disable it first: api.node_enable_disable_obm(mock_node, enabled=False) # ...and then it should work: api.project_detach_node('anvil-nextgen', mock_node)
def test_power_operations(mock_node): """Test the power-related obm api calls. i.e. power_off, power_cycle, set_bootdev. """ # Obm is disabled; these should all fail: with pytest.raises(errors.BlockedError): api.node_power_off(mock_node) with pytest.raises(errors.BlockedError): api.node_power_on(mock_node) with pytest.raises(errors.BlockedError): api.node_set_bootdev(mock_node, 'A') with pytest.raises(errors.BlockedError): api.node_power_cycle(mock_node, force=True) with pytest.raises(errors.BlockedError): api.node_power_cycle(mock_node, force=False) # Now let's enable it and try again. api.node_enable_disable_obm(mock_node, enabled=True) def _power_cycle(force): _follow_redirect( 'POST', api.node_power_cycle(mock_node, force=force), data=json.dumps({ 'force': force, })) _follow_redirect('POST', api.node_power_off(mock_node)) _follow_redirect('POST', api.node_power_on(mock_node)) _follow_redirect( 'PUT', api.node_set_bootdev(mock_node, 'A'), data=json.dumps({'bootdev': 'A'}), ) _power_cycle(True) _power_cycle(False)