Revision 2f4b4f78 qa/qa_os.py

b/qa/qa_os.py
32 32
import qa_config
33 33
import qa_utils
34 34

  
35
from qa_utils import AssertEqual, StartSSH
35
from qa_utils import AssertCommand
36 36

  
37 37

  
38 38
_TEMP_OS_NAME = "TEMP-Ganeti-QA-OS"
......
41 41

  
42 42
def TestOsList():
43 43
  """gnt-os list"""
44
  master = qa_config.GetMasterNode()
45

  
46
  cmd = ['gnt-os', 'list']
47
  AssertEqual(StartSSH(master['primary'],
48
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
44
  AssertCommand(["gnt-os", "list"])
49 45

  
50 46

  
51 47
def TestOsDiagnose():
52 48
  """gnt-os diagnose"""
53
  master = qa_config.GetMasterNode()
54

  
55
  cmd = ['gnt-os', 'diagnose']
56
  AssertEqual(StartSSH(master['primary'],
57
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
49
  AssertCommand(["gnt-os", "diagnose"])
58 50

  
59 51

  
60
def _TestOsModify(hvp_dict, expected_result=0):
52
def _TestOsModify(hvp_dict, fail=False):
61 53
  """gnt-os modify"""
62
  master = qa_config.GetMasterNode()
63

  
64 54
  cmd = ['gnt-os', 'modify']
65 55

  
66 56
  for hv_name, hv_params in hvp_dict.items():
......
71 61
    cmd.append('%s:%s' % (hv_name, ','.join(options)))
72 62

  
73 63
  cmd.append(_TEMP_OS_NAME)
74
  AssertEqual(StartSSH(master['primary'],
75
                       utils.ShellQuoteArgs(cmd)).wait(), expected_result)
64
  AssertCommand(cmd, fail=fail)
76 65

  
77 66

  
78 67
def _TestOsStates():
79 68
  """gnt-os modify, more stuff"""
80
  master = qa_config.GetMasterNode()
81

  
82 69
  cmd = ["gnt-os", "modify"]
83 70

  
84 71
  for param in ["hidden", "blacklisted"]:
85 72
    for val in ["yes", "no"]:
86 73
      new_cmd = cmd + ["--%s" % param, val, _TEMP_OS_NAME]
87
      AssertEqual(StartSSH(master["primary"],
88
                           utils.ShellQuoteArgs(new_cmd)).wait(), 0)
74
      AssertCommand(new_cmd)
89 75
      # check that double-running the command is OK
90
      AssertEqual(StartSSH(master["primary"],
91
                           utils.ShellQuoteArgs(new_cmd)).wait(), 0)
76
      AssertCommand(new_cmd)
92 77

  
93 78

  
94 79
def _SetupTempOs(node, dir, valid):
......
115 100
                            (node["primary"],
116 101
                             ["an invalid", "a valid"][int(valid)]))
117 102

  
118
  AssertEqual(StartSSH(node['primary'], cmd).wait(), 0)
103
  AssertCommand(cmd, node=node)
119 104

  
120 105

  
121 106
def _RemoveTempOs(node, dir):
122 107
  """Removes a temporary OS definition.
123 108

  
124 109
  """
125
  cmd = ['rm', '-rf', dir]
126
  AssertEqual(StartSSH(node['primary'],
127
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
110
  AssertCommand(["rm", "-rf", dir], node=node)
128 111

  
129 112

  
130 113
def _TestOs(mode):
131 114
  """Generic function for OS definition testing
132 115

  
133 116
  """
134
  master = qa_config.GetMasterNode()
135 117
  dir = _TEMP_OS_PATH
136 118

  
137 119
  nodes = []
138 120
  try:
139
    i = 0
140
    for node in qa_config.get('nodes'):
121
    for i, node in enumerate(qa_config.get("nodes")):
141 122
      nodes.append(node)
142 123
      if mode == 0:
143 124
        valid = False
......
146 127
      else:
147 128
        valid = bool(i % 2)
148 129
      _SetupTempOs(node, dir, valid)
149
      i += 1
150

  
151
    cmd = ['gnt-os', 'diagnose']
152
    result = StartSSH(master['primary'],
153
                      utils.ShellQuoteArgs(cmd)).wait()
154
    if mode == 1:
155
      AssertEqual(result, 0)
156
    else:
157
      AssertEqual(result, 1)
130

  
131
    AssertCommand(["gnt-os", "diagnose"], fail=not mode==1)
158 132
  finally:
159 133
    for node in nodes:
160 134
      _RemoveTempOs(node, dir)
......
196 170
    "blahblahblubb": {"bar": ""},
197 171
    }
198 172

  
199
  return _TestOsModify(hv_dict, 1)
173
  return _TestOsModify(hv_dict, fail=True)
200 174

  
201 175

  
202 176
def TestOsStates():

Also available in: Unified diff