Permalink
Browse files

15268 - plugin packager should copy the DDL to both the client and ag…

…ent packages

Currently DDL's are only added to the client package. We need DDL's in
both agent and client packages.

DDL's are now placed in the common package which will be created even if
the util directory isn't present during creation. Both agent and client
packages now always depend on common.
  • Loading branch information...
1 parent 5406e71 commit 53e24f2244b0989000ecf9b27eefaa050afcc127 @ploubser ploubser committed with ripienaar Jun 29, 2012
Showing with 37 additions and 23 deletions.
  1. +10 −5 lib/mcollective/pluginpackager/agent_definition.rb
  2. +27 −18 spec/unit/pluginpackager/agent_definition_spec.rb
View
15 lib/mcollective/pluginpackager/agent_definition.rb
@@ -49,7 +49,7 @@ def agent
else
return nil
end
- agent[:dependencies] << "mcollective-#{@metadata[:name]}-common" if @packagedata[:common]
+ agent[:dependencies] << "mcollective-#{@metadata[:name]}-common"
agent
end
@@ -61,14 +61,12 @@ def client
clientdir = File.join(@path, "application")
bindir = File.join(@path, "bin")
- ddldir = File.join(@path, "agent")
aggregatedir = File.join(@path, "aggregate")
client[:files] += Dir.glob(File.join(clientdir, "*")) if PluginPackager.check_dir_present clientdir
client[:files] += Dir.glob(File.join(bindir,"*")) if PluginPackager.check_dir_present bindir
- client[:files] += Dir.glob(File.join(ddldir, "*.ddl")) if PluginPackager.check_dir_present ddldir
client[:files] += Dir.glob(File.join(aggregatedir, "*")) if PluginPackager.check_dir_present aggregatedir
- client[:dependencies] << "mcollective-#{@metadata[:name]}-common" if @packagedata[:common]
+ client[:dependencies] << "mcollective-#{@metadata[:name]}-common"
client[:files].empty? ? nil : client
end
@@ -79,10 +77,17 @@ def common
:description => "Common libraries for #{@metadata[:name]}"}
commondir = File.join(@path, "util")
+ ddldir = File.join(@path, "agent")
+ common[:files] += Dir.glob(File.join(ddldir, "*.ddl")) if PluginPackager.check_dir_present ddldir
+
+ # We fail if there is no ddl file present
+ if common[:files].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
end
end
View
45 spec/unit/pluginpackager/agent_definition_spec.rb
@@ -11,16 +11,19 @@ module PluginPackager
describe "#initialize" do
it "should replace spaces in the package name with dashes" do
+ AgentDefinition.any_instance.expects(:common)
agent = AgentDefinition.new(".", "test package", nil, nil, nil, nil, [], {}, "agent")
agent.metadata[:name].should == "test-package"
end
it "should set dependencies if present" do
+ AgentDefinition.any_instance.expects(:common)
agent = AgentDefinition.new(".", "test-package", nil, nil, nil, nil, ["foo"], {}, "agent")
agent.dependencies.should == ["foo"]
end
it "should set mc server, client and common dependencies" do
+ AgentDefinition.any_instance.expects(:common)
agent = AgentDefinition.new(".", "test-package", nil, nil, nil, nil, [], {:server => "pe-mcollective"}, "agent")
agent.mcserver.should == "pe-mcollective"
agent.mcclient.should == "mcollective-client"
@@ -79,23 +82,34 @@ module PluginPackager
end
describe "#common" do
- before do
+ it "should populate the common files with only the ddl if util dir is empty" do
AgentDefinition.any_instance.expects(:agent)
AgentDefinition.any_instance.expects(:client)
- end
- it "should not populate the commong files if the util directory is empty" do
- PluginPackager.expects(:check_dir_present).returns(false)
+ PluginPackager.expects(:check_dir_present).with("./util").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].should == nil
+ common.packagedata[:common][:files].should == ["file.rb"]
end
it "should populate the common files if the common directory is present and not empty" do
- PluginPackager.expects(:check_dir_present).returns(true)
- File.stubs(:join).returns("tmpdir")
- Dir.stubs(:glob).returns(["file.rb"])
+ 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)
+ Dir.stubs(:glob).with("./util/*").returns(["file.rb"])
+ Dir.stubs(:glob).with("./agent/*.ddl").returns(["ddl.rb"])
common = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
- common.packagedata[:common][:files].should == ["file.rb"]
+ common.packagedata[:common][:files].should == ["ddl.rb", "file.rb"]
+ end
+
+ it "should raise an exception if the ddl file isn't present" do
+ PluginPackager.expects(:check_dir_present).with("./agent").returns(false)
+ expect{
+ common = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
+ }.to raise_error RuntimeError, "cannot create package - No ddl file found in ./agent"
end
end
@@ -104,44 +118,39 @@ module PluginPackager
AgentDefinition.any_instance.expects(:agent).returns(nil)
File.expects(:join).with(".", "application").returns("clientdir")
File.expects(:join).with(".", "bin").returns("bindir")
- File.expects(:join).with(".", "agent").returns("agentdir")
File.expects(:join).with(".", "aggregate").returns("aggregatedir")
end
it "should populate client files if all directories are present" do
AgentDefinition.any_instance.expects(:common).returns(nil)
- PluginPackager.expects(:check_dir_present).times(4).returns(true)
+ PluginPackager.expects(:check_dir_present).times(3).returns(true)
File.expects(:join).with("clientdir", "*").returns("clientdir/*")
File.expects(:join).with("bindir", "*").returns("bindir/*")
- File.expects(:join).with("agentdir", "*.ddl").returns("agentdir/*.ddl")
File.expects(:join).with("aggregatedir", "*").returns("aggregatedir/*")
Dir.expects(:glob).with("clientdir/*").returns(["client.rb"])
Dir.expects(:glob).with("bindir/*").returns(["bin.rb"])
- Dir.expects(:glob).with("agentdir/*.ddl").returns(["agent.ddl"])
Dir.expects(:glob).with("aggregatedir/*").returns(["aggregate.rb"])
client = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
- client.packagedata[:client][:files].should == ["client.rb", "bin.rb", "agent.ddl", "aggregate.rb"]
+ client.packagedata[:client][:files].should == ["client.rb", "bin.rb", "aggregate.rb"]
end
it "should not populate client files if directories are not present" do
AgentDefinition.any_instance.expects(:common).returns(nil)
- PluginPackager.expects(:check_dir_present).times(4).returns(false)
+ PluginPackager.expects(:check_dir_present).times(3).returns(false)
client = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")
client.packagedata[:client].should == nil
end
it "should add common package as dependency if present" do
AgentDefinition.any_instance.expects(:common).returns("common")
- PluginPackager.expects(:check_dir_present).times(4).returns(true)
+ PluginPackager.expects(:check_dir_present).times(3).returns(true)
File.expects(:join).with("clientdir", "*").returns("clientdir/*")
File.expects(:join).with("bindir", "*").returns("bindir/*")
- File.expects(:join).with("agentdir", "*.ddl").returns("agentdir/*.ddl")
File.expects(:join).with("aggregatedir", "*").returns("aggregatedir/*")
Dir.expects(:glob).with("clientdir/*").returns(["client.rb"])
Dir.expects(:glob).with("bindir/*").returns(["bin.rb"])
- Dir.expects(:glob).with("agentdir/*.ddl").returns(["agent.ddl"])
Dir.expects(:glob).with("aggregatedir/*").returns(["aggregate.rb"])
client = AgentDefinition.new(".", nil, nil, nil, nil, nil, [], {}, "agent")

0 comments on commit 53e24f2

Please sign in to comment.