Exemplo n.º 1
0
    def setUp(self):
        setup_config('data/config_openstack.py')
        self.platform = "origin_1"

        mocked_image = Mock(id=1,
                            status='active',
                            get=Mock(return_value='snapshot'),
                            min_disk=20,
                            min_ram=2,
                            instance_type_flavorid=1)
        type(mocked_image).name = PropertyMock(return_value='test_origin_1')

        with patch('core.network.Network', Mock()), patch(
                'core.connection.Virsh', Mock()), patch.multiple(
                    'core.utils.openstack_utils',
                    nova_client=Mock(),
                    neutron_client=Mock(return_value=Mock()),
                    glance_client=Mock(return_value=Mock())), patch(
                        'vmpool.platforms.OpenstackPlatforms.images',
                        Mock(return_value=[mocked_image])):
            from flask import Flask
            self.app = Flask(__name__)

            from vmpool.virtual_machines_pool import VirtualMachinesPool
            self.app.pool = VirtualMachinesPool(self.app)

            self.ctx = self.app.test_request_context()
            self.ctx.push()
Exemplo n.º 2
0
    def setUp(self):
        setup_config('data/config.py')

        self.address = ("localhost", 9001)

        with patch(
                'core.connection.Virsh',
                Mock(),
        ), patch('core.network.Network',
                 Mock()), patch('core.db.Database', DatabaseMock()):
            from vmmaster.server import VMMasterServer
            self.vmmaster = VMMasterServer(reactor, self.address[1])

        self.pool = self.vmmaster.app.pool

        server_is_up(self.address)

        self.desired_caps = {
            'desiredCapabilities': {
                'platform': self.pool.platforms.platforms.keys()[0]
            }
        }

        from core.config import config
        config.SESSION_TIMEOUT = 1

        self.ctx = self.vmmaster.app.app_context()
        self.ctx.push()
Exemplo n.º 3
0
    def setUpClass(cls):
        from core.config import setup_config
        setup_config('data/config.py')

        cls.app = Flask(__name__)
        cls.app.database = DatabaseMock()
        cls.app.sessions = Mock()
Exemplo n.º 4
0
    def setUpClass(cls):
        setup_config('data/config.py')
        cls.db = Database(config.DATABASE)
        Base.metadata.drop_all(cls.db.engine)
        Base.metadata.create_all(cls.db.engine)

        cls.size = 20
Exemplo n.º 5
0
    def setUp(self):
        from core.config import setup_config
        setup_config('data/config.py')

        with patch('core.network.Network', Mock(name='Network')), patch(
                'core.connection.Virsh', Mock(name='Virsh')), patch(
                    'core.utils.init.home_dir',
                    Mock(return_value=fake_home_dir())), patch(
                        'core.logger.setup_logging',
                        Mock(return_value=Mock())), patch(
                            'core.db.Database', DatabaseMock()):
            from vmmaster.server import create_app
            self.app = create_app()

        self.vmmaster_client = self.app.test_client()
        self.platforms = self.app.pool.platforms.platforms
        self.platform = sorted(self.app.pool.platforms.platforms.keys())[0]

        self.desired_caps = {
            'desiredCapabilities': {
                'platform': self.platform
            }
        }

        self.ctx = self.app.app_context()
        self.ctx.push()
Exemplo n.º 6
0
    def setUp(self):
        from core.config import setup_config
        setup_config('data/config_openstack.py')

        with patch('core.utils.init.home_dir',
                   Mock(return_value=fake_home_dir())), patch(
                       'core.db.Database', DatabaseMock()), patch(
                           'vmpool.virtual_machines_pool.VirtualMachinesPool',
                           Mock()):
            from vmpool.server import create_app
            from vmpool.virtual_machines_pool import VirtualMachinesPool
            self.app = create_app()
            self.app.pool = VirtualMachinesPool(
                self.app,
                'unnamed',
                platforms_class=Mock(),
                preloader_class=Mock(),
                artifact_collector_class=Mock(),
                endpoint_preparer_class=Mock(),
                endpoint_remover_class=Mock())

        self.vmmaster_client = self.app.test_client()
        self.platform = 'origin_1'

        self.ctx = self.app.app_context()
        self.ctx.push()
Exemplo n.º 7
0
    def setUp(self):
        from flask import Flask
        from core.config import setup_config
        setup_config('data/config_openstack.py')

        self.app = Flask(__name__)
        self.app.database = DatabaseMock()

        self.pool = Mock(id=1, provider=Provider(name='fake', url='no//url'))
        self.mocked_origin = Mock(short_name="platform_1",
                                  id=1,
                                  status="active",
                                  get=Mock(return_value="snapshot"),
                                  min_disk=20,
                                  min_ram=2,
                                  instance_type_flavorid=1)

        self.ctx = self.app.app_context()
        self.ctx.push()

        with patch("core.utils.openstack_utils.nova_client",
                   Mock(return_value=Mock())), patch("flask.current_app",
                                                     self.app):
            from core.db.models import OpenstackClone
            self.clone = OpenstackClone(self.mocked_origin, "preloaded",
                                        self.pool)
Exemplo n.º 8
0
    def setUpClass(cls):
        cls.app = Flask(__name__)
        cls.app.running = True
        cls.app.database = None

        from core.config import setup_config
        setup_config('data/config_openstack.py')
Exemplo n.º 9
0
    def setUp(self):
        setup_config('data/config.py')
        self.platform = "test_origin_1"

        with patch('core.connection.Virsh',
                   Mock()), patch('core.network.Network', Mock()):
            from vmpool.virtual_machines_pool import VirtualMachinesPool
            self.pool = VirtualMachinesPool()
Exemplo n.º 10
0
 def setUpClass(cls):
     setup_config('data/config_openstack.py')
     cls.app = Flask(__name__)
     cls.app.database = DatabaseMock()
     cls.app.sessions = Mock()
     cls.session_id = 1
     cls.artifact_dir = os.sep.join([config.SCREENSHOTS_DIR, str(cls.session_id)])
     if not os.path.exists(cls.artifact_dir):
         os.mkdir(cls.artifact_dir)
Exemplo n.º 11
0
    def setUpClass(cls):
        setup_config('data/config.py')

        from flask import Flask
        cls.app = Flask(__name__)
        cls.app.sessions = None

        from core import db
        cls.app.database = db.Database(config.DATABASE)
Exemplo n.º 12
0
    def setUp(self):
        setup_config('data/config.py')

        from flask import Flask
        self.app = Flask(__name__)
        self.app.sessions = Mock()
        self.app.sessions.app = self.app

        from core.sessions import SessionWorker
        self.worker = SessionWorker(self.app.sessions)
Exemplo n.º 13
0
 def setUp(self):
     with patch("docker.DockerClient", Mock(
         containers=Mock(
             create=Mock(),
             get=Mock()
         )
     )):
         from core.config import setup_config
         from core.clients.docker_client import DockerManageClient
         setup_config('data/config_openstack.py')
         self._docker_client = DockerManageClient()
Exemplo n.º 14
0
    def setUp(self):
        setup_config('data/config_with_preloaded.py')

        self.address = ("localhost", 9001)

        self.desired_caps = {'desiredCapabilities': {'platform': 'origin_1'}}

        mocked_image = Mock(id=1,
                            status='active',
                            get=Mock(return_value='snapshot'),
                            min_disk=20,
                            min_ram=2,
                            instance_type_flavorid=1)
        type(mocked_image).name = PropertyMock(return_value='test_origin_1')

        with patch(
                'core.connection.Virsh',
                Mock(),
        ), patch('core.network.Network', Mock()), patch(
                'core.db.Database',
                Mock(add=Mock(side_effect=set_primary_key))), patch.multiple(
                    'core.utils.openstack_utils',
                    neutron_client=Mock(return_value=Mock()),
                    glance_client=Mock(return_value=Mock()),
                    nova_client=Mock(return_value=Mock())), patch.multiple(
                        'vmpool.clone.OpenstackClone',
                        _wait_for_activated_service=custom_wait,
                        get_network_id=Mock(return_value=1),
                        get_network_name=Mock(
                            return_value='Local-Net')), patch.multiple(
                                'vmpool.platforms.OpenstackPlatforms',
                                images=Mock(return_value=[mocked_image]),
                                flavor_params=Mock(return_value={
                                    'vcpus': 1,
                                    'ram': 2
                                }),
                                limits=Mock(
                                    return_value={
                                        'maxTotalCores': 10,
                                        'maxTotalInstances': 10,
                                        'maxTotalRAMSize': 100,
                                        'totalCoresUsed': 0,
                                        'totalInstancesUsed': 0,
                                        'totalRAMUsed': 0
                                    })):
            from vmmaster.server import VMMasterServer
            self.vmmaster = VMMasterServer(reactor, self.address[1])

            self.ctx = self.vmmaster.app.app_context()
            self.ctx.push()

            self.pool = self.vmmaster.app.pool

        server_is_up(self.address)
Exemplo n.º 15
0
    def setUpClass(cls):
        cls.app = Flask(__name__)
        cls.app.database = None

        from core.config import setup_config
        setup_config('data/config.py')

        cls.method = "GET"
        from base64 import urlsafe_b64encode
        from core.auth.custom_auth import anonymous
        cls.headers = dict(Authorization="Basic " + urlsafe_b64encode(
            str(anonymous.username) + ":" + str(anonymous.password)))
Exemplo n.º 16
0
    def setUp(self):
        setup_config('data/config.py')
        self.platform = "test_origin_1"

        self.app = Flask(__name__)
        self.ctx = self.app.app_context()
        self.ctx.push()

        with patch('core.connection.Virsh',
                   Mock()), patch('core.network.Network', Mock()):
            from vmpool.virtual_machines_pool import VirtualMachinesPool
            self.pool = VirtualMachinesPool(self.app)
Exemplo n.º 17
0
    def setUpClass(cls):
        setup_config('data/config.py')

        from flask import Flask
        cls.app = Flask(__name__)
        cls.app.sessions = None

        from core import db
        cls.app.database = db.Database(config.DATABASE)

        with patch('core.utils.init.home_dir',
                   Mock(return_value=config.BASEDIR)):
            from vmmaster import cleanup
            cls.cleanup = cleanup
Exemplo n.º 18
0
    def setUp(self):
        setup_config('data/config_openstack.py')

        self.platform = "origin_1"
        self.address = ("localhost", 9001)

        self.mocked_image = Mock(id=1,
                                 status='active',
                                 get=Mock(return_value='snapshot'),
                                 min_disk=20,
                                 min_ram=2,
                                 instance_type_flavorid=1)
        type(self.mocked_image).name = PropertyMock(
            return_value='test_origin_1')

        with patch(
                'core.connection.Virsh',
                Mock(),
        ), patch('core.network.Network', Mock()), patch.multiple(
                'core.utils.openstack_utils',
                neutron_client=Mock(return_value=Mock()),
                nova_client=Mock(return_value=Mock()),
                glance_client=Mock(return_value=Mock())), patch.multiple(
                    'vmpool.platforms.OpenstackPlatforms',
                    images=Mock(return_value=[self.mocked_image]),
                    flavor_params=Mock(return_value={
                        'vcpus': 1,
                        'ram': 2
                    }),
                    limits=Mock(
                        return_value={
                            'maxTotalCores': 10,
                            'maxTotalInstances': 10,
                            'maxTotalRAMSize': 100,
                            'totalCoresUsed': 0,
                            'totalInstancesUsed': 0,
                            'totalRAMUsed': 0
                        })):
            from flask import Flask
            self.app = Flask(__name__)

            from vmpool.virtual_machines_pool import VirtualMachinesPool
            self.app.pool = VirtualMachinesPool(self.app)

            from vmpool.platforms import Platforms
            self.app.platforms = Platforms()

            self.ctx = self.app.test_request_context()
            self.ctx.push()
Exemplo n.º 19
0
    def setUp(self):
        setup_config('data/config.py')
        self.host = "localhost"
        self.port = 9001
        self.address = (self.host, self.port)
        self.vmmaster = vmmaster_server_mock(self.port)
        server_is_up(self.address)
        self.free_port = get_free_port()

        self.ctx = self.vmmaster.app.app_context()
        self.ctx.push()

        from core.sessions import Session
        self.session = Session()
        self.session.endpoint_ip = "localhost"
Exemplo n.º 20
0
    def setUp(self):
        setup_config('data/config.py')

        self.address = ("localhost", 9001)

        super(TestServer, self).setUp()

        self.desired_caps = {
            'desiredCapabilities': {
                'platform': 'test_origin_1'
            }
        }

        self.ctx = self.vmmaster.app.app_context()
        self.ctx.push()
Exemplo n.º 21
0
    def setUp(self):
        setup_config('data/config.py')

        self.address = ("localhost", 9001)

        super(TestSessionSteps, self).setUp()

        self.desired_caps = {
            'desiredCapabilities': {
                'platform':
                self.vmmaster.app.pool.platforms.platforms.keys()[0]
            }
        }

        self.ctx = self.vmmaster.app.app_context()
        self.ctx.push()
Exemplo n.º 22
0
    def setUp(self):
        from core.db import Database
        setup_config('data/config.py')
        self.platform_name = "origin_1"
        self.app = Flask(__name__)

        self.ctx = self.app.app_context()
        self.ctx.push()
        self.app.database = Database()
        self.app.sessions = Mock()

        self.mocked_image = Mock(
            id=1,
            status='active',
            get=Mock(return_value='snapshot'),
            min_disk=20,
            min_ram=2,
            instance_type_flavorid=1,
        )
        type(self.mocked_image).name = PropertyMock(
            return_value='test_origin_1')

        with patch.multiple(
                'vmpool.platforms.OpenstackPlatforms',
                images=Mock(return_value=[self.mocked_image]),
                flavor_params=Mock(return_value={
                    'vcpus': 1,
                    'ram': 2
                }),
                limits=Mock(
                    return_value={
                        'maxTotalCores': 10,
                        'maxTotalInstances': 10,
                        'maxTotalRAMSize': 100,
                        'totalCoresUsed': 0,
                        'totalInstancesUsed': 0,
                        'totalRAMUsed': 0
                    }),
        ):
            from vmpool.virtual_machines_pool import VirtualMachinesPool
            self.pool = VirtualMachinesPool(self.app,
                                            preloader_class=Mock(),
                                            artifact_collector_class=Mock(),
                                            endpoint_preparer_class=Mock())
            self.ctx = self.app.app_context()
            self.ctx.push()
            self.pool.register()
Exemplo n.º 23
0
    def setUp(self):
        setup_config('data/config_openstack.py')
        self.host = "localhost"
        self.port = config.PORT
        self.address = (self.host, self.port)
        self.vmmaster = vmmaster_server_mock(self.port)
        self.assertTrue(server_is_up(self.address))
        self.free_port = get_free_port()

        self.ctx = self.vmmaster.app.app_context()
        self.ctx.push()

        from core.db.models import Session, Provider, Endpoint
        self.session = Session('some_platform')

        provider = Provider(name='noname', url='nourl')
        endpoint = Endpoint(Mock(), '', provider)
        endpoint.ip = 'localhost'
        self.session.endpoint = endpoint
Exemplo n.º 24
0
    def setUpClass(cls):
        setup_config("data/config_openstack.py")
        body = {
            "sessionId": None,
            "desiredCapabilities": {
                "platform": "some_platform",
                "browserName": "firefox",
                "version": "",
                "javascriptEnabled": True
            }
        }
        session_request_body = json.dumps(body)
        session_request_headers = {
            'content-length': '%s' % len(session_request_body),
            'accept-encoding': 'identity',
            'Connection': 'close',
            'accept': 'application/json',
            'user-agent': 'Python-urllib/2.7',
            'host': '127.0.0.1:9000',
            'content-type': 'application/json;charset=UTF-8',
        }
        cls.request = Mock()
        cls.request.method = "POST"
        cls.request.path = "/wd/hub/session"
        cls.request.headers = dict()
        cls.request.headers.update(session_request_headers)
        cls.request.data = session_request_body

        cls.webdriver_server = ServerMock(cls.host, get_free_port())
        cls.webdriver_server.start()
        cls.vmmaster_agent = ServerMock(cls.host, get_free_port())
        cls.vmmaster_agent.start()
        cls.vnc_server = ServerMock(cls.host, get_free_port())
        cls.vnc_server.start()

        cls.app = Flask(__name__)
        cls.app.database = None
        cls.app.sessions = None
        cls.app.database_task_queue = Mock()
        cls.app.pool = Mock()
Exemplo n.º 25
0
    def setUp(self):
        from core.config import setup_config
        setup_config('data/config_openstack.py')

        with patch('core.utils.init.home_dir',
                   Mock(return_value=fake_home_dir())), patch(
                       'core.video.start_vnc_proxy',
                       Mock(return_value=(99999, 99999))), patch(
                           'core.utils.kill_process',
                           Mock()), patch('core.db.Database', DatabaseMock()):
            from vmmaster.server import create_app
            self.app = create_app()

        self.vmmaster_client = self.app.test_client()
        self.platform = 'origin_1'

        self.desired_caps = {
            'desiredCapabilities': {
                'platform': self.platform
            }
        }

        self.ctx = self.app.app_context()
        self.ctx.push()
Exemplo n.º 26
0
 def setUp(self):
     setup_config('data/config_openstack.py')
     self.mocked_origin = Mock(short_name="platform_1")
     self.pool = Mock(pool=dict(), using=dict())
Exemplo n.º 27
0
 def setUp(self):
     from core.config import setup_config
     setup_config('data/config_openstack.py')
Exemplo n.º 28
0
 def setUp(self):
     with patch("docker.DockerClient", Mock()):
         from core.config import setup_config
         from core.clients.docker_client import DockerManageClient
         setup_config('data/config.py')
         self.docker_client = DockerManageClient()
Exemplo n.º 29
0
 def setUpClass(cls):
     setup_config('data/config.py')
     cls.app = Flask(__name__)
     cls.app.database = DatabaseMock()
     cls.app.sessions = Mock()
Exemplo n.º 30
0
import logging
from datetime import datetime, timedelta

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.exc import ArgumentError

from core.config import config, setup_config
from core.db.models import Session, User
from core.utils import change_user_vmmaster
from core.utils.init import home_dir

from shutil import rmtree
from errno import ENOENT

setup_config('%s/config.py' % home_dir())
log = logging.getLogger(__name__)

engine = create_engine(config.DATABASE)
session_factory = sessionmaker(bind=engine)


def transaction(func):
    def wrapper(*args, **kwargs):
        dbsession = session_factory()
        try:
            return func(dbsession=dbsession, *args, **kwargs)
        except:
            dbsession.rollback()
            raise
        finally: