Revision 7b64b9ea
b/test/ganeti.objects_unittest.py | ||
---|---|---|
24 | 24 |
|
25 | 25 |
import unittest |
26 | 26 |
|
27 |
from ganeti import constants |
|
27 | 28 |
from ganeti import objects |
28 | 29 |
|
29 | 30 |
import testutils |
... | ... | |
48 | 49 |
self.assertEquals(o1.ToDict(), {'a': 2, 'b': 5}) |
49 | 50 |
|
50 | 51 |
|
52 |
class TestClusterObject(unittest.TestCase): |
|
53 |
"""Tests done on a L{objects.Cluster}""" |
|
54 |
|
|
55 |
def setUp(self): |
|
56 |
hvparams = { |
|
57 |
constants.HT_FAKE: { |
|
58 |
"foo": "bar", |
|
59 |
"bar": "foo", |
|
60 |
"foobar": "barfoo", |
|
61 |
}, |
|
62 |
} |
|
63 |
os_hvp = { |
|
64 |
"lenny-image": { |
|
65 |
constants.HT_FAKE: { |
|
66 |
"foo": "baz", |
|
67 |
"foobar": "foobar", |
|
68 |
"blah": "blibb", |
|
69 |
"blubb": "blah", |
|
70 |
}, |
|
71 |
constants.HT_XEN_PVM: { |
|
72 |
"root_path": "/dev/sda5", |
|
73 |
"foo": "foobar", |
|
74 |
}, |
|
75 |
}, |
|
76 |
"ubuntu-hardy": { |
|
77 |
}, |
|
78 |
} |
|
79 |
self.fake_cl = objects.Cluster(hvparams=hvparams, os_hvp=os_hvp) |
|
80 |
self.fake_cl.UpgradeConfig() |
|
81 |
|
|
82 |
def testFillHvFullMerge(self): |
|
83 |
inst_hvparams = { |
|
84 |
"blah": "blubb", |
|
85 |
} |
|
86 |
|
|
87 |
fake_dict = { |
|
88 |
"foo": "baz", |
|
89 |
"bar": "foo", |
|
90 |
"foobar": "foobar", |
|
91 |
"blah": "blubb", |
|
92 |
"blubb": "blah", |
|
93 |
} |
|
94 |
fake_inst = objects.Instance(name="foobar", |
|
95 |
os="lenny-image", |
|
96 |
hypervisor=constants.HT_FAKE, |
|
97 |
hvparams=inst_hvparams) |
|
98 |
self.assertEqual(fake_dict, self.fake_cl.FillHV(fake_inst)) |
|
99 |
|
|
100 |
def testFillHvGlobalParams(self): |
|
101 |
fake_inst = objects.Instance(name="foobar", |
|
102 |
os="ubuntu-hardy", |
|
103 |
hypervisor=constants.HT_FAKE, |
|
104 |
hvparams={}) |
|
105 |
self.assertEqual(self.fake_cl.hvparams[constants.HT_FAKE], |
|
106 |
self.fake_cl.FillHV(fake_inst)) |
|
107 |
|
|
108 |
def testFillHvInstParams(self): |
|
109 |
inst_hvparams = { |
|
110 |
"blah": "blubb", |
|
111 |
} |
|
112 |
fake_inst = objects.Instance(name="foobar", |
|
113 |
os="ubuntu-hardy", |
|
114 |
hypervisor=constants.HT_XEN_PVM, |
|
115 |
hvparams=inst_hvparams) |
|
116 |
self.assertEqual(inst_hvparams, self.fake_cl.FillHV(fake_inst)) |
|
117 |
|
|
118 |
def testFillHvEmptyParams(self): |
|
119 |
fake_inst = objects.Instance(name="foobar", |
|
120 |
os="ubuntu-hardy", |
|
121 |
hypervisor=constants.HT_XEN_PVM, |
|
122 |
hvparams={}) |
|
123 |
self.assertEqual({}, self.fake_cl.FillHV(fake_inst)) |
|
124 |
|
|
125 |
def testFillHvPartialParams(self): |
|
126 |
os = "lenny-image" |
|
127 |
fake_inst = objects.Instance(name="foobar", |
|
128 |
os=os, |
|
129 |
hypervisor=constants.HT_XEN_PVM, |
|
130 |
hvparams={}) |
|
131 |
self.assertEqual(self.fake_cl.os_hvp[os][constants.HT_XEN_PVM], |
|
132 |
self.fake_cl.FillHV(fake_inst)) |
|
133 |
|
|
134 |
|
|
51 | 135 |
if __name__ == '__main__': |
52 | 136 |
testutils.GanetiTestProgram() |
Also available in: Unified diff