Factor out common code in test_plan

Change-Id: I26bca9eabc62785cdb0a1bc306ae7a4e072f2474
Merge "Factor out common code in test_plan"