Пример #1
0
    def test_event_resize_from_volumedriver(self):
        """
        Test resize from volumedriver event
            - Create a vDisk using the resize event
            - Resize the created vDisk using the same resize event
        """
        structure = Helper.build_service_structure(
            {'vpools': [1],
             'storagerouters': [1],
             'storagedrivers': [(1, 1, 1)],  # (<id>, <vpool_id>, <storagerouter_id>)
             'mds_services': [(1, 1)]}  # (<id>, <storagedriver_id>)
        )
        vpools = structure['vpools']
        storagedrivers = structure['storagedrivers']
        mds_service = structure['mds_services'][1]

        # Create volume using resize from voldrv
        device_name = '/vdisk.raw'
        srclient = StorageRouterClient(vpools[1].guid, None)
        mds_backend_config = Helper._generate_mdsmetadatabackendconfig([mds_service])
        volume_id = srclient.create_volume(device_name, mds_backend_config, 1024 ** 4, str(storagedrivers[1].storagedriver_id))
        VDiskController.resize_from_voldrv(volume_id=volume_id,
                                           volume_size=1024 ** 4,
                                           volume_path=device_name,
                                           storagedriver_id=storagedrivers[1].storagedriver_id)
        vdisks = VDiskList.get_vdisks()
        self.assertTrue(expr=len(vdisks) == 1,
                        msg='Expected to find 1 vDisk in model')
        self.assertEqual(first=vdisks[0].name,
                         second='vdisk',
                         msg='Volume name should be vdisk')
        self.assertEqual(first=vdisks[0].volume_id,
                         second=volume_id,
                         msg='Volume ID should be {0}'.format(volume_id))
        self.assertEqual(first=vdisks[0].devicename,
                         second=device_name,
                         msg='Device name should be {0}'.format(device_name))
        self.assertEqual(first=vdisks[0].size,
                         second=1024 ** 4,
                         msg='Size should be 1 TiB')

        # Resize volume using resize from voldrv
        VDiskController.resize_from_voldrv(volume_id=volume_id,
                                           volume_size=2 * 1024 ** 4,
                                           volume_path=device_name,
                                           storagedriver_id=storagedrivers[1].storagedriver_id)
        vdisks = VDiskList.get_vdisks()
        self.assertTrue(expr=len(vdisks) == 1,
                        msg='Expected to find 1 vDisk in model')
        self.assertEqual(first=vdisks[0].name,
                         second='vdisk',
                         msg='Volume name should be vdisk')
        self.assertEqual(first=vdisks[0].size,
                         second=2 * 1024 ** 4,
                         msg='Size should be 2 TiB')
Пример #2
0
 def create_vdisks_for_mds_service(amount,
                                   start_id,
                                   mds_service=None,
                                   storagedriver=None):
     """
     Generates vdisks and appends them to a given mds_service
     """
     if (mds_service is None
             and storagedriver is None) or (mds_service is not None
                                            and storagedriver is not None):
         raise RuntimeError(
             'Either `mds_service` or `storagedriver` should be passed')
     vdisks = {}
     storagedriver_id = None
     vpool = None
     mds_services = []
     if mds_service is not None:
         mds_services.append(mds_service)
         for sd in mds_service.vpool.storagedrivers:
             if sd.storagerouter_guid == mds_service.service.storagerouter_guid:
                 storagedriver_id = sd.storagedriver_id
                 vpool = sd.vpool
         if storagedriver_id is None:
             raise RuntimeError(
                 'The given MDSService is located on a node without StorageDriver'
             )
     else:
         storagedriver_id = storagedriver.storagedriver_id
         vpool = storagedriver.vpool
     srclient = StorageRouterClient(vpool.guid, None)
     for i in xrange(start_id, start_id + amount):
         devicename = 'vdisk_{0}'.format(i)
         mds_backend_config = DalHelper.generate_mds_metadata_backend_config(
             mds_services)
         volume_id = srclient.create_volume(devicename, mds_backend_config,
                                            0, str(storagedriver_id))
         if len(mds_services) == 1:
             MDSClient.set_catchup(mds_services[0], volume_id, 50)
         vdisk = VDisk()
         vdisk.name = str(i)
         vdisk.devicename = devicename
         vdisk.volume_id = volume_id
         vdisk.vpool = vpool
         vdisk.size = 0
         vdisk.save()
         vdisk.reload_client('storagedriver')
         if mds_service is not None:
             junction = MDSServiceVDisk()
             junction.vdisk = vdisk
             junction.mds_service = mds_service
             junction.is_master = True
             junction.save()
         vdisks[i] = vdisk
     return vdisks
