Example #1
0
 def testPatchDatabaseWithoutSchema(self):
     """L{patchDatabase} creates a schema if one isn't already in place."""
     schema = createSchema(self.patchPackage)
     self.assertRaises(OperationalError, self.store.execute,
                       'SELECT * FROM patch')
     patchDatabase(self.store, schema)
     self.assertEqual([], list(self.store.execute('SELECT * FROM patch')))
Example #2
0
 def run(self, path, database_uri, old_format=None):
     setupLogging(self.outf)
     store = setupStore(database_uri, 'logs')
     schema = logs.createSchema()
     logging.info('Creating schema')
     patchDatabase(store, schema)
     logging.info('Loading trace logs from %s', path)
     loadTraceLogs(path, store, old_format)
     logging.info('Finished loading trace logs from %s', path)
Example #3
0
 def run(self, path, database_uri):
     setupLogging(self.outf)
     store = setupStore(database_uri, 'logs')
     schema = logs.createSchema()
     logging.info('Creating schema')
     patchDatabase(store, schema)
     logging.info('Loading log file %s', path)
     loadLogs(path, store)
     logging.info('Finished loading log file %s', path)
Example #4
0
 def testPatchDatabaseWithoutPatches(self):
     """
     L{patchDatabase} is basically a no-op if no patches are available.
     """
     schema = createSchema(self.patchPackage)
     patchDatabase(self.store, schema)
     self.assertEqual([], list(self.store.execute('SELECT * FROM patch')))
     patchDatabase(self.store, schema)
     self.assertEqual([], list(self.store.execute('SELECT * FROM patch')))
Example #5
0
 def run(self, path, database_uri, old_format=None):
     setupLogging(self.outf)
     store = setupStore(database_uri, 'logs')
     schema = logs.createSchema()
     logging.info('Creating schema')
     patchDatabase(store, schema)
     logging.info('Loading trace logs from %s', path)
     loadTraceLogs(path, store, old_format)
     logging.info('Finished loading trace logs from %s', path)
Example #6
0
 def run(self, path, database_uri):
     setupLogging(self.outf)
     store = setupStore(database_uri, 'logs')
     schema = logs.createSchema()
     logging.info('Creating schema')
     patchDatabase(store, schema)
     logging.info('Loading log file %s', path)
     loadLogs(path, store)
     logging.info('Finished loading log file %s', path)
Example #7
0
 def run(self, database_uri):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     store = setupStore(database_uri, 'main')
     schema = main.createSchema()
     logging.info('Creating schema.')
     patchDatabase(store, schema)
     logging.info('Creating system data.')
     bootstrapSystemData(store)
     logging.info('Creating web admin data.')
     bootstrapWebAdminData()
Example #8
0
 def testGetPatchStatusWithUnknownPatches(self):
     """
     L{getPatchStatus} returns information about patch versions that exist
     in the database, but not in the code base.
     """
     schema = createSchema(self.patchPackage)
     patchDatabase(self.store, schema)
     self.store.execute('INSERT INTO patch (version) VALUES (1)')
     status = getPatchStatus(self.store, schema)
     self.assertEqual([], status.unappliedPatches)
     self.assertEqual([1], status.unknownPatches)
Example #9
0
 def run(self, database_uri):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     store = setupStore(database_uri, 'main')
     schema = main.createSchema()
     logging.info('Creating schema.')
     patchDatabase(store, schema)
     logging.info('Creating system data.')
     bootstrapSystemData(store)
     logging.info('Creating web admin data.')
     bootstrapWebAdminData()
Example #10
0
 def testGetPatchStatus(self):
     """
     L{getPatchStatus} returns a L{PatchStatus} with information about
     outstanding and unknown patches.  If the database is up-to-date and no
     unknown patches have been applied to it, both of these values are
     empty C{list}s.
     """
     schema = createSchema(self.patchPackage)
     patchDatabase(self.store, schema)
     status = getPatchStatus(self.store, schema)
     self.assertEqual([], status.unappliedPatches)
     self.assertEqual([], status.unknownPatches)
Example #11
0
 def testPatchDatabaseWithoutUnappliedPatches(self):
     """L{patchDatabase} only applies unapplied patches."""
     schema = createSchema(self.patchPackage)
     patchDatabase(self.store, schema)
     self.packageBuilder.createModule('patch_1', dedent("""\
         def apply(store):
             store.execute('INSERT INTO person (name) VALUES (\\'Bob\\')')
         """))
     self.store.execute('INSERT INTO patch (version) VALUES (1)')
     patchDatabase(self.store, schema)
     self.assertEqual([(1,)],
                      list(self.store.execute('SELECT * FROM patch')))
     self.assertEqual([], list(self.store.execute('SELECT * FROM person')))
Example #12
0
 def testGetPatchStatusWithUnappliedPatches(self):
     """
     L{getPatchStatus} returns information about patch versions that need
     to be applied to a database to make it up-to-date with the code base.
     """
     schema = createSchema(self.patchPackage)
     patchDatabase(self.store, schema)
     self.packageBuilder.createModule('patch_1', dedent("""\
         def apply(store):
             store.execute('INSERT INTO person (name) VALUES (\\'Bob\\')')
         """))
     status = getPatchStatus(self.store, schema)
     self.assertEqual([1], status.unappliedPatches)
     self.assertEqual([], status.unknownPatches)
Example #13
0
 def testPatchDatabase(self):
     """
     L{patchDatabase} applies all outstanding patches.  The C{patch} table
     contains a row for every patch version that has been applied to the
     database.
     """
     schema = createSchema(self.patchPackage)
     patchDatabase(self.store, schema)
     self.packageBuilder.createModule('patch_1', dedent("""\
         def apply(store):
             store.execute('INSERT INTO person (name) VALUES (\\'Bob\\')')
         """))
     patchDatabase(self.store, schema)
     self.assertEqual([(1,)],
                      list(self.store.execute('SELECT * FROM patch')))
     self.assertEqual([('Bob',)],
                      list(self.store.execute('SELECT * FROM person')))
Example #14
0
 def run(self, database_uri):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     store = setupStore(database_uri, 'main')
     schema = main.createSchema()
     status = getPatchStatus(store, schema)
     if status.unknownPatches:
         unknownPatches = ', '.join(
             'patch_%d' % version for version in status.unknownPatches)
         logging.critical('Database has unknown patches: %s',
                          unknownPatches)
         return 1
     if status.unappliedPatches:
         unappliedPatches = ', '.join(
             'patch_%d' % version for version in status.unappliedPatches)
         logging.info('Applying patches: %s', unappliedPatches)
         patchDatabase(store, schema)
     else:
         logging.info('Database is up-to-date.')
Example #15
0
 def run(self, database_uri):
     setConfig(setupConfig(None))
     setupLogging(self.outf)
     store = setupStore(database_uri, 'main')
     schema = main.createSchema()
     status = getPatchStatus(store, schema)
     if status.unknownPatches:
         unknownPatches = ', '.join('patch_%d' % version
                                    for version in status.unknownPatches)
         logging.critical('Database has unknown patches: %s',
                          unknownPatches)
         return 1
     if status.unappliedPatches:
         unappliedPatches = ', '.join(
             'patch_%d' % version for version in status.unappliedPatches)
         logging.info('Applying patches: %s', unappliedPatches)
         patchDatabase(store, schema)
     else:
         logging.info('Database is up-to-date.')