Statistics
| Branch: | Tag: | Revision:

root / qa / qa_os.py @ 7910e7a5

History | View | Annotate | Download (3.6 kB)

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

24 8947cf2b Michael Hanselmann
"""
25 8947cf2b Michael Hanselmann
26 8947cf2b Michael Hanselmann
import os
27 8947cf2b Michael Hanselmann
import os.path
28 8947cf2b Michael Hanselmann
29 8947cf2b Michael Hanselmann
from ganeti import utils
30 8947cf2b Michael Hanselmann
from ganeti import constants
31 8947cf2b Michael Hanselmann
32 8947cf2b Michael Hanselmann
import qa_config
33 8947cf2b Michael Hanselmann
import qa_utils
34 8947cf2b Michael Hanselmann
35 8947cf2b Michael Hanselmann
from qa_utils import AssertEqual, StartSSH
36 8947cf2b Michael Hanselmann
37 8947cf2b Michael Hanselmann
38 8947cf2b Michael Hanselmann
_TEMP_OS_NAME = "TEMP-Ganeti-QA-OS"
39 8947cf2b Michael Hanselmann
_TEMP_OS_PATH = os.path.join(constants.OS_SEARCH_PATH[0], _TEMP_OS_NAME)
40 8947cf2b Michael Hanselmann
41 8947cf2b Michael Hanselmann
42 9b3939ea Michael Hanselmann
@qa_utils.DefineHook('os-list')
43 8947cf2b Michael Hanselmann
def TestOsList():
44 8947cf2b Michael Hanselmann
  """gnt-os list"""
45 8947cf2b Michael Hanselmann
  master = qa_config.GetMasterNode()
46 8947cf2b Michael Hanselmann
47 8947cf2b Michael Hanselmann
  cmd = ['gnt-os', 'list']
48 8947cf2b Michael Hanselmann
  AssertEqual(StartSSH(master['primary'],
49 8947cf2b Michael Hanselmann
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
50 8947cf2b Michael Hanselmann
51 8947cf2b Michael Hanselmann
52 9b3939ea Michael Hanselmann
@qa_utils.DefineHook('os-diagnose')
53 8947cf2b Michael Hanselmann
def TestOsDiagnose():
54 8947cf2b Michael Hanselmann
  """gnt-os diagnose"""
55 8947cf2b Michael Hanselmann
  master = qa_config.GetMasterNode()
56 8947cf2b Michael Hanselmann
57 8947cf2b Michael Hanselmann
  cmd = ['gnt-os', 'diagnose']
58 8947cf2b Michael Hanselmann
  AssertEqual(StartSSH(master['primary'],
59 8947cf2b Michael Hanselmann
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
60 8947cf2b Michael Hanselmann
61 8947cf2b Michael Hanselmann
62 8947cf2b Michael Hanselmann
def _SetupTempOs(node, dir, valid):
63 8947cf2b Michael Hanselmann
  """Creates a temporary OS definition on the given node.
64 8947cf2b Michael Hanselmann

65 8947cf2b Michael Hanselmann
  """
66 8947cf2b Michael Hanselmann
  sq = utils.ShellQuoteArgs
67 8947cf2b Michael Hanselmann
  parts = [sq(["rm", "-rf", dir]),
68 8947cf2b Michael Hanselmann
           sq(["mkdir", "-p", dir]),
69 8947cf2b Michael Hanselmann
           sq(["cd", dir]),
70 8947cf2b Michael Hanselmann
           sq(["ln", "-fs", "/bin/true", "export"]),
71 8947cf2b Michael Hanselmann
           sq(["ln", "-fs", "/bin/true", "import"]),
72 8947cf2b Michael Hanselmann
           sq(["ln", "-fs", "/bin/true", "rename"])]
73 8947cf2b Michael Hanselmann
74 8947cf2b Michael Hanselmann
  if valid:
75 8947cf2b Michael Hanselmann
    parts.append(sq(["ln", "-fs", "/bin/true", "create"]))
76 8947cf2b Michael Hanselmann
77 8947cf2b Michael Hanselmann
  parts.append(sq(["echo", str(constants.OS_API_VERSION)]) +
78 8947cf2b Michael Hanselmann
               " >ganeti_api_version")
79 8947cf2b Michael Hanselmann
80 8947cf2b Michael Hanselmann
  cmd = ' && '.join(parts)
81 8947cf2b Michael Hanselmann
82 dfe11bad Michael Hanselmann
  print qa_utils.FormatInfo("Setting up %s with %s OS definition" %
83 dfe11bad Michael Hanselmann
                            (node["primary"],
84 dfe11bad Michael Hanselmann
                             ["an invalid", "a valid"][int(valid)]))
85 8947cf2b Michael Hanselmann
86 8947cf2b Michael Hanselmann
  AssertEqual(StartSSH(node['primary'], cmd).wait(), 0)
87 8947cf2b Michael Hanselmann
88 8947cf2b Michael Hanselmann
89 8947cf2b Michael Hanselmann
def _RemoveTempOs(node, dir):
90 8947cf2b Michael Hanselmann
  """Removes a temporary OS definition.
