Ejemplo n.º 1
0
    def testInstances(self):
        cx = self.getDB()
        schema.createSchema(cx)
        cx.commit()
        v = versiontable.VersionTable(cx)
        f = flavors.Flavors(cx)
        it = items.Items(cx)
        item = it.addId('foo')
        version = v.addId(versions.VersionFromString('/c@r:d/1.0-1-1'))
        d = deps.parseDep('')
        flavor = f.get(d, None)

        idb = instances.InstanceTable(cx)
        idb.addId(item, version, flavor, clonedFromId = None, troveType = 0)
        self.assertEqual(idb[(item, version, flavor)], 1)
        self.assertEqual(idb.getId(1), (item, version, flavor, 1) )
        del idb

        idb = instances.InstanceTable(cx)
        self.assertEqual(idb[(item, version, flavor)], 1)
        cu = cx.cursor()
        cu.execute("select isPresent, clonedFromId from instances where instanceid = 1")
        row = cu.fetchall()[0]
        self.assertEqual(row[0], 1)
        self.assertEqual(row[1], None)
        idb.update(1, isPresent = 0, clonedFromId = 1)
        cu.execute("select isPresent, clonedFromId from instances where instanceid = 1")
        row = cu.fetchall()[0]
        self.assertEqual(row[0], 0)
        self.assertEqual(row[1], 1)
Ejemplo n.º 2
0
 def testCreateSchema(self):
     from conary.server import schema
     db = self.getDB()
     schema.createSchema(db)
     db.commit()
     # we sould not fail with "already exists errors"
     schema.createSchema(db)
Ejemplo n.º 3
0
 def testCreateSchema(self):
     from conary.server import schema
     db = self.getDB()
     schema.createSchema(db)
     db.commit()
     # we sould not fail with "already exists errors"
     schema.createSchema(db)
Ejemplo n.º 4
0
    def testInstances(self):
        cx = self.getDB()
        schema.createSchema(cx)
        cx.commit()
        v = versiontable.VersionTable(cx)
        f = flavors.Flavors(cx)
        it = items.Items(cx)
        item = it.addId('foo')
        version = v.addId(versions.VersionFromString('/c@r:d/1.0-1-1'))
        d = deps.parseDep('')
        flavor = f.get(d, None)

        idb = instances.InstanceTable(cx)
        idb.addId(item, version, flavor, clonedFromId=None, troveType=0)
        self.assertEqual(idb[(item, version, flavor)], 1)
        self.assertEqual(idb.getId(1), (item, version, flavor, 1))
        del idb

        idb = instances.InstanceTable(cx)
        self.assertEqual(idb[(item, version, flavor)], 1)
        cu = cx.cursor()
        cu.execute(
            "select isPresent, clonedFromId from instances where instanceid = 1"
        )
        row = cu.fetchall()[0]
        self.assertEqual(row[0], 1)
        self.assertEqual(row[1], None)
        idb.update(1, isPresent=0, clonedFromId=1)
        cu.execute(
            "select isPresent, clonedFromId from instances where instanceid = 1"
        )
        row = cu.fetchall()[0]
        self.assertEqual(row[0], 0)
        self.assertEqual(row[1], 1)
Ejemplo n.º 5
0
    def testInvalidNames(self):
        db = self.getDB()
        schema.createSchema(db)
        na = netauth.NetworkAuthorization(db, "conary.rpath.com")

        try:
            na.addUser("test user", "testpass")
        except errors.InvalidName, e:
            self.assertEqual(str(e), 'InvalidName: test user')
Ejemplo n.º 6
0
 def testInvalidEntitlementClass(self):
     db = self.getDB()
     schema.createSchema(db)
     na = netauth.NetworkAuthorization(db, "conary.rpath.com")
     self._addUserRole(na, "root", "rootpass")
     na.setAdmin("root", True)
     self.assertRaises(errors.UnknownEntitlementClass,
                       na.addEntitlementKey,
                       ("root", "rootpass", None, None), "group", "1234")
Ejemplo n.º 7
0
 def _connect(self):
     db = self.getDB()
     schema.createSchema(db)
     schema.setupTempTables(db)
     depSchema.setupTempDepTables(db)
     store = trovestore.TroveStore(db)
     auth = netauth.NetworkAuthorization(db, ['localhost'])
     auth.addUser('anonymous', 'anonymous')
     auth.addRole('anonymous')
     auth.addRoleMember('anonymous', 'anonymous')
     auth.addAcl('anonymous', None, None, write = False, remove = False)
     auth.setAdmin('anonymous', False)
     return store
