def mapping_datafile_creator(self, testbed): # Generating mapping datafile mapping_dict = {} mapping_dict.setdefault('devices', {}) testbed = load(testbed) for dev, dev_args in testbed.devices.items(): # if ha device mapping datafile with [a, b] if 'a' in dev_args.connections and \ 'b' in dev_args.connections: mapping_dict['devices'].update( {dev: { 'mapping': { 'cli': ['a', 'b'] } }}) # for single connection devices just a elif 'a' in dev_args.connections: mapping_dict['devices'].update( {dev: { 'mapping': { 'cli': 'a' } }}) # for devices with cli connection, # we pick the first connection in the list of connection # Usually these cases should have only one connection in the testbed else: connections = Dq(dev_args.connections).\ not_contains('default.*', regex=True).\ reconstruct() connection = list(connections.keys())[0] mapping_dict['devices'].update( {dev: { 'mapping': { 'cli': connection } }}) additionals_dir = self._get_dir_for_additional_datafile() with open(additionals_dir + '/mapping_datafile.yaml', 'w') as mapping_file_dumped: mapping_file_dumped.write( ruamel.yaml.round_trip_dump(mapping_dict)) return additionals_dir + '/mapping_datafile.yaml'
def test(self, steps): print(path_store) for device_name, device in self.execute_cpu.items(): header = ['PID', '1Min', '5Min', '15Min', 'Process'] output = self.execute_cpu[device_name] output = re.sub('%', ' ', output) result = parsergen.oper_fill_tabular(device_output=output, device_os='iosxr', header_fields=header, index=[0]) output = result.entries cpu_bad = Dq(output).value_operator('5Min', '>=', 75).reconstruct() process_id = str(cpu_bad.keys()) if cpu_bad != {}: self.failed( f'Very High 5 Minute CPU detected on {device} with the following Process ID {process_id}' ) else: self.passed( f'No issues found with the CPU Utilisation on {device_name}' )