def _install()

in microsoft/testsuites/dpdk/dpdktestpmd.py [0:0]


    def _install(self) -> bool:
        self._testpmd_output_after_reenable = ""
        self._testpmd_output_before_rescind = ""
        self._testpmd_output_during_rescind = ""
        self._last_run_output = ""
        self._dpdk_version_info: Union[VersionInfo, None] = None
        self._determine_network_hardware()
        node = self.node
        self._install_dependencies()
        # installing from distro package manager
        if self._dpdk_source and self._dpdk_source == "package_manager":
            self.node.log.info(
                "Installing dpdk and dev package from package manager..."
            )
            if isinstance(node.os, Ubuntu):
                node.os.install_packages(["dpdk", "dpdk-dev"])
            elif isinstance(node.os, Redhat):
                node.os.install_packages(["dpdk", "dpdk-devel"])
            else:
                raise NotImplementedError(
                    "Dpdk package names are missing in dpdktestpmd.install"
                    f" for os {node.os.name}"
                )

            self._dpdk_version_info = node.os.get_package_information("dpdk")

            if self._dpdk_version_info >= "19.11.0":
                self._testpmd_install_path = "dpdk-testpmd"
            else:
                self._testpmd_install_path = "testpmd"
            self.node.log.info(
                f"Installed DPDK version {str(self._dpdk_version_info)} "
                "from package manager"
            )
            self._load_drivers_for_dpdk()
            return True

        # otherwise install from source tarball or git
        self.node.log.info(f"Installing dpdk from source: {self._dpdk_source}")
        self._dpdk_repo_path_name = "dpdk"
        result = self.node.execute("which dpdk-testpmd")
        self.dpdk_path = self.node.working_path.joinpath(self._dpdk_repo_path_name)
        if result.exit_code == 0:  # tools are already installed
            return True
        git_tool = node.tools[Git]
        echo_tool = node.tools[Echo]

        if self._dpdk_source and self._dpdk_source.endswith(".tar.gz"):
            wget_tool = node.tools[Wget]
            tar_tool = node.tools[Tar]
            if self._dpdk_branch:
                node.log.warn(
                    (
                        "DPDK tarball source does not need dpdk_branch defined. "
                        "User-defined variable dpdk_branch will be ignored."
                    )
                )
            working_path = str(node.working_path)
            wget_tool.get(
                self._dpdk_source,
                working_path,
            )
            dpdk_filename = self._dpdk_source.split("/")[-1]
            # extract tar into dpdk/ folder and discard old root folder name
            tar_tool.extract(
                str(node.working_path.joinpath(dpdk_filename)),
                str(self.dpdk_path),
                strip_components=1,
            )
            self.set_version_info_from_source_install(
                self._dpdk_source, self._version_info_from_tarball_regex
            )
        else:
            git_tool.clone(
                self._dpdk_source,
                cwd=node.working_path,
                dir_name=self._dpdk_repo_path_name,
            )
            if self._dpdk_branch:
                git_tool.checkout(self._dpdk_branch, cwd=self.dpdk_path)
                self.set_version_info_from_source_install(
                    self._dpdk_branch, self._version_info_from_git_tag_regex
                )
        self._load_drivers_for_dpdk()
        self.__execute_assert_zero("meson build", self.dpdk_path)
        dpdk_build_path = self.dpdk_path.joinpath("build")
        self.__execute_assert_zero("which ninja", dpdk_build_path)
        self.__execute_assert_zero("ninja", dpdk_build_path, timeout=1200)
        self.__execute_assert_zero("ninja install", dpdk_build_path)
        self.__execute_assert_zero("ldconfig", dpdk_build_path)
        library_bashrc_lines = [
            "export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:/usr/local/lib64/pkgconfig/",
            "export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib64/",
        ]
        echo_tool.write_to_file(
            ";".join(library_bashrc_lines),
            node.get_pure_path("~/.bashrc"),
            append=True,
        )

        return True