Exemple #1
0
    def test_host_to_ips(self):
        """
        NOTE: When this test fails it's usually because the IP address has
        changed. In these cases, we just need to update the IP address in the
        assertion.
        """

        def _side_effect(host, *args):
            try:
                return {
                    "github.com": [
                        (2, 1, 6, "", ("192.30.255.112", 0)),
                        (2, 1, 6, "", ("192.30.255.113", 0)),
                    ],
                    "ipv6host.foo": [
                        (socket.AF_INET6, 1, 6, "", ("2001:a71::1", 0, 0, 0)),
                    ],
                }[host]
            except KeyError:
                raise socket.gaierror(-2, "Name or service not known")

        getaddrinfo_mock = MagicMock(side_effect=_side_effect)
        with patch.object(socket, "getaddrinfo", getaddrinfo_mock):
            # Test host that can be resolved
            ret = network.host_to_ips("github.com")
            self.assertEqual(ret, ["192.30.255.112", "192.30.255.113"])
            # Test ipv6
            ret = network.host_to_ips("ipv6host.foo")
            self.assertEqual(ret, ["2001:a71::1"])
            # Test host that can't be resolved
            ret = network.host_to_ips("someothersite.com")
            self.assertEqual(ret, None)
Exemple #2
0
    def test_host_to_ips(self):
        '''
        NOTE: When this test fails it's usually because the IP address has
        changed. In these cases, we just need to update the IP address in the
        assertion.
        '''
        def _side_effect(host, *args):
            try:
                return {
                    'github.com': [
                        (2, 1, 6, '', ('192.30.255.112', 0)),
                        (2, 1, 6, '', ('192.30.255.113', 0)),
                    ],
                    'ipv6host.foo': [
                        (socket.AF_INET6, 1, 6, '', ('2001:a71::1', 0, 0, 0)),
                    ],
                }[host]
            except KeyError:
                raise socket.gaierror(-2, 'Name or service not known')

        getaddrinfo_mock = MagicMock(side_effect=_side_effect)
        with patch.object(socket, 'getaddrinfo', getaddrinfo_mock):
            # Test host that can be resolved
            ret = network.host_to_ips('github.com')
            self.assertEqual(ret, ['192.30.255.112', '192.30.255.113'])
            # Test ipv6
            ret = network.host_to_ips('ipv6host.foo')
            self.assertEqual(ret, ['2001:a71::1'])
            # Test host that can't be resolved
            ret = network.host_to_ips('someothersite.com')
            self.assertEqual(ret, None)
Exemple #3
0
 def test_host_to_ips(self):
     '''
     NOTE: When this test fails it's usually because the IP address has
     changed. In these cases, we just need to update the IP address in the
     assertion.
     '''
     ret = network.host_to_ips('www.saltstack.com')
     self.assertEqual(ret, ['104.197.168.128'])
Exemple #4
0
 def test_host_to_ips(self):
     ret = network.host_to_ips('www.saltstack.com')
     self.assertEqual(ret, ['104.199.122.13'])
Exemple #5
0
 def test_host_to_ips(self):
     ret = network.host_to_ips('www.saltstack.com')
     self.assertEqual(ret, ['104.199.122.13'])