Edgewall Software

Version 1 (modified by Cinc-th, 4 years ago) ( diff )

How to use Trac for requirements management.

Requirements Management

Every once in a while there is a question about doing requirements management with Trac. For quite some time there is a th:Request-a-Hack for a plugin implementing it, see th:#1226. While having an out of the box solution would be nice there are quite a few plugins which can be leveraged for building a requirements management solution.

On this page one possible approach is shown for doing so. I'm working in development of IEC 61508 compliant control devices. We use Trac for doing all the requirements tracking mandated by the aforementioned standard. For a mid-sized project we currently track something like 4000-6000 requirements and testcases.

Be aware that the solution presented here may or may not work for you. We use quite some custom made plugins to support our internal processes wrt requirements tracking. These plugins are private and you may have to create your own to scratch your own itch.

Before you start

Don't select a tool because it's fancy and then model your requirements management process so it can be supported by the tool. This will fail in the end.

Make sure you know your process and environment, e.g.

  • Which types of requirements do you have? System requirements, functional requirements, test cases, … ?
  • Who is writing them? The tech people or maybe management people? You will learn that it may be impossible to drag your mangement people away from MS Word and friends. So you may need a Word document importer.
  • Is there a predefined workflow for requirements, e.g. draft→in review→approved→closed?
  • Is the workflow dependent on the type of requirement?
  • How do you manage changes to requirements?
  • What about roles and permissions in the process?
  • Do you need some kind of sign off?
  • It may be necessary to import data from other tools or departments. For example the test department may be using their own tool chain and even their own bug tracker.

After reviewing your process requirements you should evaluate if Trac with the appropriate plugins is a viable solution. Don't do that by counting bullet points but by actually using it for a project. The beauty of Trac is that by adding the right plugin or writing a new one more or less every need may be fulfilled and in the end your solution exactly matches your process requirements.

Requirements management using Trac

The following sections describe a bare bones implementation for requirements tracking using some available plugins.

Environment type

Each project lives in a separate environment with its own SQLite database. This way you may not accidentally alter data not belonging to your current project because of a misconfiguration (e.g. broken permissions) or bug in one of your plugins. It makes access control easier which may be important.

After the project is done one may revoke all write permissions and archive the complete environment so the current state of requirements is frozen.

Requirement types

To distinguish requirements and test cases at least two new ticket types must be created:

  • requirement
  • testcase

In our department we only track requirements in the environment so all other ticket types are removed. If you want to use your requirements Trac also for issue tracking keep the standard ticket types. There is no need to create special types for each level of a 'V model' but nobody stops you from doing so.

For administrating ticket types go to the admin area of your Trac installation or use the command line interface.

trac-admin /path/to/projenv ticket_type add requirement

trac-admin /path/to/projenv ticket_type add testcase

TracAdmin describes the command line interface in full length.

Defining roles

It may be necessary to define additional permissions to have more control of the requirements workflow. For example there may be a distinct group for requirements review and approval while the QA department is responsible for closing requirements.

To define the additional permissions

  • REQUIREMENT_APPROVE
  • REQUIREMENT_CLOSE

add the following to your trac.ini:

[components]
tracopt.perm.config_perm_provider.ExtraPermissionsProvider = enabled

[extra-permissions]
REQUIREMENT_ADMIN = REQUIREMENT_APPROVE, REQUIREMENT_CLOSE

Note that this also defines the permission REQUIREMENT_ADMIN which grants REQUIREMENT_APPROVE and REQUIREMENT_CLOSE.

For more information see ExtraPermissionsProvider.

Creating specialized workflows

A workflow for a requirement is very different from a standard issue workflow. Using th:MultipleWorkflowPlugin (disclaimer: I'm the maintainer) specific workflows for each new type may be created.

Add this to your trac.ini:

[components]
# Enable MultipleWorkflowPlugin
multipleworkflow.* = enabled

[ticket-workflow-requirement]
# Create special workflow for tickets with type 'requirement'
# Note that special permissions are used here
leave = * -> *
leave.default = 1
leave.operations = leave_status

approve = new, reopened -> approved
approve.operations = del_resolution
approve.permissions = REQUIREMENT_APPROVE

reopen_verified = closed -> reopened
reopen_verified.name = Reopen
reopen_verified.operations = set_resolution
reopen_verified.set_resolution = from verified
reopen_verified.permissions = TICKET_MODIFY

reopen_approved = approved -> reopened
reopen_approved.name = Reopen
reopen_approved.operations = set_resolution
reopen_approved.set_resolution = from approved
reopen_approved.permissions = TICKET_CREATE

remove = new, reopened, approved, closed -> removed
remove.name = Remove this Requirement permanently
remove.operations = set_resolution
remove.set_resolution = removed
remove.permissions = TICKET_MODIFY

verify = approved -> closed
verify.name = Verifiy the Requirement and mark
verify.operations = set_resolution
verify.set_resolution = verified
verify.permissions = REQUIREMENT_CLOSE

[ticket-workflow-testcase]
leave = * -> *
leave.default = 1
leave.operations = leave_status
...

In this workflow special permissions as defined in section Defining roles are used to control access. You may leverage the full power of TracWorkflows here, for example assigning new owners on state change.

Using some validation plugin correct values in required ticket fields can be enforced. Have a look at

You have to adapt the given workflow to your own process but you get the idea.

Parent - child relationship

There must be some kind of parent - child relationship between tickets so one may follow the chain of requirements in forward and backwards direction. The following plugins are suitable:

For requirements tickets th:ChildTicketsPlugin adds buttons to the ticket page to create a child ticket of type requirement or testcase. Any child tickets are directly shown on the ticket page.

See th:ChildTicketsPlugin/Examples for some screenshots of the plugin in action.

Add the following to your trac.ini to use th:ChildTicketsPlugin:

[childtickets]
# Allow child tickets for tickets of type 'requirement'
parent.requirement.allow_child_tickets = true
# Restrict child ticket types
parent.requirement.restrict_child_type = requirement, testcase
# Define the table headers to be shown for child tickets
parent.requirement.table_headers = summary, type, status, component, description
# No child tickets for ticket type 'testcase'
parent.testcase.allow_child_tickets = false

[components]
# Enable ChildTicketsPlugin
childtickets.* = enabled
childtickets.childtickets.tracchildticketsmodule = enabled

[ticket-custom]
# Define ticket custom field for use with ChildTicketsPlugin
parent = text
parent.format = wiki
parent.label = Parent ID

With the given settings only tickets with type requirement or testcase are allowed as children of requirements tickets. Testcase tickets can't have any children. If you use your environment also for issue tracking it may be necessary to change the configuration to allow other ticket types like defect or task tickets.

See the th:ChildTicketsPlugin page for more configuration options.

There is a macro th:ChildTicketTreeMacro to show a ticket hierarchy everywhere wiki content is allowed. This may be useful for reporting purposes.

Requirements grouping

Grouping may be achieved by specifying different requirement types. Each level of the V model is mapped to a different ticket type. This is probably not practical enough because you may have several thousand requirements for a single level.

Additional grouping may be done using the component field of a ticket or a custom ticket field. In our environment this is done using the custom field docid because every requirement starts life in an external document with a unique document id which is imported into Trac after approval.

For this add the following to your trac.ini:

[ticket-custom]
# Define field for grouping of requirements
docid = text
docid.format = text
docid.label = Document ID

By grouping it's possible to find requirements belonging to some part of your product/project. For example in hardware development you may group all requirements pertaining to the power supply by one id thus making it easy for the power supply people to check for fullfillment.

Cleaning up the ticket page

Depending on your audience the ticket page may be overwhelming because of all the fields. But there are quite a few plugins to hide unneeded ticket fields or prevent changes.

th:CondFieldsGenshiPlugin is one of them and is used here to disallow changing of the ticket type field. It's unlikely a requirement morphs into a testcase so preventing any accidental damage is a good idea.

[components]
condfieldsgenshi.* = enabled

[condfieldsgenshi]
# We only tweak the 'type' filed atm
tweaks = type
default = enable

# Disable ticket type field
type.type_cond = requirement, testcase

Hide any other ticket fields you don't want your users to see or change.

Possible improvements

As written before this presents a basic solution which may already work for you. You possibly want in addition:

Summary

Install the following plugins:

Add the following settings to your trac.ini:

[childtickets]
# Allow child tickets for tickets of type 'requirement'
parent.requirement.allow_child_tickets = true
# Restrict child ticket types
parent.requirement.restrict_child_type = requirement, testcase
# Define the table headers to be shown for child tickets
parent.requirement.table_headers = summary, type, status, component, description
# No child tickets for ticket type 'testcase'
parent.testcase.allow_child_tickets = false

[components]
# Enable ChildTicketsPlugin
childtickets.* = enabled
childtickets.childtickets.tracchildticketsmodule = enabled
# Enable CondFieldsGenshiPlugin
condfieldsgenshi.* = enabled
# Enable MultipleWorkflowPlugin
multipleworkflow.* = enabled
# Remove this if you need no special permissions
tracopt.perm.config_perm_provider.ExtraPermissionsProvider = enabled

[condfieldsgenshi]
# We only tweak the 'type' filed atm
tweaks = type
default = enable
# Disable ticket type field
type.type_cond = requirement, testcase

# Remove this section if you need no special permissions
[extra-permissions]
REQUIREMENT_ADMIN = REQUIREMENT_APPROVE, REQUIREMENT_CLOSE

[ticket]
# Use MultipleWorkflowPlugin for ticket workflows
workflow = MultipleWorkflowPlugin

[ticket-custom]
# Define ticket custom field for use with ChildTicketsPlugin
parent = text
parent.format = wiki
parent.label = Parent ID
# Define field for grouping of requirements
docid = text
docid.format = text
docid.label = Document ID

[ticket-workflow-requirement]
# Create special workflow for tickets with type 'requirement'
# Note that special permissions are used here
leave = * -> *
leave.default = 1
leave.operations = leave_status

approve = new, reopened -> approved
approve.operations = del_resolution
approve.permissions = REQUIREMENT_APPROVE

reopen_verified = closed -> reopened
reopen_verified.name = Reopen
reopen_verified.operations = set_resolution
reopen_verified.set_resolution = from verified
reopen_verified.permissions = TICKET_MODIFY

reopen_approved = approved -> reopened
reopen_approved.name = Reopen
reopen_approved.operations = set_resolution
reopen_approved.set_resolution = from approved
reopen_approved.permissions = TICKET_CREATE

remove = new, reopened, approved, closed -> removed
remove.name = Remove this Requirement permanently
remove.operations = set_resolution
remove.set_resolution = removed
remove.permissions = TICKET_MODIFY

verify = approved -> closed
verify.name = Verifiy the Requirement and mark
verify.operations = set_resolution
verify.set_resolution = verified
verify.permissions = REQUIREMENT_CLOSE

# Create your testcase workflow here
[ticket-workflow-testcase]
leave = * -> *
leave.default = 1
leave.operations = leave_status
...

On the command line enter the following commands to add ticket types:

trac-admin /path/to/projenv ticket_type add requirement

trac-admin /path/to/projenv ticket_type add testcase
Note: See TracWiki for help on using the wiki.