Revision 2f4b4f78 qa/qa_utils.py

b/qa/qa_utils.py
101 101
    raise qa_error.Error("%r doesn't match /%r/" % (string, pattern))
102 102

  
103 103

  
104
def AssertCommand(cmd, fail=False, node=None):
105
  """Checks that a remote command succeeds.
106

  
107
  @param cmd: either a string (the command to execute) or a list (to
108
      be converted using L{utils.ShellQuoteArgs} into a string)
109
  @type fail: boolean
110
  @param fail: if the command is expected to fail instead of succeeding
111
  @param node: if passed, it should be the node on which the command
112
      should be executed, instead of the master node (can be either a
113
      dict or a string)
114

  
115
  """
116
  if node is None:
117
    node = qa_config.GetMasterNode()
118

  
119
  if isinstance(node, basestring):
120
    nodename = node
121
  else:
122
    nodename = node["primary"]
123

  
124
  if isinstance(cmd, basestring):
125
    cmdstr = cmd
126
  else:
127
    cmdstr = utils.ShellQuoteArgs(cmd)
128

  
129
  rcode = StartSSH(nodename, cmdstr).wait()
130

  
131
  if fail:
132
    if rcode == 0:
133
      raise qa_error.Error("Command '%s' on node %s was expected to fail but"
134
                           " didn't" % (cmdstr, nodename))
135
  else:
136
    if rcode != 0:
137
      raise qa_error.Error("Command '%s' on node %s failed, exit code %s" %
138
                           (cmdstr, nodename, rcode))
139

  
140

  
104 141
def GetSSHCommand(node, cmd, strict=True):
105 142
  """Builds SSH command to be executed.
106 143

  

Also available in: Unified diff