예제 #1
0
    def test_get_switch_by_descriptor(self):
        my_semaphore = mock.Mock()
        self.semaphore_mocks['hostname'] = my_semaphore

        switch = self.factory.get_switch_by_descriptor(
            SwitchDescriptor(model='test_model', hostname='hostname'))

        assert_that(switch, is_(instance_of(FlowControlSwitch)))
        assert_that(switch.wrapped_switch, is_(instance_of(_FakeSwitch)))
        assert_that(switch.lock, is_(my_semaphore))
        assert_that(
            switch.wrapped_switch.switch_descriptor,
            is_(SwitchDescriptor(model='test_model', hostname='hostname')))
 def setUp(self):
     self.switch_impl = flexmock(
         SwitchBase(SwitchDescriptor("cisco", "name")))
     self.switch_impl.connected = True
     self.lock = flexmock()
     self.switch = switch_transactional.SwitchTransactional(
         self.switch_impl, self.lock)
예제 #3
0
    def setUp(self):
        self.switch = juniper.qfx_copper.netconf(
            SwitchDescriptor(model='juniper', hostname="toto"))

        self.netconf_mock = flexmock()
        self.switch.netconf = self.netconf_mock
        self.switch.in_transaction = True
예제 #4
0
    def _get_switch_descriptor_from_request_headers(self, hostname):
        headers_present = [
            h in request.headers
            for h in ['Netman-Model', 'Netman-Username', 'Netman-Password']
        ]

        if not any(headers_present):
            return None

        if not all(headers_present):
            raise BadRequest(
                'For anonymous switch usage, please specify headers: Netman-Model, Netman-Username and Netman-Password.'
            )

        port = None
        if "Netman-Port" in request.headers:
            try:
                port = int(request.headers["Netman-Port"])
            except ValueError:
                raise BadRequest(
                    'Netman-Port optional header should be an integer')

        netman_server = request.headers.get("Netman-Proxy-Server", None)
        if netman_server is not None and "," in netman_server:
            netman_server = [e.strip() for e in netman_server.split(",")]

        self.logger.info("Anonymous Switch Access ({}) {}@{}".format(
            request.headers['Netman-Model'],
            request.headers['Netman-Username'], hostname))
        return SwitchDescriptor(hostname=hostname,
                                model=request.headers['Netman-Model'],
                                username=request.headers['Netman-Username'],
                                password=request.headers['Netman-Password'],
                                port=port,
                                netman_server=netman_server)
    def setUp(self):
        self.switch = BackwardCompatibleBrocade(
            SwitchDescriptor("brocade", "host"), None)
        self.shell_mock = flexmock()
        self.switch.shell = self.shell_mock

        SubShell.debug = True
예제 #6
0
def test_factory():
    lock = mock.Mock()
    switch = juniper.qfx_copper_factory(SwitchDescriptor(hostname='hostname', model='juniper_qfx_copper', username='******', password='******', port=22), lock)

    assert_that(switch, instance_of(FlowControlSwitch))
    assert_that(switch.wrapped_switch, instance_of(Juniper))
    assert_that(switch.lock, is_(lock))
    assert_that(switch.switch_descriptor.hostname, equal_to("hostname"))
    assert_that(switch.switch_descriptor.model, equal_to("juniper_qfx_copper"))
    assert_that(switch.switch_descriptor.username, equal_to("username"))
    assert_that(switch.switch_descriptor.password, equal_to("password"))
    assert_that(switch.switch_descriptor.port, equal_to(22))
예제 #7
0
    def setUp(self):
        self.switch = RemoteSwitch(SwitchDescriptor(
            model="juniper", hostname="toto", username="******",
            password="******", port=1234, netman_server=self.netman_url))

        self.requests_mock = flexmock()
        self.switch.requests = self.requests_mock
        self.headers = {
            'Netman-Port': "1234",
            'Netman-Model': 'juniper',
            'Netman-Password': '******',
            'Netman-Username': '******',
            'Netman-Max-Version': "2",
            'Netman-Verbose-Errors': 'yes',
        }
def test_factory_telnet():
    lock = Mock()
    switch = brocade_factory_telnet(
        SwitchDescriptor(hostname='hostname',
                         model='brocade',
                         username='******',
                         password='******',
                         port=23), lock)

    assert_that(switch, instance_of(FlowControlSwitch))
    assert_that(switch.wrapped_switch, instance_of(Brocade))
    assert_that(switch.lock, is_(lock))
    assert_that(switch.switch_descriptor.hostname, equal_to("hostname"))
    assert_that(switch.switch_descriptor.model, equal_to("brocade"))
    assert_that(switch.switch_descriptor.username, equal_to("username"))
    assert_that(switch.switch_descriptor.password, equal_to("password"))
    assert_that(switch.switch_descriptor.port, equal_to(23))
