Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0 - Script Writing Class #62

Open
nicholas-sly opened this issue Oct 18, 2018 · 4 comments
Open

2.0 - Script Writing Class #62

nicholas-sly opened this issue Oct 18, 2018 · 4 comments
Assignees
Milestone

Comments

@nicholas-sly
Copy link
Collaborator

This class should provide the mechanisms for generating a script for use in various parts of Pavilion. It will provide the mechanism for writing the scheduler batch scripts (or bash script if running in 'raw' mode), the scripts for building the tests, and the scripts for running the tests. The basic components will include:

  • Generate Header
    • In the case of batch scripts, this will include the scheduler specific commands specifying the allocation specifics.
  • Manipulate modules
    • Either load the necessary modules or swap them in, depending on the OS.
  • Environment - Provide instance-specific environment modifications.
  • Commands - Execute commands as specified by the scheduler or user.
  • Post - Copy results files, log script outputs, clean-up the working space, etc.
  • Script Naming - Section to name the script specific to this Pavilion test run.

Each section should accept a dictionary, list, or string as appropriate.

@nicholas-sly nicholas-sly added this to the 2.0 milestone Oct 18, 2018
@pflarr
Copy link
Collaborator

pflarr commented Oct 24, 2018

I think this is reasonable. I still think you'll want to break out the parts of the scheduler that apply each piece into separate methods though. It may not make sense now, but later when you need to override just the part that designates the header, writes the post cmds, or whatever, you'll be happy it's in small steps.

@nicholas-sly nicholas-sly self-assigned this Oct 24, 2018
@nicholas-sly
Copy link
Collaborator Author

In an effort to keep this class as general as possible, I'm going to leave the scheduler-specifics to whatever calls this class and populates it's fields.

@nicholas-sly
Copy link
Collaborator Author

Implementation concept:

class scriptComposer():
    """Class to compose a bash or batch script for use by Pavilion."""

    def setHeader( ... ):
        """Function to set the header values for the script.
        :param string shell_path: Shell path specification.  Typically '/bin/bash'.  default = None.
        :param dict scheduler_macros: Scheduler macros.  If there are elements that are only one entry, the value will just be None.  default = None.
        """

    def setModules( ... ):
        """Function to set the modules section for the script.
        :param list explicit_specification: List of commands to manage the modules explicitly.  default = None.
        :param bool purge: Whether or not module purge will work on this machine. default = False
        :param list unloads: List of modules to unload for the script.  default = None.
        :param list loads: List of modules to load for the script.  default = None.
        :param dict swaps: Dictionary of modules to swap.  The current module should be the key and the module to replace it with should be the value.  default = None.
        """

    def setEnvironment( ... ):
        """Function to set and unset the environment variables.
        :param dict set_env: Dictionary of environment variables to set where the key is the environment variable and the value is the value assigned to that variable.  default = None
        :param list unset_env: List of environment variables to unset for the script.  default = None
        """

    def setCommands( ... ):
        """Function to specify the commands for the script.
        :param list commands: List of strings specifying the script commands in order.  default = None
        """

    def setPost( ... ):
        """Function to specify the commands to run at the end of the script for generic tasks.
        :param list commands: List of strings specifying the postscript commands in order.  default = None
        """

    def setDetails( ... ):
        """Function to set the final details of the script.
        :param string script_name: Specify a name for the script.  default = 'pav_(date)_(time)'
        :param string script_type: Type of script, determining an appropriate file ending.  default = bash
        :param string user: Name of user to set as owner of the file.  default = current user
        :param string group: Name of group to set as owner of the file.  default = user default group
        :param int owner_perms: Value for owner's permission on the file (see `man chmod`).  default = 7
        :param int group_perms: Value for group's permission on the file (see `man chmod`).  default = 5
        :param int world_perms: Value for the world's permission on the file (see `man chmod`).  default = 0
        """

    def writeScript():
        """Function to write the script out to file.
        :return bool result: Returns either True for successfully writing the file or False otherwise.
        """

Thoughts, @pflarr ?

@pflarr
Copy link
Collaborator

pflarr commented Oct 26, 2018

I'd changes all the those to getter/setter methods.

Then you can just say scriptwriter.post = lines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants