Commit 2db10807 authored by Petr Pudlak's avatar Petr Pudlak

QA: Allow to check that an operation doesn't change a file

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: default avatarPetr Pudlak <>
Reviewed-by: default avatarKlaus Aehlig <>
parent e0161fc9
......@@ -32,6 +32,7 @@
import contextlib
import copy
import datetime
import operator
......@@ -488,6 +489,29 @@ def BackupFile(node, path):
return result
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()
# 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.
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment