예제 #1
0
 def test_run_commands_many_commands(self, system, load_config):
     load_config.return_value = {
         'pre-restart': ['testdata/pre.sh', 'testdata/pre2.sh'],
     }
     run_commands('pre-restart')
     calls = [call("testdata/pre.sh"), call("testdata/pre2.sh")]
     system.assert_has_calls(calls)
예제 #2
0
 def test_run_commands_without_config(self, set_uid, check_output,
                                      load_config):
     load_config.return_value = {
         'hooks': {'pre-restart': []}
     }
     run_commands('pre-restart', watcher=self.watcher)
     self.assertFalse(check_output.called)
예제 #3
0
 def test_run_commands_config_without_a_hook(self, set_uid, Stream,
                                             check_output, load_config):
     load_config.return_value = {
         'hooks': {
             'pre-restart': ['testdata/pre.sh'],
         }
     }
     run_commands('post-restart', watcher=self.watcher)
예제 #4
0
 def test_run_commands_config_without_a_hook(self, set_uid, Stream,
                                             check_output, load_config):
     load_config.return_value = {
         'hooks': {
             'pre-restart': ['testdata/pre.sh'],
         }
     }
     run_commands('post-restart', watcher=self.watcher)
예제 #5
0
 def test_log_only_when_commands_are_executed(self, set_uid,
                                              Stream, load_config):
     load_config.return_value = {
         'hooks': {
             'pre-restart': ['ps -ef'],
         }
     }
     stream = Stream.return_value
     run_commands('post-restart', watcher=self.watcher)
     self.assertFalse(stream.called)
예제 #6
0
 def test_log_only_when_commands_are_executed(self, set_uid, Stream,
                                              load_config):
     load_config.return_value = {
         'hooks': {
             'pre-restart': ['ps -ef'],
         }
     }
     stream = Stream.return_value
     run_commands('post-restart', watcher=self.watcher)
     self.assertFalse(stream.called)
예제 #7
0
 def test_run_commands_with_config(self, set_uid, check_output,
                                   load_config):
     load_config.return_value = {
         'hooks': {
             'pre-restart': ['testdata/pre.sh'],
         }
     }
     set_uid.return_value = 10
     run_commands('pre-restart', watcher=self.watcher)
     check_output.assert_called_with(self.cmd("testdata/pre.sh"),
                                     stderr=subprocess.STDOUT,
                                     cwd=self.watcher.working_dir,
                                     preexec_fn=10)
예제 #8
0
 def test_run_commands_with_config(self, set_uid,
                                   check_output, load_config):
     load_config.return_value = {
         'hooks': {
             'pre-restart': ['testdata/pre.sh'],
         }
     }
     set_uid.return_value = 10
     run_commands('pre-restart', watcher=self.watcher)
     check_output.assert_called_with(self.cmd("testdata/pre.sh"),
                                     stderr=subprocess.STDOUT,
                                     cwd=self.watcher.working_dir,
                                     preexec_fn=10)
예제 #9
0
 def test_run_commands_should_log(self, set_uid, Stream,
                                  check_output, load_config):
     load_config.return_value = {
         'hooks': {
             'pre-restart': ['testdata/pre.sh'],
         }
     }
     check_output.return_value = "ble"
     stream = Stream.return_value
     run_commands('pre-restart', watcher=self.watcher)
     calls = [call({"data": " ---> Running pre-restart"}),
              call({"data": "ble"})]
     stream.assert_has_calls(calls)
예제 #10
0
 def test_run_commands_should_log(self, set_uid, Stream, check_output,
                                  load_config):
     load_config.return_value = {
         'hooks': {
             'pre-restart': ['testdata/pre.sh'],
         }
     }
     check_output.return_value = "ble"
     stream = Stream.return_value
     run_commands('pre-restart', watcher=self.watcher)
     calls = [
         call({"data": " ---> Running pre-restart"}),
         call({"data": "ble"})
     ]
     stream.assert_has_calls(calls)
예제 #11
0
 def test_run_commands_that_returns_errors(self, set_uid, Stream,
                                           check_output, load_config):
     load_config.return_value = {
         'hooks': {
             'pre-restart': ['exit 1'],
         }
     }
     stream = Stream.return_value
     check_output.side_effect = subprocess.CalledProcessError(1, "cmd")
     run_commands('pre-restart', watcher=self.watcher)
     calls = [
         call({'data': ' ---> Running pre-restart'}),
         call({'data': "Command 'cmd' returned non-zero exit status 1"}),
         call({'data': None})
     ]
     stream.assert_has_calls(calls)
예제 #12
0
 def test_run_commands_that_returns_errors(self, set_uid, Stream,
                                           check_output, load_config):
     load_config.return_value = {
         'hooks': {
             'pre-restart': ['exit 1'],
         }
     }
     stream = Stream.return_value
     check_output.side_effect = subprocess.CalledProcessError(1, "cmd")
     run_commands('pre-restart', watcher=self.watcher)
     calls = [
         call({'data': ' ---> Running pre-restart'}),
         call({'data': "Command 'cmd' returned non-zero exit status 1"}),
         call({'data': None})
     ]
     stream.assert_has_calls(calls)
예제 #13
0
 def test_should_return_true(self, set_uid, Stream, check_output,
                             load_config):
     result = run_commands('pre-restart', watcher=self.watcher)
     self.assertTrue(result)
예제 #14
0
 def test_run_commands_config_without_hooks(self, set_uid, Stream,
                                            check_output, load_config):
     load_config.return_value = {}
     run_commands('post-restart', watcher=self.watcher)
예제 #15
0
 def test_run_commands_config_without_hooks(self, set_uid, Stream,
                                            check_output, load_config):
     load_config.return_value = {}
     run_commands('post-restart', watcher=self.watcher)
예제 #16
0
 def test_should_return_true(self, set_uid, Stream, check_output,
                             load_config):
     result = run_commands('pre-restart', watcher=self.watcher)
     self.assertTrue(result)
예제 #17
0
 def test_run_commands_without_config(self, system, load_config):
     load_config.return_value = {
         'pre-restart': [],
     }
     run_commands('pre-restart')
     self.assertFalse(system.called)
예제 #18
0
 def test_run_commands_without_config(self, set_uid, check_output,
                                      load_config):
     load_config.return_value = {'hooks': {'pre-restart': []}}
     run_commands('pre-restart', watcher=self.watcher)
     self.assertFalse(check_output.called)
예제 #19
0
 def test_run_commands_with_config(self, system, load_config):
     load_config.return_value = {
         'pre-restart': ['testdata/pre.sh'],
     }
     run_commands('pre-restart')
     system.assert_called_with("testdata/pre.sh")