예제 #1
0
    def test_explore_default_provider2(self):
        Storage.explore_provider(self.MyPvd, default_for_snap=True)
        self.assertEqual(Storage.default_snap_provider, self.MyPvd.type)
        self.assertFalse(Storage.default_vol_provider)

        self.assertTrue(isinstance(Storage.lookup_provider(self.MyPvd.type), self.MyPvd))
        self.assertTrue(isinstance(Storage.lookup_provider(None, True), self.MyPvd))
예제 #2
0
 def test_snapshot_factory(self):
     Storage.providers = self._save_pvds
     pvd = Storage.lookup_provider('eph')
     snap = pvd.snapshot_factory('hom')
     self.assertEqual(snap.type, 'eph')
     self.assertEqual(snap.description, 'hom')
     self.assertTrue(isinstance(snap, EphSnapshot))
예제 #3
0
    def test_1(self):
        class TransferMock(object):
            SCHEMA = 'file://'
            def __init__(self):
                self._logger = logging.getLogger(__name__)
                pass

            def upload(self, files, remote_dst):
                remote_path = os.path.normpath(remote_dst[len(self.SCHEMA):])
                ret = []
                for file in files:
                    self._logger.debug('Copy %s -> %s/', file, remote_path)
                    shutil.copy(file, remote_path)
                    ret.append('file://%s/%s' % (remote_path, os.path.basename(file)))
                print system(('ls', '-la', remote_path))[0]
                return tuple(ret)

            def download(self, remote_files, dst, recursive=False):
                if isinstance(remote_files, basestring):
                    remote_files = (remote_files,)
                files = list(os.path.normpath(path[len(self.SCHEMA):]) for path in remote_files)

                ret = []
                for file in files:
                    self._logger.debug('Copy %s -> %s/', file, dst)
                    shutil.copy(file, dst)
                    ret.append(os.path.join(dst, os.path.basename(file)))
                return ret


        Storage.lookup_provider('eph')._snap_pvd._transfer = TransferMock()

        # Create snapshot strage volume (Remote storage emulation)
        self.vols[1] = Storage.create(
                device=self.devices[1],
                mpoint=self.mpoints[1],
                fstype='ext3'
        )
        self.vols[1].mkfs()
        self.vols[1].mount()



        # Create and mount EPH storage
        self.vols[0] = Storage.create(
                type='eph',
                disk=self.devices[0],
                vg='casstorage',
                snap_backend = '%s%s' % (TransferMock.SCHEMA, self.mpoints[1]),
                fstype = 'ext3',
                mpoint = self.mpoints[0]
        )
        self.vols[0].mkfs()
        self.vols[0].mount()

        # Create big file
        bigfile = os.path.join(self.mpoints[0], 'bigfile')
        system(('dd', 'if=/dev/urandom', 'of=%s' % bigfile, 'bs=1M', 'count=15'))
        bigsize = os.path.getsize(bigfile)
        self.assertTrue(bigsize > 0)
        md5sum = system(('/usr/bin/md5sum', bigfile))[0].strip().split(' ')[0]

        # Snapshot storage
        snap = self.vols[0].snapshot(description='Bigfile with us forever')
        self.assertEqual(snap.type, 'eph')
        self.assertEqual(snap.vg, 'casstorage')
        self.assertEqual(snap.state, Snapshot.CREATING)

        wait_until(lambda: snap.state in (Snapshot.COMPLETED, Snapshot.FAILED))
        print snap.config()
        if snap.state == Snapshot.FAILED:
            raise Exception('Snapshot creation failed. See log for more details')

        # Destroy original storage
        self.vols[0].destroy()
        self.vols[0] = None

        # Restore snapshot
        self.vols[2] = Storage.create(disk=self.devices[2], snapshot=snap)
        self.vols[2].mount(self.mpoints[2])
        bigfile2 = os.path.join(self.mpoints[2], 'bigfile')

        self.assertTrue(os.path.exists(bigfile2))

        md5sum2 = system(('/usr/bin/md5sum', bigfile2))[0].strip().split(' ')[0]
        self.assertEqual(md5sum, md5sum2)
