Skip to content

Commit

Permalink
Merge pull request internap#11 from lindycoder/remove_bond_remove_rstp
Browse files Browse the repository at this point in the history
The remove bond removes related rstp protocol
  • Loading branch information
JoProvost committed Sep 23, 2015
2 parents 893538d + 779f6ef commit c486bac
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 49 deletions.
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
48 changes: 0 additions & 48 deletions tests/adapters/switches/juniper_qfx_copper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,54 +211,6 @@ def test_port_mode_access_with_no_port_mode_or_vlan_set_just_sets_the_port_mode(

self.switch.set_access_mode("ge-0/0/6")

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

self.netconf_mock.should_receive("get_config").with_args(source="candidate", filter=is_xml("""
<filter>
<configuration>
<interfaces />
</configuration>
</filter>
""")).and_return(a_configuration("""
<interfaces>
<interface>
<name>ae10</name>
</interface>
<interface>
<name>ge-0/0/1</name>
<ether-options>
<auto-negotiation/>
<ieee-802.3ad>
<bundle>ae10</bundle>
</ieee-802.3ad>
</ether-options>
</interface>
<interface>
<name>ge-0/0/2</name>
</interface>
</interfaces>
"""))

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>
<interface>
<name>ge-0/0/1</name>
<ether-options>
<ieee-802.3ad operation="delete" />
</ether-options>
</interface>
</interfaces>
</configuration>
</config>""")).and_return(an_ok_response())

self.switch.remove_bond(10)

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

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 c486bac

Please sign in to comment.