diff options
author | zte-hanrong <han.rong3@zte.com.cn> | 2016-06-02 19:23:46 +0800 |
---|---|---|
committer | Sean Dague <sean@dague.net> | 2016-06-07 07:51:46 -0400 |
commit | 8093b764a9430a4e1c8cf2d73068f08117fec90e (patch) | |
tree | 9178810ec183627ab4f5ae2d87a266e5fb539e15 /nova/tests/unit/test_conf.py | |
parent | cfd64c976b8aaacaf09fd2a6303877674fcfada0 (diff) | |
download | nova-8093b764a9430a4e1c8cf2d73068f08117fec90e.tar.gz |
Fix nova-compute start failed when reserved_huge_pages has value.
The problem is due to this change:
https://review.openstack.org/#/c/292499/20/nova/conf/virt.py
The code of item_type=types.Dict is not correct, modfiy by
item_type=types.Dict().
Modify the usage discription of config of reserved_huge_pages.
Usage of oslo_config.types.Dict is key:value pairs separated by
commas.
Add unit test because this is a complicated option that might not work
like people expect.
Closes-Bug:#1588305
Change-Id: I06490866f24617cf99764ede73a1938c2d7b7b5c
Diffstat (limited to 'nova/tests/unit/test_conf.py')
-rw-r--r-- | nova/tests/unit/test_conf.py | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/nova/tests/unit/test_conf.py b/nova/tests/unit/test_conf.py new file mode 100644 index 0000000000..17f3630cea --- /dev/null +++ b/nova/tests/unit/test_conf.py @@ -0,0 +1,82 @@ +# Copyright 2016 HPE, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os +import tempfile + +import fixtures +from oslo_config import cfg + +import nova.conf.virt +from nova import test + + +class ConfTest(test.NoDBTestCase): + """This is a test and pattern for parsing tricky options.""" + + class TestConfigOpts(cfg.ConfigOpts): + def __call__(self, args=None, default_config_files=None): + if default_config_files is None: + default_config_files = [] + return cfg.ConfigOpts.__call__( + self, + args=args, + prog='test', + version='1.0', + usage='%(prog)s FOO BAR', + default_config_files=default_config_files, + validate_default_values=True) + + def setUp(self): + super(ConfTest, self).setUp() + self.useFixture(fixtures.NestedTempfile()) + self.conf = self.TestConfigOpts() + self.tempdirs = [] + + def create_tempfiles(self, files, ext='.conf'): + tempfiles = [] + for (basename, contents) in files: + if not os.path.isabs(basename): + (fd, path) = tempfile.mkstemp(prefix=basename, suffix=ext) + else: + path = basename + ext + fd = os.open(path, os.O_CREAT | os.O_WRONLY) + tempfiles.append(path) + try: + os.write(fd, contents.encode('utf-8')) + finally: + os.close(fd) + return tempfiles + + def test_reserved_huge_page(self): + nova.conf.virt.register_opts(self.conf) + + paths = self.create_tempfiles( + [('1', + '[DEFAULT]\n' + 'reserved_huge_pages = node:0,size:2048,count:64\n')]) + self.conf(['--config-file', paths[0]]) + # NOTE(sdague): In oslo.config if you specify a parameter + # incorrectly, it silently drops it from the conf. Which means + # the attr doesn't exist at all. The first attr test here is + # for an unrelated boolean option that is using defaults (so + # will always work. It's a basic control that *anything* is working. + self.assertTrue(hasattr(self.conf, 'force_raw_images')) + self.assertTrue(hasattr(self.conf, 'reserved_huge_pages'), + "Parse error with reserved_huge_pages") + + # NOTE(sdague): Yes, this actually parses as an array holding + # a dict. + actual = [{'node': '0', 'size': '2048', 'count': '64'}] + self.assertEqual(actual, self.conf.reserved_huge_pages) |