Ejemplo n.º 8
0
 def _connect(self):
     db = self.getDB()
     schema.createSchema(db)
     schema.setupTempTables(db)
     depSchema.setupTempDepTables(db)
     store = trovestore.TroveStore(db)
     auth = netauth.NetworkAuthorization(db, ['localhost'])
     auth.addUser('anonymous', 'anonymous')
     auth.addRole('anonymous')
     auth.addRoleMember('anonymous', 'anonymous')
     auth.addAcl('anonymous', None, None, write=False, remove=False)
     auth.setAdmin('anonymous', False)
     return store
Ejemplo n.º 9
0
 def testNodesTable(self):
     db = self.getDB()
     schema.createSchema(db)
     b = versionops.BranchTable(db)
     v = versiontable.VersionTable(db)
     i = items.Items(db)
     sv = versionops.SqlVersioning(db, v, b)
     ver = ThawVersion("/a.b.c@d:e/1:1-1-1")
     
     itemId = i.getOrAddId("foo")
     nodeId, versionId = sv.createVersion(itemId, ver, 0, None)
     cu = db.cursor()
     cu.execute("select sourceItemId from Nodes where nodeId = ?", nodeId)
     self.assertEqual(cu.fetchall()[0][0], None)
     srcId = i.getOrAddId("foo:source")
     sv.nodes.updateSourceItemId(nodeId, srcId)
     cu.execute("select sourceItemId from Nodes where nodeId = ?", nodeId)
     self.assertEqual(cu.fetchall()[0][0], srcId)
Ejemplo n.º 10
0
    def testNodesTable(self):
        db = self.getDB()
        schema.createSchema(db)
        b = versionops.BranchTable(db)
        v = versiontable.VersionTable(db)
        i = items.Items(db)
        sv = versionops.SqlVersioning(db, v, b)
        ver = ThawVersion("/a.b.c@d:e/1:1-1-1")

        itemId = i.getOrAddId("foo")
        nodeId, versionId = sv.createVersion(itemId, ver, 0, None)
        cu = db.cursor()
        cu.execute("select sourceItemId from Nodes where nodeId = ?", nodeId)
        self.assertEqual(cu.fetchall()[0][0], None)
        srcId = i.getOrAddId("foo:source")
        sv.nodes.updateSourceItemId(nodeId, srcId)
        cu.execute("select sourceItemId from Nodes where nodeId = ?", nodeId)
        self.assertEqual(cu.fetchall()[0][0], srcId)
