Пример #1
0
    def test_grep_for_environment_variables(self):
        if os.name == 'nt':
            return

        a = Action()
        a.timeout = 10
        a.env = {}  # :fixme: this sould be pre-set in Action.__init__()

        a.command = "/usr/bin/env | grep TITI"

        self.assertNotIn('TITI', a.get_local_environnement())
        a.env = {'TITI': 'est en vacance'}
        self.assertIn('TITI', a.get_local_environnement())
        self.assertEqual(a.get_local_environnement()['TITI'],
                         'est en vacance' )
        a.execute()
        self.wait_finished(a)
        self.assertEqual(a.output, 'TITI=est en vacance')
Пример #2
0
 def test_non_zero_exit_status_empty_output_but_non_empty_stderr(self):
     a = Action()
     a.command = "echo hooo >&2 ; exit 1"
     a.timeout = 10
     a.env = {}  # :fixme: this sould be pre-set in Action.__init__()
     a.execute()
     self.wait_finished(a)
     self.assertEqual(a.output, "hooo")
Пример #3
0
    def test_noshell_bang_command(self):
        a = Action()
        a.timeout = 10
        a.command = "libexec/dummy_command_nobang.sh"
        a.env = {}
        if os.name == 'nt':
            return
        self.assert_(a.got_shell_characters() == False)
        a.execute()

        self.assert_(a.status == 'launched')
        self.wait_finished(a)
        print "F**k", a.status, a.output
        self.assert_(a.exit_status == 0)
        self.assert_(a.status == 'done')
Пример #4
0
 def test_non_zero_exit_status_empty_output_but_non_empty_stderr(self):
     a = Action()
     a.command = "echo hooo >&2 ; exit 1"
     a.timeout = 10
     a.env = {}  # :fixme: this sould be pre-set in Action.__init__()
     a.execute()
     self.wait_finished(a)
     self.assertEqual(a.output, "hooo")
Пример #5
0
    def test_got_pipe_shell_characters(self):
        a = Action()
        a.timeout = 10
        a.command = "libexec/dummy_command_nobang.sh | grep 'Please do not use me directly'"
        a.env = {}
        if os.name == 'nt':
            return
        self.assert_(a.got_shell_characters() == True)
        a.execute()

        self.assert_(a.status == 'launched')
        self.wait_finished(a)
        print "F**k", a.status, a.output
        self.assert_(a.exit_status == 0)
        self.assert_(a.status == 'done')
Пример #6
0
    def test_got_shell_characters(self):
        a = Action()
        a.timeout = 10
        a.command = "libexec/dummy_command_nobang.sh && echo finished ok"
        a.env = {}
        if os.name == 'nt':
            return
        self.assertEqual(True, a.got_shell_characters())
        a.execute()

        self.assertEqual('launched', a.status)
        self.wait_finished(a)
        print "F**k", a.status, a.output
        self.assertEqual(0, a.exit_status)
        self.assertEqual('done', a.status)
Пример #7
0
    def test_action(self):
        a = Action()
        a.timeout = 10
        a.env = {}

        if os.name == 'nt':
            a.command = r'libexec\\dummy_command.cmd'
        else:
            a.command = "libexec/dummy_command.sh"
        self.assertEqual(False, a.got_shell_characters())
        a.execute()
        self.assertEqual('launched', a.status)
        # Give also the max output we want for the command
        self.wait_finished(a)
        self.assertEqual(0, a.exit_status)
        self.assertEqual('done', a.status)
        print a.output
        self.assertEqual("Hi, I'm for testing only. Please do not use me directly, really", a.output)
        self.assertEqual("Hip=99% Bob=34mm", a.perf_data)
Пример #8
0
    def test_execve_fail_with_utf8(self):
        if os.name == 'nt':
            return

        a = Action()
        a.timeout = 10
        a.env = {}  # :fixme: this sould be pre-set in Action.__init__()

        a.command = u"/bin/echo Wiadomo\u015b\u0107"

        a.execute()
        self.wait_finished(a)
        #print a.output
        self.assertEqual(a.output.decode('utf8'), u"Wiadomo\u015b\u0107")
