From 18ee75a862fe97d01201f9a5d33649ffba3f9e67 Mon Sep 17 00:00:00 2001 From: Olivier ORAND Date: Wed, 29 Nov 2023 16:22:00 +0000 Subject: [PATCH] tasks(repackage_boshreleases_fallback): fix deserialization As of Ruby 3.1, if you use YAML.load_file, you must explicitly list the classes that are allowed for deserialization. Otherwise, a `Psych::DisallowedClass` error will be thrown. --- .../repackage_releases_fallback.rb | 2 +- .../bosh_connection_refused/errors.yml | 20 +++++++++++++++++++ .../repackage_releases_fallback_spec.rb | 8 ++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 spec/tasks/repackage_boshreleases_fallback/bosh_connection_refused/errors.yml diff --git a/concourse/tasks/repackage_boshreleases_fallback/repackage_releases_fallback.rb b/concourse/tasks/repackage_boshreleases_fallback/repackage_releases_fallback.rb index ec5518adb..2abe0c12e 100644 --- a/concourse/tasks/repackage_boshreleases_fallback/repackage_releases_fallback.rb +++ b/concourse/tasks/repackage_boshreleases_fallback/repackage_releases_fallback.rb @@ -23,7 +23,7 @@ class RepackageReleasesFallback def initialize(repackaged_error_filepath = "") @repackaged_errors = if File.exist?(repackaged_error_filepath) - YAML.load_file(repackaged_error_filepath, aliases: true) || {} + YAML.load_file(repackaged_error_filepath, aliases: true, permitted_classes: [Tasks::Bosh::BoshCliError]) || {} else {} end diff --git a/spec/tasks/repackage_boshreleases_fallback/bosh_connection_refused/errors.yml b/spec/tasks/repackage_boshreleases_fallback/bosh_connection_refused/errors.yml new file mode 100644 index 000000000..45676a13d --- /dev/null +++ b/spec/tasks/repackage_boshreleases_fallback/bosh_connection_refused/errors.yml @@ -0,0 +1,20 @@ +--- +Bosh director: !ruby/exception:Tasks::Bosh::BoshCliError + message: |- + Stderr: + Stdout: + { + "Tables": null, + "Blocks": null, + "Lines": [ + "Fetching info:\n Performing request GET 'https://192.168.116.158:25555/info':\n Performing GET request:\n Retry: Get \"https://192.168.116.158:25555/info\": dial tcp 192.168.116.158:25555: connect: connection refused", + "Exit code 1" + ] + } + backtrace: + - "/tmp/build/22f65861/cf-ops-automation/lib/tasks/bosh/executor.rb:39:in `handle_bosh_cli_response'" + - "/tmp/build/22f65861/cf-ops-automation/lib/tasks/bosh/executor.rb:34:in `run_command'" + - "/tmp/build/22f65861/cf-ops-automation/lib/tasks/bosh/list_releases.rb:7:in `execute'" + - "/tmp/build/22f65861/cf-ops-automation/concourse/tasks/repackage_boshreleases/repackage_releases.rb:133:in `filter_releases'" + - "/tmp/build/22f65861/cf-ops-automation/concourse/tasks/repackage_boshreleases/repackage_releases.rb:32:in `process'" + - cf-ops-automation/concourse/tasks/repackage_boshreleases/run.rb:42:in `
' diff --git a/spec/tasks/repackage_boshreleases_fallback/repackage_releases_fallback_spec.rb b/spec/tasks/repackage_boshreleases_fallback/repackage_releases_fallback_spec.rb index 3519796d8..11a66821c 100644 --- a/spec/tasks/repackage_boshreleases_fallback/repackage_releases_fallback_spec.rb +++ b/spec/tasks/repackage_boshreleases_fallback/repackage_releases_fallback_spec.rb @@ -42,6 +42,14 @@ context "when errors file contains errors" do let(:repackaged_releases_path) { File.join(basedir, 'download_failures') } + it "creates an object with errors" do + expect(repackage_releases_fallback.has_errors?).to be_truthy + end + end + + context "when bosh returns an errors" do + let(:repackaged_releases_path) { File.join(basedir, 'bosh_connection_refused') } + it "creates an object with errors" do expect(repackage_releases_fallback.has_errors?).to be_truthy end