Example #1
0
    def reset(self):
        MockModel._mock_vms = {}
        MockModel._mock_snapshots = {}
        self._mock_swupdate = MockSoftwareUpdate()
        self._mock_repositories = MockRepositories()

        if hasattr(self, 'objstore'):
            self.objstore = ObjectStore(self.objstore_loc)

        params = {
            'vms': [u'test'],
            'templates': [],
            'networks': [u'default'],
            'storagepools': [u'default-pool']
        }

        for res, items in params.iteritems():
            resources = getattr(self, '%s_get_list' % res)()
            for i in resources:
                if i in items:
                    continue

                try:
                    getattr(self, '%s_deactivate' % res[:-1])(i)
                except:
                    pass

                getattr(self, '%s_delete' % res[:-1])(i)

        volumes = self.storagevolumes_get_list('default-pool')
        for v in volumes:
            self.storagevolume_delete('default-pool', v)
Example #2
0
    def reset(self):
        MockModel._mock_vms = defaultdict(list)
        MockModel._mock_snapshots = {}

        if hasattr(self, 'objstore'):
            self.objstore = ObjectStore(self.objstore_loc)

        params = {
            'vms': [u'test'],
            'templates': [],
            'networks': [u'default'],
            'storagepools': [u'default-pool'],
        }

        for res, items in params.items():
            resources = getattr(self, '%s_get_list' % res)()
            for i in resources:
                if i in items:
                    continue

                try:
                    getattr(self, '%s_deactivate' % res[:-1])(i)
                except Exception:
                    pass

                getattr(self, '%s_delete' % res[:-1])(i)

        volumes = self.storagevolumes_get_list('default-pool')
        for v in volumes:
            self.storagevolume_delete('default-pool', v)
Example #3
0
    def __init__(self, libvirt_uri=None, objstore_loc=None):
        def get_instances(module_name):
            instances = []
            module = import_module(module_name)
            members = inspect.getmembers(module, inspect.isclass)
            for cls_name, instance in members:
                if inspect.getmodule(instance) == module and \
                   cls_name.endswith('Model'):
                    instances.append(instance)

            return instances

        self.objstore = ObjectStore(objstore_loc or config.get_object_store())
        self.conn = LibvirtConnection(libvirt_uri)
        kargs = {'objstore': self.objstore, 'conn': self.conn}
        models = []

        # Import task model from Wok
        instances = get_instances('wok.model.tasks')
        for instance in instances:
            models.append(instance(**kargs))

        # Import all Kimchi plugin models
        this = os.path.basename(__file__)
        this_mod = os.path.splitext(this)[0]

        for mod_name in listPathModules(os.path.dirname(__file__)):
            if mod_name.startswith("_") or mod_name == this_mod:
                continue

            instances = get_instances('wok.plugins.kimchi.model.' + mod_name)
            for instance in instances:
                models.append(instance(**kargs))

        return super(Model, self).__init__(models)
Example #4
0
    def __init__(self, objstore_loc=None):
        # Override osinfo.defaults to ajust the values according to
        # test:///default driver

        self._mock_swupdate = MockSoftwareUpdate()
        self._mock_repositories = MockRepositories()

        cpuinfo.get_topo_capabilities = \
            MockModel.get_topo_capabilities

        super(MockModel, self).__init__(objstore_loc)
        self.objstore_loc = objstore_loc
        self.objstore = ObjectStore(objstore_loc)

        # The MockModel methods are instantiated on runtime according to Model
        # and BaseModel
        # Because that a normal method override will not work here
        # Instead of that we also need to do the override on runtime
        for method in dir(self):
            if method.startswith('_mock_'):
                mock_method = getattr(self, method)
                if not callable(mock_method):
                    continue

                m = method[6:]
                model_method = getattr(self, m)
                setattr(self, '_model_' + m, model_method)
                setattr(self, m, mock_method)

        DebugReportsModel._gen_debugreport_file = self._gen_debugreport_file
