czechlight-cfg-fs: migration scripts and tests

Sometimes we need to make alterations to the startup datastore (for
instance when new feature to the YANG model is added). This commit
introduces a migration script that is to be run after the machine boots.

The persistent /cfg now stores not just the data, but also the system
SW version which produced the stored configuration. Upon boot, the
current system looks at the previous config (the startup.json file
located at /cfg/sysrepo) and its associated system version
(/cfg/sysrepo/version), and if any changes need to happen, they are
automatically applied.

This commit introduces first migration.
This initial content makes sure that there's something (like a default
channel plan, or some mandatory YANG data nodes) when booting from
factory defaults (or from a pre-versioning SW release). Since this is a
one-shot operation, the operator is free to overwrite the data (e.g.,
rewrite the channel plan), and the system will happily accept the new data
as long as they pass the YANG validation. This is different from the
previous behavior of the SW stack which would apply the defaults during
each boot, even when the configuration was restored.

We also introduce tests for these migrations scripts. They are located
under tests/czechlight-cfg-fs directory and there is a pytest runner.
Each test case is a single directory containing current startup DS
content (as JSON file), expected content after running migrations,
and three control files: One for current startup DS version (so we know
which migrations to run), one for cmdline (so both scripts
czechlight-install-yang and czechlight-migrate can distinguish between
czechlight box types in code), and xpath file used only if we want to
check for a part of the sysrepo DS content.

The tests simulate the workflow that is done when the system boots.
I.e., they install YANG models, restore startup DS backup into sysrepo
and then they run the migrations if necessary.

