Пример #1
0
def test_chef_upgrade_downgrade(base_image, init_system):
    if base_image == "debian-7-wheezy":
        pytest.skip(
            "Bug in chef-client, fails with 'Malformed version number string' when parsing the apt version. \
            Latest chef-client no longer supports debian 7."
        )

    dockerfile = os.path.join(DOCKERFILES_DIR, "Dockerfile.%s" % base_image)
    with run_init_system_image(base_image, path=PROJECT_DIR, dockerfile=dockerfile) as [cont, backend]:
        try:
            agent_version = run_chef_client(cont, "4.1.1-1")
            assert agent_version == "4.1.1", "agent version is not 4.1.1: %s" % agent_version
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin", "signalfx-metadata")
            ), "Datapoints didn't come through"

            # upgrade agent
            agent_version = run_chef_client(cont, "4.2.0-1")
            assert agent_version == "4.2.0", "agent version is not 4.2.0: %s" % agent_version
            backend.reset_datapoints()
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin", "signalfx-metadata")
            ), "Datapoints didn't come through"

            # downgrade agent for distros that support package downgrades
            if base_image not in ("debian-7-wheezy", "debian-8-jessie", "ubuntu1404"):
                agent_version = run_chef_client(cont, "4.1.0-1")
                assert agent_version == "4.1.0", "agent version is not 4.1.0: %s" % agent_version
                backend.reset_datapoints()
                assert wait_for(
                    p(has_datapoint_with_dim, backend, "plugin", "signalfx-metadata")
                ), "Datapoints didn't come through"
        finally:
            print("Agent log:")
            print_lines(get_agent_logs(cont, init_system))
Пример #2
0
def test_chef_upgrade_downgrade(base_image, init_system):
    dockerfile = DOCKERFILES_DIR / f"Dockerfile.{base_image}"
    with run_init_system_image(base_image, path=REPO_ROOT_DIR, dockerfile=dockerfile) as [cont, backend]:
        try:
            agent_version = run_chef_client(cont, "4.1.1")
            assert agent_version == "4.1.1", "agent version is not 4.1.1: %s" % agent_version
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin", "host-metadata")
            ), "Datapoints didn't come through"

            # upgrade agent
            agent_version = run_chef_client(cont, "4.2.0")
            assert agent_version == "4.2.0", "agent version is not 4.2.0: %s" % agent_version
            backend.reset_datapoints()
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin", "host-metadata")
            ), "Datapoints didn't come through"

            # downgrade agent for distros that support package downgrades
            if base_image not in ("debian-7-wheezy", "debian-8-jessie", "ubuntu1404"):
                agent_version = run_chef_client(cont, "4.1.0")
                assert agent_version == "4.1.0", "agent version is not 4.1.0: %s" % agent_version
                backend.reset_datapoints()
                assert wait_for(
                    p(has_datapoint_with_dim, backend, "plugin", "host-metadata")
                ), "Datapoints didn't come through"
        finally:
            print("Agent log:")
            print_lines(get_agent_logs(cont, init_system))
