@@ -481,9 +481,10 @@ def build_pkg(config, args, pkg, arch):
481481
482482 mock .clean ()
483483
484- def test_one_pkg (config , args , pkg , vm , arch , repos , results ):
484+ def test_one_pkg (config , args , pkg , vm , arch , repos ):
485485 """
486- Launch tests on a given package on a specific VM and a set of repositories.
486+ Launch tests on a given package on a specific VM and a set of repositories
487+ and return results.
487488 """
488489 message (f"Preparing { arch } test environment" )
489490 _vm_start (vm )
@@ -495,7 +496,7 @@ def test_one_pkg(config, args, pkg, vm, arch, repos, results):
495496
496497 banner (f"Starting tests of package { pkg .name } on architecture { arch } " )
497498
498- rc = 0
499+ results = TestResults ()
499500
500501 tests = list (pkg .tests ())
501502 if not args .noauto :
@@ -509,7 +510,6 @@ def test_one_pkg(config, args, pkg, vm, arch, repos, results):
509510 results .add_success (case , time .time () - now , out = proc .out , err = proc .err )
510511 message (f"Test '{ case .fullname } ' on architecture { arch } : OK" )
511512 else :
512- rc = 1
513513 results .add_failure (case , time .time () - now , out = proc .out , err = proc .err )
514514 message (f"Test '{ case .fullname } ' on architecture { arch } : ERROR" )
515515
@@ -519,10 +519,10 @@ def test_one_pkg(config, args, pkg, vm, arch, repos, results):
519519 time .sleep (5 )
520520 vm .stop ()
521521
522- return rc
522+ return results
523523
524- def test_pkgs (config , args , results , pkgs , arch , extra_repos = None ):
525- """Test a list of packages on a specific architecture."""
524+ def test_pkgs (config , args , pkgs , arch , extra_repos = None ):
525+ """Test a list of packages on a specific architecture and return results ."""
526526
527527 if extra_repos is None :
528528 extra_repos = []
@@ -533,7 +533,7 @@ def test_pkgs(config, args, results, pkgs, arch, extra_repos=None):
533533 if vm .running ():
534534 raise RiftError ('VM is already running' )
535535
536- rc = 0
536+ results = TestResults ()
537537
538538 for pkg in pkgs :
539539
@@ -559,27 +559,30 @@ def test_pkgs(config, args, results, pkgs, arch, extra_repos=None):
559559 continue
560560
561561 pkg .load ()
562- rc += test_one_pkg (config , args , pkg , vm , arch , repos , results )
562+ results . extend ( test_one_pkg (config , args , pkg , vm , arch , repos ) )
563563
564564 if getattr (args , 'noquit' , False ):
565565 message ("Not stopping the VM. Use: rift vm connect" )
566566
567- return rc
567+ return results
568568
569- def validate_pkgs (config , args , results , pkgs , arch ):
569+
570+ def validate_pkgs (config , args , pkgs , arch ):
570571 """
571- Validate packages on a specific architecture:
572+ Validate packages on a specific architecture and return results :
572573 - rpmlint on specfile
573574 - check file patterns
574575 - build it
575- - lauch tests
576+ - launch tests
576577 """
577578
578579 repos = ProjectArchRepositories (config , arch )
579580
580581 if args .publish and not repos .can_publish ():
581582 raise RiftError ("Cannot publish if 'working_repo' is undefined" )
582583
584+ results = TestResults ()
585+
583586 for pkg in pkgs :
584587
585588 case = TestCase ('build' , pkg .name , arch )
@@ -638,20 +641,20 @@ def validate_pkgs(config, args, results, pkgs, arch):
638641 mock .publish (staging )
639642 staging .update ()
640643
641- rc = 0
642644 if args .test :
643- rc = test_pkgs (
644- config ,
645- args ,
646- results ,
647- [pkg ],
648- arch ,
649- [staging .consumables [arch ]]
645+ results .extend (
646+ test_pkgs (
647+ config ,
648+ args ,
649+ [pkg ],
650+ arch ,
651+ [staging .consumables [arch ]]
652+ )
650653 )
651654
652655 # Also publish on working repo if requested
653656 # XXX: All RPMs should be published when all of them have been validated
654- if rc == 0 and args .publish :
657+ if results . global_result and args .publish :
655658 message ("Publishing RPMS..." )
656659 mock .publish (repos .working )
657660
@@ -666,6 +669,8 @@ def validate_pkgs(config, args, results, pkgs, arch):
666669
667670 banner (f"All packages checked on architecture { arch } " )
668671
672+ return results
673+
669674def vm_build (vm , args , config ):
670675 """Build VM image."""
671676 if not args .deploy and args .output is None :
@@ -742,6 +747,44 @@ def action_vm(args, config):
742747 ret = vm_build (vm , args , config )
743748 return ret
744749
750+ def build_pkgs (config , args , pkgs , arch ):
751+ """
752+ Build a list of packages on a given architecture and return results.
753+ """
754+ results = TestResults ()
755+
756+ for pkg in pkgs :
757+ case = TestCase ('build' , pkg .name , arch )
758+ now = time .time ()
759+ try :
760+ spec = Spec (pkg .specfile , config = config )
761+ except RiftError as ex :
762+ logging .error ("Unable to load spec file: %s" , str (ex ))
763+ results .add_failure (case , time .time () - now , err = str (ex ))
764+ continue # skip current package
765+
766+ if not spec .supports_arch (arch ):
767+ logging .info (
768+ "Skipping build on architecture %s not supported by "
769+ "package %s" ,
770+ arch ,
771+ pkg .name
772+ )
773+ continue
774+
775+ banner (f"Building package '{ pkg .name } ' for architecture { arch } " )
776+ now = time .time ()
777+ try :
778+ pkg .load ()
779+ build_pkg (config , args , pkg , arch )
780+ except RiftError as ex :
781+ logging .error ("Build failure: %s" , str (ex ))
782+ results .add_failure (case , time .time () - now , err = str (ex ))
783+ else :
784+ results .add_success (case , time .time () - now )
785+
786+ return results
787+
745788def action_build (args , config ):
746789 """Action for 'build' command."""
747790
@@ -761,36 +804,8 @@ def action_build(args, config):
761804 # Build all packages for all project supported architectures
762805 for arch in config .get ('arch' ):
763806
764- for pkg in Package .list (config , staff , modules , args .packages ):
765-
766- case = TestCase ('build' , pkg .name , arch )
767- now = time .time ()
768- try :
769- spec = Spec (pkg .specfile , config = config )
770- except RiftError as ex :
771- logging .error ("Unable to load spec file: %s" , str (ex ))
772- results .add_failure (case , time .time () - now , err = str (ex ))
773- continue # skip current package
774-
775- if not spec .supports_arch (arch ):
776- logging .info (
777- "Skipping build on architecture %s not supported by "
778- "package %s" ,
779- arch ,
780- pkg .name
781- )
782- continue
783-
784- banner (f"Building package '{ pkg .name } ' for architecture { arch } " )
785- now = time .time ()
786- try :
787- pkg .load ()
788- build_pkg (config , args , pkg , arch )
789- except RiftError as ex :
790- logging .error ("Build failure: %s" , str (ex ))
791- results .add_failure (case , time .time () - now , err = str (ex ))
792- else :
793- results .add_success (case , time .time () - now )
807+ pkgs = Package .list (config , staff , modules , args .packages )
808+ results .extend (build_pkgs (config , args , pkgs , arch ))
794809
795810 if getattr (args , 'junit' , False ):
796811 logging .info ('Writing test results in %s' , args .junit )
@@ -821,12 +836,13 @@ def action_test(args, config):
821836 results = TestResults ('test' )
822837 # Test package on all project supported architectures
823838 for arch in config .get ('arch' ):
824- test_pkgs (
825- config ,
826- args ,
827- results ,
828- Package .list (config , staff , modules , args .packages ),
829- arch
839+ results .extend (
840+ test_pkgs (
841+ config ,
842+ args ,
843+ Package .list (config , staff , modules , args .packages ),
844+ arch
845+ )
830846 )
831847 if getattr (args , 'junit' , False ):
832848 logging .info ('Writing test results in %s' , args .junit )
@@ -852,12 +868,13 @@ def action_validate(args, config):
852868 results = TestResults ('validate' )
853869 # Validate packages on all project supported architectures
854870 for arch in config .get ('arch' ):
855- validate_pkgs (
856- config ,
857- args ,
858- results ,
859- Package .list (config , staff , modules , args .packages ),
860- arch
871+ results .extend (
872+ validate_pkgs (
873+ config ,
874+ args ,
875+ Package .list (config , staff , modules , args .packages ),
876+ arch
877+ )
861878 )
862879 banner ('All packages checked on all architectures' )
863880
@@ -890,7 +907,7 @@ def action_validdiff(args, config):
890907 # Re-validate all updated packages for all architectures supported by the
891908 # project.
892909 for arch in config .get ('arch' ):
893- validate_pkgs (config , args , results , updated .values (), arch )
910+ results . extend ( validate_pkgs (config , args , updated .values (), arch ) )
894911
895912
896913 if getattr (args , 'junit' , False ):
0 commit comments