Revision a20e4768
b/lib/cmdlib.py | ||
---|---|---|
32 | 32 |
import os.path |
33 | 33 |
import time |
34 | 34 |
import re |
35 |
import platform |
|
36 | 35 |
import logging |
37 | 36 |
import copy |
38 | 37 |
import OpenSSL |
... | ... | |
59 | 58 |
from ganeti import qlang |
60 | 59 |
from ganeti import opcodes |
61 | 60 |
from ganeti import ht |
61 |
from ganeti import runtime |
|
62 | 62 |
|
63 | 63 |
import ganeti.masterd.instance # pylint: disable=W0611 |
64 | 64 |
|
... | ... | |
5520 | 5520 |
"config_version": constants.CONFIG_VERSION, |
5521 | 5521 |
"os_api_version": max(constants.OS_API_VERSIONS), |
5522 | 5522 |
"export_version": constants.EXPORT_VERSION, |
5523 |
"architecture": (platform.architecture()[0], platform.machine()),
|
|
5523 |
"architecture": runtime.GetArchInfo(),
|
|
5524 | 5524 |
"name": cluster.cluster_name, |
5525 | 5525 |
"master": cluster.master_node, |
5526 | 5526 |
"default_hypervisor": cluster.enabled_hypervisors[0], |
b/lib/runtime.py | ||
---|---|---|
26 | 26 |
import grp |
27 | 27 |
import pwd |
28 | 28 |
import threading |
29 |
import platform |
|
29 | 30 |
|
30 | 31 |
from ganeti import constants |
31 | 32 |
from ganeti import errors |
... | ... | |
35 | 36 |
_priv = None |
36 | 37 |
_priv_lock = threading.Lock() |
37 | 38 |
|
39 |
#: Architecture information |
|
40 |
_arch = None |
|
41 |
|
|
38 | 42 |
|
39 | 43 |
def GetUid(user, _getpwnam): |
40 | 44 |
"""Retrieve the uid from the database. |
... | ... | |
187 | 191 |
_priv_lock.release() |
188 | 192 |
|
189 | 193 |
return _priv |
194 |
|
|
195 |
|
|
196 |
def InitArchInfo(): |
|
197 |
"""Initialize architecture information. |
|
198 |
|
|
199 |
We can assume this information never changes during the lifetime of a |
|
200 |
process, therefore the information can easily be cached. |
|
201 |
|
|
202 |
@note: This function uses C{platform.architecture} to retrieve the Python |
|
203 |
binary architecture and does so by forking to run C{file} (see Python |
|
204 |
documentation for more information). Therefore it must not be used in a |
|
205 |
multi-threaded environment. |
|
206 |
|
|
207 |
""" |
|
208 |
global _arch # pylint: disable=W0603 |
|
209 |
|
|
210 |
if _arch is not None: |
|
211 |
raise errors.ProgrammerError("Architecture information can only be" |
|
212 |
" initialized once") |
|
213 |
|
|
214 |
_arch = (platform.architecture()[0], platform.machine()) |
|
215 |
|
|
216 |
|
|
217 |
def GetArchInfo(): |
|
218 |
"""Returns previsouly initialized architecture information. |
|
219 |
|
|
220 |
""" |
|
221 |
if _arch is None: |
|
222 |
raise errors.ProgrammerError("Architecture information hasn't been" |
|
223 |
" initialized") |
|
224 |
|
|
225 |
return _arch |
b/lib/server/masterd.py | ||
---|---|---|
57 | 57 |
from ganeti import netutils |
58 | 58 |
from ganeti import objects |
59 | 59 |
from ganeti import query |
60 |
from ganeti import runtime |
|
60 | 61 |
|
61 | 62 |
|
62 | 63 |
CLIENT_REQUEST_WORKERS = 16 |
... | ... | |
548 | 549 |
(constants.MASTERD_USER, constants.DAEMONS_GROUP)) |
549 | 550 |
sys.exit(constants.EXIT_FAILURE) |
550 | 551 |
|
552 |
# Determine static runtime architecture information |
|
553 |
runtime.InitArchInfo() |
|
554 |
|
|
551 | 555 |
# Check the configuration is sane before anything else |
552 | 556 |
try: |
553 | 557 |
config.ConfigWriter() |
b/test/ganeti.runtime_unittest.py | ||
---|---|---|
23 | 23 |
from ganeti import constants |
24 | 24 |
from ganeti import errors |
25 | 25 |
from ganeti import runtime |
26 |
from ganeti import ht |
|
26 | 27 |
|
27 | 28 |
import testutils |
28 | 29 |
import unittest |
... | ... | |
138 | 139 |
self.resolver.LookupGroup, "does-not-exist-foo") |
139 | 140 |
|
140 | 141 |
|
142 |
class TestArchInfo(unittest.TestCase): |
|
143 |
EXP_TYPES = \ |
|
144 |
ht.TAnd(ht.TIsLength(2), |
|
145 |
ht.TItems([ |
|
146 |
ht.TNonEmptyString, |
|
147 |
ht.TNonEmptyString, |
|
148 |
])) |
|
149 |
|
|
150 |
def setUp(self): |
|
151 |
self.assertTrue(runtime._arch is None) |
|
152 |
|
|
153 |
def tearDown(self): |
|
154 |
runtime._arch = None |
|
155 |
|
|
156 |
def testNotInitialized(self): |
|
157 |
self.assertRaises(errors.ProgrammerError, runtime.GetArchInfo) |
|
158 |
|
|
159 |
def testInitializeMultiple(self): |
|
160 |
runtime.InitArchInfo() |
|
161 |
|
|
162 |
self.assertRaises(errors.ProgrammerError, runtime.InitArchInfo) |
|
163 |
|
|
164 |
def testNormal(self): |
|
165 |
runtime.InitArchInfo() |
|
166 |
|
|
167 |
info = runtime.GetArchInfo() |
|
168 |
|
|
169 |
self.assertTrue(self.EXP_TYPES(info), |
|
170 |
msg=("Doesn't match expected type description: %s" % |
|
171 |
self.EXP_TYPES)) |
|
172 |
|
|
173 |
|
|
141 | 174 |
if __name__ == "__main__": |
142 | 175 |
testutils.GanetiTestProgram() |
Also available in: Unified diff