Ejemplo n.º 11
0
    def testRenameColumn(self):
        db = self.getDB()
        from conary.server import schema
        schema.createSchema(db)
        db.commit()
        db.loadSchema()

        # simple columns that are not in any sort of FK relationship
        db.renameColumn("branches", "branch", "foo")

        db.renameColumn("changelogs", "name", "author")

        db.renameColumn("changelogs", "message", "msg")
        db.renameColumn("changelogs", "changed", "lastChanged")
        db.renameColumn("dependencies", "class", "cls")
        db.renameColumn("entitlementaccessmap", "entGroupId", "egid")
        db.renameColumn("entitlementgroups", "entGroup", "eg")
        db.renameColumn("entitlementowners", "ownerGroupId", "ogid")
        db.renameColumn("entitlements", "entitlement", "e")
        db.renameColumn("filestreams", "stream", "data")
        db.renameColumn("instances", "changed", "lastChanged")
        db.renameColumn("items", "item", "i")
        db.renameColumn("labelmap", "branchId", "bid")
        db.renameColumn("labelmap", "labelId", "lid")
        db.renameColumn("latestmirror", "mark", "lastMark")
        db.renameColumn("metadata", "timeStamp", "ts")
        db.renameColumn("metadata", "changed", "lastChanged")
        db.renameColumn("metadataitems", "data", "stream")
        db.renameColumn("nodes", "changed", "last_changed")
        db.renameColumn("nodes", "versionId", "vid")
        db.renameColumn("pgpfingerprints", "fingerprint", "fp")
        db.renameColumn("pgpfingerprints", "changed", "lastchanged")
        db.renameColumn("pgpkeys", "changed", "lc")
        db.renameColumn("pgpkeys", "pgpkey", "pk")
        db.renameColumn("pgpkeys", "fingerprint", "fp")
        db.renameColumn("provides", "instanceId", "iid")
        db.renameColumn("provides", "depId", "did")
        db.renameColumn("requires", "depId", "did")
        db.renameColumn("requires", "depCount", "c")
        db.renameColumn("trovefiles", "streamId", "sid")
        db.renameColumn("filepaths", "pathId", "pid")
        db.renameColumn("filepaths", "path", "path")
        db.renameColumn("troveinfo", "infoType", "it")
        db.renameColumn("troveinfo", "changed", "c")
        db.renameColumn("troveinfo", "data", "d")
        db.renameColumn("troveredirects", "flavorId", "fid")
        db.renameColumn("troveredirects", "changed", "ch")
        db.renameColumn("trovetroves", "flags", "fl")
        db.renameColumn("usergroupmembers", "userGroupId", "ugid")
        db.renameColumn("usergroupmembers", "userId", "uid")
        db.renameColumn("usergroups", "canMirror", "cm")
        db.renameColumn("usergroups", "changed", "lastc")
        db.renameColumn("users", "userName", "uname")

        # changing a column that has FKs pointing out
        db.renameColumn("nodes", "itemId", "nodeItemId")
        db.renameColumn("trovetroves", "instanceId", "id1")
        db.renameColumn("trovetroves", "includedId", "id2")

        # renaming a primary key without any FKs pointing to it
        db.renameColumn("labelmap", "labelmapid", "lmid")

        # changing a column that has FKs pointing to it
        if db.driver == "mysql":
            # this fails horribly with constraint violations
            # because MySQL is such a lame toy
            self.assertRaises(dbstore.sqlerrors.ConstraintViolation,
                              db.renameColumn, "items", "itemId", "id")
        else:
            # others should know to update the FKs
            # sqlite does not enforce FKs so this should succeed as well
            db.renameColumn("items", "itemId", "id")

        # test on a table with some entries in it
        cu = db.cursor()
        db.renameColumn("flavors", "flavor", "flavor_string")
        ret, = cu.execute(
            "select * from flavors where flavorId = 0").fetchall()
        self.assertEqual(ret['flavorId'], 0)
        self.assertEqual(ret['flavor_string'], '')

        set1 = cu.execute("select * from flavorscores").fetchall()
        db.renameColumn("flavorscores", "request", "req")
        db.renameColumn("flavorscores", "value", "val")
        set2 = cu.execute("select * from flavorscores").fetchall()
        assert (sorted(set1) == sorted(set2))
Ejemplo n.º 12
0
    def testRenameColumn(self):
        db = self.getDB()
        from conary.server import schema
        schema.createSchema(db)
        db.commit()
        db.loadSchema()

        # simple columns that are not in any sort of FK relationship
        db.renameColumn("branches", "branch", "foo")

        db.renameColumn("changelogs", "name", "author")

        db.renameColumn("changelogs", "message", "msg")
        db.renameColumn("changelogs", "changed", "lastChanged")
        db.renameColumn("dependencies", "class", "cls")
        db.renameColumn("entitlementaccessmap", "entGroupId", "egid")
        db.renameColumn("entitlementgroups", "entGroup", "eg")
        db.renameColumn("entitlementowners", "ownerGroupId", "ogid")
        db.renameColumn("entitlements", "entitlement", "e")
        db.renameColumn("filestreams", "stream", "data")
        db.renameColumn("instances", "changed", "lastChanged")
        db.renameColumn("items", "item", "i")
        db.renameColumn("labelmap", "branchId", "bid")
        db.renameColumn("labelmap", "labelId", "lid")
        db.renameColumn("latestmirror", "mark", "lastMark")
        db.renameColumn("metadata", "timeStamp", "ts")
        db.renameColumn("metadata", "changed", "lastChanged")
        db.renameColumn("metadataitems", "data", "stream")
        db.renameColumn("nodes", "changed", "last_changed")
        db.renameColumn("nodes", "versionId", "vid")
        db.renameColumn("pgpfingerprints", "fingerprint", "fp")
        db.renameColumn("pgpfingerprints", "changed", "lastchanged")
        db.renameColumn("pgpkeys", "changed", "lc")
        db.renameColumn("pgpkeys", "pgpkey", "pk")
        db.renameColumn("pgpkeys", "fingerprint", "fp")
        db.renameColumn("provides", "instanceId", "iid")
        db.renameColumn("provides", "depId", "did")
        db.renameColumn("requires", "depId", "did")
        db.renameColumn("requires", "depCount", "c")
        db.renameColumn("trovefiles", "streamId", "sid")
        db.renameColumn("filepaths", "pathId", "pid")
        db.renameColumn("filepaths", "path", "path")
        db.renameColumn("troveinfo", "infoType", "it")
        db.renameColumn("troveinfo", "changed", "c")
        db.renameColumn("troveinfo", "data", "d")
        db.renameColumn("troveredirects", "flavorId", "fid")
        db.renameColumn("troveredirects", "changed", "ch")
        db.renameColumn("trovetroves", "flags", "fl")
        db.renameColumn("usergroupmembers", "userGroupId", "ugid")
        db.renameColumn("usergroupmembers", "userId", "uid")
        db.renameColumn("usergroups", "canMirror", "cm")
        db.renameColumn("usergroups", "changed", "lastc")
        db.renameColumn("users", "userName", "uname")

        # changing a column that has FKs pointing out
        db.renameColumn("nodes", "itemId", "nodeItemId")
        db.renameColumn("trovetroves", "instanceId", "id1")
        db.renameColumn("trovetroves", "includedId", "id2")

        # renaming a primary key without any FKs pointing to it
        db.renameColumn("labelmap", "labelmapid", "lmid")

        # changing a column that has FKs pointing to it
        if db.driver == "mysql":
            # this fails horribly with constraint violations
            # because MySQL is such a lame toy
            self.assertRaises(dbstore.sqlerrors.ConstraintViolation,
                              db.renameColumn, "items", "itemId", "id")
        else:
            # others should know to update the FKs
            # sqlite does not enforce FKs so this should succeed as well
            db.renameColumn("items", "itemId", "id")

        # test on a table with some entries in it
        cu = db.cursor()
        db.renameColumn("flavors", "flavor", "flavor_string")
        ret, = cu.execute("select * from flavors where flavorId = 0").fetchall()
        self.assertEqual(ret['flavorId'], 0)
        self.assertEqual(ret['flavor_string'], '')

        set1 = cu.execute("select * from flavorscores").fetchall()
        db.renameColumn("flavorscores", "request", "req")
        db.renameColumn("flavorscores", "value", "val")
        set2 = cu.execute("select * from flavorscores").fetchall()
        assert(sorted(set1) == sorted(set2))
Ejemplo n.º 13
0
    def _setupDB(self):
        db = self.getDB()
        schema.createSchema(db)
        schema.setupTempTables(db)

        return db
Ejemplo n.º 14
0
    def testSqlVersioning(self):
        db = self.getDB()
        schema.createSchema(db)

        vTbl = versiontable.VersionTable(db)
        bTbl = versionops.BranchTable(db)
        sv = versionops.SqlVersioning(db, vTbl, bTbl)
        i = items.Items(db)
        # we need the FileStreams table for eraseVersion to work
        # properly. It is created as part of the createTroves() call

        v5 = ThawVersion("/conary.rpath.com@test:trunk/5:1.2-5")
        v10 = ThawVersion("/conary.rpath.com@test:trunk/10:1.2-10")
        v15 = ThawVersion("/conary.rpath.com@test:trunk/15:1.2-15")
        v20 = ThawVersion("/conary.rpath.com@test:trunk/20:1.2-20")

        branch = v10.branch()
        itemId = i.addId('foo')
        sv.createBranch(itemId, branch)

        sv.createVersion(itemId, v10, 0, "foo:source")
        assert(bTbl.has_key(branch))
        assert(vTbl.has_key(v10))
        assert(sv.hasVersion(itemId, vTbl[v10]))
        assert(i.has_key("foo:source"))
        assert(not sv.hasVersion(2, vTbl[v10]))

        branchId = bTbl[branch]

        itemId2 = i.addId('bar')
        sv.createBranch(itemId2, branch)
        sv.createVersion(itemId2, v10, 0, None)
        self.assertRaises(versionops.DuplicateVersionError,
                          sv.createVersion, itemId2, v10, 0, None)

        assert([vTbl.getId(x) for x in sv.versionsOnBranch(1, branchId)]
                    == [ str(v10) ])

        sv.createVersion(1, v20, 0, None)
        assert([vTbl.getId(x) for x in sv.versionsOnBranch(1, branchId)]
                    == [ str(v20), str(v10) ])

        sv.createVersion(1, v15, 0, None)
        db.commit()
        assert([vTbl.getId(x) for x in sv.versionsOnBranch(1, branchId)] ==
               [ str(v20), str(v15), str(v10) ])

        sv.createVersion(1, v5, 0, None)
        assert([vTbl.getId(x) for x in sv.versionsOnBranch(1, branchId)] ==
               [ str(v20), str(v15), str(v10), str(v5) ])

        label = Label("conary.rpath.com@test:trunk")
        assert [bTbl.getId(x) for x in sv.branchesOfLabel(1, label) ]\
                    == [ branch ]

        brLabel = Label("conary.rpath.com@test:br1")

        branch1 = v10.createBranch(brLabel, withVerRel = False)
        branch2 = v20.createBranch(brLabel, withVerRel = False)

        sv.createBranch(1, branch1)
        sv.createBranch(1, branch2)

        assert([bTbl.getId(x) for x in sv.branchesOfLabel(1, brLabel)] == \
               [branch1, branch2])

        assert([bTbl.getId(x) for x in sv.branchesOfItem(1)] ==
                    [ branch, branch1, branch2 ])
Ejemplo n.º 15
0
    def testSqlVersioning(self):
        db = self.getDB()
        schema.createSchema(db)

        vTbl = versiontable.VersionTable(db)
        bTbl = versionops.BranchTable(db)
        sv = versionops.SqlVersioning(db, vTbl, bTbl)
        i = items.Items(db)
        # we need the FileStreams table for eraseVersion to work
        # properly. It is created as part of the createTroves() call

        v5 = ThawVersion("/conary.rpath.com@test:trunk/5:1.2-5")
        v10 = ThawVersion("/conary.rpath.com@test:trunk/10:1.2-10")
        v15 = ThawVersion("/conary.rpath.com@test:trunk/15:1.2-15")
        v20 = ThawVersion("/conary.rpath.com@test:trunk/20:1.2-20")

        branch = v10.branch()
        itemId = i.addId('foo')
        sv.createBranch(itemId, branch)

        sv.createVersion(itemId, v10, 0, "foo:source")
        assert (bTbl.has_key(branch))
        assert (vTbl.has_key(v10))
        assert (sv.hasVersion(itemId, vTbl[v10]))
        assert (i.has_key("foo:source"))
        assert (not sv.hasVersion(2, vTbl[v10]))

        branchId = bTbl[branch]

        itemId2 = i.addId('bar')
        sv.createBranch(itemId2, branch)
        sv.createVersion(itemId2, v10, 0, None)
        self.assertRaises(versionops.DuplicateVersionError, sv.createVersion,
                          itemId2, v10, 0, None)

        assert ([vTbl.getId(x)
                 for x in sv.versionsOnBranch(1, branchId)] == [str(v10)])

        sv.createVersion(1, v20, 0, None)
        assert ([vTbl.getId(x) for x in sv.versionsOnBranch(1, branchId)
                 ] == [str(v20), str(v10)])

        sv.createVersion(1, v15, 0, None)
        db.commit()
        assert ([vTbl.getId(x) for x in sv.versionsOnBranch(1, branchId)
                 ] == [str(v20), str(v15), str(v10)])

        sv.createVersion(1, v5, 0, None)
        assert ([vTbl.getId(x) for x in sv.versionsOnBranch(1, branchId)
                 ] == [str(v20), str(v15),
                       str(v10), str(v5)])

        label = Label("conary.rpath.com@test:trunk")
        assert [bTbl.getId(x) for x in sv.branchesOfLabel(1, label) ]\
                    == [ branch ]

        brLabel = Label("conary.rpath.com@test:br1")

        branch1 = v10.createBranch(brLabel, withVerRel=False)
        branch2 = v20.createBranch(brLabel, withVerRel=False)

        sv.createBranch(1, branch1)
        sv.createBranch(1, branch2)

        assert([bTbl.getId(x) for x in sv.branchesOfLabel(1, brLabel)] == \
               [branch1, branch2])

        assert ([bTbl.getId(x)
                 for x in sv.branchesOfItem(1)] == [branch, branch1, branch2])