Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for yast2-configuration-management
- Loading branch information
Showing
5 changed files
with
223 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) [2018] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "y2firstboot/clients/configuration_management" | ||
|
||
Y2Firstboot::Clients::ConfigurationManagement.new.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) [2018] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "yast" | ||
require "configuration_management/clients/provision" | ||
require "configuration_management/configurators/base" | ||
|
||
Yast.import "ProductFeatures" | ||
|
||
module Y2Firstboot | ||
module Clients | ||
# This client is meant to be used in firstboot | ||
class ConfigurationManagement | ||
# Runs the client | ||
def run | ||
configurator = Yast::ConfigurationManagement::Configurators::Base.for(config) | ||
configurator.prepare | ||
Yast::ConfigurationManagement::Clients::Provision.new.run | ||
end | ||
|
||
private | ||
|
||
# @return [Hash] Default settings | ||
FIXED_SETTINGS = { "type" => "salt", "mode" => "masterless" }.freeze | ||
|
||
# Returns the configuration management configuration | ||
# | ||
# It relies in the configuration found in the control file. | ||
# | ||
# @return [Yast::ConfigurationManagement::Configurations::Base] | ||
def config | ||
settings = settings_from_control_file.merge(FIXED_SETTINGS) | ||
Yast::ConfigurationManagement::Configurations::Base.import(settings) | ||
end | ||
|
||
# Retrieves the configuration management settings found in the control file | ||
# | ||
# It returns a minimal configuration if none is found. | ||
# | ||
# @return [Hash] | ||
def settings_from_control_file | ||
Yast::ProductFeatures.GetFeature("globals", "configuration_management") || {} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
srcdir = File.expand_path("../../src", __FILE__) | ||
y2dirs = ENV.fetch("Y2DIR", "").split(":") | ||
ENV["Y2DIR"] = y2dirs.unshift(srcdir).join(":") | ||
|
||
require "yast" | ||
require "pathname" | ||
|
||
TESTS_PATH = Pathname.new(File.dirname(__FILE__)) | ||
FIXTURES_PATH = TESTS_PATH.join("fixtures") | ||
|
||
if ENV["COVERAGE"] | ||
require "simplecov" | ||
SimpleCov.start do | ||
add_filter "/test/" | ||
end | ||
|
||
# for coverage we need to load all ruby files | ||
src_location = File.expand_path("../../src", __FILE__) | ||
Dir["#{src_location}/{module,lib}/**/*.rb"].each { |f| require_relative f } | ||
|
||
# use coveralls for on-line code coverage reporting at Travis CI | ||
if ENV["TRAVIS"] | ||
require "coveralls" | ||
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ | ||
SimpleCov::Formatter::HTMLFormatter, | ||
Coveralls::SimpleCov::Formatter | ||
] | ||
end | ||
end | ||
|
||
RSpec.configure do |config| | ||
config.expect_with :rspec do |expectations| | ||
# This option will default to `true` in RSpec 4. It makes the `description` | ||
# and `failure_message` of custom matchers include text for helper methods | ||
# defined using `chain`, e.g.: | ||
# be_bigger_than(2).and_smaller_than(4).description | ||
# # => "be bigger than 2 and smaller than 4" | ||
# ...rather than: | ||
# # => "be bigger than 2" | ||
expectations.include_chain_clauses_in_custom_matcher_descriptions = true | ||
end | ||
|
||
config.mock_with :rspec do |mocks| | ||
# Prevents you from mocking or stubbing a method that does not exist on | ||
# a real object. This is generally recommended, and will default to | ||
# `true` in RSpec 4. | ||
mocks.verify_partial_doubles = true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env rspec | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) [2018] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require_relative "../../test_helper" | ||
require "y2firstboot/clients/configuration_management" | ||
require "configuration_management/configurators/salt" | ||
|
||
describe Y2Firstboot::Clients::ConfigurationManagement do | ||
subject(:client) { described_class.new } | ||
|
||
describe "#run" do | ||
let(:provisioner) do | ||
instance_double(Yast::ConfigurationManagement::Clients::Provision, run: nil) | ||
end | ||
let(:configurator) do | ||
instance_double(Yast::ConfigurationManagement::Configurators::Salt, prepare: nil) | ||
end | ||
let(:settings) { { "states_roots" => ["/srv/salt"] } } | ||
|
||
before do | ||
allow(Yast::ProductFeatures).to receive(:GetFeature) | ||
.with("globals", "configuration_management") | ||
.and_return(settings) | ||
allow(Yast::ConfigurationManagement::Clients::Provision).to receive(:new) | ||
.and_return(provisioner) | ||
allow(Yast::ConfigurationManagement::Configurators::Base).to receive(:for) | ||
.and_return(configurator) | ||
end | ||
|
||
it "runs the provisioner" do | ||
expect(provisioner).to receive(:run) | ||
client.run | ||
end | ||
|
||
it "uses the configuration from the control file" do | ||
expect(Yast::ConfigurationManagement::Configurators::Base).to receive(:for) do |config| | ||
expect(config.states_roots).to include(Pathname.new("/srv/salt")) | ||
configurator | ||
end | ||
client.run | ||
end | ||
|
||
context "when type or mode are specified in the configuration" do | ||
let(:settings) { { "type" => "puppet", "mode" => "client" } } | ||
|
||
it "forces type and mode" do | ||
expect(Yast::ConfigurationManagement::Configurators::Base).to receive(:for) | ||
.with(an_object_having_attributes(type: "salt", mode: :masterless)) | ||
.and_return(configurator) | ||
client.run | ||
end | ||
end | ||
|
||
context "when no settings are specified" do | ||
let(:settings) { nil } | ||
|
||
it "uses the default configuration" do | ||
expect(Yast::ConfigurationManagement::Configurators::Base).to receive(:for) | ||
.with(an_object_having_attributes(type: "salt")).and_return(configurator) | ||
client.run | ||
end | ||
end | ||
end | ||
end |