Statistics
| Branch: | Tag: | Revision:

root / test / ganeti.objects_unittest.py @ c1912a48

History | View | Annotate | Download (12.1 kB)

1 4c14965f Guido Trotter
#!/usr/bin/python
2 4c14965f Guido Trotter
#
3 4c14965f Guido Trotter
4 432e8e2f Iustin Pop
# Copyright (C) 2006, 2007, 2008, 2010, 2012 Google Inc.
5 4c14965f Guido Trotter
#
6 4c14965f Guido Trotter
# This program is free software; you can redistribute it and/or modify
7 4c14965f Guido Trotter
# it under the terms of the GNU General Public License as published by
8 4c14965f Guido Trotter
# the Free Software Foundation; either version 2 of the License, or
9 4c14965f Guido Trotter
# (at your option) any later version.
10 4c14965f Guido Trotter
#
11 4c14965f Guido Trotter
# This program is distributed in the hope that it will be useful, but
12 4c14965f Guido Trotter
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 4c14965f Guido Trotter
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 4c14965f Guido Trotter
# General Public License for more details.
15 4c14965f Guido Trotter
#
16 4c14965f Guido Trotter
# You should have received a copy of the GNU General Public License
17 4c14965f Guido Trotter
# along with this program; if not, write to the Free Software
18 4c14965f Guido Trotter
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 fd7b69c0 Michael Hanselmann
# 02110-1301, USA.
20 4c14965f Guido Trotter
21 4c14965f Guido Trotter
22 4c14965f Guido Trotter
"""Script for unittesting the objects module"""
23 4c14965f Guido Trotter
24 4c14965f Guido Trotter
25 4c14965f Guido Trotter
import unittest
26 4c14965f Guido Trotter
27 7b64b9ea René Nussbaumer
from ganeti import constants
28 4c14965f Guido Trotter
from ganeti import objects
29 6a050007 Michael Hanselmann
from ganeti import errors
30 4c14965f Guido Trotter
31 25231ec5 Michael Hanselmann
import testutils
32 25231ec5 Michael Hanselmann
33 25231ec5 Michael Hanselmann
34 4c14965f Guido Trotter
class SimpleObject(objects.ConfigObject):
35 8c114acd Michael Hanselmann
  __slots__ = ["a", "b"]
36 4c14965f Guido Trotter
37 25231ec5 Michael Hanselmann
38 4c14965f Guido Trotter
class TestDictState(unittest.TestCase):
39 4c14965f Guido Trotter
  """Simple dict tansformation tests"""
40 4c14965f Guido Trotter
41 4c14965f Guido Trotter
  def testSimpleObjectToDict(self):
42 8c114acd Michael Hanselmann
    o1 = SimpleObject(a="1")
43 8c114acd Michael Hanselmann
    self.assertEquals(o1.ToDict(), {"a": "1"})
44 8c114acd Michael Hanselmann
    self.assertEquals(o1.__getstate__(), {"a": "1"})
45 4c14965f Guido Trotter
    self.assertEquals(o1.__getstate__(), o1.ToDict())
46 4c14965f Guido Trotter
    o1.a = 2
47 4c14965f Guido Trotter
    o1.b = 5
48 8c114acd Michael Hanselmann
    self.assertEquals(o1.ToDict(), {"a": 2, "b": 5})
49 4c14965f Guido Trotter
    o2 = SimpleObject.FromDict(o1.ToDict())
50 8c114acd Michael Hanselmann
    self.assertEquals(o1.ToDict(), {"a": 2, "b": 5})
51 4c14965f Guido Trotter
52 4c14965f Guido Trotter
53 7b64b9ea René Nussbaumer
class TestClusterObject(unittest.TestCase):
54 7b64b9ea René Nussbaumer
  """Tests done on a L{objects.Cluster}"""
55 7b64b9ea René Nussbaumer
56 7b64b9ea René Nussbaumer
  def setUp(self):
