def create_agent_py(agent_filename): with open(agent_filename, 'w') as f: f.write( read_resource( pkg_resources.resource_filename('yandextank.plugins.Telegraf', 'agent/agent.py'))) os.chmod(agent_filename, 0o775) return os.path.abspath(agent_filename)
def load_cfg(cfg_filename): """ :type cfg_filename: str """ if is_ini(cfg_filename): return convert_ini(cfg_filename) else: return yaml.load(read_resource(cfg_filename), Loader=yaml.FullLoader)
def getconfig(self, filename, target_hint): """Prepare config data.""" try: config = read_resource(filename) tree = self.parse_xml(config) except IOError as exc: logger.error("Error loading config: %s", exc) raise RuntimeError("Can't read monitoring config %s" % filename) hosts = tree.findall('Host') config = [] for host in hosts: host_config = self.get_host_config(host, target_hint) config.append(host_config) return config
def test_ammo(stepper_kwargs, expected_stpd): stepper = Stepper( TankCore([{}], threading.Event(), TankInfo({})), rps_schedule=["const(10,10s)"], http_ver="1.1", instances_schedule=None, instances=10, loop_limit=1000, ammo_limit=1000, enum_ammo=False, **stepper_kwargs ) stepper_output = io.BytesIO() stepper.write(stepper_output) stepper_output.seek(0) expected_lines = read_resource(os.path.join(get_test_path(), expected_stpd), 'rb').split(b'\n') for i, (result, expected) in enumerate(zip(stepper_output, expected_lines)): assert result.strip() == expected.strip(), 'Line {} mismatch'.format(i)
def test_ammo(): AMMO_FILE = os.path.join(PATH, 'yandextank/stepper/tests/test-ammo.txt') stepper = Stepper( TankCore([{}], threading.Event(), TankInfo({})), rps_schedule=["const(10,30s)"], http_ver="1.1", ammo_file=AMMO_FILE, instances_schedule=None, instances=10, loop_limit=1000, ammo_limit=1000, ammo_type='phantom', autocases=0, enum_ammo=False, ) stepper_output = io.StringIO() stepper.write(stepper_output) stepper_output.seek(0) expected_lines = read_resource( os.path.join(PATH, 'yandextank/stepper/tests/expected.stpd')).split('\n') for i, (result, expected) in enumerate(zip(stepper_output, expected_lines)): assert result.strip() == expected.strip(), 'Line {} mismatch'.format(i)
def load_yaml_schema(path): # DEFAULT_FILENAME = 'schema.yaml' file_content = read_resource(path) return yaml.safe_load(file_content)