def test_operation_success_for_non_autopatching_request(self):
     argument_composer = ArgumentComposer()
     runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.ZYPPER)
     runtime.set_legacy_test_type('SuccessInstallPath')
     CoreMain(argument_composer.get_composed_arguments())
     with runtime.env_layer.file_system.open(runtime.execution_config.status_file_path, 'r') as file_handle:
         substatus_file_data = json.load(file_handle)[0]["status"]["substatus"]
     self.assertEquals(len(substatus_file_data), 2)
     self.assertTrue(substatus_file_data[0]["name"] == Constants.PATCH_ASSESSMENT_SUMMARY)
     self.assertTrue(substatus_file_data[0]["status"] == Constants.STATUS_SUCCESS.lower())
     self.assertTrue(substatus_file_data[1]["name"] == Constants.PATCH_INSTALLATION_SUMMARY)
     self.assertTrue(substatus_file_data[1]["status"] == Constants.STATUS_SUCCESS.lower())
     runtime.stop()
Exemple #2
0
    def test_inclusion_notexist(self):
        """Unit test for yum with Inclusion which does not exist & NotSelected Classifications"""
        self.runtime.set_legacy_test_type('HappyPath')
        package_manager = self.container.get('package_manager')
        self.assertIsNotNone(package_manager)
        self.runtime.stop()

        argument_composer = ArgumentComposer()
        argument_composer.classifications_to_include = [
            Constants.PackageClassification.UNCLASSIFIED
        ]
        argument_composer.patches_to_include = ["ssh"]
        argument_composer.patches_to_exclude = ["ssh*", "test"]
        self.runtime = RuntimeCompositor(
            argument_composer.get_composed_arguments(), True, Constants.YUM)
        self.container = self.runtime.container

        package_filter = self.container.get('package_filter')
        self.assertIsNotNone(package_filter)

        # test for get_available_updates
        available_updates, package_versions = package_manager.get_available_updates(
            package_filter)
        self.assertIsNotNone(available_updates)
        self.assertIsNotNone(package_versions)
        self.assertEqual(len(available_updates), 0)
        self.assertEqual(len(package_versions), 0)
Exemple #3
0
    def test_inclusion_only(self):
        """Unit test for yum package manager with inclusion only and NotSelected Classifications"""
        self.runtime.set_legacy_test_type('HappyPath')
        package_manager = self.container.get('package_manager')
        self.assertIsNotNone(package_manager)
        self.runtime.stop()

        argument_composer = ArgumentComposer()
        argument_composer.classifications_to_include = [
            Constants.PackageClassification.UNCLASSIFIED
        ]
        argument_composer.patches_to_include = ["ssh", "tar*"]
        argument_composer.patches_to_exclude = ["ssh*", "test"]
        self.runtime = RuntimeCompositor(
            argument_composer.get_composed_arguments(), True, Constants.YUM)
        self.container = self.runtime.container

        package_filter = self.container.get('package_filter')
        self.assertIsNotNone(package_filter)

        # test for get_available_updates
        available_updates, package_versions = package_manager.get_available_updates(
            package_filter)
        self.assertIsNotNone(available_updates)
        self.assertIsNotNone(package_versions)
        self.assertEqual(len(available_updates), 1)
        self.assertEqual(len(package_versions), 1)
        self.assertEqual(available_updates[0], "tar.x86_64")
        self.assertEqual(package_versions[0], "2:1.26-34.el7")