Пример #3
0
def test_ansible(base_image, init_system, ansible_version):
    if (base_image, init_system) in DEB_DISTROS:
        distro_type = "deb"
    else:
        distro_type = "rpm"
    buildargs = {"ANSIBLE_VERSION": ""}
    if ansible_version != "latest":
        buildargs = {"ANSIBLE_VERSION": f"=={ansible_version}"}
    opts = {
        "path": REPO_ROOT_DIR,
        "dockerfile": DOCKERFILES_DIR / f"Dockerfile.{base_image}",
        "buildargs": buildargs,
        "with_socat": False,
    }
    with run_init_system_image(base_image, **opts) as [cont, backend]:
        import_old_key(cont, distro_type)
        try:
            monitors = [{"type": "host-metadata"}]
            run_ansible(cont, init_system, backend, monitors, INITIAL_VERSION,
                        STAGE)
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "host-metadata")), "Datapoints didn't come through"

            assert_old_key_removed(cont, distro_type)

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

                # downgrade agent
                run_ansible(cont, init_system, 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_ansible(cont, init_system, 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("Agent log:")
            print_lines(get_agent_logs(cont, init_system))
Пример #4
0
def test_chef(base_image, init_system, chef_version):
    if (base_image, init_system) in DEB_DISTROS:
        distro_type = "deb"
    else:
        distro_type = "rpm"
    if base_image == "centos8" and chef_version != "latest" and int(
            chef_version.split(".")[0]) < 15:
        pytest.skip(f"chef {chef_version} not supported on centos 8")
    buildargs = {"CHEF_INSTALLER_ARGS": ""}
    if chef_version != "latest":
        buildargs["CHEF_INSTALLER_ARGS"] = f"-v {chef_version}"
    opts = {
        "path": REPO_ROOT_DIR,
        "dockerfile": DOCKERFILES_DIR / f"Dockerfile.{base_image}",
        "buildargs": buildargs
    }
    with run_init_system_image(base_image, **opts) as [cont, backend]:
        import_old_key(cont, distro_type)
        try:
            agent_version = INITIAL_VERSION
            monitors = [{"type": "host-metadata"}]
            run_chef_client(cont, chef_version, agent_version, STAGE, monitors)
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "host-metadata")), "Datapoints didn't come through"

            assert_old_key_removed(cont, distro_type)

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

                # downgrade agent for distros that support package downgrades
                if base_image not in ("debian-7-wheezy", "debian-8-jessie",
                                      "ubuntu1404"):
                    agent_version = INITIAL_VERSION
                    run_chef_client(cont, chef_version, agent_version, STAGE,
                                    monitors)
                    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_chef_client(cont, chef_version, agent_version, STAGE, monitors)
            backend.reset_datapoints()
            assert wait_for(
                p(has_datapoint_with_metric_name, backend,
                  "sfxagent.datapoints_sent")
            ), "Didn't get internal metric datapoints"
        finally:
            print("Agent log:")
            print_lines(get_agent_logs(cont, init_system))
