Statistics
| Branch: | Tag: | Revision:

root / qa / qa_os.py @ 2237687b

History | View | Annotate | Download (4.1 kB)

1
#
2
#
3

    
4
# Copyright (C) 2007, 2008, 2009, 2010, 2011 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 AssertCommand
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
  AssertCommand(["gnt-os", "list"])
45

    
46

    
47
def TestOsDiagnose():
48
  """gnt-os diagnose"""
49
  AssertCommand(["gnt-os", "diagnose"])
50

    
51

    
52
def _TestOsModify(hvp_dict, fail=False):
53
  """gnt-os modify"""
54
  cmd = ['gnt-os', 'modify']
55

    
56
  for hv_name, hv_params in hvp_dict.items():
57
    cmd.append('-H')
58
    options = []
59
    for key, value in hv_params.items():
60
      options.append("%s=%s" % (key, value))
61
    cmd.append('%s:%s' % (hv_name, ','.join(options)))
62

    
63
  cmd.append(_TEMP_OS_NAME)
64
  AssertCommand(cmd, fail=fail)
65

    
66

    
67
def _TestOsStates():
68
  """gnt-os modify, more stuff"""
69
  cmd = ["gnt-os", "modify"]
70

    
71
  for param in ["hidden", "blacklisted"]:
72
    for val in ["yes", "no"]:
73
      new_cmd = cmd + ["--%s" % param, val, _TEMP_OS_NAME]
74
      AssertCommand(new_cmd)
75
      # check that double-running the command is OK
76
      AssertCommand(new_cmd)
77

    
78

    
79
def _SetupTempOs(node, dirname, valid):
80
  """Creates a temporary OS definition on the given node.
81

82
  """
83
  sq = utils.ShellQuoteArgs
84
  parts = [sq(["rm", "-rf", dirname]),
85
           sq(["mkdir", "-p", dirname]),
86
           sq(["cd", dirname]),
87
           sq(["ln", "-fs", "/bin/true", "export"]),
88
           sq(["ln", "-fs", "/bin/true", "import"]),
89
           sq(["ln", "-fs", "/bin/true", "rename"])]
90

    
91
  if valid:
92
    parts.append(sq(["ln", "-fs", "/bin/true", "create"]))
93

    
94
  parts.append(sq(["echo", str(constants.OS_API_V10)]) +
95
               " >ganeti_api_version")
96

    
97
  cmd = ' && '.join(parts)
98

    
99
  print qa_utils.FormatInfo("Setting up %s with %s OS definition" %
100
                            (node["primary"],
101
                             ["an invalid", "a valid"][int(valid)]))
102

    
103
  AssertCommand(cmd, node=node)
104

    
105

    
106
def _RemoveTempOs(node, dirname):
107
  """Removes a temporary OS definition.
108

109
  """
110
  AssertCommand(["rm", "-rf", dirname], node=node)
111

    
112

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

116
  """
117
  dirname = _TEMP_OS_PATH
118

    
119
  nodes = []
120
  try:
121
    for i, node in enumerate(qa_config.get("nodes")):
122
      nodes.append(node)
123
      if mode == 0:
124
        valid = False
125
      elif mode == 1:
126
        valid = True
127
      else:
128
        valid = bool(i % 2)
129
      _SetupTempOs(node, dirname, valid)
130

    
131
    AssertCommand(["gnt-os", "diagnose"], fail=not mode==1)
132
  finally:
133
    for node in nodes:
134
      _RemoveTempOs(node, dirname)
135

    
136

    
137
def TestOsValid():
138
  """Testing valid OS definition"""
139
  return _TestOs(1)
140

    
141

    
142
def TestOsInvalid():
143
  """Testing invalid OS definition"""
144
  return _TestOs(0)
145

    
146

    
147
def TestOsPartiallyValid():
148
  """Testing partially valid OS definition"""
149
  return _TestOs(2)
150

    
151

    
152
def TestOsModifyValid():
153
  """Testing a valid os modify invocation"""
154
  hv_dict = {
155
    constants.HT_XEN_PVM: {
156
      constants.HV_ROOT_PATH: "/dev/sda5",
157
      },
158
    constants.HT_XEN_HVM: {
159
      constants.HV_ACPI: False,
160
      constants.HV_PAE: True,
161
      },
162
    }
163

    
164
  return _TestOsModify(hv_dict)
165

    
166

    
167
def TestOsModifyInvalid():
168
  """Testing an invalid os modify invocation"""
169
  hv_dict = {
170
    "blahblahblubb": {"bar": ""},
171
    }
172

    
173
  return _TestOsModify(hv_dict, fail=True)
174

    
175

    
176
def TestOsStates():
177
  """Testing OS states"""
178

    
179
  return _TestOsStates()