Exemple #4
0
    def test_exclusions_with_python_arch(self):
        argument_composer = ArgumentComposer()
        argument_composer.classifications_to_include = []
        argument_composer.patches_to_include = []
        argument_composer.patches_to_exclude = [
            "python", "ssh.i686", "all*", "added"
        ]
        runtime = RuntimeCompositor(argument_composer.get_composed_arguments(),
                                    True)

        self.assertEqual(runtime.package_filter.is_exclusion_list_present(),
                         True)
        self.assertEqual(
            runtime.package_filter.check_for_exclusion("python.x86_64"), True)
        self.assertEqual(
            runtime.package_filter.check_for_exclusion("python.i686"), True)
        self.assertEqual(
            runtime.package_filter.check_for_exclusion("python.test"), False)
        self.assertEqual(runtime.package_filter.check_for_exclusion("python."),
                         False)
        self.assertEqual(
            runtime.package_filter.check_for_exclusion("ssh.i686"), True)
        self.assertEqual(runtime.package_filter.check_for_exclusion("all"),
                         True)
        self.assertEqual(runtime.package_filter.check_for_exclusion("added"),
                         True)
        self.assertEqual(
            runtime.package_filter.check_for_exclusion("added.v4"), False)
        self.assertEqual(runtime.package_filter.check_for_exclusion("random"),
                         False)
        runtime.stop()
Exemple #5
0
    def test_inclusion_dependency_only(self):
        """Unit test for yum with test dependencies in Inclusion & NotSelected Classifications"""
        self.runtime.set_legacy_test_type('HappyPath')
        package_manager = self.container.get('package_manager')
        self.assertIsNotNone(package_manager)
        self.runtime.stop()

        argument_composer = ArgumentComposer()
        argument_composer.classifications_to_include = [
            Constants.PackageClassification.UNCLASSIFIED
        ]
        argument_composer.patches_to_include = [
            "ssh", "selinux-policy-targeted.noarch"
        ]
        argument_composer.patches_to_exclude = ["ssh*", "test"]
        self.runtime = RuntimeCompositor(
            argument_composer.get_composed_arguments(), True, Constants.YUM)
        self.container = self.runtime.container

        package_filter = self.container.get('package_filter')
        self.assertIsNotNone(package_filter)

        # test for get_available_updates
        available_updates, package_versions = package_manager.get_available_updates(
            package_filter)
        self.assertIsNotNone(available_updates)
        self.assertIsNotNone(package_versions)
        self.assertEqual(len(available_updates), 1)
        self.assertEqual(len(package_versions), 1)
        self.assertEqual(available_updates[0],
                         "selinux-policy-targeted.noarch")
        self.assertEqual(package_versions[0], "3.13.1-102.el7_3.16")
 def test_reboot_setting(self, reboot_setting_in_api='Never', reboot_setting_in_code=Constants.REBOOT_NEVER):
     argument_composer = ArgumentComposer()
     argument_composer.reboot_setting = reboot_setting_in_api
     runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.YUM)
     reboot_manager = runtime.reboot_manager
     self.assertEqual(reboot_manager.is_setting(reboot_setting_in_code), True)
     runtime.stop()
Exemple #7
0
    def healthstore_writes_helper(self, health_store_id, maintenance_run_id,
                                  expected_patch_version):
        current_time = datetime.datetime.utcnow()
        td = datetime.timedelta(hours=0, minutes=20)
        job_start_time = (current_time -
                          td).strftime("%Y-%m-%dT%H:%M:%S.9999Z")
        argument_composer = ArgumentComposer()
        argument_composer.maximum_duration = 'PT1H'
        argument_composer.start_time = job_start_time
        argument_composer.health_store_id = health_store_id
        argument_composer.maintenance_run_id = maintenance_run_id
        runtime = RuntimeCompositor(argument_composer.get_composed_arguments(),
                                    True, Constants.YUM)

        runtime.set_legacy_test_type('SuccessInstallPath')
        installed_update_count, update_run_successful, maintenance_window_exceeded = runtime.patch_installer.install_updates(
            runtime.maintenance_window, runtime.package_manager, simulate=True)
        runtime.patch_installer.mark_installation_completed()

        with runtime.env_layer.file_system.open(
                runtime.execution_config.status_file_path, 'r') as file_handle:
            substatus_file_data = json.load(
                file_handle)[0]["status"]["substatus"][1]

        self.assertEqual(
            True,
            json.loads(substatus_file_data['formattedMessage']['message'])
            ['shouldReportToHealthStore'])
        self.assertEqual(
            expected_patch_version,
            json.loads(substatus_file_data['formattedMessage']['message'])
            ['patchVersion'])
        runtime.stop()
 def test_reboot_setting_default_config(self):
     argument_composer = ArgumentComposer()
     argument_composer.reboot_setting = ""
     runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.YUM)
     reboot_manager = runtime.reboot_manager
     self.assertEqual(reboot_manager.is_setting(Constants.REBOOT_IF_REQUIRED), True)
     runtime.stop()
