plainbox.impl.session.state – session state handling

class plainbox.impl.session.state.SessionMetaData(title=None, flags=None, running_job_name=None, app_blob=None)[source]

Class representing non-critical state of the session.

The data held here allows applications to reason about sessions in general but is not relevant to the runner or the core in general

FLAG_INCOMPLETE = 'incomplete'
FLAG_SUBMITTED = 'submitted'
app_blob[source]

Custom, application specific binary blob.

The type and value of this property is irrelevant as it is not inspected by plainbox at all. Reasonable applications will not make use of this property for storing large amounts of data. If you are tempted to do that, please redesign your application or propose changes to plainbox.

flags[source]

a set of flags that are associated with this session.

This set is persisted by persistent_save() and can be used to keep track of how the application wants to interpret this session state.

Intended usage is to keep track of “testing finished” and “results submitted” flags. Some flags are added as constants to this class.

running_job_name[source]

name of the running job

This property should be updated to keep track of the name of the job that is being executed. When either plainbox or the machine it was running on crashes during the execution of a job this value should be preserved and can help the GUI to resume and provide an error message.

The property MUST be set before starting the job itself.

title[source]

the session title.

Title is just an arbitrary string that can be used to distinguish between multiple sessions.

The value can be changed at any time.

class plainbox.impl.session.state.SessionState(job_list)[source]

Class representing all state needed during a single program session.

This is the central glue/entry-point for applications. It connects user intents to the rest of the system / plumbing and keeps all of the state in one place.

The set of utility methods and properties allow applications to easily handle the lower levels of dependencies, resources and ready states.

SessionState has the following instance variables, all of which are currently exposed as properties.

Variables:
  • job_list (list) –

    A list of all known jobs

    Not all the jobs from this list are going to be executed (or selected for execution) by the user.

    It may change at runtime because of local jobs. Note that in upcoming changes this will start out empty and will be changeable dynamically. It can still change due to local jobs but there is no API yes.

    This list cannot have any duplicates, if that is the case a DependencyDuplicateError is raised. This has to be handled externally and is a sign that the job database is corrupted or has wrong data. As an exception if duplicates are perfectly identical this error is silently corrected.

  • job_state_map (dict) –

    mapping that tracks the state of each job

    Mapping from job name to JobState. This basically has the test result and the inhibitor of each job. It also serves as a plainbox.impl.job.JobDefinition.name-> job lookup helper.

    Directly exposed with the intent to fuel part of the UI. This is a way to get at the readiness state, result and readiness inhibitors, if any.

    XXX: this can loose data job_list has jobs with the same name. It would be better to use job id as the keys here. A separate map could be used for the name->job lookup. This will be fixed when session controller branch lands in trunk as then jobs are dynamically added to the system one at a time and proper error conditions can be detected and reported.

  • desired_job_list (list) –

    subset of jobs selected for execution

    This is used to compute run_list. It can only be changed by calling update_desired_job_list() which returns meaningful values so this is not a settable property.

  • run_list (list) –

    sorted list of jobs to execute

    This is basically a superset of desired_job_list and a subset of job_list that is topologically sorted to allowing all desired jobs to run. This property is updated whenever desired_job_list is changed.

  • resource_map (dict) –

    all known resources

    A mapping from resource name to a list of plainbox.impl.resource.Resource objects. This encapsulates all “knowledge” about the system plainbox is running on.

    It is needed to compute job readiness (as it stores resource data needed by resource programs). It is also available to exporters.

    This is computed internally from the output of checkbox resource jobs, it can only be changed by calling update_job_result()

  • metadata (dict) – instance of SessionMetaData
add_job(new_job, recompute=True)[source]

Add a new job to the session

Parameters:
  • new_job – The job being added
  • recompute – If True, recompute readiness inhibitors for all jobs. You should only set this to False if you’re adding a number of jobs and will otherwise ensure that _recompute_job_readiness() gets called before session state users can see the state again.
Returns:

The job that was actually added or an existing, identical job if a perfect clash was silently ignored.

Raises DependencyDuplicateError:
 

if a duplicate, clashing job definition is detected

The new_job gets added to all the state tracking objects of the session. The job is initially not selected to run (it is not in the desired_job_list and has the undesired inhibitor).

The new_job may clash with an existing job with the same name. Unless both jobs are identical this will cause DependencyDuplicateError to be raised. Identical jobs are silently discarded.

Note

This method recomputes job readiness for all jobs

desired_job_list[source]

List of jobs that are on the “desired to run” list

This is a list, not a set, because the dependency solver algorithm retains as much of the original ordering as possible. Having said that, the actual order can differ widely (for instance, be reversed)

get_estimated_duration(manual_overhead=30.0)[source]

Provide the estimated duration of the jobs that have been selected to run in this session (maintained by calling update_desired_job_list).

Manual jobs have an arbitrary figure added to their runtime to allow for execution of the test steps and verification of the result.

Returns:(estimate_automated, estimate_manual)

where estimate_automated is the value for automated jobs only and estimate_manual is the value for manual jobs only. These can be easily combined. Either value can be None if the value could not be calculated due to any job lacking the required estimated_duration field.

job_list[source]

List of all known jobs.

Not necessarily all jobs from this list can be, or are desired to run. For API simplicity this variable is read-only, if you wish to alter the list of all jobs re-instantiate this class please.

job_state_map[source]

Map from job name to JobState that encodes the state of each job.

metadata[source]

metadata object associated with this session state.

on_job_added[source]

Signal sent whenever a job is added to the session.

This signal is fired after on_job_state_map_changed()

on_job_removed[source]

Signal sent whenever a job is removed from the session.

This signal is fired after on_job_state_map_changed()

on_job_result_changed[source]

Signal fired after a job get changed (set)

This signal is fired each time a result is presented to the session.

This signal is fired after on_job_state_map_changed()

on_job_state_map_changed[source]

Signal fired after job_state_map is changed in any way.

This signal is always fired before any more specialized signals such as on_job_result_changed() and on_job_added().

This signal is fired pretty often, each time a job result is presented to the session and each time a job is added. When both of those events happen at the same time only one notification is sent. The actual state is not sent as it is quite extensive and can be easily looked at by the application.

resource_map[source]

Map from resource name to a list of resource records

run_list[source]

List of jobs that were intended to run, in the proper order

The order is a result of topological sorting of the desired_job_list. This value is recomputed when change_desired_run_list() is called. It may be shorter than desired_run_list due to dependency errors.

set_resource_list(resource_name, resource_list)[source]

Add or change a resource with the given name.

Resources silently overwrite any old resources with the same name.

trim_job_list(qualifier)[source]

Discard jobs that are selected by the given qualifier.

Parameters:qualifier – A qualifier that selects jobs to be removed
Ptype qualifier:
 IJobQualifier
Raises ValueError:
 If any of the jobs selected by the qualifier is on the desired job list (or the run list)

This function correctly and safely discards certain jobs from the job list. It also removes the associated job state (and referenced job result) and results (for jobs that were resource jobs)

update_desired_job_list(desired_job_list)[source]

Update the set of desired jobs (that ought to run)

This method can be used by the UI to recompute the dependency graph. The argument ‘desired_job_list’ is a list of jobs that should run. Those jobs must be a sub-collection of the job_list argument that was passed to the constructor.

It never fails although it may reduce the actual permitted desired_job_list to an empty list. It returns a list of problems (all instances of DependencyError class), one for each job that had to be removed.

update_job_result(job, result)[source]

Notice the specified test result and update readiness state.

This function updates the internal result collection with the data from the specified test result. Results can safely override older results. Results also change the ready map (jobs that can run) because of dependency relations.

Some results have deeper meaning, those are results for local and resource jobs. They are discussed in detail below:

Resource jobs produce resource records which are used as data to run requirement expressions against. Each time a result for a resource job is presented to the session it will be parsed as a collection of RFC822 records. A new entry is created in the resource map (entirely replacing any old entries), with a list of the resources that were parsed from the IO log.

Local jobs produce more jobs. Like with resource jobs, their IO log is parsed and interpreted as additional jobs. Unlike in resource jobs local jobs don’t replace anything. They cannot replace an existing job with the same name.

Previous topic

plainbox.impl.session.resume – session resume handling

Next topic

plainbox.impl.session.storage – storage for sessions

This Page