コード例 #1
0
ファイル: test_utils.py プロジェクト: juju/juju-gui-charm
 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])
コード例 #2
0
ファイル: test_utils.py プロジェクト: mitechie/juju-gui-charm
 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])
コード例 #3
0
ファイル: test_utils.py プロジェクト: juju/juju-gui-charm
 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)
コード例 #4
0
ファイル: test_utils.py プロジェクト: mitechie/juju-gui-charm
 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)
コード例 #5
0
ファイル: test_utils.py プロジェクト: juju/juju-gui-charm
 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])
コード例 #6
0
ファイル: test_utils.py プロジェクト: mitechie/juju-gui-charm
 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])
コード例 #7
0
ファイル: prepare.py プロジェクト: mitechie/juju-gui-charm
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()