Remove required attribute validation

Previously, the entropy types would require that either package, tag, or repo
were provided, since that makes sense for the entropy files. Having a resource
that could not provide any of these would leave a malformed entry in the files.

I've had to remove that due to a deficiency in Puppet that's taken a long time
to track down. While the validation works fine for resources specified in
manifests, it breaks when parsing the records back in. Here's why:

- The provider instances method is called to retrieve a list of all entries
  in the entropy files. This correctly parses the name and properties into the
  provider instance object
- Puppet's type.rb enumerates through each of these, and tries to create a new
  Type insance using just the name and provider parameters from the provider
  instance. It then intends to iterate through the properties and add them one
  at a time.
  0c2157974a/lib/puppet/type.rb (L1180)
- The problem is that the top-level validation function is called when the
  object is first created, and at this time, none of the properties have been
  set, so the required properties have not been set and validation fails.

The top-level validation block cannot mandate a property be set, only other
types of condition.
This commit is contained in:
2016-10-13 16:52:29 +01:00
parent 0e774c77d5
commit 5e5d056025
6 changed files with 0 additions and 16 deletions

View File

@@ -51,8 +51,6 @@ Puppet::Type.newtype(:entropy_keywords) do
end
validate do
raise(ArgumentError, "At least one of package or repo is required") if self[:package].nil? && self[:repo].nil?
raise(ArgumentError, "Package is required when a version is specified") if self[:package].nil? && !self[:version].nil?
raise(ArgumentError, "Version is required when an operator is specified") if self[:version].nil? && !self[:operator].nil?

View File

@@ -50,8 +50,6 @@ Puppet::Type.newtype(:entropy_mask) do
end
validate do
raise(ArgumentError, "At least one of package, tag or repo is required") if self[:package].nil? && self[:tag].nil? && self[:repo].nil?
raise(ArgumentError, "Package is required when a version is specified") if self[:package].nil? && !self[:version].nil?
raise(ArgumentError, "Version is required when an operator is specified") if self[:version].nil? && !self[:operator].nil?

View File

@@ -50,8 +50,6 @@ Puppet::Type.newtype(:entropy_splitdebug) do
end
validate do
raise(ArgumentError, "At least one of package, tag or repo is required") if self[:package].nil? && self[:tag].nil? && self[:repo].nil?
raise(ArgumentError, "Package is required when a version is specified") if self[:package].nil? && !self[:version].nil?
raise(ArgumentError, "Version is required when an operator is specified") if self[:version].nil? && !self[:operator].nil?

View File

@@ -50,8 +50,6 @@ Puppet::Type.newtype(:entropy_splitdebug_mask) do
end
validate do
raise(ArgumentError, "At least one of package, tag or repo is required") if self[:package].nil? && self[:tag].nil? && self[:repo].nil?
raise(ArgumentError, "Package is required when a version is specified") if self[:package].nil? && !self[:version].nil?
raise(ArgumentError, "Version is required when an operator is specified") if self[:version].nil? && !self[:operator].nil?

View File

@@ -50,8 +50,6 @@ Puppet::Type.newtype(:entropy_unmask) do
end
validate do
raise(ArgumentError, "At least one of package, tag or repo is required") if self[:package].nil? && self[:tag].nil? && self[:repo].nil?
raise(ArgumentError, "Package is required when a version is specified") if self[:package].nil? && !self[:version].nil?
raise(ArgumentError, "Version is required when an operator is specified") if self[:version].nil? && !self[:operator].nil?

View File

@@ -40,12 +40,6 @@ describe Puppet::Type.type(:entropy_keywords) do
end
describe "when validating required properties" do
it "should raise an error when no required attributes are passed" do
expect {
described_class.new(:name => "test")
}.to raise_error(Puppet::Error, /At least one of (.*) is required/)
end
it "should raise an error when a version is passed with no package" do
expect {
described_class.new(:name => "test", :repo => "test", :version => "1.2.3")