示例#1
0
def waitforpuppet(currently_running):
    while currently_running:
        for hostname, finished_logfile in currently_running:
            print "Testing if puppet apply is finished : %s" % os.path.splitext(os.path.basename(finished_logfile))[0],
            try:
                # Once a remote puppet run has finished, we retrieve the log
                # file and check it for errors
                local_server = utils.ScriptRunner()
                log = finished_logfile.replace(".finished", ".log")
                local_server.append('scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@%s:%s %s' % (hostname, finished_logfile, log))
                # Errors are expected here if the puppet run isn't finished so we suppress logging them
                local_server.execute(logerrors=False)

                # If we got to this point the puppet apply has finished
                currently_running.remove((hostname, finished_logfile))

            except ScriptRuntimeError, e:
                # the test raises an exception if the file doesn't exist yet
                # TO-DO: We need to start testing 'e' for unexpected exceptions
                time.sleep(3)
                print
                continue

            # check the log file for errors
            validate_puppet_logfile(log)
            print "OK"
示例#2
0
    def test_validate_puppet_logfile(self):
        filename = os.path.join(self.tempdir, "puppet.log")
        fp = open(filename, "w")
        fp.write("Everything went ok")
        fp.close()

        validate_puppet_logfile(filename)
示例#3
0
    def test_validate_puppet_logfile_okerror(self):
        filename = os.path.join(self.tempdir, "puppet.log")
        fp = open(filename, "w")
        fp.write("err: Could not prefetch database_grant provider 'mysql': "
                 "Execution of '/usr/bin/mysql --defaults-file=/root/.my.cnf "
                 "mysql -Be describe user' returned 1: Could not open required"
                 " defaults file: /root/.my.cnf")
        fp.close()

        validate_puppet_logfile(filename)
示例#4
0
def waitforpuppet(currently_running):
    global controller
    log_len = 0
    twirl = ["-", "\\", "|", "/"]
    while currently_running:
        for hostname, finished_logfile in currently_running:
            log_file = os.path.splitext(os.path.basename(finished_logfile))[0]
            space_len = basedefs.SPACE_LEN - len(log_file)
            if len(log_file) > log_len:
                log_len = len(log_file)
            if hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
                twirl = twirl[-1:] + twirl[:-1]
                sys.stdout.write(
                    ("\rTesting if puppet apply is finished : %s" %
                     log_file).ljust(40 + log_len))
                sys.stdout.write("[ %s ]" % twirl[0])
                sys.stdout.flush()
            try:
                # Once a remote puppet run has finished, we retrieve the log
                # file and check it for errors
                local_server = utils.ScriptRunner()
                log = os.path.join(
                    basedefs.PUPPET_MANIFEST_DIR,
                    os.path.basename(finished_logfile).replace(
                        ".finished", ".log"))
                local_server.append(
                    'scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@%s:%s %s'
                    % (hostname, finished_logfile, log))
                # Errors are expected here if the puppet run isn't finished so we suppress logging them
                local_server.execute(logerrors=False)

                # If we got to this point the puppet apply has finished
                currently_running.remove((hostname, finished_logfile))

                # clean off the last "testing apply" msg
                if hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
                    sys.stdout.write(("\r").ljust(45 + log_len))

            except ScriptRuntimeError:
                # the test raises an exception if the file doesn't exist yet
                # TO-DO: We need to start testing 'e' for unexpected exceptions
                time.sleep(3)
                continue

            # check log file for relevant notices
            controller.MESSAGES.extend(scan_puppet_logfile(log))

            # check the log file for errors
            validate_puppet_logfile(log)
            sys.stdout.write(("\r%s : " % log_file).ljust(space_len))
            print("[ " + utils.color_text(output_messages.INFO_DONE, 'green') +
                  " ]")
示例#5
0
def waitforpuppet(currently_running):
    global controller
    log_len = 0
    twirl = ["-","\\","|","/"]
    while currently_running:
        for hostname, finished_logfile in currently_running:
            log_file = os.path.splitext(os.path.basename(finished_logfile))[0]
            space_len = basedefs.SPACE_LEN - len(log_file)
            if len(log_file) > log_len:
                log_len = len(log_file)
            if hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
                twirl = twirl[-1:] + twirl[:-1]
                sys.stdout.write(("\rTesting if puppet apply is finished : %s" % log_file).ljust(40 + log_len))
                sys.stdout.write("[ %s ]" % twirl[0])
                sys.stdout.flush()
            try:
                # Once a remote puppet run has finished, we retrieve the log
                # file and check it for errors
                local_server = utils.ScriptRunner()
                log = os.path.join(basedefs.PUPPET_MANIFEST_DIR,
                                   os.path.basename(finished_logfile).replace(".finished", ".log"))
                local_server.append('scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@%s:%s %s' % (hostname, finished_logfile, log))
                # Errors are expected here if the puppet run isn't finished so we suppress logging them
                local_server.execute(logerrors=False)

                # If we got to this point the puppet apply has finished
                currently_running.remove((hostname, finished_logfile))

                # clean off the last "testing apply" msg
                if hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
                    sys.stdout.write(("\r").ljust(45 + log_len))

            except ScriptRuntimeError, e:
                # the test raises an exception if the file doesn't exist yet
                # TO-DO: We need to start testing 'e' for unexpected exceptions
                time.sleep(3)
                continue

            # check log file for relevant notices
            controller.MESSAGES.extend(scan_puppet_logfile(log))

            # check the log file for errors
            validate_puppet_logfile(log)
            sys.stdout.write(("\r%s : " % log_file).ljust(basedefs.SPACE_LEN))
            print ("[ " + utils.color_text(output_messages.INFO_DONE, 'green') + " ]")