Esempio n. 1
0
    def _prepare_remote(self):
        """Transfer local data to remote host."""
        import testplan.runners.pools.child as child
        self._child_paths['local'] = module_abspath(child, self._user)
        self._working_dirs = {'local': pwd()}
        self._workspace_paths['local'] = self.cfg.workspace

        if self.cfg.copy_workspace_check:
            cmd = self.cfg.copy_workspace_check(self.cfg.ssh_cmd,
                                                self.cfg.index,
                                                self._workspace_paths['local'])
            self._workspace_transferred = self._execute_cmd(cmd) != 0

        if self._workspace_transferred is True:
            self._create_remote_dirs()
            self._copy_child_script()
            self._copy_dependencies_module()
            self._copy_workspace()

            self._working_dirs = {
                'local':
                pwd(),
                'remote':
                '{}{}'.format(
                    self._workspace_paths['remote'],
                    '/'.join(pwd().split(os.sep)).replace(
                        '/'.join(self._workspace_paths['local'].split(os.sep)),
                        ''))
            }
        else:
            self._child_paths['remote'] = self._child_paths['local']
            self._working_dirs['remote'] = self._working_dirs['local']
            self._workspace_paths['remote'] = self._workspace_paths['local']
Esempio n. 2
0
def parse_cli_args():
    """Web App command line arguments."""
    parser = argparse.ArgumentParser()
    parser.add_argument("--static-path", nargs="?", default=None, const=pwd())
    parser.add_argument("--data-path", nargs="?", default=None, const=pwd())
    parser.add_argument("--report-name", nargs="?", default=None, const=pwd())
    return parser.parse_args()
Esempio n. 3
0
    def _define_remote_dirs(self):
        """Define mandatory directories in remote host."""

        self._remote_plan_runpath = self.cfg.remote_runpath or (
            f"/var/tmp/{getpass.getuser()}/testplan/{self._get_plan().cfg.name}"
            if IS_WIN else self._get_plan().runpath)
        self._workspace_paths.local = fix_home_prefix(
            os.path.abspath(self.cfg.workspace))
        self._workspace_paths.remote = "/".join(
            [self._remote_plan_runpath, "fetched_workspace"])
        self._testplan_import_path.remote = "/".join(
            [self._remote_plan_runpath, "testplan_lib"])
        self._remote_runid_file = os.path.join(self._remote_plan_runpath,
                                               self._get_plan().runid_filename)

        self._remote_resource_runpath = rebase_path(
            self.runpath,
            self._get_plan().runpath,
            self._remote_plan_runpath,
        )
        self.logger.debug("Remote runpath = %s", self._remote_resource_runpath)
        self._working_dirs.local = pwd()
        self._working_dirs.remote = self._remote_working_dir()
        self.logger.debug("Remote working path = %s",
                          self._working_dirs.remote)
Esempio n. 4
0
    def _prepare_remote(self):
        """Transfer local data to remote host."""
        self._child_paths.local = self._child_path()
        self._workspace_paths.local = fix_home_prefix(self.cfg.workspace)

        if self.cfg.copy_workspace_check:
            cmd = self.cfg.copy_workspace_check(self.cfg.ssh_cmd,
                                                self.cfg.index,
                                                self._workspace_paths.local)
            self._should_transfer_workspace = self._execute_cmd(
                cmd, label='copy workspace check', check=False) != 0

        self._define_remote_dirs()
        self._create_remote_dirs()
        self._copy_child_script()
        self._copy_dependencies_module()
        self._copy_workspace()

        self._working_dirs.local = pwd()
        self._working_dirs.remote = self._remote_working_dir
        self.logger.debug('Remote working path = %s',
                          self._working_dirs.remote)

        self._push_files()
        self.setup_metadata.setup_script = self.cfg.setup_script
        self.setup_metadata.env = self.cfg.env
        self.setup_metadata.workspace_paths = self._workspace_paths
Esempio n. 5
0
 def get_options(cls):
     """
     Schema for options validation and assignment of default values.
     """
     hostname = socket.gethostbyname(socket.gethostname())
     return {
         'hosts':
         dict,
         ConfigOption('abort_signals',
                      default=[signal.SIGINT, signal.SIGTERM]): [int],
         ConfigOption('worker_type', default=RemoteWorker):
         object,
         ConfigOption('pool_type', default='thread'):
         str,
         ConfigOption('host', default=hostname):
         str,
         ConfigOption('port', default=0):
         int,
         ConfigOption('copy_cmd', default=copy_cmd):
         lambda x: callable(x),
         ConfigOption('link_cmd', default=link_cmd):
         lambda x: callable(x),
         ConfigOption('ssh_cmd', default=ssh_cmd):
         lambda x: callable(x),
         ConfigOption('workspace', default=pwd()):
         str,
         ConfigOption('workspace_exclude', default=[]):
         Or(list, None),
         ConfigOption('remote_workspace', default=None):
         Or(str, None),
         ConfigOption('copy_workspace_check',
                      default=remote_filepath_exists):
         Or(lambda x: callable(x), None),
         ConfigOption('env', default=None):
         Or(dict, None),
         ConfigOption('setup_script', default=None):
         Or(list, None),
         ConfigOption('push', default=[]):
         Or(list, None),
         ConfigOption('push_exclude', default=[]):
         Or(list, None),
         ConfigOption('push_relative_dir', default=None):
         Or(str, None),
         ConfigOption('delete_pushed', default=False):
         bool,
         ConfigOption('pull', default=[]):
         Or(list, None),
         ConfigOption('pull_exclude', default=[]):
         Or(list, None),
         ConfigOption('remote_mkdir', default=['/bin/mkdir', '-p']):
         list,
         ConfigOption('testplan_path', default=None):
         Or(str, None),
         ConfigOption('worker_heartbeat', default=30):
         Or(int, float, None)
     }
Esempio n. 6
0
    def _get_reload_dirs(self, extra_deps=None):
        reload_dirs = []
        if _has_file(sys.modules['__main__']):
            main_module_file = self._module_filepath(
                sys.modules['__main__'].__file__)
            reload_dir = os.path.realpath(os.path.dirname(main_module_file))
        else:
            reload_dir = os.path.realpath(pwd())
        reload_dirs.append(fix_home_prefix(reload_dir))

        # Add extra reload source directories.
        for mod in extra_deps:
            module_file = self._module_filepath(mod.__file__)
            reload_dir = os.path.realpath(os.path.dirname(module_file))
            reload_dirs.append(fix_home_prefix(reload_dir))
        return reload_dirs
Esempio n. 7
0
    def _prepare_remote(self):
        """Transfer local data to remote host."""

        self._define_remote_dirs()
        self._create_remote_dirs()
        self._copy_workspace()
        self._copy_testplan_package()
        self._copy_dependencies_module()
        self._set_child_script()

        self._working_dirs.local = pwd()
        self._working_dirs.remote = self._remote_working_dir
        self.logger.debug('Remote working path = %s',
                          self._working_dirs.remote)

        self._push_files()
        self.setup_metadata.setup_script = self.cfg.setup_script
        self.setup_metadata.env = self.cfg.env
        self.setup_metadata.workspace_paths = self._workspace_paths
Esempio n. 8
0
 def get_options(cls):
     """
     Schema for options validation and assignment of default values.
     """
     return {
         ConfigOption("ssh_cmd", default=ssh_cmd): lambda x: callable(x),
         ConfigOption("copy_cmd", default=copy_cmd): lambda x: callable(x),
         ConfigOption("workspace", default=pwd()): str,
         ConfigOption("workspace_exclude", default=[]): Or(list, None),
         ConfigOption("remote_runpath", default=None): str,
         ConfigOption("testplan_path", default=None): str,
         ConfigOption("remote_workspace", default=None): str,
         ConfigOption("clean_remote", default=False): bool,
         ConfigOption("push", default=[]): Or(list, None),
         ConfigOption("push_exclude", default=[]): Or(list, None),
         ConfigOption("delete_pushed", default=False): bool,
         ConfigOption("fetch_runpath", default=True): bool,
         ConfigOption("fetch_runpath_exclude", default=None): list,
         ConfigOption("pull", default=[]): Or(list, None),
         ConfigOption("pull_exclude", default=[]): Or(list, None),
         ConfigOption("env", default=None): Or(dict, None),
         ConfigOption("setup_script", default=None): Or(list, None),
     }
Esempio n. 9
0
        if self.server:
            return self.server.ready
        return False

    def stop(self):
        self.server.stop()
        self.server = None


if __name__ == "__main__":
    args = parse_cli_args()

    if args.static_path:
        app.config["STATIC_PATH"] = args.static_path
    else:
        app.config["STATIC_PATH"] = pwd()
    app.static_folder = os.path.abspath(
        os.path.join(app.config["STATIC_PATH"], "testing", "build", "static"))
    if args.data_path:
        app.config["DATA_PATH"] = args.data_path
    else:
        # In future if not looking up data from the local file system
        # we will be looking it up from a database.
        app.config["DATA_PATH"] = pwd()
    if args.report_name:
        app.config["TESTPLAN_REPORT_NAME"] = args.report_name
    else:
        app.config["TESTPLAN_REPORT_NAME"] = "report.json"

    print("Running Testplan web app on 0.0.0.0...")
    app.run(host="0.0.0.0", port=0)
Esempio n. 10
0
    with open(path, "w") as fobj:
        fobj.write(content)
    return path


# Using a custom parser to support `--tasks-num` and `--pool-size` command
# line arguments so that users can experiment with remote pool test execution.

# Hard-coding `pdf_path`, 'stdout_style' and 'pdf_style' so that the
# downloadable example gives meaningful and presentable output.
# NOTE: this programmatic arguments passing approach will cause Testplan
# to ignore any command line arguments related to that functionality.
@test_plan(
    name="RemotePoolExecution",
    parser=CustomParser,
    pdf_path=os.path.join(pwd(), "report.pdf"),
    stdout_style=OUTPUT_STYLE,
    pdf_style=OUTPUT_STYLE,
)
def main(plan):
    """
    Testplan decorated main function to add and execute MultiTests.

    :return: Testplan result object.
    :rtype:  ``testplan.base.TestplanResult``
    """

    workspace = os.path.dirname(__file__)

    # Create two temporary files locally. For demonstration, just write the
    # filename as the content of each.
Esempio n. 11
0
def make_file(filename, dirname, content):
    path = os.path.join(dirname, filename)
    with open(path, 'w') as fobj:
        fobj.write(content)
    return path

# Using a custom parser to support `--tasks-num` and `--pool-size` command
# line arguments so that users can experiment with remote pool test execution.

# Hard-coding `pdf_path`, 'stdout_style' and 'pdf_style' so that the
# downloadable example gives meaningful and presentable output.
# NOTE: this programmatic arguments passing approach will cause Testplan
# to ignore any command line arguments related to that functionality.
@test_plan(name='RemotePoolExecution',
           parser=CustomParser,
           pdf_path=os.path.join(pwd(), 'report.pdf'),
           stdout_style=OUTPUT_STYLE,
           pdf_style=OUTPUT_STYLE)
def main(plan):
    """
    Testplan decorated main function to add and execute MultiTests.

    :return: Testplan result object.
    :rtype:  ``testplan.base.TestplanResult``
    """
    import testplan
    workspace = os.path.abspath(
        os.path.join(
            os.path.dirname(module_abspath(testplan)),
            '..', '..'))
Esempio n. 12
0
    def ready(self):
        if self.server:
            return self.server.ready
        return False

    def stop(self):
        self.server.stop()


if __name__ == '__main__':
    args = parse_cli_args()

    if args.static_path:
        app.config['STATIC_PATH'] = args.static_path
    else:
        app.config['STATIC_PATH'] = pwd()
    app.static_folder = os.path.abspath(
        os.path.join(app.config['STATIC_PATH'], 'testing', 'build', 'static'))
    if args.data_path:
        app.config['DATA_PATH'] = args.data_path
    else:
        # In future if not looking up data from the local file system
        # we will be looking it up from a database.
        app.config['DATA_PATH'] = pwd()
    if args.report_name:
        app.config['TESTPLAN_REPORT_NAME'] = args.report_name
    else:
        app.config['TESTPLAN_REPORT_NAME'] = 'report.json'

    print('Running Testplan web app on 0.0.0.0...')
    app.run(host='0.0.0.0', port=0)
Esempio n. 13
0
def parse_cli_args():
    """Web App command line arguments."""
    parser = argparse.ArgumentParser()
    parser.add_argument('--static-path', nargs='?', default=None, const=pwd())
    parser.add_argument('--data-path', nargs='?', default=None, const=pwd())
    return parser.parse_args()