The function checks the SHA1 sum of a given file before and after a block of code is executed, verifying that the content of the file remains the same.
Signed-off-by: Petr Pudlak <[email protected]> --- qa/qa_utils.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/qa/qa_utils.py b/qa/qa_utils.py index 9051e97..35fc5a2 100644 --- a/qa/qa_utils.py +++ b/qa/qa_utils.py @@ -32,6 +32,7 @@ """ +import contextlib import copy import datetime import operator @@ -458,6 +459,29 @@ def BackupFile(node, path): return result [email protected] +def CheckFileUnmodified(node, filename): + """Checks that the content of a given file remains the same after running a + wrapped code. + + @type node: string + @param node: node the command should run on + @type filename: string + @param filename: absolute filename to check + """ + cmd = utils.ShellQuoteArgs(["sha1sum", filename]) + def Read(): + return GetCommandOutput(node, cmd).strip() + # read the configuration + before = Read() + yield + # check that the configuration hasn't changed + after = Read() + if before != after: + raise qa_error.Error("File '%s' has changed unexpectedly on node %s" + " during the last operation" % (filename, node)) + + def ResolveInstanceName(instance): """Gets the full name of an instance. -- 2.2.0.rc0.207.ga3a616c
