-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue where newer Psych fails to load the script_info #519
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The script_info is constructed to give metadata about the script provided by the user. One of the fields uses a Range [^1] to denote the start and end lines of the code. The script_info is passed as a yaml payload to the external executor, but newer version of Psych do not permit Range objects by default, so it fails to deserialize. This commit allows that specific class and ensure we use safe_load for backward compatibility. Without this change, we get the following errors when running miq_ae_method_spec.rb: ``` 1) MiqAeEngine::MiqAeMethod.invoke_inline_ruby (private) with a script that raises logs the error with file and line numbers changed in the stacktrace, and raises an exception Failure/Error: expect($miq_ae_logger).to receive(:error).with("Method STDERR: /my/automate/method:2:in `<main>': unhandled exception").at_least(:once) #<ManageIQ::Loggers::Base:0x00007fe01d743f10 @Level=1, @progname="automation", @default_formatter=#<Logger::Formatter:0x00007fe01d743df8 @datetime_format=nil>, @Formatter=#<ManageIQ::Loggers::Base::Formatter:0x00007fe01d743cb8 @datetime_format=nil>, @logdev=#<Logger::LogDevice:0x00007fe01d743da8 @shift_period_suffix="%Y%m%d", @shift_size=1048576, @shift_age=0, @filename=#<Pathname:/Users/jfrey/dev/manageiq/log/automation.log>, @dev=#<File:/Users/jfrey/dev/manageiq/log/automation.log>, @binmode=false, @mon_data=#<Monitor:0x00007fe01d743d80>, @mon_data_owner_object_id=39840>, @write_lock=#<Thread::Mutex:0x00007fe01d743c90>, @local_levels={}> received :error with unexpected arguments expected: ("Method STDERR: /my/automate/method:2:in `<main>': unhandled exception") got: ("<AEMethod /my/automate/method> The following error occurred during method evaluation:") (1 time) ("<AEMethod /my/automate/method> RuntimeError: ") (1 time) ("Method STDERR: -: Tried to load unspecified class: Range (Psych::DisallowedClass)") (1 time) # ./spec/engine/miq_ae_method_spec.rb:56:in `block (4 levels) in <main>' # /Users/jfrey/.gem/ruby/2.7.6/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <main>' 2) MiqAeEngine::MiqAeMethod.invoke_inline_ruby (private) with a script that raises in a nested method logs the error with file and line numbers changed in the stacktrace, and raises an exception Failure/Error: expect($miq_ae_logger).to receive(:error).with("Method STDERR: /my/automate/method:2:in `my_method': unhandled exception").at_least(:once) #<ManageIQ::Loggers::Base:0x00007fe01d743f10 @Level=1, @progname="automation", @default_formatter=#<Logger::Formatter:0x00007fe01d743df8 @datetime_format=nil>, @Formatter=#<ManageIQ::Loggers::Base::Formatter:0x00007fe01d743cb8 @datetime_format=nil>, @logdev=#<Logger::LogDevice:0x00007fe01d743da8 @shift_period_suffix="%Y%m%d", @shift_size=1048576, @shift_age=0, @filename=#<Pathname:/Users/jfrey/dev/manageiq/log/automation.log>, @dev=#<File:/Users/jfrey/dev/manageiq/log/automation.log>, @binmode=false, @mon_data=#<Monitor:0x00007fe01d743d80>, @mon_data_owner_object_id=39840>, @write_lock=#<Thread::Mutex:0x00007fe01d743c90>, @local_levels={}> received :error with unexpected arguments expected: ("Method STDERR: /my/automate/method:2:in `my_method': unhandled exception") got: ("<AEMethod /my/automate/method> The following error occurred during method evaluation:") (1 time) ("<AEMethod /my/automate/method> RuntimeError: ") (1 time) ("Method STDERR: -: Tried to load unspecified class: Range (Psych::DisallowedClass)") (1 time) # ./spec/engine/miq_ae_method_spec.rb:76:in `block (4 levels) in <main>' # /Users/jfrey/.gem/ruby/2.7.6/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <main>' 3) MiqAeEngine::MiqAeMethod.invoke_inline_ruby (private) embed other methods into a method exception can log stack trace in embedded methods Failure/Error: expect($miq_ae_logger).to receive(:error).with("<AEMethod /my/automate/method> /Shared/Methods/RaiseException:8:in `some_method'").at_least(:once) #<ManageIQ::Loggers::Base:0x00007fe01d743f10 @Level=1, @progname="automation", @default_formatter=#<Logger::Formatter:0x00007fe01d743df8 @datetime_format=nil>, @Formatter=#<ManageIQ::Loggers::Base::Formatter:0x00007fe01d743cb8 @datetime_format=nil>, @logdev=#<Logger::LogDevice:0x00007fe01d743da8 @shift_period_suffix="%Y%m%d", @shift_size=1048576, @shift_age=0, @filename=#<Pathname:/Users/jfrey/dev/manageiq/log/automation.log>, @dev=#<File:/Users/jfrey/dev/manageiq/log/automation.log>, @binmode=false, @mon_data=#<Monitor:0x00007fe01d743d80>, @mon_data_owner_object_id=39840>, @write_lock=#<Thread::Mutex:0x00007fe01d743c90>, @local_levels={}> received :error with unexpected arguments expected: ("<AEMethod /my/automate/method> /Shared/Methods/RaiseException:8:in `some_method'") got: ("<AEMethod /my/automate/method> The following error occurred during method evaluation:") (1 time) ("<AEMethod /my/automate/method> RuntimeError: ") (1 time) ("Method STDERR: -: Tried to load unspecified class: Range (Psych::DisallowedClass)") (1 time) # ./spec/engine/miq_ae_method_spec.rb:360:in `block (5 levels) in <main>' # /Users/jfrey/.gem/ruby/2.7.6/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <main>' ``` [^1]: https://github.com/ManageIQ/manageiq-automation_engine/blob/77dbf078519c6b5da34c66da54bf51d1643182c5/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_method.rb#L270
Fryguy
force-pushed
the
fix_psych_safe_load
branch
from
February 13, 2023 21:18
35d9bf2
to
b846182
Compare
Checked commit Fryguy@b846182 with ruby 2.6.10, rubocop 1.28.2, haml-lint 0.35.0, and yamllint |
jrafanie
approved these changes
Feb 13, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The script_info is constructed to give metadata about the script provided by the user. One of the fields uses a Range 1 to denote the start and end lines of the code. The script_info is passed as a yaml payload to the external executor, but newer version of Psych do not permit Range objects by default, so it fails to deserialize.
This commit allows that specific class and ensure we use safe_load for backward compatibility.
Without this change, we get the following errors when running miq_ae_method_spec.rb:
@jrafanie Please review. cc @agrare
Footnotes
https://github.com/ManageIQ/manageiq-automation_engine/blob/77dbf078519c6b5da34c66da54bf51d1643182c5/lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_method.rb#L270 ↩