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 #23466: Focus reporting is not working #5049

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 @@ -141,7 +141,8 @@ sealed trait ComponentExpectedReport {
final case class BlockExpectedReport(
componentName: String,
reportingLogic: ReportingLogic,
subComponents: List[ComponentExpectedReport]
subComponents: List[ComponentExpectedReport],
id: Option[String]
) extends ComponentExpectedReport

final case class ValueExpectedReport(
Expand Down Expand Up @@ -376,7 +377,7 @@ object ExpectedReportsSerialisation {
reportingLogic: ReportingLogic,
subComponents: List[JsonComponentExpectedReport7_0]
) extends JsonComponentExpectedReport7_0 {
def transform = BlockExpectedReport(componentName, reportingLogic, subComponents.map(_.transform))
def transform = BlockExpectedReport(componentName, reportingLogic, subComponents.map(_.transform), None)
}
implicit class _JsonBlockExpectedReport7_0(x: BlockExpectedReport) {
def transform = JsonBlockExpectedReport7_0(x.componentName, x.reportingLogic, x.subComponents.map(_.transform))
Expand Down Expand Up @@ -680,12 +681,16 @@ object ExpectedReportsSerialisation {
}
)
}
final case class JsonBlockExpectedReport7_1(bid: String, rl: ReportingLogic, scs: List[JsonComponentExpectedReport7_1])
extends JsonComponentExpectedReport7_1 {
def transform = BlockExpectedReport(bid, rl, scs.map(_.transform))
final case class JsonBlockExpectedReport7_1(
bid: String,
rl: ReportingLogic,
scs: List[JsonComponentExpectedReport7_1],
id: Option[String]
) extends JsonComponentExpectedReport7_1 {
def transform = BlockExpectedReport(bid, rl, scs.map(_.transform), id)
}
implicit class _JsonBlockExpectedReport7_1(x: BlockExpectedReport) {
def transform = JsonBlockExpectedReport7_1(x.componentName, x.reportingLogic, x.subComponents.map(_.transform))
def transform = JsonBlockExpectedReport7_1(x.componentName, x.reportingLogic, x.subComponents.map(_.transform), x.id)
}

final case class JsonDirectiveExpectedReports7_1(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class TechniqueWriterImpl(
NodeSeq.Empty
} else {
val reportingLogic = block.reportingLogic.value
<SECTION component="true" multivalued="true" name={block.component} reporting={reportingLogic}>
<SECTION component="true" multivalued="true" name={block.component} reporting={reportingLogic} id={block.id}>
{childs}
</SECTION>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import better.files.File
import cats.data.NonEmptyList
import cats.implicits._
import com.normation.box._
import com.normation.cfclerk.domain.ReportingLogic.FocusReport
import com.normation.cfclerk.domain.SectionSpec
import com.normation.cfclerk.domain.TechniqueName
import com.normation.errors._
Expand Down Expand Up @@ -1838,7 +1839,28 @@ object RuleExpectedReportBuilder extends Loggable {
val currentPath = section.name :: path
val children =
section.children.collect { case c: SectionSpec => c }.flatMap(c => sectionToExpectedReports(currentPath)(c)).toList
BlockExpectedReport(section.name, rule, children) :: Nil
val correctRule = rule match {
case FocusReport(reportId) =>
val newComponent = (children
.find(c => {
c match {
case block: BlockExpectedReport => block.id.map(_ == reportId).getOrElse(false)
case v: ValueExpectedReport =>
v.componentsValues.exists { v =>
v match {
case ExpectedValueMatch(_, _) => false
case ExpectedValueId(_, id) => id == reportId
}
}
}
}))
.map(_.componentName)
.getOrElse(reportId)
FocusReport(newComponent)
case r => r
}

BlockExpectedReport(section.name, correctRule, children, section.id) :: Nil

}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</FILES>
</AGENT>
<SECTIONS>
<SECTION component="true" multivalued="true" name="block component" reporting="worst-case-weighted-sum">
<SECTION component="true" multivalued="true" name="block component" reporting="worst-case-weighted-sum" id="id_method">
<SECTION component="true" multivalued="true" id="id1" name="Customized component">
<REPORTKEYS>
<VALUE id="id1">${node.properties[apache_package_name]}</VALUE>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,8 @@ class ExpectedReportTest extends Specification {
ExpectedValueId("/tmp/${node.properties[filename]}", "87cad41f-ec88-4b32-a13c-136f15f7bf17")
)
)
)
),
None
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class ExecutionBatchTest extends Specification {
case ExpectedValueMatch(value, _) =>
ResultSuccessReport(now, ruleId, directiveId, nodeId, "report_id", componentName, value, now, "empty text")
}
case BlockExpectedReport(componentName, logic, sub) =>
case BlockExpectedReport(componentName, logic, sub, _) =>
sub.map(mapComponent(_, directiveId)).flatten
}
}
Expand Down Expand Up @@ -816,7 +816,8 @@ class ExecutionBatchTest extends Specification {
new ValueExpectedReport(
"component",
ExpectedValueMatch("foo", "foo") :: ExpectedValueMatch("bar", "bar") :: Nil
) :: Nil
) :: Nil,
None
)

