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

Avoid duplicating network definitions in multiple locations #510

Merged
merged 16 commits into from
Sep 9, 2016

Conversation

vuntz
Copy link
Member

@vuntz vuntz commented Jun 24, 2016

This makes dealing with the network config more difficult, as some bits might get outdated.

Instead, we centralize the definitions in the network role, and have proper API for accessing this easily.

This goes with crowbar/crowbar-ha#119, crowbar/crowbar-hyperv#25 and crowbar/crowbar-openstack#415.

@vuntz vuntz added the wip label Jun 24, 2016
nil
return nil unless self.crowbar["crowbar"]["network"].key?(type)
return nil unless @node["network"]["networks"].key?(type)
@node["network"]["networks"][type].merge(self.crowbar["crowbar"]["network"][type])

Choose a reason for hiding this comment

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

Style/RedundantSelf: Redundant self detected. (https://github.com/bbatsov/ruby-style-guide#no-self-unless-required)

# Error out if we were handed an invalid conduit mapping.
unless base_ifs.all?{ |i|i.is_a?(String) && ::Nic.exists?(i) }
raise ::ArgumentError.new("Conduit mapping \"#{conduit}\" for network \"#{name}\" is not sane: #{base_ifs.inspect}")
unless base_ifs.all? { |i|i.is_a?(String) && ::Nic.exists?(i) }

Choose a reason for hiding this comment

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

Style/SpaceAroundBlockParameters: Space after closing | missing.

@vuntz vuntz force-pushed the network-db2 branch 3 times, most recently from a6f5bf1 to 4866a44 Compare June 24, 2016 15:20
base_ifs = conduit_map[conduit]["if_list"]
addr = if network.address
IP.coerce("#{network.address}/#{network.netmask}")
else

Choose a reason for hiding this comment

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

Style/EmptyElse: Redundant else-clause.

Copy link
Member Author

@vuntz vuntz Jun 24, 2016

Choose a reason for hiding this comment

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

Some people in the team like to keep the explicit else here, so keeping it.

@vuntz vuntz force-pushed the network-db2 branch 3 times, most recently from bbecf03 to f5eb81c Compare June 24, 2016 15:25
The usage attribute is actually the same as the network name, so it's
just redundant.

Also, the node attribute is completely useless.
The full network definitions are already available through the
network-config-default role. However, we still allow overriding some
settings on node-specific attributes, as this can be useful (to specify
a node-specific conduit, for instance).
The full network definitions are already available through the
network-config-default role. However, we still allow overriding some
settings on node-specific attributes, as this can be useful (to specify
a node-specific conduit, for instance).
@toabctl
Copy link
Contributor

toabctl commented Jul 25, 2016

lgtm (but hav not tested it)

@toabctl toabctl removed their assignment Jul 25, 2016
vuntz added 11 commits July 25, 2016 10:14
There's no need to provide an interface or interface list anymore: this
will now be resolved on demand. This makes it a bit cheaper to create
network objects.
We do this instead of accessing attributes, in order to centralize the
location of the network definitions, so it can be changed.
Use the correct NodeObject methods instead.
We only require the address there. The definition can still be
overridden in node attributes if needed, but the code is now able to
look at the network definition directly in the network role.
When a node is discovered, but not allocated, it is not assigned an IP
address in the admin network yet. Due to the dhcp template interpreting
"no IP" as "deny booting", this resulted in reboot of discovered nodes
blocking the nodes.

Now in such cases, we simply take the current IP address of the node.
We were blindly converting attributes such as router_pref, vlan and mtu
to integer; we should only do this if they're not nil.
This avoids having to know about how the network attributes are
structured.
We need the network role on the nodes for the "installing" state as the
provisioner-server node (usually, the admin server) needs to have access
to the full network definition for that node, which is only possible if
the network role is assigned to the node.
@aspiers
Copy link
Member

aspiers commented Jul 28, 2016

Since making #575 I suddenly feel I understand a lot of this code, so this stays on my review TODO list.

@rhafer rhafer self-assigned this Sep 8, 2016
networks = {}
crowbar["crowbar"]["network"].each do |name, data|
# note that node might not be part of network proposal yet (for instance:
# if discovered, and IP got allocated by user)
Copy link
Contributor

Choose a reason for hiding this comment

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

@vuntz I might be missing something here, but if the node is not part of the network proposal yet, I think we'd not even get here. Because crowbar["crowbar"]["network"] should also be empty in that case.

Copy link
Contributor

Choose a reason for hiding this comment

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

@vuntz please ignore that. It can actually happen when allocating an IP on the node before allocating the node. (It also happened before you added 578947a)

@rhafer
Copy link
Contributor

rhafer commented Sep 8, 2016

Just for the record. I am still +1 on this. @toabctl how about you?

@vuntz: Do we need to provide some cleanup to deduplicate the node.crowbar.network attributes for people upgrading from older releases?

@toabctl toabctl self-assigned this Sep 8, 2016
@@ -39,7 +39,7 @@ def self.list_networks(node)
def self.get_network_by_type(node, type)
unless node[:crowbar][:network].nil?
[type, "admin"].uniq.each do |usage|
if found = node[:crowbar][:network].find { |net, data| data[:usage] == usage }
if found = node[:crowbar][:network].find { |net, data| net == usage }
Copy link
Contributor

@toabctl toabctl Sep 9, 2016

Choose a reason for hiding this comment

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

Unrelated to that line (but to the commit and I can't comment on the commit message): Not sure if that file is ever used for testing but in crowbar_framework/spec/fixtures/offline_chef/role_crowbar-admin_crowbar_com.json is still [:crowbar][:network][:admin][:usage] and [:crowbar][:network][:bmc][:usage].
But can be done in a follow-up PR.

@vuntz
Copy link
Member Author

vuntz commented Sep 9, 2016

@vuntz: Do we need to provide some cleanup to deduplicate the node.crowbar.network attributes for people upgrading from older releases?

I guess it'd be nice, although not mandatory.

@toabctl
Copy link
Contributor

toabctl commented Sep 9, 2016

+1 (but I haven't tested it)

@vuntz vuntz merged commit a628c77 into crowbar:master Sep 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants