Exemple #1
0
 def _get_environment(self):
     """Get the Environment object defined by the test configuration.
     Will set the owner to the currently running user. If already owned then
     a ConfigError will be raised.
     """
     if self._cache.get("_environment") is None:
         name = self.get("environmentname", "default")
         if name:
             db = self.session
             try:
                 env = db.query(models.Environment).filter(
                     models.Environment.name == name).one()
             except config.NoResultFound as err:
                 raise config.ConfigError("Bad environmentname %r: %s" %
                                          (name, err))
             username = self.get(
                 "username")  # username should be set by test runner
             if username:
                 if env.is_owned():
                     if env.owner.username != username:
                         raise config.ConfigError(
                             "Environment is currently owned by: %s" %
                             (env.owner, ))
                 env.set_owner_by_username(db, username)
             env = EnvironmentRuntime(db, env, self.logfile)
             self._cache["_environment"] = env
         else:
             raise config.ConfigError, "Bad environmentname %r." % (name, )
     return self._cache["_environment"]
Exemple #2
0
 def get_equipment(self, name):
     """Get any equipment runtime from the configuration by name."""
     db = self.session
     try:
         eqrow = db.query(models.Equipment).filter(
             models.Equipment.name.contains(name)).one()
     except config.NoResultFound as err:
         raise config.ConfigError("Bad equipment name %r: %s" % (name, err))
     return EquipmentRuntime(eqrow, "unspecified", self.get_logfile(), db)
Exemple #3
0
 def get_account(self, identifier):
     """Get account credentials by identifier."""
     db = self.session
     try:
         acct = db.query(models.LoginAccount).filter(
             models.LoginAccount.identifier == identifier).one()
     except config.NoResultFound as err:
         raise config.ConfigError("Bad account identifier %r: %s" %
                                  (identifier, err))
     return acct.login, acct.password
Exemple #4
0
def get_root(session):
    global _user
    if _user is None:
        user_pwent = passwd.getpwself()
        _user = models.User.get_by_username(session, user_pwent.name)
    if _user is None:
        raise config.ConfigError("User {} not in database.".format(user_pwent.name))
    root = config.get_root(session)
    if _user.is_superuser:
        return root
    else:
        newroot = session.query(models.Config).filter(and_(
                models.Config.name==_user.username,
                models.Config.container==root)).scalar()
        if newroot is None:
            raise config.ConfigError("No user container. Superuser account should add one.")
            #container = config.Container(session, root)
            #container.register_user(_user)
            #newroot = container.add_container(_user.username)
            #return newroot.node
        elif newroot.value is NULL:
            return newroot
        else:
            raise config.ConfigError("Not a user container")
Exemple #5
0
 def get_all_with_role(self, rolename):
     eqlist = self._environment.get_all_equipment_with_role(
         self._session, rolename)
     first = self._eqcache.get(rolename)
     if first:
         rlist = [first]
         rlist.extend([
             EquipmentRuntime(eq, rolename, self.logfile, self._session)
             for eq in eqlist if eq.name != first.name
         ])
         return rlist
     else:
         rlist = [
             EquipmentRuntime(eq, rolename, self.logfile, self._session)
             for eq in eqlist
         ]
         if rlist:
             self._eqcache[rolename] = rlist[0]
             return rlist
         else:
             raise config.ConfigError(
                 "No equipment with role {} available in environment.".
                 format(rolename))