Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

chaos: added OS class with the kill method

This method receives a process and the signal that must be sent to the
process. The default value is 9.
  • Loading branch information...
commit 3bbe3db565cf48795ddf358f460c9d3c009af3a9 1 parent 5ca62c5
Francisco Souza authored January 21, 2013
10  pantera/chaos.py
@@ -3,6 +3,7 @@
3 3
 # license that can be found in the LICENSE file.
4 4
 
5 5
 import random
  6
+import os
6 7
 
7 8
 
8 9
 class EC2(object):
@@ -63,3 +64,12 @@ def reboot(self):
63 64
 
64 65
     def __call__(self):
65 66
         self.reboot()
  67
+
  68
+
  69
+class OS(object):
  70
+
  71
+    def kill(self, process, signal=9):
  72
+        """
  73
+        Kills a process, sending the given signal.
  74
+        """
  75
+        os.kill(process, signal)
25  tests.py
@@ -5,8 +5,8 @@
5 5
 import unittest
6 6
 import mock
7 7
 
8  
-from pantera import chaos
9 8
 import pantera
  9
+from pantera import chaos
10 10
 
11 11
 
12 12
 class SimulatorCalled(Exception):
@@ -14,6 +14,7 @@ class SimulatorCalled(Exception):
14 14
 
15 15
 
16 16
 class RaisingSimulator(object):
  17
+
17 18
     def __init__(self, *args, **kwargs):
18 19
         pass
19 20
 
@@ -22,6 +23,7 @@ def __call__(self, *args, **kwargs):
22 23
 
23 24
 
24 25
 class PanterTestCase(unittest.TestCase):
  26
+
25 27
     @mock.patch("random.choice")
26 28
     def test_run_call(self, choice):
27 29
         choice.return_value = RaisingSimulator
@@ -36,6 +38,7 @@ def test_run_init(self, choice):
36 38
 
37 39
 
38 40
 class EC2TestCase(unittest.TestCase):
  41
+
39 42
     def test_init(self):
40 43
         ec2 = chaos.EC2("one", "two")
41 44
         self.assertEqual("one", ec2.access)
@@ -59,6 +62,7 @@ def test_connect(self, ec2con):
59 62
 
60 63
 
61 64
 class RebootTestCase(unittest.TestCase):
  65
+
62 66
     def test_reboot(self):
63 67
         from pantera import chaos
64 68
         vms = ["1"]
@@ -82,6 +86,7 @@ def test_call(self):
82 86
 
83 87
 
84 88
 class StopTestCase(unittest.TestCase):
  89
+
85 90
     def test_stop(self):
86 91
         vms = ["1"]
87 92
         conn = mock.Mock()
@@ -103,6 +108,7 @@ def test_call(self):
103 108
 
104 109
 
105 110
 class TerminateTestCase(unittest.TestCase):
  111
+
106 112
     def test_terminate(self):
107 113
         vms = ["1"]
108 114
         conn = mock.Mock()
@@ -121,3 +127,20 @@ def test_call(self):
121 127
         terminate.terminate = mock.Mock()
122 128
         terminate()
123 129
         terminate.terminate.assert_called_with()
  130
+
  131
+
  132
+class OSTestCase(unittest.TestCase):
  133
+
  134
+    @mock.patch("os.kill")
  135
+    def test_kill(self, kill):
  136
+        kill.return_value = True
  137
+        o = chaos.OS()
  138
+        o.kill(10000000, 15)
  139
+        kill.assert_called_with(10000000, 15)
  140
+
  141
+    @mock.patch("os.kill")
  142
+    def test_kill_default_value(self, kill):
  143
+        kill.return_value = True
  144
+        o = chaos.OS()
  145
+        o.kill(10000000)
  146
+        kill.assert_called_with(10000000, 9)

0 notes on commit 3bbe3db

Please sign in to comment.
Something went wrong with that request. Please try again.