57 7b64b9ea René Nussbaumer
    hvparams = {
58 7b64b9ea René Nussbaumer
      constants.HT_FAKE: {
59 7b64b9ea René Nussbaumer
        "foo": "bar",
60 7b64b9ea René Nussbaumer
        "bar": "foo",
61 7b64b9ea René Nussbaumer
        "foobar": "barfoo",
62 7b64b9ea René Nussbaumer
        },
63 7b64b9ea René Nussbaumer
      }
64 7b64b9ea René Nussbaumer
    os_hvp = {
65 7b64b9ea René Nussbaumer
      "lenny-image": {
66 7b64b9ea René Nussbaumer
        constants.HT_FAKE: {
67 7b64b9ea René Nussbaumer
          "foo": "baz",
68 7b64b9ea René Nussbaumer
          "foobar": "foobar",
69 7b64b9ea René Nussbaumer
          "blah": "blibb",
70 7b64b9ea René Nussbaumer
          "blubb": "blah",
71 7b64b9ea René Nussbaumer
          },
72 7b64b9ea René Nussbaumer
        constants.HT_XEN_PVM: {
73 7b64b9ea René Nussbaumer
          "root_path": "/dev/sda5",
74 7b64b9ea René Nussbaumer
          "foo": "foobar",
75 7b64b9ea René Nussbaumer
          },
76 7b64b9ea René Nussbaumer
        },
77 7b64b9ea René Nussbaumer
      "ubuntu-hardy": {
78 7b64b9ea René Nussbaumer
        },
79 7b64b9ea René Nussbaumer
      }
80 095e71aa René Nussbaumer
    ndparams = {
81 432e8e2f Iustin Pop
        constants.ND_OOB_PROGRAM: "/bin/cluster-oob",
82 0ea11dcb Bernardo Dal Seno
        constants.ND_SPINDLE_COUNT: 1,
83 0ea11dcb Bernardo Dal Seno
        constants.ND_EXCLUSIVE_STORAGE: False,
84 095e71aa René Nussbaumer
        }
85 095e71aa René Nussbaumer
86 095e71aa René Nussbaumer
    self.fake_cl = objects.Cluster(hvparams=hvparams, os_hvp=os_hvp,
87 095e71aa René Nussbaumer
                                   ndparams=ndparams)
88 7b64b9ea René Nussbaumer
    self.fake_cl.UpgradeConfig()
89 7b64b9ea René Nussbaumer
90 d63479b5 Iustin Pop
  def testGetHVDefaults(self):
91 d63479b5 Iustin Pop
    cl = self.fake_cl
92 d63479b5 Iustin Pop
    self.failUnlessEqual(cl.GetHVDefaults(constants.HT_FAKE),
93 d63479b5 Iustin Pop
                         cl.hvparams[constants.HT_FAKE])
94 d63479b5 Iustin Pop
    self.failUnlessEqual(cl.GetHVDefaults(None), {})
95 d63479b5 Iustin Pop
    self.failUnlessEqual(cl.GetHVDefaults(constants.HT_XEN_PVM,
96 d63479b5 Iustin Pop
                                          os_name="lenny-image"),
97 d63479b5 Iustin Pop
                         cl.os_hvp["lenny-image"][constants.HT_XEN_PVM])
98 d63479b5 Iustin Pop
99 d63479b5 Iustin Pop
100 7b64b9ea René Nussbaumer
  def testFillHvFullMerge(self):
101 7b64b9ea René Nussbaumer
    inst_hvparams = {
102 7b64b9ea René Nussbaumer
      "blah": "blubb",
103 7b64b9ea René Nussbaumer
      }
104 7b64b9ea René Nussbaumer
105 7b64b9ea René Nussbaumer
    fake_dict = {
106 7b64b9ea René Nussbaumer
      "foo": "baz",
107 7b64b9ea René Nussbaumer
      "bar": "foo",
108 7b64b9ea René Nussbaumer
      "foobar": "foobar",
109 7b64b9ea René Nussbaumer
      "blah": "blubb",
110 7b64b9ea René Nussbaumer
      "blubb": "blah",
111 7b64b9ea René Nussbaumer
      }
112 7b64b9ea René Nussbaumer
    fake_inst = objects.Instance(name="foobar",
113 7b64b9ea René Nussbaumer
                                 os="lenny-image",
114 7b64b9ea René Nussbaumer
                                 hypervisor=constants.HT_FAKE,
115 7b64b9ea René Nussbaumer
                                 hvparams=inst_hvparams)
