def test_db_migration_failure_inside(self): # This tests verify that an exception happeing inside a migration causes the # migration to fail and that on this condition the database results unmodified. def epilogue(self): raise Exception('failure') update_50.MigrationScript.epilogue = epilogue path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'db', 'populated') helpers.init_state() self.db_path = os.path.join(Settings.working_path, 'db') self.final_db_file = os.path.abspath( os.path.join(Settings.working_path, 'globaleaks.db')) set_db_uri('sqlite:' + self.final_db_file) shutil.rmtree(self.db_path, True) os.mkdir(self.db_path) srcdb = os.path.join(path, 'glbackend-49.db') dstdb = os.path.join(Settings.working_path, 'globaleaks.db') shutil.copyfile(srcdb, dstdb) ret = update_db() self.assertEqual(ret, -1) self.assertTrue(filecmp.cmp(srcdb, dstdb))
def _test(self, path, version): f = 'glbackend-%d.db' % version helpers.init_state() self.db_path = os.path.join(Settings.working_path, 'db') self.final_db_file = os.path.abspath( os.path.join(Settings.working_path, 'globaleaks.db')) set_db_uri('sqlite:' + self.final_db_file) shutil.rmtree(self.db_path, True) os.mkdir(self.db_path) dbpath = os.path.join(path, f) if version < 41: dbfile = os.path.join(self.db_path, f) Settings.db_file_path = os.path.join(Settings.working_path, 'db', 'glbackend-%d.db' % version) else: dbfile = os.path.join(Settings.working_path, 'globaleaks.db') shutil.copyfile(dbpath, dbfile) # TESTS PRECONDITIONS preconditions = getattr(self, 'preconditions_%d' % version, None) if preconditions is not None: preconditions() ret = update_db() # TESTS POSTCONDITIONS postconditions = getattr(self, 'postconditions_%d' % version, None) if postconditions is not None: postconditions() self.assertNotEqual(ret, -1)
def eval_paths(self): self.pidfile_path = os.path.join(self.pid_path, 'globaleaks.pid') self.files_path = os.path.abspath(os.path.join(self.working_path, 'files')) self.log_path = os.path.abspath(os.path.join(self.working_path, 'log')) self.attachments_path = os.path.abspath(os.path.join(self.working_path, 'attachments')) self.tmp_path = os.path.abspath(os.path.join(self.working_path, 'tmp')) self.backup_path = os.path.abspath(os.path.join(self.working_path, 'backups')) self.static_db_source = os.path.abspath(os.path.join(self.src_path, 'globaleaks', 'db')) self.db_schema = os.path.join(self.static_db_source, 'sqlite.sql') self.db_file_path = os.path.abspath(os.path.join(self.working_path, 'globaleaks.db')) self.logfile = os.path.abspath(os.path.join(self.log_path, 'globaleaks.log')) self.accesslogfile = os.path.abspath(os.path.join(self.log_path, "access.log")) # If we see that there is a custom build of GLClient, use that one. custom_client_path = '/var/globaleaks/client' if os.path.exists(custom_client_path): self.client_path = custom_client_path self.appdata_file = os.path.join(self.client_path, 'data/appdata.json') self.questionnaires_path = os.path.join(self.client_path, 'data/questionnaires') self.questions_path = os.path.join(self.client_path, 'data/questions') self.field_attrs_file = os.path.join(self.client_path, 'data/field_attrs.json') set_db_uri(make_db_uri(self.db_file_path))
def eval_paths(self): self.pidfile_path = os.path.join(self.working_path, 'globaleaks.pid') self.files_path = os.path.abspath(os.path.join(self.working_path, 'files')) self.log_path = os.path.abspath(os.path.join(self.working_path, 'log')) self.attachments_path = os.path.abspath(os.path.join(self.working_path, 'attachments')) self.tmp_path = os.path.abspath(os.path.join(self.working_path, 'tmp')) self.static_db_source = os.path.abspath(os.path.join(self.src_path, 'globaleaks', 'db')) self.db_schema = os.path.join(self.static_db_source, 'sqlite.sql') self.db_file_path = os.path.abspath(os.path.join(self.working_path, 'globaleaks.db')) self.logfile = os.path.abspath(os.path.join(self.log_path, 'globaleaks.log')) self.accesslogfile = os.path.abspath(os.path.join(self.log_path, "access.log")) # Client path detection possible_client_paths.insert(0, os.path.join(self.working_path, 'client')) for path in possible_client_paths: if os.path.isfile(os.path.join(path, 'index.html')): self.client_path = path break if not self.client_path: print("Unable to find a directory to load the client from") sys.exit(1) self.appdata_file = os.path.join(self.client_path, 'data/appdata.json') self.questionnaires_path = os.path.join(self.client_path, 'data/questionnaires') self.questions_path = os.path.join(self.client_path, 'data/questions') self.field_attrs_file = os.path.join(self.client_path, 'data/field_attrs.json') set_db_uri(make_db_uri(self.db_file_path))
def _test(self, path, version): f = 'glbackend-%d.db' % version helpers.init_state() self.db_path = os.path.join(Settings.working_path, 'db') self.final_db_file = os.path.abspath(os.path.join(Settings.working_path, 'globaleaks.db')) set_db_uri('sqlite:' + self.final_db_file) shutil.rmtree(self.db_path, True) os.mkdir(self.db_path) dbpath = os.path.join(path, f) if version < 41: dbfile = os.path.join(self.db_path, f) Settings.db_file_path = os.path.join(Settings.working_path, 'db', 'glbackend-%d.db' % version) else: dbfile = os.path.join(Settings.working_path, 'globaleaks.db') shutil.copyfile(dbpath, dbfile) # TESTS PRECONDITIONS preconditions = getattr(self, 'preconditions_%d' % version, None) if preconditions is not None: preconditions() ret = update_db() # TESTS POSTCONDITIONS postconditions = getattr(self, 'postconditions_%d' % version, None) if postconditions is not None: postconditions() self.assertNotEqual(ret, -1)