Ejemplo n.º 1
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_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()