Example #1
0
 def __enter__(self):
     Log.note("SingleInstance.lockfile = " + self.lockfile)
     if sys.platform == 'win32':
         try:
             # file already exists, we try to remove (in case previous execution was interrupted)
             if os.path.exists(self.lockfile):
                 os.unlink(self.lockfile)
             self.fd = os.open(self.lockfile, os.O_CREAT | os.O_EXCL | os.O_RDWR)
         except Exception as e:
             Log.alarm("Another instance is already running, quitting.")
             sys.exit(-1)
     else: # non Windows
         import fcntl
         self.fp = open(self.lockfile, 'w')
         try:
             fcntl.lockf(self.fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
         except IOError:
             Log.note(
                 "\n"
                 "**********************************************************************\n"
                 "** Another instance is already running, quitting.\n"
                 "**********************************************************************\n"
             )
             sys.exit(-1)
     self.initialized = True
Example #2
0
 def __enter__(self):
     Log.note("SingleInstance.lockfile = " + self.lockfile)
     if sys.platform == 'win32':
         try:
             # file already exists, we try to remove (in case previous execution was interrupted)
             if os.path.exists(self.lockfile):
                 os.unlink(self.lockfile)
             self.fd = os.open(self.lockfile, os.O_CREAT | os.O_EXCL | os.O_RDWR)
         except Exception as e:
             Log.alarm("Another instance is already running, quitting.")
             sys.exit(-1)
     else: # non Windows
         import fcntl
         self.fp = open(self.lockfile, 'w')
         try:
             fcntl.lockf(self.fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
         except IOError:
             Log.note(
                 "\n"
                 "**********************************************************************\n"
                 "** Another instance is already running, quitting.\n"
                 "**********************************************************************\n"
             )
             sys.exit(-1)
     self.initialized = True
Example #3
0
    def test_alarm(self):
        self._before_test()
        Log.alarm("this is a {{type}} test", type="basic")
        es = self._after_test()

        # VERIFY LOG
        result = es.search(GET_RECENT_LOG).hits.hits[0]._source
        expected = {"~N~": [{
            "context": {"~s~": "ALARM"},
            "template": {"~s~": "this is a {{type}} test"},
            "params": {"type": {"~s~": "basic"}, "~e~": 1}
        }]}
        self.assertEqual(result, expected)

        self.assertIsNotNone(result.machine.name)
        self.assertIsNotNone(result.location)
        self.assertIsNotNone(result.thread)
        self.assertIsNotNone(result.timestamp['~n~'])

        self.assertEqual(result.timestamp['~s~'], NULL)
        self._delete_testindex()