Beispiel #1
0
 def test_manage_getMountStatus(self):
     status = manage_getMountStatus(self.app)
     expected = [{'status': 'Ok',
                  'path': '/mount1',
                  'name': 'test_mount1.fs',
                  'exists': 1},
                 {'status': 'Ok',
                  'path': '/mount2',
                  'name': 'test_mount2.fs',
                  'exists': 1}]
     self.assertEqual(expected, status)
     del self.app.mount2
     status = manage_getMountStatus(self.app)
     expected = [{'status': 'Ok',
                  'path': '/mount1',
                  'name': 'test_mount1.fs',
                  'exists': 1},
                 {'status': 'Ready to create',
                  'path': '/mount2',
                  'name': 'test_mount2.fs',
                  'exists': 0}]
     self.assertEqual(expected, status)
     self.app.mount2 = Folder('mount2')
     status = manage_getMountStatus(self.app)
     expected = [{'status': 'Ok',
                  'path': '/mount1',
                  'name': 'test_mount1.fs',
                  'exists': 1},
                 {'status': '** Something is in the way **',
                  'path': '/mount2',
                  'name': 'test_mount2.fs',
                  'exists': 1}]
     self.assertEqual(expected, status)
    def test_manage_getMountStatus(self):
        status = manage_getMountStatus(self.app)
        name_sort = operator.itemgetter('name')
        expected = [{'status': 'Ok',
                     'path': '/mount1',
                     'name': 'test_mount1.fs',
                     'exists': 1},
                    {'status': 'Ok',
                     'path': '/mount2',
                     'name': 'test_mount2.fs',
                     'exists': 1},
                    {'status': 'Ok',
                     'path': '/i/mount3',
                     'name': 'test_mount3.fs',
                     'exists': 1},
                    ]
        self.assertEqual(sorted(expected, key=name_sort),
                         sorted(status, key=name_sort))
        del self.app.mount2
        status = manage_getMountStatus(self.app)
        expected = [{'status': 'Ok',
                     'path': '/mount1',
                     'name': 'test_mount1.fs',
                     'exists': 1},
                    {'status': 'Ready to create',
                     'path': '/mount2',
                     'name': 'test_mount2.fs',
                     'exists': 0},
                    {'status': 'Ok',
                     'path': '/i/mount3',
                     'name': 'test_mount3.fs',
                     'exists': 1},

                    ]
        self.assertEqual(sorted(expected, key=name_sort),
                         sorted(status, key=name_sort))
        self.app.mount2 = Folder('mount2')
        status = manage_getMountStatus(self.app)
        expected = [{'status': 'Ok',
                     'path': '/mount1',
                     'name': 'test_mount1.fs',
                     'exists': 1},
                    {'status': '** Something is in the way **',
                     'path': '/mount2',
                     'name': 'test_mount2.fs',
                     'exists': 1},
                    {'status': 'Ok',
                     'path': '/i/mount3',
                     'name': 'test_mount3.fs',
                     'exists': 1},
                    ]
        self.assertEqual(sorted(expected, key=name_sort),
                         sorted(status, key=name_sort))
def prepare_mountpoint(app, path):
    for mountpoint in manage_getMountStatus(app):
        if mountpoint["path"] == path:
            break
    else:
        raise zc.buildout.UserError('That mountpoint does not exist in zope.conf')

    if mountpoint["status"] == "** Something is in the way **":
        raise zc.buildout.UserError("The current filestorage has an obstruction prevent use of the ZODB Mount '%s'!" % path)

    elif mountpoint["status"] == "Ready to create":
        manage_addMounts(app, (path, ))
        print "Created mount point '%s'" % path

    elif mountpoint["status"] == "Ok":
        print "Mount point '%s' is Ok, nothing to update"

    else:
        raise zc.buildout.UserError("Mountpoint '%s' is '%s' - that is an unknown state, buildout cant continue" % (path, mountpoint["status"]))

    # Traverse from the root to wherever the mountpoint is, return that as the place the
    # plone site will be created
    retval = app
    for part in path.split("/"):
        if not part:
            continue
        retval = app[part]

    return retval
def mount(self, out=None):
    """ Mount catalogs
    """
    if out is None:
        out = StringIO()

    to_mount = manage_getMountStatus(self)
    items = [item for item in to_mount if 'catalog' in item['path']
                  and '** Something is in the way **' in item['status']]

    msg = 'Mounting... %s catalogs' % len(items)
    logger.warn(msg)
    out.write(msg)

    for item in items:
        path = item['path']
        logger.info('Mounting %s', path)
        oid = path.split('/')[-1]
        old_obj = self.unrestrictedTraverse(path)
        old_parent = old_obj.aq_parent.aq_base
        db_name = item['name']
        db = getConfiguration().dbtab.getDatabase(path)
        new_trans = db.open()

        root = new_trans.root()
        if not root.has_key('Application'):
            from OFS.Application import Application
            root['Application'] = Application()
            transaction.savepoint(optimistic=True)

        root = root['Application']

        f = tempfile.TemporaryFile()
        old_obj._p_jar.exportFile(old_obj._p_oid, f)
        f.seek(0)

        new_obj = root._p_jar.importFile(f)
        f.close()

        blazer = CustomTrailblazer(root)
        obj = blazer.traverseOrConstruct(path)
        obj.aq_parent._setOb(oid, new_obj)

        mo = MountedObject(path)
        mo._create_mount_points = True

        old_parent._p_jar.add(mo)
        old_parent._setOb(oid, mo)
        setMountPoint(old_parent, oid, mo)
        msg = "Path: %s, mounted to db:%s" % (path, db_name)
        logger.warn(msg)
        out.write(msg)

        msg = ("Done mounting 1 catalog. Breaking. "
               "Please rerun this until all catalogs are mounted")
        logger.warn(msg)
        out.write(msg)
        break

    return out.getvalue()
Beispiel #5
0
 def test_manage_getMountStatus(self):
     status = manage_getMountStatus(self.app)
     expected = [{
         'status': 'Ok',
         'path': '/mount1',
         'name': 'test_mount1.fs',
         'exists': 1
     }, {
         'status': 'Ok',
         'path': '/mount2',
         'name': 'test_mount2.fs',
         'exists': 1
     }]
     self.assertEqual(expected, status)
     del self.app.mount2
     status = manage_getMountStatus(self.app)
     expected = [{
         'status': 'Ok',
         'path': '/mount1',
         'name': 'test_mount1.fs',
         'exists': 1
     }, {
         'status': 'Ready to create',
         'path': '/mount2',
         'name': 'test_mount2.fs',
         'exists': 0
     }]
     self.assertEqual(expected, status)
     self.app.mount2 = Folder('mount2')
     status = manage_getMountStatus(self.app)
     expected = [{
         'status': 'Ok',
         'path': '/mount1',
         'name': 'test_mount1.fs',
         'exists': 1
     }, {
         'status': '** Something is in the way **',
         'path': '/mount2',
         'name': 'test_mount2.fs',
         'exists': 1
     }]
     self.assertEqual(expected, status)
 def test_manage_getMountStatus(self):
     status = manage_getMountStatus(self.app)
     name_sort = operator.itemgetter('name')
     expected = [
         {
             'status': 'Ok',
             'path': '/mount1',
             'name': 'test_mount1.fs',
             'exists': 1
         },
         {
             'status': 'Ok',
             'path': '/mount2',
             'name': 'test_mount2.fs',
             'exists': 1
         },
         {
             'status': 'Ok',
             'path': '/i/mount3',
             'name': 'test_mount3.fs',
             'exists': 1
         },
     ]
     self.assertEqual(sorted(expected, key=name_sort),
                      sorted(status, key=name_sort))
     del self.app.mount2
     status = manage_getMountStatus(self.app)
     expected = [
         {
             'status': 'Ok',
             'path': '/mount1',
             'name': 'test_mount1.fs',
             'exists': 1
         },
         {
             'status': 'Ready to create',
             'path': '/mount2',
             'name': 'test_mount2.fs',
             'exists': 0
         },
         {
             'status': 'Ok',
             'path': '/i/mount3',
             'name': 'test_mount3.fs',
             'exists': 1
         },
     ]
     self.assertEqual(sorted(expected, key=name_sort),
                      sorted(status, key=name_sort))
     self.app.mount2 = Folder('mount2')
     status = manage_getMountStatus(self.app)
     expected = [
         {
             'status': 'Ok',
             'path': '/mount1',
             'name': 'test_mount1.fs',
             'exists': 1
         },
         {
             'status': '** Something is in the way **',
             'path': '/mount2',
             'name': 'test_mount2.fs',
             'exists': 1
         },
         {
             'status': 'Ok',
             'path': '/i/mount3',
             'name': 'test_mount3.fs',
             'exists': 1
         },
     ]
     self.assertEqual(sorted(expected, key=name_sort),
                      sorted(status, key=name_sort))
def migrate_mount_points(portal):
    # Based on a script by Andrew Mleczko
    # http://plone.org/documentation/kb/migrating-an-existing-catalog-in-a-new-zodb

    portal_path = portal.absolute_url_path() + "/"

    for mp in manage_getMountStatus(portal):
        if not mp['path'].startswith(portal_path):
            continue

        if not '** Something is in the way **' in mp['status']:
            continue

        print "Migrating '%s' to seperate ZODB storage" % mp['path']

        path = mp['path']
        id = path.split("/")[-1]

        # Existing objects
        old_obj = portal.unrestrictedTraverse(path)
        old_parent = old_obj.aq_parent.aq_base

        # New storage from the item
        db_name = mp['name']
        db = getConfiguration().dbtab.getDatabase(path)
        new_trans = db.open()

        # Try to get the root of the new storage
        root_dict = new_trans.root()
        if not root_dict.has_key('Application'):
            from OFS.Application import Application
            root_dict['Application'] = Application()
            transaction.savepoint(optimistic=True)

        # Verify there nothing in the way
        root = root_dict['Application']
        if id in root:
            print "  Cleaning target ZODB storage"
            root.manage_delObjects([id])

        print "  Exporting current state..."
        f = tempfile.TemporaryFile()
        old_obj._p_jar.exportFile(old_obj._p_oid, f)
        f.seek(0)

        print "  Importing into new external ZODB storage..."
        new_obj = root._p_jar.importFile(f)
        f.close()
        transaction.savepoint(optimistic=True)

        print "  Set the new object in the new storage..."
        blazer = CustomTrailblazer(root)
        obj = blazer.traverseOrConstruct(path)
        obj.aq_parent._setOb(id, new_obj)

        print "  Activating the new external storage..."
        mo = MountedObject(path)
        mo._create_mount_points = True

        old_parent._p_jar.add(mo)
        old_parent._setOb(id, mo)
        setMountPoint(old_parent, id, mo)

        transaction.savepoint(optimistic=True)

    transaction.commit()