def testUTF16Change(self): # Create changes.pck cm = OldChangeMaster() cm.changes = [ Change(who=u"Frosty the \N{SNOWMAN}".encode("utf16"), files=["foo"], comments=u"Frosty the \N{SNOWMAN}".encode("utf16"), branch="b1", revision=12345) ] # instead of running contrib/fix_changes_pickle_encoding.py, we just call # the changemanager's recode_changes directly - it's the function at the # heart of the script anyway. cm.recode_changes('utf16', quiet=True) # and dump the recoded changemanager to changes.pck before trying a schema upgrade cPickle.dump(cm, open(os.path.join(self.basedir, "changes.pck"), "w")) sm = manager.DBSchemaManager(self.spec, self.basedir) sm.upgrade(quiet=True) c = self.db.getChangeNumberedNow(1) self.assertEquals(c.who, u"Frosty the \N{SNOWMAN}") self.assertEquals(c.comments, u"Frosty the \N{SNOWMAN}")
def setUp(self): self.basedir = "DBSchemaManager" if os.path.exists(self.basedir): shutil.rmtree(self.basedir) os.makedirs(self.basedir) self.spec = dbspec.DBSpec.from_url("sqlite:///state.sqlite", self.basedir) self.sm = manager.DBSchemaManager(self.spec, self.basedir)
def create_db(self): from buildbot.db import dbspec, exceptions spec = dbspec.DBSpec.from_url(self.config["db"], self.basedir) if not self.config['quiet']: print "creating database" # upgrade from "nothing" from buildbot.db.schema import manager sm = manager.DBSchemaManager(spec, self.basedir) if sm.get_db_version() != 0: raise exceptions.DBAlreadyExistsError sm.upgrade()
def setUp(self): self.basedir = "ChangeProperties" if os.path.exists(self.basedir): shutil.rmtree(self.basedir) os.makedirs(self.basedir) self.spec = DBSpec.from_url("sqlite:///state.sqlite", self.basedir) self.sm = manager.DBSchemaManager(self.spec, self.basedir) self.sm.upgrade(quiet=True) self.db = DBConnector(self.spec) self.db.start()
def testNonUnicodeChange(self): # Create changes.pck changes = [ Change(who="\xff\xff\x00", files=["foo"], comments="\xff\xff\x00", branch="b1", revision=12345) ] cPickle.dump(Thing(changes=changes), open(os.path.join(self.basedir, "changes.pck"), "w")) sm = manager.DBSchemaManager(self.spec, self.basedir) self.assertRaises(UnicodeError, lambda: sm.upgrade(quiet=True))
def setUp(self): self.basedir = "MySQLDBSchemaManager" if os.path.exists(self.basedir): shutil.rmtree(self.basedir) os.makedirs(self.basedir) self.spec = dbspec.DBSpec.from_url( "mysql://*****:*****@localhost/buildbot_test") # Drop all previous tables cur = self.spec.get_sync_connection().cursor() cur.execute("SHOW TABLES") for row in cur.fetchall(): cur.execute("DROP TABLE %s" % row[0]) cur.execute("COMMIT") self.sm = manager.DBSchemaManager(self.spec, self.basedir)
def testListsAsFilenames(self): # Create changes.pck changes = [ Change(who=u"Frosty the \N{SNOWMAN}".encode("utf8"), files=[["foo", "bar"], ['bing']], comments=u"Frosty the \N{SNOWMAN}".encode("utf8"), branch="b1", revision=12345) ] cPickle.dump(self.mkchanges(changes), open(os.path.join(self.basedir, "changes.pck"), "wb")) sm = manager.DBSchemaManager(self.spec, self.basedir) sm.upgrade(quiet=True) c = self.db.getChangeNumberedNow(1) self.assertEquals(sorted(c.files), sorted([u"foo", u"bar", u"bing"]))
def testAsciiChange(self): # Create changes.pck changes = [ Change(who="Frosty the Snowman", files=["foo"], comments="Frosty the Snowman", branch="b1", revision=12345) ] cPickle.dump(Thing(changes=changes), open(os.path.join(self.basedir, "changes.pck"), "w")) sm = manager.DBSchemaManager(self.spec, self.basedir) sm.upgrade(quiet=True) c = self.db.getChangeNumberedNow(1) self.assertEquals(c.who, "Frosty the Snowman") self.assertEquals(c.comments, "Frosty the Snowman")
def testUnicodeChange(self): # Create changes.pck changes = [ Change(who=u"Frosty the \N{SNOWMAN}".encode("utf8"), files=["foo"], comments=u"Frosty the \N{SNOWMAN}".encode("utf8"), branch="b1", revision=12345) ] cPickle.dump(Thing(changes=changes), open(os.path.join(self.basedir, "changes.pck"), "w")) sm = manager.DBSchemaManager(self.spec, self.basedir) sm.upgrade(quiet=True) c = self.db.getChangeNumberedNow(1) self.assertEquals(c.who, u"Frosty the \N{SNOWMAN}") self.assertEquals(c.comments, u"Frosty the \N{SNOWMAN}")
def upgradeMaster(config): basedir = os.path.expanduser(config['basedir']) m = Maker(config) # TODO: check Makefile # TODO: check TAC file # check web files: index.html, default.css, robots.txt m.upgrade_public_html({ 'bg_gradient.jpg': util.sibpath(__file__, "../status/web/files/bg_gradient.jpg"), 'default.css': util.sibpath(__file__, "../status/web/files/default.css"), 'robots.txt': util.sibpath(__file__, "../status/web/files/robots.txt"), 'favicon.ico': util.sibpath(__file__, "../status/web/files/favicon.ico"), }) m.populate_if_missing(os.path.join(basedir, "master.cfg.sample"), util.sibpath(__file__, "sample.cfg"), overwrite=True) # if index.html exists, use it to override the root page tempalte m.move_if_present(os.path.join(basedir, "public_html/index.html"), os.path.join(basedir, "templates/root.html")) from buildbot.db import connector, dbspec spec = dbspec.DBSpec.from_url(config["db"], basedir) # TODO: check that TAC file specifies the right spec # upgrade the db from buildbot.db.schema import manager sm = manager.DBSchemaManager(spec, basedir) sm.upgrade() # check the configuration rc = m.check_master_cfg() if rc: return rc if not config['quiet']: print "upgrade complete" return 0