Change-Id: I96191630fd6b3a1ffbc5ba9f62c4a6c14ab5ed92
diff --git a/tests/czechlight-cfg-fs/data/v0_sdn-roadm-line_empty/cmdline b/tests/czechlight-cfg-fs/data/v0_sdn-roadm-line_empty/cmdline
new file mode 100644
index 0000000..6b1d906
--- /dev/null
+++ b/tests/czechlight-cfg-fs/data/v0_sdn-roadm-line_empty/cmdline
@@ -0,0 +1 @@
+czechlight=sdn-roadm-line
diff --git a/tests/czechlight-cfg-fs/data/v0_sdn-roadm-line_empty/expected.json b/tests/czechlight-cfg-fs/data/v0_sdn-roadm-line_empty/expected.json
new file mode 100644
index 0000000..4ab1a31
--- /dev/null
+++ b/tests/czechlight-cfg-fs/data/v0_sdn-roadm-line_empty/expected.json
@@ -0,0 +1,732 @@
+{
+  "czechlight-roadm-device:channel-plan": {
+    "channel": [
+      {
+        "name": "C-band",
+        "lower-frequency": "191325000",
+        "upper-frequency": "196125000"
+      },
+      {
+        "name": "13.5",
+        "lower-frequency": "191325000",
+        "upper-frequency": "191375000"
+      },
+      {
+        "name": "14.0",
+        "lower-frequency": "191375000",
+        "upper-frequency": "191425000"
+      },
+      {
+        "name": "14.5",
+        "lower-frequency": "191425000",
+        "upper-frequency": "191475000"
+      },
+      {
+        "name": "15.0",
+        "lower-frequency": "191475000",
+        "upper-frequency": "191525000"
+      },
+      {
+        "name": "15.5",
+        "lower-frequency": "191525000",
+        "upper-frequency": "191575000"
+      },
+      {
+        "name": "16.0",
+        "lower-frequency": "191575000",
+        "upper-frequency": "191625000"
+      },
+      {
+        "name": "16.5",
+        "lower-frequency": "191625000",
+        "upper-frequency": "191675000"
+      },
+      {
+        "name": "17.0",
+        "lower-frequency": "191675000",
+        "upper-frequency": "191725000"
+      },
+      {
+        "name": "17.5",
+        "lower-frequency": "191725000",
+        "upper-frequency": "191775000"
+      },
+      {
+        "name": "18.0",
+        "lower-frequency": "191775000",
+        "upper-frequency": "191825000"
+      },
+      {
+        "name": "18.5",
+        "lower-frequency": "191825000",
+        "upper-frequency": "191875000"
+      },
+      {
+        "name": "19.0",
+        "lower-frequency": "191875000",
+        "upper-frequency": "191925000"
+      },
+      {
+        "name": "19.5",
+        "lower-frequency": "191925000",
+        "upper-frequency": "191975000"
+      },
+      {
+        "name": "20.0",
+        "lower-frequency": "191975000",
+        "upper-frequency": "192025000"
+      },
+      {
+        "name": "20.5",
+        "lower-frequency": "192025000",
+        "upper-frequency": "192075000"
+      },
+      {
+        "name": "21.0",
+        "lower-frequency": "192075000",
+        "upper-frequency": "192125000"
+      },
+      {
+        "name": "21.5",
+        "lower-frequency": "192125000",
+        "upper-frequency": "192175000"
+      },
+      {
+        "name": "22.0",
+        "lower-frequency": "192175000",
+        "upper-frequency": "192225000"
+      },
+      {
+        "name": "22.5",
+        "lower-frequency": "192225000",
+        "upper-frequency": "192275000"
+      },
+      {
+        "name": "23.0",
+        "lower-frequency": "192275000",
+        "upper-frequency": "192325000"
+      },
+      {
+        "name": "23.5",
+        "lower-frequency": "192325000",
+        "upper-frequency": "192375000"
+      },
+      {
+        "name": "24.0",
+        "lower-frequency": "192375000",
+        "upper-frequency": "192425000"
+      },
+      {
+        "name": "24.5",
+        "lower-frequency": "192425000",
+        "upper-frequency": "192475000"
+      },
+      {
+        "name": "25.0",
+        "lower-frequency": "192475000",
+        "upper-frequency": "192525000"
+      },
+      {
+        "name": "25.5",
+        "lower-frequency": "192525000",
+        "upper-frequency": "192575000"
+      },
+      {
+        "name": "26.0",
+        "lower-frequency": "192575000",
+        "upper-frequency": "192625000"
+      },
+      {
+        "name": "26.5",
+        "lower-frequency": "192625000",
+        "upper-frequency": "192675000"
+      },
+      {
+        "name": "27.0",
+        "lower-frequency": "192675000",
+        "upper-frequency": "192725000"
+      },
+      {
+        "name": "27.5",
+        "lower-frequency": "192725000",
+        "upper-frequency": "192775000"
+      },
+      {
+        "name": "28.0",
+        "lower-frequency": "192775000",
+        "upper-frequency": "192825000"
+      },
+      {
+        "name": "28.5",
+        "lower-frequency": "192825000",
+        "upper-frequency": "192875000"
+      },
+      {
+        "name": "29.0",
+        "lower-frequency": "192875000",
+        "upper-frequency": "192925000"
+      },
+      {
+        "name": "29.5",
+        "lower-frequency": "192925000",
+        "upper-frequency": "192975000"
+      },
+      {
+        "name": "30.0",
+        "lower-frequency": "192975000",
+        "upper-frequency": "193025000"
+      },
+      {
+        "name": "30.5",
+        "lower-frequency": "193025000",
+        "upper-frequency": "193075000"
+      },
+      {
+        "name": "31.0",
+        "lower-frequency": "193075000",
+        "upper-frequency": "193125000"
+      },
+      {
+        "name": "31.5",
+        "lower-frequency": "193125000",
+        "upper-frequency": "193175000"
+      },
+      {
+        "name": "32.0",
+        "lower-frequency": "193175000",
+        "upper-frequency": "193225000"
+      },
+      {
+        "name": "32.5",
+        "lower-frequency": "193225000",
+        "upper-frequency": "193275000"
+      },
+      {
+        "name": "33.0",
+        "lower-frequency": "193275000",
+        "upper-frequency": "193325000"
+      },
+      {
+        "name": "33.5",
+        "lower-frequency": "193325000",
+        "upper-frequency": "193375000"
+      },
+      {
+        "name": "34.0",
+        "lower-frequency": "193375000",
+        "upper-frequency": "193425000"
+      },
+      {
+        "name": "34.5",
+        "lower-frequency": "193425000",
+        "upper-frequency": "193475000"
+      },
+      {
+        "name": "35.0",
+        "lower-frequency": "193475000",
+        "upper-frequency": "193525000"
+      },
+      {
+        "name": "35.5",
+        "lower-frequency": "193525000",
+        "upper-frequency": "193575000"
+      },
+      {
+        "name": "36.0",
+        "lower-frequency": "193575000",
+        "upper-frequency": "193625000"
+      },
+      {
+        "name": "36.5",
+        "lower-frequency": "193625000",
+        "upper-frequency": "193675000"
+      },
+      {
+        "name": "37.0",
+        "lower-frequency": "193675000",
+        "upper-frequency": "193725000"
+      },
+      {
+        "name": "37.5",
+        "lower-frequency": "193725000",
+        "upper-frequency": "193775000"
+      },
+      {
+        "name": "38.0",
+        "lower-frequency": "193775000",
+        "upper-frequency": "193825000"
+      },
+      {
+        "name": "38.5",
+        "lower-frequency": "193825000",
+        "upper-frequency": "193875000"
+      },
+      {
+        "name": "39.0",
+        "lower-frequency": "193875000",
+        "upper-frequency": "193925000"
+      },
+      {
+        "name": "39.5",
+        "lower-frequency": "193925000",
+        "upper-frequency": "193975000"
+      },
+      {
+        "name": "40.0",
+        "lower-frequency": "193975000",
+        "upper-frequency": "194025000"
+      },
+      {
+        "name": "40.5",
+        "lower-frequency": "194025000",
+        "upper-frequency": "194075000"
+      },
+      {
+        "name": "41.0",
+        "lower-frequency": "194075000",
+        "upper-frequency": "194125000"
+      },
+      {
+        "name": "41.5",
+        "lower-frequency": "194125000",
+        "upper-frequency": "194175000"
+      },
+      {
+        "name": "42.0",
+        "lower-frequency": "194175000",
+        "upper-frequency": "194225000"
+      },
+      {
+        "name": "42.5",
+        "lower-frequency": "194225000",
+        "upper-frequency": "194275000"
+      },
+      {
+        "name": "43.0",
+        "lower-frequency": "194275000",
+        "upper-frequency": "194325000"
+      },
+      {
+        "name": "43.5",
+        "lower-frequency": "194325000",
+        "upper-frequency": "194375000"
+      },
+      {
+        "name": "44.0",
+        "lower-frequency": "194375000",
+        "upper-frequency": "194425000"
+      },
+      {
+        "name": "44.5",
+        "lower-frequency": "194425000",
+        "upper-frequency": "194475000"
+      },
+      {
+        "name": "45.0",
+        "lower-frequency": "194475000",
+        "upper-frequency": "194525000"
+      },
+      {
+        "name": "45.5",
+        "lower-frequency": "194525000",
+        "upper-frequency": "194575000"
+      },
+      {
+        "name": "46.0",
+        "lower-frequency": "194575000",
+        "upper-frequency": "194625000"
+      },
+      {
+        "name": "46.5",
+        "lower-frequency": "194625000",
+        "upper-frequency": "194675000"
+      },
+      {
+        "name": "47.0",
+        "lower-frequency": "194675000",
+        "upper-frequency": "194725000"
+      },
+      {
+        "name": "47.5",
+        "lower-frequency": "194725000",
+        "upper-frequency": "194775000"
+      },
+      {
+        "name": "48.0",
+        "lower-frequency": "194775000",
+        "upper-frequency": "194825000"
+      },
+      {
+        "name": "48.5",
+        "lower-frequency": "194825000",
+        "upper-frequency": "194875000"
+      },
+      {
+        "name": "49.0",
+        "lower-frequency": "194875000",
+        "upper-frequency": "194925000"
+      },
+      {
+        "name": "49.5",
+        "lower-frequency": "194925000",
+        "upper-frequency": "194975000"
+      },
+      {
+        "name": "50.0",
+        "lower-frequency": "194975000",
+        "upper-frequency": "195025000"
+      },
+      {
+        "name": "50.5",
+        "lower-frequency": "195025000",
+        "upper-frequency": "195075000"
+      },
+      {
+        "name": "51.0",
+        "lower-frequency": "195075000",
+        "upper-frequency": "195125000"
+      },
+      {
+        "name": "51.5",
+        "lower-frequency": "195125000",
+        "upper-frequency": "195175000"
+      },
+      {
+        "name": "52.0",
+        "lower-frequency": "195175000",
+        "upper-frequency": "195225000"
+      },
+      {
+        "name": "52.5",
+        "lower-frequency": "195225000",
+        "upper-frequency": "195275000"
+      },
+      {
+        "name": "53.0",
+        "lower-frequency": "195275000",
+        "upper-frequency": "195325000"
+      },
+      {
+        "name": "53.5",
+        "lower-frequency": "195325000",
+        "upper-frequency": "195375000"
+      },
+      {
+        "name": "54.0",
+        "lower-frequency": "195375000",
+        "upper-frequency": "195425000"
+      },
+      {
+        "name": "54.5",
+        "lower-frequency": "195425000",
+        "upper-frequency": "195475000"
+      },
+      {
+        "name": "55.0",
+        "lower-frequency": "195475000",
+        "upper-frequency": "195525000"
+      },
+      {
+        "name": "55.5",
+        "lower-frequency": "195525000",
+        "upper-frequency": "195575000"
+      },
+      {
+        "name": "56.0",
+        "lower-frequency": "195575000",
+        "upper-frequency": "195625000"
+      },
+      {
+        "name": "56.5",
+        "lower-frequency": "195625000",
+        "upper-frequency": "195675000"
+      },
+      {
+        "name": "57.0",
+        "lower-frequency": "195675000",
+        "upper-frequency": "195725000"
+      },
+      {
+        "name": "57.5",
+        "lower-frequency": "195725000",
+        "upper-frequency": "195775000"
+      },
+      {
+        "name": "58.0",
+        "lower-frequency": "195775000",
+        "upper-frequency": "195825000"
+      },
+      {
+        "name": "58.5",
+        "lower-frequency": "195825000",
+        "upper-frequency": "195875000"
+      },
+      {
+        "name": "59.0",
+        "lower-frequency": "195875000",
+        "upper-frequency": "195925000"
+      },
+      {
+        "name": "59.5",
+        "lower-frequency": "195925000",
+        "upper-frequency": "195975000"
+      },
+      {
+        "name": "60.0",
+        "lower-frequency": "195975000",
+        "upper-frequency": "196025000"
+      },
+      {
+        "name": "60.5",
+        "lower-frequency": "196025000",
+        "upper-frequency": "196075000"
+      },
+      {
+        "name": "61.0",
+        "lower-frequency": "196075000",
+        "upper-frequency": "196125000"
+      },
+      {
+        "name": "14 (100GHz)",
+        "lower-frequency": "191350000",
+        "upper-frequency": "191450000"
+      },
+      {
+        "name": "15 (100GHz)",
+        "lower-frequency": "191450000",
+        "upper-frequency": "191550000"
+      },
+      {
+        "name": "16 (100GHz)",
+        "lower-frequency": "191550000",
+        "upper-frequency": "191650000"
+      },
+      {
+        "name": "17 (100GHz)",
+        "lower-frequency": "191650000",
+        "upper-frequency": "191750000"
+      },
+      {
+        "name": "18 (100GHz)",
+        "lower-frequency": "191750000",
+        "upper-frequency": "191850000"
+      },
+      {
+        "name": "19 (100GHz)",
+        "lower-frequency": "191850000",
+        "upper-frequency": "191950000"
+      },
+      {
+        "name": "20 (100GHz)",
+        "lower-frequency": "191950000",
+        "upper-frequency": "192050000"
+      },
+      {
+        "name": "21 (100GHz)",
+        "lower-frequency": "192050000",
+        "upper-frequency": "192150000"
+      },
+      {
+        "name": "22 (100GHz)",
+        "lower-frequency": "192150000",
+        "upper-frequency": "192250000"
+      },
+      {
+        "name": "23 (100GHz)",
+        "lower-frequency": "192250000",
+        "upper-frequency": "192350000"
+      },
+      {
+        "name": "24 (100GHz)",
+        "lower-frequency": "192350000",
+        "upper-frequency": "192450000"
+      },
+      {
+        "name": "25 (100GHz)",
+        "lower-frequency": "192450000",
+        "upper-frequency": "192550000"
+      },
+      {
+        "name": "26 (100GHz)",
+        "lower-frequency": "192550000",
+        "upper-frequency": "192650000"
+      },
+      {
+        "name": "27 (100GHz)",
+        "lower-frequency": "192650000",
+        "upper-frequency": "192750000"
+      },
+      {
+        "name": "28 (100GHz)",
+        "lower-frequency": "192750000",
+        "upper-frequency": "192850000"
+      },
+      {
+        "name": "29 (100GHz)",
+        "lower-frequency": "192850000",
+        "upper-frequency": "192950000"
+      },
+      {
+        "name": "30 (100GHz)",
+        "lower-frequency": "192950000",
+        "upper-frequency": "193050000"
+      },
+      {
+        "name": "31 (100GHz)",
+        "lower-frequency": "193050000",
+        "upper-frequency": "193150000"
+      },
+      {
+        "name": "32 (100GHz)",
+        "lower-frequency": "193150000",
+        "upper-frequency": "193250000"
+      },
+      {
+        "name": "33 (100GHz)",
+        "lower-frequency": "193250000",
+        "upper-frequency": "193350000"
+      },
+      {
+        "name": "34 (100GHz)",
+        "lower-frequency": "193350000",
+        "upper-frequency": "193450000"
+      },
+      {
+        "name": "35 (100GHz)",
+        "lower-frequency": "193450000",
+        "upper-frequency": "193550000"
+      },
+      {
+        "name": "36 (100GHz)",
+        "lower-frequency": "193550000",
+        "upper-frequency": "193650000"
+      },
+      {
+        "name": "37 (100GHz)",
+        "lower-frequency": "193650000",
+        "upper-frequency": "193750000"
+      },
+      {
+        "name": "38 (100GHz)",
+        "lower-frequency": "193750000",
+        "upper-frequency": "193850000"
+      },
+      {
+        "name": "39 (100GHz)",
+        "lower-frequency": "193850000",
+        "upper-frequency": "193950000"
+      },
+      {
+        "name": "40 (100GHz)",
+        "lower-frequency": "193950000",
+        "upper-frequency": "194050000"
+      },
+      {
+        "name": "41 (100GHz)",
+        "lower-frequency": "194050000",
+        "upper-frequency": "194150000"
+      },
+      {
+        "name": "42 (100GHz)",
+        "lower-frequency": "194150000",
+        "upper-frequency": "194250000"
+      },
+      {
+        "name": "43 (100GHz)",
+        "lower-frequency": "194250000",
+        "upper-frequency": "194350000"
+      },
+      {
+        "name": "44 (100GHz)",
+        "lower-frequency": "194350000",
+        "upper-frequency": "194450000"
+      },
+      {
+        "name": "45 (100GHz)",
+        "lower-frequency": "194450000",
+        "upper-frequency": "194550000"
+      },
+      {
+        "name": "46 (100GHz)",
+        "lower-frequency": "194550000",
+        "upper-frequency": "194650000"
+      },
+      {
+        "name": "47 (100GHz)",
+        "lower-frequency": "194650000",
+        "upper-frequency": "194750000"
+      },
+      {
+        "name": "48 (100GHz)",
+        "lower-frequency": "194750000",
+        "upper-frequency": "194850000"
+      },
+      {
+        "name": "49 (100GHz)",
+        "lower-frequency": "194850000",
+        "upper-frequency": "194950000"
+      },
+      {
+        "name": "50 (100GHz)",
+        "lower-frequency": "194950000",
+        "upper-frequency": "195050000"
+      },
+      {
+        "name": "51 (100GHz)",
+        "lower-frequency": "195050000",
+        "upper-frequency": "195150000"
+      },
+      {
+        "name": "52 (100GHz)",
+        "lower-frequency": "195150000",
+        "upper-frequency": "195250000"
+      },
+      {
+        "name": "53 (100GHz)",
+        "lower-frequency": "195250000",
+        "upper-frequency": "195350000"
+      },
+      {
+        "name": "54 (100GHz)",
+        "lower-frequency": "195350000",
+        "upper-frequency": "195450000"
+      },
+      {
+        "name": "55 (100GHz)",
+        "lower-frequency": "195450000",
+        "upper-frequency": "195550000"
+      },
+      {
+        "name": "56 (100GHz)",
+        "lower-frequency": "195550000",
+        "upper-frequency": "195650000"
+      },
+      {
+        "name": "57 (100GHz)",
+        "lower-frequency": "195650000",
+        "upper-frequency": "195750000"
+      },
+      {
+        "name": "58 (100GHz)",
+        "lower-frequency": "195750000",
+        "upper-frequency": "195850000"
+      },
+      {
+        "name": "59 (100GHz)",
+        "lower-frequency": "195850000",
+        "upper-frequency": "195950000"
+      },
+      {
+        "name": "60 (100GHz)",
+        "lower-frequency": "195950000",
+        "upper-frequency": "196050000"
+      }
+    ]
+  },
+  "czechlight-roadm-device:media-channels": [
+    {
+      "channel": "C-band",
+      "description": "Whole-band overview"
+    }
+  ]
+}
diff --git a/tests/czechlight-cfg-fs/data/v0_sdn-roadm-line_empty/startup.json b/tests/czechlight-cfg-fs/data/v0_sdn-roadm-line_empty/startup.json
new file mode 100644
index 0000000..2c63c08
--- /dev/null
+++ b/tests/czechlight-cfg-fs/data/v0_sdn-roadm-line_empty/startup.json
@@ -0,0 +1,2 @@
+{
+}
diff --git a/tests/czechlight-cfg-fs/data/v0_sdn-roadm-line_empty/version b/tests/czechlight-cfg-fs/data/v0_sdn-roadm-line_empty/version
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/tests/czechlight-cfg-fs/data/v0_sdn-roadm-line_empty/version
@@ -0,0 +1 @@
+0