Esempio n. 1
0
    def __init__(self, instance=None, disk_name=None, path=None, **kwargs):
        if not CONF.libvirt.images_rbd_pool:
            raise RuntimeError(
                _('You should specify'
                  ' images_rbd_pool'
                  ' flag to use rbd images.'))

        if path:
            try:
                self.rbd_name = path.split('/')[1]
            except IndexError:
                raise exception.InvalidDevicePath(path=path)
        else:
            self.rbd_name = '%s_%s' % (instance.uuid, disk_name)

        self.pool = CONF.libvirt.images_rbd_pool
        self.rbd_user = CONF.libvirt.rbd_user
        self.ceph_conf = CONF.libvirt.images_rbd_ceph_conf

        path = 'rbd:%s/%s' % (self.pool, self.rbd_name)
        if self.rbd_user:
            path += ':id=' + self.rbd_user
        if self.ceph_conf:
            path += ':conf=' + self.ceph_conf

        super(Rbd, self).__init__(path, "block", "rbd", is_block_dev=False)

        self.driver = rbd_utils.RBDDriver(pool=self.pool,
                                          ceph_conf=self.ceph_conf,
                                          rbd_user=self.rbd_user)

        self.discard_mode = CONF.libvirt.hw_disk_discard
Esempio n. 2
0
    def setUp(self):
        super(RbdTestCase, self).setUp()

        self.rbd_pool = 'rbd'
        self.rbd_connect_timeout = 5
        self.flags(images_rbd_pool=self.rbd_pool, group='libvirt')
        self.flags(rbd_connect_timeout=self.rbd_connect_timeout,
                    group='libvirt')

        rados_patcher = mock.patch.object(rbd_utils, 'rados')
        self.mock_rados = rados_patcher.start()
        self.addCleanup(rados_patcher.stop)
        self.mock_rados.Rados = mock.Mock
        self.mock_rados.Rados.ioctx = mock.Mock()
        self.mock_rados.Rados.connect = mock.Mock()
        self.mock_rados.Rados.shutdown = mock.Mock()
        self.mock_rados.Rados.open_ioctx = mock.Mock()
        self.mock_rados.Rados.open_ioctx.return_value = \
            self.mock_rados.Rados.ioctx
        self.mock_rados.Error = Exception

        rbd_patcher = mock.patch.object(rbd_utils, 'rbd')
        self.mock_rbd = rbd_patcher.start()
        self.addCleanup(rbd_patcher.stop)
        self.mock_rbd.RBD = mock.Mock()
        self.mock_rbd.Image = mock.Mock()
        self.mock_rbd.Image.close = mock.Mock()
        self.mock_rbd.Error = Exception
        self.mock_rbd.ImageBusy = FakeException
        self.mock_rbd.ImageHasSnapshots = FakeException

        self.driver = rbd_utils.RBDDriver()

        self.volume_name = u'volume-00000001'
        self.snap_name = u'test-snap'
Esempio n. 3
0
    def setUp(self, mock_rados, mock_rbd):
        super(RbdTestCase, self).setUp()

        self.mock_rados = mock_rados
        self.mock_rados.Rados = mock.Mock
        self.mock_rados.Rados.ioctx = mock.Mock()
        self.mock_rados.Rados.connect = mock.Mock()
        self.mock_rados.Rados.shutdown = mock.Mock()
        self.mock_rados.Rados.open_ioctx = mock.Mock()
        self.mock_rados.Rados.open_ioctx.return_value = \
            self.mock_rados.Rados.ioctx
        self.mock_rados.Error = Exception

        self.mock_rbd = mock_rbd
        self.mock_rbd.RBD = mock.Mock
        self.mock_rbd.Image = mock.Mock
        self.mock_rbd.Image.close = mock.Mock()
        self.mock_rbd.RBD.Error = Exception

        self.rbd_pool = 'rbd'
        self.driver = rbd_utils.RBDDriver(self.rbd_pool, None, None)

        self.volume_name = u'volume-00000001'