adric.net

RTtestenvScripts
Login

Using the rt cli to script bringing up the testenv

In which we use built-in tools and ruby scripts to bring up the RTtestenv in a sane and repeatable manner

RTDEBUG2 exported as a shell variable (eg export RTDEBUG=3 ) is handy for debugging RT cli tools. That helped me figure out that I should change a 1 to a 0 at 987,66 (line_num, char) in bin/rt (now 993,66 in RT 3.9.4)to disable use of proxy environment variables so that requests for 127.0.0.1 don't go to squid pointlessly. That makes rt cli work. Then we can use a config file:

### .rtrc - Request Tracker 3.8.x rt cli configuration ###
server  http://127.0.0.1:8888
user root
passwd password

##These specify defaults and more than one queue can be given (by adding a query expression)
##queue helpdesk or queue=support
##query Status != resolved and Owner=myaccount

or the RT env vars (both described in bin/rt help usage) and can wrangle RT internals without using WebUI or Perl, as needed.

Output of bin/rt , create -t queue -e:

# Required: Name

id: queue/new
Name: <queue name>
Description:
CorrespondAddress:
CommentAddress:
InitialPriority:
FinalPriority:
DefaultDueIn:
, giving us this working recipe for programatically creating Queues: bin/rt create -t queue set name=NewestQ description="a newer still Q than thee", allowing us to declare:
#!/usr/bin/ruby -w

## Example:
## bin/rt create -t queue set name=NewestQ description="a newer still Q than thee"

test_queues = [
        { :qname => 'External', :qdesc => 'External ticket Queue for Rt testenv' },
        { :qname => 'Helpdesk', :qdesc => 'Helpdesk ticket Queue for Rt testenv' },
        { :qname => 'Oversight', :qdesc => 'Oversight ticket Queue for Rt testenv' },
]

test_queues.each { |tq|
        `bin/rt create -t queue set name=\"#{tq[:qname]}\" description=\"#{tq[:qdesc]}\"`
}

and we should easily be able to do the same for some sample users, groups. bin/rt -t user -e yields:

# Required: Name, EmailAddress

id: user/new
Name:
EmailAddress:
Organization:
Password:
Comments:
and so we can script users:
#!/usr/bin/ruby -w

## Example:
## bin/rt create -t queue set name=NewestQ description="a newer still Q than thee"

maildomain = 'rttestenv.test'

test_users = [
        { :uname => 'Test External', :uemail => "text@#{maildomain}", :uorg => 'RTtestenv', :upass => 'badpassword' },
        { :uname => 'Test Helpdesk', :uemail => "telp@#{maildomain}", :uorg => 'RTtestenv', :upass => 'badpassword' },
        { :uname => 'Test Oversight', :uemail => "tosh@#{maildomain}", :uorg => 'RTtestenv', :upass => 'badpassword' },
        { :uname => 'Test Requestor', :uemail => "tester@#{maildomain}", :uorg => 'RTtestenv', :upass => 'badpassword' },
]

test_users.each { |tu|
        `bin/rt create -t user set name=\"#{tu[:uname]}\" Emailaddress=\"#{tu[:uemail]}\" Organization=\"#{tu[:uorg]}\" Password=\"#{tu[:upass]}\"`

Unfortunately we can't add scrips or templates this way, yet. Another thing worth noting is that we can't specify an id to objects we create this way, so if you care about the object id (sometimes used for sort order or hardcoded in places) be sure to add your objects in order.

--

2 http://www.gossamer-threads.com/lists/rt/users/61505?do=post_view_threaded