Ejemplo n.º 1
0
    def test_set_static_ip(self):
        '''
        Test if it set static IP configuration on a Windows NIC.
        '''
        self.assertRaises(SaltInvocationError, win_ip.set_static_ip,
                          'Local Area Connection', '10.1.2/24')

        mock_cmd = MagicMock(return_value=ETHERNET_CONFIG)
        mock_all = MagicMock(return_value={'retcode': 1, 'stderr': 'Error'})
        with patch.dict(win_ip.__salt__, {'cmd.run': mock_cmd,
                                          'cmd.run_all': mock_all}):
            self.assertRaises(CommandExecutionError, win_ip.set_static_ip,
                              'Ethernet', '1.2.3.74/24', append=True)
            self.assertRaises(CommandExecutionError, win_ip.set_static_ip,
                              'Ethernet', '1.2.3.74/24')

        mock_all = MagicMock(return_value={'retcode': 0})
        with patch.dict(win_ip.__salt__, {'cmd.run': mock_cmd,
                                          'cmd.run_all': mock_all}):
            self.assertDictEqual(win_ip.set_static_ip('Local Area Connection',
                                                      '1.2.3.74/24'), {})
            self.assertDictEqual(win_ip.set_static_ip('Ethernet',
                                                      '1.2.3.74/24'),
                                 {'Address Info': {'IP Address': '1.2.3.74',
                                                   'Netmask': '255.255.255.0',
                                                   'Subnet': '1.2.3.0/24'}})
Ejemplo n.º 2
0
    def test_set_static_ip(self):
        """
        Test if it set static IP configuration on a Windows NIC.
        """
        self.assertRaises(
            SaltInvocationError,
            win_ip.set_static_ip,
            "Local Area Connection",
            "10.1.2/24",
        )

        mock_cmd = MagicMock(return_value=ETHERNET_CONFIG)
        mock_all = MagicMock(return_value={"retcode": 1, "stderr": "Error"})
        with patch.dict(win_ip.__salt__, {
                "cmd.run": mock_cmd,
                "cmd.run_all": mock_all
        }):
            self.assertRaises(
                CommandExecutionError,
                win_ip.set_static_ip,
                "Ethernet",
                "1.2.3.74/24",
                append=True,
            )
            self.assertRaises(CommandExecutionError, win_ip.set_static_ip,
                              "Ethernet", "1.2.3.74/24")

        mock_all = MagicMock(return_value={"retcode": 0})
        with patch.dict(win_ip.__salt__, {
                "cmd.run": mock_cmd,
                "cmd.run_all": mock_all
        }):
            self.assertDictEqual(
                win_ip.set_static_ip("Local Area Connection", "1.2.3.74/24"),
                {})
            self.assertDictEqual(
                win_ip.set_static_ip("Ethernet", "1.2.3.74/24"),
                {
                    "Address Info": {
                        "IP Address": "1.2.3.74",
                        "Netmask": "255.255.255.0",
                        "Subnet": "1.2.3.0/24",
                    }
                },
            )
Ejemplo n.º 3
0
    def test_set_static_ip(self):
        """
        Test if it set static IP configuration on a Windows NIC.
        """
        self.assertRaises(SaltInvocationError, win_ip.set_static_ip, "Local Area Connection", "10.1.2/24")

        mock_cmd = MagicMock(return_value=ETHERNET_CONFIG)
        mock_all = MagicMock(return_value={"retcode": 1, "stderr": "Error"})
        with patch.dict(win_ip.__salt__, {"cmd.run": mock_cmd, "cmd.run_all": mock_all}):
            self.assertRaises(CommandExecutionError, win_ip.set_static_ip, "Ethernet", "1.2.3.74/24", append=True)
            self.assertRaises(CommandExecutionError, win_ip.set_static_ip, "Ethernet", "1.2.3.74/24")

        mock_all = MagicMock(return_value={"retcode": 0})
        with patch.dict(win_ip.__salt__, {"cmd.run": mock_cmd, "cmd.run_all": mock_all}):
            self.assertDictEqual(win_ip.set_static_ip("Local Area Connection", "1.2.3.74/24"), {})
            self.assertDictEqual(
                win_ip.set_static_ip("Ethernet", "1.2.3.74/24"),
                {"Address Info": {"IP Address": "1.2.3.74", "Netmask": "255.255.255.0", "Subnet": "1.2.3.0/24"}},
            )