Support identifying different tgz files based on run_label attribute

tgz files in trials can be categorized in subdirectories, allowing to
select different bianry files at runtime based on the target run node
which is going to run them. This way for instance one can have a binary
linked against libs for eg. CentOS under run_label "centos/" or an ARM
target under "arm", and then use "run_label: arm" on the resource using
it.

Change-Id: Iaf2e97da3aff693395f44f0e93b184d4846cf6da
diff --git a/selftest/trial_test/run_label/checksums.md5 b/selftest/trial_test/run_label/checksums.md5
new file mode 100644
index 0000000..a162c56
--- /dev/null
+++ b/selftest/trial_test/run_label/checksums.md5
@@ -0,0 +1,2 @@
+b13c9c94d41c45caaa08ad9ad3ee0f11  sample.tar.gz
+430ec62329747b5f15fe6e2cb141b909  foobar/sample.tar.gz
diff --git a/selftest/trial_test/run_label/foobar/sample.tar.gz b/selftest/trial_test/run_label/foobar/sample.tar.gz
new file mode 100644
index 0000000..2c1b029
--- /dev/null
+++ b/selftest/trial_test/run_label/foobar/sample.tar.gz
Binary files differ
diff --git a/selftest/trial_test/run_label/sample.tar.gz b/selftest/trial_test/run_label/sample.tar.gz
new file mode 100644
index 0000000..3932964
--- /dev/null
+++ b/selftest/trial_test/run_label/sample.tar.gz
Binary files differ
diff --git a/selftest/trial_test/trial_test.ok b/selftest/trial_test/trial_test.ok
index 8c6a567..75bd1a7 100644
--- a/selftest/trial_test/trial_test.ok
+++ b/selftest/trial_test/trial_test.ok
@@ -14,3 +14,12 @@
 ok, got RuntimeError: Checksum mismatch for '[PATH]/trial_test/invalid_checksum/file2' vs. '[PATH]/trial_test/invalid_checksum/checksums.md5' line 2
 - detect missing file
 ok, got RuntimeError: File listed in checksums file but missing in trials dir: '[PATH]/trial_test/missing_file/file2' vs. '[PATH]/trial_test/missing_file/checksums.md5' line 2
+- Verify trials based on run_label
+tst run_label: DBG: has bin_tar {bin_name='sample', matches=['sample.tar.gz'], run_label='foobar'}
+inst: [PATH]/trial_test/run_label/inst/foobar/sample
+content file2: subhello
+
+tst run_label: DBG: has bin_tar {bin_name='sample', matches=['sample.tar.gz'], run_label=''}
+inst: [PATH]/trial_test/run_label/inst/sample
+content file1: hello
+
diff --git a/selftest/trial_test/trial_test.ok.ign b/selftest/trial_test/trial_test.ok.ign
index 1a969de..46c3943 100644
--- a/selftest/trial_test/trial_test.ok.ign
+++ b/selftest/trial_test/trial_test.ok.ign
@@ -1,3 +1,3 @@
 /tmp/[^/]*	[TMP]
 ....-..-.._..-..-..	[TIMESTAMP]
-'[^']*/trial_test	'[PATH]/trial_test
+/[^ ]*/trial_test/	[PATH]/trial_test/
diff --git a/selftest/trial_test/trial_test.py b/selftest/trial_test/trial_test.py
index a99428a..cf91a85 100755
--- a/selftest/trial_test/trial_test.py
+++ b/selftest/trial_test/trial_test.py
@@ -1,8 +1,10 @@
 #!/usr/bin/env python3
 
-import time
 import _prep
+
+import time
 import os
+
 from osmo_gsm_tester.core import util
 from osmo_gsm_tester.core.trial import Trial
 
@@ -46,4 +48,17 @@
 except RuntimeError as e:
     print('ok, got RuntimeError: %s' % str(e))
 
+print('- Verify trials based on run_label')
+d = util.Dir('trial_test')
+t = Trial(d.child('run_label'))
+t.verify()
+inst = util.Dir(t.get_inst('sample', 'foobar'))
+print('inst: ' + str(inst))
+with open(inst.child('file2'), 'r') as f:
+    print('content file2: %s' % f.read())
+inst = util.Dir( t.get_inst('sample'))
+print('inst: ' + str(inst))
+with open(inst.child('file1'), 'r') as f:
+    print('content file1: %s' % f.read())
+
 # vim: expandtab tabstop=4 shiftwidth=4