示例#1
0
 def test_get_command_list(self):
     with temp_dir() as directory:
         runner = Runner(directory, ChaosMonkey.factory())
         with NamedTemporaryFile() as temp_file:
             self._write_command_list_to_file(temp_file)
             args = Namespace(replay=temp_file.name, restart=False)
             commands = runner._get_command_list(args)
     expected = [['deny-state-server', 1], ['deny-api-server', 1]]
     self.assertItemsEqual(commands, expected)
示例#2
0
 def test_replay_commands_with_restart_command(self):
     commands = "- [restart-unit, 1]\n- [deny-api-server, 1]\n"
     with patch('utility.check_output', autospec=True) as mock:
         with patch('runner.Init.install'):
             with temp_dir() as directory:
                 runner = Runner(directory, ChaosMonkey.factory())
                 with NamedTemporaryFile() as temp_file:
                     self._write_command_list_to_file(
                         temp_file, data=commands)
                     args = Namespace(replay=temp_file.name, restart=False)
                     runner.replay_commands(args)
                     # Verify a temporary file is created because there
                     # is a restart-unit command in the list.
                     self.assertIs(os.path.isfile(
                         temp_file.name + runner.replay_filename_ext), True)
                     args = Namespace(replay=temp_file.name, restart=True)
                     file_content = runner._get_command_list(args)
                     # Verify the temporary files is deleted.
                     self.assertIsNot(os.path.isfile(
                         temp_file.name + runner.replay_filename_ext), True)
     self.assertEqual(mock.mock_calls, [call(['shutdown', '-r', 'now'])])
     self.assertEqual(file_content, [yaml.load(commands)[1]])