예제 #9
0
    def test_get_connection_to_anonymous_switch(self):
        my_semaphore = mock.Mock()
        self.semaphore_mocks['hostname'] = my_semaphore

        switch = self.factory.get_anonymous_switch(hostname='hostname',
                                                   model='test_model',
                                                   username='******',
                                                   password='******',
                                                   port=22)

        assert_that(switch, is_(instance_of(FlowControlSwitch)))
        assert_that(switch.wrapped_switch, is_(instance_of(_FakeSwitch)))
        assert_that(switch.lock, is_(my_semaphore))
        assert_that(
            switch.wrapped_switch.switch_descriptor,
            is_(
                SwitchDescriptor(hostname='hostname',
                                 model='test_model',
                                 username='******',
                                 password='******',
                                 port=22)))
예제 #10
0
    def test_get_connection_to_anonymous_remote_switch(self):
        my_semaphore = mock.Mock()
        self.semaphore_mocks['hostname'] = my_semaphore
        switch = self.factory.get_anonymous_switch(
            hostname='hostname',
            model='test_model',
            username='******',
            password='******',
            port=22,
            netman_server='https://netman.url.example.org:4443')

        assert_that(switch, is_(instance_of(FlowControlSwitch)))
        assert_that(switch.wrapped_switch, is_(instance_of(RemoteSwitch)))
        assert_that(switch.lock, is_(my_semaphore))
        assert_that(
            switch.wrapped_switch.switch_descriptor,
            is_(
                SwitchDescriptor(
                    hostname='hostname',
                    model='test_model',
                    username='******',
                    password='******',
                    port=22,
                    netman_server='https://netman.url.example.org:4443')))
예제 #11
0
 def setUp(self):
     self.real_switch_mock = flexmock()
     self.real_switch_mock.switch_descriptor = SwitchDescriptor(
         'model', 'hostname')
     self.switch = CachedSwitch(self.real_switch_mock)
예제 #12
0
from fake_switches.cisco6500.cisco_core import Cisco6500SwitchCore
from fake_switches.dell.dell_core import DellSwitchCore
from fake_switches.dell10g.dell_core import Dell10GSwitchCore
from fake_switches.juniper.juniper_core import JuniperSwitchCore
from fake_switches.juniper_qfx_copper.juniper_qfx_copper_core import JuniperQfxCopperSwitchCore
from fake_switches.ssh_service import SwitchSshService
from fake_switches.switch_configuration import Port
from fake_switches.telnet_service import SwitchTelnetService
from netman.core.objects.switch_descriptor import SwitchDescriptor

available_models = [
    {
        "switch_descriptor": SwitchDescriptor(
            model="cisco",
            hostname="127.0.0.1",
            port=11002,
            username="******",
            password="******",
        ),
        "test_port_name": "FastEthernet0/3",
        "test_vrrp_track_id": "101",
        "core_class": CiscoSwitchCore,
        "service_class": SwitchSshService,
        "ports": [
            Port("FastEthernet0/1"),
            Port("FastEthernet0/2"),
            Port("FastEthernet0/3"),
            Port("FastEthernet0/4"),
        ]
    },
    {
예제 #13
0
 def setUp(self):
     self.wrapped_switch = flexmock(
         SwitchBase(SwitchDescriptor("cisco", "name")))
     self.lock = flexmock()
     self.switch = FlowControlSwitch(self.wrapped_switch, self.lock)
예제 #14
0
 def get_anonymous_switch(self, **kwargs):
     return self.get_switch_by_descriptor(SwitchDescriptor(**kwargs))
예제 #15
0
 def setUp(self):
     self.switch = flexmock(
         SwitchBase(SwitchDescriptor("cisco", "myswitch")))
예제 #16
0
 def setUp(self):
     self.switch_mock = flexmock()
     self.switch_mock.switch_descriptor = SwitchDescriptor('dell', "a_host")
     self.session_manager = SwitchSessionManager()
예제 #17
0
 def setUp(self):
     self.switch = Cisco(
         SwitchDescriptor(model='cisco', hostname="my.hostname"))
     SubShell.debug = True
     self.mocked_ssh_client = flexmock()
     self.switch.ssh = self.mocked_ssh_client