yanglint BUGFIX check of parent data node for oper

Checking that a parent data node exists in the datastore for the
nested-notification and action.
diff --git a/tools/lint/common.c b/tools/lint/common.c
index 298936f..2f2905a 100644
--- a/tools/lint/common.c
+++ b/tools/lint/common.c
@@ -598,6 +598,60 @@
     return 0;
 }
 
+/**
+ * @brief Checking that a parent data node exists in the datastore for the nested-notification and action.
+ *
+ * @param[in] op Operation to check.
+ * @param[in] oper_tree Data from datastore.
+ * @param[in] operational_f Operational datastore file information.
+ * @return LY_ERR value.
+ */
+static LY_ERR
+check_operation_parent(struct lyd_node *op, struct lyd_node *oper_tree, struct cmdline_file *operational_f)
+{
+    LY_ERR ret;
+    struct ly_set *set = NULL;
+    char *path = NULL;
+
+    if (!op || !lyd_parent(op)) {
+        /* The function is defined only for nested-notification and action. */
+        return LY_SUCCESS;
+    }
+
+    if (!operational_f || (operational_f && !operational_f->in)) {
+        YLMSG_E("The --operational parameter needed to validate operation \"%s\" is missing.\n", LYD_NAME(op));
+        ret = LY_EVALID;
+        goto cleanup;
+    }
+
+    path = lyd_path(lyd_parent(op), LYD_PATH_STD, NULL, 0);
+    if (!path) {
+        ret = LY_EMEM;
+        goto cleanup;
+    }
+
+    if (!oper_tree) {
+        YLMSG_W("Operational datastore is empty or contains unknown data.\n");
+        YLMSG_E("Operation \"%s\" parent \"%s\" not found in the operational data.\n", LYD_NAME(op), path);
+        ret = LY_EVALID;
+        goto cleanup;
+    }
+    if ((ret = lyd_find_xpath(oper_tree, path, &set))) {
+        goto cleanup;
+    }
+    if (!set->count) {
+        YLMSG_E("Operation \"%s\" parent \"%s\" not found in the operational data.\n", LYD_NAME(op), path);
+        ret = LY_EVALID;
+        goto cleanup;
+    }
+
+cleanup:
+    ly_set_free(set, NULL);
+    free(path);
+
+    return ret;
+}
+
 LY_ERR
 process_data(struct ly_ctx *ctx, enum lyd_type data_type, uint8_t merge, LYD_FORMAT format, struct ly_out *out,
         uint32_t options_parse, uint32_t options_validate, uint32_t options_print, struct cmdline_file *operational_f,
@@ -605,7 +659,6 @@
 {
     LY_ERR ret = LY_SUCCESS;
     struct lyd_node *tree = NULL, *op = NULL, *envp = NULL, *merged_tree = NULL, *oper_tree = NULL;
-    char *path = NULL;
     const char *xpath;
     struct ly_set *set = NULL;
 
@@ -731,21 +784,8 @@
                 goto cleanup;
             }
 
-            if (op && oper_tree && lyd_parent(op)) {
-                /* check operation parent existence */
-                path = lyd_path(lyd_parent(op), LYD_PATH_STD, NULL, 0);
-                if (!path) {
-                    ret = LY_EMEM;
-                    goto cleanup;
-                }
-                if ((ret = lyd_find_xpath(oper_tree, path, &set))) {
-                    goto cleanup;
-                }
-                if (!set->count) {
-                    YLMSG_E("Operation \"%s\" parent \"%s\" not found in the operational data.\n", LYD_NAME(op), path);
-                    ret = LY_EVALID;
-                    goto cleanup;
-                }
+            if ((ret = check_operation_parent(op, oper_tree, operational_f))) {
+                goto cleanup;
             }
         }
 
@@ -789,7 +829,6 @@
     lyd_free_all(envp);
     lyd_free_all(merged_tree);
     lyd_free_all(oper_tree);
-    free(path);
     ly_set_free(set, NULL);
     return ret;
 }
diff --git a/tools/lint/tests/data/modaction_ds.xml b/tools/lint/tests/data/modaction_ds.xml
new file mode 100644
index 0000000..a5a1727
--- /dev/null
+++ b/tools/lint/tests/data/modaction_ds.xml
@@ -0,0 +1,5 @@
+<con xmlns="urn:yanglint:modaction">
+  <ls>
+    <lfkey>kv</lfkey>
+  </ls>
+</con>
diff --git a/tools/lint/tests/data/modnotif_ds.xml b/tools/lint/tests/data/modnotif_ds.xml
new file mode 100644
index 0000000..efd835b
--- /dev/null
+++ b/tools/lint/tests/data/modnotif_ds.xml
@@ -0,0 +1 @@
+<con xmlns="urn:yanglint:modnotif"></con>
diff --git a/tools/lint/tests/interactive/data_operational.test b/tools/lint/tests/interactive/data_operational.test
index 011936a..ce81344 100644
--- a/tools/lint/tests/interactive/data_operational.test
+++ b/tools/lint/tests/interactive/data_operational.test
@@ -32,6 +32,14 @@
     ly_cmd "data -t rpc -O $ddir/modmandatory_invalid.xml $ddir/modrpc.xml"
 }}
 
+test data_operational_empty_datastore {datastore is considered empty because it contains unknown data} {
+-setup $ly_setup -cleanup $ly_cleanup -body {
+    ly_cmd "load modrpc modnotif"
+    ly_cmd "data -t rpc -O $ddir/modmandatory_invalid.xml $ddir/modrpc.xml"
+    set msg "parent \"/modnotif:con\" not found in the operational data"
+    ly_cmd_err "data -t notif -O $ddir/modmandatory_invalid.xml $ddir/modnotif.xml" $msg
+}}
+
 test data_operational_notif_leafref {--operational data is referenced from notification-leafref} {
 -setup $ly_setup -cleanup $ly_cleanup -body {
     ly_cmd "load modoper-leafref"
diff --git a/tools/lint/tests/interactive/data_type.test b/tools/lint/tests/interactive/data_type.test
index 4705ba2..f0538ce 100644
--- a/tools/lint/tests/interactive/data_type.test
+++ b/tools/lint/tests/interactive/data_type.test
@@ -68,22 +68,27 @@
 -setup $ly_setup -cleanup $ly_cleanup -body {
     ly_cmd "load modaction modleaf"
     ly_cmd_err "data -t rpc $ddir/modleaf.xml" "Missing the operation node."
-    ly_cmd "data -t rpc $ddir/modaction.xml"
+    ly_cmd "data -t rpc -O $ddir/modaction_ds.xml $ddir/modaction.xml"
 }}
 
 test data_type_rpc_action_reply {Validation of action-reply by data --type reply} {
 -setup $ly_setup -cleanup $ly_cleanup -body {
     ly_cmd "load modaction modleaf"
     ly_cmd_err "data -t rpc $ddir/modleaf.xml" "Missing the operation node."
-    ly_cmd "data -t reply $ddir/modaction_reply.xml"
+    ly_cmd "data -t reply -O $ddir/modaction_ds.xml $ddir/modaction_reply.xml"
 }}
 
 test data_type_notif {Validation of notification-statement by data --type notif} {
 -setup $ly_setup -cleanup $ly_cleanup -body {
     ly_cmd "load modnotif modleaf"
     ly_cmd_err "data -t notif $ddir/modleaf.xml" "Missing the operation node."
-    ly_cmd "data -t notif $ddir/modnotif.xml"
     ly_cmd "data -t notif $ddir/modnotif2.xml"
 }}
 
+test data_type_notif_nested {Validation of nested-notification-statement by data --type notif} {
+-setup $ly_setup -cleanup $ly_cleanup -body {
+    ly_cmd "load modnotif modleaf"
+    ly_cmd "data -t notif -O $ddir/modnotif_ds.xml $ddir/modnotif.xml"
+}}
+
 cleanupTests
diff --git a/tools/lint/tests/non-interactive/data_operational.test b/tools/lint/tests/non-interactive/data_operational.test
index d027ee9..6635932 100644
--- a/tools/lint/tests/non-interactive/data_operational.test
+++ b/tools/lint/tests/non-interactive/data_operational.test
@@ -24,6 +24,12 @@
     ly_cmd "-t rpc -O $ddir/modmandatory_invalid.xml $mdir/modrpc.yang $ddir/modrpc.xml"
 } {}
 
+test data_operational_empty_datastore {datastore is considered empty because it contains unknown data} {
+    ly_cmd "-t rpc -O $ddir/modmandatory_invalid.xml $mdir/modrpc.yang $ddir/modrpc.xml"
+    set msg "parent \"/modnotif:con\" not found in the operational data"
+    ly_cmd_err "-t notif -O $ddir/modmandatory_invalid.xml $mdir/modnotif.yang $ddir/modnotif.xml" $msg
+} {}
+
 test data_operational_notif_leafref {--operational data is referenced from notification-leafref} {
     ly_cmd "-t notif -O $ddir/modconfig.xml $mdir/modoper-leafref.yang $ddir/modoper_leafref_notif.xml"
 } {}
diff --git a/tools/lint/tests/non-interactive/data_type.test b/tools/lint/tests/non-interactive/data_type.test
index d928d9b..1396b36 100644
--- a/tools/lint/tests/non-interactive/data_type.test
+++ b/tools/lint/tests/non-interactive/data_type.test
@@ -49,18 +49,21 @@
 
 test data_type_rpc_action {Validation of action-statement by data --type rpc} {
     ly_cmd_err "-t rpc $mdir/modleaf.yang $ddir/modleaf.xml" "Missing the operation node."
-    ly_cmd "-t rpc $mdir/modaction.yang $ddir/modaction.xml"
+    ly_cmd "-t rpc -O $ddir/modaction_ds.xml $mdir/modaction.yang $ddir/modaction.xml"
 } {}
 
 test data_type_rpc_action_reply {Validation of action-reply by data --type reply} {
     ly_cmd_err "-t rpc $mdir/modleaf.yang $ddir/modleaf.xml" "Missing the operation node."
-    ly_cmd "-t reply $mdir/modaction.yang $ddir/modaction_reply.xml"
+    ly_cmd "-t reply -O $ddir/modaction_ds.xml $mdir/modaction.yang $ddir/modaction_reply.xml"
 } {}
 
 test data_type_notif {Validation of notification-statement by data --type notif} {
     ly_cmd_err "-t notif $mdir/modleaf.yang $ddir/modleaf.xml" "Missing the operation node."
-    ly_cmd "-t notif $mdir/modnotif.yang $ddir/modnotif.xml"
     ly_cmd "-t notif $mdir/modnotif.yang $ddir/modnotif2.xml"
 } {}
 
+test data_type_notif_nested {Validation of nested-notification-statement by data --type notif} {
+    ly_cmd "-t notif -O $ddir/modnotif_ds.xml $mdir/modnotif.yang $ddir/modnotif.xml"
+} {}
+
 cleanupTests