s = '_'.join(s.split())
return s
+ def safe_get(self, section, key):
+ """
+ Attempt to get a configuration value from a certain section
+ in a ``cfg`` object but returning None if not found. Avoids the need
+ to be doing try/except {ConfigParser Exceptions} every time.
+ """
+ try:
+ #Use full parent function so we can replace it in the class
+ # if desired
+ return ConfigParser.RawConfigParser.get(self, section, key)
+ except (ConfigParser.NoSectionError,
+ ConfigParser.NoOptionError):
+ return None
+
def parse(fp):
cfg = CephConf()
import logging
-import ConfigParser
from cStringIO import StringIO
LOG = logging.getLogger(__name__)
-def safe_get(cfg, section, key):
- """
- Attempt to get a configuration value from a certain section
- in a ``cfg`` object but returning None if not found. Avoids the need
- to be doing try/except {ConfigParser Exceptions} every time.
- """
- try:
- return cfg.get(section, key)
- except (ConfigParser.NoSectionError,
- ConfigParser.NoOptionError):
- return None
-
-
def config_push(args):
cfg = conf.load(args)
conf_data = StringIO()
import argparse
-import ConfigParser
import json
import logging
import re
from textwrap import dedent
import time
-from . import conf, config, exc
+from . import conf, exc
from .cliutil import priority
from .sudo_pushy import get_transport
from .util import paths
"""
conn = conn or get_connection(hostname, logger=logger)
monmap = mon_status_check(conn, logger, hostname).get('monmap', {})
- mon_initial_members = config.safe_get(cfg, 'global', 'mon_initial_members')
- public_addr = config.safe_get(cfg, 'global', 'public_addr')
- public_network = config.safe_get(cfg, 'global', 'public_network')
+ mon_initial_members = cfg.safe_get('global', 'mon_initial_members')
+ public_addr = cfg.safe_get('global', 'public_addr')
+ public_network = cfg.safe_get('global', 'public_network')
mon_in_monmap = [
mon.get('name')
for mon in monmap.get('mons', [{}])
cfg = conf.load(args)
if not args.mon:
- try:
- mon_initial_members = cfg.get('global', 'mon_initial_members')
- except (ConfigParser.NoSectionError,
- ConfigParser.NoOptionError):
- pass
- else:
- args.mon = re.split(r'[,\s]+', mon_initial_members)
+ mon_initial_members = cfg.safe_get('global', 'mon_initial_members')
+ args.mon = re.split(r'[,\s]+', mon_initial_members)
if not args.mon:
raise exc.NeedHostError()
def mon_create_initial(args):
- try:
- cfg = conf.load(args)
- cfg_initial_members = cfg.get('global', 'mon_initial_members')
- mon_initial_members = re.split(r'[,\s]+', cfg_initial_members)
- except (ConfigParser.NoSectionError,
- ConfigParser.NoOptionError):
+ cfg = conf.load(args)
+ cfg_initial_members = cfg.safe_get('global', 'mon_initial_members')
+ if cfg_initial_members is None:
raise RuntimeError('No `mon initial members` defined in config')
+ mon_initial_members = re.split(r'[,\s]+', cfg_initial_members)
# create them normally through mon_create
mon_create(args)
-import ConfigParser
import errno
import logging
import os
from ceph_deploy import mon
+from ceph_deploy.conf import CephConf
from mock import Mock
+def make_fake_conf():
+ return CephConf()
+
# NOTE: If at some point we re-use this helper, move it out
# and make it even more generic
def test_warn_if_no_intial_members(self):
fake_conn = make_fake_conn()
- mon.catch_mon_errors(fake_conn, self.logger, 'host', {})
+ cfg = make_fake_conf()
+ mon.catch_mon_errors(fake_conn, self.logger, 'host', cfg)
expected_msg = 'is not defined in `mon initial members`'
self.assert_logger_message(self.logger.warning, expected_msg)
def test_warn_if_not_mon_in_monmap(self):
fake_conn = make_fake_conn()
- mon.catch_mon_errors(fake_conn, self.logger, 'host', {})
+ cfg = make_fake_conf()
+ mon.catch_mon_errors(fake_conn, self.logger, 'host', cfg)
expected_msg = 'does not exist in monmap'
self.assert_logger_message(self.logger.warning, expected_msg)
def test_warn_if_not_public_addr_and_not_public_netw(self):
fake_conn = make_fake_conn()
- mon.catch_mon_errors(fake_conn, self.logger, 'host', {'global': ''})
+ cfg = make_fake_conf()
+ cfg.add_section('global')
+ mon.catch_mon_errors(fake_conn, self.logger, 'host', cfg)
expected_msg = 'neither `public_addr` nor `public_network`'
self.assert_logger_message(self.logger.warning, expected_msg)