Example #1
0
    def test_bad_config_pass_string(self):
        command = "asdf poknw"
        self.device.cu.load.side_effect = ConfigLoadError(command)

        with pytest.raises(CommandError) as err:
            self.device.config(command)
        assert err.value.command == command
Example #2
0
    def test_exec_command_fail_to_load(self, mock_rpc_error, mock_config):

        # Mocks
        config_load_error = ConfigLoadError('')
        config_load_error.rpc_error = mock_rpc_error
        mock_config.load.side_effect = config_load_error  # Forced exception here

        # Create plugin
        plugin = JUNOS(equipment_access=self.mock_equipment_access)
        plugin.configuration = mock_config  # add mock to plugin instance

        # Test
        with self.assertRaises(exceptions.APIException):
            plugin.exec_command("any command")
        plugin.configuration.load.assert_called_with(
            "any command",
            format='set',
            ignore_warning=plugin.ignore_warning_list)
 def test_config_load_try_load_rpcerror(self, mock_open):
     ex = ConfigLoadError(
         rsp=etree.fromstring(("""<load-configuration-results>
             <rpc-error>
             <error-severity>error</error-severity>
             <error-message>syntax error</error-message>
             </rpc-error>
             </load-configuration-results>""")))
     self.conf.rpc.load_config = MagicMock(side_effect=ex)
     self.assertRaises(ConfigLoadError, self.conf.load, path='config.conf')
Example #4
0
    def test_execute_diff_raise(self, mocked_device, capsys, caplog):
        """It should skip the device that raises an HomerLoadError."""
        mocked_device.return_value.cu.load.side_effect = ConfigLoadError(
            etree.XML(ERROR_RESPONSE.format(insert='')))
        return_code = self.homer.diff('device1*')

        out, _ = capsys.readouterr()
        assert return_code == 1
        assert 'Failed to get diff for device1.example.com: ConfigLoadError(' in caplog.text
        assert "Changes for 1 devices: ['device1.example.com']\n# Failed" in out
Example #5
0
    def test_commit_prepare_failed_load(self, mocked_junos_device):
        """It should raise if unable to load the configuration."""
        mocked_junos_device.return_value.cu = mock.MagicMock(
            spec_set=junos.Config)
        mocked_junos_device.return_value.cu.load.side_effect = ConfigLoadError(
            etree.XML(ERROR_RESPONSE.format(insert='')))
        device = junos.ConnectedDevice(self.fqdn)
        callback = mock.Mock()
        with pytest.raises(ConfigLoadError):
            device.commit('config', COMMIT_MESSAGE, callback)

        callback.assert_not_called()
        mocked_junos_device.return_value.cu.commit.assert_not_called()
        mocked_junos_device.return_value.cu.rollback.assert_not_called()
Example #6
0
 def load_side_effect(*args, **kwargs):
     if args[0] == commands[1]:
         raise ConfigLoadError(args[0])
Example #7
0
    def test_bad_config(self):
        command = 'asdf poknw'
        self.device.cu.load.side_effect = ConfigLoadError(command)

        with self.assertRaisesRegexp(CommandError, command):
            self.device.config(command)
Example #8
0
 def test_ConfigLoadError_repr(self):
     rsp = etree.XML(conf_xml)
     obj = ConfigLoadError(rsp=rsp)
     err = 'ConfigLoadError(severity: error, bad_element: ' \
           'system1, message: syntax error)'
     self.assertEqual(obj.__repr__(), err)
Example #9
0
 def test_ConfigLoadError_repr(self):
     rsp = etree.XML(conf_xml)
     obj = ConfigLoadError(rsp=rsp)
     err = 'ConfigLoadError(severity: error, bad_element: system1, message: syntax error)'
     self.assertEqual(obj.__repr__(), err)