Пример #1
0
    def test_when_during_proxy_starting_already_started_from_other_thread(
            self):
        from core.db.models import Session, Endpoint, Provider
        provider = Provider(name='noname', url='nourl')
        endpoint = Endpoint(Mock(), '', provider)
        endpoint.ip = '127.0.0.1'
        endpoint.name = 'test_endpoint'
        endpoint.ports = {'4455': 4455, '9000': 9000, '5900': 5900}
        session = Session("some_platform")
        session.id = 1
        session.name = "session1"
        session.status = "running"
        type(session).vnc_proxy_port = PropertyMock(
            side_effect=[None, 55555, 55555])
        session.vnc_proxy_pid = 55555
        session.created = session.modified = datetime.now()
        session.endpoint = endpoint
        session.stop_vnc_proxy = Mock()

        with patch('flask.current_app.sessions.get_session',
                   Mock(return_value=session)):
            response = self.vmmaster_client.get(
                '/api/session/{}/vnc_info'.format(session.id))
            session._close()

        body = json.loads(response.data)
        self.assertEqual(200, response.status_code)
        self.assertDictEqual({'vnc_proxy_port': 55555}, body['result'])
        self.assertEqual(200, body['metacode'])
        self.assertTrue(session.stop_vnc_proxy.called)
Пример #2
0
    def test_get_vnc_proxy_port_if_session_is_waiting(self):
        from core.db.models import Session, Endpoint, Provider
        provider = Provider(name='noname', url='nourl')
        endpoint = Endpoint(Mock(), '', provider)
        endpoint.ip = '127.0.0.1'
        endpoint.name = 'test_endpoint'
        endpoint.ports = {'4455': 4455, '9000': 9000, '5900': 5900}
        session = Session("some_platform")
        session.name = "session1"
        session.id = 1
        session.status = "waiting"
        session.vnc_proxy_port = None
        session.vnc_proxy_pid = None
        session.created = session.modified = datetime.now()
        session.endpoint = endpoint

        with patch('flask.current_app.sessions.get_session',
                   Mock(return_value=session)):
            response = self.vmmaster_client.get(
                '/api/session/{}/vnc_info'.format(session.id))

        body = json.loads(response.data)
        self.assertEqual(200, response.status_code)
        self.assertDictEqual({}, body['result'])
        self.assertEqual(500, body['metacode'])
Пример #3
0
    def test_get_vnc_port_if_running_proxy(self):
        from core.db.models import Session, Endpoint, Provider
        provider = Provider(name='noname', url='nourl')
        endpoint = Endpoint(Mock(), '', provider)
        endpoint.ip = '127.0.0.1'
        endpoint.name = 'test_endpoint'
        endpoint.ports = {'4455': 4455, '9000': 9000, '5900': 5900}
        session = Session("some_platform")
        session.id = 1
        session.name = "session1"
        session.status = "running"
        session.vnc_proxy_port = 55555
        session.vnc_proxy_pid = 55555
        session.created = session.modified = datetime.now()
        session.endpoint = endpoint
        session.stop_vnc_proxy = Mock()

        with patch('flask.current_app.sessions.get_session',
                   Mock(return_value=session)), patch(
                       'core.utils.kill_process', Mock(return_value=True)):
            response = self.vmmaster_client.get('/api/session/%s/vnc_info' %
                                                session.id)
            session._close()

        body = json.loads(response.data)
        self.assertEqual(200, response.status_code)
        self.assertDictEqual({'vnc_proxy_port': 55555}, body['result'])
        self.assertEqual(200, body['metacode'])
        self.assertTrue(session.stop_vnc_proxy.called)
Пример #4
0
    def test_sessions_overflow(self):
        user = Mock(id=1, max_stored_sessions=0)
        from core.db.models import Session
        session = Session('some_platform')
        session.status = 'unknown'
        session.closed = True
        session.name = '__test_outdated_sessions'
        session.save()

        session_ids_to_delete = [
            p.id for p in self.cleanup.sessions_overflow(user)
        ]

        self.assertIn(session.id, session_ids_to_delete)
        self.cleanup.delete_session_data([session])
Пример #5
0
    def test_file_deletion(self):
        from core.db.models import Session
        session = Session('some_platform')
        session.status = 'unknown'
        session.name = '__test_file_deletion'
        session.save()

        session_dir = os.path.join(config.SCREENSHOTS_DIR, str(session.id))
        system_utils.run_command(["mkdir", config.SCREENSHOTS_DIR],
                                 silent=True)
        system_utils.run_command(["mkdir", session_dir], silent=True)
        system_utils.run_command(
            ["touch", os.path.join(session_dir, "file_for_deletion")],
            silent=True)
        self.cleanup.delete_session_data([session])
        self.assertEqual(os.path.isdir(session_dir), 0)
        system_utils.run_command(["rm", "-rf", config.SCREENSHOTS_DIR],
                                 silent=True)