summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMariano Lopez <mariano.lopez@linux.intel.com>2016-11-17 12:18:52 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-12-13 22:55:19 +0000
commitdc721f7590464cf9b53812ce604268130717c2ed (patch)
tree7e4fdecc3a6e936ed21ff17ac1a7e35b0b85451c
parent904b9153697493671cee600a184725ac87ee23a8 (diff)
downloadpoky-dc721f7590464cf9b53812ce604268130717c2ed.tar.gz
oe-selftest: Add option to submit test result to a git repository.
This new option allows to commit the result to a git repository, along with the results it will add a metadata file for information of the current selftest run, such as: hostname, machine, distro, distro version, host version, and layers. This implementation will have a branch per different hostname, testing branch, and machine. To use this feature use: oe-selftest <options> --repository <repository_link> [YOCTO #9954] (From OE-Core rev: 758e4b7e619f9aaa79e3910b5539ff8fb2d1064a) Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-xscripts/oe-selftest102
1 files changed, 102 insertions, 0 deletions
diff --git a/scripts/oe-selftest b/scripts/oe-selftest
index deaa4324cc..f4b861f2c3 100755
--- a/scripts/oe-selftest
+++ b/scripts/oe-selftest
@@ -36,6 +36,7 @@ import re
36import fnmatch 36import fnmatch
37import collections 37import collections
38import imp 38import imp
39import git
39 40
40sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '/lib') 41sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '/lib')
41import scriptpath 42import scriptpath
@@ -46,6 +47,7 @@ import argparse_oe
46import oeqa.selftest 47import oeqa.selftest
47import oeqa.utils.ftools as ftools 48import oeqa.utils.ftools as ftools
48from oeqa.utils.commands import runCmd, get_bb_var, get_test_layer 49from oeqa.utils.commands import runCmd, get_bb_var, get_test_layer
50from oeqa.utils.metadata import metadata_from_bb, write_metadata_file
49from oeqa.selftest.base import oeSelfTest, get_available_machines 51from oeqa.selftest.base import oeSelfTest, get_available_machines
50 52
51try: 53try:
@@ -106,6 +108,8 @@ def get_args_parser():
106 help='List all tags that have been set to test cases.') 108 help='List all tags that have been set to test cases.')
107 parser.add_argument('--machine', required=False, dest='machine', choices=['random', 'all'], default=None, 109 parser.add_argument('--machine', required=False, dest='machine', choices=['random', 'all'], default=None,
108 help='Run tests on different machines (random/all).') 110 help='Run tests on different machines (random/all).')
111 parser.add_argument('--repository', required=False, dest='repository', default='', action='store',
112 help='Submit test results to a repository')
109 return parser 113 return parser
110 114
111 115
@@ -572,6 +576,75 @@ def main():
572 576
573 log.info("Finished") 577 log.info("Finished")
574 578
579 if args.repository:
580 # Commit tests results to repository
581 metadata = metadata_from_bb()
582 git_dir = os.path.join(os.getcwd(), 'selftest')
583 if not os.path.isdir(git_dir):
584 os.mkdir(git_dir)
585
586 log.debug('Checking for git repository in %s' % git_dir)
587 try:
588 repo = git.Repo(git_dir)
589 except git.exc.InvalidGitRepositoryError:
590 log.debug("Couldn't find git repository %s; "
591 "cloning from %s" % (git_dir, args.repository))
592 repo = git.Repo.clone_from(args.repository, git_dir)
593
594 r_branches = repo.git.branch(r=True)
595 r_branches = set(r_branches.replace('origin/', '').split())
596 l_branches = {str(branch) for branch in repo.branches}
597 branch = '%s/%s/%s' % (metadata['hostname'],
598 metadata['layers']['meta']['branch'],
599 metadata['machine'])
600
601 if branch in l_branches:
602 log.debug('Found branch in local repository, checking out')
603 repo.git.checkout(branch)
604 elif branch in r_branches:
605 log.debug('Found branch in remote repository, checking'
606 ' out and pulling')
607 repo.git.checkout(branch)
608 repo.git.pull()
609 else:
610 log.debug('New branch %s' % branch)
611 repo.git.checkout('master')
612 repo.git.checkout(b=branch)
613
614 cleanResultsDir(repo)
615 xml_dir = os.path.join(os.getcwd(), log_prefix)
616 copyResultFiles(xml_dir, git_dir, repo)
617 metadata_file = os.path.join(git_dir, 'metadata.xml')
618 write_metadata_file(metadata_file, metadata)
619 repo.index.add([metadata_file])
620 repo.index.write()
621
622 # Get information for commit message
623 layer_info = ''
624 for layer, values in metadata['layers'].items():
625 layer_info = '%s%-17s = %s:%s\n' % (layer_info, layer,
626 values['branch'], values['revision'])
627 msg = 'Selftest for build %s of %s %s for machine %s on %s\n\n%s' % (
628 log_prefix[12:], metadata['distro'], metadata['distro_version'],
629 metadata['machine'], metadata['hostname'], layer_info)
630
631 log.debug('Commiting results to local repository')
632 repo.index.commit(msg)
633 if not repo.is_dirty():
634 try:
635 if branch in r_branches:
636 log.debug('Pushing changes to remote repository')
637 repo.git.push()
638 else:
639 log.debug('Pushing changes to remote repository '
640 'creating new branch')
641 repo.git.push('-u', 'origin', branch)
642 except GitCommandError:
643 log.error('Falied to push to remote repository')
644 return 1
645 else:
646 log.error('Local repository is dirty, not pushing commits')
647
575 if result.wasSuccessful(): 648 if result.wasSuccessful():
576 return 0 649 return 0
577 else: 650 else:
@@ -655,6 +728,35 @@ def buildResultClass(args):
655 728
656 return StampedResult 729 return StampedResult
657 730
731def cleanResultsDir(repo):
732 """ Remove result files from directory """
733
734 xml_files = []
735 directory = repo.working_tree_dir
736 for f in os.listdir(directory):
737 path = os.path.join(directory, f)
738 if os.path.isfile(path) and path.endswith('.xml'):
739 xml_files.append(f)
740 repo.index.remove(xml_files, working_tree=True)
741
742def copyResultFiles(src, dst, repo):
743 """ Copy result files from src to dst removing the time stamp. """
744
745 import shutil
746
747 re_time = re.compile("-[0-9]+")
748 file_list = []
749
750 for root, subdirs, files in os.walk(src):
751 tmp_dir = root.replace(src, '').lstrip('/')
752 for s in subdirs:
753 os.mkdir(os.path.join(dst, tmp_dir, s))
754 for f in files:
755 file_name = os.path.join(dst, tmp_dir, re_time.sub("", f))
756 shutil.copy2(os.path.join(root, f), file_name)
757 file_list.append(file_name)
758 repo.index.add(file_list)
759
658class TestRunner(_TestRunner): 760class TestRunner(_TestRunner):
659 """Test runner class aware of exporting tests.""" 761 """Test runner class aware of exporting tests."""
660 def __init__(self, *args, **kwargs): 762 def __init__(self, *args, **kwargs):