示例#1
0
    def Test_D_user_group(self):
        """
        Now start the legion with user and group strings.
    """
        self.set_path('PATH', env.examples_bin)
        self.log.info("PATH: %s", os.environ['PATH'])
        os.environ['EXAMPLES_BASE'] = env.examples_dir
        os.environ['EXAMPLES_TESTUSER'] = pwd.getpwuid(os.getuid()).pw_name
        os.environ['EXAMPLES_TESTGROUP'] = grp.getgrgid(os.getgid()).gr_name
        os.environ['EXAMPLES_LISTEN'] = self.tcp_listen
        new_roles = env.test_roles
        self.set_roles(new_roles)
        self.log.info("Setting roles %s", new_roles)
        self.log.info("Will run: %s", ' '.join(support.taskforce.command_line(env, [])))
        tf = support.taskforce(env, [], log=self.log)

        self.log.info("Checking startup of %s roles", new_roles)
        db_started = tf.search([r"Task 'db_server' already started"], log=self.log)
        assert db_started
        kids = len(support.proctree().processes[tf.pid].children) 
        assert self.find_children(tf, roles=new_roles) == expected_frontback_process_count
        self.log.info("User/group names ok")

        support.check_procsim_errors(self.__module__, env, log=self.log)
        tf.close()
示例#2
0
 def find_children(self, tf, roles=None):
     kids = support.proctree().processes[tf.pid].children
     self.log.info("Processes for %s: %d", roles, len(kids))
     k = 0
     for kid in kids:
         k += 1
         self.log.debug("    %2d %s", k, kid.command)
     return k
示例#3
0
    def Test_C_role_switch(self):
        """
        Check that a role change stops and starts processes correctly.
        Also excercise the uid-setting code (even though this just sets
        it to ourself as we are not necessarily running as root).
    """
        self.set_path('PATH', env.examples_bin)
        self.log.info("PATH: %s", os.environ['PATH'])
        os.environ['EXAMPLES_BASE'] = env.examples_dir
        os.environ['EXAMPLES_TESTUSER'] = str(os.getuid())
        os.environ['EXAMPLES_TESTGROUP'] = str(os.getgid())
        os.environ['EXAMPLES_LISTEN'] = self.tcp_listen
        new_roles = env.test_roles
        self.set_roles(new_roles)
        self.log.info("Setting roles %s", new_roles)
        self.log.info("Will run: %s", ' '.join(support.taskforce.command_line(env, [])))
        tf = support.taskforce(env, [], log=self.log)

        new_roles = env.test_roles
        self.log.info("Checking startup of %s roles", new_roles)
        db_started = tf.search([r"Task 'db_server' already started"], log=self.log)
        assert db_started
        kids = len(support.proctree().processes[tf.pid].children) 
        assert self.find_children(tf, roles=new_roles) == expected_frontback_process_count
        self.log.info("Startup ok")

        new_roles = env.test_roles[0]
        self.log.info("Switching to role %s", new_roles)
        self.set_roles(new_roles)
        db_stopped = tf.search([r"Task 'db_server' (still|pid)", r"Task 'ws_server' already started"],
                                                        log=self.log)
        assert db_stopped
        children_found = self.find_children(tf, roles=new_roles)
        if children_found != expected_frontend_process_count:
            self.log.warning("Found %d children, expected %d", children_found, expected_frontend_process_count)
        assert children_found == expected_frontend_process_count
        self.log.info("Switch to %s ok, pid to check is %d", new_roles, tf.pid)

        new_roles = env.test_roles[1]
        self.log.info("Switching to role %s", new_roles)
        self.set_roles(new_roles)
        db_restarted = tf.search([
            r"Task 'db_server' already started",
            r"Task 'db_server' a[l]ready started",  #  Bit of a kludge to be sure we see this at least twice
            r"Task 'httpd' already started" ], log=self.log)
        assert db_restarted
        assert self.find_children(tf, roles=new_roles) == expected_backend_process_count
        self.log.info("Switch to %s ok, pid to check is %d", new_roles, tf.pid)

        support.check_procsim_errors(self.__module__, env, log=self.log)

        tf.close()