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

Fixes #21114 - Update error message #375

Merged
merged 1 commit into from Sep 29, 2017
Merged

Fixes #21114 - Update error message #375

merged 1 commit into from Sep 29, 2017

Conversation

chris1984
Copy link
Member

No description provided.

@theforeman-bot
Copy link
Member

@chris1984, the Redmine ticket used is for a different project than the one associated with this GitHub repository. Please either:

If changing the ticket number used, remember to update the PR title and the commit message (using git commit --amend).


This message was auto-generated by Foreman's prprocessor

@@ -3,7 +3,7 @@
# puppet fact names are converted from ethX.X and ethX:X to ethX_X
# so for alias and vlan interfaces we have to modify the name accordingly
$interface_fact_name = regsubst($foreman_proxy::dhcp_interface, '[.:]', '_')
$ip = pick($::foreman_proxy::dhcp_pxeserver, inline_template("<%= scope.lookupvar('::ipaddress_${interface_fact_name}') %>"))
$ip = pick_default($::foreman_proxy::dhcp_pxeserver, inline_template("<%= scope.lookupvar('::ipaddress_${interface_fact_name}', '') %>"), '')
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should depend on puppetlabs-stdlib 4.19.0 already since it's very new, but with that it can be $ip = pick_default($::foreman_proxy::dhcp_pxeserver, fact("ipaddress_${interface_fact_name}")).

@chris1984
Copy link
Member Author

@ekohl thanks, fixed with the correction, can you look at it when you get another chance please?

@iNecas
Copy link
Member

iNecas commented Sep 26, 2017

👍

@ekohl
Copy link
Member

ekohl commented Sep 27, 2017

Could you add a testcase? Untested, but something adding the following to spec/classes/foreman_proxy__proxydhcp__spec.rb should do it:

context "on a non-existing interface" do
  let :pre_condition do
    "class { 'foreman_proxy':
      dhcp_interface => 'doesnotexist',
    }"
  end

  it { should raise_error(Puppet::Error, /Could not get the ip address from fact ipaddress_doesnotexist/) }
end

You should also increase the puppetlabs-stdlib minimum version to 4.19.0 in metadata.json since the function fact was introduced there.

@chris1984
Copy link
Member Author

@ekohl thanks for the help with the tests and the corrections, I have made the requested changes. Can you review when you get a chance, please?

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Looks good. Some minor style tweaks would be nice.

@@ -183,6 +183,16 @@
}"
end

context "on a non-existing interface" do
Copy link
Member

Choose a reason for hiding this comment

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

The indenting looks inconsistent.

Copy link
Member Author

Choose a reason for hiding this comment

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

I looked in Atom and it at spot 7 and the other contexts are as well

Copy link
Member

Choose a reason for hiding this comment

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

It looks like you pasted in the middle of another context. That's why the indenting looks incorrect.

@@ -3,7 +3,7 @@
# puppet fact names are converted from ethX.X and ethX:X to ethX_X
# so for alias and vlan interfaces we have to modify the name accordingly
$interface_fact_name = regsubst($foreman_proxy::dhcp_interface, '[.:]', '_')
$ip = pick($::foreman_proxy::dhcp_pxeserver, inline_template("<%= scope.lookupvar('::ipaddress_${interface_fact_name}') %>"))
$ip = pick_default($::foreman_proxy::dhcp_pxeserver, fact("ipaddress_${interface_fact_name}"))
if ! is_ip_address($ip) {
fail("Could not get the ip address from fact ipaddress_${interface_fact_name}")
}
Copy link
Member

Choose a reason for hiding this comment

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

Just below the fold here we have more inline_template use. Could you also replace those with fact to keep it consistent?

@@ -3,7 +3,7 @@
# puppet fact names are converted from ethX.X and ethX:X to ethX_X
# so for alias and vlan interfaces we have to modify the name accordingly
$interface_fact_name = regsubst($foreman_proxy::dhcp_interface, '[.:]', '_')
$ip = pick($::foreman_proxy::dhcp_pxeserver, inline_template("<%= scope.lookupvar('::ipaddress_${interface_fact_name}') %>"))
$ip = pick_default($::foreman_proxy::dhcp_pxeserver, fact("ipaddress_${interface_fact_name}"))
if ! is_ip_address($ip) {
Copy link
Member

Choose a reason for hiding this comment

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

While you're at it, mind replacing this with the non-deprecated version to remove a deprecation warning? I think unless $ip =~ Stdlib::Compat::Ipv4 { should work. Same for the other 3 occurrences.

@chris1984
Copy link
Member Author

@ekohl can I get another review please, also see the comment about the indenting.

fail("Could not get the ip address from fact ipaddress_${interface_fact_name}")
}

$net = inline_template("<%= scope.lookupvar('::network_${interface_fact_name}') %>")
if ! is_ip_address($net) {
$net = fact("<%= scope.lookupvar('::network_${interface_fact_name}') %>")
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 fact("network_${interface_fact_name}")

fail("Could not get the network address from fact network_${interface_fact_name}")
}

$mask = inline_template("<%= scope.lookupvar('::netmask_${interface_fact_name}') %>")
if ! is_ip_address($mask) {
$mask = fact("<%= scope.lookupvar('::netmask_${interface_fact_name}') %>")
Copy link
Member

Choose a reason for hiding this comment

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

Here too.

@chris1984
Copy link
Member Author

@ekohl the tests are failing since it cant find the ip, do i need to update the tests as well, I made the changes you suggested.

@ekohl ekohl requested a review from mmoll September 29, 2017 18:34
@mmoll mmoll merged commit f291aa3 into theforeman:master Sep 29, 2017
@mmoll
Copy link
Contributor

mmoll commented Sep 29, 2017

merged, thanks @chris1984!

@chris1984 chris1984 deleted the update_error branch September 29, 2017 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants