示例#1
0
    def create_builder(self, name, pgp, ssl):
        if NAMESPACE.session.query(Builder).filter_by(name=name).first():
            raise ValueError("Slave already exists.")

        pgp = import_pgp(self.pgp_keyring, pgp)
        ssl = import_ssl(self.ssl_keyring, ssl, name)

        b = Builder(name=name, maintainer=NAMESPACE.user, pgp=pgp, ssl=ssl,
                    last_ping=datetime.utcnow())
        NAMESPACE.session.add(b)

        emit('create', 'slave', b.debilize())
        return b.debilize()
示例#2
0
    def create_builder(self, slave_name, slave_password, key):
        keyid = import_key(key)

        obid = NAMESPACE.session.query(Builder).filter_by(
            name=slave_name).count()

        if obid != 0:
            raise ValueError("Slave already exists.")

        b = Builder(maintainer=NAMESPACE.user, name=slave_name, key=keyid,
                    password=slave_password, last_ping=dt.datetime.utcnow())
        emit('create', 'slave', b.debilize())
        NAMESPACE.session.add(b)
        NAMESPACE.session.commit()
        return b.debilize()
示例#3
0
    def create_builder(self, name, pgp, ssl=None, ip=None):
        """
        :param str name: name of the builder
        :param str pgp: path to the pgp public keyfile
        :param str ssl: path to the ssl certificate
        :param str ip: ip address of the builder
        """

        if NAMESPACE.session.query(Builder).filter_by(name=name).first():
            raise ValueError("Slave already exists.")

        pgp = import_pgp(self.pgp_keyring, pgp)
        if ssl is not None:
            ssl = import_ssl(self.ssl_keyring, ssl, name)
            b = Builder(name=name, maintainer=NAMESPACE.user, pgp=pgp, ssl=ssl,
                        last_ping=datetime.utcnow())

        elif ip is not None:
            b = Builder(name=name, maintainer=NAMESPACE.user, pgp=pgp, ip=ip,
                        last_ping=datetime.utcnow())

        else:
            raise ValueError("Need either ssl certificate or ip address")

        NAMESPACE.session.add(b)

        emit('create', 'slave', b.debilize())
        return b.debilize()
示例#4
0
def dimport(args, s):
    obj = yaml.safe_load(open(args.file, 'r'))

    users = obj.pop("Users", [])
    builders = obj.pop("Builders", [])
    suites = obj.pop("Suites", [])
    components = obj.pop("Components", [])
    arches = obj.pop("Arches", [])
    checks = obj.pop("Checks", [])
    groups = obj.pop("Groups", [])

    Base.metadata.create_all(s.bind)

    for user in users:
        s.add(Person(**user))

    for builder in builders:
        # FIXME: check that builder['maintainer'] exists in the DB/config file
        who = s.query(Person).filter_by(email=builder['maintainer']).one()
        builder['maintainer'] = who
        builder['last_ping'] = datetime.utcnow()
        s.add(Builder(**builder))

    for suite in suites:
        s.add(Suite(**suite))

    for component in components:
        s.add(Component(**component))

    for arch in ["source", "all"]:
        s.add(Arch(name=arch))

    for arch in arches:
        s.add(Arch(name=arch['name']))

    for check in checks:
        s.add(Check(**check))

    for group in groups:
        suites = group.pop('suites')

        # FIXME: check that group['maintainer'] exists in the DB/config file
        who = s.query(Person).filter_by(email=group['maintainer']).one()
        group['maintainer'] = who
        group = Group(**group)
        s.add(group)

        for suite in suites:
            gs = GroupSuite(
                group=group,
                suite=s.query(Suite).filter_by(name=suite['suite']).one())

            for component in suite.pop('components'):
                component = s.query(Component).filter_by(name=component).one()
                gs.components.append(component)

            for arch in ["source", "all"] + suite.pop('arches'):
                arch = s.query(Arch).filter_by(name=arch).one()
                gs.arches.append(arch)

            for check in suite.pop('checks'):
                check = s.query(Check).filter_by(name=check).one()
                gs.checks.append(check)

            s.add(gs)

        sane = True
        for key in obj:
            print "Unknown key '%s' in yaml file '%s'" % (key, args.file)
            sane = False

        if not s.query(exists().where(Person.id == Person.id)).scalar():
            print "No users in yaml file '%s'" % args.file
            sane = False
        elif not s.query(exists().where((
            (Person.ssl != None) & (Person.ssl != DEADBEEF))
                                        | (Person.ip != None))).scalar():
            print(
                "No enabled users in yaml file '%s' (user 'ssl' key missing or dummy 'DEADBEEF' string"
                "and no ip address configured)" % args.file)
            sane = False

        if not s.query(
                exists().where(GroupSuite.id == GroupSuite.id)).scalar():
            print "No group in yaml file '%s'" % args.file
            sane = False

        for group in s.query(Group).filter(~Group.group_suites.any()):
            print "No suites in group '%s' " % group.name
            sane = False

        for gs in s.query(GroupSuite).filter(~GroupSuite.arches.any(
            (Arch.name != 'source') & (Arch.name != 'all'))):
            print "No arches in group '%s' suite '%s'" % (gs.group.name,
                                                          gs.suite.name)
            sane = False

        for gs in s.query(GroupSuite).filter(~GroupSuite.components.any()):
            print "No components in group '%s' suite '%s'" % (gs.group.name,
                                                              gs.suite.name)
            sane = False

        for gs in s.query(GroupSuite).filter(~GroupSuite.checks.any()):
            print "No checks in group '%s' suite '%s'" % (gs.group.name,
                                                          gs.suite.name)
            sane = False

        if not sane and not args.force:
            raise Exception("Sanity checks failed, use --force to override")
示例#5
0
def import_dict(obj):
    maintainer = obj.pop("Maintainer", None)
    users = obj.pop("Users", [])
    builders = obj.pop("Builders", [])
    suites = obj.pop("Suites", [])
    groups = obj.pop("Groups", [])
    checks = obj.pop("Checks", [])
    arches = obj.pop("Arches", [])

    if obj != {}:
        for key in obj:
            print "Igorning key %s" % (key)

    with session() as s:
        for user in users:
            existing = None
            try:
                existing = s.query(Person).filter_by(
                    username=user['username']).one()
            except NoResultFound:
                pass

            p = Person(**user)

            if existing:
                p.id = existing.id
                s.merge(p)
            else:
                s.add(p)

        for builder in builders:
            username = builder.pop('maintainer')
            who = s.query(Person).filter_by(username=username).one()
            builder['maintainer'] = who
            builder['last_ping'] = dt.datetime.utcnow()
            s.add(Builder(**builder))

        for suite in suites:
            s.add(Suite(**suite))

        for arch in arches:
            s.add(Arch(name=arch['name']))

        for group in groups:
            arches = group.pop('arches')
            suites = group.pop('suites')

            who = s.query(Person).filter_by(username=group['maintainer']).one()
            group['maintainer'] = who
            group = Group(**group)
            s.add(group)

            for arch in arches:
                arch = s.query(Arch).filter_by(name=arch).one()
                ga = GroupArch(group=group, arch=arch)
                s.add(ga)

            for suite in suites:
                suite = s.query(Suite).filter_by(name=suite).one()
                ga = GroupSuite(group=group, suite=suite)
                s.add(ga)

        for check in checks:
            group = s.query(Group).filter_by(name=check['group']).one()
            check['group'] = group
            s.add(Check(**check))