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

Start moving away from search queries to static config items for cookbooks #947

Merged
merged 11 commits into from
Jan 16, 2017

Conversation

vuntz
Copy link
Member

@vuntz vuntz commented Jan 3, 2017

The static config items are actually data bag items (for now).

The main benefits are:

  • performance improvement (as a search query can be expensive)
  • going in the direction of not depending on centralized chef-server
  • in some cases, simplification of the cookbooks

The rake task will be used from barclamp_install.rb so that the config items get regenerated when the code is updated (so that there's no need to reapply a barclamp to get an up-to-date config item with the new fields).

Marking as WIP as I'd like to gather feedback; but this seems to work quite well.


barclamps.each do |barclamp|
begin
cls = eval("#{barclamp.camelize}Service")

Choose a reason for hiding this comment

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

Lint/Eval: The use of eval is a serious security risk.


barclamps.each do |barclamp|
begin
cls = eval("#{barclamp.camelize}Service")

Choose a reason for hiding this comment

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

Lint/Eval: The use of eval is a serious security risk.


Chef::DataBagItem.load(data_bag_name, group)
rescue Net::HTTPServerException
db = begin

Choose a reason for hiding this comment

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

Lint/UselessAssignment: Useless assignment to variable - db. (https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars)


Chef::DataBagItem.load(data_bag_name, group)
rescue Net::HTTPServerException
db = begin

Choose a reason for hiding this comment

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

Lint/UselessAssignment: Useless assignment to variable - db. (https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars)


execute "pip install --index-url http://#{proxy_addr}:#{proxy_port}/files/pip_cache/simple/ uwsgi" do
execute "pip install --index-url #{provisioner_config["root_url"]}/files/pip_cache/simple/ uwsgi" do

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [102/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength)


execute "pip install --index-url http://#{proxy_addr}:#{proxy_port}/files/pip_cache/simple/ uwsgi" do
execute "pip install --index-url #{provisioner_config["root_url"]}/files/pip_cache/simple/ uwsgi" do

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [102/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength)

template "/etc/ntp.conf" do
owner "root"
group "root"
mode 0644
source "ntp.conf.erb"
variables(ntp_servers: ntp_servers,
admin_interface: admin_interface,
admin_interface: local_admin_address,

Choose a reason for hiding this comment

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

Style/AlignHash: Align the elements of a hash literal if they span more than one line.

template "/etc/ntp.conf" do
owner "root"
group "root"
mode 0644
source "ntp.conf.erb"
variables(ntp_servers: ntp_servers,
admin_interface: admin_interface,
admin_interface: local_admin_address,

Choose a reason for hiding this comment

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

Style/AlignHash: Align the elements of a hash literal if they span more than one line.

provisioner_address = provisioner_config["server"]

if provisioner_address
Chef::Log.info("Checking we can ping #{provisioner_address}; " +

Choose a reason for hiding this comment

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

Style/LineEndConcatenation: Use \ instead of + or << to concatenate those strings.

provisioner_address = provisioner_config["server"]

if provisioner_address
Chef::Log.info("Checking we can ping #{provisioner_address}; " +

Choose a reason for hiding this comment

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

Style/LineEndConcatenation: Use \ instead of + or << to concatenate those strings.

@@ -377,5 +377,60 @@ def self.size_to_bytes(s)
end
end
end

class Config
def self.node=(node)

Choose a reason for hiding this comment

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

Style/TrivialAccessors: Use attr_writer to define trivial writer methods. (https://github.com/bbatsov/ruby-style-guide#attr_family)

@@ -377,5 +377,60 @@ def self.size_to_bytes(s)
end
end
end

class Config
def self.node=(node)

Choose a reason for hiding this comment

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

Style/TrivialAccessors: Use attr_writer to define trivial writer methods. (https://github.com/bbatsov/ruby-style-guide#attr_family)

@vuntz
Copy link
Member Author

vuntz commented Jan 9, 2017

IMHO, this is ready for reviews (& merging, if people are fine with this).

@vuntz
Copy link
Member Author

vuntz commented Jan 9, 2017

Oh, we'll want crowbar/crowbar#2302 at the same time.

proxy_addr = provisioner[:fqdn]
proxy_port = provisioner[:provisioner][:web_port]
provisioner_config = BarclampLibrary::Barclamp::Config.load("core", "provisioner")
index_url = "#{provisioner_config["root_url"]}/files/pip_cache/simple/"

Choose a reason for hiding this comment

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

Style/StringLiteralsInInterpolation: Prefer single-quoted strings inside interpolations.

old_install_url = "#{web_path}/install"

web_path = "#{provisioner_web}/#{node[:target_platform]}/#{arch}"
web_path = "#{provisioner_config["root_url"]}/#{node[:target_platform]}/#{arch}"

Choose a reason for hiding this comment

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

Style/StringLiteralsInInterpolation: Prefer single-quoted strings inside interpolations.

provisioner_web = "http://#{admin_ip}:#{web_port}"

web_path = "#{provisioner_web}/#{node[:platform]}-#{node[:platform_version]}/#{arch}"
web_path = "#{provisioner_config["root_url"]}/#{node[:platform]}-#{node[:platform_version]}/#{arch}"

Choose a reason for hiding this comment

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

Style/StringLiteralsInInterpolation: Prefer single-quoted strings inside interpolations.

The goal of this is to allow barclamps to export the relevant config
bits to data bag items, so that nodes that are either not part of this
proposal but need config from that barclamp or nodes that require info
about other nodes in this proposal, can simply load the data bag item.

We also cache the config to avoid loading it multiple times per run.

This will help reduce the amount of search queries that are done from
the clients to the chef server.
There are more uses of search queries for the provisioner-server node,
but let's ignore that for now.
This will be used when we need to load the config from the rails app (to
avoid looking at proposals).
When no instance is specified and we can't detect which one to use, then
try with "default", and if that doesn't work, find the first instance
that has an applied proposal for this barclamp.

This makes it possible to do something like Config.load("openstack",
"nova") without having to care what's the instance of the applied nova
proposal -- which is okay because there's only one applied proposal for
that barclamp.
On installation, the data bag configuration is created before the admin
server gets allocated an IP address. So we need to deal with the case
where the node may not have an admin network in the code.

This also means we will need to regenerate the data bag configuration at
some point; this will be done in the install script, after we move the
admin server to hardware-installing.
Copy link
Contributor

@dirkmueller dirkmueller left a comment

Choose a reason for hiding this comment

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

can you fix the houndci issues ? I'm in general happy about the change otherwise.

@vuntz
Copy link
Member Author

vuntz commented Jan 12, 2017

@dirkmueller Added two commits to fix the remaining hound comments.

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.

6 participants