Esempio n. 1
0
    def test_dns_check_errors(self):
        with patch.object(socket, 'getaddrinfo', create_autospec(socket.getaddrinfo, return_value=[])):
            with self.assertRaisesRegex(salt.exceptions.SaltSystemExit,
                                        "DNS lookup or connection check of 'foo' failed"):
                network.dns_check('foo', '1')

        with patch.object(socket, 'getaddrinfo', create_autospec(socket.getaddrinfo, side_effect=TypeError)):
            with self.assertRaisesRegex(salt.exceptions.SaltSystemExit,
                                        "Invalid or unresolveable address"):
                network.dns_check('foo', '1')
Esempio n. 2
0
 def test_dns_check_ipv6_filter(self):
     # raise exception to skip everything after the getaddrinfo call
     with patch.object(socket, 'getaddrinfo',
                       create_autospec(socket.getaddrinfo, side_effect=Exception)) as getaddrinfo:
         for ipv6, param in [
             (None, socket.AF_UNSPEC),
             (True, socket.AF_INET6),
             (False, socket.AF_INET),
         ]:
             with self.assertRaises(Exception):
                 network.dns_check('foo', '1', ipv6=ipv6)
             getaddrinfo.assert_called_with('foo', '1', param, socket.SOCK_STREAM)
Esempio n. 3
0
 def test_dns_check(self):
     hosts = [
         {'host': '10.10.0.3',
          'port': '',
          'mocked': [(2, 1, 6, '', ('10.10.0.3', 0))],
          'ret': '10.10.0.3'},
         {'host': '10.10.0.3',
          'port': '1234',
          'mocked': [(2, 1, 6, '', ('10.10.0.3', 0))],
          'ret': '10.10.0.3'},
         {'host': '2001:0db8:85a3::8a2e:0370:7334',
          'port': '',
          'mocked': [(10, 1, 6, '', ('2001:db8:85a3::8a2e:370:7334', 0, 0, 0))],
          'ret': '[2001:db8:85a3::8a2e:370:7334]'},
         {'host': '2001:0db8:85a3::8a2e:370:7334',
          'port': '1234',
          'mocked': [(10, 1, 6, '', ('2001:db8:85a3::8a2e:370:7334', 0, 0, 0))],
          'ret': '[2001:db8:85a3::8a2e:370:7334]'},
         {'host': 'salt-master',
          'port': '1234',
          'mocked': [(2, 1, 6, '', ('127.0.0.1', 0))],
          'ret': '127.0.0.1'},
     ]
     for host in hosts:
         with patch.object(socket, 'getaddrinfo', create_autospec(socket.getaddrinfo, return_value=host['mocked'])):
             with patch('socket.socket', create_autospec(socket.socket)):
                 ret = network.dns_check(host['host'], host['port'])
                 self.assertEqual(ret, host['ret'])
Esempio n. 4
0
 def test_dns_check(self):
     hosts = [
         {
             "host": "10.10.0.3",
             "port": "",
             "mocked": [(2, 1, 6, "", ("10.10.0.3", 0))],
             "ret": "10.10.0.3",
         },
         {
             "host": "10.10.0.3",
             "port": "1234",
             "mocked": [(2, 1, 6, "", ("10.10.0.3", 0))],
             "ret": "10.10.0.3",
         },
         {
             "host":
             "2001:0db8:85a3::8a2e:0370:7334",
             "port":
             "",
             "mocked":
             [(10, 1, 6, "", ("2001:db8:85a3::8a2e:370:7334", 0, 0, 0))],
             "ret":
             "[2001:db8:85a3::8a2e:370:7334]",
         },
         {
             "host":
             "2001:0db8:85a3::8a2e:370:7334",
             "port":
             "1234",
             "mocked":
             [(10, 1, 6, "", ("2001:db8:85a3::8a2e:370:7334", 0, 0, 0))],
             "ret":
             "[2001:db8:85a3::8a2e:370:7334]",
         },
         {
             "host": "salt-master",
             "port": "1234",
             "mocked": [(2, 1, 6, "", ("127.0.0.1", 0))],
             "ret": "127.0.0.1",
         },
     ]
     for host in hosts:
         with patch.object(
                 socket,
                 "getaddrinfo",
                 create_autospec(socket.getaddrinfo,
                                 return_value=host["mocked"]),
         ):
             with patch("socket.socket", create_autospec(socket.socket)):
                 ret = network.dns_check(host["host"], host["port"])
                 self.assertEqual(ret, host["ret"])
Esempio n. 5
0
    def test_dns_check(self):
        class MockSocket(object):
            def __init__(self, *args, **kwargs):
                pass

            def __call__(self, *args, **kwargs):
                pass

            def setsockopt(self, *args, **kwargs):
                pass

            def sendto(self, *args, **kwargs):
                pass

            def connect(self, *args, **kwargs):
                pass

            def close(self, *args, **kwargs):
                pass

        hosts = [
            {'host': '10.10.0.3',
             'port': '',
             'mocked': [(2, 1, 6, '', ('10.10.0.3', 0))],
             'ret': '10.10.0.3'},
            {'host': '10.10.0.3',
             'port': '1234',
             'mocked': [(2, 1, 6, '', ('10.10.0.3', 0))],
             'ret': '10.10.0.3'},
            {'host': '2001:0db8:85a3::8a2e:0370:7334',
             'port': '',
             'mocked': [(10, 1, 6, '', ('2001:db8:85a3::8a2e:370:7334', 0, 0, 0))],
             'ret': '2001:db8:85a3::8a2e:370:7334'},
            {'host': '2001:0db8:85a3::8a2e:370:7334',
             'port': '1234',
             'mocked': [(10, 1, 6, '', ('2001:db8:85a3::8a2e:370:7334', 0, 0, 0))],
             'ret': '2001:db8:85a3::8a2e:370:7334'},
            {'host': 'salt-master',
             'port': '1234',
             'mocked': [(2, 1, 6, '', ('127.0.0.1', 0))],
             'ret': '127.0.0.1'},
        ]
        for host in hosts:
            with patch.object(socket, 'getaddrinfo', MagicMock(return_value=host['mocked'])):
                with patch('socket.socket', MockSocket):
                    ret = network.dns_check(host['host'], host['port'])
                    self.assertEqual(ret, host['ret'])