Skip to content
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

(HC-31) Handle type change from scalar -> array #26

Merged
merged 3 commits into from
Dec 10, 2015
Merged

(HC-31) Handle type change from scalar -> array #26

merged 3 commits into from
Dec 10, 2015

Conversation

vilmibm
Copy link
Contributor

@vilmibm vilmibm commented Dec 8, 2015

Previously, if a setting existed on disk as a scalar and the puppet resource changed the setting's type to array, the file would not be updated to reflect this explicit type.

In addition to the new unit test, I manually tested this and saw the fix working locally. I am unable to run the acceptance tests.

I've never touched types and providers before and have barely written ruby, so in many ways I feel like I was coding in the dark. Extra scrutiny on this PR would be great!

@vilmibm vilmibm changed the title (HC-31) Handle type change from scalar -> array [review only] (HC-31) Handle type change from scalar -> array Dec 8, 2015
@MSLilah
Copy link
Contributor

MSLilah commented Dec 9, 2015

The reason we're seeing this issue is because of all the weirdness around Puppet's :array-matchingsetting, and how we can't differentiate between a single-element array and a scalar value. I think it would be awesome if we could potentially do something in the value function to differentiate those cases, but I'm not sure how we would do that, especially since we need to ensure that the module doesn't register a change to a setting every time if the value is identical to what's already there and it's a scalar value.

In light of that, I'm good with the approach taken here. It feels like the best approach given the circumstances. 👍

@vilmibm vilmibm changed the title [review only] (HC-31) Handle type change from scalar -> array (HC-31) Handle type change from scalar -> array Dec 9, 2015
File.open(tmpfile, 'w') do |fh|
fh.write('ennui: yes')
end
validate_file('ennui: yes')
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a nitpick, but we probably don't need to validate the file, since it's just testing the behavior of write, right?
Similar thing in the other test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

absolutely. i normally wouldn't do this but i was a stranger in a strange land and any bit of sanity checking was helping me. i left em in because i figured they wouldn't hurt.

@jpinsonault
Copy link
Contributor

I'm also not super familiar with types, providers, and these tests, but this looks good to me. I just had one comment but I'm 👍

end

if type == 'array_element'
Array(@resource[:value]).each do |v|
Copy link

Choose a reason for hiding this comment

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

I think this can be return Array(@resource[:value]).any? {|v| value.flatten.include?(v) }, but I'm not sure if that makes it more readable or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the .any? makes the intent clearer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems better. i was just preserving what was there previously.

Previously, if a setting existed on disk as a scalar and the puppet
resource changed the setting's type to array, the file would not be
updated to reflect this explicit type.
@vilmibm
Copy link
Contributor Author

vilmibm commented Dec 10, 2015

Updated @jpinsonault @haus

@haus
Copy link

haus commented Dec 10, 2015

👍

1 similar comment
@jpinsonault
Copy link
Contributor

👍

jpinsonault added a commit that referenced this pull request Dec 10, 2015
(HC-31) Handle type change from scalar -> array
@jpinsonault jpinsonault merged commit 7c49628 into puppetlabs:master Dec 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants