View | Details | Raw Unified | Return to bug 34593
Collapse All | Expand All

(-)a/branches/ucs-3.2/ucs-3.2-2/test/ucs-test/tests/60_umc-system/22_umc-service-proc-killing (-5 / +3 lines)
 Lines 65-71   class TestUMCProcessKilling(TestUMCSystem): Link Here 
65
            print("Created process with pid '%s' was not terminated, "
65
            print("Created process with pid '%s' was not terminated, "
66
                  "forcing kill" % self.Proc.pid)
66
                  "forcing kill" % self.Proc.pid)
67
            self.Proc.kill()
67
            self.Proc.kill()
68
            exit_status = wait4(self.Proc.pid, WNOHANG)[1]
68
            _pid, exit_status, _res_usage = wait4(self.Proc.pid, WNOHANG)
69
            if exit_status != 9:
69
            if exit_status != 9:
70
                print("The exit status while force kill is '%s' "
70
                print("The exit status while force kill is '%s' "
71
                      "instead of 'SIGKILL' code 9." % exit_status)
71
                      "instead of 'SIGKILL' code 9." % exit_status)
 Lines 97-103   class TestUMCProcessKilling(TestUMCSystem): Link Here 
97
            pid = self.create_process()
97
            pid = self.create_process()
98
            if self.query_process_exists(pid):
98
            if self.query_process_exists(pid):
99
                self.make_kill_request('SIGTERM', [pid])
99
                self.make_kill_request('SIGTERM', [pid])
100
                exit_status = wait4(pid, WNOHANG)[1]
100
                _pid, exit_status, _res_usage = wait4(pid, WNOHANG)
101
                if exit_status != 15:
101
                if exit_status != 15:
102
                    utils.fail("Process exit status is '%s' instead of "
102
                    utils.fail("Process exit status is '%s' instead of "
103
                               "'SIGTERM' code 15." % exit_status)
103
                               "'SIGTERM' code 15." % exit_status)
 Lines 115-121   class TestUMCProcessKilling(TestUMCSystem): Link Here 
115
            pid = self.create_process()
115
            pid = self.create_process()
116
            if self.query_process_exists(pid):
116
            if self.query_process_exists(pid):
117
                self.make_kill_request('SIGKILL', [pid])
117
                self.make_kill_request('SIGKILL', [pid])
118
                exit_status = wait4(pid, WNOHANG)[1]
118
                _pid, exit_status, _res_usage = wait4(pid, WNOHANG)
119
                if exit_status != 9:
119
                if exit_status != 9:
120
                    utils.fail("Process exit status is '%s' instead of "
120
                    utils.fail("Process exit status is '%s' instead of "
121
                               "'SIGKILL' code 9." % exit_status)
121
                               "'SIGKILL' code 9." % exit_status)
122
- 
123
--
124
.../test/ucs-test/tests/60_umc-system/22_umc-service-proc-killing   | 6 +++---
122
.../test/ucs-test/tests/60_umc-system/22_umc-service-proc-killing   | 6 +++---
125
1 file changed, 3 insertions(+), 3 deletions(-)
123
1 file changed, 3 insertions(+), 3 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-2/test/ucs-test/tests/60_umc-system/22_umc-service-proc-killing (-5 / +3 lines)
 Lines 53-61   class TestUMCProcessKilling(TestUMCSystem): Link Here 
53
                    if 'python' in result['command']:
53
                    if 'python' in result['command']:
54
                        return True
54
                        return True
55
            except KeyError as exc:
55
            except KeyError as exc:
56
                utils.fail("Failed to find 'pid' or 'command' keys in"
56
                utils.fail("Failed to find key '%s' in"
57
                           "the 'top/query' request respone from UMC: %s"
57
                           "the 'top/query' request respone from UMC: %r"
58
                           % result)
58
                           % (exc, result))
59
59
60
    def force_process_kill(self):
60
    def force_process_kill(self):
61
        """
61
        """
62
- 
63
--
64
.../60_umc-system/22_umc-service-proc-killing      | 22 +++++++++++-----------
62
.../60_umc-system/22_umc-service-proc-killing      | 22 +++++++++++-----------
65
1 file changed, 11 insertions(+), 11 deletions(-)
63
1 file changed, 11 insertions(+), 11 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-2/test/ucs-test/tests/60_umc-system/22_umc-service-proc-killing (-13 / +11 lines)
 Lines 8-15   sys.path.insert(0, '.') Link Here 