Exemple #9
0
    def test_exclusions(self):
        argument_composer = ArgumentComposer()
        argument_composer.classifications_to_include = []
        argument_composer.patches_to_include = []
        argument_composer.patches_to_exclude = ["ssh*", "test"]
        runtime = RuntimeCompositor(argument_composer.get_composed_arguments(),
                                    True)

        self.assertEqual(runtime.package_filter.is_exclusion_list_present(),
                         True)

        self.assertEqual(runtime.package_filter.check_for_exclusion("ssh"),
                         True)
        self.assertEqual(
            runtime.package_filter.check_for_exclusion("ssh-client"), True)
        self.assertEqual(
            runtime.package_filter.check_for_exclusion("custom-ssh"), False)
        self.assertEqual(runtime.package_filter.check_for_exclusion("test"),
                         True)
        self.assertEqual(runtime.package_filter.check_for_exclusion("kernel"),
                         False)

        self.assertEqual(
            runtime.package_filter.check_for_exclusion(["kernel", "firefox"]),
            False)
        self.assertEqual(
            runtime.package_filter.check_for_exclusion(
                ["firefox", "ssh-client"]), True)
        runtime.stop()
Exemple #10
0
    def test_inclusion_type_critical(self):
        """Unit test for yum package manager with inclusion and Classification = Critical"""
        self.runtime.set_legacy_test_type('HappyPath')
        package_manager = self.container.get('package_manager')
        self.assertIsNotNone(package_manager)
        self.runtime.stop()

        argument_composer = ArgumentComposer()
        argument_composer.classifications_to_include = [
            Constants.PackageClassification.CRITICAL
        ]
        argument_composer.patches_to_exclude = ["ssh*", "test"]
        argument_composer.patches_to_include = ["ssh", "tar*"]
        self.runtime = RuntimeCompositor(
            argument_composer.get_composed_arguments(), True, Constants.YUM)
        self.container = self.runtime.container

        package_filter = self.container.get('package_filter')
        self.assertIsNotNone(package_filter)

        # test for get_available_updates
        available_updates, package_versions = package_manager.get_available_updates(
            package_filter)
        self.assertIsNotNone(available_updates)
        self.assertIsNotNone(package_versions)
        self.assertEqual(len(available_updates), 2)
        self.assertEqual(len(package_versions), 2)
        self.assertEqual(available_updates[0], "libgcc.i686")
        self.assertEqual(available_updates[1], "tar.x86_64")
        self.assertEqual(package_versions[0], "4.8.5-28.el7")
        self.assertEqual(package_versions[1], "2:1.26-34.el7")
    def test_reboot_always_runs_only_once_if_no_reboot_is_required(self):
        reboot_setting_in_api = 'Always'
        argument_composer = ArgumentComposer()
        argument_composer.reboot_setting = reboot_setting_in_api
        runtime = RuntimeCompositor(argument_composer.get_composed_arguments(),
                                    True, Constants.YUM)
        reboot_manager = runtime.reboot_manager

        # Validate single reboot scenario
        runtime.status_handler.is_reboot_pending = True
        self.assertEqual(
            reboot_manager.start_reboot_if_required_and_time_available(20),
            True)

        # mock completing the reboot once, with no reboot required
        runtime.status_handler.set_installation_reboot_status(
            Constants.RebootStatus.REQUIRED)
        runtime.status_handler.set_installation_reboot_status(
            Constants.RebootStatus.STARTED)
        runtime.status_handler.is_reboot_pending = False
        runtime.status_handler.set_installation_reboot_status(
            Constants.RebootStatus.COMPLETED)

        # no further reboot should be required
        self.assertEqual(
            reboot_manager.start_reboot_if_required_and_time_available(20),
            False)
        runtime.stop()
 def test_reboot_always_time_not_available(self):
     reboot_setting_in_api = 'Always'
     argument_composer = ArgumentComposer()
     argument_composer.reboot_setting = reboot_setting_in_api
     runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.YUM)
     reboot_manager = runtime.reboot_manager
     self.assertEqual(reboot_manager.start_reboot_if_required_and_time_available(10), False)
     runtime.stop()
    def test_invalid_maintenance_run_id(self):
        # test with empty string for maintenence run id
        argument_composer = ArgumentComposer()
        maintenance_run_id = ""
        argument_composer.maintenance_run_id = maintenance_run_id
        runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.ZYPPER)
        runtime.set_legacy_test_type('SuccessInstallPath')
        CoreMain(argument_composer.get_composed_arguments())
        with runtime.env_layer.file_system.open(runtime.execution_config.status_file_path, 'r') as file_handle:
            substatus_file_data = json.load(file_handle)[0]["status"]["substatus"]
        self.assertEquals(len(substatus_file_data), 3)
        self.assertTrue(substatus_file_data[0]["name"] == Constants.PATCH_ASSESSMENT_SUMMARY)
        self.assertTrue(substatus_file_data[0]["status"] == Constants.STATUS_SUCCESS.lower())
        self.assertTrue(substatus_file_data[1]["name"] == Constants.PATCH_INSTALLATION_SUMMARY)
        self.assertTrue(substatus_file_data[1]["status"] == Constants.STATUS_TRANSITIONING.lower())
        self.assertTrue(substatus_file_data[2]["name"] == Constants.PATCH_METADATA_FOR_HEALTHSTORE)
        self.assertTrue(substatus_file_data[2]["status"] == Constants.STATUS_SUCCESS.lower())
        substatus_file_data_patch_metadata_summary = json.loads(substatus_file_data[2]["formattedMessage"]["message"])
        self.assertEqual(substatus_file_data_patch_metadata_summary["patchVersion"], Constants.PATCH_VERSION_UNKNOWN)
        self.assertFalse(substatus_file_data_patch_metadata_summary["shouldReportToHealthStore"])
        runtime.stop()

        # todo: This will become a valid success operation run once the temp fix for maintenanceRunId is removed
        # test with a random string for maintenance run id
        argument_composer = ArgumentComposer()
        maintenance_run_id = "test"
        argument_composer.maintenance_run_id = maintenance_run_id
        runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.ZYPPER)
        runtime.set_legacy_test_type('SuccessInstallPath')
        CoreMain(argument_composer.get_composed_arguments())
        with runtime.env_layer.file_system.open(runtime.execution_config.status_file_path, 'r') as file_handle:
            substatus_file_data = json.load(file_handle)[0]["status"]["substatus"]
        self.assertEquals(len(substatus_file_data), 3)
        self.assertTrue(substatus_file_data[0]["name"] == Constants.PATCH_ASSESSMENT_SUMMARY)
        self.assertTrue(substatus_file_data[0]["status"] == Constants.STATUS_SUCCESS.lower())
        self.assertTrue(substatus_file_data[1]["name"] == Constants.PATCH_INSTALLATION_SUMMARY)
        self.assertTrue(substatus_file_data[1]["status"] == Constants.STATUS_TRANSITIONING.lower())
        self.assertTrue(substatus_file_data[2]["name"] == Constants.PATCH_METADATA_FOR_HEALTHSTORE)
        self.assertTrue(substatus_file_data[2]["status"] == Constants.STATUS_SUCCESS.lower())
        substatus_file_data_patch_metadata_summary = json.loads(substatus_file_data[2]["formattedMessage"]["message"])
        self.assertEqual(substatus_file_data_patch_metadata_summary["patchVersion"], Constants.PATCH_VERSION_UNKNOWN)
        self.assertFalse(substatus_file_data_patch_metadata_summary["shouldReportToHealthStore"])
        runtime.stop()
 def test_operation_fail_for_autopatching_request(self):
     argument_composer = ArgumentComposer()
     argument_composer.maintenance_run_id = str(datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%fZ"))
     runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.ZYPPER)
     runtime.set_legacy_test_type('FailInstallPath')
     CoreMain(argument_composer.get_composed_arguments())
     with runtime.env_layer.file_system.open(runtime.execution_config.status_file_path, 'r') as file_handle:
         substatus_file_data = json.load(file_handle)[0]["status"]["substatus"]
     self.assertEquals(len(substatus_file_data), 3)
     self.assertTrue(substatus_file_data[0]["name"] == Constants.PATCH_ASSESSMENT_SUMMARY)
     self.assertTrue(substatus_file_data[0]["status"] == Constants.STATUS_SUCCESS.lower())
     self.assertTrue(substatus_file_data[1]["name"] == Constants.PATCH_INSTALLATION_SUMMARY)
     self.assertTrue(substatus_file_data[1]["status"] == Constants.STATUS_ERROR.lower())
     self.assertEqual(len(json.loads(substatus_file_data[1]["formattedMessage"]["message"])["errors"]["details"]), 1)
     self.assertTrue(substatus_file_data[2]["name"] == Constants.PATCH_METADATA_FOR_HEALTHSTORE)
     self.assertTrue(substatus_file_data[2]["status"] == Constants.STATUS_SUCCESS.lower())
     substatus_file_data_patch_metadata_summary = json.loads(substatus_file_data[2]["formattedMessage"]["message"])
     self.assertTrue(substatus_file_data_patch_metadata_summary["patchVersion"], Constants.PATCH_VERSION_UNKNOWN)
     self.assertFalse(substatus_file_data_patch_metadata_summary["shouldReportToHealthStore"])
     runtime.stop()
 def test_check_available_time(self):
     argument_composer = ArgumentComposer()
     argument_composer.start_time = (
         datetime.datetime.utcnow() -
         datetime.timedelta(minutes=39)).strftime("%Y-%m-%dT%H:%M:%S.9999Z")
     argument_composer.maximum_duration = "PT1H"
     runtime = RuntimeCompositor(argument_composer.get_composed_arguments(),
                                 True)
     self.assertEqual(
         runtime.maintenance_window.is_package_install_time_available(),
         True)
     runtime.stop()
