# Path: ceph_deploy/util/net.py
# LOG = logging.getLogger(__name__)
# def get_nonlocal_ip(host, subnet=None):
# def ip_in_subnet(ip, subnet):
# def in_subnet(cidr, addrs=None):
# def ip_addresses(conn, interface=None, include_loopback=False):
# def linux_interfaces(conn):
# def _interfaces_ip(out):
#     def parse_network(value, cols):
# def _interfaces_ifconfig(out):
# def _number_of_set_bits_to_ipv4_netmask(set_bits):  # pylint: disable=C0103
# def _number_of_set_bits(x):
# def cidr_to_ipv4_netmask(cidr_bits):
# def get_request(url):
# def get_chacra_repo(shaman_url):
# 
# Path: ceph_deploy/tests/util.py
# def generate_ips(start_ip, end_ip):
#     def __init__(self, **kw):
# def assert_too_few_arguments(err):
# class Empty(object):


    from urllib.error import HTTPError
    from urllib2 import HTTPError
    from StringIO import StringIO
    from io import StringIO
from ceph_deploy.util import net
from ceph_deploy.tests import util
import pytest

    @pytest.mark.parametrize('ip', util.generate_ips("10.0.0.1", "10.0.0.255"))
    def test_false_for_10_0_0_255(self, ip):
        assert net.ip_in_subnet(ip, "10.2.0.0/24") is False

    @pytest.mark.parametrize('ip', util.generate_ips("255.255.255.1", "255.255.255.255"))
    def test_false_for_255_addresses(self, ip):
        assert net.ip_in_subnet(ip, "10.9.1.0/16") is False

    @pytest.mark.parametrize('ip', util.generate_ips("172.7.1.1", "172.7.1.255"))
    def test_false_for_172_addresses(self, ip):
        assert net.ip_in_subnet(ip, "172.3.0.0/16") is False

    @pytest.mark.parametrize('ip', util.generate_ips("10.9.8.0", "10.9.8.255"))
    def test_true_for_16_subnets(self, ip):
        assert net.ip_in_subnet(ip, "10.9.1.0/16") is True

    @pytest.mark.parametrize('ip', util.generate_ips("10.9.8.0", "10.9.8.255"))
    def test_false_for_24_subnets(self, ip):
        assert net.ip_in_subnet(ip, "10.9.1.0/24") is False


class TestGetRequest(object):

    def test_urlopen_fails(self, monkeypatch):
        def bad_urlopen(url):
            raise HTTPError('url', 500, 'error', '', StringIO())

        monkeypatch.setattr(net, 'urlopen', bad_urlopen)
        with pytest.raises(RuntimeError):

# Path: ceph_deploy/util/net.py
# LOG = logging.getLogger(__name__)
# def get_nonlocal_ip(host, subnet=None):
# def ip_in_subnet(ip, subnet):
# def in_subnet(cidr, addrs=None):
# def ip_addresses(conn, interface=None, include_loopback=False):
# def linux_interfaces(conn):
# def _interfaces_ip(out):
#     def parse_network(value, cols):
# def _interfaces_ifconfig(out):
# def _number_of_set_bits_to_ipv4_netmask(set_bits):  # pylint: disable=C0103
# def _number_of_set_bits(x):
# def cidr_to_ipv4_netmask(cidr_bits):
# def get_request(url):
# def get_chacra_repo(shaman_url):
# 
# Path: ceph_deploy/tests/util.py
# def generate_ips(start_ip, end_ip):
#     def __init__(self, **kw):
# def assert_too_few_arguments(err):
# class Empty(object):


# Path: ceph_deploy/tests/unit/util/test_net.py
    from urllib.error import HTTPError
    from urllib2 import HTTPError
    from StringIO import StringIO
    from io import StringIO
from ceph_deploy.util import net
from ceph_deploy.tests import util
import pytest


    @pytest.mark.parametrize('ip', util.generate_ips("10.0.0.1", "10.0.0.255"))
    def test_false_for_10_0_0_255(self, ip):
        assert net.ip_in_subnet(ip, "10.2.0.0/24") is False

    @pytest.mark.parametrize('ip', util.generate_ips("255.255.255.1", "255.255.255.255"))
    def test_false_for_255_addresses(self, ip):
        assert net.ip_in_subnet(ip, "10.9.1.0/16") is False

    @pytest.mark.parametrize('ip', util.generate_ips("172.7.1.1", "172.7.1.255"))
    def test_false_for_172_addresses(self, ip):
        assert net.ip_in_subnet(ip, "172.3.0.0/16") is False

    @pytest.mark.parametrize('ip', util.generate_ips("10.9.8.0", "10.9.8.255"))
    def test_true_for_16_subnets(self, ip):
        assert net.ip_in_subnet(ip, "10.9.1.0/16") is True

    @pytest.mark.parametrize('ip', util.generate_ips("10.9.8.0", "10.9.8.255"))
    def test_false_for_24_subnets(self, ip):
        assert net.ip_in_subnet(ip, "10.9.1.0/24") is False


class TestGetRequest(object):

    def test_urlopen_fails(self, monkeypatch):
        def bad_urlopen(url):
            raise HTTPError('url', 500, 'error', '', StringIO())

        monkeypatch.setattr(net, 'urlopen', bad_urlopen)
        with pytest.raises(RuntimeError):

            net.get_request('https://example.ceph.com')