Skip to content

Commit

Permalink
Fixes #13810: Update ldap node entries from ipNetworkNumber => networ…
Browse files Browse the repository at this point in the history
…kSubnet
  • Loading branch information
fanf committed Nov 12, 2018
1 parent fd95d3b commit c6af419
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions rudder-webapp/SOURCES/rudder-upgrade
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ trap anomaly_handler ERR INT TERM
# - 4.1.0 : Migrate script properties to hooks
# - 4.1.12 : Create nodecompliancelevels table
# - 4.1.12 : Add new property rudder.batch.reportscleaner.compliancelevels.delete.TTL
# - 4.1.17 : Change LDAP attribute ipNetworkNumber -> networkSubnet
####################################################################################

# Some paths
Expand Down Expand Up @@ -146,6 +147,7 @@ JETTY_INIT="service rudder-jetty"
LDAPSEARCH="ldapsearch ${LDAP_PARAMETERS} -LLL"
LDAPMODRDN="ldapmodrdn ${LDAP_PARAMETERS}"
LDAPADD="ldapadd ${LDAP_PARAMETERS}"
LDAPMODIFY="ldapmodify ${LDAP_PARAMETERS}"

PSQL="psql -q -h ${SQL_SERVER} -p ${SQL_PORT} -U ${SQL_USER}"

Expand Down Expand Up @@ -760,6 +762,56 @@ upgrade_inventory() {
echo " Done."
fi

# - 4.1.17, 4.3.7, 5.0.3: ipNetworkNumber -> networkSubnet
STEP="Migrate LDAP attribute ipNetworkNumber in networkInterface"
# change:
# dn: networkInterface=etho0,nodeId=0876521e-3c81-4775-85c7-5dd7f9d5d3da,ou=Nodes,ou=Accepted Inventories,ou=Inventories,cn=rudder-configuration
# ipNetworkNumber: 192.268.1.1
# ipNetworkNumber: ffff:::1
#
# into:
# dn: networkInterface=lo,nodeId=0876521e-3c81-4775-85c7-5dd7f9d5d3da,ou=Nodes,ou=Accepted Inventories,ou=Inventories,cn=rudder-configuration
# changetype: modify
# delete: ipNetworkNumber
# -
# replace: networkSubnet
# networkSubnet: 192.268.1.1
# networkSubnet: ffff:::1
# -
#
LDAP_TEST_MIGRATE_NETWORK=$(${LDAPSEARCH} -b "ou=Inventories,cn=rudder-configuration" -s sub '(&(objectClass=networkInterfaceLogicalElement)(ipNetworkNumber=*))' 1.1 2> /dev/null | grep -c "dn: networkInterface=" || true)
if [ ${LDAP_TEST_MIGRATE_NETWORK} -eq 0 ]; then
echo -n "INFO: migrate LDAP attribute ipNetworkNumber -> networkSubnet in networkInterface"
MIGRATE_IPNET_FILE="/tmp/rudder-migrate-ipNetworkNumber-network.ldif"
${LDAPSEARCH} -o ldif-wrap=no -b "ou=Inventories,cn=rudder-configuration" -s sub '(&(objectClass=networkInterfaceLogicalElement)(ipNetworkNumber=*))' 'ipNetworkNumber' > ${MIGRATE_IPNET_FILE}
sed -i -e "s/ipNetworkNumber/networkSubnet/" ${MIGRATE_IPNET_FILE}
sed -i -e "s/dn:\(.*\)$/dn:\1\nchangetype:modify\ndelete: ipNetworkNumber\n-\nreplace: networkSubnet/" ${MIGRATE_IPNET_FILE}
sed -i -e "s/^$/-\n/" ${MIGRATE_IPNET_FILE}
${LDAPMODIFY} -l ${MIGRATE_IPNET_FILE} && rm ${MIGRATE_IPNET_FILE}
fi

STEP="Migrate LDAP attribute ipNetworkNumber in node group query"
# change:
# dn: nodeGroupId=ede838d0-b064-4739-a03e-f6a7651dce7b,groupCategoryId=GroupRoot,ou=Rudder,cn=rudder-configuration
# jsonNodeGroupQuery: {"select":"node","composition":"And","where":[{"objectType":"networkInterfaceLogicalElement","attribute":"ipNetworkNumber","comparator":"regex","value":"192.168.42.*"}]}
#
# into:
# dn: nodeGroupId=ede838d0-b064-4739-a03e-f6a7651dce7b,groupCategoryId=GroupRoot,ou=Rudder,cn=rudder-configuration
# changetype: modify
# replace: jsonNodeGroupQuery
# jsonNodeGroupQuery: {"select":"node","composition":"And","where":[{"objectType":"networkInterfaceLogicalElement","attribute":"networkSubnet","comparator":"regex","value":"192.168.42.*"}]}
# -
#
LDAP_TEST_MIGRATE_GROUP=$(${LDAPSEARCH} -b "ou=Rudder,,cn=rudder-configuration" -s sub '(&(objectClass=nodeGroup)(jsonNodeGroupQuery=*ipNetworkNumber*))' 1.1 2> /dev/null | grep -c "dn: nodeGroupId=" || true)
if [ ${LDAP_TEST_MIGRATE_GROUP} -eq 0 ]; then
echo -n "INFO: migrate LDAP attribute ipNetworkNumber -> networkSubnet in networkInterface"
MIGRATE_IPNET_FILE="/tmp/rudder-migrate-ipNetworkNumber-group.ldif"
${LDAPSEARCH} -o ldif-wrap=no -b "ou=Inventories,cn=rudder-configuration" -s sub '(&(objectClass=nodeGroup)(jsonNodeGroupQuery=*ipNetworkNumber*))' 'jsonNodeGroupQuery' > ${MIGRATE_IPNET_FILE}
sed -i -e "s/^$/-\n\n/" ${MIGRATE_IPNET_FILE}
sed -i -e "s/ipNetworkNumber/networkSubnet/" ${MIGRATE_IPNET_FILE}
sed -i -e "s/jsonNodeGroupQuery/changetype: modify\nreplace: jsonNodeGroupQuery\njsonNodeGroupQuery/" ${MIGRATE_IPNET_FILE}
${LDAPMODIFY} -l ${MIGRATE_IPNET_FILE} && rm ${MIGRATE_IPNET_FILE}
fi
fi

}
Expand Down

0 comments on commit c6af419

Please sign in to comment.