1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# Copyright (C) 2013 Hewlett-Packard Development Company, L.P.
#
# Author: Juerg Haefliger <juerg.haefliger@hp.com>
#
# This file is part of cloud-init. See LICENSE file for license information.
from cloudinit.config import cc_locale
from cloudinit import cloud
from cloudinit import distros
from cloudinit import helpers
from cloudinit import util
from cloudinit.sources import DataSourceNoCloud
from .. import helpers as t_help
from configobj import ConfigObj
from six import BytesIO
import logging
import shutil
import tempfile
LOG = logging.getLogger(__name__)
class TestLocale(t_help.FilesystemMockingTestCase):
def setUp(self):
super(TestLocale, self).setUp()
self.new_root = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, self.new_root)
def _get_cloud(self, distro):
self.patchUtils(self.new_root)
paths = helpers.Paths({})
cls = distros.fetch(distro)
d = cls(distro, {}, paths)
ds = DataSourceNoCloud.DataSourceNoCloud({}, d, paths)
cc = cloud.Cloud(ds, paths, {}, d, None)
return cc
def test_set_locale_sles(self):
cfg = {
'locale': 'My.Locale',
}
cc = self._get_cloud('sles')
cc_locale.handle('cc_locale', cfg, cc, LOG, [])
if cc.distro.uses_systemd():
locale_conf = cc.distro.systemd_locale_conf_fn
else:
locale_conf = cc.distro.locale_conf_fn
contents = util.load_file(locale_conf, decode=False)
n_cfg = ConfigObj(BytesIO(contents))
if cc.distro.uses_systemd():
self.assertEqual({'LANG': cfg['locale']}, dict(n_cfg))
else:
self.assertEqual({'RC_LANG': cfg['locale']}, dict(n_cfg))
# vi: ts=4 expandtab
|