Conversation
:platform => platform, | ||
:platform_version => version | ||
} | ||
platform.any? do |key, value| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to explictly return the result of this (also platform.all? in the second function)
|
👎 The client side validation is missing |
@tboerger Where is the client side validation code? |
@@ -893,6 +943,28 @@ def validate_proposal_constraints(proposal) | |||
break | |||
end | |||
|
|||
if violates_platform_constraint?(elements, role) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this part of the cluster constraint check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not. I guess that you are tricked by the github collapse algorithm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right
I would prefer a hash for the constraint definition. The key is the platform and the value can be the specific version constrai t in form of a string, regexp or integer/float. |
You can find the javascript for clientside galidation at https://github.com/crowbar/barclamp-crowbar/blob/master/crowbar_framework/app/assets/javascripts/jquery/nodeList.js#L237 |
@aplanas I'm not sure there's a way to express something like the following with your patch: "if platform is SLE, then SLE12 only; accept all non-SLE platforms" |
@vuntz I think for that, we have "exclude_platform" => [/suse/, '11.3'] |
@jsuchome well, it's "if platform is SLE, then not SLE11-SP3", which is slightly different than "if platfirm is SLE, then SLE12 only". But it might be good enough for now, indeed. |
But the pattern is still messy |
Yep, I think that "Accept SLES12 or anything that is not SLE" is approx. to "Exclude SLES11*" for this use case. As @jsuchome this is something like { "exclude_platform" => ['suse', /9|(1[01].*)/] } |
I guess that to alleviate the messy regexp we can use @tboerger approach of using hashes instead of list. {
"exclude_platform" => {
"suse": "9",
"suse": "10.*",
"suse": "11.*"
}
} But the semantic is the same : m |
That won't work. But regular expressions are fine. You can even negate the value of the regex. But hash keys have to be unique. |
Uau. Sometimes I amuse myself : ( Of course the hash is wrong. But we can use some lists here: {
"exclude_platform" => [
["suse", "9"],
["suse", "10.*"],
["suse", "11.*"]
]
} |
And why do you strictly rely on arrays? Something like this is IMHO absolutly fine. What do you think @bkutil? {
"exclude_platform" => {
"suse" => /[^12]/
}
} Edit: And maybe something like this: {
"exclude_platform" => {
"suse" => "< 12.0"
}
} |
I agree with use of hashes as @tboerger proposes. At least we do not have to convert arrays to hashes in validate functions |
I am not sure that I like the hash solution, are we going to allow this? {
"exclude_platform" => {
"suse" => /[^12]/,
"debian" => /.*/
}
} |
Of course is that allowed. |
Add two new validation constraints.
"platform" => {
{
'suse' => /12.(0|1)/,
/debian/ => /.*/
}
} This will expect that the service have a platform equal to 'suse' and a platform_version of 12.0 or 12.1, or a debian.
"exclude_platform" => {
{
'suse' => '11.3',
/redhat/ => /.*/
}
} If the platform is a SLES11 SP3 or a redhat, the service will not be installed. |
Uhm, if I add regular expression, the javascript serializer do not work properly |
Please dont use regex for the hash keys. |
|
end | ||
|
||
if violates_exclude_platform_constraint?(elements, role) | ||
platforms = role_constraints[role]["platform"].map {|k, v| [k, v].join(' ')}.join(', ') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"exclude_platform"
|
|
||
if violates_exclude_platform_constraint?(elements, role) | ||
platforms = role_constraints[role]["exclude_platform"].map {|k, v| [k, v].join(' ')}.join(', ') | ||
validation_error("Role #{role} can't be used in #{platforms} platform(s).") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't there be 'for xy platforms' in this message as well?
|
@@ -359,6 +397,16 @@ | |||
this.dataBag.removedOld = true; | |||
}; | |||
|
|||
var equal_or_match = function(value, maybe_regexp) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please dont pullute the namespace. Make it as NodeList.prototype.equalOrMatch
and call it with self.equalOrMatch()
|
@aplanas Sorry, i have done it wrong... https://github.com/chef/chef/blob/master/lib/chef/version_class.rb should be a good starting point how to parse the versions correctly. Split the platform version my |
|
|
||
match = /^(\d+)$/.exec(version); | ||
if (match) { | ||
return [parseInt(match[1]), parseInt(match[2]), 0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/parseInt(match[2])/0/
end | ||
end | ||
|
||
op_value = maybe_regexp.scan(/^(>=?|<=?)\s*([.\d]+)$/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the record, I like the code flow of the js bits a bit better (where this regexp is only used when we're not in the /foo/
case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's not a big issue as the regex is not too hungry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I maintain it here? I think that the eslif op_value
is more clear here, and I can avoid multiple returns. I think that this is the idiomatic Ruby, but I am not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tboerger oh, it was not about performance, just about readability. If people prefer it here, then sure. It's just less readable (or well, more confusing) to me :-)
* Add "platform" constraint: "platform" => { 'suse' => '/12.(0|1)/', 'debian' => '/.*/' } This will expect that the service have a platform equal to 'suse' and a platform_version of 12.0 or 12.1, or a debian. * Add "exclude_platform" constraint: "exclude_platform" => { 'suse' => '11.3', 'ubuntu' => '> 10', 'redhat' => '/.*/' } If the platform is a SLES11 SP3 or a redhat, the service will not be installed. * Add constrains to JavaScript validator Because JSON can't contains regular expressions, the constraints needs to be expressed as strings. If the string starts and ends with '/', the JavaScript and the Ruby part takes care of convert it into a Regexp. * Add test cases
|
Let's do it! |
Add two new validation constraints.
Add "platform" constraint:
"platform" => ['suse', /12.(0|1)/]
This will expect that the service have a platform equal to 'suse'
and a platform_version of 12.0 or 12.1
Add "exclude_platform" constraint:
"exclude_platform" => [/suse/, '11.3']
If the platform is a SLES11 SP3, the service will not be installed.