本文整理汇总了Python中cloudinstall.config.Config类的典型用法代码示例。如果您正苦于以下问题:Python Config类的具体用法?Python Config怎么用?Python Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
class LandscapeInstall:
def __init__(self, opts, display_controller):
self.config = Config()
self.opts = opts
self.display_controller = display_controller
# Sets install type
utils.spew(os.path.join(self.config.cfg_path,
'landscape'),
'auto-generated')
self.landscape_tasks = ["Preparing Landscape",
"Deploying Landscape",
"Registering against Landscape"]
def _do_install_existing_maas(self):
""" Performs the landscape deployment with existing MAAS
"""
MultiInstallExistingMaas(
self.opts, self.display_controller,
post_tasks=self.landscape_tasks).run()
def _do_install_new_maas(self):
""" Prepare new maas environment for landscape
"""
MultiInstallNewMaas(self.opts, self.display_controller,
post_tasks=self.landscape_tasks).run()
def _save_lds_creds(self, creds):
admin_name = creds['admin_name'].value
admin_email = creds['admin_email'].value
system_email = creds['system_email'].value
maas_server = creds['maas_server'].value
maas_apikey = creds['maas_apikey'].value
self.config.save_landscape_creds(
admin_name, admin_email, system_email,
maas_server, maas_apikey)
self.display_controller.ui.hide_widget_on_top()
self.display_controller.info_message("Running ..")
if not maas_server:
log.debug("No maas credentials entered, doing a new MAAS install")
self._do_install_new_maas()
else:
log.debug("Existing MAAS defined, doing a LDS "
"installation with existing MAAS.")
self.config.save_maas_creds(maas_server,
maas_apikey)
self._do_install_existing_maas()
def run(self):
self.display_controller.info_message(
"Please enter your Landscape information and "
"optionally an existing MAAS Server IP. If MAAS "
"is not defined a new one will be created for you.")
self.display_controller.show_landscape_input("Landscape Setup",
self._save_lds_creds)
示例2: setUp
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]
示例3: setUp
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)
示例4: WaitForDeployedServicesReadyCoreTestCase
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)
示例5: setUp
def setUp(self):
self._temp_conf = Config({}, save_backups=False)
with NamedTemporaryFile(mode='w+', encoding='utf-8') as tempf:
# Override config file to save to
self.conf = Config(self._temp_conf._config, tempf.name,
save_backups=False)
self.mock_ui = MagicMock(name='ui')
self.mock_log = MagicMock(name='log')
self.mock_loop = MagicMock(name='loop')
示例6: TestBadConfig
class TestBadConfig(unittest.TestCase):
def setUp(self):
self._temp_conf = Config(BAD_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_no_openstack_password(self):
""" No openstack password defined """
self.assertFalse(self.conf.getopt('openstack_password'))
def test_no_landscape_creds(self):
""" No landscape creds defined """
self.assertFalse(self.conf.getopt('landscapecreds'))
def test_no_installer_type(self):
""" No installer type defined """
self.assertFalse(self.conf.is_single)
示例7: setUp
def setUp(self):
self.conf = Config({}, save_backups=False)
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()
示例8: __init__
def __init__(self, opts, display_controller):
self.config = Config()
self.opts = opts
self.display_controller = display_controller
# Sets install type
utils.spew(os.path.join(self.config.cfg_path,
'landscape'),
'auto-generated')
self.landscape_tasks = ["Preparing Landscape",
"Deploying Landscape",
"Registering against Landscape"]
示例9: MultiInstallNewMaasTestCase
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)
示例10: setUp
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()
示例11: CoreStateTestCase
class CoreStateTestCase(unittest.TestCase):
""" Handles validating current state within the controllers
core
"""
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.mock_ui = MagicMock(name='ui')
@patch('cloudinstall.core.Controller')
def test_controller_state_init(self, Controller):
""" Validate controller state in core during class init """
Controller(self.mock_ui, self.conf)
self.assertEqual(
self.conf.getopt('current_state'), ControllerState.INSTALL_WAIT)
示例12: MultiInstallStateTestCase
class MultiInstallStateTestCase(unittest.TestCase):
""" Handles validating current state within a
multi install
"""
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.mock_ui = MagicMock(name='ui')
@patch('cloudinstall.controllers.install.MultiInstall')
def test_do_install_sets_state(self, MultiInstall):
""" Validate installstate in multi install """
mi = MultiInstall(self.mock_ui, config=self.conf)
mi.do_install()
self.assertEqual(
self.conf.getopt('current_state'), InstallState.RUNNING)
示例13: InstallStateTestCase
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)
示例14: ControllerStateTestCase
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)
示例15: setUp
def setUp(self):
self.conf = Config({})
self.mock_ui = MagicMock(name='ui')
self.mock_log = MagicMock(name='log')
self.mock_loop = MagicMock(name='loop')