Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue52 : First method change for approuval #70

Merged
merged 5 commits into from
Feb 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions netman/adapters/switches/backward_compatible_brocade.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def remove_trunk_vlan(self, interface_id, vlan):
def remove_native_vlan(self, interface_id):
return super(BackwardCompatibleBrocade, self).remove_native_vlan(_add_ethernet(interface_id))

def remove_access_vlan(self, interface_id):
return super(BackwardCompatibleBrocade, self).remove_access_vlan(_add_ethernet(interface_id))
def unset_access_vlan(self, interface_id):
return super(BackwardCompatibleBrocade, self).unset_access_vlan(_add_ethernet(interface_id))

def openup_interface(self, interface_id):
return super(BackwardCompatibleBrocade, self).openup_interface(_add_ethernet(interface_id))
Expand Down
4 changes: 2 additions & 2 deletions netman/adapters/switches/brocade.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def shutdown_interface(self, interface_id):
with self.config(), self.interface(interface_id):
self.shell.do("disable")

def remove_access_vlan(self, interface_id):
def unset_access_vlan(self, interface_id):
content = self.shell.do("show vlan brief | include {}"
.format(_to_short_name(interface_id)))
if len(content) == 0:
Expand All @@ -172,7 +172,7 @@ def remove_access_vlan(self, interface_id):
self.shell.do("no untagged {}".format(interface_id))

def remove_native_vlan(self, interface_id):
return self.remove_access_vlan(interface_id)
return self.unset_access_vlan(interface_id)

def remove_trunk_vlan(self, interface_id, vlan):
self._get_vlan(vlan)
Expand Down
4 changes: 2 additions & 2 deletions netman/adapters/switches/cached.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ def set_access_vlan(self, interface_id, vlan):
self.real_switch.set_access_vlan(interface_id, vlan)
self.interfaces_cache[interface_id].access_vlan = vlan

def remove_access_vlan(self, interface_id):
self.real_switch.remove_access_vlan(interface_id)
def unset_access_vlan(self, interface_id):
self.real_switch.unset_access_vlan(interface_id)
self.interfaces_cache[interface_id].access_vlan = None

def configure_native_vlan(self, interface_id, vlan):
Expand Down
2 changes: 1 addition & 1 deletion netman/adapters/switches/cisco.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def set_access_vlan(self, interface_id, vlan):
with self.config(), self.interface(interface_id):
self.ssh.do('switchport access vlan {}'.format(vlan))

def remove_access_vlan(self, interface_id):
def unset_access_vlan(self, interface_id):
with self.config(), self.interface(interface_id):
self.ssh.do('no switchport access vlan')

Expand Down
2 changes: 1 addition & 1 deletion netman/adapters/switches/dell.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def set_access_vlan(self, interface_id, vlan):
.on_result_matching(".*VLAN ID not found.*", UnknownVlan, vlan)\
.on_result_matching(".*Interface not in Access Mode.*", InterfaceInWrongPortMode, "trunk")

def remove_access_vlan(self, interface_id):
def unset_access_vlan(self, interface_id):
with self.config(), self.interface(interface_id):
self.shell.do("no switchport access vlan")

Expand Down
2 changes: 1 addition & 1 deletion netman/adapters/switches/juniper/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def set_access_vlan(self, interface_id, vlan):
raise UnknownVlan(vlan)
raise

def remove_access_vlan(self, interface_id):
def unset_access_vlan(self, interface_id):
interface = self.get_interface(interface_id)

if interface.port_mode == TRUNK:
Expand Down
2 changes: 1 addition & 1 deletion netman/adapters/switches/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def set_bond_trunk_mode(self, bond_number):
def set_access_vlan(self, interface_id, vlan):
self.put("/interfaces/" + interface_id + '/access-vlan', raw_data=str(vlan))

def remove_access_vlan(self, interface_id):
def unset_access_vlan(self, interface_id):
self.delete("/interfaces/" + interface_id + '/access-vlan')