8
from TestUMCSystemModule import TestUMCSystem
8
from TestUMCSystemModule import TestUMCSystem
9
9
10
from psutil import Process
10
from psutil import Process
11
from os import wait4, WNOHANG
11
from os import wait4, WNOHANG, WTERMSIG
12
from subprocess import Popen
12
import signal
13
13
14
from univention.config_registry import ConfigRegistry
14
from univention.config_registry import ConfigRegistry
15
import univention.testing.utils as utils
15
import univention.testing.utils as utils
 Lines 66-74   class TestUMCProcessKilling(TestUMCSystem): Link Here 
66
                  "forcing kill" % self.Proc.pid)
66
                  "forcing kill" % self.Proc.pid)
67
            self.Proc.kill()
67
            self.Proc.kill()
68
            _pid, exit_status, _res_usage = wait4(self.Proc.pid, WNOHANG)
68
            _pid, exit_status, _res_usage = wait4(self.Proc.pid, WNOHANG)
69
            if exit_status != 9:
69
            if WTERMSIG(exit_status) != signal.SIGKILL:
70
                print("The exit status while force kill is '%s' "
70
                print("The exit status while force kill is 0x%x "
71
                      "instead of 'SIGKILL' code 9." % exit_status)
71
                      "instead of 'SIGKILL'(%d)." % (exit_status, signal.SIGKILL))
72
72
73
    def create_process(self):
73
    def create_process(self):
74
        """
74
        """
 Lines 98-106   class TestUMCProcessKilling(TestUMCSystem): Link Here 
98
            if self.query_process_exists(pid):
98
            if self.query_process_exists(pid):
99
                self.make_kill_request('SIGTERM', [pid])
99
                self.make_kill_request('SIGTERM', [pid])
100
                _pid, exit_status, _res_usage = wait4(pid, WNOHANG)
100
                _pid, exit_status, _res_usage = wait4(pid, WNOHANG)
101
                if exit_status != 15:
101
                if WTERMSIG(exit_status) != signal.SIGTERM:
102
                    utils.fail("Process exit status is '%s' instead of "
102
                    utils.fail("Process exit status is 0x%x instead of "
103
                               "'SIGTERM' code 15." % exit_status)
103
                               "SIGTERM(%d)." % (exit_status, signal.SIGTERM))
104
                if self.query_process_exists(pid):
104
                if self.query_process_exists(pid):
105
                    utils.fail("Process did not terminate after request "
105
                    utils.fail("Process did not terminate after request "
106
                               "with 'SIGTERM' signal")
106
                               "with 'SIGTERM' signal")
 Lines 116-124   class TestUMCProcessKilling(TestUMCSystem): Link Here 
116
            if self.query_process_exists(pid):
116
            if self.query_process_exists(pid):
117
                self.make_kill_request('SIGKILL', [pid])
117
                self.make_kill_request('SIGKILL', [pid])
118
                _pid, exit_status, _res_usage = wait4(pid, WNOHANG)
118
                _pid, exit_status, _res_usage = wait4(pid, WNOHANG)
119
                if exit_status != 9:
119
                if WTERMSIG(exit_status) != signal.SIGKILL:
120
                    utils.fail("Process exit status is '%s' instead of "
120
                    utils.fail("Process exit status is 0x%x instead of "
121
                               "'SIGKILL' code 9." % exit_status)
121
                               "SIGKILL(%d)." % (exit_status, signal.SIGKILL))
122
                if self.query_process_exists(pid):
122
                if self.query_process_exists(pid):
123
                    utils.fail("Process did not terminate after request "
123
                    utils.fail("Process did not terminate after request "
124
                               "with 'SIGKILL' signal")
124
                               "with 'SIGKILL' signal")
125
- 
126
--
127
.../60_umc-system/22_umc-service-proc-killing      | 49 +++++++++-------------
125
.../60_umc-system/22_umc-service-proc-killing      | 49 +++++++++-------------
128
1 file changed, 19 insertions(+), 30 deletions(-)
126
1 file changed, 19 insertions(+), 30 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-2/test/ucs-test/tests/60_umc-system/22_umc-service-proc-killing (-32 / +19 lines)
 Lines 83-131   class TestUMCProcessKilling(TestUMCSystem): Link Here 
83
        self.Proc = Process(pid)
83
        self.Proc = Process(pid)
84
        return pid
84
        return pid
85
85
86
    def main(self):
86
    def test(self, signame):
87
        """
87
        print "Testing UMC process killing with signal '%s'" % signame
88
        Method to start the test of the UMC backend
88
        signum = getattr(signal, signame)
89
        process killing functionality.
90
        """
91
        self.get_ucr_credentials()
92
        self.create_connection_authenticate()
93
94
        # case 1: killing process using signal 'SIGTERM'
95
        try:
89
        try:
96
            print "Testing UMC process killing with 'SIGTERM' signal"
97
            pid = self.create_process()
90
            pid = self.create_process()
98
            if self.query_process_exists(pid):
91
            if self.query_process_exists(pid):
99
                self.make_kill_request('SIGTERM', [pid])
92
                self.make_kill_request(signame, [pid])
100
                _pid, exit_status, _res_usage = wait4(pid, WNOHANG)
93
                _pid, exit_status, _res_usage = wait4(pid, WNOHANG)
101
                if WTERMSIG(exit_status) != signal.SIGTERM:
94
                if WTERMSIG(exit_status) != signum:
102
                    utils.fail("Process exit status is 0x%x instead of "
95
                    utils.fail("Process exit status is 0x%x instead of "
103
                               "SIGTERM(%d)." % (exit_status, signal.SIGTERM))
96
                               "%s(%d)." % (exit_status, signame, signum))
104
                if self.query_process_exists(pid):
97
                if self.query_process_exists(pid):
105
                    utils.fail("Process did not terminate after request "
98
                    utils.fail("Process did not terminate after request "
106
                               "with 'SIGTERM' signal")
99
                               "with signal %s" % (signame))
107
            else:
100
            else:
108
                utils.fail("The process is not running right after creation")
101
                utils.fail("The process is not running right after creation")
109
        finally:
102
        finally:
110
            self.force_process_kill()
103
            self.force_process_kill()
111
104
105
    def main(self):
106
        """
107
        Method to start the test of the UMC backend
108
        process killing functionality.
109
        """
110
        self.get_ucr_credentials()
111
        self.create_connection_authenticate()
112
113
        # case 1: killing process using signal 'SIGTERM'
114
        self.test('SIGTERM')
115
112
        # case 2: killing process using signal 'SIGKILL'
116
        # case 2: killing process using signal 'SIGKILL'
113
        try:
117
        self.test('SIGKILL')
114
            print "Testing UMC process killing with 'SIGKILL' signal"
115
            pid = self.create_process()
116
            if self.query_process_exists(pid):
117
                self.make_kill_request('SIGKILL', [pid])
118
                _pid, exit_status, _res_usage = wait4(pid, WNOHANG)
119
                if WTERMSIG(exit_status) != signal.SIGKILL:
120
                    utils.fail("Process exit status is 0x%x instead of "
121
                               "SIGKILL(%d)." % (exit_status, signal.SIGKILL))
122
                if self.query_process_exists(pid):
123
                    utils.fail("Process did not terminate after request "
124
                               "with 'SIGKILL' signal")
125
            else:
126
                utils.fail("The process is not running right after creation")
127
        finally:
128
            self.force_process_kill()
129
118
130
119
131
if __name__ == '__main__':
120
if __name__ == '__main__':
132
- 
133
--
134
.../60_umc-system/22_umc-service-proc-killing      | 22 +++++++++++++---------
121
.../60_umc-system/22_umc-service-proc-killing      | 22 +++++++++++++---------
135
1 file changed, 13 insertions(+), 9 deletions(-)
122
1 file changed, 13 insertions(+), 9 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-2/test/ucs-test/tests/60_umc-system/22_umc-service-proc-killing (-11 / +13 lines)
 Lines 8-15   sys.path.insert(0, '.') Link Here 
8
from TestUMCSystemModule import TestUMCSystem
8
from TestUMCSystemModule import TestUMCSystem
9
9
10
from psutil import Process
10
from psutil import Process
11
from os import wait4, WNOHANG, WTERMSIG
11
from os import wait4, WNOHANG, WTERMSIG, fork
12
import signal
12
import signal
13
from time import sleep
13
14
14
from univention.config_registry import ConfigRegistry
15
from univention.config_registry import ConfigRegistry
15
import univention.testing.utils as utils
16
import univention.testing.utils as utils
 Lines 50-56   class TestUMCProcessKilling(TestUMCSystem): Link Here 
50
        for result in request_result:
51
        for result in request_result:
51
            try:
52
            try:
52
                if result['pid'] == pid:
53
                if result['pid'] == pid:
53
                    if 'python' in result['command']:
54
                    if sys.executable in result['command']:
54
                        return True
55
                        return True
55
            except KeyError as exc:
56
            except KeyError as exc:
56
                utils.fail("Failed to find key '%s' in"
57
                utils.fail("Failed to find key '%s' in"
 Lines 70-87   class TestUMCProcessKilling(TestUMCSystem): Link Here 
70
                print("The exit status while force kill is 0x%x "
71
                print("The exit status while force kill is 0x%x "
71
                      "instead of 'SIGKILL'(%d)." % (exit_status, signal.SIGKILL))
72
                      "instead of 'SIGKILL'(%d)." % (exit_status, signal.SIGKILL))
72
73
73
    def create_process(self):
74
    def create_process(self, ignore_sigterm=False):
74
        """
75
        """
75
        Initiates a simple test process that should be killed after.
76
        Initiates a simple test process that should be killed after.
76
        Creates a psutil Process class to check running state
77
        Creates a psutil Process class to check running state
77
        before terminating. Also returns process id (pid).
78
        before terminating. Also returns process id (pid).
78
        """
79
        """
79
        proc = Popen(['python',
80
        pid = fork()
80
                      '-c',
81
        if pid:  # parent
81
                      'from time import sleep \nsleep(30)'])
82
            self.Proc = Process(pid)
82
        pid = proc.pid
83
            return pid
83
        self.Proc = Process(pid)
84
        else:  # child under test
84
        return pid
85
            if ignore_sigterm:
86
                signal.signal(signal.SIGTERM, signal.SIG_IGN)
87
            sleep(30)
88
            sys.exit(0)
85
89
86
    def test(self, signame):
90
    def test(self, signame):
87
        print "Testing UMC process killing with signal '%s'" % signame
91
        print "Testing UMC process killing with signal '%s'" % signame
88
- 
89
--
90
.../ucs-test/tests/60_umc-system/22_umc-service-proc-killing | 12 ++++++++----
92
.../ucs-test/tests/60_umc-system/22_umc-service-proc-killing | 12 ++++++++----
91
1 file changed, 8 insertions(+), 4 deletions(-)
93
1 file changed, 8 insertions(+), 4 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-2/test/ucs-test/tests/60_umc-system/22_umc-service-proc-killing (-5 / +8 lines)
 Lines 57-62   class TestUMCProcessKilling(TestUMCSystem): Link Here 
57
                utils.fail("Failed to find key '%s' in"
57
                utils.fail("Failed to find key '%s' in"
58
                           "the 'top/query' request respone from UMC: %r"
58
                           "the 'top/query' request respone from UMC: %r"
59
                           % (exc, result))
59
                           % (exc, result))
60
        return False
60
61
61
    def force_process_kill(self):
62
    def force_process_kill(self):
62
        """
63
        """
 Lines 87-104   class TestUMCProcessKilling(TestUMCSystem): Link Here 
87
            sleep(30)
88
            sleep(30)
88
            sys.exit(0)
89
            sys.exit(0)
89
90
90
    def test(self, signame):
91
    def test(self, signame, ignore_signal=False):
91
        print "Testing UMC process killing with signal '%s'" % signame
92
        print "Testing UMC process killing with signal '%s'" % signame
92
        signum = getattr(signal, signame)
93
        signum = getattr(signal, signame)
93
        try:
94
        try:
94
            pid = self.create_process()
95
            pid = self.create_process(ignore_signal)
95
            if self.query_process_exists(pid):
96
            if self.query_process_exists(pid):
96
                self.make_kill_request(signame, [pid])
97
                self.make_kill_request(signame, [pid])
97
                _pid, exit_status, _res_usage = wait4(pid, WNOHANG)
98
                _pid, exit_status, _res_usage = wait4(pid, WNOHANG)
98
                if WTERMSIG(exit_status) != signum:
99
                if ignore_signal != (WTERMSIG(exit_status) != signum):
99
                    utils.fail("Process exit status is 0x%x instead of "
100
                    utils.fail("Process exit status is 0x%x instead of "
100
                               "%s(%d)." % (exit_status, signame, signum))
101
                               "%s(%d)." % (exit_status, signame, signum))
101
                if self.query_process_exists(pid):
102
                if ignore_signal != self.query_process_exists(pid):
102
                    utils.fail("Process did not terminate after request "
103
                    utils.fail("Process did not terminate after request "
103
                               "with signal %s" % (signame))
104
                               "with signal %s" % (signame))
104
            else:
105
            else:
 Lines 120-125   class TestUMCProcessKilling(TestUMCSystem): Link Here 
120
        # case 2: killing process using signal 'SIGKILL'
121
        # case 2: killing process using signal 'SIGKILL'
121
        self.test('SIGKILL')
122
        self.test('SIGKILL')
122
123
124
        # case 3: killing unwilling process using signal 'SIGTERM'
125
        self.test('SIGTERM', ignore_signal=True)
126
123
127
124
if __name__ == '__main__':
128
if __name__ == '__main__':
125
    TestUMC = TestUMCProcessKilling()
129
    TestUMC = TestUMCProcessKilling()
126
- 

Return to bug 34593