Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The examples in the tutorial show how to build up a suite definition using the python api.

However the suite definition describes the static structure, it not until it is loaded in the server, that we see its dynamic behaviour.

The python api allows the simulation of the dynamic behaviour of the suite, (in the same manner as the server).

python API allows simulation. Simulation has the following benefits:

  • Exercise the suite definition. There is no need for '.ecf' files
  • Allows for very easy experimentation.
  • Can be done on the client side, no need for server
  • Can help in detecting deadlock's
  • Will simulate with both 'real' and 'hybrid' clocks
  • A year's simulation can be done in a few minutes. Small definitions can be simulated in a few secondsseconds

The simulation relies on you adding simple verification attributes. (This is similar to c/c++/python asserts)

There are however restrictions. If the definition has large loops due to Repeat date attributes, which run indefinitely, then in this case the simulation will never complete, and will timeout after a years worth of run time.

(This can be compensated for by adding start and end clock)Hence it's best to restrict simulation, to definitions which are known to complete.. Here is an example a text suite definition that use a verify attribute.

Code Block
languagebash
titlecron.def
suite year            # use real clock otherwise the date wont change
 clock real 1.1.2017  # define a start date for deterministic simulation
 endclock   1.1.2018  # When to finish. 
 family cronFamily
  task t
   cron -d 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 -m 1,2,3,4,5,6,7,8,9,10,11,12 10:00 # run every day for a year
   verify complete:365 # assert that this task completes 365 times
 endfamily
endsuite

suite leap_year       # use real clock otherwise the date wont change
 clock real 1.1.2016  # define a start date for deterministic simulation 
 endclock   1.1.2017  # When to finish. 
 family cronFamily
  task t
   cron -d 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 -m 1,2,3,4,5,6,7,8,9,10,11,12 10:00  # run every day for a year
   verify complete:366 # # assert that this task completes 366 times in a leap year
 endfamily
endsuite

This python segment show how to load a text based suite definition(cron.def) and simulate it in python.

Code Block
import ecflow
defs = Defs("cron,def")
result = defs.simulate()    
assert len(result) == 0,  "Expected simulation to return without any errors, but found:\n" + result


If the simulation does not complete it will produce two files, which will help in the analysis:

...

This simulation is expected to fail, since we have a deadlock/ race condition


Code Block

...

suite dead_lock
  family family
    task t1
      trigger t2 =

...

= complete
    task t2
      trigger t1 == complete
  endfamily
endsuite



Code Block
languagepy
titlesiumuate a deadlock. Create definition in python
import ecflow
defs = ecflow.Defs().add(
	     Suite("dead_lock")

...

.add(
            Family("family")

...

.add(
               Task("t1").add

...

( Trigger(

...

t2 == complete

...

))

...

,
               Task("t2").add

...

( Trigger(

...

t1 == complete

...

)))))

theResult = defs.simulate(); # simulate the definition
assert len(theResult) != 0, "Expected simulation to return errors" 
print theResult

...