Exemple #1
0
def main(raw_args):
    args = _parse_arguments(raw_args)

    distro_name = _os_environ_get("DISTRO", "ubuntu-20.04")
    docker_tag = _os_environ_get("DOCKER_TAG",
                                 "%s-latest" % current_base_branch_name())
    version_spec = _os_environ_get("VERSION", CMKVersion.GIT)
    edition = _os_environ_get("EDITION", CMKVersion.CEE)
    branch = _os_environ_get("BRANCH", current_base_branch_name())

    version = CMKVersion(version_spec, edition, branch)
    logger.info("Version: %s (%s), Edition: %s, Branch: %s", version.version,
                version.version_spec, edition, branch)

    result_path_str = _os_environ_get("RESULT_PATH", "")
    if result_path_str:
        result_path = Path(result_path_str)
    else:
        # Only create the temporary directory when RESULT_PATH not given. And keep it after the
        # script finishes. Otherwise the results are lost.
        result_path = Path(tempfile.mkdtemp(prefix="cmk-run-dockerized-"))

    result_path.mkdir(parents=True, exist_ok=True)
    logger.info("Prepared result path: %s", result_path)

    return execute_tests_in_container(
        distro_name=distro_name,
        docker_tag=docker_tag,
        command=["make", "-C", "tests", args.make_target],
        version=version,
        result_path=result_path,
        interactive=args.make_target == "debug",
    )
def main(raw_args):
    args = _parse_arguments(raw_args)

    with tempfile.TemporaryDirectory(prefix="cmk-run-dockerized-") as tmpdir:
        tmp_path = Path(tmpdir)

        distro_name = os.environ.get("DISTRO", "ubuntu-19.04")
        docker_tag = os.environ.get("DOCKER_TAG", "%s-latest" % current_base_branch_name())
        version_spec = os.environ.get("VERSION", CMKVersion.GIT)
        edition = os.environ.get("EDITION", CMKVersion.CEE)
        branch = os.environ.get("BRANCH", current_base_branch_name())

        version = CMKVersion(version_spec, edition, branch)
        logger.info("Version: %s (%s), Edition: %s, Branch: %s", version.version,
                    version.version_spec, edition, branch)

        result_path = Path(os.environ.get("RESULT_PATH", tmp_path.joinpath("results")))
        result_path.mkdir(parents=True, exist_ok=True)
        logger.info("Prepared result path: %s", result_path)

        return execute_tests_in_container(
            distro_name=distro_name,
            docker_tag=docker_tag,
            command=["make", "-C", "tests-py3", args.make_target],
            version=version,
            result_path=result_path,
            interactive=args.make_target == "debug",
        )
Exemple #3
0
    def __init__(self,
                 site_id,
                 reuse=True,
                 version=CMKVersion.DEFAULT,
                 edition=CMKVersion.CEE,
                 branch="master",
                 update_from_git=False,
                 install_test_python_modules=True):
        assert site_id
        self.id = site_id
        self.root = "/omd/sites/%s" % self.id
        self.version = CMKVersion(version, edition, branch)

        self.update_from_git = update_from_git
        self.install_test_python_modules = install_test_python_modules

        self.reuse = reuse

        self.http_proto = "http"
        self.http_address = "127.0.0.1"
        self.url = "%s://%s/%s/check_mk/" % (self.http_proto,
                                             self.http_address, self.id)

        self._apache_port = None  # internal cache for the port
        self._livestatus_port = None
Exemple #4
0
    def _copy_omd_version_for_test(self):
        if not os.environ.get("BUILD_NUMBER"):
            return  # Don't do this in non CI environments

        src_version, src_path = self.version.version, self.version.version_path(
        )
        new_version_name = "%s-%s" % (src_version, os.environ["BUILD_NUMBER"])
        self.version = CMKVersion(new_version_name, self.version.edition(),
                                  self.version._branch)

        print("Copy CMK '%s' to '%s'" %
              (src_path, self.version.version_path()))
        assert not os.path.exists(self.version.version_path()), \
            "New version path '%s' already exists" % self.version.version_path()

        def execute(cmd):
            print("Executing: %s" % cmd)
            rc = os.system(cmd) >> 8  # nosec
            if rc != 0:
                raise Exception("Failed to execute '%s'. Exit code: %d" %
                                (cmd, rc))

        execute("sudo /bin/cp -a %s %s" %
                (src_path, self.version.version_path()))

        execute("sudo sed -i \"s|%s|%s|g\" %s/bin/omd" %
                (src_version, new_version_name, self.version.version_path()))

        omd_init_path = "%s/lib/python3/omdlib/__init__.py" % self.version.version_path(
        )
        # Temporary hack. Can be removed after 2019-12-19
        if not os.path.exists(omd_init_path):
            omd_init_path = "%s/lib/python/omdlib/__init__.py" % self.version.version_path(
            )
        execute("sudo sed -i \"s|%s|%s|g\" %s" %
                (src_version, new_version_name, omd_init_path))

        execute("sudo sed -i \"s|%s|%s|g\" %s/share/omd/omd.info" %
                (src_version, new_version_name, self.version.version_path()))

        # we should use self.version.version_path() in the RPATH, but that is limited to
        # 32 bytes and our versions exceed this limit. We need to use some hack to make
        # this possible
        if not os.path.exists("/omd/v"):
            execute("sudo /bin/ln -s /omd/versions /omd/v")

        execute(
            "sudo chrpath -r /omd/v/%s/lib %s/bin/python" %
            (self.version.version_directory(), self.version.version_path()))

        execute(
            "sudo chrpath -r /omd/v/%s/lib %s/bin/python3" %
            (self.version.version_directory(), self.version.version_path()))
Exemple #5
0
    def __init__(self,
                 site_id,
                 reuse=True,
                 version=CMKVersion.DEFAULT,
                 edition=CMKVersion.CEE,
                 branch="master"):
        assert site_id
        self.id = site_id
        self.root = "/omd/sites/%s" % self.id
        self.version = CMKVersion(version, edition, branch)

        self.update_with_git = version == CMKVersion.GIT

        self.reuse = reuse

        self.http_proto = "http"
        self.http_address = "127.0.0.1"
        self.url = "%s://%s/%s/check_mk/" % (self.http_proto, self.http_address, self.id)

        self._apache_port = None  # internal cache for the port
        self._livestatus_port = None
Exemple #6
0
def main():
    add_python_paths()

    version_spec = os.environ.get("VERSION", CMKVersion.DAILY)
    edition = os.environ.get("EDITION", CMKVersion.CEE)
    branch = os.environ.get("BRANCH")
    if branch is None:
        branch = current_base_branch_name()

    logger.info("Version: %s, Edition: %s, Branch: %s", version_spec, edition, branch)
    version = CMKVersion(version_spec, edition, branch)

    if version.is_installed():
        logger.info("Version %s is already installed. Terminating.")
        return 0

    manager = ABCPackageManager.factory()
    manager.install(version.version, version.edition())

    if not version.is_installed():
        logger.error("Failed not install version")

    return 0