Statistics
| Branch: | Tag: | Revision:

root / qa / qa_os.py @ c68d1f43

History | View | Annotate | Download (3.6 kB)

1
#
2
#
3

    
4
# Copyright (C) 2007 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
@qa_utils.DefineHook('os-list')
43
def TestOsList():
44
  """gnt-os list"""
45
  master = qa_config.GetMasterNode()
46

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

    
51

    
52
@qa_utils.DefineHook('os-diagnose')
53
def TestOsDiagnose():
54
  """gnt-os diagnose"""
55
  master = qa_config.GetMasterNode()
56

    
57
  cmd = ['gnt-os', 'diagnose']
58
  AssertEqual(StartSSH(master['primary'],
59
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
60

    
61

    
62
def _SetupTempOs(node, dir, valid):
63
  """Creates a temporary OS definition on the given node.
64

65
  """
66
  sq = utils.ShellQuoteArgs
67
  parts = [sq(["rm", "-rf", dir]),
68
           sq(["mkdir", "-p", dir]),
69
           sq(["cd", dir]),
70
           sq(["ln", "-fs", "/bin/true", "export"]),
71
           sq(["ln", "-fs", "/bin/true", "import"]),
72
           sq(["ln", "-fs", "/bin/true", "rename"])]
73

    
74
  if valid:
75
    parts.append(sq(["ln", "-fs", "/bin/true", "create"]))
76

    
77
  parts.append(sq(["echo", str(constants.OS_API_VERSION)]) +
78
               " >ganeti_api_version")
79

    
80
  cmd = ' && '.join(parts)
81

    
82
  print qa_utils.FormatInfo("Setting up %s with %s OS definition" %
83
                            (node["primary"],
84
                             ["an invalid", "a valid"][int(valid)]))
85

    
86
  AssertEqual(StartSSH(node['primary'], cmd).wait(), 0)
87

    
88

    
89
def _RemoveTempOs(node, dir):
90
  """Removes a temporary OS definition.
91

92
  """
93
  cmd = ['rm', '-rf', dir]
94
  AssertEqual(StartSSH(node['primary'],
95
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
96

    
97

    
98
def _TestOs(mode):
99
  """Generic function for OS definition testing
100

101
  """
102
  master = qa_config.GetMasterNode()
103
  dir = _TEMP_OS_PATH
104

    
105
  nodes = []
106
  try:
107
    i = 0
108
    for node in qa_config.get('nodes'):
109
      nodes.append(node)
110
      if mode == 0:
111
        valid = False
112
      elif mode == 1:
113
        valid = True
114
      else:
115
        valid = bool(i % 2)
116
      _SetupTempOs(node, dir, valid)
117
      i += 1
118

    
119
    cmd = ['gnt-os', 'diagnose']
120
    result = StartSSH(master['primary'],
121
                      utils.ShellQuoteArgs(cmd)).wait()
122
    if mode == 1:
123
      AssertEqual(result, 0)
124
    else:
125
      AssertEqual(result, 1)
126
  finally:
127
    for node in nodes:
128
      _RemoveTempOs(node, dir)
129

    
130

    
131
@qa_utils.DefineHook('os-valid')
132
def TestOsValid():
133
  """Testing valid OS definition"""
134
  return _TestOs(1)
135

    
136

    
137
@qa_utils.DefineHook('os-invalid')
138
def TestOsInvalid():
139
  """Testing invalid OS definition"""
140
  return _TestOs(0)
141

    
142

    
143
@qa_utils.DefineHook('os-partially-valid')
144
def TestOsPartiallyValid():
145
  """Testing partially valid OS definition"""
146
  return _TestOs(2)