本文整理汇总了Python中cloudinstall.config.Config.setopt方法的典型用法代码示例。如果您正苦于以下问题:Python Config.setopt方法的具体用法?Python Config.setopt怎么用?Python Config.setopt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudinstall.config.Config
的用法示例。
在下文中一共展示了Config.setopt方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: WaitForDeployedServicesReadyCoreTestCase
# 需要导入模块: from cloudinstall.config import Config [as 别名]
# 或者: from cloudinstall.config.Config import setopt [as 别名]
class WaitForDeployedServicesReadyCoreTestCase(unittest.TestCase):
""" Tests core.wait_for_deployed_services_ready to make sure waiting
for services to start are handled properly.
"""
def setUp(self):
self.conf = Config({})
self.mock_ui = MagicMock(name='ui')
self.mock_log = MagicMock(name='log')
self.mock_loop = MagicMock(name='loop')
self.conf.setopt('headless', False)
self.dc = Controller(
ui=self.mock_ui, config=self.conf,
loop=self.mock_loop)
self.dc.initialize = MagicMock()
self.dc.juju_state = JujuState(juju=MagicMock())
self.dc.juju_state.all_agents_started = MagicMock()
def test_validate_services_ready(self):
""" Verifies wait_for_deployed_services_ready
time.sleep should not be called here as all services
are in a started state.
"""
self.dc.juju_state.all_agents_started.return_value = True
with patch('cloudinstall.core.time.sleep') as mock_sleep:
self.dc.wait_for_deployed_services_ready()
self.assertEqual(len(mock_sleep.mock_calls), 0)
def test_validate_services_some_ready(self):
""" Verifies wait_for_deployed_services_ready against some of the
services in started state
Here we test if time.sleep was called twice due to some services
being in an installing and allocating state.
"""
self.dc.juju_state.all_agents_started.side_effect = [
False, False, True, True]
with patch('cloudinstall.core.time.sleep') as mock_sleep:
self.dc.wait_for_deployed_services_ready()
print(mock_sleep.mock_calls)
self.assertEqual(len(mock_sleep.mock_calls), 2)
示例2: MultiInstallNewMaasTestCase
# 需要导入模块: from cloudinstall.config import Config [as 别名]
# 或者: from cloudinstall.config.Config import setopt [as 别名]
class MultiInstallNewMaasTestCase(unittest.TestCase):
def setUp(self):
with NamedTemporaryFile(mode='w+', encoding='utf-8') as tempf:
# Override config file to save to
self.conf = Config({}, tempf.name)
self.conf.setopt('openstack_password', 'ampersand&')
def make_installer(self, loop=None, dc=None):
if dc is None:
dc = MagicMock(name="display_controller")
if loop is None:
loop = MagicMock(name="loop")
self.installer = MultiInstallNewMaas(
loop, dc, self.conf)
def _create_superuser(self, raises):
expected = ("maas-region-admin createadmin --username root "
"--password 'ampersand&' "
"--email [email protected]")
self.make_installer()
with patch('cloudinstall.multi_install.utils') as mock_utils:
if raises:
mock_utils.get_command_output.return_value = {'status': -1}
self.assertRaises(MaasInstallError,
self.installer.create_superuser)
else:
mock_utils.get_command_output.return_value = {'status': 0}
self.installer.create_superuser()
mock_utils.get_command_output.assert_called_with(expected)
def test_create_superuser_raises(self):
self._create_superuser(True)
def test_create_superuser_ok(self):
self._create_superuser(False)
示例3: ControllerStateTestCase
# 需要导入模块: from cloudinstall.config import Config [as 别名]
# 或者: from cloudinstall.config.Config import setopt [as 别名]
class ControllerStateTestCase(unittest.TestCase):
def setUp(self):
with NamedTemporaryFile(mode='w+', encoding='utf-8') as tempf:
# Override config file to save to
self.conf = Config({}, tempf.name, save_backups=False)
self.bad_states_int = [5, 6, 7]
self.good_states_int = [0, 1, 2]
def test_set_controller_state(self):
""" Validate config controller state """
for i in self.bad_states_int:
self.conf.setopt('current_state', i)
with self.assertRaises(ValueError):
s = self.conf.getopt('current_state')
ControllerState(s)
for i in self.good_states_int:
self.conf.setopt('current_state', i)
s = self.conf.getopt('current_state')
self.assertEqual(ControllerState(s), i)
示例4: InstallStateTestCase
# 需要导入模块: from cloudinstall.config import Config [as 别名]
# 或者: from cloudinstall.config.Config import setopt [as 别名]
class InstallStateTestCase(unittest.TestCase):
def setUp(self):
with NamedTemporaryFile(mode='w+', encoding='utf-8') as tempf:
# Override config file to save to
self.conf = Config({}, tempf.name)
self.bad_states_int = [5, 6, 7]
self.good_states_int = [0, 1]
def test_install_state(self):
""" Validate config install state """
for i in self.bad_states_int:
self.conf.setopt('current_state', i)
with self.assertRaises(ValueError):
s = self.conf.getopt('current_state')
InstallState(s)
for i in self.good_states_int:
self.conf.setopt('current_state', i)
s = self.conf.getopt('current_state')
self.assertEqual(InstallState(s), i)
示例5: EventLoopCoreTestCase
# 需要导入模块: from cloudinstall.config import Config [as 别名]
# 或者: from cloudinstall.config.Config import setopt [as 别名]
class EventLoopCoreTestCase(unittest.TestCase):
def setUp(self):
self.conf = Config({})
self.mock_ui = MagicMock(name='ui')
self.mock_log = MagicMock(name='log')
self.mock_loop = MagicMock(name='loop')
def make_ev(self, headless=False):
self.conf.setopt('headless', headless)
return EventLoop(self.mock_ui, self.conf,
self.mock_log)
def test_validate_loop(self):
""" Validate eventloop runs """
self.conf.setopt('headless', False)
dc = Controller(
ui=self.mock_ui, config=self.conf,
loop=self.mock_loop)
dc.initialize = MagicMock()
dc.start()
self.mock_loop.run.assert_called_once_with()
def test_validate_redraw_screen_commit_placement(self):
""" Validate redraw_screen on commit_placement """
self.conf.setopt('headless', False)
dc = Controller(
ui=self.mock_ui, config=self.conf,
loop=self.mock_loop)
dc.initialize = MagicMock()
dc.commit_placement()
self.mock_loop.redraw_screen.assert_called_once_with()
def test_validate_redraw_screen_enqueue(self):
""" Validate redraw_screen on enqueue_deployed_charms """
self.conf.setopt('headless', False)
dc = Controller(
ui=self.mock_ui, config=self.conf,
loop=self.mock_loop)
dc.initialize = MagicMock()
dc.enqueue_deployed_charms()
self.mock_loop.redraw_screen.assert_called_once_with()
def test_validate_set_alarm_in(self):
""" Validate set_alarm_in called with eventloop """
dc = Controller(
ui=self.mock_ui, config=self.conf,
loop=self.mock_loop)
dc.initialize = MagicMock()
self.conf.node_install_wait_interval = 1
dc.update(self.conf.node_install_wait_interval, ANY)
self.mock_loop.set_alarm_in.assert_called_once_with(1, ANY)
def test_validate_exit(self):
""" Validate error code set with eventloop """
ev = self.make_ev()
dc = Controller(
ui=self.mock_ui, config=self.conf,
loop=ev)
dc.initialize = MagicMock()
with self.assertRaises(urwid.ExitMainLoop):
dc.loop.exit(1)
self.assertEqual(ev.error_code, 1)
def test_hotkey_exit(self):
ev = self.make_ev()
dc = Controller(
ui=self.mock_ui, config=self.conf,
loop=ev)
dc.initialize = MagicMock()
with self.assertRaises(urwid.ExitMainLoop):
dc.loop.header_hotkeys('q')
self.assertEqual(ev.error_code, 0)
def test_repr_ev(self):
""" Prints appropriate class string for eventloop """
ev = self.make_ev()
dc = Controller(
ui=self.mock_ui, config=self.conf,
loop=ev)
dc.initialize = MagicMock()
self.assertEqual(str(ev), '<eventloop urwid based on select()>')
def test_repr_no_ev(self):
""" Prints appropriate class string for no eventloop """
ev = self.make_ev(True)
dc = Controller(
ui=self.mock_ui, config=self.conf,
loop=ev)
dc.initialize = MagicMock()
self.assertEqual(str(ev), '<eventloop disabled>')
def test_validate_exit_no_ev(self):
""" Validate SystemExit with no eventloop """
ev = self.make_ev(True)
dc = Controller(
ui=self.mock_ui, config=self.conf,
loop=ev)
dc.initialize = MagicMock()
with self.assertRaises(SystemExit) as cm:
#.........这里部分代码省略.........
示例6: TestGoodConfig
# 需要导入模块: from cloudinstall.config import Config [as 别名]
# 或者: from cloudinstall.config.Config import setopt [as 别名]
class TestGoodConfig(unittest.TestCase):
def setUp(self):
self._temp_conf = Config(GOOD_CONFIG)
with NamedTemporaryFile(mode='w+', encoding='utf-8') as tempf:
# Override config file to save to
self.conf = Config(self._temp_conf._config, tempf.name)
def test_save_openstack_password(self):
""" Save openstack password to config """
self.conf.setopt('openstack_password', 'pass')
self.conf.save()
self.assertEqual('pass', self.conf.getopt('openstack_password'))
def test_save_maas_creds(self):
""" Save maas credentials """
self.conf.setopt('maascreds', dict(api_host='127.0.0.1',
api_key='1234567'))
self.conf.save()
self.assertEqual(
'127.0.0.1', self.conf.getopt('maascreds')['api_host'])
def test_save_landscape_creds(self):
""" Save landscape credentials """
self.conf.setopt('landscapecreds',
dict(admin_name='foo',
admin_email='[email protected]',
system_email='[email protected]',
maas_server='127.0.0.1',
maas_apikey='123457'))
self.conf.save()
self.assertEqual(
'[email protected]', self.conf.getopt('landscapecreds')['admin_email'])
def test_save_installer_type(self):
""" Save installer type """
self.conf.setopt("install_type", 'multi')
self.conf.save()
self.assertEqual('multi', self.conf.getopt('install_type'))
@unittest.skip
def test_cfg_path(self):
""" Validate current users config path """
self.assertEqual(
self.conf.cfg_path, path.join(USER_DIR, '.cloud-install'))
def test_bin_path(self):
""" Validate additional tools bin path """
self.assertEqual(self.conf.bin_path, '/usr/share/openstack/bin')
@unittest.skip
def test_juju_environments_path(self):
""" Validate juju environments path in user dir """
self.assertEqual(
self.conf.juju_environments_path,
path.join(
USER_DIR, '.cloud-install/juju/environments.yaml'))
def test_clear_empty_args(self):
""" Empty cli options are not populated
in generated config
"""
cfg_file = path.join(DATA_DIR, 'good_config.yaml')
cfg = utils.populate_config(parse_opts(['--config', cfg_file]))
self.assertEqual(True, 'http-proxy' not in cfg)
def test_config_file_persists(self):
""" CLI options override options in config file
"""
cfg_file = path.join(DATA_DIR, 'good_config.yaml')
cfg = utils.populate_config(
parse_opts(['--config', cfg_file,
'--headless']))
self.assertEqual(True, cfg['headless'])
def test_config_file_persists_new_cli_opts(self):
""" Generated config object appends new options
passed via cli
"""
cfg_file = path.join(DATA_DIR, 'good_config.yaml')
cfg = utils.populate_config(
parse_opts(['--config', cfg_file,
'--install-only',
'--killcloud-noprompt']))
self.assertEqual(True, cfg['install_only'])
self.assertEqual(True, cfg['killcloud_noprompt'])
def test_config_overrides_from_cli(self):
""" Config object item is not overridden
by unset cli option
"""
cfg_file = path.join(DATA_DIR, 'good_config.yaml')
cfg = utils.populate_config(
parse_opts(['--http-proxy',
'http://localhost:2222',
'--killcloud-noprompt',
'--config', cfg_file]))
self.assertEqual(cfg['https_proxy'], GOOD_CONFIG['https_proxy'])
def test_default_opts_not_override_config(self):
#.........这里部分代码省略.........
示例7: TestRenderCharmConfig
# 需要导入模块: from cloudinstall.config import Config [as 别名]
# 或者: from cloudinstall.config.Config import setopt [as 别名]
class TestRenderCharmConfig(unittest.TestCase):
def setUp(self):
with NamedTemporaryFile(mode="w+", encoding="utf-8") as tempf:
# Override config file to save to
self.config = Config({}, tempf.name)
type(self.config).cfg_path = PropertyMock(return_value="fake_cfg_path")
self.config.setopt("openstack_password", "fake_pw")
self.ltp = patch("cloudinstall.utils.load_template")
self.mock_load_template = self.ltp.start()
self.mock_load_template.side_effect = source_tree_template_loader
def tearDown(self):
self.ltp.stop()
def _do_test_osrel(self, series, optsvalue, expected, mockspew):
"check that opts.openstack_release is rendered correctly"
self.config.setopt("openstack_release", optsvalue)
self.config.setopt("ubuntu_series", series)
render_charm_config(self.config)
(fake_path, generated_yaml), kwargs = mockspew.call_args
d = yaml.load(generated_yaml)
print(d)
for oscharmname in ["nova-cloud-controller", "glance", "openstack-dashboard", "keystone", "swift-proxy"]:
if expected is None:
self.assertTrue(oscharmname not in d or "openstack-origin" not in d[oscharmname])
else:
self.assertEqual(d[oscharmname]["openstack-origin"], expected)
def test_render_openstack_release_given(self, mockspew):
self._do_test_osrel("trusty", "klaxon", "cloud:trusty-klaxon", mockspew)
def _do_test_multiplier(self, is_single, mockspew, expected=None):
if is_single:
self.config.setopt("install_type", "Single")
else:
self.config.setopt("install_type", "Multi")
self.config.setopt("openstack_release", "klaxon")
render_charm_config(self.config)
(fake_path, generated_yaml), kwargs = mockspew.call_args
d = yaml.load(generated_yaml)
wmul = d["nova-cloud-controller"].get("worker-multiplier", None)
self.assertEqual(wmul, expected)
wmul = d["glance"].get("worker-multiplier", None)
self.assertEqual(wmul, expected)
wmul = d["keystone"].get("worker-multiplier", None)
self.assertEqual(wmul, expected)
def test_render_worker_multiplier_multi(self, mockspew):
self._do_test_multiplier(False, mockspew)
def test_render_worker_multiplier_single(self, mockspew):
self._do_test_multiplier(True, mockspew, expected=1)
def test_charmconfig_custom_merge(self, mockspew):
""" Verify rightmost custom charm config dictionary
does not overwrite untouched items in rendered
charmconfig
"""
charm_custom = {"swift-proxy": {"replicas": 15}, "mysql": {"dataset-size": "2048M"}}
charm_conf = yaml.load(slurp(os.path.join(DATA_DIR, "charmconf.yaml")))
merged_dicts = merge_dicts(charm_conf, charm_custom)
self.assertEqual(merged_dicts["mysql"]["max-connections"], 25000)
self.assertEqual(merged_dicts["swift-proxy"]["zone-assignment"], "auto")
示例8: LandscapeInstallFinalTestCase
# 需要导入模块: from cloudinstall.config import Config [as 别名]
# 或者: from cloudinstall.config.Config import setopt [as 别名]
class LandscapeInstallFinalTestCase(unittest.TestCase):
def setUp(self):
self.mock_multi_installer = MagicMock()
self.mock_display_controller = MagicMock()
self.loop = MagicMock()
with NamedTemporaryFile(mode='w+', encoding='utf-8') as tempf:
# Override config file to save to
self.conf = Config({}, tempf.name)
def make_installer_with_config(self, landscape_creds=None,
maas_creds=None):
if landscape_creds is None:
landscape_creds = dict(admin_name="fakeadminname",
admin_email="[email protected]",
system_email="[email protected]",
maas_server='fake.host',
maas_apikey='fake:keyz:yo')
self.conf.setopt('maascreds', dict(api_host='fake.host',
api_key='fake:keyz:yo'))
self.conf.setopt('landscapecreds', landscape_creds)
pm_binpath = PropertyMock(return_value='mockbinpath')
type(self.conf).bin_path = pm_binpath
pm_cfgpath = PropertyMock(return_value='mockcfgpath')
type(self.conf).cfg_path = pm_cfgpath
lif = LandscapeInstallFinal(self.mock_multi_installer,
self.mock_display_controller,
self.conf,
self.loop)
self.installer = lif
def test_run_configure_not_sudo_user(self, mock_utils):
"""Do not sudo -u $SUDO_USER when running landscape-configure, it will
be 'root'.
"""
self.make_installer_with_config()
mock_utils.get_command_output.return_value = {'status': '',
'output': ''}
self.installer.run_configure_script()
mock_utils.get_command_output.assert_called_with(ANY, timeout=None)
def test_run_configure_quotes_config_values(self, mock_utils):
cd = dict(admin_name="fake admin name with spaces",
admin_email="[email protected]",
system_email="[email protected]")
self.make_installer_with_config(landscape_creds=cd)
mock_utils.get_command_output.return_value = {'status': '',
'output': ''}
self.installer.run_configure_script()
expectedcmdstr = ("mockbinpath/configure-landscape "
"--admin-email '{}' "
"--admin-name '{}' "
"--system-email '{}' "
"--maas-host fake.host".format(cd['admin_email'],
cd['admin_name'],
cd['system_email']))
mock_utils.get_command_output.assert_called_with(expectedcmdstr,
timeout=None)
def test_run_configure_raises_on_error(self, mock_utils):
self.make_installer_with_config()
mock_utils.get_command_output.return_value = {'status': 1,
'output': 'failure'}
self.assertRaises(Exception, self.installer.run_configure_script)
def test_run_deployer_raises_on_error(self, mock_utils):
self.make_installer_with_config()
mock_utils.get_command_output.return_value = {'status': 1,
'output': 'failure'}
self.assertRaises(Exception, self.installer.run_deployer)
def test_run_deployer_has_no_timeout(self, mock_utils):
self.make_installer_with_config()
mock_utils.get_command_output.return_value = {'status': '',
'output': 'failure'}
self.installer.run_deployer()
mock_utils.get_command_output.assert_called_with(ANY, timeout=None,
user_sudo=ANY)