Exemplo n.º 1
0
    def test_endpoints_cleanup(self):
        """
        - endpoint1 linked with session
        - endpoint2 not linked with session
        - both endpoints mark as 'deleted'
        expected: endpoint1 deleted, endpoint2 not deleted
        """
        class FakeOrigin(str):
            short_name = 'fake_short_name'

        from core.db.models import Session, Endpoint, Provider
        provider = Provider('name', 'url')
        endpoint1 = Endpoint(origin=FakeOrigin('fake'),
                             prefix='prefix',
                             provider=provider)
        endpoint2 = Endpoint(origin=FakeOrigin('fake'),
                             prefix='prefix',
                             provider=provider)
        endpoint1.deleted, endpoint2.deleted = True, True
        endpoint1.save(), endpoint2.save()

        session = Session(platform='some_platform',
                          name='__test_keep_forever_sessions_1')
        session.refresh()
        session.endpoint = endpoint1
        session.save()

        endpoints_to_delete = [
            e.id for e in self.cleanup.endpoints_to_delete()
        ]
        self.assertNotIn(endpoint1.id, endpoints_to_delete)
        self.assertIn(endpoint2.id, endpoints_to_delete)
Exemplo n.º 2
0
def get_session():
    profiler.register_get_session_call()

    dc = commands.get_desired_capabilities(request)
    matched_platform, provider_id = current_app.get_matched_platforms(dc)
    if not matched_platform:
        raise SessionException("Cannot match platform for DesiredCapabilities: {}".format(dc))

    session = Session(platform=matched_platform, dc=dc, provider_id=provider_id)
    request.session = session
    log.info("New session {}({}) on provider {} with dc: {}".format(session.id, session.name, provider_id, dc))
    yield session

    start_time = time.time()
    while not session.endpoint_id:
        time.sleep(constants.GET_SESSION_SLEEP_TIME)
        if time.time() - start_time >= config.GET_VM_TIMEOUT:
            raise CreationException("Timeout getting endpoint for {}".format(session))
        session.refresh()
        yield session

    session.run()
    yield session