buildtest.buildsystem.base

BuilderBase class is an abstract class that defines common functions for any types of builders. Each type schema (script, compiler) is implemented as separate Builder.

ScriptBuilder class implements ‘type: script’ CompilerBuilder class implements ‘type: compiler’

Module Contents

Classes

BuilderBase

The BuilderBase is an abstract class that implements common functions for

class buildtest.buildsystem.base.BuilderBase(name, recipe, buildspec, executor, buildexecutor, testdir)

Bases: abc.ABC

The BuilderBase is an abstract class that implements common functions for any kind of builder.

__repr__(self)

Return repr(self).

__str__(self)

Return str(self).

_build_setup(self)

This method is the setup operation to get ready to build test which includes getting unique build id, setting up metadata object to store test details such as where test will be located and directory of test. This section cannot be reached without a valid, loaded recipe.

_check_regex(self)

This method conducts a regular expression check using re.search with regular expression defined in Buildspec. User must specify an output stream (stdout, stderr) to select when performing regex. In buildtest, this would read the .out or .err file based on stream and run the regular expression to see if there is a match. This method will return a boolean True indicates there is a match otherwise False if regex object not defined or re.search doesn’t find a match.

Parameters

builder (BuilderBase (subclass)) – instance of BuilderBase class

Returns

A boolean return True/False based on if re.search is successful or not

Return type

bool

_check_runtime(self)

This method will return a boolean (True/False) based on runtime specified in buildspec and check with test runtime. User can specify both min and max, or just specify min or max.

_default_test_variables(self)

Return a list of lines inserted in testscript that define buildtest specific variables that can be referenced when writing tests. The buildtest variables all start with BUILDTEST_*

_emit_command(self)

This method will return a shell command used to invoke the script that is used for tests that use local executors

_generate_unique_id(self)

Generate a unique build id using uuid.uuid4().

_get_burst_buffer(self, burstbuffer)

Get Burst Buffer directives (#BB) lines specified by BB property

Parameters

burstbuffer (dict, required) – Burst Buffer configuration specified by BB property

Returns

list of burst buffer directives

Return type

list

_get_data_warp(self, datawarp)

Get Cray Data Warp directives (#DW) lines specified by DW property.

Parameters

datawarp (dict, required) – Data Warp configuration specified by DW property

Returns

list of data warp directives

Return type

list

_get_environment(self, env)

Retrieve a list of environment variables defined in buildspec and return them as list with the shell equivalent command

Returns

list of environment variable lines to add to test script.

Return type

list

_get_scheduler_directives(self, bsub=None, sbatch=None, cobalt=None, pbs=None, batch=None)

Get Scheduler Directives for LSF, Slurm, PBS or Cobalt if we are processing test with one of the executor types. This method will return a list of string containing scheduler directives generally found at top of script. If test is local executor we return an empty list

Parameters
  • bsub – bsub property from buildspec

  • sbatch – sbatch property from buildspec

  • cobalt – cobalt property from buildspec

  • pbs – pbs property from buildspec

  • batch – batch property from buildspec

_get_variables(self, variables)

Retrieve a list of variables defined in buildspec and return them as list with the shell equivalent command.

Returns

list of variables variable lines to add to test script.

Return type

list

_returncode_check(self)

Check status check of returncode field if specified in status property.

_set_execute_perm(self, fname)

Set permission to 755 for a given file. The filepath must be an absolute path to file

_set_metadata_values(self)

This method sets self.metadata that contains metadata for each builder object.

_write_build_script(self)

This method will write the build script used for running the test

_write_test(self)

This method is responsible for invoking generate_script that formulates content of testscript which is implemented in each subclass. Next we write content to file and apply 755 permission on script so it has executable permission.

add_metrics(self)

This method will update the metrics field stored in self.metadata['metrics']. The metrics property can be defined in the buildspdec to assign value to a metrics name based on regular expression, environment or variable assignment.

build(self)

This method is responsible for invoking setup, creating test directory and writing test. This method is called from an instance object of this class that does builder.build().

check_test_state(self)

This method is responsible for detecting state of test (PASS/FAIL) based on returncode or regular expression.

complete(self)

This method is invoked to indicate that builder job is complete after polling job.

copy_stage_files(self)

Copy output and error file into test root directory since stage directory will be removed.

endtime(self)

This method is called upon termination of job, we get current time using datetime.datetime.now() and calculate runtime of job

error(self)

Return error content

abstract generate_script(self)

Build the testscript content implemented in each subclass

get_runtime(self)
get_test_extension(self)

Return the test extension, which depends on the shell used. Based on the value of shell key we return the shell extension.

shell: bash –> sh (default)

Returns

returns test extension based on shell type

Return type

str

incomplete(self)

This method indicates that builder job is not complete after polling job either job was cancelled by scheduler or job failed to run.

output(self)

Return output content

post_run_steps(self)
run(self)

Run the test and record the starttime and start timer. We also return the instance object of type BuildTestCommand which is used by Executors for processing output and error

run_command(self)

Command used to run the build script. buildtest will change into the stage directory (self.stage_dir) before running the test.

runtime(self)

Calculate runtime of job by calculating delta between endtime and starttime. The unit of measure is seconds.

start(self)

Keep internal time for start of test. We start timer by calling Timer class

starttime(self)

This method will record the starttime when job starts execution by using datetime.datetime.now()

stop(self)

Stop timer of test and calculate duration.