Example #5
0
    def __init__(self, libvirt_uri=None, objstore_loc=None):

        self.objstore = ObjectStore(objstore_loc or config.get_object_store())
        self.conn = LibvirtConnection(libvirt_uri)

        # Register for libvirt events
        self.events = LibvirtEvents()
        self.events.handleEnospc(self.conn)
        self.events.registerPoolEvents(self.conn, self._events_handler,
                                       'storages')
        self.events.registerNetworkEvents(self.conn, self._events_handler,
                                          'networks')
        self.events.registerDomainEvents(self.conn, self._events_handler,
                                         'vms')

        kargs = {'objstore': self.objstore, 'conn': self.conn,
                 'eventsloop': self.events}

        models = get_all_model_instances(__name__, __file__, kargs)

        # Import task model from Wok
        instances = get_model_instances('wok.model.tasks')
        for instance in instances:
            models.append(instance(**kargs))

        super(Model, self).__init__(models)
Example #6
0
    def __init__(self, objstore_loc=None):
        # Override osinfo.defaults to ajust the values according to
        # test:///default driver
        defaults = dict(osinfo.defaults)
        defaults.update(mockmodel_defaults)
        osinfo.defaults = dict(defaults)

        self._mock_devices = MockDevices()
        self._mock_partitions = MockPartitions()
        self._mock_storagevolumes = MockStorageVolumes()
        self._mock_swupdate = MockSoftwareUpdate()
        self._mock_repositories = MockRepositories()

        cpuinfo.get_topo_capabilities = MockModel.get_topo_capabilities
        vmifaces.getDHCPLeases = MockModel.getDHCPLeases
        libvirt.virConnect.defineXML = MockModel.domainDefineXML
        libvirt.virDomain.XMLDesc = MockModel.domainXMLDesc
        libvirt.virDomain.undefine = MockModel.undefineDomain
        libvirt.virDomain.attachDeviceFlags = MockModel.attachDeviceFlags
        libvirt.virDomain.detachDeviceFlags = MockModel.detachDeviceFlags
        libvirt.virDomain.updateDeviceFlags = MockModel.updateDeviceFlags
        libvirt.virStorageVol.resize = MockModel.volResize
        libvirt.virStorageVol.wipePattern = MockModel.volWipePattern

        IscsiPoolDef.prepare = NetfsPoolDef.prepare = StoragePoolDef.prepare

        PAMUsersModel.auth_type = 'fake'
        PAMGroupsModel.auth_type = 'fake'

        super(MockModel, self).__init__('test:///default', objstore_loc)
        self.objstore_loc = objstore_loc
        self.objstore = ObjectStore(objstore_loc)

        # The MockModel methods are instantiated on runtime according to Model
        # and BaseModel
        # Because that a normal method override will not work here
        # Instead of that we also need to do the override on runtime
        for method in dir(self):
            if method.startswith('_mock_'):
                mock_method = getattr(self, method)
                if not callable(mock_method):
                    continue

                m = method[6:]
                model_method = getattr(self, m)
                setattr(self, '_model_' + m, model_method)
                setattr(self, m, mock_method)

        DeviceModel.lookup = self._mock_device_lookup
        StoragePoolModel._update_lvm_disks = self._update_lvm_disks
        StorageVolumesModel.get_list = self._mock_storagevolumes_get_list
        StorageVolumeModel.doUpload = self._mock_storagevolume_doUpload
        DebugReportsModel._gen_debugreport_file = self._gen_debugreport_file
        LibvirtVMTemplate._get_volume_path = self._get_volume_path
        VMTemplate.get_iso_info = self._probe_image
        imageinfo.probe_image = self._probe_image
Example #7
0
    def setUp(self):
        self.temp_file = tempfile.NamedTemporaryFile(delete=False)
        objstore_loc = self.temp_file.name
        self._objstore = ObjectStore(objstore_loc)

        self.task = TaskModel(objstore=self._objstore)

        ArchivesModel._archive_dir = '/tmp'
        ArchivesModel._default_include = []
        ArchivesModel._default_exclude = []