Пример #3
0
 def create_vdisks_for_mds_service(amount, start_id, mds_service=None, storagedriver=None):
     """
     Generates vdisks and appends them to a given mds_service
     """
     if (mds_service is None and storagedriver is None) or (mds_service is not None and storagedriver is not None):
         raise RuntimeError("Either `mds_service` or `storagedriver` should be passed")
     vdisks = {}
     storagedriver_id = None
     vpool = None
     mds_services = []
     if mds_service is not None:
         mds_services.append(mds_service)
         for sd in mds_service.vpool.storagedrivers:
             if sd.storagerouter_guid == mds_service.service.storagerouter_guid:
                 storagedriver_id = sd.storagedriver_id
                 vpool = sd.vpool
         if storagedriver_id is None:
             raise RuntimeError("The given MDSService is located on a node without StorageDriver")
     else:
         storagedriver_id = storagedriver.storagedriver_id
         vpool = storagedriver.vpool
     srclient = StorageRouterClient(vpool.guid, None)
     for i in xrange(start_id, start_id + amount):
         devicename = "vdisk_{0}".format(i)
         mds_backend_config = Helper._generate_mdsmetadatabackendconfig(mds_services)
         volume_id = srclient.create_volume(devicename, mds_backend_config, 0, str(storagedriver_id))
         if len(mds_services) == 1:
             MDSClient.set_catchup(mds_services[0], volume_id, 50)
         vdisk = VDisk()
         vdisk.name = str(i)
         vdisk.devicename = devicename
         vdisk.volume_id = volume_id
         vdisk.vpool = vpool
         vdisk.size = 0
         vdisk.save()
         vdisk.reload_client("storagedriver")
         if mds_service is not None:
             junction = MDSServiceVDisk()
             junction.vdisk = vdisk
             junction.mds_service = mds_service
             junction.is_master = True
             junction.save()
         vdisks[i] = vdisk
     return vdisks
Пример #4
0
    def test_event_resize_from_volumedriver(self):
        """
        Test resize from volumedriver event
            - Create a vDisk using the resize event
            - Resize the created vDisk using the same resize event
        """
        structure = DalHelper.build_dal_structure({
            'vpools': [1],
            'storagerouters': [1],
            'storagedrivers':
            [(1, 1, 1)],  # (<id>, <vpool_id>, <storagerouter_id>)
            'mds_services': [(1, 1)]
        }  # (<id>, <storagedriver_id>)
                                                  )
        vpools = structure['vpools']
        storagedrivers = structure['storagedrivers']
        mds_service = structure['mds_services'][1]

        # Create volume using resize from voldrv
        device_name = '/vdisk.raw'
        srclient = StorageRouterClient(vpools[1].guid, None)
        mds_backend_config = DalHelper.generate_mds_metadata_backend_config(
            [mds_service])
        volume_id = srclient.create_volume(
            device_name, mds_backend_config, 1024**4,
            str(storagedrivers[1].storagedriver_id))
        VDiskController.resize_from_voldrv(
            volume_id=volume_id,
            volume_size=1024**4,
            volume_path=device_name,
            storagedriver_id=storagedrivers[1].storagedriver_id)
        vdisks = VDiskList.get_vdisks()
        self.assertTrue(expr=len(vdisks) == 1,
                        msg='Expected to find 1 vDisk in model')
        self.assertEqual(first=vdisks[0].name,
                         second='vdisk',
                         msg='Volume name should be vdisk')
        self.assertEqual(first=vdisks[0].volume_id,
                         second=volume_id,
                         msg='Volume ID should be {0}'.format(volume_id))
        self.assertEqual(first=vdisks[0].devicename,
                         second=device_name,
                         msg='Device name should be {0}'.format(device_name))
        self.assertEqual(first=vdisks[0].size,
                         second=1024**4,
                         msg='Size should be 1 TiB')

        # Resize volume using resize from voldrv
        VDiskController.resize_from_voldrv(
            volume_id=volume_id,
            volume_size=2 * 1024**4,
            volume_path=device_name,
            storagedriver_id=storagedrivers[1].storagedriver_id)
        vdisks = VDiskList.get_vdisks()
        self.assertTrue(expr=len(vdisks) == 1,
                        msg='Expected to find 1 vDisk in model')
        self.assertEqual(first=vdisks[0].name,
                         second='vdisk',
                         msg='Volume name should be vdisk')
        self.assertEqual(first=vdisks[0].size,
                         second=2 * 1024**4,
                         msg='Size should be 2 TiB')
