diff --git a/rudder-core/src/main/scala/com/normation/rudder/domain/eventlog/AssetsEventLog.scala b/rudder-core/src/main/scala/com/normation/rudder/domain/eventlog/AssetsEventLog.scala index 210ee7611ff..1442e6c10be 100644 --- a/rudder-core/src/main/scala/com/normation/rudder/domain/eventlog/AssetsEventLog.scala +++ b/rudder-core/src/main/scala/com/normation/rudder/domain/eventlog/AssetsEventLog.scala @@ -4,12 +4,12 @@ ************************************************************************************* * * This file is part of Rudder. -* +* * Rudder is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * In accordance with the terms of section 7 (7. Additional Terms.) of * the GNU General Public License version 3, the copyright holders add * the following Additional permissions: @@ -22,12 +22,12 @@ * documentation that, without modification of the Source Code, enables * supplementary functions or services in addition to those offered by * the Software. -* +* * Rudder is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with Rudder. If not, see . @@ -47,12 +47,10 @@ import com.normation.rudder.domain.nodes.Node import com.normation.rudder.domain.nodes.NodeInfo import com.normation.rudder.domain.Constants - /** * Accept/refuse new server */ - final case class InventoryLogDetails( nodeId : NodeId , inventoryVersion: DateTime @@ -87,7 +85,6 @@ object InventoryEventLog { } } - final case class AcceptNodeEventLog ( override val eventDetails : EventLogDetails ) extends InventoryEventLog with HashcodeCaching { @@ -100,7 +97,6 @@ object AcceptNodeEventLog extends EventLogFilter { override def apply(x : (EventLogType, EventLogDetails)) : AcceptNodeEventLog = AcceptNodeEventLog(x._2) - def fromInventoryLogDetails( id : Option[Int] = None , principal : EventActor @@ -129,7 +125,6 @@ object RefuseNodeEventLog extends EventLogFilter { override def apply(x : (EventLogType, EventLogDetails)) : RefuseNodeEventLog = RefuseNodeEventLog(x._2) - def fromInventoryLogDetails( id : Option[Int] = None , principal : EventActor @@ -146,8 +141,6 @@ object RefuseNodeEventLog extends EventLogFilter { } } - - // Accepted node part final case class NodeLogDetails( @@ -191,7 +184,6 @@ object NodeEventLog { } } - final case class DeleteNodeEventLog ( override val eventDetails : EventLogDetails ) extends InventoryEventLog with HashcodeCaching { @@ -204,8 +196,6 @@ object DeleteNodeEventLog extends EventLogFilter { override def apply(x : (EventLogType, EventLogDetails)) : DeleteNodeEventLog = DeleteNodeEventLog(x._2) - - def fromInventoryLogDetails( id : Option[Int] = None , principal : EventActor diff --git a/rudder-core/src/main/scala/com/normation/rudder/domain/nodes/Node.scala b/rudder-core/src/main/scala/com/normation/rudder/domain/nodes/Node.scala index 51677f75990..03328008122 100644 --- a/rudder-core/src/main/scala/com/normation/rudder/domain/nodes/Node.scala +++ b/rudder-core/src/main/scala/com/normation/rudder/domain/nodes/Node.scala @@ -4,12 +4,12 @@ ************************************************************************************* * * This file is part of Rudder. -* +* * Rudder is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * In accordance with the terms of section 7 (7. Additional Terms.) of * the GNU General Public License version 3, the copyright holders add * the following Additional permissions: @@ -22,12 +22,12 @@ * documentation that, without modification of the Source Code, enables * supplementary functions or services in addition to those offered by * the Software. -* +* * Rudder is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with Rudder. If not, see . @@ -40,11 +40,17 @@ package com.normation.rudder.domain.nodes import com.normation.inventory.domain.NodeId import com.normation.utils.HashcodeCaching - /** * The entry point for a REGISTERED node in Rudder. * * This is independant from inventory, and can exist without one. * */ -case class Node(id:NodeId, name:String, description:String, isBroken : Boolean, isSystem : Boolean, isPolicyServer: Boolean) extends HashcodeCaching \ No newline at end of file +case class Node( + id:NodeId + , name:String + , description:String + , isBroken : Boolean + , isSystem : Boolean + , isPolicyServer: Boolean +) extends HashcodeCaching \ No newline at end of file diff --git a/rudder-core/src/main/scala/com/normation/rudder/domain/nodes/NodeInfo.scala b/rudder-core/src/main/scala/com/normation/rudder/domain/nodes/NodeInfo.scala index b90cee6cf25..e120e66df9e 100644 --- a/rudder-core/src/main/scala/com/normation/rudder/domain/nodes/NodeInfo.scala +++ b/rudder-core/src/main/scala/com/normation/rudder/domain/nodes/NodeInfo.scala @@ -4,12 +4,12 @@ ************************************************************************************* * * This file is part of Rudder. -* +* * Rudder is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * In accordance with the terms of section 7 (7. Additional Terms.) of * the GNU General Public License version 3, the copyright holders add * the following Additional permissions: @@ -22,12 +22,12 @@ * documentation that, without modification of the Source Code, enables * supplementary functions or services in addition to those offered by * the Software. -* +* * Rudder is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with Rudder. If not, see . @@ -48,9 +48,7 @@ import com.normation.inventory.domain.ServerRole * always useful about a node */ case class NodeInfo( - id : NodeId - , name : String - , description : String + node : Node , hostname : String , machineType : String , osName : String @@ -63,12 +61,18 @@ case class NodeInfo( , policyServerId: NodeId , localAdministratorAccountName: String , creationDate : DateTime - , isBroken : Boolean - , isSystem : Boolean - , isPolicyServer: Boolean //for now, isPolicyServer and server role ARE NOT //dependant. So EXPECTS inconsistencies. //TODO: remove isPolicyServer, and pattern match on // on role everywhere. , serverRoles : Set[ServerRole] -) extends HashcodeCaching +) extends HashcodeCaching { + + val id = node.id + val name = node.name + val description = node.description + val isBroken = node.isBroken + val isSystem = node.isSystem + val isPolicyServer = node.isPolicyServer + +} diff --git a/rudder-core/src/main/scala/com/normation/rudder/repository/ldap/LDAPEntityMapper.scala b/rudder-core/src/main/scala/com/normation/rudder/repository/ldap/LDAPEntityMapper.scala index 53b18ed03ff..e897c3566b4 100644 --- a/rudder-core/src/main/scala/com/normation/rudder/repository/ldap/LDAPEntityMapper.scala +++ b/rudder-core/src/main/scala/com/normation/rudder/repository/ldap/LDAPEntityMapper.scala @@ -4,12 +4,12 @@ ************************************************************************************* * * This file is part of Rudder. -* +* * Rudder is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * In accordance with the terms of section 7 (7. Additional Terms.) of * the GNU General Public License version 3, the copyright holders add * the following Additional permissions: @@ -22,12 +22,12 @@ * documentation that, without modification of the Source Code, enables * supplementary functions or services in addition to those offered by * the Software. -* +* * Rudder is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with Rudder. If not, see . @@ -76,7 +76,6 @@ import com.normation.rudder.rule.category.RuleCategoryId import com.normation.rudder.rule.category.RuleCategory import com.normation.rudder.rule.category.RuleCategoryId - /** * Map objects from/to LDAPEntries * @@ -88,11 +87,8 @@ class LDAPEntityMapper( , cmdbQueryParser: CmdbQueryParser ) extends Loggable { - ////////////////////////////// Node ////////////////////////////// - - def nodeToEntry(node:Node) : LDAPEntry = { val entry = if(node.isPolicyServer) { @@ -107,6 +103,25 @@ class LDAPEntityMapper( entry } + def entryToNode(e:LDAPEntry) : Box[Node] = { + if(e.isA(OC_RUDDER_NODE)||e.isA(OC_POLICY_SERVER_NODE)) { + //OK, translate + for { + id <- nodeDit.NODES.NODE.idFromDn(e.dn) ?~! s"Bad DN found for a Node: ${e.dn}" + } yield { + Node( + id + , e(A_NAME).getOrElse("") + , e(A_DESCRIPTION).getOrElse("") + , e.getAsBoolean(A_IS_BROKEN).getOrElse(false) + , e.getAsBoolean(A_IS_SYSTEM).getOrElse(false) + , e.isA(OC_POLICY_SERVER_NODE) + ) + } + } else { + Failure(s"The given entry is not of the expected ObjectClass ${OC_RUDDER_NODE} or ${OC_POLICY_SERVER_NODE}. Entry details: ${e}") + } + } ////////////////////////////// NodeInfo ////////////////////////////// @@ -122,30 +137,24 @@ class LDAPEntityMapper( //why not using InventoryMapper ? Some required things for node are not // wanted here ? for { - checkIsANode <- if(nodeEntry.isA(OC_RUDDER_NODE)) Full("ok") - else Failure("Bad object class, need %s and found %s".format(OC_RUDDER_NODE,nodeEntry.valuesFor(A_OC))) - - checkIsANode <- if(inventoryEntry.isA(OC_NODE)) Full("Ok") - else Failure("Bad object class, need %s and found %s".format(OC_NODE,inventoryEntry.valuesFor(A_OC))) + node <- entryToNode(nodeEntry) machineType = machineEntryObjectClass.map(machine => if (machine.exists( _ == OC_PM)) "Physical" else "Virtual").getOrElse("No Machine Inventory") checkSameID <- if(nodeEntry(A_NODE_UUID).isDefined && nodeEntry(A_NODE_UUID) == inventoryEntry(A_NODE_UUID)) Full("Ok") else Failure("Mismatch id for the node %s and the inventory %s".format(nodeEntry(A_NODE_UUID), inventoryEntry(A_NODE_UUID))) - id <- nodeDit.NODES.NODE.idFromDn(nodeEntry.dn) ?~! "Bad DN found for a Node: %s".format(nodeEntry.dn) // Compute the parent policy Id policyServerId <- inventoryEntry.valuesFor(A_POLICY_SERVER_UUID).toList match { case Nil => Failure("No policy servers for a Node: %s".format(nodeEntry.dn)) case x :: Nil => Full(x) case _ => Failure("Too many policy servers for a Node: %s".format(nodeEntry.dn)) } - + date <- nodeEntry.getAsGTime(A_OBJECT_CREATION_DATE) ?~! + "Can not find mandatory attribute '%s' in entry".format(A_OBJECT_CREATION_DATE) agentsName <- sequence(inventoryEntry.valuesFor(A_AGENTS_NAME).toSeq) { x => AgentType.fromValue(x) ?~! "Unknow value for agent type: '%s'. Authorized values are: %s".format(x, AgentType.allValues.mkString(", ")) } - date <- nodeEntry.getAsGTime(A_OBJECT_CREATION_DATE) ?~! - "Can not find mandatory attribute '%s' in entry".format(A_OBJECT_CREATION_DATE) osVersion = inventoryEntry(A_OS_VERSION).getOrElse("N/A") osName = inventoryEntry(A_OS_NAME).getOrElse("N/A") servicePack = inventoryEntry(A_OS_SERVICE_PACK) @@ -154,9 +163,7 @@ class LDAPEntityMapper( // fetch the inventory datetime of the object val dateTime = inventoryEntry.getAsGTime(A_INVENTORY_DATE) map(_.dateTime) getOrElse(DateTime.now) NodeInfo( - id - , nodeEntry(A_NAME).getOrElse("") - , nodeEntry(A_DESCRIPTION).getOrElse("") + node , inventoryEntry(A_HOSTNAME).getOrElse("") //OsType.osTypeFromObjectClasses(inventoryEntry.valuesFor(A_OC)).map(_.toString).getOrElse(""), , machineType @@ -171,15 +178,11 @@ class LDAPEntityMapper( //nodeDit.NODES.NODE.idFromDn(policyServerDN).getOrElse(error("Bad DN found for the policy server of Node: %s".format(nodeEntry.dn))), , inventoryEntry(A_ROOT_USER).getOrElse("") , date.dateTime - , nodeEntry.getAsBoolean(A_IS_BROKEN).getOrElse(false) - , nodeEntry.getAsBoolean(A_IS_SYSTEM).getOrElse(false) - , nodeEntry.isA(OC_POLICY_SERVER_NODE) , serverRoles ) } } - /** * Build the ActiveTechniqueCategoryId from the given DN */ @@ -241,7 +244,6 @@ class LDAPEntityMapper( } } - def nodeDn2OptNodeId(dn:DN) : Box[NodeId] = { val rdn = dn.getRDN if(!rdn.isMultiValued && rdn.hasAttribute(A_NODE_UUID)) { @@ -251,7 +253,6 @@ class LDAPEntityMapper( ////////////////////////////// ActiveTechniqueCategory ////////////////////////////// - /** * children and items are left empty */ @@ -303,7 +304,6 @@ class LDAPEntityMapper( } } - /** * Build a ActiveTechnique from and LDAPEntry. * children directives are left empty @@ -337,7 +337,6 @@ class LDAPEntityMapper( ////////////////////////////// NodeGroupCategory ////////////////////////////// - /** * children and items are left empty */ @@ -401,7 +400,6 @@ class LDAPEntityMapper( } else Failure("The given entry is not of the expected ObjectClass '%s'. Entry details: %s".format(OC_RUDDER_NODE_GROUP, e)) } - ////////////////////////////// Special Policy target info ////////////////////////////// def entry2RuleTargetInfo(e:LDAPEntry) : Box[RuleTargetInfo] = { @@ -426,8 +424,6 @@ class LDAPEntityMapper( } } - - ////////////////////////////// Directive ////////////////////////////// def entry2Directive(e:LDAPEntry) : Box[Directive] = { @@ -473,7 +469,6 @@ class LDAPEntityMapper( ////////////////////////////// Rule Category ////////////////////////////// - /** * children and items are left empty */ @@ -498,7 +493,6 @@ class LDAPEntityMapper( rudderDit.RULECATEGORY.ruleCategoryModel(category.id.value, parentDN, category.name,category.description,category.isSystem) } - ////////////////////////////// Rule ////////////////////////////// def entry2OptTarget(optValue:Option[String]) : Box[Option[RuleTarget]] = { (for { @@ -556,7 +550,6 @@ class LDAPEntityMapper( } } - /** * Map a rule to an LDAP Entry. * WARN: serial is NEVER mapped. @@ -577,8 +570,6 @@ class LDAPEntityMapper( entry } - - ////////////////////////////// API Accounts ////////////////////////////// /** @@ -664,5 +655,4 @@ class LDAPEntityMapper( entry } - } diff --git a/rudder-core/src/test/scala/com/normation/rudder/domain/policies/RuleTargetTest.scala b/rudder-core/src/test/scala/com/normation/rudder/domain/policies/RuleTargetTest.scala index 558208d8cd3..2270310aae4 100644 --- a/rudder-core/src/test/scala/com/normation/rudder/domain/policies/RuleTargetTest.scala +++ b/rudder-core/src/test/scala/com/normation/rudder/domain/policies/RuleTargetTest.scala @@ -12,11 +12,11 @@ import net.liftweb.common._ import com.normation.cfclerk.domain._ import com.normation.rudder.repository.FullNodeGroupCategory import com.normation.rudder.domain.nodes.NodeGroupCategoryId +import com.normation.rudder.domain.nodes.Node @RunWith(classOf[JUnitRunner]) class RuleTargetTest extends Specification with Loggable { - val nodeIds = (for { i <- 0 to 10 } yield { @@ -29,12 +29,12 @@ class RuleTargetTest extends Specification with Loggable { ( id , NodeInfo ( - id, s"Node-${id}" - , "" ,"" ,"" ,"" ,"" + Node(id,"" ,"", false, false, false), s"Node-${id}" + , "" ,"" ,"" , None, Nil, DateTime.now , "", Seq(), NodeId("root") - , "", DateTime.now - , false, false, false, Set() + , "", DateTime.now, + Set() ) ) }.toMap @@ -104,8 +104,6 @@ class RuleTargetTest extends Specification with Loggable { val allTargets : Set[RuleTarget] = (groupTargets.map(_._1) ++ (allComposite.map(_._1)) ++ allTargetExclusions.map(_._1)) - - " Nodes from Rule targets" should { "Be found correctly on simple rule targets" in { groupTargets.forall { case (gt,g) => @@ -154,5 +152,4 @@ class RuleTargetTest extends Specification with Loggable { } } - } diff --git a/rudder-core/src/test/scala/com/normation/rudder/services/nodes/NodeConfigurationChangeDetectServiceTest.scala b/rudder-core/src/test/scala/com/normation/rudder/services/nodes/NodeConfigurationChangeDetectServiceTest.scala index afa4cb5eaff..7fbc932416a 100644 --- a/rudder-core/src/test/scala/com/normation/rudder/services/nodes/NodeConfigurationChangeDetectServiceTest.scala +++ b/rudder-core/src/test/scala/com/normation/rudder/services/nodes/NodeConfigurationChangeDetectServiceTest.scala @@ -4,12 +4,12 @@ ************************************************************************************* * * This file is part of Rudder. -* +* * Rudder is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * In accordance with the terms of section 7 (7. Additional Terms.) of * the GNU General Public License version 3, the copyright holders add * the following Additional permissions: @@ -22,12 +22,12 @@ * documentation that, without modification of the Source Code, enables * supplementary functions or services in addition to those offered by * the Software. -* +* * Rudder is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with Rudder. If not, see . @@ -54,12 +54,10 @@ import com.normation.rudder.repository.FullActiveTechniqueCategory import com.normation.rudder.services.policies.nodeconfig._ import com.normation.rudder.domain.policies.DirectiveId - - @RunWith(classOf[JUnitRunner]) class NodeConfigurationChangeDetectServiceTest extends Specification { - + import com.normation.rudder.services.policies.NodeConfigData._ /* Test the change in node */ def newTechnique(id: TechniqueId) = Technique(id, "tech" + id, "", Seq(), Seq(), TrackerVariableSpec(), SectionSpec("plop"), Set(), None) @@ -127,33 +125,8 @@ class NodeConfigurationChangeDetectServiceTest extends Specification { cf3PolicyDraft = policyVaredOne.cf3PolicyDraft.copy(serial = 1) ) - private val nodeInfo = NodeInfo( - id = NodeId("name") - , name = "name" - , description = "" - , hostname = "hostname" - , machineType = "vm" - , osName = "debian" - , osVersion = "5.4" - , servicePack = None - , ips = List("127.0.0.1") - , inventoryDate = DateTime.now() - , publicKey = "" - , agentsName = Seq(COMMUNITY_AGENT) - , policyServerId= NodeId("root") - , localAdministratorAccountName= "root" - , creationDate = DateTime.now() - , isBroken = false - , isSystem = false - , isPolicyServer= false - , serverRoles = Set() - ) - - private val nodeInfo2 = nodeInfo.copy(name = "name2") - - val emptyNodeConfig = NodeConfiguration( - nodeInfo = nodeInfo + nodeInfo = node1 , policyDrafts= Set[RuleWithCf3PolicyDraft]() , nodeContext = Map[String, Variable]() , parameters = Set[ParameterForConfiguration]() @@ -180,14 +153,13 @@ class NodeConfigurationChangeDetectServiceTest extends Specification { "not have a change if the minimal are different, but there is no CR" in { service.detectChangeInNode( Some(NodeConfigurationCache(emptyNodeConfig)) - , emptyNodeConfig.copy(nodeInfo = nodeInfo2) + , emptyNodeConfig.copy(nodeInfo = node2) , directiveLib , true ) must beTheSameAs(Set()) } } - "An node with one easy CR " should { "not have a change if everything is equal" in { @@ -211,7 +183,7 @@ class NodeConfigurationChangeDetectServiceTest extends Specification { "have its CR that changed if the minimal are different" in { service.detectChangeInNode( Some(NodeConfigurationCache(simpleNodeConfig)) - , simpleNodeConfig.copy(nodeInfo = nodeInfo2) + , simpleNodeConfig.copy(nodeInfo = node2) , directiveLib , true ) === Set(new RuleId("ruleId")) @@ -259,7 +231,7 @@ class NodeConfigurationChangeDetectServiceTest extends Specification { "have a change if minimal is not equals" in { service.detectChangeInNode( Some(NodeConfigurationCache(complexeNodeConfig)) - , complexeNodeConfig.copy(nodeInfo = nodeInfo2) + , complexeNodeConfig.copy(nodeInfo = node2) , directiveLib , true ) === Set(new RuleId("ruleId1")) @@ -269,7 +241,7 @@ class NodeConfigurationChangeDetectServiceTest extends Specification { service.detectChangeInNode( Some(NodeConfigurationCache(complexeNodeConfig)) , complexeNodeConfig.copy( - nodeInfo = nodeInfo2 + nodeInfo = node2 , policyDrafts = Set(nextPolicyVaredOne) ) , directiveLib @@ -298,7 +270,7 @@ class NodeConfigurationChangeDetectServiceTest extends Specification { "have a change if min is different, previous CR is existant and current is non existant" in { service.detectChangeInNode( Some(NodeConfigurationCache(complexeNodeConfig)) - , emptyNodeConfig.copy( nodeInfo = nodeInfo2 ) + , emptyNodeConfig.copy( nodeInfo = node2 ) , directiveLib , true ) === Set(new RuleId("ruleId1")) @@ -307,12 +279,11 @@ class NodeConfigurationChangeDetectServiceTest extends Specification { "have a change if min is different, previous CR is non existant and current is existant" in { service.detectChangeInNode( Some(NodeConfigurationCache(emptyNodeConfig)) - , complexeNodeConfig.copy( nodeInfo = nodeInfo2 ) + , complexeNodeConfig.copy( nodeInfo = node2 ) , directiveLib , true ) === Set(new RuleId("ruleId1")) } } - } \ No newline at end of file diff --git a/rudder-core/src/test/scala/com/normation/rudder/services/path/PathComputerTest.scala b/rudder-core/src/test/scala/com/normation/rudder/services/path/PathComputerTest.scala index 8c0bd73a779..07dff07d389 100644 --- a/rudder-core/src/test/scala/com/normation/rudder/services/path/PathComputerTest.scala +++ b/rudder-core/src/test/scala/com/normation/rudder/services/path/PathComputerTest.scala @@ -4,12 +4,12 @@ ************************************************************************************* * * This file is part of Rudder. -* +* * Rudder is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * In accordance with the terms of section 7 (7. Additional Terms.) of * the GNU General Public License version 3, the copyright holders add * the following Additional permissions: @@ -22,12 +22,12 @@ * documentation that, without modification of the Source Code, enables * supplementary functions or services in addition to those offered by * the Software. -* +* * Rudder is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with Rudder. If not, see . @@ -56,86 +56,11 @@ import com.normation.rudder.domain.policies.DirectiveId import net.liftweb.common.Box import net.liftweb.common.Full - - @RunWith(classOf[JUnitRunner]) class PathComputerTest extends Specification { + import com.normation.rudder.services.policies.NodeConfigData._ - private val root = NodeInfo( - id = NodeId("root") - , name = "root" - , description = "" - , hostname = "hostname" - , machineType = "vm" - , osName = "debian" - , osVersion = "5.4" - , servicePack = None - , ips = List("127.0.0.1") - , inventoryDate = DateTime.now() - , publicKey = "" - , agentsName = Seq(COMMUNITY_AGENT) - , policyServerId= NodeId("root") - , localAdministratorAccountName= "root" - , creationDate = DateTime.now() - , isBroken = false - , isSystem = false - , isPolicyServer= false - , serverRoles = Set() - ) - - private val nodeInfo = NodeInfo( - id = NodeId("name") - , name = "name" - , description = "" - , hostname = "hostname" - , machineType = "vm" - , osName = "debian" - , osVersion = "5.4" - , servicePack = None - , ips = List("127.0.0.1") - , inventoryDate = DateTime.now() - , publicKey = "" - , agentsName = Seq(COMMUNITY_AGENT) - , policyServerId= root.id - , localAdministratorAccountName= "root" - , creationDate = DateTime.now() - , isBroken = false - , isSystem = false - , isPolicyServer= false - , serverRoles = Set() - ) - - private val nodeInfo2 = nodeInfo.copy(id = NodeId("name2"), name = "name2", policyServerId = nodeInfo.id ) - - val rootNodeConfig = NodeConfiguration( - nodeInfo = root - , policyDrafts= Set[RuleWithCf3PolicyDraft]() - , nodeContext = Map[String, Variable]() - , parameters = Set[ParameterForConfiguration]() - , writtenDate = None - , isRootServer= false - ) - - val nodeConfig = NodeConfiguration( - nodeInfo = nodeInfo - , policyDrafts= Set[RuleWithCf3PolicyDraft]() - , nodeContext = Map[String, Variable]() - , parameters = Set[ParameterForConfiguration]() - , writtenDate = None - , isRootServer= false - ) - - val nodeConfig2 = NodeConfiguration( - nodeInfo = nodeInfo2 - , policyDrafts= Set[RuleWithCf3PolicyDraft]() - , nodeContext = Map[String, Variable]() - , parameters = Set[ParameterForConfiguration]() - , writtenDate = None - , isRootServer= false - ) - - - val allNodeConfig = Map(root.id -> rootNodeConfig, nodeInfo.id -> nodeConfig, nodeInfo2.id -> nodeConfig2) + val allNodeConfig = Map(root.id -> rootNodeConfig, node1.id -> node1NodeConfig, node2.id -> node2NodeConfig) val pathComputer = new PathComputerImpl("/var/rudder/backup/") ////////////////////////// test ////////////////////////// @@ -143,17 +68,16 @@ class PathComputerTest extends Specification { "The paths for " should { "the nodeConfig should be " in { - pathComputer.computeBaseNodePath(nodeInfo.id, root.id, allNodeConfig) must - beEqualTo(Full(("/var/rudder/share/name/rules", "/var/rudder/share/name/rules.new", "/var/rudder/backup/name/rules"))) + pathComputer.computeBaseNodePath(node1.id, root.id, allNodeConfig) must + beEqualTo(Full((s"/var/rudder/share/${id1.value}/rules", s"/var/rudder/share/${id1.value}/rules.new", s"/var/rudder/backup/${id1.value}/rules"))) } "the nodeConfig2, behind a relay should be " in { - pathComputer.computeBaseNodePath(nodeInfo2.id, root.id, allNodeConfig) must - beEqualTo(Full(("/var/rudder/share/name/share/name2/rules", "/var/rudder/share/name/share/name2/rules.new", "/var/rudder/backup/name/share/name2/rules"))) + pathComputer.computeBaseNodePath(node2.id, root.id, allNodeConfig) must + beEqualTo(Full((s"/var/rudder/share/${id1.value}/share/${id2.value}/rules", s"/var/rudder/share/${id1.value}/share/${id2.value}/rules.new", s"/var/rudder/backup/${id1.value}/share/${id2.value}/rules"))) } } - } diff --git a/rudder-core/src/test/scala/com/normation/rudder/services/policies/NodeConfigData.scala b/rudder-core/src/test/scala/com/normation/rudder/services/policies/NodeConfigData.scala new file mode 100644 index 00000000000..fbfbfbe4ee4 --- /dev/null +++ b/rudder-core/src/test/scala/com/normation/rudder/services/policies/NodeConfigData.scala @@ -0,0 +1,202 @@ +/* +************************************************************************************* +* Copyright 2015 Normation SAS +************************************************************************************* +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* In accordance with the terms of section 7 (7. Additional Terms.) of +* the GNU Affero GPL v3, the copyright holders add the following +* Additional permissions: +* Notwithstanding to the terms of section 5 (5. Conveying Modified Source +* Versions) and 6 (6. Conveying Non-Source Forms.) of the GNU Affero GPL v3 +* licence, when you create a Related Module, this Related Module is +* not considered as a part of the work and may be distributed under the +* license agreement of your choice. +* A "Related Module" means a set of sources files including their +* documentation that, without modification of the Source Code, enables +* supplementary functions or services in addition to those offered by +* the Software. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +************************************************************************************* +*/ + +package com.normation.rudder.services.policies + +import com.normation.rudder.services.policies.nodeconfig.NodeConfiguration +import com.normation.rudder.domain.nodes.NodeInfo +import com.normation.inventory.domain.NodeId +import com.normation.rudder.services.policies.nodeconfig.ParameterForConfiguration +import com.normation.inventory.domain.COMMUNITY_AGENT +import com.normation.cfclerk.domain.Variable +import org.joda.time.DateTime +import com.normation.inventory.domain.NodeSummary +import com.normation.inventory.domain.Linux +import com.normation.inventory.domain.AcceptedInventory +import com.normation.inventory.domain.Debian +import com.normation.inventory.domain.NodeInventory +import com.normation.inventory.domain.Version +import com.normation.inventory.domain.EnvironmentVariable +import com.normation.inventory.domain.ServerRole +import com.normation.rudder.domain.nodes.Node +import com.normation.rudder.domain.policies.RuleWithCf3PolicyDraft + +/* + * This file is a container for testing data that are a little boring to + * define, like node info, node config, etc. so that their declaration + * can be share among tests. + */ +object NodeConfigData { + + //val emptyNodeReportingConfiguration = ReportingConfiguration(None,None) + + val id1 = NodeId("node1") + val hostname1 = "node1.localhost" + val admin1 = "root" + val id2 = NodeId("node2") + val rootId = NodeId("root") + val rootHostname = "server.rudder.local" + val rootAdmin = "root" + + val rootNode = Node ( + rootId + , "root" + , "" + , false + , false + , true +/* , DateTime.now + , emptyNodeReportingConfiguration + , Seq()*/ + ) + val root = NodeInfo ( + rootNode + , rootHostname + , "vm" + , "Debian" + , "7.0" + , None + , List("127.0.0.1", "192.168.0.100") + , DateTime.now + , "" + , Seq(COMMUNITY_AGENT) + , rootId + , rootAdmin + , DateTime.now + , Set( //by default server roles for root + "rudder-db" + , "rudder-inventory-endpoint" + , "rudder-inventory-ldap" + , "rudder-jetty" + , "rudder-ldap" + , "rudder-reports" + , "rudder-server-root" + , "rudder-webapp" + ).map(ServerRole(_)) + ) + + val node1Node = Node ( + id1 + , "node1" + , "" + , false + , false + , true + /*, DateTime.now + , emptyNodeReportingConfiguration + , Seq()*/ + ) + val node1 = NodeInfo ( + node1Node + , hostname1 + , "vm" + , "Debian" + , "7.0" + , None + , List("192.168.0.10") + , DateTime.now + , "" + , Seq(COMMUNITY_AGENT) + , rootId + , admin1 + , DateTime.now + , Set() + ) + + val nodeInventory1: NodeInventory = NodeInventory( + NodeSummary( + node1.id + , AcceptedInventory + , node1.localAdministratorAccountName + , node1.hostname + , Linux(Debian, "test machine", new Version("1.0"), None, new Version("3.42")) + , root.id + // 3.1 , UndefinedKey + ) + , name = None + , description = None + , ram = None + , swap = None + , inventoryDate = None + , receiveDate = None + , archDescription = None + , lastLoggedUser = None + , lastLoggedUserTime = None + , agentNames = Seq() + , publicKeys = Seq() + , serverIps = Seq() + , machineId = None //if we want several ids, we would have to ass an "alternate machine" field + , softwareIds = Seq() + , accounts = Seq() + , environmentVariables = Seq(EnvironmentVariable("THE_VAR", Some("THE_VAR value!"))) + , processes = Seq() + , vms = Seq() + , networks = Seq() + , fileSystems = Seq() + , serverRoles = Set() + ) + + //node1 us a relay + val node2Node = node1Node.copy(id = id2, name = id2.value) + val node2 = node1.copy(node = node2Node, policyServerId = node1.id ) + + val allNodesInfo = Map( rootId -> root, node1.id -> node1, node2.id -> node2) + + val rootNodeConfig = NodeConfiguration( + nodeInfo = root + , policyDrafts= Set[RuleWithCf3PolicyDraft]() + , nodeContext = Map[String, Variable]() + , parameters = Set[ParameterForConfiguration]() + , writtenDate = None + , isRootServer= true + ) + + val node1NodeConfig = NodeConfiguration( + nodeInfo = node1 + , policyDrafts= Set[RuleWithCf3PolicyDraft]() + , nodeContext = Map[String, Variable]() + , parameters = Set[ParameterForConfiguration]() + , writtenDate = None + , isRootServer= false + ) + + val node2NodeConfig = NodeConfiguration( + nodeInfo = node2 + , policyDrafts= Set[RuleWithCf3PolicyDraft]() + , nodeContext = Map[String, Variable]() + , parameters = Set[ParameterForConfiguration]() + , writtenDate = None + , isRootServer= false + ) +} diff --git a/rudder-core/src/test/scala/com/normation/rudder/services/policies/TestNodeAndParameterLookup.scala b/rudder-core/src/test/scala/com/normation/rudder/services/policies/TestNodeAndParameterLookup.scala index bab486f013d..595601d7491 100644 --- a/rudder-core/src/test/scala/com/normation/rudder/services/policies/TestNodeAndParameterLookup.scala +++ b/rudder-core/src/test/scala/com/normation/rudder/services/policies/TestNodeAndParameterLookup.scala @@ -4,12 +4,12 @@ ************************************************************************************* * * This file is part of Rudder. -* +* * Rudder is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * In accordance with the terms of section 7 (7. Additional Terms.) of * the GNU General Public License version 3, the copyright holders add * the following Additional permissions: @@ -22,12 +22,12 @@ * documentation that, without modification of the Source Code, enables * supplementary functions or services in addition to those offered by * the Software. -* +* * Rudder is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with Rudder. If not, see . @@ -59,73 +59,20 @@ import scala.collection.immutable.TreeMap //for treemap ordering import InterpolationContext._ - - /** * Test how parametrized variables are replaced for * parametrization with ${rudder.param.XXX} and * ${rudder.node.YYYY} */ - @RunWith(classOf[JUnitRunner]) class TestNodeAndParameterLookup extends Specification { - + import NodeConfigData._ //null is for RuleValService, only used in //rule lookup, node tested here. val compiler = new InterpolatedValueCompilerImpl() val lookupService = new RuleValServiceImpl(compiler) - val id1 = NodeId("node1") - val hostname1 = "node1.localhost" - val admin1 = "root" - val rootId = NodeId("root") - val rootHostname = "root.localhost" - val rootAdmin = "root" - - val node1 = NodeInfo( - id = id1 - , name = "node1" - , description = "" - , hostname = hostname1 - , machineType = "vm" - , osName = "Debian" - , osVersion = "7.0" - , servicePack = None - , ips = List("192.168.0.10") - , inventoryDate = DateTime.now - , publicKey = "" - , agentsName = Seq(COMMUNITY_AGENT) - , policyServerId= rootId - , localAdministratorAccountName= admin1 - , creationDate = DateTime.now - , isBroken = false - , isSystem = false - , isPolicyServer= true - , serverRoles = Set() - ) - val root = NodeInfo( - id = rootId - , name = "root" - , description = "" - , hostname = rootHostname - , machineType = "vm" - , osName = "Debian" - , osVersion = "7.0" - , servicePack = None - , ips = List("192.168.0.100") - , inventoryDate = DateTime.now - , publicKey = "" - , agentsName = Seq(COMMUNITY_AGENT) - , policyServerId= rootId - , localAdministratorAccountName= rootAdmin - , creationDate = DateTime.now - , isBroken = false - , isSystem = false - , isPolicyServer= true - , serverRoles = Set() - ) - val context = InterpolationContext( parameters = Map() , nodeInfo = node1 @@ -134,7 +81,6 @@ class TestNodeAndParameterLookup extends Specification { , nodeContext = Map() ) - def lookup( variables: Seq[Variable] , context: InterpolationContext @@ -148,8 +94,6 @@ class TestNodeAndParameterLookup extends Specification { } } - - //two variables val var1 = InputVariableSpec("var1", "").toVariable(Seq("== ${rudder.param.foo} ==")) val var1_double = InputVariableSpec("var1_double", "").toVariable(Seq("== ${rudder.param.foo}${rudder.param.bar} ==")) @@ -175,7 +119,6 @@ class TestNodeAndParameterLookup extends Specification { , "!${rudder.node.policyserver.admin}^" )) - val badEmptyRudder = InputVariableSpec("empty", "").toVariable(Seq("== ${rudder.} ==")) val badUnclosed = InputVariableSpec("empty", "").toVariable(Seq("== ${rudder.param.foo ==")) val badUnknown = InputVariableSpec("empty", "").toVariable(Seq("== ${rudder.foo} ==")) @@ -256,7 +199,6 @@ class TestNodeAndParameterLookup extends Specification { } } - /** * Test that the interpretation of an AST is * correctly done (with forged interpretation contexts) @@ -278,7 +220,6 @@ class TestNodeAndParameterLookup extends Specification { , expected ) - //map of server.param -> AST val accessors = List( comp("id", context.nodeInfo.id.value) @@ -307,7 +248,6 @@ class TestNodeAndParameterLookup extends Specification { } } - "correctly interpret simple param" in { val res = "p1 replaced" val i = compileAndGet("${rudder.param.p1}") @@ -413,7 +353,6 @@ class TestNodeAndParameterLookup extends Specification { } - "A single parameter" should { "be replaced by its value" in { lookup(Seq(var1), context.copy(parameters = p(fooParam)))( values => @@ -465,7 +404,6 @@ class TestNodeAndParameterLookup extends Specification { } - "A double parameter" should { "be replaced by its value" in { lookup(Seq(var1_double), context.copy(parameters = p(fooParam, barParam)))( values => @@ -497,7 +435,6 @@ class TestNodeAndParameterLookup extends Specification { } } - "Case" should { "not matter in the path" in { lookup(Seq(pathCaseInsensitive), context.copy(parameters = p(fooParam)))( values => diff --git a/rudder-web/src/main/scala/com/normation/rudder/web/components/ShowNodeDetailsFromNode.scala b/rudder-web/src/main/scala/com/normation/rudder/web/components/ShowNodeDetailsFromNode.scala index d7a65c38fe9..bc6a50ae3c2 100644 --- a/rudder-web/src/main/scala/com/normation/rudder/web/components/ShowNodeDetailsFromNode.scala +++ b/rudder-web/src/main/scala/com/normation/rudder/web/components/ShowNodeDetailsFromNode.scala @@ -154,7 +154,7 @@ class ShowNodeDetailsFromNode(
    {DisplayNodeGroupTree.buildTreeKeepingGroupWithNode(groupLib, node)}
- , "nodeDetails" -> DisplayNode.showNodeDetails(inventory, Some(node.creationDate), AcceptedInventory, isDisplayingInPopup = withinPopup) + , "nodeDetails" -> DisplayNode.showNodeDetails(inventory,Some(node.creationDate), AcceptedInventory, isDisplayingInPopup = withinPopup) , "inventory" -> DisplayNode.show(inventory, false) , "extraHeader" -> DisplayNode.showExtraHeader(inventory) , "extraContent" -> DisplayNode.showExtraContent(inventory) diff --git a/rudder-web/src/main/scala/com/normation/rudder/web/services/EventListDisplayer.scala b/rudder-web/src/main/scala/com/normation/rudder/web/services/EventListDisplayer.scala index f59cf95e2df..e6b25fc68f4 100644 --- a/rudder-web/src/main/scala/com/normation/rudder/web/services/EventListDisplayer.scala +++ b/rudder-web/src/main/scala/com/normation/rudder/web/services/EventListDisplayer.scala @@ -4,12 +4,12 @@ ************************************************************************************* * * This file is part of Rudder. -* +* * Rudder is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * In accordance with the terms of section 7 (7. Additional Terms.) of * the GNU General Public License version 3, the copyright holders add * the following Additional permissions: @@ -22,12 +22,12 @@ * documentation that, without modification of the Source Code, enables * supplementary functions or services in addition to those offered by * the Software. -* +* * Rudder is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with Rudder. If not, see . @@ -125,7 +125,6 @@ class EventListDisplayer( ).apply(dataTableXml(gridName)) } - def initJs(gridName : String) : JsCmd = { val jsGridName = "oTable" + gridName JsRaw("var %s;".format(jsGridName)) & @@ -230,7 +229,6 @@ class EventListDisplayer( } } - private[this] def dataTableXml(gridName:String) = {
@@ -261,7 +259,6 @@ class EventListDisplayer( } - //////////////////// Display description/details of //////////////////// //convention: "X" means "ignore" @@ -348,7 +345,6 @@ class EventListDisplayer( Text(s"API Account ${name} ${actionName}") } - event match { case x:ActivateRedButton => Text("Stop Rudder agents on all nodes") case x:ReleaseRedButton => Text("Start again Rudder agents on all nodes") @@ -660,7 +656,6 @@ class EventListDisplayer( } xml } - case x:AddDirective => "*" #> { val xml : NodeSeq = logDetailsService.getDirectiveAddDetails(x.details) match { case Full((diff,sectionVal)) => @@ -676,7 +671,6 @@ class EventListDisplayer( } xml} - case x:DeleteDirective => "*" #> { val xml : NodeSeq = logDetailsService.getDirectiveDeleteDetails(x.details) match { case Full((diff,sectionVal)) => @@ -739,7 +733,6 @@ class EventListDisplayer( } xml } - case x:AddNodeGroup => "*" #> { val xml : NodeSeq = logDetailsService.getNodeGroupAddDetails(x.details) match { case Full(diff) => @@ -754,8 +747,6 @@ class EventListDisplayer( } xml } - - case x:DeleteNodeGroup => "*" #> { val xml : NodeSeq = logDetailsService.getNodeGroupDeleteDetails(x.details) match { case Full(diff) => @@ -1197,7 +1188,6 @@ class EventListDisplayer( , ("to ^*" #> "X" & "* *" #> ( (x:NodeSeq) => x))(xml) ) - private[this] def nodeNodeSeqLink(id: NodeId): NodeSeq = { nodeInfoService.getNodeInfo(id) match { case t: EmptyBox => @@ -1447,7 +1437,6 @@ class EventListDisplayer( - private[this] val globalParamDetailsXML =

Global Parameter overview:

@@ -1473,7 +1462,6 @@ class EventListDisplayer(
- private[this] def liModDetailsXML(id:String, name:String) = (
{name} changed: