Exemple #1
0
    def _check_workspace(self):
        """
        Check if workspace is available on remote host
        :return: True if exsit, false otherwise
        """

        if self.cfg.remote_workspace:
            # User defined the remote workspace to be used
            # will raise if check fail
            if 0 == self._execute_cmd_remote(
                    cmd=filepath_exist_cmd(
                        fix_home_prefix(self.cfg.remote_workspace)),
                    label="workspace availability check (1)",
                    check=True,
            ):
                return True

        if 0 == self._execute_cmd_remote(
                cmd=filepath_exist_cmd(self._workspace_paths.local),
                label="workspace availability check (2)",
                check=False,
        ):
            # local workspace accessible on remote
            return True

        return False
Exemple #2
0
def test_prepare_remote(remote_resource, workspace, push_dir):
    remote_resource.make_runpath_dirs()
    remote_resource._prepare_remote()

    assert (
        remote_resource._remote_plan_runpath == remote_resource.parent.runpath
    )
    assert remote_resource._remote_resource_runpath == remote_resource.runpath
    assert remote_resource._remote_runid_file == "/".join(
        [
            remote_resource._remote_plan_runpath,
            remote_resource.parent.runid_filename,
        ]
    )
    assert remote_resource._workspace_paths.remote == "/".join(
        [remote_resource._remote_plan_runpath, "fetched_workspace"]
    )

    assert remote_resource._working_dirs.remote == rebase_path(
        os.getcwd(),
        workspace,
        remote_resource._workspace_paths.remote,
    )

    for remote_path in [
        remote_resource._remote_runid_file,
        "/".join([remote_resource._workspace_paths.remote, "tests", "unit"]),
        "/".join([push_dir, "file1"]),
        "/".join([push_dir, "file1_ln"]),
        "/".join([remote_resource._working_dirs.remote, "file1"]),
        "/".join([workspace, "file2"]),
    ]:
        assert 0 == remote_resource._execute_cmd_remote(
            cmd=filepath_exist_cmd(remote_path),
            check=False,
        )

    for remote_path in [
        "/".join(
            [remote_resource._workspace_paths.remote, "tests", "functional"]
        ),
        "/".join([push_dir, "file3"]),
    ]:
        assert 0 != remote_resource._execute_cmd_remote(
            cmd=filepath_exist_cmd(remote_path),
            check=False,
        )

    # for now, these setting are used by child.py rather than remote_resource
    assert remote_resource.setup_metadata.env == {
        "LOCAL_USER": getpass.getuser()
    }
    assert remote_resource.setup_metadata.setup_script == ["remote_setup.py"]
    assert remote_resource.setup_metadata.push_dirs == [push_dir]
    assert remote_resource.setup_metadata.push_files == [
        "/".join([remote_resource._working_dirs.remote, "file1"]),
        "/".join([workspace, "file2"]),
    ]

    remote_resource._clean_remote()
Exemple #3
0
    def _create_remote_dirs(self):
        """Create mandatory directories in remote host."""

        exist_on_remote = self._check_workspace()

        if 0 != self._execute_cmd_remote(
                cmd=filepath_exist_cmd(self._remote_runid_file),
                label="runid file availability check",
                check=False,
        ):
            # clean up remote runpath
            self._execute_cmd_remote(
                cmd=rm_cmd(self._remote_plan_runpath),
                label="remove remote plan runpath",
            )

            self._execute_cmd_remote(
                cmd=mkdir_cmd(self._remote_plan_runpath),
                label="create remote plan runpath",
            )

            self._execute_cmd_remote(
                cmd=f"/bin/touch {self._remote_runid_file}",
                label="create remote runid file",
            )

            self._prepare_workspace(exist_on_remote)
            self._copy_testplan_package()

        self._execute_cmd_remote(
            cmd=mkdir_cmd(self._remote_resource_runpath),
            label="create remote resource runpath",
        )
Exemple #4
0
def test_runpath_in_ws(workspace):

    mockplan = TestplanMock(
        "plan", runpath=os.path.join(workspace, "runpath_in_ws")
    )

    remote_resource = RemoteResource(
        REMOTE_HOST,
        workspace=workspace,
        workspace_exclude=[
            "conftest.py",
            "helpers",
            "*unctiona*",
            "__pycache__",
            "*.pyc",
        ],
    )
    remote_resource.parent = mockplan.runnable
    remote_resource.cfg.parent = mockplan.runnable.cfg

    remote_resource.make_runpath_dirs()
    remote_resource._prepare_remote()

    assert 0 != remote_resource._execute_cmd_remote(
        cmd=filepath_exist_cmd(
            "/".join(
                [
                    remote_resource._workspace_paths.remote,
                    "tests",
                    "functional",
                ]
            )
        ),
        check=False,
    )
Exemple #5
0
    def _copy_testplan_package(self):
        """Make testplan package available on remote host"""

        if self.cfg.testplan_path:
            self._execute_cmd_remote(
                cmd=link_cmd(
                    path=self.cfg.testplan_path,
                    link=self._testplan_import_path.remote,
                ),
                label="linking to testplan package (1).",
            )
            return

        self._testplan_import_path.local = os.path.dirname(
            os.path.dirname(module_abspath(testplan)))

        # test if testplan package is available on remote host
        if 0 == self._execute_cmd_remote(
                cmd=filepath_exist_cmd(self._testplan_import_path.local),
                label="testplan package availability check",
                check=False,
        ):
            # exists on remote, make symlink
            self._execute_cmd_remote(
                cmd=link_cmd(
                    path=self._testplan_import_path.local,
                    link=self._testplan_import_path.remote,
                ),
                label="linking to testplan package (2).",
            )

        else:
            # copy to remote
            self._transfer_data(
                # join with "" to add trailing "/" to source
                # this will copy everything under local import path to to testplan_lib
                source=os.path.join(self._testplan_import_path.local, ""),
                target=self._testplan_import_path.remote,
                remote_target=True,
                deref_links=True,
            )
    def _copy_workspace(self):
        """Make the local workspace available on remote host."""

        if self.cfg.remote_workspace:
            # User defined the remote workspace to be used
            # Make a soft link and return
            self._execute_cmd_remote(
                cmd=link_cmd(
                    path=fix_home_prefix(self.cfg.remote_workspace),
                    link=self._workspace_paths.remote,
                ),
                label="linking to remote workspace (1).",
            )
            return

        if 0 == self._execute_cmd_remote(
                cmd=filepath_exist_cmd(self._workspace_paths.local),
                label="workspace availability check",
                check=False,
        ):
            # exists on remote, make symlink
            self._execute_cmd_remote(
                cmd=link_cmd(
                    path=self._workspace_paths.local,
                    link=self._workspace_paths.remote,
                ),
                label="linking to remote workspace (2).",
            )

        else:
            # copy to remote
            self._transfer_data(
                # join with "" to add trailing "/" to source
                # this will copy everything under local import path to to testplan_lib
                source=os.path.join(self._workspace_paths.local, ""),
                target=self._workspace_paths.remote,
                remote_target=True,
                exclude=self.cfg.workspace_exclude,
            )