def get_client(client_type=None): """ Returns a persistent storage client :param client_type: Type of store client """ if not hasattr(PersistentFactory, 'store') or PersistentFactory.store is None: if hasattr(unittest, 'running_tests') and getattr( unittest, 'running_tests'): client_type = 'dummy' if client_type is None: client_type = EtcdConfiguration.get( '/ovs/framework/stores|persistent') PersistentFactory.store = None if client_type in ['pyrakoon', 'arakoon']: from ovs.extensions.storage.persistent.pyrakoonstore import PyrakoonStore PersistentFactory.store = PyrakoonStore( str( EtcdConfiguration.get( '/ovs/framework/arakoon_clusters|ovsdb'))) if client_type == 'dummy': from ovs.extensions.storage.persistent.dummystore import DummyPersistentStore PersistentFactory.store = DummyPersistentStore() if PersistentFactory.store is None: raise RuntimeError('Invalid client_type specified') return PersistentFactory.store
def setUpClass(cls): """ Sets up the unittest, mocking a certain set of 3rd party libraries and extensions. This makes sure the unittests can be executed without those libraries installed """ # Load dummy stores PersistentFactory.store = DummyPersistentStore() VolatileFactory.store = DummyVolatileStore() # Replace mocked classes sys.modules[ 'ovs.extensions.storageserver.storagedriver'] = StorageDriver # Import required modules/classes after mocking is done from ovs.dal.hybrids.vmachine import VMachine from ovs.dal.hybrids.vdisk import VDisk from ovs.extensions.generic.volatilemutex import VolatileMutex from ovs.lib.vmachine import VMachineController from ovs.lib.vdisk import VDiskController from ovs.lib.scheduledtask import ScheduledTaskController # Globalize mocked classes global VDisk global VMachine global VolatileMutex global VMachineController global VDiskController global ScheduledTaskController _ = VDisk(), VolatileMutex('dummy'), VMachine( ), VMachineController, VDiskController, ScheduledTaskController # Cleaning storage VolatileFactory.store.clean() PersistentFactory.store.clean()
def get_client(client_type=None): """ Returns a persistent storage client :param client_type: Type of store client """ if not hasattr(PersistentFactory, 'store') or PersistentFactory.store is None: if os.environ.get('RUNNING_UNITTESTS') == 'True': client_type = 'dummy' if client_type is None: client_type = Configuration.get( '/ovs/framework/stores|persistent') PersistentFactory.store = None if client_type in ['pyrakoon', 'arakoon']: from ovs.extensions.storage.persistent.pyrakoonstore import PyrakoonStore PersistentFactory.store = PyrakoonStore( str( Configuration.get( '/ovs/framework/arakoon_clusters|ovsdb'))) if client_type == 'dummy': from ovs.extensions.storage.persistent.dummystore import DummyPersistentStore PersistentFactory.store = DummyPersistentStore() if PersistentFactory.store is None: raise RuntimeError('Invalid client_type specified') return PersistentFactory.store
def setUp(cls): """ (Re)Sets the stores on every test """ PersistentFactory.store = DummyPersistentStore() PersistentFactory.store.clean() VolatileFactory.store = DummyVolatileStore() VolatileFactory.store.clean()
def setUp(cls): """ (Re)Sets the stores on every test """ PersistentFactory.store = DummyPersistentStore() PersistentFactory.store.clean() VolatileFactory.store = DummyVolatileStore() VolatileFactory.store.clean() PersistentFactory.store._save(Decorators.initial_data[0]) VolatileFactory.store._save(Decorators.initial_data[1])
def setUpClass(cls): """ Sets up the unittest, mocking a certain set of 3rd party libraries and extensions. This makes sure the unittests can be executed without those libraries installed """ # Load dummy stores PersistentFactory.store = DummyPersistentStore() VolatileFactory.store = DummyVolatileStore() # Replace mocked classes sys.modules[ 'ovs.extensions.storageserver.storagedriver'] = StorageDriverModule # Import required modules/classes after mocking is done from ovs.dal.hybrids.vdisk import VDisk from ovs.dal.hybrids.service import Service from ovs.dal.hybrids.vpool import VPool from ovs.dal.hybrids.storagerouter import StorageRouter from ovs.dal.hybrids.pmachine import PMachine from ovs.dal.hybrids.servicetype import ServiceType from ovs.dal.hybrids.storagedriver import StorageDriver from ovs.dal.hybrids.backendtype import BackendType from ovs.dal.hybrids.j_mdsservice import MDSService from ovs.dal.hybrids.j_mdsservicevdisk import MDSServiceVDisk from ovs.extensions.generic.volatilemutex import VolatileMutex from ovs.lib.mdsservice import MDSServiceController # Globalize mocked classes global VDisk global VPool global Service global StorageRouter global StorageDriver global BackendType global PMachine global MDSService global ServiceType global MDSServiceVDisk global VolatileMutex global MDSServiceController _ = VDisk(), VPool(), Service(), MDSService(), MDSServiceVDisk(), ServiceType(), \ StorageRouter(), StorageDriver(), BackendType(), PMachine(), \ VolatileMutex('dummy'), MDSServiceController # Configuration def _get(key): c = PersistentFactory.get_client() if c.exists(key): return c.get(key) return None Configuration.get = staticmethod(_get) # Cleaning storage VolatileFactory.store.clean() PersistentFactory.store.clean()
def setUpClass(cls): """ Sets up the unittest, mocking a certain set of 3rd party libraries and extensions. This makes sure the unittests can be executed without those libraries installed """ # Load dummy stores PersistentFactory.store = DummyPersistentStore() VolatileFactory.store = DummyVolatileStore() # Replace mocked classes sys.modules[ 'ovs.extensions.storageserver.storagedriver'] = StorageDriverModule sys.modules['ovs.extensions.hypervisor.hypervisors.kvm'] = KVMModule # Import required modules/classes after mocking is done from ovs.dal.hybrids.backendtype import BackendType from ovs.dal.hybrids.vdisk import VDisk from ovs.dal.hybrids.j_mdsservice import MDSService from ovs.dal.hybrids.j_mdsservicevdisk import MDSServiceVDisk from ovs.lib.vdisk import VDiskController from ovs.dal.hybrids.pmachine import PMachine from ovs.dal.hybrids.vmachine import VMachine from ovs.dal.hybrids.vpool import VPool from ovs.dal.hybrids.storagedriver import StorageDriver from ovs.dal.hybrids.storagerouter import StorageRouter from ovs.dal.hybrids.failuredomain import FailureDomain from ovs.dal.hybrids.service import Service from ovs.dal.hybrids.servicetype import ServiceType from ovs.dal.lists.vdisklist import VDiskList from ovs.lib.mdsservice import MDSServiceController # Globalize mocked classes global VDisk global VDiskController global PMachine global VMachine global BackendType global VPool global StorageDriver global StorageRouter global FailureDomain global MDSService global MDSServiceVDisk global Service global ServiceType global VDiskList global MDSServiceController _ = VDisk(), PMachine(), VMachine(), VDiskController, VPool(), BackendType(), StorageDriver(), StorageRouter(), \ FailureDomain(), MDSService(), MDSServiceVDisk(), Service(), ServiceType(), VDiskList, MDSServiceController # Cleaning storage VolatileFactory.store.clean() PersistentFactory.store.clean()
def setUpClass(cls): """ Sets up the unittest, mocking a certain set of 3rd party libraries and extensions. This makes sure the unittests can be executed without those libraries installed """ # Replace mocked classes sys.modules['ovs.extensions.hypervisor.factory'] = FactoryModule PersistentFactory.store = DummyPersistentStore() PersistentFactory.store.clean() PersistentFactory.store.clean() VolatileFactory.store = DummyVolatileStore() VolatileFactory.store.clean() VolatileFactory.store.clean()
def setUpClass(cls): """ Sets up the unittest, mocking a certain set of 3rd party libraries and extensions. This makes sure the unittests can be executed without those libraries installed """ # Load dummy stores PersistentFactory.store = DummyPersistentStore() VolatileFactory.store = DummyVolatileStore() # Replace mocked classes sys.modules[ 'ovs.extensions.storageserver.storagedriver'] = StorageDriverModule # Import required modules/classes after mocking is done from ovs.dal.hybrids.backendtype import BackendType from ovs.dal.hybrids.disk import Disk from ovs.dal.hybrids.diskpartition import DiskPartition from ovs.dal.hybrids.failuredomain import FailureDomain from ovs.dal.hybrids.pmachine import PMachine from ovs.dal.hybrids.storagerouter import StorageRouter from ovs.dal.hybrids.vdisk import VDisk from ovs.dal.hybrids.vmachine import VMachine from ovs.dal.hybrids.vpool import VPool from ovs.extensions.generic.volatilemutex import VolatileMutex from ovs.lib.vmachine import VMachineController from ovs.lib.vdisk import VDiskController from ovs.lib.scheduledtask import ScheduledTaskController # Globalize mocked classes global Disk global VDisk global VMachine global PMachine global VPool global BackendType global DiskPartition global FailureDomain global StorageRouter global VolatileMutex global VMachineController global VDiskController global ScheduledTaskController _ = VDisk(), VolatileMutex('dummy'), VMachine(), PMachine(), VPool(), BackendType(), FailureDomain(), \ VMachineController, VDiskController, ScheduledTaskController, StorageRouter(), Disk(), DiskPartition() # Cleaning storage VolatileFactory.store.clean() PersistentFactory.store.clean()
def get_client(client_type=None): """ Returns a persistent storage client """ if not hasattr(PersistentFactory, 'store') or PersistentFactory.store is None: if client_type is None: client_type = Configuration.get('ovs.core.storage.persistent') PersistentFactory.store = None if client_type == 'arakoon': from ovs.extensions.storage.persistent.arakoonstore import ArakoonStore PersistentFactory.store = ArakoonStore('ovsdb') if client_type == 'default': from ovs.extensions.storage.persistent.dummystore import DummyPersistentStore PersistentFactory.store = DummyPersistentStore() if PersistentFactory.store is None: raise RuntimeError('Invalid client_type specified') return PersistentFactory.store
def setUpClass(cls): """ Sets up the unittest, mocking a certain set of 3rd party libraries and extensions. This makes sure the unittests can be executed without those libraries installed """ PersistentFactory.store = DummyPersistentStore() PersistentFactory.store.clean() PersistentFactory.store.clean() VolatileFactory.store = DummyVolatileStore() VolatileFactory.store.clean() VolatileFactory.store.clean() admin_group = Group() admin_group.name = 'administrators' admin_group.description = 'Administrators' admin_group.save() viewers_group = Group() viewers_group.name = 'viewers' viewers_group.description = 'Viewers' viewers_group.save() # Create users admin = User() admin.username = '******' admin.password = hashlib.sha256('admin').hexdigest() admin.is_active = True admin.group = admin_group admin.save() admin_npg = User() admin_npg.username = '******' admin_npg.password = hashlib.sha256('admin_npg').hexdigest() admin_npg.is_active = True admin_npg.group = admin_group admin_npg.save() admin_na = User() admin_na.username = '******' admin_na.password = hashlib.sha256('admin_na').hexdigest() admin_na.is_active = False admin_na.group = admin_group admin_na.save() user = User() user.username = '******' user.password = hashlib.sha256('user').hexdigest() user.is_active = True user.group = viewers_group user.save() sort_combinations = [('bb', 'aa'), ('aa', 'cc'), ('bb', 'dd'), ('aa', 'bb')] # No logical ordering for username, password in sort_combinations: sort_user = User() sort_user.username = username sort_user.password = password sort_user.is_active = True sort_user.group = viewers_group sort_user.save() # Create internal OAuth 2 clients admin_client = Client() admin_client.ovs_type = 'FRONTEND' admin_client.grant_type = 'PASSWORD' admin_client.user = admin admin_client.save() admin_na_client = Client() admin_na_client.ovs_type = 'FRONTEND' admin_na_client.grant_type = 'PASSWORD' admin_na_client.user = admin_na admin_na_client.save() user_client = Client() user_client.ovs_type = 'FRONTEND' user_client.grant_type = 'PASSWORD' user_client.user = user user_client.save() # Create roles read_role = Role() read_role.code = 'read' read_role.name = 'Read' read_role.description = 'Can read objects' read_role.save() write_role = Role() write_role.code = 'write' write_role.name = 'Write' write_role.description = 'Can write objects' write_role.save() manage_role = Role() manage_role.code = 'manage' manage_role.name = 'Manage' manage_role.description = 'Can manage the system' manage_role.save() # Attach groups to roles mapping = [(admin_group, [read_role, write_role, manage_role]), (viewers_group, [read_role])] for setting in mapping: for role in setting[1]: rolegroup = RoleGroup() rolegroup.group = setting[0] rolegroup.role = role rolegroup.save() for user in setting[0].users: for role in setting[1]: for client in user.clients: roleclient = RoleClient() roleclient.client = client roleclient.role = role roleclient.save() Decorators.initial_data = PersistentFactory.store._read( ), VolatileFactory.store._read() sys.modules['backend.serializers.serializers'] = Serializers sys.path.append('/opt/OpenvStorage') sys.path.append('/opt/OpenvStorage/webapps') os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") from django.conf import settings settings.VERSION = (1, 2, 3) from django.test import RequestFactory Decorators.factory = RequestFactory() fakesleep.monkey_patch()