Statistics
| Branch: | Tag: | Revision:

root / qa / qa_os.py @ 7b4eed05

History | View | Annotate | Download (4.8 kB)

1
#
2
#
3

    
4
# Copyright (C) 2007, 2008, 2009, 2010 Google Inc.
5
#
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
# General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
# 02110-1301, USA.
20

    
21

    
22
"""OS related QA tests.
23

24
"""
25

    
26
import os
27
import os.path
28

    
29
from ganeti import utils
30
from ganeti import constants
31

    
32
import qa_config
33
import qa_utils
34

    
35
from qa_utils import AssertEqual, StartSSH
36

    
37

    
38
_TEMP_OS_NAME = "TEMP-Ganeti-QA-OS"
39
_TEMP_OS_PATH = os.path.join(constants.OS_SEARCH_PATH[0], _TEMP_OS_NAME)
40

    
41

    
42
def TestOsList():
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)
49

    
50

    
51
def TestOsDiagnose():
52
  """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)
58

    
59

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

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

    
66
  for hv_name, hv_params in hvp_dict.items():
67
    cmd.append('-H')
68
    options = []
69
    for key, value in hv_params.items():
70
      options.append("%s=%s" % (key, value))
71
    cmd.append('%s:%s' % (hv_name, ','.join(options)))
72

    
73
  cmd.append(_TEMP_OS_NAME)
74
  AssertEqual(StartSSH(master['primary'],
75
                       utils.ShellQuoteArgs(cmd)).wait(), expected_result)
76

    
77

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

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

    
84
  for param in ["hidden", "blacklisted"]:
85
    for val in ["yes", "no"]:
86
      new_cmd = cmd + ["--%s" % param, val, _TEMP_OS_NAME]
87
      AssertEqual(StartSSH(master["primary"],
88
                           utils.ShellQuoteArgs(new_cmd)).wait(), 0)
89

    
90

    
91
def _SetupTempOs(node, dir, valid):
92
  """Creates a temporary OS definition on the given node.
93

94
  """
95
  sq = utils.ShellQuoteArgs
96
  parts = [sq(["rm", "-rf", dir]),
97
           sq(["mkdir", "-p", dir]),
98
           sq(["cd", dir]),
99
           sq(["ln", "-fs", "/bin/true", "export"]),
100
           sq(["ln", "-fs", "/bin/true", "import"]),
101
           sq(["ln", "-fs", "/bin/true", "rename"])]
102

    
103
  if valid:
104
    parts.append(sq(["ln", "-fs", "/bin/true", "create"]))
105

    
106
  parts.append(sq(["echo", str(constants.OS_API_V10)]) +
107
               " >ganeti_api_version")
108

    
109
  cmd = ' && '.join(parts)
110

    
111
  print qa_utils.FormatInfo("Setting up %s with %s OS definition" %
112
                            (node["primary"],
113
                             ["an invalid", "a valid"][int(valid)]))
114

    
115
  AssertEqual(StartSSH(node['primary'], cmd).wait(), 0)
116

    
117

    
118
def _RemoveTempOs(node, dir):
119
  """Removes a temporary OS definition.
120

121
  """
122
  cmd = ['rm', '-rf', dir]
123
  AssertEqual(StartSSH(node['primary'],
124
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
125

    
126

    
127
def _TestOs(mode):
128
  """Generic function for OS definition testing
129

130
  """
131
  master = qa_config.GetMasterNode()
132
  dir = _TEMP_OS_PATH
133

    
134
  nodes = []
135
  try:
136
    i = 0
137
    for node in qa_config.get('nodes'):
138
      nodes.append(node)
139
      if mode == 0:
140
        valid = False
141
      elif mode == 1:
142
        valid = True
143
      else:
144
        valid = bool(i % 2)
145
      _SetupTempOs(node, dir, valid)
146
      i += 1
147

    
148
    cmd = ['gnt-os', 'diagnose']
149
    result = StartSSH(master['primary'],
150
                      utils.ShellQuoteArgs(cmd)).wait()
151
    if mode == 1:
152
      AssertEqual(result, 0)
153
    else:
154
      AssertEqual(result, 1)
155
  finally:
156
    for node in nodes:
157
      _RemoveTempOs(node, dir)
158

    
159

    
160
def TestOsValid():
161
  """Testing valid OS definition"""
162
  return _TestOs(1)
163

    
164

    
165
def TestOsInvalid():
166
  """Testing invalid OS definition"""
167
  return _TestOs(0)
168

    
169

    
170
def TestOsPartiallyValid():
171
  """Testing partially valid OS definition"""
172
  return _TestOs(2)
173

    
174

    
175
def TestOsModifyValid():
176
  """Testing a valid os modify invocation"""
177
  hv_dict = {
178
    constants.HT_XEN_PVM: {
179
      constants.HV_ROOT_PATH: "/dev/sda5",
180
      },
181
    constants.HT_XEN_HVM: {
182
      constants.HV_ACPI: False,
183
      constants.HV_PAE: True,
184
      },
185
    }
186

    
187
  return _TestOsModify(hv_dict)
188

    
189

    
190
def TestOsModifyInvalid():
191
  """Testing an invalid os modify invocation"""
192
  hv_dict = {
193
    "blahblahblubb": {"bar": ""},
194
    }
195

    
196
  return _TestOsModify(hv_dict, 1)
197

    
198

    
199
def TestOsStates():
200
  """Testing OS states"""
201

    
202
  return _TestOsStates()