Example #1
0
    def test_delete_data_isolated(self):
        self.mock_object(
            share_types, 'get_share_type_extra_specs',
            mock.Mock(return_value={"cephfs:data_isolated": True}))

        self._driver.delete_share(self._context, self._share)

        self._driver._volume_client.delete_volume.assert_called_once_with(
            driver.cephfs_share_path(self._share), data_isolated=True)
        self._driver._volume_client.purge_volume.assert_called_once_with(
            driver.cephfs_share_path(self._share), data_isolated=True)
Example #2
0
    def test_shrink_share(self):
        new_size_gb = self._share['size'] * 0.5
        new_size = new_size_gb * units.Gi

        self._driver.shrink_share(self._share, new_size_gb, None)

        self._driver._volume_client.get_used_bytes.assert_called_once_with(
            driver.cephfs_share_path(self._share))
        self._driver._volume_client.set_max_bytes.assert_called_once_with(
            driver.cephfs_share_path(self._share),
            new_size)
Example #3
0
    def test_deny_access(self):
        vc = self._native_protocol_helper.volume_client
        self._native_protocol_helper._deny_access(self._context, self._share, {
            'access_level': 'rw',
            'access_type': 'cephx',
            'access_to': 'alice'
        })

        vc.deauthorize.assert_called_once_with(
            driver.cephfs_share_path(self._share), "alice")
        vc.evict.assert_called_once_with(
            "alice", volume_path=driver.cephfs_share_path(self._share))
Example #4
0
    def test_ensure_share(self):
        self._driver.ensure_share(self._context, self._share)

        self._driver._volume_client.create_volume.assert_called_once_with(
            driver.cephfs_share_path(self._share),
            size=self._share['size'] * units.Gi,
            data_isolated=False)
Example #5
0
    def test_extend_share(self):
        new_size_gb = self._share['size'] * 2
        new_size = new_size_gb * units.Gi

        self._driver.extend_share(self._share, new_size_gb, None)

        self._driver._volume_client.set_max_bytes.assert_called_once_with(
            driver.cephfs_share_path(self._share), new_size)
Example #6
0
    def test_delete_snapshot(self):
        self._driver.delete_snapshot(self._context, {
            "id": "instance1",
            "share": self._share,
            "snapshot_id": "snappy1"
        }, None)

        (self._driver._volume_client.destroy_snapshot_volume.
         assert_called_once_with(driver.cephfs_share_path(self._share),
                                 "snappy1_instance1"))
Example #7
0
    def test_create_share(self):
        cephfs_volume = {"mount_path": "/foo/bar"}

        self._driver.create_share(self._context, self._share)

        self._driver._volume_client.create_volume.assert_called_once_with(
            driver.cephfs_share_path(self._share),
            size=self._share['size'] * units.Gi,
            data_isolated=False)
        (self._driver.protocol_helper.get_export_locations.
         assert_called_once_with(self._share, cephfs_volume))
Example #8
0
    def test_create_snapshot(self):
        self._driver.create_snapshot(self._context, {
            "id": "instance1",
            "share": self._share,
            "snapshot_id": "snappy1"
        }, None)

        (self._driver._volume_client.create_snapshot_volume.
         assert_called_once_with(driver.cephfs_share_path(self._share),
                                 "snappy1_instance1",
                                 mode=DEFAULT_VOLUME_MODE))
Example #9
0
    def test_allow_access_rw(self, volume_client_version):
        vc = self._native_protocol_helper.volume_client
        rule = {
            'access_level': constants.ACCESS_LEVEL_RW,
            'access_to': 'alice',
            'access_type': 'cephx',
        }
        vc.version = volume_client_version

        auth_key = self._native_protocol_helper._allow_access(
            self._context, self._share, rule)

        self.assertEqual("abc123", auth_key)

        if not volume_client_version:
            vc.authorize.assert_called_once_with(
                driver.cephfs_share_path(self._share), "alice")
        else:
            vc.authorize.assert_called_once_with(
                driver.cephfs_share_path(self._share), "alice",
                readonly=False, tenant_id=self._share['project_id'])
Example #10
0
    def test_create_data_isolated(self):
        self.mock_object(
            share_types, 'get_share_type_extra_specs',
            mock.Mock(return_value={"cephfs:data_isolated": True}))

        self._driver.create_share(self._context, self._share)

        self._driver._volume_client.create_volume.assert_called_once_with(
            driver.cephfs_share_path(self._share),
            size=self._share['size'] * units.Gi,
            data_isolated=True,
            mode=DEFAULT_VOLUME_MODE)
Example #11
0
    def test_update_access_all(self, volume_client_version):
        vc = self._native_protocol_helper.volume_client
        alice = {
            'id': 'instance_mapping_id1',
            'access_id': 'accessid1',
            'access_level': 'rw',
            'access_type': 'cephx',
            'access_to': 'alice'
        }
        vc.version = volume_client_version

        access_updates = self._native_protocol_helper.update_access(
            self._context,
            self._share,
            access_rules=[alice],
            add_rules=[],
            delete_rules=[])

        self.assertEqual({'accessid1': {
            'access_key': 'abc123'
        }}, access_updates)

        if volume_client_version:
            vc.get_authorized_ids.assert_called_once_with(
                driver.cephfs_share_path(self._share))
            vc.authorize.assert_called_once_with(
                driver.cephfs_share_path(self._share),
                "alice",
                readonly=False,
                tenant_id=self._share['project_id'])
            vc.deauthorize.assert_called_once_with(
                driver.cephfs_share_path(self._share), "eve")
        else:
            self.assertFalse(vc.get_authorized_ids.called)
            vc.authorize.assert_called_once_with(
                driver.cephfs_share_path(self._share), "alice")
Example #12
0
    def test_allow_access_ro(self, volume_client_version):
        vc = self._native_protocol_helper.volume_client
        rule = {
            'access_level': constants.ACCESS_LEVEL_RO,
            'access_to': 'alice',
            'access_type': 'cephx',
        }
        vc.version = volume_client_version

        if not volume_client_version:
            self.assertRaises(exception.InvalidShareAccessLevel,
                              self._native_protocol_helper._allow_access,
                              self._context, self._share, rule)
        else:
            auth_key = (self._native_protocol_helper._allow_access(
                self._context, self._share, rule))

            self.assertEqual("abc123", auth_key)
            vc.authorize.assert_called_once_with(
                driver.cephfs_share_path(self._share),
                "alice",
                readonly=True,
                tenant_id=self._share['project_id'])