Beispiel #1
0
class SessionServerTest(unittest.TestCase):
    """Test basic session server operation"""
    def setUp(self):
        self._server_results = []
        self._server = SessionServer(self._new_connection)
        self._server.start()
        self._server.connect(TEST_MAC_ADDRESS, self._callback)

    def tearDown(self):
        self._server.stop()

    def _callback(self, port_event):
        pass

    def _new_connection(self, result):
        print('receive result')
        self._server_results.append(result)
        self._server.send_device_result(TEST_MAC_ADDRESS, PortBehavior.passed)
        self._server.close_stream(TEST_MAC_ADDRESS)

    # pylint: disable=no-member
    def test_server_connect(self):
        """Simple server connetion test"""
        client = TestingSessionServerClient()
        session = client.start_session(TEST_MAC_ADDRESS)
        print('session running')
        results = list(session)
        self.assertEqual(len(results), 3)
        self.assertEqual(results[0].endpoint.ip, 'ip-' + TEST_MAC_ADDRESS)
        self.assertEqual(results[1].result.code,
                         SessionResult.ResultCode.STARTED)
        self.assertEqual(len(self._server_results), 1)
        self.assertEqual(self._server_results[0].device_mac, TEST_MAC_ADDRESS)
Beispiel #2
0
 def setUp(self):
     self._server_results = []
     self._on_session_end = MagicMock(return_value=None)
     self._server = SessionServer(on_session=self._new_connection,
                                  on_session_end=self._on_session_end, server_port=self.port,
                                  local_ip=_LOCAL_IP)
     self._server.start()
Beispiel #3
0
class BaseSessionServerTest(unittest.TestCase):
    """Base session server test class for setup."""
    port = _BASE_PORT

    def setUp(self):
        self._server_results = []
        self._on_session_end = MagicMock(return_value=None)
        self._server = SessionServer(on_session=self._new_connection,
                                     on_session_end=self._on_session_end, server_port=self.port,
                                     local_ip=_LOCAL_IP)
        self._server.start()

    def tearDown(self):
        self._server.stop()

    def _new_connection(self, result):
        print('receive result')
        self._server_results.append(result)
Beispiel #4
0
 def _init_device_result_handler(self):
     server_port = self.config.get('device_reporting',
                                   {}).get('server_port')
     egress_vlan = self.config.get('run_trigger', {}).get('egress_vlan')
     local_ip = self.config.get('switch_setup', {}).get('endpoint',
                                                        {}).get('ip')
     LOGGER.info('Device result handler on port %s, vlan %s, ip %s',
                 server_port, egress_vlan, local_ip)
     if server_port:
         assert not egress_vlan, 'both egress_vlan and server_port defined'
         # TODO: Make this all configured from run_trigger not device_reporting
         handler = SessionServer(on_session=self._on_session,
                                 on_session_end=self._on_session_end,
                                 server_port=server_port,
                                 local_ip=local_ip)
         return handler
     return None
Beispiel #5
0
 def _init_device_result_handler(self):
     server_port = self.config.get('device_reporting', {}).get('server_port')
     egress_vlan = self.config.get('run_trigger', {}).get('egress_vlan')
     server_address = self.config.get('device_reporting', {}).get('server_address')
     LOGGER.info('Device result handler configuration %s:%s %s',
                 server_port, server_address, egress_vlan)
     if server_port:
         assert not egress_vlan, 'both egress_vlan and server_port defined'
         timeout = self.config['device_reporting'].get('rpc_timeout_sec')
         if server_address:
             handler = DeviceReportClient(server_address=server_address,
                                          server_port=server_port, rpc_timeout_sec=timeout)
         else:
             # TODO: Make this all configured from run_trigger not device_reporting
             handler = SessionServer(on_session=self._on_session,
                                     server_port=server_port)
         return handler
     return None
Beispiel #6
0
 def setUp(self):
     self._server_results = []
     self._server = SessionServer(self._new_connection)
     self._server.start()
     self._server.connect(TEST_MAC_ADDRESS, self._callback)