Пример #5
0
def test_chef(base_image, init_system, chef_version):
    buildargs = {"CHEF_INSTALLER_ARGS": ""}
    if chef_version != "latest":
        buildargs["CHEF_INSTALLER_ARGS"] = f"-v {chef_version}"
    opts = {
        "path": REPO_ROOT_DIR,
        "dockerfile": DOCKERFILES_DIR / f"Dockerfile.{base_image}",
        "buildargs": buildargs
    }
    with run_init_system_image(base_image, **opts) as [cont, backend]:
        try:
            run_chef_client(cont, chef_version, INITIAL_VERSION, STAGE)
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "host-metadata")), "Datapoints didn't come through"

            # upgrade agent
            run_chef_client(cont, chef_version, 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 for distros that support package downgrades
            if base_image not in ("debian-7-wheezy", "debian-8-jessie",
                                  "ubuntu1404"):
                run_chef_client(cont, chef_version, 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("Agent log:")
            print_lines(get_agent_logs(cont, init_system))
Пример #6
0
def _run_tests(base_image,
               init_system,
               installer_args,
               user=None,
               **extra_run_kwargs):
    if user:
        installer_args = f"--service-user {user} --service-group {user} {installer_args}"
    else:
        user = "******"
    with run_init_system_image(base_image,
                               **extra_run_kwargs) as [cont, backend]:
        copy_file_into_container(INSTALLER_PATH, cont, "/opt/install.sh")

        # Unfortunately, wget and curl both don't like self-signed certs, even
        # if they are in the system bundle, so we need to use the --insecure
        # flag.
        code, output = cont.exec_run(
            f"sh /opt/install.sh --insecure {installer_args}")
        print("Output of install script:")
        print_lines(output)
        assert code == 0, "Agent could not be installed!"

        try:
            verify_override_files(cont, init_system, user)
            assert is_agent_running_as_non_root(
                cont, user), f"Agent is not running as {user} user"
            yield backend, cont
        finally:
            print("Agent log:")
            print_lines(get_agent_logs(cont, init_system))
Пример #7
0
def run_puppet_agent(base_image, init_system):
    dockerfile = os.path.join(DOCKERFILES_DIR, "Dockerfile.%s" % base_image)
    with run_init_system_image(base_image,
                               path=REPO_ROOT_DIR,
                               dockerfile=dockerfile,
                               with_socat=False) as [
                                   cont,
                                   backend,
                               ]:
        if (base_image, init_system) in DEB_DISTROS:
            code, output = cont.exec_run(
                f"puppet module install puppetlabs-apt --version {APT_MODULE_VERSION}"
            )
            assert code == 0, output.decode("utf-8")
            print_lines(output)
        with tempfile.NamedTemporaryFile(mode="w") as fd:
            fd.write(
                CONFIG.substitute(ingest_url=backend.ingest_url,
                                  api_url=backend.api_url))
            fd.flush()
            copy_file_into_container(fd.name, cont, "/root/agent.pp")
        code, output = cont.exec_run("puppet apply /root/agent.pp")
        assert code in (0, 2), output.decode("utf-8")
        print_lines(output)
        try:
            yield cont, backend
        finally:
            print("Agent log:")
            print_lines(get_agent_logs(cont, init_system))
Пример #8
0
def test_puppet(base_image, init_system, puppet_release):
    if (base_image, init_system) in DEB_DISTROS:
        distro_type = "deb"
    else:
        distro_type = "rpm"
    buildargs = {"PUPPET_RELEASE": ""}
    if puppet_release != "latest":
        buildargs = {"PUPPET_RELEASE": puppet_release}
    opts = {
        "path": REPO_ROOT_DIR,
        "dockerfile": DOCKERFILES_DIR / f"Dockerfile.{base_image}",
        "buildargs": buildargs,
        "with_socat": False,
    }
    with run_init_system_image(base_image, **opts) as [cont, backend]:
        import_old_key(cont, distro_type)
        if (base_image, init_system) in DEB_DISTROS:
            code, output = cont.exec_run(
                f"puppet module install puppetlabs-apt --version {APT_MODULE_VERSION}"
            )
            assert code == 0, output.decode("utf-8")
            print_lines(output)
        try:
            monitors = [{"type": "host-metadata"}]
            run_puppet_agent(cont, backend, monitors, INITIAL_VERSION, STAGE)
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "host-metadata")), "Datapoints didn't come through"

            assert_old_key_removed(cont, distro_type)

            if UPGRADE_VERSION:
                # upgrade agent
                run_puppet_agent(cont, 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_puppet_agent(cont, 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_puppet_agent(cont, 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("Agent log:")
            print_lines(get_agent_logs(cont, init_system))
Пример #9
0
def test_chef(base_image, init_system, chef_version):
    dockerfile = DOCKERFILES_DIR / f"Dockerfile.{base_image}"
    buildargs = {"CHEF_INSTALLER_ARGS": ""}
    if chef_version != "latest":
        buildargs["CHEF_INSTALLER_ARGS"] = f"-v {chef_version}"
    with run_init_system_image(base_image,
                               path=REPO_ROOT_DIR,
                               dockerfile=dockerfile,
                               buildargs=buildargs) as [
                                   cont,
                                   backend,
                               ]:
        try:
            installed_version = run_chef_client(cont, chef_version,
                                                INITIAL_VERSION,
                                                STAGE).replace("-", "~")
            assert installed_version == INITIAL_VERSION, "installed agent version is '%s', expected '%s'" % (
                installed_version,
                INITIAL_VERSION,
            )
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "host-metadata")), "Datapoints didn't come through"

            # upgrade agent
            installed_version = run_chef_client(cont, chef_version,
                                                UPGRADE_VERSION,
                                                STAGE).replace("-", "~")
            assert installed_version == UPGRADE_VERSION, "installed agent version is '%s', expected '%s'" % (
                installed_version,
                UPGRADE_VERSION,
            )
            backend.reset_datapoints()
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "host-metadata")), "Datapoints didn't come through"

            # downgrade agent for distros that support package downgrades
            if base_image not in ("debian-7-wheezy", "debian-8-jessie",
                                  "ubuntu1404"):
                installed_version = run_chef_client(cont, chef_version,
                                                    INITIAL_VERSION,
                                                    STAGE).replace("-", "~")
                assert installed_version == INITIAL_VERSION, "installed agent version is '%s', expected '%s'" % (
                    installed_version,
                    INITIAL_VERSION,
                )
                backend.reset_datapoints()
                assert wait_for(
                    p(has_datapoint_with_dim, backend, "plugin",
                      "host-metadata")), "Datapoints didn't come through"
        finally:
            print("Agent log:")
            print_lines(get_agent_logs(cont, init_system))
Пример #10
0
def test_chef(base_image, init_system):
    dockerfile = DOCKERFILES_DIR / f"Dockerfile.{base_image}"
    with run_init_system_image(base_image, path=REPO_ROOT_DIR, dockerfile=dockerfile) as [cont, backend]:
        try:
            # install latest agent
            run_chef_client(cont)
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin", "host-metadata")
            ), "Datapoints didn't come through"
        finally:
            print("Agent log:")
            print_lines(get_agent_logs(cont, init_system))
Пример #11
0
def test_chef(base_image, init_system):
    dockerfile = os.path.join(DOCKERFILES_DIR, "Dockerfile.%s" % base_image)
    with run_init_system_image(base_image,
                               path=PROJECT_DIR,
                               dockerfile=dockerfile) as [cont, backend]:
        try:
            # install latest agent
            run_chef_client(cont)
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "signalfx-metadata")), "Datapoints didn't come through"
        finally:
            print("Agent log:")
            print_lines(get_agent_logs(cont, init_system))
Пример #12
0
def _test_package_install(base_image, package_path, init_system):
    with run_init_system_image(base_image,
                               with_socat=False) as [cont, backend]:
        _, package_ext = os.path.splitext(package_path)
        copy_file_into_container(package_path, cont,
                                 "/opt/signalfx-agent%s" % package_ext)

        install_deps(cont, base_image)

        if "opensuse" in base_image:
            install_cmd = "rpm -ivh --nodeps /opt/signalfx-agent.rpm"
        else:
            install_cmd = INSTALL_COMMAND[package_ext]

        _test_install_package(cont, install_cmd)

        _test_package_verify(cont, package_ext, base_image)

        if init_system == INIT_SYSTEMD:
            assert not path_exists_in_container(cont,
                                                "/etc/init.d/signalfx-agent")
        else:
            assert path_exists_in_container(cont, "/etc/init.d/signalfx-agent")

        cont.exec_run("bash -ec 'echo -n testing123 > /etc/signalfx/token'")
        update_agent_yaml(cont, backend, hostname="test-" + base_image)

        try:
            _test_service_list(cont, init_system)
            _test_service_restart(cont, init_system, backend)
            _test_service_status(cont, init_system, "active")
            _test_service_stop(cont, init_system, backend)
            _test_service_status(cont, init_system, "inactive")
            _test_service_start(cont, init_system, backend)
            _test_service_status(cont, init_system, "active")
            _test_service_stop(cont, init_system, backend)
            _test_system_restart(cont, init_system, backend)
            if init_system == INIT_SYSTEMD:
                _test_service_status_redirect(cont)
            _test_agent_status(cont)
            _test_service_override(cont, init_system, backend)
        finally:
            cont.reload()
            if cont.status.lower() == "running":
                print("Agent service status:")
                print_lines(
                    cont.exec_run(INIT_STATUS_COMMAND[init_system]).output)
                print("Agent log:")
                print_lines(get_agent_logs(cont, init_system))
Пример #13
0
def test_puppet(base_image, init_system):
    dockerfile = os.path.join(DOCKERFILES_DIR, "Dockerfile.%s" % base_image)
    with run_init_system_image(base_image,
                               path=REPO_ROOT_DIR,
                               dockerfile=dockerfile,
                               with_socat=False) as [
                                   cont,
                                   backend,
                               ]:
        if (base_image, init_system) in DEB_DISTROS:
            code, output = cont.exec_run(
                f"puppet module install puppetlabs-apt --version {APT_MODULE_VERSION}"
            )
            assert code == 0, output.decode("utf-8")
            print_lines(output)
        try:
            monitors = '{ type => "host-metadata" },'
            run_puppet_agent(cont, backend, monitors, INITIAL_VERSION, STAGE)
            assert is_agent_running_as_non_root(
                cont), "Agent is not running as non-root user"
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "host-metadata")), "Datapoints didn't come through"
            run_puppet_agent(cont, backend, monitors, UPGRADE_VERSION, STAGE)
            backend.reset_datapoints()
            assert is_agent_running_as_non_root(
                cont), "Agent is not running as non-root user"
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "host-metadata")), "Datapoints didn't come through"
            run_puppet_agent(cont, backend, monitors, INITIAL_VERSION, STAGE)
            backend.reset_datapoints()
            assert is_agent_running_as_non_root(
                cont), "Agent is not running as non-root user"
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "host-metadata")), "Datapoints didn't come through"
            monitors = '{ type => "internal-metrics" },'
            run_puppet_agent(cont, backend, monitors, INITIAL_VERSION, STAGE)
            backend.reset_datapoints()
            assert is_agent_running_as_non_root(
                cont), "Agent is not running as non-root user"
            assert wait_for(
                p(has_datapoint_with_metric_name, backend,
                  "sfxagent.datapoints_sent")
            ), "Didn't get internal metric datapoints"
        finally:
            print("Agent log:")
            print_lines(get_agent_logs(cont, init_system))
