Skip to content

Commit

Permalink
fixup! Merge pull request Normation#18 from fanf/pr/3904
Browse files Browse the repository at this point in the history
Fixes #19990: Technique editor blocks do not report as expected
  • Loading branch information
VinceMacBuche committed Oct 5, 2021
1 parent 746a99d commit 2d9319f
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,6 @@ object RuleExpectedReportBuilder extends Loggable {
val directives = seq.map { policy =>
// from a policy, get one "directive expected reports" by directive.
// As we flattened previously, we only need/want "head"
//if (policy) logger.info(policy.policyVars)
val pvar = policy.policyVars.head
DirectiveExpectedReports(
pvar.policyId.directiveId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,18 @@ class RuleValServiceImpl(
private[this] def buildVariables(
variableSpecs: Seq[(List[SectionSpec], VariableSpec)]
, context : Map[String, Seq[String]]
, debugLog : Boolean
) : Box[Map[(List[String],String), Variable]] = {

Full(
variableSpecs.map { case (parents, spec) =>
if (debugLog) {
println("<<<<<<")
logger.info(spec)
logger.warn(parents)
}
val res = context.get(spec.name) match {
context.get(spec.name) match {
case None => spec.toVariable()
((parents.map(_.name),spec.toVariable().spec.name) ,spec.toVariable())
case Some(seqValues) =>
val newVar = spec.toVariable(seqValues)
assert(seqValues.toSet == newVar.values.toSet)
((parents.map(_.name),newVar.spec.name) ,newVar)
}
if (debugLog) {
logger.info(res)

println(">>>>>>")
}

res
}.toMap
)
}
Expand Down Expand Up @@ -136,9 +123,7 @@ class RuleValServiceImpl(
for {
technique <- Box(fullActiveTechnique.techniques.get(directive.techniqueVersion)) ?~! s"Version '${directive.techniqueVersion.debugString}' of technique '${fullActiveTechnique.techniqueName.value}' is not available for directive '${directive.name}' [${directive.id.uid.value}]"
varSpecs = technique.rootSection.getAllVariablesBySection(Nil) ++ technique.systemVariableSpecs.map((Nil,_)) :+ ((Nil, technique.trackerVariableSpec))
_ = if (!technique.isSystem) println(varSpecs)
vared <- buildVariables(varSpecs, directive.parameters,!technique.isSystem)
_ = if (!technique.isSystem) logger.warn(vared)
vared <- buildVariables(varSpecs, directive.parameters)
exists <- {
if (vared.isDefinedAt((Nil, technique.trackerVariableSpec.name))) {
Full("OK")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,6 @@ object ExecutionBatch extends Loggable {
final def checkExpectedVariable(expected : String,effective : String) : Boolean = {
val isVar = matchCFEngineVars.pattern.matcher(expected).matches()
if (isVar) { // If this is not a var, there isn't anything to replace.
println(expected)
println(effective)
println(replaceCFEngineVars(expected).matcher(effective).matches())
replaceCFEngineVars(expected).matcher(effective).matches()
} else {
expected == effective
Expand Down Expand Up @@ -948,7 +945,6 @@ final case class ContextForNoAnswer(
Seq[DirectiveStatusReport]()
})

if (ruleId == RuleId("32377fd7-02fd-43d0-aab7-28460a91347b")) logger.error(unexpected)
val t4 = System.nanoTime
u3 += t4-t3

Expand All @@ -965,12 +961,9 @@ final case class ContextForNoAnswer(
})
}


if (ruleId == RuleId("32377fd7-02fd-43d0-aab7-28460a91347b")) logger.error(expected.filter(_.directiveId == DirectiveId(DirectiveUid("e041f5e8-c57a-4b80-a42f-58ccf612de96"))))
val t5 = System.nanoTime
u4 += t5-t4



( unexpected, expected)
}
} yield {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ class RuleValServiceTest extends Specification {
variables(null).either.runNow match {
case Left(_) => ko("Error when parsing variable")
case Right(vars) =>
println(vars)
vars.get(("component1" :: "root section" :: Nil, reportKeysVariableName("component1"))) match {
case None => ko(s"Excepted variable variable_component1, but got nothing. The variables are ${variables}")
case Some(variable) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,8 @@ class ComplianceTest extends Specification {
//here, we assume "compute compliance", i.e we are only testing the compliance engine, not
//the meta-analysis on run consistancy (correct run, at the correct time, etc)
val runinfo = ComputeCompliance(runTime, config, runTime)
println(config.ruleExpectedReports.find(_.ruleId == RuleId("32377fd7-02fd-43d0-aab7-28460a91347b")))//.flatMap(_.directives.filter(_.directiveId == DirectiveId(DirectiveUid("e041f5e8-c57a-4b80-a42f-58ccf612de96")))))
println(reports.filter(_.ruleId == RuleId("32377fd7-02fd-43d0-aab7-28460a91347b") ))
val status = ExecutionBatch.getNodeStatusReports(config.nodeId, runinfo, reports, UnexpectedReportInterpretation(Set()))

println(status.byRules.get(RuleId("32377fd7-02fd-43d0-aab7-28460a91347b")).flatMap(_.directives.get(DirectiveId(DirectiveUid("e041f5e8-c57a-4b80-a42f-58ccf612de96")))))
status.compliance must beEqualTo(ComplianceLevel(success=34, notApplicable = 5))
}
}
Expand Down

0 comments on commit 2d9319f

Please sign in to comment.