Beispiel #1
0
def test_wire_request_sucess(mock_logging, mock_request, mock_resolver):
    """Test success for info on the wire server"""
    mock_request.side_effect = [
        None,
        _get_proper_goal_state_response(),
        _get_proper_extensions_response()
    ]
    mock_resolver.return_value = _get_nameserver_resolver()
    result = azure.generateRegionSrvArgs()
    assert result == 'regionHint=useast'
Beispiel #2
0
def test_wire_request_goal_state_request_fail(mock_logging, mock_request,
                                              mock_resolver):
    """Test behavior goal state access triggering exception"""
    mock_request.side_effect = [None, Exception]
    mock_resolver.return_value = _get_nameserver_resolver()
    result = azure.generateRegionSrvArgs()
    assert result == None
    assert mock_logging.warning.called
    expected = 'Could not retrieve goal state XML from 1.1.1.1'
    actual = _get_msg(mock_logging.warning.call_args_list[0])
    assert actual == expected
Beispiel #3
0
def test_metadata_request_fail(mock_logging, mock_request, mock_resolver):
    """Test proper exception handling when request to metadata server fails"""
    mock_request.side_effect = Exception
    mock_resolver.return_value = _get_no_nameservers_resolver()
    result = azure.generateRegionSrvArgs()
    assert result == None
    assert mock_logging.warning.called
    expected = 'Unable to determine instance placement from metadata '
    expected += 'server "http://169.254.169.254/metadata/instance/location"'
    actual = _get_msg(mock_logging.warning.call_args_list[0])
    assert actual == expected
Beispiel #4
0
def test_wire_request_goal_state_request_success_no_match(
        mock_logging, mock_request, mock_resolver):
    """Test behavior with goal state request success improper data"""
    mock_request.side_effect = [None, _get_unexpected_response()]
    mock_resolver.return_value = _get_nameserver_resolver()
    result = azure.generateRegionSrvArgs()
    assert result == None
    assert mock_logging.warning.called
    expected = 'No "<ExtensionsConfig>" in goal state XML'
    actual = _get_msg(mock_logging.warning.call_args_list[0])
    assert actual == expected
Beispiel #5
0
def test_wire_request_goal_state_request_fail_server_error(
        mock_logging, mock_request, mock_resolver):
    """Test behavior with goal state access triggering server error"""
    mock_request.side_effect = [None, _get_error_response()]
    mock_resolver.return_value = _get_nameserver_resolver()
    result = azure.generateRegionSrvArgs()
    assert result == None
    assert mock_logging.warning.called
    expected = '1.1.1.1 error for goal state request: 500'
    actual = _get_msg(mock_logging.warning.call_args_list[0])
    assert actual == expected
Beispiel #6
0
def test_wire_request_extension_request_fail_server_error(
        mock_logging, mock_request, mock_resolver):
    """Test request for extension data triggering server error"""
    mock_request.side_effect = [
        None, _get_proper_goal_state_response(),
        _get_error_response()
    ]
    mock_resolver.return_value = _get_nameserver_resolver()
    result = azure.generateRegionSrvArgs()
    assert result == None
    assert mock_logging.warning.called
    expected = 'Extensions request failed with: 500'
    actual = _get_msg(mock_logging.warning.call_args_list[0])
    assert actual == expected
Beispiel #7
0
def test_wire_request_extension_request_fail(mock_logging, mock_request,
                                             mock_resolver):
    """Test behavior with extension request triggering  exception"""
    mock_request.side_effect = [
        None, _get_proper_goal_state_response(), Exception
    ]
    mock_resolver.return_value = _get_nameserver_resolver()
    result = azure.generateRegionSrvArgs()
    assert result == None
    assert mock_logging.warning.called
    expected = 'Could not get extensions information from "'
    expected += 'http://ola%sdme&?getit=1"'
    actual = _get_msg(mock_logging.warning.call_args_list[0])
    assert actual == expected
Beispiel #8
0
def test_metadata_request_fail_server_error(mock_logging, mock_request):
    """Test metadata server error code return"""
    mock_request.return_value = _get_error_response()
    result = azure.generateRegionSrvArgs()
    assert result == None
    assert mock_logging.warning.called
    expected = 'Unable to get availability zone metadata'
    actual = _get_msg(mock_logging.warning.call_args_list[0])
    assert actual == expected
    expected = '\tReturn code: 500'
    actual = _get_msg(mock_logging.warning.call_args_list[1])
    assert actual == expected
    expected = '\tMessage: Test server failure'
    actual = _get_msg(mock_logging.warning.call_args_list[2])
    assert actual == expected
Beispiel #9
0
def test_metadata_request_success(mock_request):
    """Test unexpected return value"""
    mock_request.return_value = _get_expected_response_metadata()
    result = azure.generateRegionSrvArgs()
    assert result == 'regionHint=useast'