val withGood = ExecutionBatch
Expand Down Expand Up @@ -937,7 +938,8 @@ class ExecutionBatchTest extends Specification {
new ValueExpectedReport(
"component",
ExpectedValueMatch("foo", "foo") :: ExpectedValueMatch("bar", "bar") :: Nil
) :: Nil
) :: Nil,
None
)

val withGood = ExecutionBatch
Expand Down Expand Up @@ -1058,7 +1060,8 @@ class ExecutionBatchTest extends Specification {
new ValueExpectedReport(
"component",
ExpectedValueMatch("foo", "foo") :: ExpectedValueMatch("bar", "bar") :: Nil
) :: Nil
) :: Nil,
None
)

val withGood = ExecutionBatch
Expand Down Expand Up @@ -1182,7 +1185,8 @@ class ExecutionBatchTest extends Specification {
) :: new ValueExpectedReport(
"component1",
ExpectedValueId("bar", "report_1") :: Nil
) :: Nil
) :: Nil,
None
)

val withGood = ExecutionBatch
Expand Down Expand Up @@ -1358,7 +1362,8 @@ class ExecutionBatchTest extends Specification {
) :: new ValueExpectedReport(
"component2",
ExpectedValueMatch("b1c2", "b1c2") :: Nil
) :: Nil
) :: Nil,
None
) :: BlockExpectedReport(
"block2",
ReportingLogic.WeightedReport,
Expand All @@ -1368,8 +1373,10 @@ class ExecutionBatchTest extends Specification {
) :: new ValueExpectedReport(
"component2",
ExpectedValueMatch("b2c2", "b2c2") :: Nil
) :: Nil
) :: Nil
) :: Nil,
None
) :: Nil,
None
)
val directiveExpectedReports =
DirectiveExpectedReports(DirectiveId(DirectiveUid("policy")), None, false, expectedComponent :: Nil)
Expand Down Expand Up @@ -1527,7 +1534,8 @@ class ExecutionBatchTest extends Specification {
) :: new ValueExpectedReport(
"component2",
ExpectedValueMatch("b1c2", "b1c2") :: Nil
) :: Nil
) :: Nil,
None
) :: BlockExpectedReport(
"block2",
ReportingLogic.WeightedReport,
Expand All @@ -1537,8 +1545,10 @@ class ExecutionBatchTest extends Specification {
) :: new ValueExpectedReport(
"component2",
ExpectedValueMatch("${loop}", "${loop}") :: Nil
) :: Nil
) :: Nil
) :: Nil,
None
) :: Nil,
None
)
val directiveExpectedReports =
DirectiveExpectedReports(DirectiveId(DirectiveUid("policy")), None, false, expectedComponent :: Nil)
Expand Down Expand Up @@ -1663,7 +1673,8 @@ class ExecutionBatchTest extends Specification {
) :: new ValueExpectedReport(
"component",
ExpectedValueId("keyvalue", "report_id_b1c2") :: Nil
) :: Nil
) :: Nil,
None
) :: BlockExpectedReport(
"block2",
ReportingLogic.WeightedReport,
Expand All @@ -1673,8 +1684,10 @@ class ExecutionBatchTest extends Specification {
) :: new ValueExpectedReport(
"component",
ExpectedValueId("${loop2}", "report_id_b2c2") :: Nil
) :: Nil
) :: Nil
) :: Nil,
None
) :: Nil,
None
)
val directiveExpectedReports =
DirectiveExpectedReports(DirectiveId(DirectiveUid("policy")), None, false, expectedComponent :: Nil)
Expand Down Expand Up @@ -1855,7 +1868,8 @@ class ExecutionBatchTest extends Specification {
) :: new ValueExpectedReport(
"component2",
ExpectedValueMatch("b1c2", "b1c2") :: Nil
) :: Nil
) :: Nil,
None
) :: BlockExpectedReport(
"block2",
ReportingLogic.FocusReport("component1"),
Expand All @@ -1865,8 +1879,10 @@ class ExecutionBatchTest extends Specification {
) :: new ValueExpectedReport(
"component2",
ExpectedValueMatch("b2c2", "b2c2") :: Nil
) :: Nil
) :: Nil
) :: Nil,
None
) :: Nil,
None
)
val directiveExpectedReports =
DirectiveExpectedReports(DirectiveId(DirectiveUid("policy")), None, false, expectedComponent :: Nil)
Expand Down Expand Up @@ -2060,7 +2076,8 @@ class ExecutionBatchTest extends Specification {
) :: new ValueExpectedReport(
"component2",
ExpectedValueMatch("b1c2", "b1c2") :: Nil
) :: Nil
) :: Nil,
None
) :: BlockExpectedReport(
"block2",
ReportingLogic.WeightedReport,
Expand All @@ -2070,8 +2087,10 @@ class ExecutionBatchTest extends Specification {
) :: new ValueExpectedReport(
"component2",
ExpectedValueMatch("b2c2", "b2c2") :: Nil
) :: Nil
) :: Nil
) :: Nil,
None
) :: Nil,
None
)
val directiveExpectedReports =
DirectiveExpectedReports(DirectiveId(DirectiveUid("policy")), None, false, expectedComponent :: Nil)
Expand Down Expand Up @@ -2214,7 +2233,8 @@ class ExecutionBatchTest extends Specification {
new ValueExpectedReport(
"component",
ExpectedValueMatch("foo", "foo") :: ExpectedValueMatch("bar", "bar") :: Nil
) :: Nil
) :: Nil,
None
)

val withGood = ExecutionBatch
Expand Down Expand Up @@ -2535,7 +2555,8 @@ class ExecutionBatchTest extends Specification {
) :: new ValueExpectedReport(
"Check right OK for ${user} and what follows '$' does not matter in pattern matching",
ExpectedValueId("/bin/checkRightsOK ${user}", "report_1") :: Nil
) :: Nil
) :: Nil,
None
)

val reports = Seq[ResultReports](
Expand Down Expand Up @@ -2751,7 +2772,8 @@ class ExecutionBatchTest extends Specification {
List(
ValueExpectedReport("gm1", List(ExpectedValueId("value1", "reportid1"))),
ValueExpectedReport("gm2", List(ExpectedValueId("value2", "reportid2")))
)
),
None
),
ValueExpectedReport("gm3", List(ExpectedValueId("value3", "reportid3"))),
ValueExpectedReport("gm4", List(ExpectedValueId("value4", "reportid4")))
Expand Down