def check_all(): '''Check All Environement Object''' LOG.debug('This option will do following things:') for i in register.all: fmt_print('--' + i) for i in register.all: eval(i)()
def check_profile(profile, role): # if the profile file is not exists, go back if not os.path.exists(profile): LOG.error('Can not find this profile. Abort this check!') return # get template path template = get_template_path(profile, role) # if the template file is not exists, go back if not os.path.exists(template): LOG.error('Template file is missing, Please check it by yourself.') return if role is not 'mongo': # check file resolvability, if not resolvability, go back for filepath in (profile, template): if not check_file_resolvability(filepath): return # Check profile keys check_list = get_check_list(profile) miss_keys = [] for section in sorted(check_list.keys()): for key in check_list[section]: (miss_key, current_value) = check_key(section, key, profile, template) if miss_key: if '[' + section + ']' not in miss_keys: miss_keys.append('[' + section + ']') miss_keys.append(key + ' = ' + current_value) else: miss_keys.append(key + ' = ' + current_value) if miss_keys: LOG.warn( 'Can not check following option, please check it by yourself. ' ) for entry in miss_keys: fmt_print(entry) # some keys in template but not in profile(named lost keys) t_check_list = get_check_list(template) for t_section in sorted(t_check_list.keys()): for t_key in t_check_list[t_section]: check_lost_key(t_section, t_key, profile) else: # Check profile keys check_list = get_check_list_common(profile) for key in check_list: check_key_common(key, profile, template) # some keys in template but not in profile(named lost keys) t_check_list = get_check_list_common(template) for t_key in t_check_list: check_lost_key_common(t_key, profile)
def check_lost_key(section, key, profile): p = ConfigParser.ConfigParser() p.read(profile) try: dict(p.items(section))[key] except ConfigParser.NoSectionError: LOG.warn('Lost section [%s] in this profile.' % section) except KeyError: LOG.warn('Lost following option in this profile. Please check it.') fmt_print('[%s]' % section) fmt_print(key)
def check_profile(profile, role): # if the profile file is not exists, go back if not os.path.exists(profile): LOG.error('Can not find this profile. Abort this check!') return # get template path template = get_template_path(profile, role) # if the template file is not exists, go back if not os.path.exists(template): LOG.error('Template file is missing, Please check it by yourself.') return if role is not 'mongo': # check file resolvability, if not resolvability, go back for filepath in (profile, template): if not check_file_resolvability(filepath): return # Check profile keys check_list = get_check_list(profile) miss_keys = [] for section in sorted(check_list.keys()): for key in check_list[section]: (miss_key, current_value) = check_key(section, key, profile, template) if miss_key: if '[' + section + ']' not in miss_keys: miss_keys.append('[' + section + ']') miss_keys.append(key + ' = ' + current_value) else: miss_keys.append(key + ' = ' + current_value) if miss_keys: LOG.warn('Can not check following option, please check it by yourself. ') for entry in miss_keys: fmt_print(entry) # some keys in template but not in profile(named lost keys) t_check_list = get_check_list(template) for t_section in sorted(t_check_list.keys()): for t_key in t_check_list[t_section]: check_lost_key(t_section, t_key, profile) else: # Check profile keys check_list = get_check_list_common(profile) for key in check_list: check_key_common(key, profile, template) # some keys in template but not in profile(named lost keys) t_check_list = get_check_list_common(template) for t_key in t_check_list: check_lost_key_common(t_key, profile)
def check_key(section, key, profile, template): pp = ConfigParser.ConfigParser() pp.read(profile) pt = ConfigParser.ConfigParser() pt.read(template) current_value = dict(pp.items(section))[key] try: correct_value = dict(pt.items(section))[key] # there is no this section in the template file except ConfigParser.NoSectionError: LOG.warn(' Can not check following option, please check it by yourself. ') LOG.warn(' [%s] ' % section) fmt_print(' %s=%s' % (key, current_value)) correct_value = current_value # there is no this key in the section except KeyError: LOG.warn(' Can not check following option, please check it by yourself. ') LOG.warn(' [%s] ' % section) fmt_print(' %s=%s' % (key, current_value)) correct_value = current_value # if the key in profile and template didn't matched, check faild if current_value != correct_value: LOG.error(' [%s] ' % section) LOG.error(' "%s" option check faild' % key) fmt_print(' Current is "%s=%s"' % (key, current_value)) fmt_print(' Correct is "%s=%s"' % (key, correct_value))
def check_key(section, key, profile, template): pp = ConfigParser.ConfigParser() pp.read(profile) pt = ConfigParser.ConfigParser() pt.read(template) current_value = dict(pp.items(section))[key] filterfile = template + '.filter' if os.path.exists(filterfile): pf = ConfigParser.ConfigParser() pf.read(filterfile) try: dict(pf.items(section))[key] LOG.debug( '[%s] ==> "%s = %s" option in the filter file, skip check this option.' % (section, key, current_value)) return False, None except: pass current_value = dict(pp.items(section))[key] try: correct_value = dict(pt.items(section))[key] # there is no this section in the template file except ConfigParser.NoSectionError: correct_value = current_value return True, current_value # there is no this key in the section except KeyError: correct_value = current_value return True, current_value # if the key in profile and template didn't matched, check faild if current_value != correct_value: LOG.error('[%s] ' % section) LOG.error('"%s" option check faild' % key) fmt_print('Current is "%s=%s"' % (key, current_value)) fmt_print('Correct is "%s=%s"' % (key, correct_value)) return False, None else: return False, None
def check_key(section, key, profile, template): pp = ConfigParser.ConfigParser() pp.read(profile) pt = ConfigParser.ConfigParser() pt.read(template) current_value = dict(pp.items(section))[key] filterfile = template + '.filter' if os.path.exists(filterfile): pf = ConfigParser.ConfigParser() pf.read(filterfile) try: dict(pf.items(section))[key] LOG.debug('[%s] ==> "%s = %s" option in the filter file, skip check this option.' % (section, key, current_value)) return False, None except: pass current_value = dict(pp.items(section))[key] try: correct_value = dict(pt.items(section))[key] # there is no this section in the template file except ConfigParser.NoSectionError: correct_value = current_value return True, current_value # there is no this key in the section except KeyError: correct_value = current_value return True, current_value # if the key in profile and template didn't matched, check faild if current_value != correct_value: LOG.error('[%s] ' % section) LOG.error('"%s" option check faild' % key) fmt_print('Current is "%s=%s"' % (key, current_value)) fmt_print('Correct is "%s=%s"' % (key, correct_value)) return False, None else: return False, None
def check_key_common(key, profile, template): current_value = get_value_common(key, profile) correct_value = get_value_common(key, template) filterfile = template + '.filter' if os.path.exists(filterfile): if get_value_common(key, filterfile) is '': LOG.debug('"%s = %s" option in the filter file, skip check this option.' % (key, current_value)) elif not correct_value: LOG.warn('Can not check following option, please check it by yourself. ') fmt_print('%s=%s' % (key, current_value)) elif current_value != correct_value: LOG.error('"%s" option check faild' % key) fmt_print('Current is "%s=%s"' % (key, current_value)) fmt_print('Correct is "%s=%s"' % (key, correct_value))