예제 #4
0
 def test_explore_provider(self):
     Storage.explore_provider(self.MyPvd)
     self.assertFalse(Storage.default_snap_provider)
     self.assertFalse(Storage.default_vol_provider)
     self.assertTrue(isinstance(Storage.lookup_provider(self.MyPvd.type), self.MyPvd))
예제 #5
0
    def test_1(self):
        class TransferMock(object):
            SCHEMA = 'file://'

            def __init__(self):
                self._logger = logging.getLogger(__name__)
                pass

            def upload(self, files, remote_dst):
                remote_path = os.path.normpath(remote_dst[len(self.SCHEMA):])
                ret = []
                for file in files:
                    self._logger.debug('Copy %s -> %s/', file, remote_path)
                    shutil.copy(file, remote_path)
                    ret.append('file://%s/%s' %
                               (remote_path, os.path.basename(file)))
                print system(('ls', '-la', remote_path))[0]
                return tuple(ret)

            def download(self, remote_files, dst, recursive=False):
                if isinstance(remote_files, basestring):
                    remote_files = (remote_files, )
                files = list(
                    os.path.normpath(path[len(self.SCHEMA):])
                    for path in remote_files)

                ret = []
                for file in files:
                    self._logger.debug('Copy %s -> %s/', file, dst)
                    shutil.copy(file, dst)
                    ret.append(os.path.join(dst, os.path.basename(file)))
                return ret

        Storage.lookup_provider('eph')._snap_pvd._transfer = TransferMock()

        # Create snapshot strage volume (Remote storage emulation)
        self.vols[1] = Storage.create(device=self.devices[1],
                                      mpoint=self.mpoints[1],
                                      fstype='ext3')
        self.vols[1].mkfs()
        self.vols[1].mount()

        # Create and mount EPH storage
        self.vols[0] = Storage.create(type='eph',
                                      disk=self.devices[0],
                                      vg='casstorage',
                                      snap_backend='%s%s' %
                                      (TransferMock.SCHEMA, self.mpoints[1]),
                                      fstype='ext3',
                                      mpoint=self.mpoints[0])
        self.vols[0].mkfs()
        self.vols[0].mount()

        # Create big file
        bigfile = os.path.join(self.mpoints[0], 'bigfile')
        system(
            ('dd', 'if=/dev/urandom', 'of=%s' % bigfile, 'bs=1M', 'count=15'))
        bigsize = os.path.getsize(bigfile)
        self.assertTrue(bigsize > 0)
        md5sum = system(('/usr/bin/md5sum', bigfile))[0].strip().split(' ')[0]

        # Snapshot storage
        snap = self.vols[0].snapshot(description='Bigfile with us forever')
        self.assertEqual(snap.type, 'eph')
        self.assertEqual(snap.vg, 'casstorage')
        self.assertEqual(snap.state, Snapshot.CREATING)

        wait_until(lambda: snap.state in (Snapshot.COMPLETED, Snapshot.FAILED))
        print snap.config()
        if snap.state == Snapshot.FAILED:
            raise Exception(
                'Snapshot creation failed. See log for more details')

        # Destroy original storage
        self.vols[0].destroy()
        self.vols[0] = None

        # Restore snapshot
        self.vols[2] = Storage.create(disk=self.devices[2], snapshot=snap)
        self.vols[2].mount(self.mpoints[2])
        bigfile2 = os.path.join(self.mpoints[2], 'bigfile')

        self.assertTrue(os.path.exists(bigfile2))

        md5sum2 = system(
            ('/usr/bin/md5sum', bigfile2))[0].strip().split(' ')[0]
        self.assertEqual(md5sum, md5sum2)