Statistics
| Branch: | Tag: | Revision:

root / test / py / ganeti.storage.gluster_unittest.py @ 560ef132

History | View | Annotate | Download (4.5 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
"""Script for unittesting the ganeti.storage.gluster module"""
22

    
23
import os
24
import shutil
25
import tempfile
26
import unittest
27
import mock
28

    
29
from ganeti import errors
30
from ganeti.storage import filestorage
31
from ganeti.storage import gluster
32
from ganeti import utils
33

    
34
import testutils
35

    
36
class TestGlusterVolume(testutils.GanetiTestCase):
37

    
38
  testAddrIpv = {4: "203.0.113.42",
39
                 6: "2001:DB8::74:65:28:6:69",
40
                }
41

    
42
  @staticmethod
43
  def _MakeVolume(addr=None, port=9001,
44
                  run_cmd=NotImplemented,
45
                  vol_name="pinky"):
46

    
47
    addr = addr if addr is not None else TestGlusterVolume.testAddrIpv[4]
48

    
49
    return gluster.GlusterVolume(addr, port, vol_name, _run_cmd=run_cmd,
50
                                 _mount_point="/invalid")
51

    
52
  def setUp(self):
53
    testutils.GanetiTestCase.setUp(self)
54

    
55
    # Create some volumes.
56
    self.vol_a = TestGlusterVolume._MakeVolume()
57
    self.vol_a_clone = TestGlusterVolume._MakeVolume()
58
    self.vol_b = TestGlusterVolume._MakeVolume(vol_name="pinker")
59

    
60
  def testEquality(self):
61
    self.assertEqual(self.vol_a, self.vol_a_clone)
62

    
63
  def testInequality(self):
64
    self.assertNotEqual(self.vol_a, self.vol_b)
65

    
66
  def testHostnameResolution(self):
67
    vol_1 = TestGlusterVolume._MakeVolume(addr="localhost")
68
    self.assertEqual(vol_1.server_ip, "127.0.0.1")
69
    self.assertRaises(errors.ResolverError, lambda: \
70
      TestGlusterVolume._MakeVolume(addr="E_NOENT"))
71

    
72
  def testKVMMountStrings(self):
73
    # The only source of documentation I can find is:
74
    #   https://github.com/qemu/qemu/commit/8d6d89c
75
    # This test gets as close as possible to the examples given there,
76
    # within the limits of our implementation (no transport specification,
77
    #                                          no default port version).
78

    
79
    vol_1 = TestGlusterVolume._MakeVolume(addr=TestGlusterVolume.testAddrIpv[4],
80
                                          port=24007,
81
                                          vol_name="testvol")
82
    self.assertEqual(
83
      vol_1.GetKVMMountString("dir/a.img"),
84
      "gluster://203.0.113.42:24007/testvol/dir/a.img"
85
    )
86

    
87
    vol_2 = TestGlusterVolume._MakeVolume(addr=TestGlusterVolume.testAddrIpv[6],
88
                                          port=24007,
89
                                          vol_name="testvol")
90
    self.assertEqual(
91
      vol_2.GetKVMMountString("dir/a.img"),
92
      "gluster://[2001:db8:0:74:65:28:6:69]:24007/testvol/dir/a.img"
93
    )
94

    
95
    vol_3 = TestGlusterVolume._MakeVolume(addr="localhost",
96
                                          port=9001,
97
                                          vol_name="testvol")
98
    self.assertEqual(
99
      vol_3.GetKVMMountString("dir/a.img"),
100
      "gluster://127.0.0.1:9001/testvol/dir/a.img"
101
    )
102

    
103
  def testFUSEMountStrings(self):
104
    vol_1 = TestGlusterVolume._MakeVolume(addr=TestGlusterVolume.testAddrIpv[4],
105
                                          port=24007,
106
                                          vol_name="testvol")
107
    self.assertEqual(
108
      vol_1._GetFUSEMountString(),
109
      "203.0.113.42:24007:testvol"
110
    )
111

    
112
    vol_2 = TestGlusterVolume._MakeVolume(addr=TestGlusterVolume.testAddrIpv[6],
113
                                          port=24007,
114
                                          vol_name="testvol")
115
    # This _ought_ to work. https://bugzilla.redhat.com/show_bug.cgi?id=764188
116
    self.assertEqual(
117
      vol_2._GetFUSEMountString(),
118
      "2001:db8:0:74:65:28:6:69:24007:testvol"
119
    )
120

    
121
    vol_3 = TestGlusterVolume._MakeVolume(addr="localhost",
122
                                          port=9001,
123
                                          vol_name="testvol")
124
    self.assertEqual(
125
      vol_3._GetFUSEMountString(),
126
      "127.0.0.1:9001:testvol"
127
    )
128

    
129

    
130
if __name__ == "__main__":
131
  testutils.GanetiTestProgram()