Пример #9
0
    def test_action(self):
        a = Action()
        a.timeout = 10
        a.env = {}

        if os.name == 'nt':
            a.command = r'libexec\\dummy_command.cmd'
        else:
            a.command = "libexec/dummy_command.sh"
        self.assert_(a.got_shell_characters() == False)
        a.execute()
        self.assert_(a.status == 'launched')
        #Give also the max output we want for the command
        self.wait_finished(a)
        self.assert_(a.exit_status == 0)
        self.assert_(a.status == 'done')
        self.assert_(a.output == "Hi, I'm for testing only. Please do not use me directly, really")
        self.assert_(a.perf_data == "Hip=99% Bob=34mm")
Пример #10
0
    def test_got_shell_characters(self):
        a = Action()
        a.timeout = 10
        a.command = "libexec/dummy_command_nobang.sh && echo finished ok"
        a.env = {}
        if os.name == 'nt':
            return
        self.assert_(a.got_shell_characters() == True)
        a.execute()

        self.assert_(a.status == 'launched')
        self.wait_finished(a)
        print "F**k", a.status, a.output
        self.assert_(a.exit_status == 0)
        self.assert_(a.status == 'done')
Пример #11
0
    def test_got_pipe_shell_characters(self):
        a = Action()
        a.timeout = 10
        a.command = "libexec/dummy_command_nobang.sh | grep 'Please do not use me directly'"
        a.env = {}
        if os.name == 'nt':
            return
        self.assertEqual(True, a.got_shell_characters())
        a.execute()

        self.assertEqual('launched', a.status)
        self.wait_finished(a)
        print "F**k", a.status, a.output
        self.assertEqual(0, a.exit_status)
        self.assertEqual('done', a.status)
Пример #12
0
    def test_noshell_bang_command(self):
        a = Action()
        a.timeout = 10
        a.command = "libexec/dummy_command_nobang.sh"
        a.env = {}
        if os.name == 'nt':
            return
        self.assertEqual(False, a.got_shell_characters())
        a.execute()

        self.assertEqual('launched', a.status)
        self.wait_finished(a)
        print "F**k", a.status, a.output
        self.assertEqual(0, a.exit_status)
        self.assertEqual('done', a.status)
Пример #13
0
    def test_execve_fail_with_utf8(self):
        if os.name == 'nt':
            return

        a = Action()
        a.timeout = 10
        a.env = {}  # :fixme: this sould be pre-set in Action.__init__()

        a.command = u"/bin/echo Wiadomo\u015b\u0107"

        a.execute()
        self.wait_finished(a)
        #print a.output
        self.assertEqual(a.output.decode('utf8'), u"Wiadomo\u015b\u0107")
Пример #14
0
    def test_environnement_variables(self):
        a = Action()
        a.timeout = 10
        if os.name == 'nt':
            return
        else:
            a.command = "/usr/bin/env"
        a.env = {'TITI': 'est en vacance'}

        self.assert_(a.got_shell_characters() == False)

        a.execute()

        self.assert_(a.status == 'launched')
        #Give also the max output we want for the command
        self.wait_finished(a)
        print "Output", a.long_output, a.output
        titi_found = False
        for l in a.long_output.splitlines():
            if l == 'TITI=est en vacance':
                titi_found = True

        self.assert_(titi_found == True)
Пример #15
0
    def test_huge_output(self):
        a = Action()
        a.timeout = 5
        a.env = {}

        if os.name == 'nt':
            a.command = r"""python -c 'print "A"*1000000'"""
            # FROM NOW IT4S FAIL ON WINDOWS :(
            return
        else:
            a.command = r"""python -u -c 'print "A"*100000'"""
        print "EXECUTE"
        a.execute()
        print "EXECUTE FINISE"
        self.assert_(a.status == 'launched')
        # Give also the max output we want for the command
        self.wait_finished(a, 10000000000)
        print "Status?", a.exit_status
        self.assert_(a.exit_status == 0)
        print "Output", len(a.output)
        self.assert_(a.exit_status == 0)
        self.assert_(a.status == 'done')
        self.assert_(a.output == "A" * 100000)
        self.assert_(a.perf_data == "")
Пример #16
0
    def test_got_unclosed_quote(self):
        # https://github.com/naparuba/shinken/issues/155
        a = Action()
        a.timeout = 10
        a.command = "libexec/dummy_command_nobang.sh -a 'wwwwzzzzeeee"
        a.env = {}
        if os.name == 'nt':
            return
        a.execute()

        self.wait_finished(a)
        self.assertEqual('done', a.status)
        print "F**k", a.status, a.output
        if sys.version_info < (2, 7):
            # cygwin: /bin/sh: -c: line 0: unexpected EOF while looking for matching'
            # ubuntu: /bin/sh: Syntax error: Unterminated quoted string
            self.assertTrue(a.output.startswith("/bin/sh"))
            self.assertEqual(3, a.exit_status)
        else:
            self.assertEqual('Not a valid shell command: No closing quotation', a.output)
            self.assertEqual(3, a.exit_status)
Пример #17
0
    def test_environnement_variables(self):
        a = Action()
        a.timeout = 10
        if os.name == 'nt':
            return
        else:
            a.command = "/usr/bin/env"
        a.env = {'TITI' : 'est en vacance'}

        self.assert_(a.got_shell_characters() == False)

        a.execute()

        self.assert_(a.status == 'launched')
        #Give also the max output we want for the command
        self.wait_finished(a)
        print "Output", a.long_output, a.output
        titi_found = False
        for l in a.long_output.splitlines():
            if l == 'TITI=est en vacance':
                titi_found = True

        self.assert_(titi_found == True)
Пример #18
0
    def test_huge_output(self):
        a = Action()
        a.timeout = 5
        a.env = {}

        if os.name == 'nt':
            a.command = r"""python -c 'print "A"*1000000'"""
            # FROM NOW IT4S FAIL ON WINDOWS :(
            return
        else:
            a.command = r"""python -u -c 'print "A"*100000'"""
        print "EXECUTE"
        a.execute()
        print "EXECUTE FINISE"
        self.assertEqual('launched', a.status)
        # Give also the max output we want for the command
        self.wait_finished(a, 10000000000)
        print "Status?", a.exit_status
        self.assertEqual(0, a.exit_status)
        print "Output", len(a.output)
        self.assertEqual(0, a.exit_status)
        self.assertEqual('done', a.status)
        self.assertEqual("A"*100000, a.output)
        self.assertEqual("", a.perf_data)
Пример #19
0
    def test_got_unclosed_quote(self):
        # https://github.com/naparuba/shinken/issues/155
        a = Action()
        a.timeout = 10
        a.command = "libexec/dummy_command_nobang.sh -a 'wwwwzzzzeeee"
        a.env = {}
        if os.name == 'nt':
            return
        a.execute()

        self.wait_finished(a)
        self.assertEqual('done', a.status)
        print "F**k", a.status, a.output
        if sys.version_info < (2, 7):
            # cygwin: /bin/sh: -c: line 0: unexpected EOF while looking for matching'
            # ubuntu: /bin/sh: Syntax error: Unterminated quoted string
            self.assertTrue(a.output.startswith("/bin/sh"))
            self.assertEqual(3, a.exit_status)
        else:
            self.assertEqual('Not a valid shell command: No closing quotation', a.output)
            self.assertEqual(3, a.exit_status)
Пример #20
0
    def test_grep_for_environment_variables(self):
        if os.name == 'nt':
            return

        a = Action()
        a.timeout = 10
        a.env = {}  # :fixme: this sould be pre-set in Action.__init__()

        a.command = "/usr/bin/env | grep TITI"

        self.assertNotIn('TITI', a.get_local_environnement())
        a.env = {'TITI': 'est en vacance'}
        self.assertIn('TITI', a.get_local_environnement())
        self.assertEqual(a.get_local_environnement()['TITI'], 'est en vacance')
        a.execute()
        self.wait_finished(a)
        self.assertEqual(a.output, 'TITI=est en vacance')