Revision b9955569 qa/qa_utils.py

b/qa/qa_utils.py
218 218
    f.close()
219 219

  
220 220

  
221
def UploadData(node, data, mode=0600, filename=None):
222
  """Uploads data to a node and returns the filename.
223

  
224
  Caller needs to remove the returned file on the node when it's not needed
225
  anymore.
226

  
227
  """
228
  if filename:
229
    tmp = "tmp=%s" % utils.ShellQuote(filename)
230
  else:
231
    tmp = "tmp=$(tempfile --mode %o --prefix gnt)" % mode
232
  cmd = ("%s && "
233
         "[[ -f \"${tmp}\" ]] && "
234
         "cat > \"${tmp}\" && "
235
         "echo \"${tmp}\"") % tmp
236

  
237
  p = subprocess.Popen(GetSSHCommand(node, cmd), shell=False,
238
                       stdin=subprocess.PIPE, stdout=subprocess.PIPE)
239
  p.stdin.write(data)
240
  p.stdin.close()
241
  AssertEqual(p.wait(), 0)
242

  
243
  # Return temporary filename
244
  return p.stdout.read().strip()
245

  
246

  
221 247
def BackupFile(node, path):
222 248
  """Creates a backup of a file on the node and returns the filename.
223 249

  

Also available in: Unified diff