def create(self, conf_path, extra_options=None): self.conf.read(os.path.join(os.path.dirname(__file__), "config.ini")) for name, method in inspect.getmembers(self, inspect.ismethod): if name.startswith("_configure_"): method() if extra_options: utils.add_extra_options(extra_options, self.conf) with open(conf_path, "w") as configfile: self.conf.write(configfile) raw_conf = six.StringIO() raw_conf.write("# Some empty values of options will be replaced while " "creating required resources (images, flavors, etc).\n") self.conf.write(raw_conf) return raw_conf.getvalue()
def test_add_extra_options(self): conf = configparser.ConfigParser() extra_options = {"section": {"foo": "bar"}, "section2": {"option": "value"}} conf = utils.add_extra_options(extra_options, conf) expected = {"section": ("foo", "bar"), "section2": ("option", "value")} for section, option in expected.items(): result = conf.items(section) self.assertIn(option, result)
def test_add_extra_options(self): conf = configparser.ConfigParser() extra_options = { "section": { "foo": "bar" }, "section2": { "option": "value" } } conf = utils.add_extra_options(extra_options, conf) expected = {"section": ("foo", "bar"), "section2": ("option", "value")} for section, option in expected.items(): result = conf.items(section) self.assertIn(option, result)