Revision 70e8dd0a

b/test/py/cmdlib/cluster_unittest.py
481 481

  
482 482
    self.mcpu.assertLogContainsRegex("file storage dir already set to value")
483 483

  
484
  def testUnsetFileStorageDirFileStorageEnabled(self):
485
    self.cfg.SetEnabledDiskTemplates([constants.DT_FILE])
486
    op = opcodes.OpClusterSetParams(file_storage_dir='')
487
    self.ExecOpCodeExpectOpPrereqError(op, "Unsetting the 'file' storage")
488

  
489
  def testUnsetFileStorageDirFileStorageDisabled(self):
490
    self.cfg.SetEnabledDiskTemplates([constants.DT_PLAIN])
491
    op = opcodes.OpClusterSetParams(file_storage_dir='')
492
    self.ExecOpCode(op)
493

  
494
  def testSetFileStorageDirFileStorageDisabled(self):
495
    self.cfg.SetEnabledDiskTemplates([constants.DT_PLAIN])
496
    op = opcodes.OpClusterSetParams(file_storage_dir='/some/path/')
497
    self.ExecOpCode(op)
498
    self.mcpu.assertLogContainsRegex("although file storage is not enabled")
499

  
484 500
  def testValidDrbdHelper(self):
485 501
    node1 = self.cfg.AddNewNode()
486 502
    node1.offline = True
/dev/null
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
if __name__ == "__main__":
80
  testutils.GanetiTestProgram()

Also available in: Unified diff