Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Send mapped statuses #9

Merged
merged 1 commit into from
Oct 19, 2021
Merged

Send mapped statuses #9

merged 1 commit into from
Oct 19, 2021

Conversation

ofedoren
Copy link
Member

No description provided.

@ofedoren
Copy link
Member Author

Hm... :/ Not sure why the test failed, the new snapshot looks OK to me.

"proxy" => proxy,
"body" => @json_body ? body.to_json : body,
"keywords" => keywords,
},
}.merge(statuses),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you merging instead of just building the hash?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, from my perspective it looks cleaner, but if you prefer explicit style, I can refactor :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am good, I just thought there is something behind this.


def process_statuses
stats = @body["metrics"]["resources"]["values"].collect { |s| [s[0], s[2]] }
.to_h
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be resistant to missing keys, please add rescue method block and log a warning and return stats with all values set to zero.

You do not need to break at 80th column, unless you prefer to do it.

applied: stats["changed"] + stats["corrective_change"],
failed: stats["failed"] + stats["failed_to_restart"],
pending: stats["scheduled"],
other: stats["restarted"] + stats["skipped"] + stats["out_of_sync"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem why tests fail is that you use Ruby symbols here, for the best performance I am using strings everywhere since JSON deserialization is into strings by default.

pending: @body["status"]["pending"] || 0, # It's only present in check mode
other: @body["status"]["skipped"],
}
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to add a rescue block and return zeroes in case anything goes wrong, drop a warning into logs as well. These keys should be always present but for consistency with Puppet.

@lzap
Copy link
Member

lzap commented Oct 19, 2021

I have just realized that not all output keys are strings actually, I am fixing that in another PR. Adding a test to ensure this so we won't run into this in the future.

@lzap
Copy link
Member

lzap commented Oct 19, 2021

I pushed a huge refactoring of tests, there are now tests for both Puppet and Ansible and for all fixtures we have (tests are created dynamically).

Also there is an extra test that fails when there is a symbol hash key instead of string.

I moved all fixtures from contrib/fixtures to test/fixtures and merged them with existing puppet ones.

d71bad9..ca6d93e

@lzap
Copy link
Member

lzap commented Oct 19, 2021

Please rebase, simply delete all snapshots and run tests once to write them over: rm test/snapshots/*

@ofedoren
Copy link
Member Author

@lzap, updated.

@lzap
Copy link
Member

lzap commented Oct 19, 2021

It works fine, thanks.

@lzap lzap merged commit dd74c6a into theforeman:develop Oct 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants