本文整理汇总了Python中bootstrap.Bootstrap.copied_password_file方法的典型用法代码示例。如果您正苦于以下问题:Python Bootstrap.copied_password_file方法的具体用法?Python Bootstrap.copied_password_file怎么用?Python Bootstrap.copied_password_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bootstrap.Bootstrap
的用法示例。
在下文中一共展示了Bootstrap.copied_password_file方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_run
# 需要导入模块: from bootstrap import Bootstrap [as 别名]
# 或者: from bootstrap.Bootstrap import copied_password_file [as 别名]
def test_run(self, error_mock, warn_mock, write_mock, createDoneFile_mock,
hasPassword_mock, try_to_execute_mock):
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
"setupAgentFile", "ambariServer", "centos6",
None, "8440", "root")
bootstrap_obj = Bootstrap("hostname", shared_state)
# Testing workflow without password
bootstrap_obj.copied_password_file = False
hasPassword_mock.return_value = False
try_to_execute_mock.return_value = {"exitstatus": 0, "log":"log0", "errormsg":"errormsg0"}
bootstrap_obj.run()
self.assertEqual(try_to_execute_mock.call_count, 7) # <- Adjust if changed
self.assertTrue(createDoneFile_mock.called)
self.assertEqual(bootstrap_obj.getStatus()["return_code"], 0)
try_to_execute_mock.reset_mock()
createDoneFile_mock.reset_mock()
# Testing workflow with password
bootstrap_obj.copied_password_file = True
hasPassword_mock.return_value = True
try_to_execute_mock.return_value = {"exitstatus": 0, "log":"log0", "errormsg":"errormsg0"}
bootstrap_obj.run()
self.assertEqual(try_to_execute_mock.call_count, 10) # <- Adjust if changed
self.assertTrue(createDoneFile_mock.called)
self.assertEqual(bootstrap_obj.getStatus()["return_code"], 0)
error_mock.reset_mock()
write_mock.reset_mock()
try_to_execute_mock.reset_mock()
createDoneFile_mock.reset_mock()
# Testing workflow when some action failed before copying password
bootstrap_obj.copied_password_file = False
hasPassword_mock.return_value = False
try_to_execute_mock.side_effect = [{"exitstatus": 0, "log":"log0", "errormsg":"errormsg0"}, {"exitstatus": 1, "log":"log1", "errormsg":"errormsg1"}]
bootstrap_obj.run()
self.assertEqual(try_to_execute_mock.call_count, 2) # <- Adjust if changed
self.assertTrue("ERROR" in error_mock.call_args[0][0])
self.assertTrue("ERROR" in write_mock.call_args[0][0])
self.assertTrue(createDoneFile_mock.called)
self.assertEqual(bootstrap_obj.getStatus()["return_code"], 1)
try_to_execute_mock.reset_mock()
createDoneFile_mock.reset_mock()
# Testing workflow when some action failed after copying password
bootstrap_obj.copied_password_file = True
hasPassword_mock.return_value = True
try_to_execute_mock.side_effect = [{"exitstatus": 0, "log":"log0", "errormsg":"errormsg0"}, {"exitstatus": 42, "log":"log42", "errormsg":"errormsg42"}, {"exitstatus": 0, "log":"log0", "errormsg":"errormsg0"}]
bootstrap_obj.run()
self.assertEqual(try_to_execute_mock.call_count, 3) # <- Adjust if changed
self.assertTrue(createDoneFile_mock.called)
self.assertEqual(bootstrap_obj.getStatus()["return_code"], 42)
error_mock.reset_mock()
write_mock.reset_mock()
try_to_execute_mock.reset_mock()
createDoneFile_mock.reset_mock()
# Testing workflow when some action failed after copying password and
# removing password failed too
bootstrap_obj.copied_password_file = True
hasPassword_mock.return_value = True
try_to_execute_mock.side_effect = [{"exitstatus": 0, "log":"log0", "errormsg":"errormsg0"}, {"exitstatus": 17, "log":"log17", "errormsg":"errormsg17"}, {"exitstatus": 19, "log":"log19", "errormsg":"errormsg19"}]
bootstrap_obj.run()
self.assertEqual(try_to_execute_mock.call_count, 3) # <- Adjust if changed
self.assertTrue("ERROR" in write_mock.call_args_list[0][0][0])
self.assertTrue("ERROR" in error_mock.call_args[0][0])
self.assertTrue("WARNING" in write_mock.call_args_list[1][0][0])
self.assertTrue("WARNING" in warn_mock.call_args[0][0])
self.assertTrue(createDoneFile_mock.called)
self.assertEqual(bootstrap_obj.getStatus()["return_code"], 17)