Skip to content

Commit

Permalink
Changing exported dict should not affect on adapter (#39)
Browse files Browse the repository at this point in the history
Co-authored-by: Igor Mineev <mineev@cryptopro.ru>
  • Loading branch information
ObjatieGroba and Igor Mineev committed Mar 20, 2021
1 parent f56d1e5 commit 56c6e19
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
18 changes: 10 additions & 8 deletions debinterface/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
every options on earth !
"""
from __future__ import print_function, with_statement, absolute_import

import copy
import socket
import warnings

from .adapterValidation import NetworkAdapterValidation, VALID_OPTS


Expand Down Expand Up @@ -427,8 +430,8 @@ def setUnknown(self, key, val):
self._ifAttributes['unknown'][key] = val

def export(self, options_list=None):
""" Return the ifAttributes data structure. as dict.
You may pass a list of options you want
""" Return a copy of the ifAttributes data structure as dict.
You may optionally pass a list of options to return
Args:
options_list (list, optional): a list of options you want
Expand All @@ -437,16 +440,15 @@ def export(self, options_list=None):
dict: the ifAttributes data structure, optionaly filtered
"""

attrs = self._ifAttributes
if options_list:
ret = {}
attrs = {}
for k in options_list:
try:
ret[k] = self._ifAttributes[k]
attrs[k] = self._ifAttributes[k]
except KeyError:
ret[k] = None
return ret
else:
return self._ifAttributes
attrs[k] = None
return copy.deepcopy(attrs)

def display(self):
"""Display a (kind of) human readable representation of the adapter."""
Expand Down
9 changes: 9 additions & 0 deletions test/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ def test_add_adapter_index(self):
self.assertEqual(len(itfs.adapters), nb_adapters + 1)
self.assertEqual(itfs.adapters[4].attributes["name"], options["name"])

def test_export_adapter_settings(self):
itfs = Interfaces(interfaces_path=INF_PATH)
adapter = itfs.getAdapter("eth0")
attrs = adapter.export()
attrs["attr"] = "value"
with self.assertRaises(KeyError):
adapter.get_attr("attr")


def test_remove_adapter(self):
itfs = Interfaces(interfaces_path=INF_PATH)
nb_adapters = len(itfs.adapters)
Expand Down

0 comments on commit 56c6e19

Please sign in to comment.