Exemple #16
0
    def test_invalid_classifications(self):
        argument_composer = ArgumentComposer()
        argument_composer.classifications_to_include = ['Security', "Other"]
        argument_composer.patches_to_include = []
        argument_composer.patches_to_exclude = []
        runtime = RuntimeCompositor(argument_composer.get_composed_arguments(),
                                    True)

        self.assertEqual(
            runtime.package_filter.is_invalid_classification_combination(),
            True)
        runtime.stop()
 def test_operation_success_for_autopatching_request(self):
     # test with valid datetime string for maintenance run id
     argument_composer = ArgumentComposer()
     maintenance_run_id = "9/28/2020 02:00:00 PM +00:00"
     argument_composer.maintenance_run_id = str(maintenance_run_id)
     runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.ZYPPER)
     runtime.set_legacy_test_type('SuccessInstallPath')
     CoreMain(argument_composer.get_composed_arguments())
     with runtime.env_layer.file_system.open(runtime.execution_config.status_file_path, 'r') as file_handle:
         substatus_file_data = json.load(file_handle)[0]["status"]["substatus"]
     self.assertEquals(len(substatus_file_data), 3)
     self.assertTrue(substatus_file_data[0]["name"] == Constants.PATCH_ASSESSMENT_SUMMARY)
     self.assertTrue(substatus_file_data[0]["status"] == Constants.STATUS_SUCCESS.lower())
     self.assertTrue(substatus_file_data[1]["name"] == Constants.PATCH_INSTALLATION_SUMMARY)
     self.assertTrue(substatus_file_data[1]["status"] == Constants.STATUS_SUCCESS.lower())
     self.assertTrue(substatus_file_data[2]["name"] == Constants.PATCH_METADATA_FOR_HEALTHSTORE)
     self.assertTrue(substatus_file_data[2]["status"] == Constants.STATUS_SUCCESS.lower())
     substatus_file_data_patch_metadata_summary = json.loads(substatus_file_data[2]["formattedMessage"]["message"])
     self.assertEqual(substatus_file_data_patch_metadata_summary["patchVersion"], "2020.09.28")
     self.assertTrue(substatus_file_data_patch_metadata_summary["shouldReportToHealthStore"])
     runtime.stop()
    def test_with_none_for_classifications(self):
        argument_composer = ArgumentComposer()
        argument_composer.classifications_to_include = None
        argument_composer.patches_to_include = []
        argument_composer.patches_to_exclude = []
        runtime = RuntimeCompositor(argument_composer.get_composed_arguments(),
                                    True)

        self.assertEqual(
            runtime.package_filter.is_invalid_classification_combination(),
            False)
        runtime.stop()
Exemple #19
0
    def test_included_classifications(self):
        argument_composer = ArgumentComposer()
        argument_composer.classifications_to_include = ['Critical', 'Security']
        argument_composer.patches_to_include = []
        argument_composer.patches_to_exclude = []
        runtime = RuntimeCompositor(argument_composer.get_composed_arguments(),
                                    True)

        self.assertEqual(
            runtime.package_filter.is_msft_critsec_classification_only(), True)
        self.assertEqual(
            runtime.package_filter.is_msft_other_classification_only(), False)
        runtime.stop()
    def test_RemainingTime_after_duration_complete(self):
        argument_composer = ArgumentComposer()
        argument_composer.start_time = "2017-02-15T18:15:12.9828835Z"
        argument_composer.maximum_duration = "PT1H"
        runtime = RuntimeCompositor(argument_composer.get_composed_arguments(),
                                    True)

        current_time = datetime.datetime.strptime('2017-02-15 19:16:20',
                                                  "%Y-%m-%d %H:%M:%S")
        remaining_time = runtime.maintenance_window.get_remaining_time_in_minutes(
            current_time)

        self.assertEqual(int(remaining_time), 0)
        runtime.stop()
Exemple #21
0
 def test_zypper_install_updates_maintenance_window_exceeded(self):
     current_time = datetime.datetime.utcnow()
     td = datetime.timedelta(hours=1, minutes=2)
     job_start_time = (current_time -
                       td).strftime("%Y-%m-%dT%H:%M:%S.9999Z")
     argument_composer = ArgumentComposer()
     argument_composer.maximum_duration = 'PT1H'
     argument_composer.start_time = job_start_time
     runtime = RuntimeCompositor(argument_composer.get_composed_arguments(),
                                 True, Constants.ZYPPER)
     # Path change
     runtime.set_legacy_test_type('FailInstallPath')
     installed_update_count, update_run_successful, maintenance_window_exceeded = runtime.patch_installer.install_updates(
         runtime.maintenance_window, runtime.package_manager, simulate=True)
     self.assertEqual(0, installed_update_count)
     self.assertTrue(update_run_successful)
     self.assertTrue(maintenance_window_exceeded)
     runtime.stop()
    def test_included_classifications_short_term_accomodations(self):
        # this test should be removed once the accommodations in execution config are removed
        argument_composer = ArgumentComposer()
        argument_composer.classifications_to_include = ['Security', 'Other']
        argument_composer.patches_to_include = []
        argument_composer.patches_to_exclude = []
        runtime = RuntimeCompositor(argument_composer.get_composed_arguments(),
                                    True)

        self.assertEqual(
            runtime.package_filter.is_invalid_classification_combination(),
            False)  # this will fail after accommodations are removed.
        self.assertEqual(
            runtime.package_filter.is_msft_all_classification_included(),
            True)  # this will fail after accommodations are removed.
        self.assertEqual(
            runtime.package_filter.is_msft_critsec_classification_only(),
            False)
        self.assertEqual(
            runtime.package_filter.is_msft_other_classification_only(), False)
        runtime.stop()
