def test_app_config(): # Get configured auth params specified_app_config = utils.get_cluster_var('cartridge_app_config') if not specified_app_config: return # Get all configured instances configured_instances = utils.get_configured_instances() if not configured_instances: return # Get cartridge app config config_url = '%s/admin/config' % utils.get_any_instance_url() session = utils.get_authorized_session() response = session.get(config_url) assert response.status_code == 200 loader = Loader(response.content) app_config = loader.get_data() # Check if app config is equal to configured one for section_name, section in specified_app_config.items(): if section_is_deleted(section): assert section_name not in app_config else: assert section_name in app_config assert app_config[section_name] == section['body']
def get_yaml_docs(): """Parse the YAML file""" source = read_yaml_file(args['infile']) if args.get('template'): source = read_yaml_file(args['template']) + source source_str = ''.join([line[0] for line in source]) def mark_str(mark): line = source[mark.line] return ("In file " + line[1] + ", line " + str(line[2]) + ", column " + str(mark.column + 1) + ":\n" + line[0].rstrip() + "\n" + ' ' * mark.column + "^\n") # We iterate through all of the documents to properly diagnose errors, # because the load_all generator does not handle exceptions correctly. docs = [] load = Loader(source_str) while load.check_data(): try: doc = load.get_data() except yaml.YAMLError as err: sys.exit((mark_str(err.problem_mark) if err.problem_mark else "") + (err.problem + "\n" if err.problem else "") + (err.note + "\n" if err.note else "")) else: docs.append(doc) return docs
def load_yaml(fn, q, pid, output_lock, semp): # output_lock.acquire() # print('load_yaml({0}, {1}, {2})'.format(fn, q, pid)) # output_lock.release() with open(fn) as file: q.put( (pid, 'size', file_size(file)) ) semp.acquire() finished = threading.Event() update_thread = threading.Thread(target=updater, args=(finished, file, q, pid)) update_thread.daemon = True update_thread.start() loader = Loader(file) stats = [] while loader.check_data(): stats.append( loader.get_data() ) semp.release() finished.set() update_thread.join() q.put( (pid, 'done', stats) )
def check_conf_file(conf_file, instance_id, conf): assert conf_file.exists assert conf_file.user == 'tarantool' assert conf_file.group == 'tarantool' loader = Loader(conf_file.content_string) conf_file_dict = loader.get_data() assert instance_id in conf_file_dict assert conf_file_dict[instance_id] == conf
def process_notify(self, notification): """Process events""" loader = Loader(self.events_stream) setattr(loader, 'notification', notification) setattr(loader, 'system', self.system) notifications = loader.get_data() for notify_name in notifications: logging.debug('Process "{}" notification'.format(notify_name)) if notifications[notify_name] is not None: self.send_data(notifications[notify_name])
def process_measurements(self): """Process measurements""" loader = Loader(self.measurements_stream) setattr(loader, 'collector', self.collector) setattr(loader, 'system', self.system) setattr(loader, 'config', self.config) measurements = loader.get_data() for measurement_name in measurements: logging.debug('Process "{}" measurements: {}'.format( measurement_name, measurements[measurement_name])) for measurement in measurements[measurement_name]: self.send_data(measurement)
for fn in sys.argv[1:]: p = Process(target=load_yaml, args=(fn, q, fn)) f_size = os.path.getsize(fn) # err(" Loading [%s] (%d)" % (fn,f_size)) with open(fn) as file: finished = threading.Event() update_thread = threading.Thread(target=updater, args=(finished, file, file_size(file))) update_thread.daemon = True update_thread.start() loader = Loader(file) stats = [] while loader.check_data(): stats.append( loader.get_data() ) finished.set() update_thread.join() #filters = [ TagFilter('total') ] #for filter in filters: #stats = filter.filter(stats) if not stats: continue kernel = TagFilter('kernel').filter(stats)[0] user = TagFilter('user').filter(stats)[0] total = TagFilter('total').filter(stats)[0] L2 = PathFilter(['L2_0']).filter(total, valueOnly=True)