예제 #1
0
 def test_direct(self):
     plogging.setLevel(logging.DEBUG)
     self.assertEqual(plogging.getEffectiveLevel(), logging.DEBUG)
     plogging.debug("hello world -- debug")
     plogging.info("hello world -- info")
     plogging.warning("hello world -- warning")
     plogging.error("hello world -- error")
     plogging.critical("hello world -- critical")
     self.assertEqual(plogging.foundErrors(), True)
     plogging.reset()
     self.assertEqual(plogging.foundErrors(), False)
예제 #2
0
    def test_direct(self):

        class DullHandler(logging.NullHandler):
            level = logging.DEBUG
            def emit(self, record):
                log_entry = self.format(record)

        plogging.addHandler(DullHandler())
        plogging.setLevel(logging.DEBUG)
        self.assertEqual(plogging.getEffectiveLevel(), logging.DEBUG)
        plogging.debug("hello world -- debug")
        plogging.info("hello world -- info")
        plogging.warning("hello world -- warning")
        plogging.error("hello world -- error")
        plogging.critical("hello world -- critical")
        self.assertEqual(plogging.foundErrors(), True)
        plogging.reset()
        self.assertEqual(plogging.foundErrors(), False)
예제 #3
0
    try:
        engine.do(args.action, args.blueprints, args.facilities)

        plogging.info(engine.document_elapsed())

    except Exception as feedback:
        if plogging.getEffectiveLevel() == logging.DEBUG:
            plogging.error("Unable to do '{}'".format(args.action))
            raise
        else:
            plogging.error("Unable to do '{}', run with -d for debug".format(
                args.action))
            plogging.error("{}: {}".format(feedback.__class__.__name__,
                                           str(feedback)))
        sys.exit(1)


if __name__ == "__main__":
    try:
        main()

        # if some errors have been logged, make it explicit to the caller
        if plogging.foundErrors():
            plogging.error("Hit some error, you should check the logs")
            sys.exit(1)

    except KeyboardInterrupt:
        plogging.error("Aborted by user")
        sys.exit(1)
예제 #4
0
    def test_keys(self):

        engine = PlumberyEngine()
        self.assertEqual(engine._sharedKeyFiles, [])

        with self.assertRaises(ValueError):
            engine.set_shared_key_files('this_does_not_exist')
        self.assertTrue(isinstance(engine.get_shared_key_files(), list))
        self.assertEqual(engine._sharedKeyFiles,
                         engine.get_shared_key_files())

        with mock.patch.object(engine, 'get_shared_key_files') as patched:
            patched.return_value = []

            files = ['*unknown-file*', '**me-too*']
            with self.assertRaises(ValueError):
                engine.set_shared_key_files(files)

        file = os.path.abspath(
            os.path.dirname(__file__))+'/fixtures/dummy_rsa.pub'
        engine.set_shared_key_files(file)
        self.assertTrue(isinstance(engine.get_shared_key_files(), list))
        self.assertEqual(engine.get_shared_key_files()[0], file)
        self.assertEqual(engine._sharedKeyFiles,
                         engine.get_shared_key_files())

        with mock.patch.object(engine, 'get_shared_key_files') as patched:
            patched.return_value = []

            files = [file, file, file]
            engine.set_shared_key_files(files)

            self.assertEqual(engine._sharedKeyFiles, [file])

        if 'SHARED_KEY' in os.environ:
            memory = os.environ["SHARED_KEY"]
        else:
            memory = None

        engine._sharedKeyFiles = []
        os.environ["SHARED_KEY"] = 'this_does_not_exist'
        with self.assertRaises(ValueError):
            engine.set_shared_key_files()
        with self.assertRaises(ValueError):
            engine.get_shared_key_files()
        self.assertTrue(isinstance(engine._sharedKeyFiles, list))

        engine._sharedKeyFiles = []
        os.environ["SHARED_KEY"] = file
        engine.set_shared_key_files()
        self.assertTrue(isinstance(engine.get_shared_key_files(), list))
        self.assertEqual(engine.get_shared_key_files()[0], file)
        self.assertEqual(engine._sharedKeyFiles,
                         engine.get_shared_key_files())

        if memory is None:
            os.environ.pop("SHARED_KEY")
        else:
            os.environ["SHARED_KEY"] = memory

        with mock.patch.object(engine, 'get_shared_key_files') as patched:
            patched.return_value = []

            self.assertTrue(isinstance(engine.get_shared_key_files(), list))

            engine.set_shared_key_files()
            self.assertTrue(plogging.foundErrors())

            with self.assertRaises(ValueError):
                engine.set_shared_key_files('this_does_not_exist')

            file = os.path.abspath(
                os.path.dirname(__file__))+'/fixtures/dummy_rsa.pub'
            engine.set_shared_key_files(file)
            self.assertEqual(engine._sharedKeyFiles, [file])
예제 #5
0
    def test_keys(self):

        engine = PlumberyEngine()
        self.assertEqual(engine._sharedKeyFiles, [])

        with self.assertRaises(ValueError):
            engine.set_shared_key_files('this_does_not_exist')
        self.assertTrue(isinstance(engine.get_shared_key_files(), list))
        self.assertEqual(engine._sharedKeyFiles, engine.get_shared_key_files())

        with mock.patch.object(engine, 'get_shared_key_files') as patched:
            patched.return_value = []

            files = ['*unknown-file*', '**me-too*']
            with self.assertRaises(ValueError):
                engine.set_shared_key_files(files)

        file = os.path.abspath(
            os.path.dirname(__file__)) + '/fixtures/dummy_rsa.pub'
        engine.set_shared_key_files(file)
        self.assertTrue(isinstance(engine.get_shared_key_files(), list))
        self.assertEqual(engine.get_shared_key_files()[0], file)
        self.assertEqual(engine._sharedKeyFiles, engine.get_shared_key_files())

        with mock.patch.object(engine, 'get_shared_key_files') as patched:
            patched.return_value = []

            files = [file, file, file]
            engine.set_shared_key_files(files)

            self.assertEqual(engine._sharedKeyFiles, [file])

        if 'SHARED_KEY' in os.environ:
            memory = os.environ["SHARED_KEY"]
        else:
            memory = None

        engine._sharedKeyFiles = []
        os.environ["SHARED_KEY"] = 'this_does_not_exist'
        with self.assertRaises(ValueError):
            engine.set_shared_key_files()
        with self.assertRaises(ValueError):
            engine.get_shared_key_files()
        self.assertTrue(isinstance(engine._sharedKeyFiles, list))

        engine._sharedKeyFiles = []
        os.environ["SHARED_KEY"] = file
        engine.set_shared_key_files()
        self.assertTrue(isinstance(engine.get_shared_key_files(), list))
        self.assertEqual(engine.get_shared_key_files()[0], file)
        self.assertEqual(engine._sharedKeyFiles, engine.get_shared_key_files())

        if memory is None:
            os.environ.pop("SHARED_KEY")
        else:
            os.environ["SHARED_KEY"] = memory

        with mock.patch.object(engine, 'get_shared_key_files') as patched:
            patched.return_value = []

            self.assertTrue(isinstance(engine.get_shared_key_files(), list))

            engine.set_shared_key_files()
            self.assertTrue(plogging.foundErrors())

            with self.assertRaises(ValueError):
                engine.set_shared_key_files('this_does_not_exist')

            file = os.path.abspath(
                os.path.dirname(__file__)) + '/fixtures/dummy_rsa.pub'
            engine.set_shared_key_files(file)
            self.assertEqual(engine._sharedKeyFiles, [file])
예제 #6
0
    try:
        engine.do(args.action, args.blueprints, args.facilities)

        plogging.info(engine.document_elapsed())

    except Exception as feedback:
        if plogging.getEffectiveLevel() == logging.DEBUG:
            plogging.error("Unable to do '{}'".format(args.action))
            raise
        else:
            plogging.error("Unable to do '{}', run with -d for debug".format(
                args.action))
            plogging.error("{}: {}".format(
                feedback.__class__.__name__,
                str(feedback)))
        sys.exit(1)

if __name__ == "__main__":
    try:
        main()

        # if some errors have been logged, make it explicit to the caller
        if plogging.foundErrors():
            plogging.error("Hit some error, you should check the logs")
            sys.exit(1)

    except KeyboardInterrupt:
        plogging.error("Aborted by user")
        sys.exit(1)