azure-linux-automation/remote-scripts/BVT-VERIFY-BASH-HISTORY.py

39 строки
1.1 KiB
Python
Исходник Обычный вид История

2015-12-16 09:33:03 +03:00
#! /usr/bin/env python
from azuremodules import *
import os
import os.path
root_bash_hist_file = '/root/.bash_history'
root_bash_hist_file_default = '/root/default_bash_history'
def RunTest():
UpdateState("TestRunning")
if os.path.exists(root_bash_hist_file_default):
RunLog.info("This is a prepared image, check the copied default history file: %s" % root_bash_hist_file_default)
2015-12-17 08:31:55 +03:00
result, hist_file_content = IsBashHistFileEmpty(root_bash_hist_file_default)
2015-12-16 09:33:03 +03:00
elif os.path.exists(root_bash_hist_file):
RunLog.info("This is a unprepared image, check the original history file: %s" % root_bash_hist_file)
2015-12-17 08:31:55 +03:00
result, hist_file_content = IsBashHistFileEmpty(root_bash_hist_file)
2015-12-16 09:33:03 +03:00
else:
RunLog.info("No bash history file exists.")
result = True
if result:
ResultLog.info('PASS')
RunLog.info("Empty, as expected.")
else:
ResultLog.error('FAIL')
RunLog.error("Not empty, non-expected.")
2015-12-17 08:31:55 +03:00
RunLog.info("Content:\n%s" % hist_file_content)
2015-12-16 09:33:03 +03:00
UpdateState("TestCompleted")
def IsBashHistFileEmpty(file):
2015-12-17 08:31:55 +03:00
if os.stat(file).st_size == 0:
return True, ''
else:
with open(file,'r') as f:
return False, f.read()
2015-12-16 09:33:03 +03:00
RunTest()