def run_win_chef_client(backend, agent_version, stage): attributes = json.loads(ATTRIBUTES_JSON) attributes["signalfx_agent"]["agent_version"] = agent_version attributes["signalfx_agent"]["package_stage"] = stage attributes["signalfx_agent"]["conf"]["ingestUrl"] = backend.ingest_url attributes["signalfx_agent"]["conf"]["apiUrl"] = backend.api_url if running_in_azure_pipelines(): attributes["signalfx_agent"]["user"] = os.environ.get("USERNAME") attributes["signalfx_agent"]["group"] = os.environ.get("USERNAME") print(attributes) attributes_path = r"C:\chef\cookbooks\attributes.json" with open(attributes_path, "w+") as fd: fd.write(json.dumps(attributes)) fd.flush() if int(get_win_chef_version().split(".")[0]) >= 15: cmd = CHEF_CMD.format( attributes_path) + " --chef-license accept-silent" else: cmd = CHEF_CMD.format(attributes_path) print('running "%s" ...' % cmd) proc = subprocess.run(cmd, cwd=r"C:\chef\cookbooks", stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) output = proc.stdout.decode("utf-8") assert proc.returncode == 0, output print(output) installed_version = get_win_agent_version() assert installed_version == agent_version, "installed agent version is '%s', expected '%s'" % ( installed_version, agent_version, )
def run_win_chef_client(backend, agent_version=None, stage=STAGE): attributes = json.loads(ATTRIBUTES_JSON) attributes["signalfx_agent"]["agent_version"] = agent_version attributes["signalfx_agent"]["package_stage"] = stage attributes["signalfx_agent"]["conf"]["ingestUrl"] = backend.ingest_url attributes["signalfx_agent"]["conf"]["apiUrl"] = backend.api_url if os.environ.get("AZURE_HTTP_USER_AGENT"): # running in Azure Pipelines; need to override Administrator user/group attributes["signalfx_agent"]["user"] = os.environ.get("USERNAME") attributes["signalfx_agent"]["group"] = os.environ.get("USERNAME") print(attributes) attributes_path = r"C:\chef\cookbooks\attributes.json" with open(attributes_path, "w+") as fd: fd.write(json.dumps(attributes)) fd.flush() cmd = CHEF_CMD.format( attributes_path) + " --chef-license accept-silent" print('running "%s" ...' % cmd) proc = subprocess.run(cmd, cwd=r"C:\chef\cookbooks", stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) output = proc.stdout.decode("utf-8") assert proc.returncode == 0, output print(output) installed_version = get_win_agent_version() if agent_version: assert installed_version == agent_version, "installed agent version is '%s', expected '%s'" % ( installed_version, agent_version, ) return installed_version
def run_win_puppet_agent(backend, monitors, agent_version, stage, config_path=WIN_CONFIG_PATH, install_dir=WIN_INSTALL_DIR): with open(WIN_HIERA_DEST_PATH, "w+", encoding="utf-8") as fd: hiera_yaml = get_hiera(WIN_HIERA_SRC_PATH, backend, monitors) print(hiera_yaml) fd.write(hiera_yaml) with tempfile.TemporaryDirectory() as tmpdir: manifest_path = os.path.join(tmpdir, "agent.pp") config = get_config(agent_version, stage, config_path=config_path, install_dir=install_dir) print(config) with open(manifest_path, "w+", encoding="utf-8") as fd: fd.write(config) cmd = f"puppet apply {manifest_path}" run_win_command(cmd, returncodes=[0, 2]) installed_version = get_win_agent_version( os.path.join(install_dir, "SignalFxAgent", "bin", "signalfx-agent.exe")) assert installed_version == agent_version, "installed agent version is '%s', expected '%s'" % ( installed_version, agent_version, )
def run_win_puppet_agent(backend, monitors, agent_version=None, stage=STAGE): manifest_path = "agent.pp" with open(manifest_path, "w+") as fd: fd.write(get_config(backend, monitors, agent_version, stage)) cmd = f"puppet apply {manifest_path}" run_win_command(cmd, [0, 2]) installed_version = get_win_agent_version() if agent_version: assert installed_version == agent_version, "installed agent version is '%s', expected '%s'" % ( installed_version, agent_version, ) return installed_version
def run_win_puppet_agent(backend, monitors, agent_version, stage): with tempfile.TemporaryDirectory() as tmpdir: manifest_path = os.path.join(tmpdir, "agent.pp") config = get_config(backend, monitors, agent_version, stage) print(config) with open(manifest_path, "w+") as fd: fd.write(config) cmd = f"puppet apply {manifest_path}" run_win_command(cmd, returncodes=[0, 2]) installed_version = get_win_agent_version() assert installed_version == agent_version, "installed agent version is '%s', expected '%s'" % ( installed_version, agent_version, )
def run_win_installer(backend, args=""): installer_cmd = f'"{WIN_INSTALLER_PATH}" -ingest_url {backend.ingest_url} -api_url {backend.api_url} {args}'.strip( ) run_win_command(f"powershell {installer_cmd}", cwd="c:\\") return get_win_agent_version()