Statistics
| Branch: | Tag: | Revision:

root / test / py / ganeti.cmdlib.cluster_unittest.py @ c89eb67d

History | View | Annotate | Download (2.8 kB)

1
#!/usr/bin/python
2
#
3

    
4
# Copyright (C) 2013 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
"""Script for unittesting the cmdlib module 'cluster'"""
23

    
24

    
25
import unittest
26

    
27
from ganeti.cmdlib import cluster
28
from ganeti import constants
29
from ganeti import errors
30

    
31
import testutils
32
import mock
33

    
34

    
35
class TestCheckFileStoragePath(unittest.TestCase):
36

    
37
  def setUp(self):
38
    unittest.TestCase.setUp(self)
39
    self.log_warning = mock.Mock()
40

    
41
  def enableFileStorage(self, file_storage_enabled):
42
    if file_storage_enabled:
43
      self.enabled_disk_templates = [constants.DT_FILE]
44
    else:
45
      # anything != 'file' would do here
46
      self.enabled_disk_templates = [constants.DT_DISKLESS]
47

    
48
  def testNone(self):
49
    self.enableFileStorage(True)
50
    self.assertRaises(
51
        errors.ProgrammerError,
52
        cluster.CheckFileStoragePathVsEnabledDiskTemplates,
53
        self.log_warning, None, self.enabled_disk_templates)
54

    
55
  def testNotEmptyAndEnabled(self):
56
    self.enableFileStorage(True)
57
    cluster.CheckFileStoragePathVsEnabledDiskTemplates(
58
        self.log_warning, "/some/path", self.enabled_disk_templates)
59

    
60
  def testNotEnabled(self):
61
    self.enableFileStorage(False)
62
    cluster.CheckFileStoragePathVsEnabledDiskTemplates(
63
        self.log_warning, "/some/path", self.enabled_disk_templates)
64
    self.assertTrue(self.log_warning.called)
65

    
66
  def testEmptyAndEnabled(self):
67
    self.enableFileStorage(True)
68
    self.assertRaises(
69
        errors.OpPrereqError,
70
        cluster.CheckFileStoragePathVsEnabledDiskTemplates,
71
        self.log_warning, "", self.enabled_disk_templates)
72

    
73
  def testEmptyAndDisabled(self):
74
    self.enableFileStorage(False)
75
    cluster.CheckFileStoragePathVsEnabledDiskTemplates(
76
        NotImplemented, "", self.enabled_disk_templates)
77

    
78

    
79
class TestGetEnabledDiskTemplates(unittest.TestCase):
80

    
81
  def testNoNew(self):
82
    op_dts = [constants.DT_DISKLESS]
83
    old_dts = [constants.DT_DISKLESS]
84
    (enabled_dts, new_dts) =\
85
        cluster.LUClusterSetParams._GetEnabledDiskTemplatesInner(
86
            op_dts, old_dts)
87
    self.assertEqual(enabled_dts, old_dts)
88
    self.assertEqual(new_dts, [])
89

    
90

    
91
if __name__ == "__main__":
92
  testutils.GanetiTestProgram()