Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #23446: Change request on special:all_nodes_without_role lead to error #5254

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ case object AllTarget extends NonGroupRuleTarget {

case object AllTargetExceptPolicyServers extends NonGroupRuleTarget {
override def target = "special:all_exceptPolicyServers"
def r = "special:all_exceptPolicyServers".r
// for compat reason in event logs < Rudder 7.0, we must be able to parse also old format: `special:all_nodes_without_role`
def r = "(?:special:all_exceptPolicyServers|special:all_nodes_without_role)".r
}

case object AllPolicyServers extends NonGroupRuleTarget {
override def target = "special:all_policyServers"
def r = "special:all_policyServers".r
// for compat reason in event logs < Rudder 7.0, we must be able to parse also old format: `special:all_servers_with_role`
def r = "(?:special:all_policyServers|special:all_servers_with_role)".r
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,37 @@ class RuleTargetTest extends Specification with Loggable {
allTargets.forall { gt =>
RuleTarget.unser(gt.target) match {
case Some(unser) => unser == gt
// TODO: what was he meaning of this test? It makes no sense
case None => false // gt.target == gt
case None => false
}
} === true
}

/*
* The format changed in 7.0, but we can have eventLogs with the old format.
* It is unclear is we want to pay the big migration cost for only that, and
* we would prefer to either amortize it with an other rewrite of eventLogs,
* or just keep it forever (we are not sure we really want to change evenLog ever)
*/
"Is able to correctly parse the old format and write back the new one for policy servers" in {

val oldFormat = """{"include":{"or":["special:all_servers_with_role"]},"exclude":{"or":[]}}"""
val newFormat = """{"include":{"or":["special:all_policyServers"]},"exclude":{"or":[]}}"""

val p = RuleTarget.unser(oldFormat)
(p === Some(TargetExclusion(TargetUnion(Set(AllPolicyServers)), TargetUnion()))) and
(p.get.toString === newFormat)
}

"Is able to correctly parse the old format and write back for simple nodes" in {

val oldFormat = """{"include":{"or":["special:all_nodes_without_role"]},"exclude":{"or":[]}}"""
val newFormat = """{"include":{"or":["special:all_exceptPolicyServers"]},"exclude":{"or":[]}}"""

val p = RuleTarget.unser(oldFormat)
(p === Some(TargetExclusion(TargetUnion(Set(AllTargetExceptPolicyServers)), TargetUnion()))) and
(p.get.toString === newFormat)
}

"Have their group target removed in composite targets" in {
val allComp = (allComposite ++ allTargetExclusions)
groupTargets.forall {
Expand Down