Exemple #23
0
    def test_inclusion_type_all(self):
        """Unit test for yum package manager Classification = all and IncludedPackageNameMasks not specified."""
        self.runtime.set_legacy_test_type('HappyPath')
        package_manager = self.container.get('package_manager')
        self.assertIsNotNone(package_manager)
        self.runtime.stop()

        argument_composer = ArgumentComposer()
        argument_composer.classifications_to_include = [
            Constants.PackageClassification.UNCLASSIFIED
        ]
        argument_composer.patches_to_exclude = ["ssh*", "test"]
        self.runtime = RuntimeCompositor(
            argument_composer.get_composed_arguments(), True, Constants.YUM)
        self.container = self.runtime.container

        package_filter = self.container.get('package_filter')

        # test for get_available_updates
        available_updates, package_versions = package_manager.get_available_updates(
            package_filter)
        self.assertIsNotNone(available_updates)
        self.assertIsNotNone(package_versions)
        self.assertEqual(len(available_updates), 5)
        self.assertEqual(len(package_versions), 5)
        self.assertEqual(available_updates[0], "selinux-policy.noarch")
        self.assertEqual(package_versions[0], "3.13.1-102.el7_3.16")
        self.assertEqual(available_updates[1],
                         "selinux-policy-targeted.noarch")
        self.assertEqual(package_versions[1], "3.13.1-102.el7_3.16")
        self.assertEqual(available_updates[2], "libgcc.i686")
        self.assertEqual(package_versions[2], "4.8.5-28.el7")
        self.assertEqual(available_updates[3], "tar.x86_64")
        self.assertEqual(package_versions[3], "2:1.26-34.el7")
        self.assertEqual(available_updates[4], "tcpdump.x86_64")
        self.assertEqual(package_versions[4], "14:4.9.2-3.el7")
