Revision 2932dc44 qa/qa_os.py

b/qa/qa_os.py
31 31

  
32 32
import qa_config
33 33
import qa_utils
34
import qa_error
34 35

  
35
from qa_utils import AssertCommand
36
from qa_utils import AssertCommand, AssertIn, AssertNotIn
36 37

  
37 38

  
38 39
_TEMP_OS_NAME = "TEMP-Ganeti-QA-OS"
......
114 115
  AssertCommand(["rm", "-rf", dirname], node=node)
115 116

  
116 117

  
117
def _TestOs(mode):
118
def _TestOs(mode, rapi_cb):
118 119
  """Generic function for OS definition testing
119 120

  
120 121
  """
122
  master = qa_config.GetMasterNode()
123

  
124
  name = _TEMP_OS_NAME
121 125
  dirname = _TEMP_OS_PATH
122 126

  
127
  # Ensure OS is usable
128
  cmd = ["gnt-os", "modify", "--hidden=no", "--blacklisted=no", name]
129
  AssertCommand(cmd)
130

  
123 131
  nodes = []
124 132
  try:
125 133
    for i, node in enumerate(qa_config.get("nodes")):
......
134 142
        raise AssertionError("Unknown mode %s" % mode)
135 143
      _SetupTempOs(node, dirname, valid)
136 144

  
137
    AssertCommand(["gnt-os", "diagnose"], fail=(mode != _ALL_VALID))
145
    # TODO: Use Python 2.6's itertools.permutations
146
    for (hidden, blacklisted) in [(False, False), (True, False),
147
                                  (False, True), (True, True)]:
148
      # Change OS' visibility
149
      cmd = ["gnt-os", "modify", "--hidden", ["no", "yes"][int(hidden)],
150
             "--blacklisted", ["no", "yes"][int(blacklisted)], name]
151
      AssertCommand(cmd)
152

  
153
      # Diagnose, checking exit status
154
      AssertCommand(["gnt-os", "diagnose"], fail=(mode != _ALL_VALID))
155

  
156
      # Diagnose again, ignoring exit status
157
      output = qa_utils.GetCommandOutput(master["primary"],
158
                                         "gnt-os diagnose || :")
159
      for line in output.splitlines():
160
        if line.startswith("OS: %s [global status:" % name):
161
          break
162
      else:
163
        raise qa_error.Error("Didn't find OS '%s' in 'gnt-os diagnose'" % name)
164

  
165
      # Check info for all
166
      cmd = ["gnt-os", "info"]
167
      output = qa_utils.GetCommandOutput(master["primary"],
168
                                         utils.ShellQuoteArgs(cmd))
169
      AssertIn("%s:" % name, output.splitlines())
170

  
171
      # Check info for OS
172
      cmd = ["gnt-os", "info", name]
173
      output = qa_utils.GetCommandOutput(master["primary"],
174
                                         utils.ShellQuoteArgs(cmd)).splitlines()
175
      AssertIn("%s:" % name, output)
176
      for (field, value) in [("valid", mode == _ALL_VALID),
177
                             ("hidden", hidden),
178
                             ("blacklisted", blacklisted)]:
179
        AssertIn("  - %s: %s" % (field, value), output)
180

  
181
      # Only valid OSes should be listed
182
      cmd = ["gnt-os", "list", "--no-headers"]
183
      output = qa_utils.GetCommandOutput(master["primary"],
184
                                         utils.ShellQuoteArgs(cmd))
185
      if mode == _ALL_VALID and not (hidden or blacklisted):
186
        assert_fn = AssertIn
187
      else:
188
        assert_fn = AssertNotIn
189
      assert_fn(name, output.splitlines())
190

  
191
      # Check via RAPI
192
      if rapi_cb:
193
        assert_fn(name, rapi_cb())
138 194
  finally:
139 195
    for node in nodes:
140 196
      _RemoveTempOs(node, dirname)
141 197

  
142 198

  
143
def TestOsValid():
199
def TestOsValid(rapi_cb):
144 200
  """Testing valid OS definition"""
145
  return _TestOs(_ALL_VALID)
201
  return _TestOs(_ALL_VALID, rapi_cb)
146 202

  
147 203

  
148
def TestOsInvalid():
204
def TestOsInvalid(rapi_cb):
149 205
  """Testing invalid OS definition"""
150
  return _TestOs(_ALL_INVALID)
206
  return _TestOs(_ALL_INVALID, rapi_cb)
151 207

  
152 208

  
153
def TestOsPartiallyValid():
209
def TestOsPartiallyValid(rapi_cb):
154 210
  """Testing partially valid OS definition"""
155
  return _TestOs(_PARTIALLY_VALID)
211
  return _TestOs(_PARTIALLY_VALID, rapi_cb)
156 212

  
157 213

  
158 214
def TestOsModifyValid():

Also available in: Unified diff