Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

15917 - plugin packager should retain the source deb/rpm

In the past source packages created by the plugin packager
where not created correctly and unusable.

Source packages are now created correctly on both Debian
and Redhat machines
  • Loading branch information...
commit 532a8d58e3b960bc55dc9d6179f247404f79779e 1 parent 68704fb
@ploubser ploubser authored ripienaar committed
View
17 lib/mcollective/pluginpackager/agent_definition.rb
@@ -44,8 +44,6 @@ def agent
if PluginPackager.check_dir_present agentdir
ddls = Dir.glob(File.join(agentdir, "*.ddl"))
agent[:files] = (Dir.glob(File.join(agentdir, "*")) - ddls)
- implementations = Dir.glob(File.join(@metadata[:name], "**"))
- agent[:files] += implementations unless implementations.empty?
else
return nil
end
@@ -76,19 +74,20 @@ def common
:dependencies => @dependencies.clone << @mccommon,
:description => "Common libraries for #{@metadata[:name]}"}
- commondir = File.join(@path, "util")
- ddldir = File.join(@path, "agent")
- validatordir = File.join(@path, "validator")
+ datadir = File.join(@path, "data", "**")
+ utildir = File.join(@path, "util", "**", "**")
+ ddldir = File.join(@path, "agent", "*.ddl")
+ validatordir = File.join(@path, "validator", "**")
- common[:files] += Dir.glob(File.join(ddldir, "*.ddl")) if PluginPackager.check_dir_present ddldir
- common[:files] += Dir.glob(File.join(validatordir, "*")) if PluginPackager.check_dir_present validatordir
+ [datadir, utildir, validatordir, ddldir].each do |directory|
+ common[:files] += Dir.glob(directory)
+ end
# We fail if there is no ddl file present
- if common[:files].empty?
+ if common[:files].grep(/^.*\.ddl$/).empty?
raise "cannot create package - No ddl file found in #{File.join(@path, "agent")}"
end
- common[:files] += Dir.glob(File.join(commondir,"*")) if PluginPackager.check_dir_present commondir
common[:files].empty? ? nil : common
end
end
View
11 plugins/mcollective/pluginpackager/debpackage_packager.rb
@@ -15,7 +15,7 @@ def initialize(plugin, pluginpath = nil, signature = nil, verbose = false)
@libdir = pluginpath || "/usr/share/mcollective/plugins/mcollective/"
@signature = signature
@tmpdir = ""
- @builddir = ""
+ @build_dir = ""
@targetdir = ""
end
@@ -29,7 +29,7 @@ def create_packages
@current_package_fullname = "mcollective-#{@plugin.metadata[:name]}-#{@current_package_type}" +
"_#{@plugin.metadata[:version]}-#{@plugin.iteration}"
- @build_dir = File.join(@tmpdir, @current_package_fullname)
+ @build_dir = File.join(@tmpdir, "#{@current_package_shortname}_#{@plugin.metadata[:version]}")
Dir.mkdir @build_dir
prepare_tmpdirs data
@@ -97,7 +97,8 @@ def create_install
begin
File.open(File.join(@build_dir, "debian", "#{@current_package_shortname}.install"), "w") do |f|
@current_package_data[:files].each do |filename|
- f.puts "#{File.join(@libdir, filename.gsub(/#{plugin.path}|\.\//, ""))} #{File.join(@libdir, File.dirname(filename).gsub(/#{plugin.path}|\.\//,""))}"
+ extended_filename = File.join(@libdir, File.expand_path(filename).gsub(/#{File.expand_path(plugin.path)}|\.\//, ''))
+ f.puts "#{extended_filename} #{File.dirname(extended_filename)}"
end
end
rescue Exception => e
@@ -108,7 +109,9 @@ def create_install
def create_tar
begin
PluginPackager.do_quietly?(@verbose) do
- PluginPackager.safe_system "tar -Pcvzf #{File.join(@tmpdir,"#{@current_package_shortname}_#{@plugin.metadata[:version]}.orig.tar.gz")} #{@build_dir}"
+ Dir.chdir(@tmpdir) do
+ PluginPackager.safe_system "tar -Pcvzf #{File.join(@tmpdir,"#{@current_package_shortname}_#{@plugin.metadata[:version]}.orig.tar.gz")} #{@current_package_shortname}_#{@plugin.metadata[:version]}"
+ end
end
rescue Exception => e
raise "Could not create tarball - #{e}"
View
31 plugins/mcollective/pluginpackager/rpmpackage_packager.rb
@@ -20,6 +20,8 @@ def initialize(plugin, pluginpath = nil, signature = nil, verbose = false)
@verbose = verbose
@libdir = pluginpath || "/usr/libexec/mcollective/mcollective/"
@signature = signature
+ @rpmdir = `rpm --eval '%_rpmdir'`.chomp
+ @srpmdir = `rpm --eval '%_srcrpmdir'`.chomp
end
def create_packages
@@ -41,13 +43,19 @@ def create_packages
def create_package(type, data)
begin
+ tarfile = "#{@current_package_name}-#{@plugin.metadata[:version]}.tgz"
make_spec_file
- PluginPackager.do_quietly?(@verbose) do
- PluginPackager.safe_system("rpmbuild -ba #{"--quiet" unless verbose} #{"--sign" if @signature} #{File.join(@tmpdir, "SPECS", "#{type}.spec")} --buildroot #{File.join(@tmpdir, "BUILD")}")
+ PluginPackager.do_quietly?(verbose) do
+ Dir.chdir(@tmpdir) do
+ PluginPackager.safe_system("tar -cvzf #{File.join(@tmpdir, tarfile)} #{@current_package_name}-#{@plugin.metadata[:version]}")
+ end
+
+ PluginPackager.safe_system("rpmbuild -ta #{"--quiet" unless verbose} #{"--sign" if @signature} #{File.join(@tmpdir, tarfile)}")
end
- FileUtils.cp(File.join(`rpm --eval '%_rpmdir'`.chomp, "noarch", "#{@current_package_name}-#{@plugin.metadata[:version]}-#{@plugin.iteration}.noarch.rpm"), ".")
- FileUtils.cp(File.join(`rpm --eval '%_srcrpmdir'`.chomp, "#{@current_package_name}-#{@plugin.metadata[:version]}-#{@plugin.iteration}.src.rpm"), ".")
+ FileUtils.cp(File.join(@rpmdir, "noarch", "#{@current_package_name}-#{@plugin.metadata[:version]}-#{@plugin.iteration}.noarch.rpm"), ".")
+ FileUtils.cp(File.join(@srpmdir, "#{@current_package_name}-#{@plugin.metadata[:version]}-#{@plugin.iteration}.src.rpm"), ".")
+
puts "Created RPM and SRPM packages for #{@current_package_name}"
rescue Exception => e
raise RuntimeError, "Could not build package. Reason - #{e}"
@@ -57,7 +65,7 @@ def create_package(type, data)
def make_spec_file
begin
spec_template = ERB.new(File.read(File.join(File.dirname(__FILE__), "templates", "redhat", "rpm_spec.erb")), nil, "-")
- File.open(File.join(@tmpdir, "SPECS", "#{@current_package_type}.spec"), "w") do |f|
+ File.open(File.join(@tmpdir, "#{@current_package_name}-#{@plugin.metadata[:version]}" ,"#{@current_package_name}-#{@plugin.metadata[:version]}.spec"), "w") do |f|
f.puts spec_template.result(binding)
end
rescue Exception => e
@@ -66,24 +74,13 @@ def make_spec_file
end
def prepare_tmpdirs(data)
- make_rpm_dirs
data[:files].each do |file|
- targetdir = File.join(@tmpdir, "BUILD", @libdir, File.dirname(File.expand_path(file)).gsub(@plugin.target_path, ""))
+ targetdir = File.join(@tmpdir, "#{@current_package_name}-#{@plugin.metadata[:version]}", @libdir, File.dirname(File.expand_path(file)).gsub(@plugin.target_path, ""))
FileUtils.mkdir_p(targetdir) unless File.directory? targetdir
FileUtils.cp_r(file, targetdir)
end
end
- def make_rpm_dirs
- ["BUILD", "SOURCES", "SPECS", "SRPMS", "RPMS"].each do |dir|
- begin
- FileUtils.mkdir(File.join(@tmpdir, dir))
- rescue Exception => e
- raise RuntimeError, "Could not create #{dir} directory - #{e}"
- end
- end
- end
-
def cleanup_tmpdirs
FileUtils.rm_r @tmpdir if File.directory? @tmpdir
end
View
29 plugins/mcollective/pluginpackager/templates/redhat/rpm_spec.erb
@@ -9,24 +9,39 @@ Packager: <%= @plugin.metadata[:author] %>
BuildRoot: %buildroot
BuildArch: noarch
Group: System Tools
-
-<% @current_package_data[:dependencies].each do |dep|%>
+Source0: <%= "#{@current_package_name}-#{@plugin.metadata[:version]}.tgz" %>
+<% @current_package_data[:dependencies].each do |dep|-%>
Requires: <%= dep.is_a?(Array) ? "%s = %s" % [dep[0], dep[1]] : dep%>
-<% end %>
+<% end -%>
%description
-<%= @plugin.metadata[:description] -%>
+<%= @plugin.metadata[:description] %>
%prep
+%setup
%build
%install
+<% @dirs = [] -%>
+<% @package_files = [] -%>
+<% @current_package_data[:files].each do |file| -%>
+<% @dirs << File.dirname(File.join(@libdir, File.expand_path(file).gsub(/#{File.expand_path(plugin.path)}|\.\//, ''))) -%>
+<% @package_files << File.join(@libdir, File.expand_path(file).gsub(/#{File.expand_path(plugin.path)}|\.\//, '')) -%>
+<% end -%>
+rm -rf %{buildroot}
+<% @dirs.uniq.each do |dir| -%>
+%{__install} -d -m0755 %{buildroot}<%= dir%>
+<% end -%>
+<% @package_files -= @dirs %>
+<% @package_files.each do |package_file| -%>
+%{__install} -m0644 <%= (package_file[0].chr == '/') ? package_file[1..package_file.size-1]: package_file%> %{buildroot}<%=package_file %>
+<% end -%>
%files
%defattr(-,root,root,-)
-<% @current_package_data[:files].each do |file| -%>
-<%=@libdir + file.gsub(/#{plugin.path}|\.\//, '')%>
+<% @package_files.each do |file| -%>
+<%= file %>
<% end -%>
<% if @plugin.preinstall -%>
@@ -39,5 +54,5 @@ Requires: <%= dep.is_a?(Array) ? "%s = %s" % [dep[0], dep[1]] : dep%>
<% end -%>
%changelog
-* <%= Time.now.strftime("%a %b %d %Y") -%> - <%= @plugin.vendor%>
+* <%= Time.now.strftime("%a %b %d %Y") -%> <%= @plugin.metadata[:author]%> - <%= @plugin.metadata[:version]%>-<%= @plugin.iteration%>
- Built Package <%= @current_package_name-%>
View
57 spec/unit/pluginpackager/agent_definition_spec.rb
@@ -56,16 +56,17 @@ module PluginPackager
agent.packagedata[:agent].should == nil
end
- it "should populate the agent files if the agent directory is present and not empty" do
+ it "should add the agent file if the agent directory and implementation file is present" do
AgentDefinition.any_instance.expects(:common).returns(nil)
- PluginPackager.expects(:check_dir_present).with("tmpdir/agent").returns(true)
- File.stubs(:join).returns("tmpdir")
+ PluginPackager.stubs(:check_dir_present).returns(true)
File.stubs(:join).with(".", "agent").returns("tmpdir/agent")
- File.stubs(:join).with(".", "aggregate").returns("tmpdir/aggregate")
- Dir.stubs(:glob).returns(["file.rb", "implementation.rb"])
+ File.stubs(:join).with("tmpdir/agent", "*.ddl").returns("tmpdir/agent/*.ddl")
+ File.stubs(:join).with("tmpdir/agent", "*").returns("tmpdir/agent/*")
+ Dir.stubs(:glob).with("tmpdir/agent/*.ddl").returns([])
+ Dir.stubs(:glob).with("tmpdir/agent/*").returns(["implementation.rb"])
agent = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
- agent.packagedata[:agent][:files].should == ["file.rb", "implementation.rb"]
+ agent.packagedata[:agent][:files].should == ["implementation.rb"]
end
it "should add common package as dependency if present" do
@@ -82,38 +83,36 @@ module PluginPackager
end
describe "#common" do
- it "should populate the common files with only the ddl if util dir is empty" do
+ it "should populate the common files if there are any" do
AgentDefinition.any_instance.expects(:agent)
AgentDefinition.any_instance.expects(:client)
+ File.expects(:join).with(".", "data", "**").returns("datadir")
+ File.expects(:join).with(".", "util", "**", "**").returns("utildir")
+ File.expects(:join).with(".", "agent", "*.ddl").returns("ddldir")
+ File.expects(:join).with(".", "validator", "**").returns("validatordir")
+ Dir.expects(:glob).with("datadir").returns(["data.rb"])
+ Dir.expects(:glob).with("utildir").returns(["util.rb"])
+ Dir.expects(:glob).with("validatordir").returns(["validator.rb"])
+ Dir.expects(:glob).with("ddldir").returns(["agent.ddl"])
- PluginPackager.expects(:check_dir_present).with("./util").returns(false)
- PluginPackager.expects(:check_dir_present).with("./validator").returns(false)
- PluginPackager.expects(:check_dir_present).with("./agent").returns(true)
- Dir.stubs(:glob).returns(["file.rb"])
common = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
- common.packagedata[:common][:files].should == ["file.rb"]
- end
-
- it "should populate the common files if the common directory is present and not empty" do
- AgentDefinition.any_instance.expects(:agent)
- AgentDefinition.any_instance.expects(:client)
-
- PluginPackager.expects(:check_dir_present).with("./util").returns(true)
- PluginPackager.expects(:check_dir_present).with("./agent").returns(true)
- PluginPackager.expects(:check_dir_present).with("./validator").returns(true)
- Dir.stubs(:glob).with("./util/*").returns(["file.rb"])
- Dir.stubs(:glob).with("./agent/*.ddl").returns(["ddl.rb"])
- Dir.stubs(:glob).with("./validator/*").returns(["validator.rb"])
- common = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
- common.packagedata[:common][:files].should == ["ddl.rb", "validator.rb", "file.rb"]
+ common.packagedata[:common][:files].should == ["data.rb", "util.rb", "validator.rb", "agent.ddl"]
end
it "should raise an exception if the ddl file isn't present" do
- PluginPackager.expects(:check_dir_present).with("./agent").returns(false)
- PluginPackager.expects(:check_dir_present).with("./validator").returns(false)
+ File.expects(:join).with(".", "data", "**").returns("datadir")
+ File.expects(:join).with(".", "util", "**", "**").returns("utildir")
+ File.expects(:join).with(".", "agent", "*.ddl").returns("ddldir")
+ File.expects(:join).with(".", "agent").returns("ddldir")
+ File.expects(:join).with(".", "validator", "**").returns("validatordir")
+ Dir.expects(:glob).with("datadir").returns(["data.rb"])
+ Dir.expects(:glob).with("utildir").returns(["util.rb"])
+ Dir.expects(:glob).with("validatordir").returns(["validator.rb"])
+ Dir.expects(:glob).with("ddldir").returns([])
+
expect{
common = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
- }.to raise_error RuntimeError, "cannot create package - No ddl file found in ./agent"
+ }.to raise_error RuntimeError, "cannot create package - No ddl file found in ddldir"
end
end
View
8 spec/unit/plugins/mcollective/packagers/debpackage_packager_spec.rb
@@ -64,7 +64,7 @@ module PluginPackager
end
it "Should create the build dir" do
- Dir.expects(:mkdir).with("/tmp/mcollective-test_plugin-test_1-1")
+ Dir.expects(:mkdir).with("/tmp/mcollective-test_plugin-test_1")
@packager.create_packages
end
@@ -165,7 +165,7 @@ module PluginPackager
describe "#create_install" do
before :each do
@packager = DebpackagePackager.new(@plugin)
- @plugin.stubs(:path)
+ @plugin.stubs(:path).returns("")
end
it "should raise an exception if the install file can't be created" do
@@ -183,7 +183,7 @@ module PluginPackager
@packager.current_package_data = {:files => ["foo.rb"]}
@packager.create_install
install_file = File.read("#{tmpdir}/debian/test.install")
- install_file.should == "/usr/share/mcollective/plugins/mcollective/foo.rb /usr/share/mcollective/plugins/mcollective/.\n"
+ install_file.should == "/usr/share/mcollective/plugins/mcollective/foo.rb /usr/share/mcollective/plugins/mcollective\n"
end
end
@@ -228,7 +228,7 @@ module PluginPackager
@plugin.stubs(:metadata).returns(@plugin)
@plugin.stubs(:[]).with(:version).returns("1")
@plugin.stubs(:iteration).returns("1")
- PluginPackager.expects(:safe_system).with("tar -Pcvzf /tmp/test_1.orig.tar.gz /build_dir")
+ PluginPackager.expects(:safe_system).with("tar -Pcvzf /tmp/test_1.orig.tar.gz test_1")
@packager.create_tar
end
end
View
45 spec/unit/plugins/mcollective/packagers/rpmpackage_packager_spec.rb
@@ -83,8 +83,9 @@ module PluginPackager
end
it "should create the package" do
- PluginPackager.expects(:safe_system).with("rpmbuild -ba /tmp/SPECS/test.spec --buildroot /tmp/BUILD")
- FileUtils.expects(:cp).twice
+ Dir.expects(:chdir)
+ PluginPackager.expects(:safe_system).with("rpmbuild -ta /tmp/mcollective-testplugin-test-1.tgz")
+ FileUtils.expects(:cp).times(2)
@packager.tmpdir = "/tmp"
@packager.verbose = "true"
@packager.expects(:make_spec_file)
@@ -94,8 +95,9 @@ module PluginPackager
end
it "should sign the package if a signature is given" do
- PluginPackager.expects(:safe_system).with("rpmbuild -ba --sign /tmp/SPECS/test.spec --buildroot /tmp/BUILD")
- FileUtils.expects(:cp).twice
+ Dir.expects(:chdir)
+ PluginPackager.expects(:safe_system).with("rpmbuild -ta --sign /tmp/mcollective-testplugin-test-1.tgz")
+ FileUtils.expects(:cp).times(2)
@packager.signature = true
@packager.tmpdir = "/tmp"
@packager.verbose = "true"
@@ -107,6 +109,7 @@ module PluginPackager
it "should raise an error if the package can't be built" do
@packager = RpmpackagePackager.new(@plugin)
+ @packager.tmpdir = "/tmp"
@packager.expects(:make_spec_file)
PluginPackager.stubs(:do_quietly?).raises("foo")
expect{
@@ -117,7 +120,8 @@ module PluginPackager
describe "#make_spec_file" do
before :each do
- @packager = RpmpackagePackager.new("package")
+ @plugin = mock
+ @packager = RpmpackagePackager.new(@plugin)
end
it "should raise an exception if specfile cannot be built" do
@@ -129,11 +133,12 @@ module PluginPackager
it "should create the specfile from the erb" do
File.stubs(:read).returns("specfile")
- @packager.current_package_type = "test"
+ @plugin.stubs(:metadata).returns({:version => 2})
+ @packager.current_package_name = "test"
@packager.tmpdir = maketmpdir
- Dir.mkdir(File.join(@packager.tmpdir, "SPECS"))
+ Dir.mkdir(File.join(@packager.tmpdir, "test-2"))
@packager.make_spec_file
- File.read(File.join(@packager.tmpdir, "SPECS", "test.spec")).should == "specfile"
+ File.read(File.join(@packager.tmpdir, "test-2", "test-2.spec")).should == "specfile"
end
end
@@ -141,7 +146,6 @@ module PluginPackager
it "should create the tmp dirs and cp the package files" do
@plugin.stubs(:target_path).returns("")
packager = RpmpackagePackager.new(@plugin)
- packager.expects(:make_rpm_dirs)
FileUtils.expects(:mkdir_p)
File.stubs(:join).returns("/target")
FileUtils.expects(:cp_r).with("test.rb", "/target")
@@ -149,29 +153,6 @@ module PluginPackager
end
end
- describe "#make_rpm_dirs" do
- before :each do
- @packager = RpmpackagePackager.new("package")
- end
-
- it "should raise an exception if a directory can't be created" do
- File.expects(:join).raises("test error")
- expect{
- @packager.make_rpm_dirs
- }.to raise_error(RuntimeError, "Could not create BUILD directory - test error")
- end
-
- it "should create the correct RPM build directories" do
- @packager.tmpdir = maketmpdir
- @packager.make_rpm_dirs
- File.directory?(File.join(@packager.tmpdir, "SPECS")).should == true
- File.directory?(File.join(@packager.tmpdir, "SOURCES")).should == true
- File.directory?(File.join(@packager.tmpdir, "SRPMS")).should == true
- File.directory?(File.join(@packager.tmpdir, "BUILD")).should == true
- File.directory?(File.join(@packager.tmpdir, "RPMS")).should == true
- end
- end
-
describe "#cleanup_tmpdirs" do
it "should remove the temp directories" do
packager = RpmpackagePackager.new("package")
Please sign in to comment.
Something went wrong with that request. Please try again.