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_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()
 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()
 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_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()
 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()
    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()
 def test_reboot_time_available(self):
     runtime = RuntimeCompositor(ArgumentComposer().get_composed_arguments(), True)
     reboot_manager = runtime.reboot_manager
     self.assertEqual(reboot_manager.is_reboot_time_available(20), True)
     self.assertEqual(reboot_manager.is_reboot_time_available(15), True)
     self.assertEqual(reboot_manager.is_reboot_time_available(14), False)
     runtime.stop()
Esempio n. 9
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()
Esempio n. 10
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_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_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()
Esempio n. 14
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()
Esempio n. 15
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()
Esempio n. 16
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")
Esempio n. 17
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")
Esempio n. 18
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)
Esempio n. 19
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")
Esempio n. 20
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")
Esempio n. 21
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_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()
Esempio n. 23
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_iso8601_duration_to_timedelta_str_conversion(self):
     runtime = RuntimeCompositor(
         ArgumentComposer().get_composed_arguments(), True)
     self.assertEqual(
         "2:00:00",
         runtime.execution_config.
         _ExecutionConfig__convert_iso8601_duration_to_timedelta_str(
             "PT2H"))
     self.assertEqual(
         "0:03:00",
         runtime.execution_config.
         _ExecutionConfig__convert_iso8601_duration_to_timedelta_str(
             "PT3M"))
     self.assertEqual(
         "0:00:40",
         runtime.execution_config.
         _ExecutionConfig__convert_iso8601_duration_to_timedelta_str(
             "PT40S"))
     self.assertEqual(
         "0:03:40",
         runtime.execution_config.
         _ExecutionConfig__convert_iso8601_duration_to_timedelta_str(
             "PT3M40S"))
     self.assertEqual(
         "12:03:40",
         runtime.execution_config.
         _ExecutionConfig__convert_iso8601_duration_to_timedelta_str(
             "PT12H3M40S"))
     self.assertEqual(
         "1:00:40",
         runtime.execution_config.
         _ExecutionConfig__convert_iso8601_duration_to_timedelta_str(
             "PT1H40S"))
     with self.assertRaises(Exception):
         runtime.env_layer.datetime.convert_iso8601_duration_to_timedelta_str(
             "P1DT12H3M40S")
     runtime.stop()
    def __init__(self, argv=Constants.DEFAULT_UNSPECIFIED_VALUE, legacy_mode=False, package_manager_name=Constants.APT):
        # Init data
        self.current_env = Constants.DEV
        os.environ[Constants.LPE_ENV_VARIABLE] = self.current_env
        self.argv = argv if argv != Constants.DEFAULT_UNSPECIFIED_VALUE else ArgumentComposer().get_composed_arguments()

        # Overriding time.sleep to avoid delays in test execution
        time.sleep = self.mock_sleep

        # Adapted bootstrapper
        bootstrapper = Bootstrapper(self.argv, capture_stdout=False)

        # Reconfigure env layer for legacy mode tests
        self.env_layer = bootstrapper.env_layer
        if legacy_mode:
            self.legacy_env_layer_extensions = LegacyEnvLayerExtensions(package_manager_name)
            self.reconfigure_env_layer_to_legacy_mode()

        # Core components
        self.container = bootstrapper.build_out_container()
        self.file_logger = bootstrapper.file_logger
        self.composite_logger = bootstrapper.composite_logger
        self.lifecycle_manager, self.telemetry_writer, self.status_handler = bootstrapper.build_core_components(self.container)

        # Business logic components
        self.execution_config = self.container.get('execution_config')
        self.package_manager = self.container.get('package_manager')
        self.reboot_manager = self.container.get('reboot_manager')
        self.reconfigure_reboot_manager()
        self.package_filter = self.container.get('package_filter')
        self.patch_assessor = self.container.get('patch_assessor')
        self.patch_installer = self.container.get('patch_installer')
        self.maintenance_window = self.container.get('maintenance_window')

        # Extension handler dependency
        self.write_ext_state_file(self.lifecycle_manager.ext_state_file_path, self.execution_config.sequence_number, datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%fZ"), self.execution_config.operation)
    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()
Esempio n. 27
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")
Esempio n. 28
0
 def setUp(self):
     self.argument_composer = ArgumentComposer().get_composed_arguments()
     self.runtime = RuntimeCompositor(self.argument_composer,
                                      True,
                                      package_manager_name=Constants.ZYPPER)
     self.container = self.runtime.container
Esempio n. 29
0
    def __init__(self,
                 argv=Constants.DEFAULT_UNSPECIFIED_VALUE,
                 legacy_mode=False,
                 package_manager_name=Constants.APT,
                 vm_cloud_type=Constants.VMCloudType.AZURE):
        # Init data
        self.current_env = Constants.DEV
        os.environ[Constants.LPE_ENV_VARIABLE] = self.current_env
        self.argv = argv if argv != Constants.DEFAULT_UNSPECIFIED_VALUE else ArgumentComposer(
        ).get_composed_arguments()
        self.vm_cloud_type = vm_cloud_type
        Constants.Paths.SYSTEMD_ROOT = os.getcwd(
        )  # mocking to pass a basic systemd check in Windows

        # Overriding time.sleep and urlopen to avoid delays in test execution
        self.backup_time_sleep = time.sleep
        time.sleep = self.mock_sleep
        self.backup_url_open = urlreq.urlopen
        urlreq.urlopen = self.mock_urlopen

        # Adapted bootstrapper
        bootstrapper = Bootstrapper(self.argv, capture_stdout=False)

        # Overriding sudo status check
        Bootstrapper.check_sudo_status = self.check_sudo_status

        # Reconfigure env layer for legacy mode tests
        self.env_layer = bootstrapper.env_layer
        if legacy_mode:
            self.legacy_env_layer_extensions = LegacyEnvLayerExtensions(
                package_manager_name)
            self.reconfigure_env_layer_to_legacy_mode()

        # Core components
        self.container = bootstrapper.build_out_container()
        self.file_logger = bootstrapper.file_logger
        self.composite_logger = bootstrapper.composite_logger

        # re-initializing telemetry_writer, outside of Bootstrapper, to correctly set the env_layer configured for tests
        self.telemetry_writer = TelemetryWriter(
            self.env_layer, self.composite_logger,
            bootstrapper.telemetry_writer.events_folder_path)
        bootstrapper.telemetry_writer = self.telemetry_writer
        bootstrapper.composite_logger.telemetry_writer = self.telemetry_writer

        self.lifecycle_manager, self.status_handler = bootstrapper.build_core_components(
            self.container)

        # Business logic components
        self.execution_config = self.container.get('execution_config')
        self.package_manager = self.container.get('package_manager')
        self.backup_get_current_auto_os_patch_state = None
        self.reconfigure_package_manager()
        self.configure_patching_processor = self.container.get(
            'configure_patching_processor')
        self.reboot_manager = self.container.get('reboot_manager')
        self.reconfigure_reboot_manager()
        self.package_filter = self.container.get('package_filter')
        self.patch_assessor = self.container.get('patch_assessor')
        self.patch_installer = self.container.get('patch_installer')
        self.maintenance_window = self.container.get('maintenance_window')
        self.vm_cloud_type = bootstrapper.configuration_factory.vm_cloud_type
        # Extension handler dependency
        self.write_ext_state_file(
            self.lifecycle_manager.ext_state_file_path,
            self.execution_config.sequence_number,
            datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
            self.execution_config.operation)

        # Mock service and timer creation and removal used for Auto Assessment
        self.backup_create_and_set_service_idem = self.configure_patching_processor.auto_assess_service_manager.create_and_set_service_idem
        self.configure_patching_processor.auto_assess_service_manager.create_and_set_service_idem = self.mock_create_and_set_service_idem
        self.backup_mock_create_and_set_timer_idem = self.configure_patching_processor.auto_assess_timer_manager.create_and_set_timer_idem
        self.configure_patching_processor.auto_assess_timer_manager.create_and_set_timer_idem = self.mock_create_and_set_timer_idem
        self.backup_remove_service = self.configure_patching_processor.auto_assess_service_manager.remove_service
        self.configure_patching_processor.auto_assess_service_manager.remove_service = self.mock_remove_service
        self.backup_remove_timer = self.configure_patching_processor.auto_assess_timer_manager.remove_timer
        self.configure_patching_processor.auto_assess_timer_manager.remove_timer = self.mock_remove_timer
        self.backup_os_getenv = os.getenv
        os.getenv = self.getenv_telemetry_enabled
Esempio n. 30
0
 def setUp(self):
     self.runtime = RuntimeCompositor(
         ArgumentComposer().get_composed_arguments(), True)
     self.container = self.runtime.container