Пример #14
0
def test_salt(base_image, init_system):
    if (base_image, init_system) in DEB_DISTROS:
        distro_type = "deb"
    else:
        distro_type = "rpm"

    opts = {"path": REPO_ROOT_DIR, "dockerfile": DOCKERFILES_DIR / f"Dockerfile.{base_image}", "with_socat": False}
    with run_init_system_image(base_image, **opts) as [cont, backend]:
        try:
            import_old_key(cont, distro_type)

            monitors = [{"type": "host-metadata"}]
            run_salt(cont, init_system, backend, INITIAL_VERSION, monitors, STAGE)
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin", "host-metadata")
            ), "Datapoints didn't come through"

            assert_old_key_removed(cont, distro_type)

            if UPGRADE_VERSION:
                # upgrade agent
                user = "******"
                if tuple(UPGRADE_VERSION.split(".")) >= ("5", "1", "0"):
                    user = "******"
                run_salt(cont, init_system, backend, UPGRADE_VERSION, monitors, STAGE, user)
                backend.reset_datapoints()
                assert wait_for(
                    p(has_datapoint_with_dim, backend, "plugin", "host-metadata")
                ), "Datapoints didn't come through"

                # downgrade agent
                run_salt(cont, init_system, backend, INITIAL_VERSION, monitors, 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_salt(cont, init_system, backend, INITIAL_VERSION, monitors, 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("Agent log:")
            print_lines(get_agent_logs(cont, init_system))
Пример #15
0
def test_ansible(base_image, init_system, ansible_version):
    if base_image == "centos8" and ansible_version != "latest" and tuple(
            ansible_version.split(".")) < ("2", "8", "1"):
        pytest.skip(f"ansible {ansible_version} not supported on {base_image}")
    buildargs = {"ANSIBLE_VERSION": ""}
    if ansible_version != "latest":
        buildargs = {"ANSIBLE_VERSION": f"=={ansible_version}"}
    opts = {
        "path": REPO_ROOT_DIR,
        "dockerfile": DOCKERFILES_DIR / f"Dockerfile.{base_image}",
        "buildargs": buildargs,
        "with_socat": False,
    }
    with run_init_system_image(base_image, **opts) as [cont, backend]:
        try:
            monitors = [{"type": "host-metadata"}]
            run_ansible(cont, 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_ansible(cont, 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_ansible(cont, 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_ansible(cont, 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("Agent log:")
            print_lines(get_agent_logs(cont, init_system))
Пример #16
0
def test_chef(base_image, init_system):
    if base_image == "debian-7-wheezy":
        pytest.skip(
            "Bug in chef-client, fails with 'Malformed version number string' when parsing the apt version. \
            Latest chef-client no longer supports debian 7."
        )

    dockerfile = os.path.join(DOCKERFILES_DIR, "Dockerfile.%s" % base_image)
    with run_init_system_image(base_image, path=PROJECT_DIR, dockerfile=dockerfile) as [cont, backend]:
        try:
            # install latest agent
            run_chef_client(cont)
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin", "signalfx-metadata")
            ), "Datapoints didn't come through"
        finally:
            print("Agent log:")
            print_lines(get_agent_logs(cont, init_system))
Пример #17
0
def test_salt(base_image, init_system):
    opts = {
        "path": REPO_ROOT_DIR,
        "dockerfile": DOCKERFILES_DIR / f"Dockerfile.{base_image}",
        "with_socat": False
    }
    with run_init_system_image(base_image, **opts) as [cont, backend]:
        try:
            monitors = [{"type": "host-metadata"}]
            run_salt(cont, backend, INITIAL_VERSION, monitors, STAGE)
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "host-metadata")), "Datapoints didn't come through"

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

            # downgrade agent
            run_salt(cont, backend, INITIAL_VERSION, monitors, 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_salt(cont, backend, INITIAL_VERSION, monitors, 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("Agent log:")
            print_lines(get_agent_logs(cont, init_system))
Пример #18
0
def _test_package_upgrade(base_image, package_path, init_system):
    with run_init_system_image(base_image,
                               with_socat=False) as [cont, backend]:
        _, package_ext = os.path.splitext(package_path)
        copy_file_into_container(package_path, cont,
                                 "/opt/signalfx-agent%s" % package_ext)

        install_deps(cont, base_image)

        if "opensuse" in base_image:
            install_cmd = f"bash -ec 'wget -nv {OLD_SUSE_RPM_URL} && rpm -ivh --nodeps {OLD_SUSE_RPM_NAME}'"
            upgrade_cmd = "rpm -Uvh --nodeps /opt/signalfx-agent.rpm"
        else:
            install_cmd = OLD_INSTALL_COMMAND[package_ext]
            upgrade_cmd = UPGRADE_COMMAND[package_ext]

        _test_install_package(cont, install_cmd)

        cont.exec_run("bash -ec 'echo -n testing123 > /etc/signalfx/token'")
        old_agent_yaml = update_agent_yaml(cont,
                                           backend,
                                           hostname="test-" + base_image)
        _, _ = cont.exec_run("cp -f %s %s.orig" %
                             (AGENT_YAML_PATH, AGENT_YAML_PATH))

        code, output = cont.exec_run(upgrade_cmd)
        print("Output of package upgrade:")
        print_lines(output)
        assert code == 0, "Package could not be upgraded!"

        _test_package_verify(cont, package_ext, base_image)

        if init_system == INIT_SYSTEMD:
            assert not path_exists_in_container(cont,
                                                "/etc/init.d/signalfx-agent")
        else:
            assert path_exists_in_container(cont, "/etc/init.d/signalfx-agent")

        new_agent_yaml = get_container_file_content(cont, AGENT_YAML_PATH)
        diff = get_agent_yaml_diff(old_agent_yaml, new_agent_yaml)
        assert not diff, "%s different after upgrade!\n%s" % (AGENT_YAML_PATH,
                                                              diff)

        try:
            _test_service_list(cont, init_system)
            _test_service_restart(cont, init_system, backend)
            _test_service_status(cont, init_system, "active")
            _test_service_stop(cont, init_system, backend)
            _test_service_status(cont, init_system, "inactive")
            _test_service_start(cont, init_system, backend)
            _test_service_status(cont, init_system, "active")
            _test_service_stop(cont, init_system, backend)
            _test_system_restart(cont, init_system, backend)
            if init_system == INIT_SYSTEMD:
                _test_service_status_redirect(cont)
            _test_agent_status(cont)
            _test_service_override(cont, init_system, backend)
        finally:
            cont.reload()
            if cont.status.lower() == "running":
                print("Agent service status:")
                print_lines(
                    cont.exec_run(INIT_STATUS_COMMAND[init_system]).output)
                print("Agent log:")
                print_lines(get_agent_logs(cont, init_system))