Example #8
0
    def __init__(self):
        objstore_loc = config.get_object_store() + '_ginger'
        self._objstore = ObjectStore(objstore_loc)

        sub_models = []
        firmware = FirmwareModel()
        powerprofiles = PowerProfilesModel()
        powerprofile = PowerProfileModel()
        users = UsersModel()
        user = UserModel()
        interfaces = InterfacesModel()
        interface = InterfaceModel()
        cfginterface = CfginterfaceModel()
        cfginterfaces = CfginterfacesModel()
        dasddevs = DASDdevsModel()
        dasddev = DASDdevModel(objstore=self._objstore)
        dasdpartitions = DASDPartitionsModel()
        dasdpartition = DASDPartitionModel()
        network = NetworkModel()
        filesystems = FileSystemsModel()
        filesystem = FileSystemModel()
        archives = ArchivesModel(objstore=self._objstore)
        archive = ArchiveModel(objstore=self._objstore)
        backup = BackupModel(objstore=self._objstore,
                             archives_model=archives,
                             archive_model=archive)
        san_adapters = SanAdaptersModel()
        san_adapter = SanAdapterModel()
        sensors = SensorsModel()
        ibm_sep = SepModel()
        subscription = SubscriptionModel()
        subscriber = SubscribersModel()

        features = [
            firmware, backup, dasddevs, dasdpartitions, network, powerprofiles,
            san_adapters, sensors, ibm_sep, users, filesystems
        ]
        capabilities = CapabilitiesModel(features)

        sub_models = [
            backup, archives, archive, firmware, interfaces, interface,
            cfginterface, cfginterfaces, dasddevs, dasddev, dasdpartitions,
            dasdpartition, network, filesystems, filesystem, powerprofiles,
            powerprofile, users, user, san_adapters, san_adapter, sensors,
            ibm_sep, subscription, subscriber, capabilities
        ]
        super(GingerModel, self).__init__(sub_models)
Example #9
0
    def __init__(self):

        objstore_loc = wok_config.get_object_store() + '_ginger'
        self._objstore = ObjectStore(objstore_loc)
        # Some paths or URI's present in the objectstore have changed after
        # Wok 2.0.0 release. Check here if a schema upgrade is necessary.
        upgrade_objectstore_schema(objstore_loc, 'version')

        kargs = {'objstore': self._objstore}
        models = get_all_model_instances(__name__, __file__, kargs)

        # Import task model from Wok
        instances = get_model_instances('wok.model.tasks')
        for instance in instances:
            models.append(instance(**kargs))

        super(GingerModel, self).__init__(models)
Example #10
0
    def __init__(self, objstore_loc=None):
        def get_instances(module_name):
            instances = []
            module = import_module(module_name)
            members = inspect.getmembers(module, inspect.isclass)
            for cls_name, instance in members:
                if inspect.getmodule(instance) == module and \
                   cls_name.endswith('Model'):
                    instances.append(instance)

            return instances

        if objstore_loc is None:
            objstore_loc = config.get_object_store()

        # Some paths or URI's present in the objectstore have changed after
        # Wok 2.0.0 release. Check here if a schema upgrade is necessary.
        upgrade_objectstore_schema(objstore_loc, 'version')

        self.objstore = ObjectStore(objstore_loc)
        kargs = {'objstore': self.objstore}

        models = []
        # Import task model from Wok
        instances = get_instances('wok.model.tasks')
        for instance in instances:
            models.append(instance(**kargs))

        # Import all Kimchi plugin models
        this = os.path.basename(__file__)
        this_mod = os.path.splitext(this)[0]

        for mod_name in listPathModules(os.path.dirname(__file__)):
            if mod_name.startswith("_") or mod_name == this_mod:
                continue

            instances = get_instances('wok.plugins.gingerbase.model.' +
                                      mod_name)
            for instance in instances:
                models.append(instance(**kargs))

        return super(Model, self).__init__(models)
Example #11
0
    def __init__(self, objstore_loc=None):

        self.objstore = ObjectStore(objstore_loc)
        kargs = {'objstore': self.objstore}

        this = os.path.basename(__file__)
        this_mod = os.path.splitext(this)[0]

        models = []
        for mod_name in listPathModules(os.path.dirname(__file__)):
            if mod_name.startswith("_") or mod_name == this_mod:
                continue

            module = import_module('wok.model.' + mod_name)
            members = inspect.getmembers(module, inspect.isclass)
            for cls_name, instance in members:
                if inspect.getmodule(instance) == module:
                    if cls_name.endswith('Model'):
                        models.append(instance(**kargs))

        return super(Model, self).__init__(models)
Example #12
0
    def __init__(self, libvirt_uri=None, objstore_loc=None):

        self.objstore = ObjectStore(objstore_loc or config.get_object_store())
        self.conn = LibvirtConnection(libvirt_uri)

        # Register for Libvirt's host ENOSPC event and notify UI if it happens
        self.events = LibvirtEvents()
        self.events.handleEnospc(self.conn)

        kargs = {
            'objstore': self.objstore,
            'conn': self.conn,
            'eventsloop': self.events
        }

        models = get_all_model_instances(__name__, __file__, kargs)

        # Import task model from Wok
        instances = get_model_instances('wok.model.tasks')
        for instance in instances:
            models.append(instance(**kargs))

        return super(Model, self).__init__(models)
Example #13
0
 def setUp(self):
     objstore_loc = config.get_object_store() + '_ginger'
     self._objstore = ObjectStore(objstore_loc)
     self.task_model = TaskModel(objstore=self._objstore)
Example #14
0
 def setUp(self):
     objstore_loc = config.get_object_store() + '_ginger'
     self._objstore = ObjectStore(objstore_loc)
Example #15
0
    def __init__(self, objstore_loc=None):

        self.objstore = ObjectStore(objstore_loc)
        kargs = {'objstore': self.objstore}
        models = get_all_model_instances(__name__, __file__, kargs)
        super(Model, self).__init__(models)
Example #16
0
    def __init__(self, objstore_loc=None):
        # Override osinfo.defaults to ajust the values according to
        # test:///default driver
        defaults = dict(osinfo.defaults)
        defaults.update(mockmodel_defaults)
        defaults['disks'][0]['pool'] = {'name': DEFAULT_POOL}
        osinfo.defaults = dict(defaults)

        self._mock_vgs = MockVolumeGroups()
        self._mock_partitions = MockPartitions()
        self._mock_devices = MockDevices()
        self._mock_storagevolumes = MockStorageVolumes()

        cpuinfo.get_topo_capabilities = MockModel.get_topo_capabilities
        libvirt.virNetwork.DHCPLeases = MockModel.getDHCPLeases
        libvirt.virDomain.XMLDesc = MockModel.domainXMLDesc
        libvirt.virDomain.undefine = MockModel.undefineDomain
        libvirt.virDomain.attachDeviceFlags = MockModel.attachDeviceFlags
        libvirt.virDomain.detachDeviceFlags = MockModel.detachDeviceFlags
        libvirt.virDomain.updateDeviceFlags = MockModel.updateDeviceFlags
        libvirt.virStorageVol.resize = MockModel.volResize
        libvirt.virStorageVol.wipePattern = MockModel.volWipePattern

        IscsiPoolDef.prepare = NetfsPoolDef.prepare = StoragePoolDef.prepare

        PAMUsersModel.auth_type = 'fake'
        PAMGroupsModel.auth_type = 'fake'

        super(MockModel, self).__init__('test:///default', objstore_loc)
        self.objstore_loc = objstore_loc
        self.objstore = ObjectStore(objstore_loc)

        # The MockModel methods are instantiated on runtime according to Model
        # and BaseModel
        # Because that a normal method override will not work here
        # Instead of that we also need to do the override on runtime

        for method in dir(self):
            if method.startswith('_mock_'):
                mock_method = getattr(self, method)
                if not callable(mock_method):
                    continue

                m = method[6:]
                model_method = getattr(self, m)
                setattr(self, '_model_' + m, model_method)
                setattr(self, m, mock_method)

        DeviceModel.lookup = self._mock_device_lookup
        DeviceModel.get_iommu_groups = self._mock_device_get_iommu_groups
        DeviceModel.is_device_3D_controller = self._mock_device_is_device_3D_controller
        DevicesModel.get_list = self._mock_devices_get_list
        StoragePoolsModel._check_lvm = self._check_lvm
        StoragePoolModel._update_lvm_disks = self._update_lvm_disks
        StoragePoolModel._pool_used_by_template = self._pool_used_by_template
        StorageVolumesModel.get_list = self._mock_storagevolumes_get_list
        StorageVolumeModel.doUpload = self._mock_storagevolume_doUpload
        LibvirtVMTemplate._get_volume_path = self._get_volume_path
        VMTemplate.get_iso_info = self._probe_image
        imageinfo.probe_image = self._probe_image
        VMHostDevsModel._get_pci_device_xml = self._get_pci_device_xml
        VMHostDevsModel._validate_pci_passthrough_env = self._validate_pci

        self._create_virt_viewer_tmp_file()
        cherrypy.engine.subscribe('exit', self.virtviewertmpfile_cleanup)
Example #17
0
    def reset(self):
        self._mock_swupdate = MockSoftwareUpdate()
        self._mock_repositories = MockRepositories()

        if hasattr(self, 'objstore'):
            self.objstore = ObjectStore(self.objstore_loc)