116 7b64b9ea René Nussbaumer
    self.assertEqual(fake_dict, self.fake_cl.FillHV(fake_inst))
117 7b64b9ea René Nussbaumer
118 7b64b9ea René Nussbaumer
  def testFillHvGlobalParams(self):
119 7b64b9ea René Nussbaumer
    fake_inst = objects.Instance(name="foobar",
120 7b64b9ea René Nussbaumer
                                 os="ubuntu-hardy",
121 7b64b9ea René Nussbaumer
                                 hypervisor=constants.HT_FAKE,
122 7b64b9ea René Nussbaumer
                                 hvparams={})
123 7b64b9ea René Nussbaumer
    self.assertEqual(self.fake_cl.hvparams[constants.HT_FAKE],
124 7b64b9ea René Nussbaumer
                     self.fake_cl.FillHV(fake_inst))
125 7b64b9ea René Nussbaumer
126 7b64b9ea René Nussbaumer
  def testFillHvInstParams(self):
127 7b64b9ea René Nussbaumer
    inst_hvparams = {
128 7b64b9ea René Nussbaumer
      "blah": "blubb",
129 7b64b9ea René Nussbaumer
      }
130 7b64b9ea René Nussbaumer
    fake_inst = objects.Instance(name="foobar",
131 7b64b9ea René Nussbaumer
                                 os="ubuntu-hardy",
132 7b64b9ea René Nussbaumer
                                 hypervisor=constants.HT_XEN_PVM,
133 7b64b9ea René Nussbaumer
                                 hvparams=inst_hvparams)
134 7b64b9ea René Nussbaumer
    self.assertEqual(inst_hvparams, self.fake_cl.FillHV(fake_inst))
135 7b64b9ea René Nussbaumer
136 7b64b9ea René Nussbaumer
  def testFillHvEmptyParams(self):
137 7b64b9ea René Nussbaumer
    fake_inst = objects.Instance(name="foobar",
138 7b64b9ea René Nussbaumer
                                 os="ubuntu-hardy",
139 7b64b9ea René Nussbaumer
                                 hypervisor=constants.HT_XEN_PVM,
140 7b64b9ea René Nussbaumer
                                 hvparams={})
141 7b64b9ea René Nussbaumer
    self.assertEqual({}, self.fake_cl.FillHV(fake_inst))
142 7b64b9ea René Nussbaumer
143 7b64b9ea René Nussbaumer
  def testFillHvPartialParams(self):
144 7b64b9ea René Nussbaumer
    os = "lenny-image"
145 7b64b9ea René Nussbaumer
    fake_inst = objects.Instance(name="foobar",
146 7b64b9ea René Nussbaumer
                                 os=os,
147 7b64b9ea René Nussbaumer
                                 hypervisor=constants.HT_XEN_PVM,
148 7b64b9ea René Nussbaumer
                                 hvparams={})
149 7b64b9ea René Nussbaumer
    self.assertEqual(self.fake_cl.os_hvp[os][constants.HT_XEN_PVM],
150 7b64b9ea René Nussbaumer
                     self.fake_cl.FillHV(fake_inst))
151 7b64b9ea René Nussbaumer
152 095e71aa René Nussbaumer
  def testFillNdParamsCluster(self):
153 095e71aa René Nussbaumer
    fake_node = objects.Node(name="test",
154 095e71aa René Nussbaumer
                             ndparams={},
155 095e71aa René Nussbaumer
                             group="testgroup")
156 095e71aa René Nussbaumer
    fake_group = objects.NodeGroup(name="testgroup",
157 095e71aa René Nussbaumer
                                   ndparams={})
158 095e71aa René Nussbaumer
    self.assertEqual(self.fake_cl.ndparams,
159 095e71aa René Nussbaumer
                     self.fake_cl.FillND(fake_node, fake_group))
160 095e71aa René Nussbaumer
161 095e71aa René Nussbaumer
  def testFillNdParamsNodeGroup(self):
162 095e71aa René Nussbaumer
    fake_node = objects.Node(name="test",
163 095e71aa René Nussbaumer
                             ndparams={},
164 095e71aa René Nussbaumer
                             group="testgroup")
165 095e71aa René Nussbaumer
    group_ndparams = {
166 432e8e2f Iustin Pop
        constants.ND_OOB_PROGRAM: "/bin/group-oob",
167 432e8e2f Iustin Pop
        constants.ND_SPINDLE_COUNT: 10,
168 0ea11dcb Bernardo Dal Seno
        constants.ND_EXCLUSIVE_STORAGE: True,
169 095e71aa René Nussbaumer
        }
170 095e71aa René Nussbaumer
    fake_group = objects.NodeGroup(name="testgroup",
171 095e71aa René Nussbaumer
                                   ndparams=group_ndparams)
172 095e71aa René Nussbaumer
    self.assertEqual(group_ndparams,
173 095e71aa René Nussbaumer
                     self.fake_cl.FillND(fake_node, fake_group))
174 095e71aa René Nussbaumer
175 095e71aa René Nussbaumer
  def testFillNdParamsNode(self):
176 095e71aa René Nussbaumer
    node_ndparams = {
177 432e8e2f Iustin Pop
        constants.ND_OOB_PROGRAM: "/bin/node-oob",
178 432e8e2f Iustin Pop
        constants.ND_SPINDLE_COUNT: 2,
179 0ea11dcb Bernardo Dal Seno
        constants.ND_EXCLUSIVE_STORAGE: True,
180 095e71aa René Nussbaumer
        }
181 095e71aa René Nussbaumer
    fake_node = objects.Node(name="test",
182 095e71aa René Nussbaumer
                             ndparams=node_ndparams,
183 095e71aa René Nussbaumer
                             group="testgroup")
184 095e71aa René Nussbaumer
    fake_group = objects.NodeGroup(name="testgroup",
185 095e71aa René Nussbaumer
                                   ndparams={})
186 095e71aa René Nussbaumer
    self.assertEqual(node_ndparams,
187 095e71aa René Nussbaumer
                     self.fake_cl.FillND(fake_node, fake_group))
188 095e71aa René Nussbaumer
189 095e71aa René Nussbaumer
  def testFillNdParamsAll(self):
190 095e71aa René Nussbaumer
    node_ndparams = {
191 432e8e2f Iustin Pop
        constants.ND_OOB_PROGRAM: "/bin/node-oob",
192 432e8e2f Iustin Pop
        constants.ND_SPINDLE_COUNT: 5,
193 0ea11dcb Bernardo Dal Seno
        constants.ND_EXCLUSIVE_STORAGE: True,
194 095e71aa René Nussbaumer
        }
195 095e71aa René Nussbaumer
    fake_node = objects.Node(name="test",
196 095e71aa René Nussbaumer
                             ndparams=node_ndparams,
197 095e71aa René Nussbaumer
                             group="testgroup")
198 095e71aa René Nussbaumer
    group_ndparams = {
199 432e8e2f Iustin Pop
        constants.ND_OOB_PROGRAM: "/bin/group-oob",
200 432e8e2f Iustin Pop
        constants.ND_SPINDLE_COUNT: 4,
201 095e71aa René Nussbaumer
        }
202 095e71aa René Nussbaumer
    fake_group = objects.NodeGroup(name="testgroup",
203 095e71aa René Nussbaumer
                                   ndparams=group_ndparams)
204 095e71aa René Nussbaumer
    self.assertEqual(node_ndparams,
205 095e71aa René Nussbaumer
                     self.fake_cl.FillND(fake_node, fake_group))
206 095e71aa René Nussbaumer
207 0fbedb7a Michael Hanselmann
  def testPrimaryHypervisor(self):
208 0fbedb7a Michael Hanselmann
    assert self.fake_cl.enabled_hypervisors is None
209 0fbedb7a Michael Hanselmann
    self.fake_cl.enabled_hypervisors = [constants.HT_XEN_HVM]
210 0fbedb7a Michael Hanselmann
    self.assertEqual(self.fake_cl.primary_hypervisor, constants.HT_XEN_HVM)
