Revision 8947cf2b

b/qa/Makefile.am
5 5
	qa_env.py \
6 6
	qa_error.py \
7 7
	qa_instance.py \
8
	qa_node.py
8
	qa_node.py \
9
	qa_os.py \
9 10
	qa_other.py \
10 11
	qa_utils.py
11 12
CLEANFILES = *.py[co]
b/qa/ganeti-qa.py
37 37
import qa_env
38 38
import qa_instance
39 39
import qa_node
40
import qa_os
40 41
import qa_other
41 42

  
42 43

  
......
121 122
  if qa_config.TestEnabled('cluster-master-failover'):
122 123
    RunTest(qa_cluster.TestClusterMasterFailover)
123 124

  
125
  if qa_config.TestEnabled('os'):
126
    RunTest(qa_os.TestOsList)
127
    RunTest(qa_os.TestOsDiagnose)
128
    RunTest(qa_os.TestOsValid)
129
    RunTest(qa_os.TestOsInvalid)
130
    RunTest(qa_os.TestOsPartiallyValid)
131

  
124 132
  node = qa_config.AcquireNode()
125 133
  try:
126 134
    if qa_config.TestEnabled('instance-add-plain-disk'):
b/qa/qa-sample.yaml
26 26
tests:
27 27
  env: True
28 28

  
29
  os: True
30

  
29 31
  cluster-verify: True
30 32
  cluster-info: True
31 33
  cluster-getmaster: True
b/qa/qa_os.py
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)

Also available in: Unified diff