def test_run_restart_hooks_calls_stream(self, popen_call, stream_mock): out1 = ['stdout_out1', ''] out2 = ['stderr_out1', ''] popen_call.return_value.stdout.readline.side_effect = lambda: out1.pop(0) popen_call.return_value.stderr.readline.side_effect = lambda: out2.pop(0) wait_mock = popen_call.return_value.wait wait_mock.return_value = 0 data = {"hooks": {"restart": { "before": ["b1"], }}} run_restart_hooks('before', data, envs={'env': 'varrr'}) self.assertEqual(os.environ, {'env': 'var', 'env1': 'var1'}) self.assertEqual(popen_call.call_count, 1) self.assertEqual(popen_call.call_args_list[0][0][0], ['/bin/bash', '-lc', 'b1']) self.assertEqual(popen_call.call_args_list[0][1]['shell'], False) self.assertEqual(popen_call.call_args_list[0][1]['cwd'], '/') self.assertEqual(popen_call.call_args_list[0][1]['env'], {'env': 'varrr', 'env1': 'var1'}) wait_mock.assert_called_once_with() self.assertEqual(stream_mock.call_count, 2) self.assertEqual(stream_mock.call_args_list[0][1]['echo_output'], sys.stdout) self.assertEqual(stream_mock.call_args_list[0][1]['default_stream_name'], 'stdout') self.assertEqual(stream_mock.call_args_list[0][1]['watcher_name'], 'unit-agent') self.assertEqual(stream_mock.call_args_list[0][1]['envs'], {'env': 'varrr', 'env1': 'var1'}) self.assertEqual(stream_mock.call_args_list[1][1]['echo_output'], sys.stderr) self.assertEqual(stream_mock.call_args_list[1][1]['default_stream_name'], 'stderr') self.assertEqual(stream_mock.call_args_list[1][1]['watcher_name'], 'unit-agent') self.assertEqual(stream_mock.call_args_list[1][1]['envs'], {'env': 'varrr', 'env1': 'var1'}) write_mock = stream_mock.return_value.write write_mock.assert_any_call('stdout_out1') write_mock.assert_any_call('stderr_out1') stream_mock.return_value.flush.assert_any_call() stream_mock.return_value.close.assert_any_call()
def test_run_restart_hooks(self, popen_call, Stream): popen_call.return_value.stdout.readline.return_value = '' popen_call.return_value.stderr.readline.return_value = '' wait_mock = popen_call.return_value.wait wait_mock.return_value = 0 data = { "hooks": { "restart": { "before": ["b1"], "before-each": ["b2"], "after": ["a1"], "after-each": ["a2"], } } } run_restart_hooks('before', data, envs={'env': 'varrr'}) self.assertEqual(popen_call.call_count, 2) self.assertEqual(popen_call.call_args_list[0][0][0], ['/bin/bash', '-lc', 'b2']) self.assertEqual(popen_call.call_args_list[0][1]['shell'], False) self.assertEqual(popen_call.call_args_list[0][1]['cwd'], '/') self.assertEqual(popen_call.call_args_list[0][1]['env'], { 'env': 'varrr', 'env1': 'var1' }) self.assertEqual(popen_call.call_args_list[1][0][0], ['/bin/bash', '-lc', 'b1']) wait_mock.assert_any_call() run_restart_hooks('after', data) self.assertEqual(popen_call.call_count, 4) self.assertEqual(popen_call.call_args_list[3][0][0], ['/bin/bash', '-lc', 'a1']) self.assertEqual(popen_call.call_args_list[2][0][0], ['/bin/bash', '-lc', 'a2'])
def test_run_restart_hooks_calls_stream(self, popen_call, stream_mock): out1 = ['stdout_out1', ''] out2 = ['stderr_out1', ''] popen_call.return_value.stdout.readline.side_effect = lambda: out1.pop( 0) popen_call.return_value.stderr.readline.side_effect = lambda: out2.pop( 0) wait_mock = popen_call.return_value.wait wait_mock.return_value = 0 data = { "hooks": { "restart": { "before": ["b1"], } } } run_restart_hooks('before', data, envs={'env': 'varrr'}) self.assertEqual(os.environ, {'env': 'var', 'env1': 'var1'}) self.assertEqual(popen_call.call_count, 1) self.assertEqual(popen_call.call_args_list[0][0][0], ['/bin/bash', '-lc', 'b1']) self.assertEqual(popen_call.call_args_list[0][1]['shell'], False) self.assertEqual(popen_call.call_args_list[0][1]['cwd'], '/') self.assertEqual(popen_call.call_args_list[0][1]['env'], { 'env': 'varrr', 'env1': 'var1' }) wait_mock.assert_called_once_with() self.assertEqual(stream_mock.call_count, 2) self.assertEqual(stream_mock.call_args_list[0][1]['echo_output'], sys.stdout) self.assertEqual( stream_mock.call_args_list[0][1]['default_stream_name'], 'stdout') self.assertEqual(stream_mock.call_args_list[0][1]['watcher_name'], 'unit-agent') self.assertEqual(stream_mock.call_args_list[0][1]['envs'], { 'env': 'varrr', 'env1': 'var1' }) self.assertEqual(stream_mock.call_args_list[1][1]['echo_output'], sys.stderr) self.assertEqual( stream_mock.call_args_list[1][1]['default_stream_name'], 'stderr') self.assertEqual(stream_mock.call_args_list[1][1]['watcher_name'], 'unit-agent') self.assertEqual(stream_mock.call_args_list[1][1]['envs'], { 'env': 'varrr', 'env1': 'var1' }) write_mock = stream_mock.return_value.write write_mock.assert_any_call('stdout_out1') write_mock.assert_any_call('stderr_out1') stream_mock.return_value.flush.assert_any_call() stream_mock.return_value.close.assert_any_call()
def run_action(args): client = Client(args.url, args.token) envs = None try: envs = client.register_unit(args.app_name) tasks.save_apprc_file(envs) except ConnectionError: envs = tasks.parse_apprc_file() yaml_data = tasks.load_app_yaml() tasks.write_circus_conf(envs=envs) tasks.run_restart_hooks('before', yaml_data, envs=envs) tasks.execute_start_script(args.start_cmd, envs=envs, with_shell=False) tasks.run_restart_hooks('after', yaml_data, envs=envs)
def run_action(args): client = Client(args.url, args.token) envs = None try: envs, supported_tsuru = client.register_unit(args.app_name) save_apprc_file(envs, supported_tsuru) except ConnectionError: envs = tasks.parse_apprc_file() yaml_data = tasks.load_app_yaml() tasks.write_circus_conf(envs=envs) tasks.run_restart_hooks('before', yaml_data, envs=envs) tasks.execute_start_script(args.start_cmd, envs=envs, with_shell=False) tasks.run_restart_hooks('after', yaml_data, envs=envs) remove_temp_env_file()
def test_run_restart_hooks(self, popen_call, Stream): popen_call.return_value.stdout.readline.return_value = '' popen_call.return_value.stderr.readline.return_value = '' wait_mock = popen_call.return_value.wait wait_mock.return_value = 0 data = {"hooks": {"restart": { "before": ["b1"], "before-each": ["b2"], "after": ["a1"], "after-each": ["a2"], }}} run_restart_hooks('before', data, envs={'env': 'varrr'}) self.assertEqual(popen_call.call_count, 2) self.assertEqual(popen_call.call_args_list[0][0][0], ['/bin/bash', '-lc', 'b2']) self.assertEqual(popen_call.call_args_list[0][1]['shell'], False) self.assertEqual(popen_call.call_args_list[0][1]['cwd'], '/') self.assertEqual(popen_call.call_args_list[0][1]['env'], {'env': 'varrr', 'env1': 'var1'}) self.assertEqual(popen_call.call_args_list[1][0][0], ['/bin/bash', '-lc', 'b1']) wait_mock.assert_any_call() run_restart_hooks('after', data) self.assertEqual(popen_call.call_count, 4) self.assertEqual(popen_call.call_args_list[3][0][0], ['/bin/bash', '-lc', 'a1']) self.assertEqual(popen_call.call_args_list[2][0][0], ['/bin/bash', '-lc', 'a2'])