예제 #1
0
def test_chef_on_windows(chef_version):
    run_win_chef_setup(chef_version)
    with ensure_fake_backend() as backend:
        try:
            run_win_chef_client(backend, INITIAL_VERSION, STAGE)
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "host-metadata")), "Datapoints didn't come through"

            # upgrade agent
            run_win_chef_client(backend, UPGRADE_VERSION, STAGE)
            backend.reset_datapoints()
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "host-metadata")), "Datapoints didn't come through"

            # downgrade agent
            run_win_chef_client(backend, INITIAL_VERSION, STAGE)
            backend.reset_datapoints()
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "host-metadata")), "Datapoints didn't come through"
        finally:
            print("\nDatapoints received:")
            for dp in backend.datapoints:
                print_dp_or_event(dp)
            print("\nEvents received:")
            for event in backend.events:
                print_dp_or_event(event)
            print(f"\nDimensions set: {backend.dims}")
예제 #2
0
def test_win_local_nupkg(request):
    assert has_choco(), "choco not installed"

    # Get nupkg path from command line flag to pytest
    nupkg_path = request.config.getoption("--test-nupkg-path")
    if not nupkg_path:
        raise ValueError(
            "You must specify the --test-nupkg-path flag to run choco tests")

    nupkg_path = os.path.abspath(nupkg_path)
    assert os.path.isfile(nupkg_path), f"{nupkg_path} not found!"

    nupkg_dir = os.path.dirname(nupkg_path)

    uninstall_win_agent()

    with ensure_fake_backend() as backend:
        try:
            params = f"/access_token:MYTOKEN /ingest_url:{backend.ingest_url} /api_url:{backend.api_url}"
            run_win_command(
                f"choco install signalfx-agent -y -s {nupkg_dir} --params=\"'{params}'\""
            )
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "host-metadata")), "Datapoints didn't come through"
        finally:
            print("\nDatapoints received:")
            for dp in backend.datapoints:
                print_dp_or_event(dp)
            print("\nEvents received:")
            for event in backend.events:
                print_dp_or_event(event)
            print(f"\nDimensions set: {backend.dims}")
            run_win_command("choco uninstall -y signalfx-agent")
            uninstall_win_agent()
예제 #3
0
def test_win_installer(agent_version):
    uninstall_win_agent()
    with ensure_fake_backend() as backend:
        try:
            args = "-access_token MYTOKEN -stage final"
            if agent_version == "latest":
                agent_version = get_latest_win_agent_version(stage="final")
            else:
                args += f" -agent_version {agent_version}"
            installed_version = run_win_installer(backend, args)
            assert installed_version == agent_version, "installed agent version is '%s', expected '%s'" % (
                installed_version,
                agent_version,
            )
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "signalfx-metadata")), "Datapoints didn't come through"
        finally:
            print("\nDatapoints received:")
            for dp in backend.datapoints:
                print_dp_or_event(dp)
            print("\nEvents received:")
            for event in backend.events:
                print_dp_or_event(event)
            print(f"\nDimensions set: {backend.dims}")
예제 #4
0
def test_win_local_msi_installer(request):
    # Get msi path from command line flag to pytest
    msi_path = request.config.getoption("--test-msi-path")
    if not msi_path:
        raise ValueError(
            "You must specify the --test-msi-path flag to run msi tests")

    msi_path = os.path.abspath(msi_path)
    assert os.path.isfile(msi_path), f"{msi_path} not found!"

    uninstall_win_agent()

    with ensure_fake_backend() as backend:
        try:
            args = f"-access_token MYTOKEN -msi_path {msi_path}"
            run_win_installer(backend, args)
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "host-metadata")), "Datapoints didn't come through"
        finally:
            print("\nDatapoints received:")
            for dp in backend.datapoints:
                print_dp_or_event(dp)
            print("\nEvents received:")
            for event in backend.events:
                print_dp_or_event(event)
            print(f"\nDimensions set: {backend.dims}")
            uninstall_win_agent(msi_path=msi_path)
예제 #5
0
def test_cluster_prop_is_merged_into_existing():
    with ensure_fake_backend() as fake_services:
        fake_services.dims["host"]["myhost"] = {
            "customProperties": {
                "os": "linux"
            },
            "tags": ["important"]
        }

        with Agent.run(
                """
            cluster: prod
            hostname: myhost
            writer:
              propertiesSendDelaySeconds: 1
        """,
                fake_services=fake_services,
                # Make it ignore all platform metrics for CI environments
                extra_env={"SKIP_PLATFORM_HOST_DIMS": "yes"},
        ):

            def assert_cluster_property():
                dim = fake_services.dims["host"]["myhost"]
                assert dim["customProperties"] == {
                    "os": "linux",
                    "cluster": "prod"
                }
                assert dim["tags"] == ["important"]

            wait_for_assertion(assert_cluster_property)
예제 #6
0
def test_puppet_on_windows(puppet_version):
    run_win_command(f"powershell.exe '{WIN_UNINSTALL_SCRIPT_PATH}'")
    if os.environ.get("USERNAME") == "VssAdministrator":
        if puppet_version == "latest":
            run_win_command(f"choco upgrade -y -f puppet-agent")
        else:
            run_win_command(
                f"choco upgrade -y -f puppet-agent --version {puppet_version}")
        if WIN_PUPPET_BIN_DIR not in os.environ.get("PATH"):
            os.environ["PATH"] = WIN_PUPPET_BIN_DIR + ";" + os.environ.get(
                "PATH")
    if os.path.isdir(WIN_PUPPET_MODULE_DEST_DIR):
        shutil.rmtree(WIN_PUPPET_MODULE_DEST_DIR)
    shutil.copytree(WIN_PUPPET_MODULE_SRC_DIR, WIN_PUPPET_MODULE_DEST_DIR)
    run_win_command("puppet module install puppet-archive")
    run_win_command("puppet module install puppetlabs-powershell")
    with ensure_fake_backend() as backend:
        try:
            monitors = '{ type => "host-metadata" },'
            run_win_puppet_agent(backend, monitors, INITIAL_VERSION, STAGE)
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "host-metadata")), "Datapoints didn't come through"
            run_win_puppet_agent(backend, monitors, UPGRADE_VERSION, STAGE)
            backend.reset_datapoints()
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "host-metadata")), "Datapoints didn't come through"
            run_win_puppet_agent(backend, monitors, INITIAL_VERSION, STAGE)
            backend.reset_datapoints()
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "host-metadata")), "Datapoints didn't come through"
            monitors = '{ type => "internal-metrics" },'
            run_win_puppet_agent(backend, monitors, INITIAL_VERSION, STAGE)
            backend.reset_datapoints()
            assert wait_for(
                p(has_datapoint_with_metric_name, backend,
                  "sfxagent.datapoints_sent")
            ), "Didn't get internal metric datapoints"
        finally:
            print("\nDatapoints received:")
            for dp in backend.datapoints:
                print_dp_or_event(dp)
            print("\nEvents received:")
            for event in backend.events:
                print_dp_or_event(event)
            print(f"\nDimensions set: {backend.dims}")
예제 #7
0
def test_puppet_on_windows(puppet_version):
    run_win_puppet_setup(puppet_version)
    with ensure_fake_backend() as backend:
        try:
            monitors = [{"type": "host-metadata"}]
            run_win_puppet_agent(backend, monitors, INITIAL_VERSION, STAGE)
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin", "host-metadata")
            ), "Datapoints didn't come through"

            if UPGRADE_VERSION:
                # upgrade agent
                run_win_puppet_agent(backend, monitors, UPGRADE_VERSION, STAGE)
                backend.reset_datapoints()
                assert wait_for(
                    p(has_datapoint_with_dim, backend, "plugin", "host-metadata")
                ), "Datapoints didn't come through"

                # downgrade agent
                run_win_puppet_agent(backend, monitors, INITIAL_VERSION, STAGE)
                backend.reset_datapoints()
                assert wait_for(
                    p(has_datapoint_with_dim, backend, "plugin", "host-metadata")
                ), "Datapoints didn't come through"

            # change agent config
            monitors = [{"type": "internal-metrics"}]
            run_win_puppet_agent(backend, monitors, INITIAL_VERSION, STAGE)
            backend.reset_datapoints()
            assert wait_for(
                p(has_datapoint_with_metric_name, backend, "sfxagent.datapoints_sent")
            ), "Didn't get internal metric datapoints"

            # re-apply without any changes
            run_win_puppet_agent(backend, monitors, INITIAL_VERSION, STAGE)
            backend.reset_datapoints()
            assert wait_for(
                p(has_datapoint_with_metric_name, backend, "sfxagent.datapoints_sent")
            ), "Didn't get internal metric datapoints"
        finally:
            print("\nDatapoints received:")
            for dp in backend.datapoints:
                print_dp_or_event(dp)
            print("\nEvents received:")
            for event in backend.events:
                print_dp_or_event(event)
            print(f"\nDimensions set: {backend.dims}")
예제 #8
0
def test_puppet_on_windows(puppet_version):
    run_win_puppet_setup(puppet_version)
    with ensure_fake_backend() as backend:
        try:
            monitors = [{"type": "host-metadata"}]
            run_win_puppet_agent(backend, monitors, INITIAL_VERSION, STAGE)
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "host-metadata")), "Datapoints didn't come through"

            if UPGRADE_VERSION:
                # upgrade agent
                run_win_puppet_agent(backend, monitors, UPGRADE_VERSION, STAGE)
                backend.reset_datapoints()
                assert wait_for(
                    p(has_datapoint_with_dim, backend, "plugin",
                      "host-metadata")), "Datapoints didn't come through"

                # downgrade agent
                run_win_puppet_agent(backend, monitors, INITIAL_VERSION, STAGE)
                backend.reset_datapoints()
                assert wait_for(
                    p(has_datapoint_with_dim, backend, "plugin",
                      "host-metadata")), "Datapoints didn't come through"

            # change agent config
            monitors = [{"type": "internal-metrics"}]
            run_win_puppet_agent(backend, monitors, INITIAL_VERSION, STAGE)
            backend.reset_datapoints()
            assert wait_for(
                p(has_datapoint_with_metric_name, backend,
                  "sfxagent.datapoints_sent")
            ), "Didn't get internal metric datapoints"

            # re-apply without any changes
            run_win_puppet_agent(backend, monitors, INITIAL_VERSION, STAGE)
            backend.reset_datapoints()
            assert wait_for(
                p(has_datapoint_with_metric_name, backend,
                  "sfxagent.datapoints_sent")
            ), "Didn't get internal metric datapoints"

            # change agent config path
            if os.path.isfile(WIN_CONFIG_PATH):
                os.remove(WIN_CONFIG_PATH)
            with tempfile.TemporaryDirectory() as tmpdir:
                new_config_path = os.path.join(tmpdir, "agent.yaml")
                run_win_puppet_agent(backend,
                                     monitors,
                                     INITIAL_VERSION,
                                     STAGE,
                                     config_path=new_config_path)
                backend.reset_datapoints()
                assert wait_for(
                    p(has_datapoint_with_metric_name, backend,
                      "sfxagent.datapoints_sent")
                ), "Didn't get internal metric datapoints"

            # change agent installation path
            with tempfile.TemporaryDirectory() as new_install_dir:
                new_install_dir = os.path.realpath(new_install_dir)
                try:
                    run_win_puppet_agent(backend,
                                         monitors,
                                         INITIAL_VERSION,
                                         STAGE,
                                         install_dir=new_install_dir)
                    backend.reset_datapoints()
                    assert wait_for(
                        p(has_datapoint_with_metric_name, backend,
                          "sfxagent.datapoints_sent")
                    ), "Didn't get internal metric datapoints"
                finally:
                    agent_path = os.path.join(new_install_dir, "SignalFxAgent",
                                              "bin", "signalfx-agent.exe")
                    if os.path.isfile(agent_path):
                        run_win_command([
                            "powershell.exe", "-command",
                            "Stop-Service -Name signalfx-agent"
                        ])
                        run_win_command([agent_path, "-service", "uninstall"])
        finally:
            print("\nDatapoints received:")
            for dp in backend.datapoints:
                print_dp_or_event(dp)
            print("\nEvents received:")
            for event in backend.events:
                print_dp_or_event(event)
            print(f"\nDimensions set: {backend.dims}")