91 8947cf2b Michael Hanselmann

92 8947cf2b Michael Hanselmann
  """
93 8947cf2b Michael Hanselmann
  cmd = ['rm', '-rf', dir]
94 8947cf2b Michael Hanselmann
  AssertEqual(StartSSH(node['primary'],
95 8947cf2b Michael Hanselmann
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
96 8947cf2b Michael Hanselmann
97 8947cf2b Michael Hanselmann
98 8947cf2b Michael Hanselmann
def _TestOs(mode):
99 8947cf2b Michael Hanselmann
  """Generic function for OS definition testing
100 8947cf2b Michael Hanselmann

101 8947cf2b Michael Hanselmann
  """
102 8947cf2b Michael Hanselmann
  master = qa_config.GetMasterNode()
103 8947cf2b Michael Hanselmann
  dir = _TEMP_OS_PATH
104 8947cf2b Michael Hanselmann
105 8947cf2b Michael Hanselmann
  nodes = []
106 8947cf2b Michael Hanselmann
  try:
107 8947cf2b Michael Hanselmann
    i = 0
108 8947cf2b Michael Hanselmann
    for node in qa_config.get('nodes'):
109 8947cf2b Michael Hanselmann
      nodes.append(node)
110 8947cf2b Michael Hanselmann
      if mode == 0:
111 8947cf2b Michael Hanselmann
        valid = False
112 8947cf2b Michael Hanselmann
      elif mode == 1:
113 8947cf2b Michael Hanselmann
        valid = True
114 8947cf2b Michael Hanselmann
      else:
115 8947cf2b Michael Hanselmann
        valid = bool(i % 2)
116 8947cf2b Michael Hanselmann
      _SetupTempOs(node, dir, valid)
117 8947cf2b Michael Hanselmann
      i += 1
118 8947cf2b Michael Hanselmann
119 8947cf2b Michael Hanselmann
    cmd = ['gnt-os', 'diagnose']
120 8947cf2b Michael Hanselmann
    result = StartSSH(master['primary'],
121 8947cf2b Michael Hanselmann
                      utils.ShellQuoteArgs(cmd)).wait()
122 8947cf2b Michael Hanselmann
    if mode == 1:
123 8947cf2b Michael Hanselmann
      AssertEqual(result, 0)
124 8947cf2b Michael Hanselmann
    else:
125 8947cf2b Michael Hanselmann
      AssertEqual(result, 1)
126 8947cf2b Michael Hanselmann
  finally:
127 8947cf2b Michael Hanselmann
    for node in nodes:
128 8947cf2b Michael Hanselmann
      _RemoveTempOs(node, dir)
129 8947cf2b Michael Hanselmann
130 8947cf2b Michael Hanselmann
131 9b3939ea Michael Hanselmann
@qa_utils.DefineHook('os-valid')
132 8947cf2b Michael Hanselmann
def TestOsValid():
133 8947cf2b Michael Hanselmann
  """Testing valid OS definition"""
134 8947cf2b Michael Hanselmann
  return _TestOs(1)
135 8947cf2b Michael Hanselmann
136 8947cf2b Michael Hanselmann
137 9b3939ea Michael Hanselmann
@qa_utils.DefineHook('os-invalid')
138 8947cf2b Michael Hanselmann
def TestOsInvalid():
139 8947cf2b Michael Hanselmann
  """Testing invalid OS definition"""
140 8947cf2b Michael Hanselmann
  return _TestOs(0)
141 8947cf2b Michael Hanselmann
142 8947cf2b Michael Hanselmann
143 9b3939ea Michael Hanselmann
@qa_utils.DefineHook('os-partially-valid')
144 8947cf2b Michael Hanselmann
def TestOsPartiallyValid():
145 8947cf2b Michael Hanselmann
  """Testing partially valid OS definition"""
146 8947cf2b Michael Hanselmann
  return _TestOs(2)