Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request tumblr#154 from byxorna/gabe-extra-provision-attri…
Browse files Browse the repository at this point in the history
…butes

Gabe extra provision attributes
  • Loading branch information
William Richard committed May 2, 2014
2 parents 4fdb81c + 575fdd2 commit 9049196
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/collins/provisioning/ProfileLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ object ProfileLoader {
optionalButNonEmpty(profile.getSecondary_role()),
optionalButNonEmpty(profile.getContact()),
optionalButNonEmpty(profile.getContact_notes()),
profile.getAttributes().asScala.map(a => (a._1.toUpperCase, a._2.toString)).toMap,
profile.getClear_attributes().asScala.map(_.toUpperCase).toSet,
Option(profile.getRequires_primary_role()).map(_.booleanValue()).getOrElse(true),
Option(profile.getRequires_pool()).map(_.booleanValue()).getOrElse(true),
Option(profile.getRequires_secondary_role()).map(_.booleanValue()).getOrElse(false)
Expand Down
4 changes: 3 additions & 1 deletion app/collins/provisioning/ProvisionerRoleData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ case class ProvisionerRoleData(
secondary_role: Option[String],
contact: Option[String],
contact_notes: Option[String],
attributes: Map[String,String],
clear_attributes: Set[String],
requires_primary_role: Boolean,
requires_pool: Boolean,
requires_secondary_role: Boolean
) {
def this() = this(None,None,None,None,None,false,false,false)
def this() = this(None,None,None,None,None,Map(),Set(),false,false,false)
}


13 changes: 9 additions & 4 deletions app/controllers/actions/asset/ProvisionUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ trait ProvisionUtil { self: SecureAction =>
val build_contact = form._2
val suffix = form._3
val role = request.profile.role
val attribSequence =
Seq(
val highPriorityAttrs =
Map(
"NODECLASS" -> request.profile.identifier,
"CONTACT" -> role.contact.getOrElse(""),
"CONTACT_NOTES" -> role.contact_notes.getOrElse(""),
Expand All @@ -111,8 +111,13 @@ trait ProvisionUtil { self: SecureAction =>
"SECONDARY_ROLE" -> role.secondary_role.getOrElse(""),
"BUILD_CONTACT" -> build_contact
)
val mapForDelete = Feature.deleteSomeMetaOnRepurpose.map(_.name).map(s => (s -> "")).toMap
mapForDelete ++ Map(attribSequence:_*)
val lowPriorityAttrs = role.attributes
val clearOnRepurposeAttrs = Feature.deleteSomeMetaOnRepurpose.map(_.name).map(s => (s -> "")).toMap
val clearProfileAttrs = role.clear_attributes.map(a => (a -> "")).toMap

// make sure high priority attrs take precedence over low priority
// and make sure any explicitly set attrs override any that are to be cleared
clearOnRepurposeAttrs ++ clearProfileAttrs ++ lowPriorityAttrs ++ highPriorityAttrs
}

protected def fieldError(form: Form[ProvisionForm]): Validation = (form match {
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/com/tumblr/play/interop/JProfile.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package com.tumblr.play.interop;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;

public class JProfile implements java.io.Serializable {
static final long serialVersionUID = -3055921821909895808L;
Expand All @@ -9,6 +13,8 @@ public class JProfile implements java.io.Serializable {
private String pool;
private String contact;
private String contact_notes;
private Map<String,Object> attributes;
private List<String> clear_attributes;

private Boolean allow_suffix;
private Boolean requires_primary_role;
Expand All @@ -21,6 +27,10 @@ public JProfile() {
primary_role = "";
secondary_role = "";
pool = "";
contact = "";
contact_notes = "";
attributes = new HashMap<String,Object>();
clear_attributes = new ArrayList<String>();
allow_suffix = Boolean.FALSE;
requires_primary_role = Boolean.TRUE;
requires_secondary_role = Boolean.FALSE;
Expand Down Expand Up @@ -62,6 +72,20 @@ public void setContact_notes(final String contact_notes) {
this.contact_notes = contact_notes;
}

public Map<String,Object> getAttributes(){
return attributes;
}
public void setAttributes(final Map<String,Object> attributes) {
this.attributes = attributes;
}

public List<String> getClear_attributes(){
return clear_attributes;
}
public void setClear_attributes(final List<String> clear_attributes) {
this.clear_attributes = clear_attributes;
}

public String getSecondary_role() {
return secondary_role;
}
Expand Down
19 changes: 18 additions & 1 deletion test/collins/provisioning/ProfileLoaderSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ProfileLoaderSpec extends Specification {
}
"The test profiles.yaml should load" should {
"all profiles" >> {
profiles.size === 37
profiles.size === 38
}
"a profile with all values specified" >> {
val profile = profiles.find(_.identifier == "searchnode").get
Expand All @@ -24,6 +24,8 @@ class ProfileLoaderSpec extends Specification {
role.requires_primary_role === false
role.requires_secondary_role === true
role.requires_pool === false
role.attributes === Map()
role.clear_attributes === Set()
}
"a profile with mostly defaults" >> {
val profile = profiles.find(_.identifier == "webnode").get
Expand All @@ -37,6 +39,21 @@ class ProfileLoaderSpec extends Specification {
role.requires_primary_role === true
role.requires_secondary_role === true
role.requires_pool === true
role.attributes === Map()
role.clear_attributes === Set()
}
"a profile with custom attributes" >> {
val profile = profiles.find(_.identifier == "testattributesnode").get
profile.label === "Test Custom Attributes Node"
val role = profile.role
val addattrs = role.attributes
addattrs.keys.size === 4
addattrs.get("SUPER_IMPORTANT_TAG").get === "true"
addattrs.get("LOWER_CASE_ATTRIBUTE").get === "Hello world"
addattrs.get("NUMERIC_ATTRIBUTE").get === "123"
addattrs.get("NODECLASS").get === "shouldnt be set to this"
val clearattrs = role.clear_attributes
clearattrs === Set("NODECLASS","DELETE_ME","SUPER_DANGEROUS_TAG","DUPLICATE_ATTRIBUTE")
}
}
}
27 changes: 27 additions & 0 deletions test/resources/profiles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ profiles:
vlans: ["aaa"]
primary_role: "INFRA"
allow_suffix: true
attributes:
super_important_tag: true
lower_case_attribute: Hello world
numeric_attribute: 123
nodeclass: shouldnt be set to this
clear_attributes:
- nodeclass
- delete_me
- super_dangerous_tag
dhcpnode:
cobbler_profile: "centos-5.6-x86_64-web-v2"
label: "DHCP/iPXE Server"
Expand Down Expand Up @@ -289,3 +298,21 @@ profiles:
pool: "MREPO_POOL"
secondary_role: "MREPO_MIRROR"
allow_suffix: false
testattributesnode:
label: "Test Custom Attributes Node"
prefix: "test"
vlans: ["whatever"]
primary_role: "PRI_ROLE"
requires_pool: no
allow_suffix: true
attributes:
super_important_tag: true
lower_case_attribute: Hello world
numeric_attribute: 123
nodeclass: shouldnt be set to this
clear_attributes:
- nodeclass
- delete_me
- duplicate_attribute
- super_dangerous_tag
- duplicate_attribute

0 comments on commit 9049196

Please sign in to comment.