Statistics
| Branch: | Tag: | Revision:

root / qa / qa_os.py @ 8947cf2b

History | View | Annotate | Download (3.3 kB)

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

    
18

    
19
"""OS related QA tests.
20

21
"""
22

    
23
import os
24
import os.path
25

    
26
from ganeti import utils
27
from ganeti import constants
28

    
29
import qa_config
30
import qa_utils
31

    
32
from qa_utils import AssertEqual, StartSSH
33

    
34

    
35
_TEMP_OS_NAME = "TEMP-Ganeti-QA-OS"
36
_TEMP_OS_PATH = os.path.join(constants.OS_SEARCH_PATH[0], _TEMP_OS_NAME)
37

    
38

    
39
def TestOsList():
40
  """gnt-os list"""
41
  master = qa_config.GetMasterNode()
42

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

    
47

    
48
def TestOsDiagnose():
49
  """gnt-os diagnose"""
50
  master = qa_config.GetMasterNode()
51

    
52
  cmd = ['gnt-os', 'diagnose']
53
  AssertEqual(StartSSH(master['primary'],
54
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
55

    
56

    
57
def _SetupTempOs(node, dir, valid):
58
  """Creates a temporary OS definition on the given node.
59

60
  """
61
  sq = utils.ShellQuoteArgs
62
  parts = [sq(["rm", "-rf", dir]),
63
           sq(["mkdir", "-p", dir]),
64
           sq(["cd", dir]),
65
           sq(["ln", "-fs", "/bin/true", "export"]),
66
           sq(["ln", "-fs", "/bin/true", "import"]),
67
           sq(["ln", "-fs", "/bin/true", "rename"])]
68

    
69
  if valid:
70
    parts.append(sq(["ln", "-fs", "/bin/true", "create"]))
71

    
72
  parts.append(sq(["echo", str(constants.OS_API_VERSION)]) +
73
               " >ganeti_api_version")
74

    
75
  cmd = ' && '.join(parts)
76

    
77
  qa_utils.PrintInfo("Setting up %s with %s OS definition" %
78
                     (node["primary"], ["an invalid", "a valid"][int(valid)]))
79

    
80
  AssertEqual(StartSSH(node['primary'], cmd).wait(), 0)
81

    
82

    
83
def _RemoveTempOs(node, dir):
84
  """Removes a temporary OS definition.
85

86
  """
87
  cmd = ['rm', '-rf', dir]
88
  AssertEqual(StartSSH(node['primary'],
89
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
90

    
91

    
92
def _TestOs(mode):
93
  """Generic function for OS definition testing
94

95
  """
96
  master = qa_config.GetMasterNode()
97
  dir = _TEMP_OS_PATH
98

    
99
  nodes = []
100
  try:
101
    i = 0
102
    for node in qa_config.get('nodes'):
103
      nodes.append(node)
104
      if mode == 0:
105
        valid = False
106
      elif mode == 1:
107
        valid = True
108
      else:
109
        valid = bool(i % 2)
110
      _SetupTempOs(node, dir, valid)
111
      i += 1
112

    
113
    cmd = ['gnt-os', 'diagnose']
114
    result = StartSSH(master['primary'],
115
                      utils.ShellQuoteArgs(cmd)).wait()
116
    if mode == 1:
117
      AssertEqual(result, 0)
118
    else:
119
      AssertEqual(result, 1)
120
  finally:
121
    for node in nodes:
122
      _RemoveTempOs(node, dir)
123

    
124

    
125
def TestOsValid():
126
  """Testing valid OS definition"""
127
  return _TestOs(1)
128

    
129

    
130
def TestOsInvalid():
131
  """Testing invalid OS definition"""
132
  return _TestOs(0)
133

    
134

    
135
def TestOsPartiallyValid():
136
  """Testing partially valid OS definition"""
137
  return _TestOs(2)