Skip to content

Commit

Permalink
The remove bond removes related rstp protocol
Browse files Browse the repository at this point in the history
In a juniper the rstp can still exist if the interface doesn't so let's remove it at the same time
  • Loading branch information
Martin Roy committed Sep 23, 2015
1 parent 893538d commit a62736b
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 1 deletion.
20 changes: 19 additions & 1 deletion netman/adapters/switches/juniper/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,16 @@ def add_bond(self, number):
raise

def remove_bond(self, number):
config = self.query(all_interfaces)
config = self.query(all_interfaces, one_rstp_protocol_interface(bond_name(number)))
self.get_bond_config(number, config)

update = Update()
update.add_interface(interface_removal(bond_name(number)))

rstp_node = first(config.xpath("data/configuration/protocols/rstp/interface/name[text()=\"{0:s}\"]/..".format(bond_name(number))))
if rstp_node is not None:
update.add_rstp_protocol_interface(rstp_interface_removal(bond_name(number)))

for interface_node in self.get_bond_slaves_config(number, config):
interface_name = first(interface_node.xpath("name")).text
update.add_interface(free_from_bond_operation(interface_name))
Expand Down Expand Up @@ -664,6 +668,20 @@ def rstp_protocol_interfaces():
""")


def one_rstp_protocol_interface(interface_id):
def m():
return to_ele("""
<protocols>
<rstp>
<interface>
<name>{}</name>
</interface>
</rstp>
</protocols>
""".format(interface_id))
return m


class Update(object):
def __init__(self):
self.root = new_ele("configuration")
Expand Down
78 changes: 78 additions & 0 deletions tests/adapters/switches/juniper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3482,6 +3482,13 @@ def test_remove_bond(self):
<filter>
<configuration>
<interfaces/>
<protocols>
<rstp>
<interface>
<name>ae10</name>
</interface>
</rstp>
</protocols>
</configuration>
</filter>
""")).and_return(a_configuration("""
Expand Down Expand Up @@ -3509,13 +3516,77 @@ def test_remove_bond(self):

self.switch.remove_bond(10)

def test_remove_bond_also_removes_rstp_protocol(self):
with self.expecting_successful_transaction():

self.netconf_mock.should_receive("get_config").with_args(source="candidate", filter=is_xml("""
<filter>
<configuration>
<interfaces/>
<protocols>
<rstp>
<interface>
<name>ae10</name>
</interface>
</rstp>
</protocols>
</configuration>
</filter>
""")).and_return(a_configuration("""
<interfaces>
<interface>
<name>ae10</name>
</interface>
<interface>
<name>ge-4/3/3</name>
</interface>
</interfaces>
<protocols>
<rstp>
<interface>
<name>ae10</name>
<edge/>
<no-root-port/>
</interface>
</rstp>
</protocols>
"""))

self.netconf_mock.should_receive("edit_config").once().with_args(target="candidate", config=is_xml("""
<config>
<configuration>
<interfaces>
<interface operation="delete">
<name>ae10</name>
</interface>
</interfaces>
<protocols>
<rstp>
<interface operation="delete">
<name>ae10</name>
</interface>
</rstp>
</protocols>
</configuration>
</config>
""")).and_return(an_ok_response())

self.switch.remove_bond(10)

def test_remove_bond_invalid_number_raises(self):
with self.expecting_failed_transaction():

self.netconf_mock.should_receive("get_config").with_args(source="candidate", filter=is_xml("""
<filter>
<configuration>
<interfaces/>
<protocols>
<rstp>
<interface>
<name>ae7</name>
</interface>
</rstp>
</protocols>
</configuration>
</filter>
""")).and_return(a_configuration())
Expand All @@ -3532,6 +3603,13 @@ def test_remove_bond_delete_slaves_and_interface_at_same_time(self):
<filter>
<configuration>
<interfaces />
<protocols>
<rstp>
<interface>
<name>ae10</name>
</interface>
</rstp>
</protocols>
</configuration>
</filter>
""")).and_return(a_configuration("""
Expand Down

0 comments on commit a62736b

Please sign in to comment.