Exemplo n.º 1
0
def _leave(client, network):
    """Join the given network.

    Args:
        client (two1.server.rest_client.TwentyOneRestClient) an object
            for sending authenticated requests to the TwentyOne
            backend
        network (str): the name of the network being joined. Defaults
        to 21market
    """
    # ensures the zerotier daemon is running
    zerotier.start_daemon()
    is_in_network = False
    for ntwk in zerotier.list_networks():
        if ntwk['name'] == network:
            is_in_network = True
            nwid = ntwk['nwid']
            break
    if not is_in_network:
        logger.info('not in network')
        return {'left': False, 'reason': 'not in network'}
    try:
        zerotier.leave_network(nwid)
        logger.info(uxstring.UxString.successful_leave.format(click.style(network, fg="magenta")))
        return {'left': True}
    except subprocess.CalledProcessError as e:
        logger.info(str(e))
        return {'left': False, 'reason': str(e)}
Exemplo n.º 2
0
def _leave(client, network):
    """Join the given network.

    Args:
        client (two1.server.rest_client.TwentyOneRestClient) an object
            for sending authenticated requests to the TwentyOne
            backend
        network (str): the name of the network being joined. Defaults
        to 21market
    """
    # ensures the zerotier daemon is running
    zerotier.start_daemon()
    is_in_network = False
    for ntwk in zerotier.list_networks():
        if ntwk['name'] == network:
            is_in_network = True
            nwid = ntwk['nwid']
            break
    if not is_in_network:
        logger.info('not in network')
        return {'left': False, 'reason': 'not in network'}
    try:
        zerotier.leave_network(nwid)
        logger.info(
            uxstring.UxString.successful_leave.format(
                click.style(network, fg="magenta")))
        return {'left': True}
    except subprocess.CalledProcessError as e:
        logger.info(str(e))
        return {'left': False, 'reason': str(e)}
Exemplo n.º 3
0
def test_leave_network(mock_cli, network_id, outcome):
    """ Ensures that a ValueError is reaised on invalid id """
    if isinstance(outcome, str):
        mock_cli.return_value = outcome
        assert zerotier.leave_network(network_id) == outcome
    else:
        with pytest.raises(outcome):
            zerotier.leave_network(network_id)
Exemplo n.º 4
0
def test_leave_network(mock_cli, network_id, outcome):
    """ Ensures that a ValueError is reaised on invalid id """
    if isinstance(outcome, str):
        mock_cli.return_value = outcome
        assert zerotier.leave_network(network_id) == outcome
    else:
        with pytest.raises(outcome):
            zerotier.leave_network(network_id)