1818import unittest
1919from core .src .bootstrap .Constants import Constants
2020from core .tests .library .ArgumentComposer import ArgumentComposer
21+ from core .tests .library .LegacyEnvLayerExtensions import LegacyEnvLayerExtensions
2122from core .tests .library .RuntimeCompositor import RuntimeCompositor
2223
2324
@@ -35,6 +36,12 @@ def mock_do_processes_require_restart(self):
3536
3637 def mock_write_with_retry_raise_exception (self , file_path_or_handle , data , mode = 'a+' ):
3738 raise Exception
39+
40+ def mock_linux7_distribution_to_return_redhat (self ):
41+ return ['Red Hat Enterprise Linux Server' , '7' , 'Maipo' ]
42+
43+ def mock_linux8_distribution_to_return_redhat (self ):
44+ return ['Red Hat Enterprise Linux Server' , '8' , 'Ootpa' ]
3845 #endregion Mocks
3946
4047 def mock_do_processes_require_restart_raise_exception (self ):
@@ -619,5 +626,55 @@ def test_obsolete_packages_should_not_considered_in_available_updates(self):
619626 self .assertTrue (available_updates [0 ] == "grub2-tools.x86_64" )
620627 self .assertTrue (package_versions [0 ] == "1:2.02-142.el8" )
621628
629+ def test_rhel7_image_with_security_plugin (self ):
630+ """Unit test for yum package manager rhel images below 8 and Classification = Security"""
631+ # mock linux_distribution
632+ backup_envlayer_platform_linux_distribution = LegacyEnvLayerExtensions .LegacyPlatform .linux_distribution
633+ LegacyEnvLayerExtensions .LegacyPlatform .linux_distribution = self .mock_linux7_distribution_to_return_redhat
634+
635+ self .__assert_test_rhel8_image ()
636+
637+ # restore linux_distribution
638+ LegacyEnvLayerExtensions .LegacyPlatform .linux_distribution = backup_envlayer_platform_linux_distribution
639+
640+ def test_rhel8_image_higher_no_security_plugin (self ):
641+ """Unit test for yum package manager rhel images >= 8 and Classification = Security"""
642+ # mock linux_distribution
643+ backup_envlayer_platform_linux_distribution = LegacyEnvLayerExtensions .LegacyPlatform .linux_distribution
644+ LegacyEnvLayerExtensions .LegacyPlatform .linux_distribution = self .mock_linux8_distribution_to_return_redhat
645+
646+ self .__assert_test_rhel8_image ()
647+
648+ # restore linux_distribution
649+ LegacyEnvLayerExtensions .LegacyPlatform .linux_distribution = backup_envlayer_platform_linux_distribution
650+
651+ def __assert_test_rhel8_image (self ):
652+ self .runtime .set_legacy_test_type ('HappyPath' )
653+ package_manager = self .container .get ('package_manager' )
654+ self .assertIsNotNone (package_manager )
655+ self .runtime .stop ()
656+
657+ argument_composer = ArgumentComposer ()
658+ argument_composer .classifications_to_include = [Constants .PackageClassification .SECURITY ]
659+ argument_composer .patches_to_include = ["ssh" , "tcpdump" ]
660+ argument_composer .patches_to_exclude = ["ssh*" , "test" ]
661+ self .runtime = RuntimeCompositor (argument_composer .get_composed_arguments (), True , Constants .YUM )
662+ self .container = self .runtime .container
663+
664+ package_filter = self .container .get ('package_filter' )
665+ self .assertIsNotNone (package_filter )
666+
667+ available_updates , package_versions = package_manager .get_available_updates (package_filter )
668+
669+ # test for get_available_updates
670+ self .assertIsNotNone (available_updates )
671+ self .assertIsNotNone (package_versions )
672+ self .assertEqual (len (available_updates ), 2 )
673+ self .assertEqual (len (package_versions ), 2 )
674+ self .assertEqual (available_updates [0 ], "libgcc.i686" )
675+ self .assertEqual (package_versions [0 ], "4.8.5-28.el7" )
676+ self .assertEqual (available_updates [1 ], "tcpdump.x86_64" )
677+ self .assertEqual (package_versions [1 ], "14:4.9.2-3.el7" )
678+
622679if __name__ == '__main__' :
623680 unittest .main ()
0 commit comments