Пример #5
0
    def test_reusing_devicename(self):
        """
        Validates whether the framework can handle out of sync processed events when a vDisk with the same devicename
        is created and removed over and over
        """
        structure = DalHelper.build_dal_structure({
            'vpools': [1],
            'storagerouters': [1],
            'storagedrivers':
            [(1, 1, 1)],  # (<id>, <vpool_id>, <storagerouter_id>)
            'mds_services': [(1, 1)]
        }  # (<id>, <storagedriver_id>)
                                                  )
        vpool = structure['vpools'][1]
        storagedriver = structure['storagedrivers'][1]
        mds_service = structure['mds_services'][1]
        # noinspection PyArgumentList
        backend_config = MDSMetaDataBackendConfig([
            MDSNodeConfig(address=str(mds_service.service.storagerouter.ip),
                          port=mds_service.service.ports[0])
        ])
        devicename = '/test.raw'
        size = 1024**3
        srclient = StorageRouterClient(vpool.guid, None)

        # A normal flow would be:
        # * create volume, resize event,
        # * delete volume, delete event,
        # * create volume, resize event,
        # * delete volume, delete event

        # Let's test the normal flow
        first_volume_id = srclient.create_volume(
            devicename, backend_config, size, storagedriver.storagedriver_id)
        VDiskController.resize_from_voldrv(first_volume_id, size, devicename,
                                           storagedriver.storagedriver_id)
        self.assertEqual(len(srclient.list_volumes()), 1)
        self.assertEqual(len(vpool.vdisks), 1)
        srclient.unlink(devicename)
        VDiskController.delete_from_voldrv(first_volume_id)
        self.assertEqual(len(srclient.list_volumes()), 0)
        self.assertEqual(len(vpool.vdisks), 0)
        second_volume_id = srclient.create_volume(
            devicename, backend_config, size, storagedriver.storagedriver_id)
        VDiskController.resize_from_voldrv(second_volume_id, size, devicename,
                                           storagedriver.storagedriver_id)
        self.assertEqual(len(srclient.list_volumes()), 1)
        self.assertEqual(len(vpool.vdisks), 1)
        srclient.unlink(devicename)
        VDiskController.delete_from_voldrv(second_volume_id)
        self.assertEqual(len(srclient.list_volumes()), 0)
        self.assertEqual(len(vpool.vdisks), 0)

        # Out of sync - scenario 1
        first_volume_id = srclient.create_volume(
            devicename, backend_config, size, storagedriver.storagedriver_id)
        VDiskController.resize_from_voldrv(first_volume_id, size, devicename,
                                           storagedriver.storagedriver_id)
        self.assertEqual(len(srclient.list_volumes()), 1)
        self.assertEqual(len(vpool.vdisks), 1)
        srclient.unlink(devicename)
        second_volume_id = srclient.create_volume(
            devicename, backend_config, size, storagedriver.storagedriver_id)
        VDiskController.resize_from_voldrv(second_volume_id, size, devicename,
                                           storagedriver.storagedriver_id)
        self.assertEqual(len(srclient.list_volumes()), 1)
        self.assertEqual(len(vpool.vdisks), 2)
        VDiskController.delete_from_voldrv(first_volume_id)
        self.assertEqual(len(srclient.list_volumes()), 1)
        self.assertEqual(len(vpool.vdisks), 1)
        srclient.unlink(devicename)
        VDiskController.delete_from_voldrv(second_volume_id)
        self.assertEqual(len(srclient.list_volumes()), 0)
        self.assertEqual(len(vpool.vdisks), 0)

        # Out of sync - scenario 2
        first_volume_id = srclient.create_volume(
            devicename, backend_config, size, storagedriver.storagedriver_id)
        self.assertEqual(len(srclient.list_volumes()), 1)
        self.assertEqual(len(vpool.vdisks), 0)
        srclient.unlink(devicename)
        self.assertEqual(len(srclient.list_volumes()), 0)
        self.assertEqual(len(vpool.vdisks), 0)
        second_volume_id = srclient.create_volume(
            devicename, backend_config, size, storagedriver.storagedriver_id)
        self.assertEqual(len(srclient.list_volumes()), 1)
        self.assertEqual(len(vpool.vdisks), 0)
        VDiskController.resize_from_voldrv(first_volume_id, size, devicename,
                                           storagedriver.storagedriver_id)
        self.assertEqual(len(srclient.list_volumes()), 1)
        self.assertEqual(len(vpool.vdisks), 0)
        VDiskController.resize_from_voldrv(second_volume_id, size, devicename,
                                           storagedriver.storagedriver_id)
        self.assertEqual(len(srclient.list_volumes()), 1)
        self.assertEqual(len(vpool.vdisks), 1)
        srclient.unlink(devicename)
        self.assertEqual(len(srclient.list_volumes()), 0)
        self.assertEqual(len(vpool.vdisks), 1)
        VDiskController.delete_from_voldrv(first_volume_id)
        self.assertEqual(len(srclient.list_volumes()), 0)
        self.assertEqual(len(vpool.vdisks), 1)
        VDiskController.delete_from_voldrv(second_volume_id)
        self.assertEqual(len(srclient.list_volumes()), 0)
        self.assertEqual(len(vpool.vdisks), 0)