Exemple #24
0
    def test_inclusion_type_other(self):
        """Unit test for yum package manager with inclusion and Classification = Other"""
        self.runtime.set_legacy_test_type('HappyPath')
        package_manager = self.container.get('package_manager')
        self.assertIsNotNone(package_manager)
        self.runtime.stop()

        argument_composer = ArgumentComposer()
        argument_composer.classifications_to_include = [
            Constants.PackageClassification.OTHER
        ]
        argument_composer.patches_to_include = ["ssh", "tcpdump"]
        argument_composer.patches_to_exclude = ["ssh*", "test"]
        self.runtime = RuntimeCompositor(
            argument_composer.get_composed_arguments(), True, Constants.YUM)
        self.container = self.runtime.container

        package_filter = self.container.get('package_filter')
        self.assertIsNotNone(package_filter)

        # test for get_available_updates
        available_updates, package_versions = package_manager.get_available_updates(
            package_filter)
        self.assertIsNotNone(available_updates)
        self.assertIsNotNone(package_versions)
        self.assertEqual(len(available_updates), 4)
        self.assertEqual(len(package_versions), 4)
        self.assertEqual(available_updates[0], "selinux-policy.noarch")
        self.assertEqual(package_versions[0], "3.13.1-102.el7_3.16")
        self.assertEqual(available_updates[1],
                         "selinux-policy-targeted.noarch")
        self.assertEqual(package_versions[1], "3.13.1-102.el7_3.16")
        self.assertEqual(available_updates[2], "tar.x86_64")
        self.assertEqual(package_versions[2], "2:1.26-34.el7")
        self.assertEqual(available_updates[3], "tcpdump.x86_64")
        self.assertEqual(package_versions[3], "14:4.9.2-3.el7")
    def test_package_manager(self):
        """Unit test for zypper package manager"""
        self.runtime.set_legacy_test_type('HappyPath')

        package_manager = self.container.get('package_manager')
        self.assertIsNotNone(package_manager)
        package_filter = self.container.get('package_filter')
        self.assertIsNotNone(package_filter)

        # test for get_available_updates
        # legacy_test_type ='Happy Path'
        available_updates, package_versions = package_manager.get_available_updates(
            package_filter)
        self.assertIsNotNone(available_updates)
        self.assertIsNotNone(package_versions)
        self.assertEqual(len(available_updates), 3)
        self.assertEqual(len(package_versions), 3)
        self.assertEqual(available_updates[0], "kernel-default")
        self.assertEqual(available_updates[1], "libgcc")
        self.assertEqual(available_updates[2], "libgoa-1_0-0")
        self.assertEqual(package_versions[0], "4.4.49-92.11.1")
        self.assertEqual(package_versions[1], "5.60.7-8.1")
        self.assertEqual(package_versions[2], "3.20.5-9.6")

        # test for get_available_updates with security classification
        # legacy_test_type ='Happy Path'
        self.runtime.stop()
        argument_composer = ArgumentComposer()
        argument_composer.classifications_to_include = [
            Constants.PackageClassification.SECURITY
        ]
        self.runtime = RuntimeCompositor(
            argument_composer.get_composed_arguments(), True, Constants.ZYPPER)
        self.container = self.runtime.container
        package_manager = self.container.get('package_manager')
        self.assertIsNotNone(package_manager)
        package_filter = self.container.get('package_filter')
        self.assertIsNotNone(package_filter)
        available_updates, package_versions = package_manager.get_available_updates(
            package_filter)
        self.assertIsNotNone(available_updates)
        self.assertIsNotNone(package_versions)
        self.assertEqual(len(available_updates), 1)
        self.assertEqual(len(package_versions), 1)

        # test for get_available_updates with other classification
        # legacy_test_type ='Happy Path'
        self.runtime.stop()
        argument_composer = ArgumentComposer()
        argument_composer.classifications_to_include = [
            Constants.PackageClassification.OTHER
        ]
        self.runtime = RuntimeCompositor(
            argument_composer.get_composed_arguments(), True, Constants.ZYPPER)
        self.container = self.runtime.container
        package_manager = self.container.get('package_manager')
        self.assertIsNotNone(package_manager)
        package_filter = self.container.get('package_filter')
        self.assertIsNotNone(package_filter)
        available_updates, package_versions = package_manager.get_available_updates(
            package_filter)
        self.assertIsNotNone(available_updates)
        self.assertIsNotNone(package_versions)
        self.assertEqual(len(available_updates), 1)
        self.assertEqual(len(package_versions), 1)

        # test for get_package_size
        cmd = package_manager.single_package_upgrade_cmd + "sudo"
        code, out = self.runtime.env_layer.run_command_output(
            cmd, False, False)
        size = package_manager.get_package_size(out)
        self.assertEqual(size, "810.9 KiB")

        # test for get_dependent_list
        # legacy_test_type ='Happy Path'
        dependent_list = package_manager.get_dependent_list("man")
        self.assertIsNotNone(dependent_list)
        self.assertEqual(len(dependent_list), 16)

        self.runtime.stop()
        self.runtime = RuntimeCompositor(
            ArgumentComposer().get_composed_arguments(), True,
            Constants.ZYPPER)
        self.container = self.runtime.container
        self.runtime.set_legacy_test_type('ExceptionPath')

        package_manager = self.container.get('package_manager')
        self.assertIsNotNone(package_manager)
        package_filter = self.container.get('package_filter')
        self.assertIsNotNone(package_filter)

        # test for get_available_updates
        # legacy_test_type ='Exception Path'
        try:
            package_manager.get_available_updates(package_filter)
        except Exception as exception:
            self.assertTrue(str(exception))
        else:
            self.assertFalse(1 != 2,
                             'Exception did not occur and test failed.')

        # test for get_dependent_list
        # legacy_test_type ='Exception Path'
        try:
            package_manager.get_dependent_list("man")
        except Exception as exception:
            self.assertTrue(str(exception))
        else:
            self.assertFalse(1 != 2,
                             'Exception did not occur and test failed.')