def configure_native_vlan(self, interface_id, vlan):
Expand Down
6 changes: 3 additions & 3 deletions netman/api/switch_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def hook_to(self, server):
server.add_url_rule('/switches/<hostname>/interfaces/<path:interface_id>/shutdown', view_func=self.set_shutdown_state, methods=['PUT'])
server.add_url_rule('/switches/<hostname>/interfaces/<path:interface_id>/port-mode', view_func=self.set_port_mode, methods=['PUT'])
server.add_url_rule('/switches/<hostname>/interfaces/<path:interface_id>/access-vlan', view_func=self.set_access_vlan, methods=['PUT'])
server.add_url_rule('/switches/<hostname>/interfaces/<path:interface_id>/access-vlan', view_func=self.remove_access_vlan, methods=['DELETE'])
server.add_url_rule('/switches/<hostname>/interfaces/<path:interface_id>/access-vlan', view_func=self.unset_access_vlan, methods=['DELETE'])
server.add_url_rule('/switches/<hostname>/interfaces/<path:interface_id>/trunk-vlans', view_func=self.add_trunk_vlan, methods=['POST'])
server.add_url_rule('/switches/<hostname>/interfaces/<path:interface_id>/trunk-vlans/<vlan_number>', view_func=self.remove_trunk_vlan, methods=['DELETE'])
server.add_url_rule('/switches/<hostname>/interfaces/<path:interface_id>/trunk-native-vlan', view_func=self.configure_native_vlan, methods=['PUT'])
Expand Down Expand Up @@ -358,15 +358,15 @@ def set_access_vlan(self, switch, interface_id, vlan_number):

@to_response
@resource(Switch, Interface)
def remove_access_vlan(self, switch, interface_id):
def unset_access_vlan(self, switch, interface_id):
"""
Removes the access vlan of an interface

:arg str hostname: Hostname or IP of the switch
:arg str interface_id: Interface name (ex. ``FastEthernet0/1``, ``ethernet1/11``)

"""
switch.remove_access_vlan(interface_id)
switch.unset_access_vlan(interface_id)
return 204, None

@to_response
Expand Down
23 changes: 23 additions & 0 deletions netman/core/objects/backward_compatible_switch_operations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2015 Internap.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import warnings


class BackwardCompatibleSwitchOperations(object):
"""
Depecrated methods
"""
def remove_access_vlan(self, interface_id):
warnings.warn("Deprecated, use unset_access_vlan(interface_id) instead")
return self.unset_access_vlan(interface_id)
8 changes: 5 additions & 3 deletions netman/core/objects/switch_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from contextlib import contextmanager
import logging
from contextlib import contextmanager

from netman.core.objects.backward_compatible_switch_operations import BackwardCompatibleSwitchOperations


class SwitchOperations(object):
class SwitchOperations(BackwardCompatibleSwitchOperations):

def connect(self):
raise NotImplementedError()
Expand Down Expand Up @@ -57,7 +59,7 @@ def get_interfaces(self):
def set_access_vlan(self, interface_id, vlan):
raise NotImplementedError()

def remove_access_vlan(self, interface_id):
def unset_access_vlan(self, interface_id):
raise NotImplementedError()

