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 #16951 - ipv6 compute orchestration #3943

Merged
merged 1 commit into from Nov 2, 2016

Conversation

timogoebel
Copy link
Member

No description provided.

@timogoebel
Copy link
Member Author

This can be tested with theforeman/foreman-digitalocean#16

Copy link
Contributor

@domcleal domcleal left a comment

Choose a reason for hiding this comment

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

find_address causes problems when IPv6 is not active on a v6-capable provider.

@@ -124,7 +128,7 @@ def setComputeDetails
attrs.each do |foreman_attr, fog_attr|
if foreman_attr == :mac
return false unless match_macs_to_nics(fog_attr)
elsif foreman_attr == :ip
elsif [:ip, :ip6].include?(foreman_attr)
value = vm.send(fog_attr) || find_address
Copy link
Contributor

Choose a reason for hiding this comment

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

find_address isn't IPv6 aware here, it'll call vm.ip_addresses which can return v4 addresses if the compute claims to provide v6 but vm.send(fog_attr) returns nil. You can reproduce this by not ticking the IPv6 box when using fog-digitalocean.

It probably needs to be changed to filter addresses from vm.ip_addresses depending on their type?

@timogoebel
Copy link
Member Author

@domcleal : The code is more reliable now. find_address filters the ip addresses by type and returns early if any other ip address is already set. I also removed the delCompute calls from validate_forman_attr as they would eventually try to delete the vm twice.

[test foreman]
[test katello]
[test upgrade]

@domcleal
Copy link
Contributor

domcleal commented Nov 1, 2016

[test foreman]

end
end

if ip.blank? && ip6.blank? && (compute_provides?(:ip) || compute_provides?(:ip6))
return failure(_("failed to acquire ip addresses from compute resource for %s") % name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Capitalise "Failed" and "IP", important in translated (and therefore user-visible) strings.

end
ip
end

def filter_ip_addresses(addresses, type)
check_method = type == :ip6 ? :ipv6? : :ipv4?
addresses.map {|ip| IPAddr.new(ip) rescue nil}.compact.select { |ip| ip.send(check_method) }.map(&:to_s)
Copy link
Contributor

Choose a reason for hiding this comment

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

select { |ip| ip.send(check_method) } can be written as select(&check_method)

elsif foreman_attr == :ip
value = vm.send(fog_attr) || find_address
elsif [:ip, :ip6].include?(foreman_attr)
value = vm.send(fog_attr) || find_address(foreman_attr)
self.send("#{foreman_attr}=", value)
return false unless validate_foreman_attr(value, ::Nic::Base, foreman_attr)
Copy link
Contributor

Choose a reason for hiding this comment

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

If the provider claims to provide :ip6 but it doesn't (e.g. foreman_digitalocean, don't tick IPv6), then this still throws an error if value.blank? and there's another blank value in the database. Don't call it if the value's blank?

2016-11-01T14:36:30 c50b235a [sql] [W] ip6  is already used by 

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, sorry. I have tested this with a fresh install and an empty database and it worked fine. I will make the necessary adjustments and add a test case for this.

test "are set for CR providing IPv6" do
an_ip6 = '2001:db8::1'
@cr.stubs(:provided_attributes).returns({:ip6 => :ip6})
@host.vm.expects(:ip6).returns(an_ip6)
Copy link
Contributor

Choose a reason for hiding this comment

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

A test that returns a blank value for :ip6 while claiming to provide ip4 + ip6 would be a good idea.

@timogoebel
Copy link
Member Author

@domcleal : Thanks for giving this another spin. I have fixed the issue and tested with more hosts. It should work fine now. Also improved the test coverage of this.

@domcleal domcleal merged commit b215c09 into theforeman:develop Nov 2, 2016
@domcleal
Copy link
Contributor

domcleal commented Nov 2, 2016

Merged, thanks @timogoebel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants