Пример #1
0
    def test_version_and_stream_logger(self):
        # remember std out & err
        self.old_stdout, self.old_stderr = sys.stdout, sys.stderr
        self.old_stdout.flush()
        self.old_stderr.flush()

        # redirects std out & err to log
        setup_logging(logging.INFO)

        # test
        sys.stdout.write('test redirect stdout to log')
        sys.argv.append('-v')
        self.assertRaises(SystemExit, main)

        # reset std out & err
        # no need to flush, the logger doesn't need to
        sys.stdout = self.old_stdout
        sys.stderr = self.old_stderr

        # reset logging
        setup_logging(logging.DEBUG)
Пример #2
0
    def test_version_and_stream_logger(self):
        # remember std out & err
        self.old_stdout, self.old_stderr = sys.stdout, sys.stderr
        self.old_stdout.flush()
        self.old_stderr.flush()

        # redirects std out & err to log
        setup_logging(logging.INFO)

        # test
        sys.stdout.write("test redirect stdout to log")
        sys.argv.append("-v")
        self.assertRaises(SystemExit, main)

        # reset std out & err
        # no need to flush, the logger doesn't need to
        sys.stdout = self.old_stdout
        sys.stderr = self.old_stderr

        # reset logging
        setup_logging(logging.DEBUG)
Пример #3
0
def main():
    '''
    Description:
        This script will be used on EC2 for configuring the running
        instance based on Cloud Engine configuration supplied at
        launch time in the user data.

        Config Server Status:
        200 HTTP OK - Success and no more data of this type
        202 HTTP Accepted - Success and more data of this type
        404 HTTP Not Found - This may be temporary so try again
    '''
    # parse the args and setup logging
    conf = parse_args()
    log_file = {}
    if 'pwd' in conf and conf.pwd:
        log_file = {'logfile_name': 'audrey.log'}

    logger = setup_logging(level=conf.log_level, **log_file)

    if not conf.endpoint:
        # discover the cloud I'm on
        # update the conf with the user data
        #conf = dict(vars(conf).items() + user_data.discover().read().items())
        vars(conf).update(user_data.discover().read().items())

    # ensure the conf is a dictionary, not a namespace
    if hasattr(conf, '__dict__'):
        conf = vars(conf)

    logger.info('Invoked audrey main')

    # Create the Client Object and test connectivity
    # to CS by negotiating the api version
    client = CSClient(**conf)
    client.test_connection()

    # Get the agent object
    agent = AudreyFactory(client.api_version).agent
    # run the agent
    agent(conf).run()