def set_access_mode(self, interface_id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_set_access_vlan_accepts_no_ethernet(self):

self.switch.set_access_vlan("1/4", vlan=2999)

def test_remove_access_vlan_accepts_no_ethernet(self):
def test_unset_access_vlan_accepts_no_ethernet(self):
self.shell_mock.should_receive("do").with_args("show vlan brief | include ethe 1/4").once().ordered().and_return([
"1202 your-name- 1202 - Untagged Ports : ethe 1/10"
])
Expand All @@ -57,7 +57,7 @@ def test_remove_access_vlan_accepts_no_ethernet(self):
self.shell_mock.should_receive("do").with_args("no untagged ethernet 1/4").and_return([]).once().ordered()
self.shell_mock.should_receive("do").with_args("exit").and_return([]).twice().ordered().ordered()

self.switch.remove_access_vlan("1/4")
self.switch.unset_access_vlan("1/4")

def test_set_access_mode_accepts_no_ethernet(self):
self.shell_mock.should_receive("do").with_args("show vlan ethernet 1/4").once().ordered().and_return([
Expand Down
8 changes: 4 additions & 4 deletions tests/adapters/switches/brocade_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ def test_set_access_vlan_invalid_interface_raises(self):

assert_that(str(expect.exception), equal_to("Unknown interface ethernet 9/999"))

def test_remove_access_vlan(self):
def test_unset_access_vlan(self):
self.shell_mock.should_receive("do").with_args("show vlan brief | include ethe 1/4").once().ordered().and_return([
"1202 your-name- 1202 - Untagged Ports : ethe 1/10"
])
Expand All @@ -584,13 +584,13 @@ def test_remove_access_vlan(self):
self.shell_mock.should_receive("do").with_args("no untagged ethernet 1/4").and_return([]).once().ordered()
self.shell_mock.should_receive("do").with_args("exit").and_return([]).twice().ordered().ordered()

self.switch.remove_access_vlan("ethernet 1/4")
self.switch.unset_access_vlan("ethernet 1/4")

def test_remove_access_vlan_invalid_interface_raises(self):
def test_unset_access_vlan_invalid_interface_raises(self):
self.shell_mock.should_receive("do").with_args("show vlan brief | include ethe 9/999").once().ordered().and_return([])

with self.assertRaises(UnknownInterface) as expect:
self.switch.remove_access_vlan("ethernet 9/999")
self.switch.unset_access_vlan("ethernet 9/999")

assert_that(str(expect.exception), equal_to("Unknown interface ethernet 9/999"))

Expand Down
6 changes: 3 additions & 3 deletions tests/adapters/switches/cached_switch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ def test_set_access_vlan(self):
is_([Interface('eth0', access_vlan=123)])
)

def test_remove_access_vlan(self):
def test_unset_access_vlan(self):
self.real_switch_mock.should_receive("get_interfaces").once().and_return(
[Interface('eth0', access_vlan=123)])
self.switch.get_interfaces()

self.real_switch_mock.should_receive("remove_access_vlan").once() \
self.real_switch_mock.should_receive("unset_access_vlan").once() \
.with_args('eth0')

self.switch.remove_access_vlan('eth0')
self.switch.unset_access_vlan('eth0')

assert_that(
self.switch.get_interfaces(),
Expand Down
8 changes: 4 additions & 4 deletions tests/adapters/switches/cisco_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,17 +540,17 @@ def test_set_access_vlan_invalid_interface_raises(self):

assert_that(str(expect.exception), equal_to("Unknown interface SlowEthernet42/9999"))

def test_remove_access_vlan(self):
def test_unset_access_vlan(self):
self.mocked_ssh_client.should_receive("do").with_args("configure terminal").once().ordered().and_return([
"Enter configuration commands, one per line. End with CNTL/Z."
])
self.mocked_ssh_client.should_receive("do").with_args("interface FastEthernet0/4").and_return([]).once().ordered()
self.mocked_ssh_client.should_receive("do").with_args("no switchport access vlan").and_return([]).once().ordered()
self.mocked_ssh_client.should_receive("do").with_args("exit").and_return([]).twice().ordered().ordered()

self.switch.remove_access_vlan("FastEthernet0/4")
self.switch.unset_access_vlan("FastEthernet0/4")

def test_remove_access_vlan_invalid_interface_raises(self):
def test_unset_access_vlan_invalid_interface_raises(self):
self.mocked_ssh_client.should_receive("do").with_args("configure terminal").once().ordered().and_return([
"Enter configuration commands, one per line. End with CNTL/Z."
])
Expand All @@ -561,7 +561,7 @@ def test_remove_access_vlan_invalid_interface_raises(self):
self.mocked_ssh_client.should_receive("do").with_args("exit").and_return([]).once().ordered()

with self.assertRaises(UnknownInterface) as expect:
self.switch.remove_access_vlan("SlowEthernet42/9999")
self.switch.unset_access_vlan("SlowEthernet42/9999")

assert_that(str(expect.exception), equal_to("Unknown interface SlowEthernet42/9999"))

Expand Down
8 changes: 4 additions & 4 deletions tests/adapters/switches/dell10g_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,22 +558,22 @@ def test_set_access_vlan_invalid_mode_general(self):

assert_that(str(expect.exception), equal_to("Operation cannot be performed on a general mode interface"))

def test_remove_access_vlan(self):
def test_unset_access_vlan(self):
with self.configuring_and_committing():
self.mocked_ssh_client.should_receive("do").with_args("interface tengigabitethernet 1/0/10").once().ordered().and_return([])
self.mocked_ssh_client.should_receive("do").with_args("no switchport access vlan").once().ordered().and_return([])
self.mocked_ssh_client.should_receive("do").with_args("exit").once().ordered().and_return([])

self.switch.remove_access_vlan("tengigabitethernet 1/0/10")
self.switch.unset_access_vlan("tengigabitethernet 1/0/10")

def test_remove_access_vlan_invalid_interface(self):
def test_unset_access_vlan_invalid_interface(self):
with self.configuring():
self.mocked_ssh_client.should_receive("do").with_args("interface tengigabitethernet 1/0/99").once().ordered().and_return([
"An invalid interface has been used for this function."
])

with self.assertRaises(UnknownInterface) as expect:
self.switch.remove_access_vlan("tengigabitethernet 1/0/99")
self.switch.unset_access_vlan("tengigabitethernet 1/0/99")

assert_that(str(expect.exception), equal_to("Unknown interface tengigabitethernet 1/0/99"))

Expand Down
8 changes: 4 additions & 4 deletions tests/adapters/switches/dell_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ def test_set_access_vlan_invalid_mode(self):

assert_that(str(expect.exception), equal_to("Operation cannot be performed on a trunk mode interface"))

def test_remove_access_vlan(self):
def test_unset_access_vlan(self):
with self.configuring_and_committing():
self.mocked_ssh_client.should_receive("do").with_args("interface ethernet 1/g10").once().ordered().and_return([])
self.mocked_ssh_client.should_receive("do").with_args("no switchport access vlan").once().ordered().and_return([
Expand All @@ -728,16 +728,16 @@ def test_remove_access_vlan(self):
])
self.mocked_ssh_client.should_receive("do").with_args("exit").once().ordered().and_return([])

self.switch.remove_access_vlan("ethernet 1/g10")
self.switch.unset_access_vlan("ethernet 1/g10")

def test_remove_access_vlan_invalid_interface(self):
def test_unset_access_vlan_invalid_interface(self):
with self.configuring():
self.mocked_ssh_client.should_receive("do").with_args("interface ethernet 1/g99").once().ordered().and_return([
"An invalid interface has been used for this function."
])

with self.assertRaises(UnknownInterface) as expect:
self.switch.remove_access_vlan("ethernet 1/g99")
self.switch.unset_access_vlan("ethernet 1/g99")

assert_that(str(expect.exception), equal_to("Unknown interface ethernet 1/g99"))

Expand Down
16 changes: 8 additions & 8 deletions tests/adapters/switches/juniper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,7 @@ def test_set_access_vlan_on_unknown_interface_raises(self):

assert_that(str(expect.exception), contains_string("Unknown interface ge-0/0/6"))

def test_remove_access_vlan_removes_the_vlan_members(self):
def test_unset_access_vlan_removes_the_vlan_members(self):
self.netconf_mock.should_receive("get_config").with_args(source="candidate", filter=is_xml("""
<filter>
<configuration>
Expand Down Expand Up @@ -1812,9 +1812,9 @@ def test_remove_access_vlan_removes_the_vlan_members(self):
</config>
""")).and_return(an_ok_response())

self.switch.remove_access_vlan("ge-0/0/6")
self.switch.unset_access_vlan("ge-0/0/6")

def test_remove_access_vlan_with_no_vlan_raises(self):
def test_unset_access_vlan_with_no_vlan_raises(self):
self.netconf_mock.should_receive("get_config").with_args(source="candidate", filter=is_xml("""
<filter>
<configuration>
Expand All @@ -1841,11 +1841,11 @@ def test_remove_access_vlan_with_no_vlan_raises(self):
self.netconf_mock.should_receive("edit_config").never()

with self.assertRaises(AccessVlanNotSet) as expect:
self.switch.remove_access_vlan("ge-0/0/6")
self.switch.unset_access_vlan("ge-0/0/6")

assert_that(str(expect.exception), contains_string("Access Vlan is not set on interface ge-0/0/6"))

def test_remove_access_vlan_on_trunk_mode_raises(self):
def test_unset_access_vlan_on_trunk_mode_raises(self):
self.netconf_mock.should_receive("get_config").with_args(source="candidate", filter=is_xml("""
<filter>
<configuration>
Expand Down Expand Up @@ -1876,11 +1876,11 @@ def test_remove_access_vlan_on_trunk_mode_raises(self):
self.netconf_mock.should_receive("edit_config").never()

with self.assertRaises(InterfaceInWrongPortMode) as expect:
self.switch.remove_access_vlan("ge-0/0/6")
self.switch.unset_access_vlan("ge-0/0/6")

assert_that(str(expect.exception), contains_string("Operation cannot be performed on a trunk mode interface"))

def test_remove_access_vlan_on_unknown_interface_raises(self):
def test_unset_access_vlan_on_unknown_interface_raises(self):
self.netconf_mock.should_receive("get_config").with_args(source="candidate", filter=is_xml("""
<filter>
<configuration>
Expand All @@ -1893,7 +1893,7 @@ def test_remove_access_vlan_on_unknown_interface_raises(self):
self.netconf_mock.should_receive("edit_config").never()

with self.assertRaises(UnknownInterface) as expect:
self.switch.remove_access_vlan("ge-0/0/6")
self.switch.unset_access_vlan("ge-0/0/6")

assert_that(str(expect.exception), contains_string("Unknown interface ge-0/0/6"))

Expand Down
4 changes: 2 additions & 2 deletions tests/adapters/switches/remote_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ def test_set_access_vlan(self):

self.switch.set_access_vlan("ge-0/0/6", 1000)

def test_remove_access_vlan(self):
def test_unset_access_vlan(self):
self.requests_mock.should_receive("delete").once().with_args(
url=self.netman_url+'/switches/toto/interfaces/ge-0/0/6/access-vlan',
headers=self.headers
Expand All @@ -771,7 +771,7 @@ def test_remove_access_vlan(self):
content='',
status_code=204))

self.switch.remove_access_vlan("ge-0/0/6")
self.switch.unset_access_vlan("ge-0/0/6")

def test_set_native_vlan(self):
self.requests_mock.should_receive("put").once().with_args(
Expand Down
4 changes: 2 additions & 2 deletions tests/adapters/unified_tests/vlan_management_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_setting_a_vlan_on_an_interface(self):

self.client.set_access_vlan(self.test_port, vlan=2999)

self.client.remove_access_vlan(self.test_port)
self.client.unset_access_vlan(self.test_port)

self.client.remove_vlan(2999)

Expand Down Expand Up @@ -185,7 +185,7 @@ def test_invalid_interface_parameter_fails(self):
self.client.set_access_vlan('42/9999', 1234)

with self.assertRaises(UnknownInterface):
self.client.remove_access_vlan('42/9999')
self.client.unset_access_vlan('42/9999')

# TODO(jprovost) Unify switch adapters to raise the same exception
# Dell 10G raises UnknownInterface
Expand Down
Loading