211 0fbedb7a Michael Hanselmann
212 0fbedb7a Michael Hanselmann
    self.fake_cl.enabled_hypervisors = [constants.HT_XEN_PVM, constants.HT_KVM]
213 0fbedb7a Michael Hanselmann
    self.assertEqual(self.fake_cl.primary_hypervisor, constants.HT_XEN_PVM)
214 0fbedb7a Michael Hanselmann
215 0fbedb7a Michael Hanselmann
    self.fake_cl.enabled_hypervisors = sorted(constants.HYPER_TYPES)
216 0fbedb7a Michael Hanselmann
    self.assertEqual(self.fake_cl.primary_hypervisor, constants.HT_CHROOT)
217 0fbedb7a Michael Hanselmann
218 7b64b9ea René Nussbaumer
219 870dc44c Iustin Pop
class TestOS(unittest.TestCase):
220 870dc44c Iustin Pop
  ALL_DATA = [
221 870dc44c Iustin Pop
    "debootstrap",
222 870dc44c Iustin Pop
    "debootstrap+default",
223 870dc44c Iustin Pop
    "debootstrap++default",
224 870dc44c Iustin Pop
    ]
225 870dc44c Iustin Pop
226 870dc44c Iustin Pop
  def testSplitNameVariant(self):
227 870dc44c Iustin Pop
    for name in self.ALL_DATA:
228 870dc44c Iustin Pop
      self.assertEqual(len(objects.OS.SplitNameVariant(name)), 2)
229 870dc44c Iustin Pop
230 870dc44c Iustin Pop
  def testVariant(self):
231 870dc44c Iustin Pop
    self.assertEqual(objects.OS.GetVariant("debootstrap"), "")
232 870dc44c Iustin Pop
    self.assertEqual(objects.OS.GetVariant("debootstrap+default"), "default")
233 870dc44c Iustin Pop
234 870dc44c Iustin Pop
235 6a050007 Michael Hanselmann
class TestInstance(unittest.TestCase):
236 6a050007 Michael Hanselmann
  def _GenericCheck(self, inst):
237 6a050007 Michael Hanselmann
    for i in [inst.all_nodes, inst.secondary_nodes]:
238 6a050007 Michael Hanselmann
      self.assertTrue(isinstance(inst.all_nodes, (list, tuple)),
239 6a050007 Michael Hanselmann
                      msg="Data type doesn't guarantee order")
240 6a050007 Michael Hanselmann
241 6a050007 Michael Hanselmann
    self.assertTrue(inst.primary_node not in inst.secondary_nodes)
242 6a050007 Michael Hanselmann
    self.assertEqual(inst.all_nodes[0], inst.primary_node,
243 6a050007 Michael Hanselmann
                     msg="Primary node not first node in list")
244 6a050007 Michael Hanselmann
245 6a050007 Michael Hanselmann
  def testNodesNoDisks(self):
246 6a050007 Michael Hanselmann
    inst = objects.Instance(name="fakeinst.example.com",
247 6a050007 Michael Hanselmann
      primary_node="pnode.example.com",
248 6a050007 Michael Hanselmann
      disks=[
249 6a050007 Michael Hanselmann
        ])
250 6a050007 Michael Hanselmann
251 6a050007 Michael Hanselmann
    self._GenericCheck(inst)
252 6a050007 Michael Hanselmann
    self.assertEqual(len(inst.secondary_nodes), 0)
253 6a050007 Michael Hanselmann
    self.assertEqual(set(inst.all_nodes), set([inst.primary_node]))
254 6a050007 Michael Hanselmann
    self.assertEqual(inst.MapLVsByNode(), {
255 6a050007 Michael Hanselmann
      inst.primary_node: [],
256 6a050007 Michael Hanselmann
      })
257 6a050007 Michael Hanselmann
258 6a050007 Michael Hanselmann
  def testNodesPlainDisks(self):
