Ejemplo n.º 1
0
    def test_set_static_dns_no_action(self):
        """
        Test if it set static DNS configuration on a Windows NIC.
        """
        # Test passing nothing
        self.assertDictEqual(
            win_ip.set_static_dns("Ethernet"),
            {
                "DNS Server": "No Changes",
                "Interface": "Ethernet"
            },
        )
        # Test passing None
        self.assertDictEqual(
            win_ip.set_static_dns("Ethernet", None),
            {
                "DNS Server": "No Changes",
                "Interface": "Ethernet"
            },
        )

        # Test passing string None
        self.assertDictEqual(
            win_ip.set_static_dns("Ethernet", "None"),
            {
                "DNS Server": "No Changes",
                "Interface": "Ethernet"
            },
        )
Ejemplo n.º 2
0
 def test_set_static_dns_clear(self):
     """
     Test if it set static DNS configuration on a Windows NIC.
     """
     mock_cmd = MagicMock()
     with patch.dict(win_ip.__salt__, {"cmd.run": mock_cmd}):
         self.assertDictEqual(
             win_ip.set_static_dns("Ethernet", []),
             {
                 "DNS Server": [],
                 "Interface": "Ethernet"
             },
         )
         mock_cmd.assert_called_once_with(
             [
                 "netsh",
                 "interface",
                 "ip",
                 "set",
                 "dns",
                 "name=Ethernet",
                 "source=static",
                 "address=none",
             ],
             python_shell=False,
         )
Ejemplo n.º 3
0
 def test_set_static_dns(self):
     '''
     Test if it set static DNS configuration on a Windows NIC.
     '''
     mock_cmd = MagicMock()
     with patch.dict(win_ip.__salt__, {'cmd.run': mock_cmd}):
         self.assertDictEqual(
             win_ip.set_static_dns('Ethernet', '192.168.1.252',
                                   '192.168.1.253'), {
                                       'DNS Server':
                                       ('192.168.1.252', '192.168.1.253'),
                                       'Interface': 'Ethernet'
                                   })
         mock_cmd.assert_has_calls([
             call([
                 'netsh', 'interface', 'ip', 'set', 'dns', 'name=Ethernet',
                 'source=static', 'address=192.168.1.252',
                 'register=primary'
             ],
                  python_shell=False),
             call([
                 'netsh', 'interface', 'ip', 'add', 'dns', 'name=Ethernet',
                 'address=192.168.1.253', 'index=2'
             ],
                  python_shell=False)
         ])
Ejemplo n.º 4
0
 def test_set_static_dns(self):
     """
     Test if it set static DNS configuration on a Windows NIC.
     """
     mock_cmd = MagicMock(return_value=ETHERNET_CONFIG)
     with patch.dict(win_ip.__salt__, {"cmd.run": mock_cmd}):
         self.assertDictEqual(
             win_ip.set_static_dns("Ethernet", "192.168.1.252", "192.168.1.253"),
             {"DNS Server": ("192.168.1.252", "192.168.1.253"), "Interface": "Ethernet"},
         )
Ejemplo n.º 5
0
    def test_set_static_dns_no_action(self):
        '''
        Test if it set static DNS configuration on a Windows NIC.
        '''
        # Test passing nothing
        self.assertDictEqual(win_ip.set_static_dns('Ethernet'), {
            'DNS Server': 'No Changes',
            'Interface': 'Ethernet'
        })
        # Test passing None
        self.assertDictEqual(win_ip.set_static_dns('Ethernet', None), {
            'DNS Server': 'No Changes',
            'Interface': 'Ethernet'
        })

        # Test passing string None
        self.assertDictEqual(win_ip.set_static_dns('Ethernet', 'None'), {
            'DNS Server': 'No Changes',
            'Interface': 'Ethernet'
        })
Ejemplo n.º 6
0
 def test_set_static_dns(self):
     '''
     Test if it set static DNS configuration on a Windows NIC.
     '''
     mock_cmd = MagicMock(return_value=ETHERNET_CONFIG)
     with patch.dict(win_ip.__salt__, {'cmd.run': mock_cmd}):
         self.assertDictEqual(win_ip.set_static_dns('Ethernet',
                                                    '192.168.1.252',
                                                    '192.168.1.253'),
                              {'DNS Server': ('192.168.1.252',
                                              '192.168.1.253'),
                               'Interface': 'Ethernet'})
Ejemplo n.º 7
0
 def test_set_static_dns_clear(self):
     '''
     Test if it set static DNS configuration on a Windows NIC.
     '''
     mock_cmd = MagicMock()
     with patch.dict(win_ip.__salt__, {'cmd.run': mock_cmd}):
         self.assertDictEqual(win_ip.set_static_dns('Ethernet', []), {
             'DNS Server': [],
             'Interface': 'Ethernet'
         })
         mock_cmd.assert_called_once_with([
             'netsh', 'interface', 'ip', 'set', 'dns', 'name=Ethernet',
             'source=static', 'address=none'
         ],
                                          python_shell=False)
Ejemplo n.º 8
0
 def test_set_static_dns(self):
     """
     Test if it set static DNS configuration on a Windows NIC.
     """
     mock_cmd = MagicMock()
     with patch.dict(win_ip.__salt__, {"cmd.run": mock_cmd}):
         self.assertDictEqual(
             win_ip.set_static_dns("Ethernet", "192.168.1.252",
                                   "192.168.1.253"),
             {
                 "DNS Server": ("192.168.1.252", "192.168.1.253"),
                 "Interface": "Ethernet",
             },
         )
         mock_cmd.assert_has_calls([
             call(
                 [
                     "netsh",
                     "interface",
                     "ip",
                     "set",
                     "dns",
                     "name=Ethernet",
                     "source=static",
                     "address=192.168.1.252",
                     "register=primary",
                 ],
                 python_shell=False,
             ),
             call(
                 [
                     "netsh",
                     "interface",
                     "ip",
                     "add",
                     "dns",
                     "name=Ethernet",
                     "address=192.168.1.253",
                     "index=2",
                 ],
                 python_shell=False,
             ),
         ])