예제 #1
0
    def __enter__(self):
        # This function is synchronized with glance's image creation to
        # provide correct free space computations
        # initialize ceph connection
        rbd_store = rbd_store_driver.Store(CONF)
        ceph_cfg_file = CONF.glance_store.rbd_store_ceph_conf
        with rados.Rados(conffile=ceph_cfg_file) as cluster:
            with cluster.open_ioctx(str(self.pool)) as ioctx:
                # Get quota
                ceph_quota_output = json.loads(
                    cluster.mon_command(
                        json.dumps({
                            "prefix": "osd pool get-quota",
                            "pool": self.pool,
                            "format": "json-pretty"
                        }), "")[1])

                glance_ceph_quota = ceph_quota_output.get("quota_max_bytes", 0)

                rbd_store.validate_available_space(ioctx, self.image_id,
                                                   self.size,
                                                   glance_ceph_quota)

        # Reserve space
        # NOTE: Conversions are done serially therefore we can safely replace
        # the old entry
        with open(DEFAULT_POOL_RESERVATION_FILE, "w+") as f:
            data = {
                "image_id": (self.image_id + '_raw'),
                "reserved": self.size
            }
            f.write(str(data))
        return self
예제 #2
0
    def setUp(self):
        """Establish a clean test environment."""
        super(TestReSize, self).setUp()

        rbd_store.rados = MockRados
        rbd_store.rbd = MockRBD

        self.store = rbd_store.Store(self.conf)
        self.store.configure()
        self.store_specs = {
            'pool': 'fake_pool',
            'image': 'fake_image',
            'snapshot': 'fake_snapshot'
        }
        self.location = rbd_store.StoreLocation(self.store_specs, self.conf)
        self.hash_algo = 'sha256'
    def setUp(self):
        """Establish a clean test environment"""
        super(TestStore, self).setUp()

        rbd_store.rados = MockRados
        rbd_store.rbd = MockRBD

        self.store = rbd_store.Store(self.conf)
        self.store.configure()
        self.store.chunk_size = 2
        self.called_commands_actual = []
        self.called_commands_expected = []
        self.store_specs = {'image': 'fake_image', 'snapshot': 'fake_snapshot'}
        self.location = rbd_store.StoreLocation(self.store_specs)
        # Provide enough data to get more than one chunk iteration.
        self.data_len = 3 * 1024
        self.data_iter = StringIO.StringIO('*' * self.data_len)
예제 #4
0
    def setUp(self):
        """Establish a clean test environment."""
        super(TestStore, self).setUp()

        rbd_store.rados = MockRados
        rbd_store.rbd = MockRBD

        self.store = rbd_store.Store(self.conf)
        self.store.configure()
        self.store.chunk_size = 2
        self.called_commands_actual = []
        self.called_commands_expected = []
        self.store_specs = {'pool': 'fake_pool',
                            'image': 'fake_image',
                            'snapshot': 'fake_snapshot'}
        self.location = rbd_store.StoreLocation(self.store_specs,
                                                self.conf)
        # Provide enough data to get more than one chunk iteration.
        self.data_len = 3 * units.Ki
        self.data_iter = six.BytesIO(b'*' * self.data_len)
        self.hash_algo = 'sha256'
예제 #5
0
    def setUp(self):
        """Establish a clean test environment."""
        super(TestMultiStore, self).setUp()
        enabled_backends = {"ceph1": "rbd", "ceph2": "rbd"}
        self.conf = self._CONF
        self.conf(args=[])
        self.conf.register_opt(cfg.DictOpt('enabled_backends'))
        self.config(enabled_backends=enabled_backends)
        store.register_store_opts(self.conf)
        self.config(default_backend='ceph1', group='glance_store')

        # Ensure stores + locations cleared
        g_location.SCHEME_TO_CLS_BACKEND_MAP = {}

        with mock.patch.object(rbd_store.Store, '_set_url_prefix'):
            store.create_multi_stores(self.conf)

        self.addCleanup(setattr, g_location, 'SCHEME_TO_CLS_BACKEND_MAP',
                        dict())
        self.addCleanup(self.conf.reset)

        rbd_store.rados = MockRados
        rbd_store.rbd = MockRBD

        self.store = rbd_store.Store(self.conf, backend="ceph1")
        self.store.configure()
        self.store.chunk_size = 2
        self.called_commands_actual = []
        self.called_commands_expected = []
        self.store_specs = {
            'pool': 'fake_pool',
            'image': 'fake_image',
            'snapshot': 'fake_snapshot'
        }
        self.location = rbd_store.StoreLocation(self.store_specs, self.conf)
        # Provide enough data to get more than one chunk iteration.
        self.data_len = 3 * units.Ki
        self.data_iter = six.BytesIO(b'*' * self.data_len)
예제 #6
0
    def test_add_w_image_size_zero_to_different_backend(self):
        """Assert that correct size is returned even though 0 was provided."""
        self.store = rbd_store.Store(self.conf, backend="ceph2")
        self.store.configure()
        self.called_commands_actual = []
        self.called_commands_expected = []
        self.store_specs = {'pool': 'fake_pool_1',
                            'image': 'fake_image_1',
                            'snapshot': 'fake_snapshot_1'}
        self.location = rbd_store.StoreLocation(self.store_specs,
                                                self.conf)
        # Provide enough data to get more than one chunk iteration.
        self.data_len = 3 * units.Ki
        self.data_iter = six.BytesIO(b'*' * self.data_len)
        self.store.chunk_size = units.Ki
        with mock.patch.object(rbd_store.rbd.Image, 'resize') as resize:
            with mock.patch.object(rbd_store.rbd.Image, 'write') as write:
                ret = self.store.add('fake_image_id', self.data_iter, 0)

                self.assertTrue(resize.called)
                self.assertTrue(write.called)
                self.assertEqual(ret[1], self.data_len)
                self.assertEqual("ceph2", ret[3]['backend'])