259 6a050007 Michael Hanselmann
    inst = objects.Instance(name="fakeinstplain.example.com",
260 6a050007 Michael Hanselmann
      primary_node="node3.example.com",
261 6a050007 Michael Hanselmann
      disks=[
262 6a050007 Michael Hanselmann
        objects.Disk(dev_type=constants.LD_LV, size=128,
263 6a050007 Michael Hanselmann
                     logical_id=("myxenvg", "disk25494")),
264 6a050007 Michael Hanselmann
        objects.Disk(dev_type=constants.LD_LV, size=512,
265 6a050007 Michael Hanselmann
                     logical_id=("myxenvg", "disk29071")),
266 6a050007 Michael Hanselmann
        ])
267 6a050007 Michael Hanselmann
268 6a050007 Michael Hanselmann
    self._GenericCheck(inst)
269 6a050007 Michael Hanselmann
    self.assertEqual(len(inst.secondary_nodes), 0)
270 6a050007 Michael Hanselmann
    self.assertEqual(set(inst.all_nodes), set([inst.primary_node]))
271 6a050007 Michael Hanselmann
    self.assertEqual(inst.MapLVsByNode(), {
272 6a050007 Michael Hanselmann
      inst.primary_node: ["myxenvg/disk25494", "myxenvg/disk29071"],
273 6a050007 Michael Hanselmann
      })
274 6a050007 Michael Hanselmann
275 6a050007 Michael Hanselmann
  def testNodesDrbdDisks(self):
276 6a050007 Michael Hanselmann
    inst = objects.Instance(name="fakeinstdrbd.example.com",
277 6a050007 Michael Hanselmann
      primary_node="node10.example.com",
278 6a050007 Michael Hanselmann
      disks=[
279 6a050007 Michael Hanselmann
        objects.Disk(dev_type=constants.LD_DRBD8, size=786432,
280 6a050007 Michael Hanselmann
          logical_id=("node10.example.com", "node15.example.com",
281 6a050007 Michael Hanselmann
                      12300, 0, 0, "secret"),
282 6a050007 Michael Hanselmann
          children=[
283 6a050007 Michael Hanselmann
            objects.Disk(dev_type=constants.LD_LV, size=786432,
284 6a050007 Michael Hanselmann
                         logical_id=("myxenvg", "disk0")),
285 6a050007 Michael Hanselmann
            objects.Disk(dev_type=constants.LD_LV, size=128,
286 6a050007 Michael Hanselmann
                         logical_id=("myxenvg", "meta0"))
287 6a050007 Michael Hanselmann
          ],
288 6a050007 Michael Hanselmann
          iv_name="disk/0")
289 6a050007 Michael Hanselmann
        ])
290 6a050007 Michael Hanselmann
291 6a050007 Michael Hanselmann
    self._GenericCheck(inst)
292 6a050007 Michael Hanselmann
    self.assertEqual(set(inst.secondary_nodes), set(["node15.example.com"]))
293 6a050007 Michael Hanselmann
    self.assertEqual(set(inst.all_nodes),
294 6a050007 Michael Hanselmann
                     set([inst.primary_node, "node15.example.com"]))
295 6a050007 Michael Hanselmann
    self.assertEqual(inst.MapLVsByNode(), {
296 6a050007 Michael Hanselmann
      inst.primary_node: ["myxenvg/disk0", "myxenvg/meta0"],
297 6a050007 Michael Hanselmann
      "node15.example.com": ["myxenvg/disk0", "myxenvg/meta0"],
298 6a050007 Michael Hanselmann
      })
299 6a050007 Michael Hanselmann
300 6a050007 Michael Hanselmann
    self.assertEqual(inst.FindDisk(0), inst.disks[0])
301 6a050007 Michael Hanselmann
    self.assertRaises(errors.OpPrereqError, inst.FindDisk, "hello")
302 6a050007 Michael Hanselmann
    self.assertRaises(errors.OpPrereqError, inst.FindDisk, 100)
303 6a050007 Michael Hanselmann
    self.assertRaises(errors.OpPrereqError, inst.FindDisk, 1)
304 6a050007 Michael Hanselmann
305 6a050007 Michael Hanselmann
306 5f06ce5e Michael Hanselmann
class TestNode(unittest.TestCase):
307 5f06ce5e Michael Hanselmann
  def testEmpty(self):
308 5f06ce5e Michael Hanselmann
    self.assertEqual(objects.Node().ToDict(), {})
309 5f06ce5e Michael Hanselmann
    self.assertTrue(isinstance(objects.Node.FromDict({}), objects.Node))
310 5f06ce5e Michael Hanselmann
311 5f06ce5e Michael Hanselmann
  def testHvState(self):
312 5f06ce5e Michael Hanselmann
    node = objects.Node(name="node18157.example.com", hv_state={
313 5f06ce5e Michael Hanselmann
      constants.HT_XEN_HVM: objects.NodeHvState(cpu_total=64),
314 5f06ce5e Michael Hanselmann
      constants.HT_KVM: objects.NodeHvState(cpu_node=1),
315 5f06ce5e Michael Hanselmann
      })
316 5f06ce5e Michael Hanselmann
317 5f06ce5e Michael Hanselmann
    node2 = objects.Node.FromDict(node.ToDict())
318 5f06ce5e Michael Hanselmann
319 5f06ce5e Michael Hanselmann
    # Make sure nothing can reference it anymore
320 5f06ce5e Michael Hanselmann
    del node
321 5f06ce5e Michael Hanselmann
322 5f06ce5e Michael Hanselmann
    self.assertEqual(node2.name, "node18157.example.com")
323 5f06ce5e Michael Hanselmann
    self.assertEqual(frozenset(node2.hv_state), frozenset([
324 5f06ce5e Michael Hanselmann
      constants.HT_XEN_HVM,
325 5f06ce5e Michael Hanselmann
      constants.HT_KVM,
326 5f06ce5e Michael Hanselmann
      ]))
327 5f06ce5e Michael Hanselmann
    self.assertEqual(node2.hv_state[constants.HT_KVM].cpu_node, 1)
328 5f06ce5e Michael Hanselmann
    self.assertEqual(node2.hv_state[constants.HT_XEN_HVM].cpu_total, 64)
329 5f06ce5e Michael Hanselmann
330 5f06ce5e Michael Hanselmann
  def testDiskState(self):
331 5f06ce5e Michael Hanselmann
    node = objects.Node(name="node32087.example.com", disk_state={
332 5f06ce5e Michael Hanselmann
      constants.LD_LV: {
333 5f06ce5e Michael Hanselmann
        "lv32352": objects.NodeDiskState(total=128),
334 5f06ce5e Michael Hanselmann
        "lv2082": objects.NodeDiskState(total=512),
335 5f06ce5e Michael Hanselmann
        },
336 5f06ce5e Michael Hanselmann
      })
337 5f06ce5e Michael Hanselmann
338 5f06ce5e Michael Hanselmann
    node2 = objects.Node.FromDict(node.ToDict())
339 5f06ce5e Michael Hanselmann
340 5f06ce5e Michael Hanselmann
    # Make sure nothing can reference it anymore
341 5f06ce5e Michael Hanselmann
    del node
342 5f06ce5e Michael Hanselmann
343 5f06ce5e Michael Hanselmann
    self.assertEqual(node2.name, "node32087.example.com")
344 5f06ce5e Michael Hanselmann
    self.assertEqual(frozenset(node2.disk_state), frozenset([
345 5f06ce5e Michael Hanselmann
      constants.LD_LV,
346 5f06ce5e Michael Hanselmann
      ]))
347 5f06ce5e Michael Hanselmann
    self.assertEqual(frozenset(node2.disk_state[constants.LD_LV]), frozenset([
348 5f06ce5e Michael Hanselmann
      "lv32352",
349 5f06ce5e Michael Hanselmann
      "lv2082",
350 5f06ce5e Michael Hanselmann
      ]))
351 5f06ce5e Michael Hanselmann
    self.assertEqual(node2.disk_state[constants.LD_LV]["lv2082"].total, 512)
352 5f06ce5e Michael Hanselmann
    self.assertEqual(node2.disk_state[constants.LD_LV]["lv32352"].total, 128)
353 5f06ce5e Michael Hanselmann
354 5f06ce5e Michael Hanselmann
355 2f96c43c Michael Hanselmann
if __name__ == "__main__":
356 25231ec5 Michael Hanselmann
  testutils.GanetiTestProgram()