示例#1
0
    def test__init_ssh_raise_exception(self):
        """ UT: nxos module:_init_ssh method - raise exception """
        class SSHException(Exception):
            pass

        with patch("salt.proxy.nxos.SSHConnection",
                   autospec=True) as SSHConnection:
            with patch("salt.proxy.nxos.log", autospec=True) as log:
                with self.assertRaises(SSHException):
                    SSHConnection.side_effect = SSHException
                    nxos_proxy._init_ssh(None)
                log.error.assert_called()
示例#2
0
    def test__init_ssh_opts(self):
        """ UT: nxos module:_init_ssh method - successful connectinon """

        with patch("salt.proxy.nxos.DEVICE_DETAILS", {}):
            with patch("salt.proxy.nxos.SSHConnection",
                       autospec=True) as SSHConnection:
                SSHConnection().sendline.return_value = ["", ""]
                nxos_proxy._init_ssh(None)
                self.assertEqual(
                    nxos_proxy.__opts__["proxy"]["host"],
                    SSHConnection.call_args[1]["host"],
                )

                opts = MagicMock()
                nxos_proxy._init_ssh(opts)
                self.assertEqual(opts["proxy"]["host"],
                                 SSHConnection.call_args[1]["host"])
示例#3
0
    def test__init_ssh_device_details(self):
        with patch("salt.proxy.nxos.SSHConnection",
                   autospec=True) as SSHConnection:
            SSHConnection().sendline.return_value = ["", ""]

            with patch("salt.proxy.nxos.DEVICE_DETAILS", {}) as device_details:
                nxos_proxy._init_ssh(None)
                self.assertIn(nxos_proxy._worker_name(), device_details)
                self.assertTrue(device_details["initialized"])
                self.assertTrue(device_details["save_config"])

            with patch.dict(nxos_proxy.__opts__["proxy"],
                            {"save_config": False}):
                with patch("salt.proxy.nxos.DEVICE_DETAILS",
                           {}) as device_details:
                    nxos_proxy._init_ssh(None)
                    self.assertIn(nxos_proxy._worker_name(), device_details)
                    self.assertTrue(device_details["initialized"])
                    self.assertFalse(device_details["save_config"])
示例#4
0
    def test__init_ssh_prompt(self):
        """ UT: nxos module:_init_ssh method - prompt regex """

        with patch("salt.proxy.nxos.DEVICE_DETAILS", {}):
            with patch("salt.proxy.nxos.SSHConnection",
                       autospec=True) as SSHConnection:
                SSHConnection().sendline.return_value = ["", ""]

                with patch.dict(nxos_proxy.__opts__["proxy"],
                                {"prompt_regex": "n9k.*device"}):
                    nxos_proxy._init_ssh(None)
                    self.assertEqual("n9k.*device",
                                     SSHConnection.call_args[1]["prompt"])

                with patch.dict(nxos_proxy.__opts__["proxy"],
                                {"prompt_name": "n9k-device"}):
                    nxos_proxy._init_ssh(None)
                    self.assertEqual("n9k-device.*#",
                                     SSHConnection.call_args[1]["prompt"])

                nxos_proxy._init_ssh(None)
                self.assertEqual(".+#$", SSHConnection.call_args[1]["prompt"])