Update cla-sysrepo and velia to use ietf-hardware
Update cla-sysrepo and velia. They now implement ietf-hardware YANG
model instead of ietf-hardware-state (both defined in RFC 8348 [1]).
With latest changes to cla-sysrepo and velia, we should install
ietf-hardware model instead of ietf-hardware-state now.
Unfortunately, we encountered a bug/feature of Sysrepo. When
uninstalling implemented model which has an imported dependency, then
the YANG model of the imported dependency is not removed from the
repository. See example below.
Link to Sysrepo's issue tracker is in the footer.
We have two implemented models. iana-hardware and ietf-hardware-state.
ietf-hardware model is imported as a dependency of ietf-hardware-state.
# pwd is sysrepo repository
$ sysrepoctl -l | grep hardware | cut -d"|" -f1-3
iana-hardware | 2018-03-13 | I
ietf-hardware | 2018-03-13 | i
ietf-hardware-state | 2018-03-13 | I
$ ls *hardware*
iana-hardware@2018-03-13.yang ietf-hardware-state@2018-03-13.yang ietf-hardware@2018-03-13.yang
$ sysrepoctl -u ietf-hardware-state --apply
$ sysrepoctl -l | grep hardware | cut -d"|" -f1-3
iana-hardware | 2018-03-13 | I
$ ls *hardware*
iana-hardware@2018-03-13.yang ietf-hardware@2018-03-13.yang
[1] https://tools.ietf.org/html/rfc8348
Bug: https://github.com/sysrepo/sysrepo/issues/2263
Depends-on: https://cesnet-gerrit-czechlight/c/CzechLight/cla-sysrepo/+/3352
Depends-on: https://gerrit.cesnet.cz/c/CzechLight/cla-sysrepo/+/3352
Depends-on: https://cesnet-gerrit-czechlight/c/CzechLight/velia/+/3329
Depends-on: https://cesnet-gerrit-public/c/CzechLight/velia/+/3329
Depends-on: https://gerrit.cesnet.cz/c/CzechLight/velia/+/3329
Change-Id: I580e52ff10c5a17f99db18c080b10c1d40aacd78
diff --git a/package/cla-sysrepo/czechlight-install-yang.sh b/package/cla-sysrepo/czechlight-install-yang.sh
index 6585b54..38e4c95 100755
--- a/package/cla-sysrepo/czechlight-install-yang.sh
+++ b/package/cla-sysrepo/czechlight-install-yang.sh
@@ -43,10 +43,24 @@
;;
esac
-if [[ ${IETF_HW_STATE} == 1 && ! -f ${REPO}/ietf-hardware-state@2018-03-13.yang ]]; then
- sysrepoctl --search-dirs ${YANG_DIR} --install ${YANG_DIR}/iana-hardware@2018-03-13.yang
- sysrepoctl --search-dirs ${YANG_DIR} --install ${YANG_DIR}/ietf-hardware-state@2018-03-13.yang
- sysrepoctl --change ietf-hardware-state --permissions 0664 --enable-feature hardware-sensor --apply
+# asks ietf-yang-library model in sysrepo for the state of a module given by $1
+# can return "implement", "import" or "" if the module is not present in the tree
+yang-module-state() {
+ sysrepocfg -f xml -X --xpath "/ietf-yang-library:modules-state/module[name='$1']/conformance-type" -d operational | sed -n 's/\s*<conformance-type>\(.*\)<\/conformance-type>/\1/p'
+}
+
+if [[ ${IETF_HW_STATE} == 1 ]]; then
+ # if old model is implemented, remove it first. This uninstall dependent ietf-hardware if imported and not implemented
+ if [[ "$(yang-module-state ietf-hardware-state)" == "implement" ]]; then
+ sysrepoctl -u ietf-hardware-state --apply
+ fi
+
+ # if new model is not implemented
+ if [[ "$(yang-module-state ietf-hardware)" != "implement" ]]; then
+ sysrepoctl --search-dirs ${YANG_DIR} --install ${YANG_DIR}/iana-hardware@2018-03-13.yang
+ sysrepoctl --search-dirs ${YANG_DIR} --install ${YANG_DIR}/ietf-hardware@2018-03-13.yang
+ sysrepoctl --change ietf-hardware --permissions 0664 --enable-feature hardware-sensor --apply
+ fi
fi
if [[ ${YANG_ROADM} == 1 && ! -f ${REPO}/czechlight-roadm-device@2019-09-30.yang ]]; then