def test_volxml_get_notfound_fallback(self, default):
        xmlout = mock.Mock()
        xmlout.find = mock.Mock(return_value=None)

        ret = common.volxml_get(xmlout, 'some/path', default)

        self.assertEqual(default, ret)
Example #2
0
    def test_volxml_get_notfound_fallback(self, default):
        xmlout = mock.Mock()
        xmlout.find = mock.Mock(return_value=None)

        ret = common.volxml_get(xmlout, 'some/path', default=default)

        self.assertEqual(default, ret)
    def test_volxml_get(self):
        xmlout = mock.Mock()
        value = mock.Mock()
        value.text = 'foobar'
        xmlout.find = mock.Mock(return_value=value)

        ret = common.volxml_get(xmlout, 'some/path')

        self.assertEqual('foobar', ret)
Example #4
0
    def test_volxml_get(self):
        xmlout = mock.Mock()
        value = mock.Mock()
        value.text = 'foobar'
        xmlout.find = mock.Mock(return_value=value)

        ret = common.volxml_get(xmlout, 'some/path')

        self.assertEqual('foobar', ret)
Example #5
0
    def test_volxml_get_multiple(self):
        xmlout = mock.Mock()
        value = mock.Mock()
        value.text = 'foobar'
        xmlout.find = mock.Mock(side_effect=(None, value))

        ret = common.volxml_get(xmlout, 'some/path', 'better/path')

        self.assertEqual('foobar', ret)
Example #6
0
    def create_snapshot(self, context, snapshot, share_server=None):
        """Creates a snapshot."""

        gluster_mgr = self._share_manager(snapshot['share'])
        if gluster_mgr.qualified in self.gluster_nosnap_vols_dict:
            opret, operrno = -1, 0
            operrstr = self.gluster_nosnap_vols_dict[gluster_mgr.qualified]
        else:
            args = ('--xml', 'snapshot', 'create', 'manila-' + snapshot['id'],
                    gluster_mgr.volume)
            out, err = gluster_mgr.gluster_call(*args,
                                                log=("Retrieving volume info"))

            if not out:
                raise exception.GlusterfsException(
                    'gluster volume info %s: no data received' %
                    gluster_mgr.volume)

            outxml = etree.fromstring(out)
            opret = int(common.volxml_get(outxml, 'opRet'))
            operrno = int(common.volxml_get(outxml, 'opErrno'))
            operrstr = common.volxml_get(outxml, 'opErrstr', default=None)

        if opret == -1:
            vers = self.glusterfs_versions[gluster_mgr.host_access]
            if common.numreduct(vers) > (3, 6):
                # This logic has not yet been implemented in GlusterFS 3.6
                if operrno == 0:
                    self.gluster_nosnap_vols_dict[
                        gluster_mgr.qualified] = operrstr
                    msg = _("Share %(share_id)s does not support snapshots: "
                            "%(errstr)s.") % {
                                'share_id': snapshot['share_id'],
                                'errstr': operrstr
                            }
                    LOG.error(msg)
                    raise exception.ShareSnapshotNotSupported(msg)
            raise exception.GlusterfsException(
                _("Creating snapshot for share %(share_id)s failed "
                  "with %(errno)d: %(errstr)s") % {
                      'share_id': snapshot['share_id'],
                      'errno': operrno,
                      'errstr': operrstr
                  })
Example #7
0
    def create_snapshot(self, context, snapshot, share_server=None):
        """Creates a snapshot."""

        gluster_mgr = self._share_manager(snapshot['share'])
        if gluster_mgr.qualified in self.gluster_nosnap_vols_dict:
            opret, operrno = -1, 0
            operrstr = self.gluster_nosnap_vols_dict[gluster_mgr.qualified]
        else:
            args = ('--xml', 'snapshot', 'create', 'manila-' + snapshot['id'],
                    gluster_mgr.volume)
            out, err = gluster_mgr.gluster_call(
                *args,
                log=("Retrieving volume info"))

            if not out:
                raise exception.GlusterfsException(
                    'gluster volume info %s: no data received' %
                    gluster_mgr.volume
                )

            outxml = etree.fromstring(out)
            opret = int(common.volxml_get(outxml, 'opRet'))
            operrno = int(common.volxml_get(outxml, 'opErrno'))
            operrstr = common.volxml_get(outxml, 'opErrstr', default=None)

        if opret == -1:
            vers = self.glusterfs_versions[gluster_mgr.host_access]
            if common.numreduct(vers) > (3, 6):
                # This logic has not yet been implemented in GlusterFS 3.6
                if operrno == 0:
                    self.gluster_nosnap_vols_dict[
                        gluster_mgr.qualified] = operrstr
                    msg = _("Share %(share_id)s does not support snapshots: "
                            "%(errstr)s.") % {'share_id': snapshot['share_id'],
                                              'errstr': operrstr}
                    LOG.error(msg)
                    raise exception.ShareSnapshotNotSupported(msg)
            raise exception.GlusterfsException(
                _("Creating snapshot for share %(share_id)s failed "
                  "with %(errno)d: %(errstr)s") % {
                      'share_id': snapshot['share_id'],
                      'errno': operrno,
                      'errstr': operrstr})