diff --git a/netjsonconfig/backends/openwrt/openwrt.py b/netjsonconfig/backends/openwrt/openwrt.py index 2c22b8c3f..f7d0da84a 100644 --- a/netjsonconfig/backends/openwrt/openwrt.py +++ b/netjsonconfig/backends/openwrt/openwrt.py @@ -4,6 +4,7 @@ import time import tarfile from io import BytesIO +from copy import deepcopy from jsonschema import validate from jsonschema.exceptions import ValidationError as JsonSchemaError @@ -32,7 +33,8 @@ def __init__(self, config, templates=[]): as a base for the main config, defaults to empty list :raises TypeError: raised if config is not dict or templates is not a list """ - config = self._load(config) + # perform deepcopy to avoid modifying the original config argument + config = deepcopy(self._load(config)) # allow omitting NetJSON type if 'type' not in config: config.update({'type': 'DeviceConfiguration'}) diff --git a/tests/openwrt/test_backend.py b/tests/openwrt/test_backend.py index c22102b02..a558d08f4 100644 --- a/tests/openwrt/test_backend.py +++ b/tests/openwrt/test_backend.py @@ -12,8 +12,15 @@ class TestBackend(unittest.TestCase, _TabsMixin): """ tests for backends.openwrt.OpenWrt """ + def test_config_copy(self): + config = {'interfaces': []} + o = OpenWrt(config) + o.validate() + self.assertDictEqual(config, {'interfaces': []}) + def test_json_method(self): config = { + "type": "DeviceConfiguration", "interfaces": [ { "name": "lo",