Ejemplo n.º 1
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',
        }
Ejemplo n.º 2
0
    def test_remote_sessions_can_continue_on_a_different_netman(self):
        with NetmanTestApp() as partial_client1, NetmanTestApp() as partial_client2:
            switch_descriptor = get_available_switch("juniper")

            client1 = partial_client1(switch_descriptor)
            first_netman_url = "{}:{}".format(client1.host, client1.port)

            client2 = partial_client2(switch_descriptor)
            second_netman_url = "{}:{}".format(client2.host, client2.port)

            remote_switch = RemoteSwitch(switch_descriptor)
            remote_switch._proxy = first_netman_url
            switch = FlowControlSwitch(remote_switch, ThreadingLockFactory().new_lock())

            with switch.transaction():
                switch.add_vlan(1498, "one")

                remote_switch._proxy = second_netman_url

                switch.add_vlan(1499, "two")

            assert_that(client1.get("/switches/{hostname}/vlans/1498").json()["name"], is_("one"))
            assert_that(client1.get("/switches/{hostname}/vlans/1499").json()["name"], is_("two"))
Ejemplo n.º 3
0
    def setUp(self):
        if self.switch_specs is not None:
            specs = type(self).switch_specs
        else:
            specs = next(s for s in available_models
                         if s["switch_descriptor"].model == self._dev_sample)

        self.switch_descriptor = specs["switch_descriptor"]
        self.test_port = specs["test_port_name"]
        self.test_ports = specs["ports"]
        self.test_vrrp_track_id = specs.get("test_vrrp_track_id")

        self.switch_descriptor.netman_server = ''
        self.remote_switch = RemoteSwitch(self.switch_descriptor)
        self.remote_switch.requests = FlaskRequest(app.test_client())

        self.client = ValidatingCachedSwitch(self.remote_switch)
        self.try_to = ExceptionIgnoringProxy(self.client,
                                             [NotImplementedError])
        self.janitor = ExceptionIgnoringProxy(
            self.client, [NotImplementedError, NetmanException])

        self.client.connect()
        self.client.start_transaction()
Ejemplo n.º 4
0
 def get_switch_by_descriptor(self, switch_descriptor):
     if switch_descriptor.netman_server:
         return RemoteSwitch(switch_descriptor)
     return factories[switch_descriptor.model](switch_descriptor)