Example #1
0
    def test_exec_command_fail_to_commit_check(self, mock_config):

        # Mocks
        error = RpcError('')
        mock_config.commit_check.side_effect = error  # Forced exception here

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

        # Tests
        with self.assertRaises(exceptions.APIException):
            plugin.exec_command("any command")
        plugin.configuration.commit_check.assert_called_with()
Example #2
0
    def test_exec_command_fail_to_lock(self, time_sleep, mock_config):
        """
        test_exec_command_fail_to_lock
        """

        # Mocks
        time_sleep.return_value = None  # to be executed instantly
        mock_config.lock.side_effect = LockError('')  # 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.lock.assert_called_with()
Example #3
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)
Example #4
0
    def test_exec_command_success(self, mock_config):
        """
        test_exec_command_success - This test asserts the success of the complete workflow of executing any command.
        Note: All internal functions in Config Class are mocked, raising no exceptions on it
        """

        # Mocking result
        plugin = JUNOS(equipment_access=self.mock_equipment_access)
        plugin.plugin_try_lock = MagicMock()
        plugin.plugin_try_lock.return_value = True
        plugin.configuration = mock_config

        # Close real test
        exec_command_response = plugin.exec_command("any command")

        # Assert
        plugin.configuration.rollback.assert_called_once()
        plugin.configuration.load.assert_called_once()
        plugin.configuration.commit_check.assert_called_once()
        plugin.configuration.commit.assert_called_once()
        plugin.configuration.unlock.assert_called_once()
        self.assertIsNotNone(exec_command_response)