Skip to content

Commit

Permalink
improved getitems
Browse files Browse the repository at this point in the history
  • Loading branch information
fsalamida committed Jul 3, 2014
1 parent 51f773d commit 7a81b56
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 13 deletions.
14 changes: 11 additions & 3 deletions pynetworking/features/ats_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,18 @@ def __str__(self):
__repr__ = __str__ #pragma: no cover

def __getitem__(self, ifn):
if isinstance(ifn, str) or isinstance(vid, unicode):
self._update_interface()
if ifn in self._interface:
return self._interface[ifn]
raise KeyError('interface {0} does not exist'.format(ifn))
else:
raise TypeError, "Invalid argument type."

def __iter__(self):
self._update_interface()
if ifn in self._interface.keys():
return self._interface[ifn]
raise IndexError
for interface in self._interface:
yield interface

def _update_interface(self):
self._d.log_info("_update_interface")
Expand Down
14 changes: 11 additions & 3 deletions pynetworking/features/awp_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,18 @@ def __str__(self):
__repr__ = __str__ #pragma: no cover

def __getitem__(self, ifn):
if isinstance(ifn, str) or isinstance(vid, unicode):
self._update_interface()
if ifn in self._interface:
return self._interface[ifn]
raise KeyError('interface {0} does not exist'.format(ifn))
else:
raise TypeError, "Invalid argument type."

def __iter__(self):
self._update_interface()
if ifn in self._interface.keys():
return self._interface[ifn]
raise KeyError('{0} key does not exist'.format(key))
for interface in self._interface:
yield interface

def _get_interface_ns(self, ifn):
ifn = str(ifn)
Expand Down
17 changes: 12 additions & 5 deletions pynetworking/features/awp_vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def add_interface(self, vid, ifn, tagged=False):
self._device.cmd(cmds, cache=False, flush_cache=True)
self._device.load_system()


def delete_interface(self, vid, ifn):
self._d.log_info("delete_interface {0} ifn={1}".format(vid, ifn))
self._update_vlan()
Expand Down Expand Up @@ -168,11 +167,19 @@ def __str__(self):
__repr__ = __str__ #pragma: no cover

def __getitem__(self, vid):
if isinstance(vid, str) or isinstance(vid, int) or isinstance(vid, unicode):
self._update_vlan()
vid = str(vid)
if vid in self._vlan:
return self._vlan[vid]
raise KeyError('vlan id {0} does not exist'.format(vid))
else:
raise TypeError, "Invalid argument type."

def __iter__(self):
self._update_vlan()
vid = str(vid)
if vid in self._vlan:
return self._vlan[vid]
raise KeyError('vlan id {0} does not exist'.format(vid))
for vlan in self._vlan:
yield vlan

def _get_vlan_ids(self, vlan_id):
vlan_id = str(vlan_id)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def run(self):
'Jinja2',
'ply',
'pyasn1',
'pyzmq',
'pyzmq>=14.0.0',
'ordereddict'
],
setup_requires = [ 'sphinx',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ def test_description(dut, log_level):
d.interface.update('1.0.10',description='camera_1')
assert d.interface['1.0.10']['description'] == 'camera_1'
d.interface.update('1.0.10',description='cam one')
# assert d.interface['1.0.10']['description'] == 'cam one'
d.close()

def test_unexisting_interface(dut, log_level):
Expand All @@ -272,4 +271,5 @@ def test_unexisting_interface(dut, log_level):
with pytest.raises(ValueError) as excinfo:
d.interface.update(max_if_name,enable=False)
assert max_if_str in excinfo.value
assert '1.0.10' in d.interface
d.close()
1 change: 1 addition & 0 deletions tests/test_interface_ats.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ def test_update_interface_48(dut, log_level):
"""]})
d=Device(host=dut.host,port=dut.port,protocol=dut.protocol, log_level=log_level)
d.open()
assert '1.0.10' in d.interface
assert d.interface['1.0.24']['enable'] == False
d.interface.update('1.0.18',description='test description')
assert d.interface['1.0.18']['description'] == 'test description'
Expand Down
1 change: 1 addition & 0 deletions tests/test_vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def test_create_vlan_1(dut, log_level):
d=Device(host=dut.host,port=dut.port,protocol=dut.protocol, log_level=log_level)
d.open()
d.vlan.create(20, name='admin', mtu=1300)
assert '20' in d.vlan
assert d.vlan[20]['state'] == 'enable'
assert d.vlan[20]['name'] == 'admin'
assert d.vlan[20]['mtu'] == 1300
Expand Down

0 comments on commit 7a81b56

Please sign in to comment.