Пример #6
0
    def test_sync(self):
        """
        Validates whether the sync works as expected
        """
        structure = DalHelper.build_dal_structure({
            'vpools': [1],
            'storagerouters': [1],
            'storagedrivers':
            [(1, 1, 1)],  # (<id>, <vpool_id>, <storagerouter_id>)
            'mds_services': [(1, 1)]
        }  # (<id>, <storagedriver_id>)
                                                  )
        vpool = structure['vpools'][1]
        storagedriver = structure['storagedrivers'][1]
        mds_service = structure['mds_services'][1]
        # noinspection PyArgumentList
        backend_config = MDSMetaDataBackendConfig([
            MDSNodeConfig(address=str(mds_service.service.storagerouter.ip),
                          port=mds_service.service.ports[0])
        ])
        srclient = StorageRouterClient(vpool.guid, None)

        VDiskController.create_new('one', 1024**3, storagedriver.guid)
        VDiskController.create_new('two', 1024**3, storagedriver.guid)

        vdisks = VDiskList.get_vdisks()
        self.assertEqual(len(vdisks), 2)
        self.assertEqual(len(srclient.list_volumes()), 2)

        VDiskController.sync_with_reality()
        vdisks = VDiskList.get_vdisks()
        self.assertEqual(len(vdisks), 2)
        self.assertEqual(len(srclient.list_volumes()), 2)

        volume_id = srclient.create_volume('/three.raw', backend_config,
                                           1024**3,
                                           storagedriver.storagedriver_id)

        vdisks = VDiskList.get_vdisks()
        self.assertEqual(len(vdisks), 2)
        self.assertEqual(len(srclient.list_volumes()), 3)

        VDiskController.sync_with_reality()
        vdisks = VDiskList.get_vdisks()
        self.assertEqual(len(vdisks), 3)
        self.assertEqual(len(srclient.list_volumes()), 3)

        vdisk = VDiskList.get_vdisk_by_volume_id(volume_id)
        self.assertEqual(vdisk.devicename, '/three.raw')

        vdisk = VDisk()
        vdisk.volume_id = 'foo'
        vdisk.name = 'foo'
        vdisk.devicename = 'foo.raw'
        vdisk.size = 1024**3
        vdisk.vpool = vpool
        vdisk.save()
        vdisks = VDiskList.get_vdisks()
        self.assertEqual(len(vdisks), 4)
        self.assertEqual(len(srclient.list_volumes()), 3)

        VDiskController.sync_with_reality()
        vdisks = VDiskList.get_vdisks()
        self.assertEqual(len(vdisks), 3)
        self.assertEqual(len(srclient.list_volumes()), 3)

        with self.assertRaises(ObjectNotFoundException):
            vdisk.save()