Exemplo n.º 1
0
 def test_error(self):
     # Possible errors are re-raised by the context manager.
     with self.assertRaises(TypeError) as cm:
         with log_hook():
             raise TypeError
     exception = cm.exception
     self.assertIsInstance(exception, TypeError)
     self.assertIn("<<< Exiting", self.output[-1])
Exemplo n.º 2
0
 def test_error(self):
     # Possible errors are re-raised by the context manager.
     with self.assertRaises(TypeError) as cm:
         with log_hook():
             raise TypeError
     exception = cm.exception
     self.assertIsInstance(exception, TypeError)
     self.assertIn('<<< Exiting', self.output[-1])
Exemplo n.º 3
0
 def test_logging(self):
     # The function emits log messages on entering and exiting the hook.
     with log_hook():
         self.output.append("executing hook")
     self.assertEqual(3, len(self.output))
     enter_message, executing_message, exit_message = self.output
     self.assertIn(">>> Entering", enter_message)
     self.assertEqual("executing hook", executing_message)
     self.assertIn("<<< Exiting", exit_message)
Exemplo n.º 4
0
 def test_logging(self):
     # The function emits log messages on entering and exiting the hook.
     with log_hook():
         self.output.append('executing hook')
     self.assertEqual(3, len(self.output))
     enter_message, executing_message, exit_message = self.output
     self.assertIn('>>> Entering', enter_message)
     self.assertEqual('executing hook', executing_message)
     self.assertIn('<<< Exiting', exit_message)
Exemplo n.º 5
0
 def test_subprocess_error(self):
     # If a CalledProcessError exception is raised, the command output is
     # logged.
     with self.assertRaises(CalledProcessError) as cm:
         with log_hook():
             raise CalledProcessError(2, "command", "output")
     exception = cm.exception
     self.assertIsInstance(exception, CalledProcessError)
     self.assertEqual(2, exception.returncode)
     self.assertEqual("output", self.output[-2])
Exemplo n.º 6
0
 def test_subprocess_error(self):
     # If a CalledProcessError exception is raised, the command output is
     # logged.
     with self.assertRaises(CalledProcessError) as cm:
         with log_hook():
             raise CalledProcessError(2, 'command', 'output')
     exception = cm.exception
     self.assertIsInstance(exception, CalledProcessError)
     self.assertEqual(2, exception.returncode)
     self.assertEqual('output', self.output[-2])
Exemplo n.º 7
0
def main():
    # Run pre-install tasks, if available.
    if os.path.isdir('exec.d'):
        dirnames = os.listdir('exec.d')
        dirnames.sort()
        for module in dirnames:
            filename = os.path.join('exec.d', module, 'charm-pre-install')
            try:
                run(filename)
            except OSError, e:
                # If the exec.d file does not exist or is not runnable or
                # is not a directory, assume we can recover.  Log the problem
                # and proceed.  Note that Juju Core has a special need of
                # errno.ENOTDIR because it apparently adds a ".empty" file in
                # empty charm directories, so trying to run
                # ./exec.d/.empty/charm-pre-install will trigger that error.
                if e.errno in (errno.ENOENT, errno.EACCES, errno.ENOTDIR):
                    log('{}: {}'.format(e.strerror, filename))
                else:
                    raise
    config = get_config()
    backend = Backend(config)
    backend.install()
    # Store current configuration.
    config_json.set(config)


if __name__ == '__main__':
    with log_hook():
        main()