Knowledge Search


×
 

[Junos] "replace pattern" command can create an invalid configuration without displaying any warning or error

  [KB30332] Show Article Properties


Summary:

This article explains the issue of the addition of an invalid configuration when configuring using the replace pattern command.

Symptoms:

The following example shows where an invalid configuration (1G speed on 10G interface) was committed and no error was observed using the replace pattern command. Initially, the gigabit interface was configured with 1G speed.

lab@R1# show interfaces ge-1/0/8
speed 1g;
unit 0 {
    family inet {
        address 1.1.1.1/30;
    }
}

There is no configuration on the 10G interface:

[edit]
lab@R1# show interfaces xe-0/0/0 

[edit]lab@R1#

Do a replace pattern for ge-1/0/8 to xe-0/0/0:

[edit]
lab@R1# replace pattern ge-1/0/8 with xe-0/0/0 

[edit]
lab@R1# 

[edit]
lab@R1# show interfaces xe-0/0/0 
speed 1g;
unit 0 {
    family inet {
        address 1.1.1.1/30;
    }
}
[edit]
lab@R1# show interfaces ge-1/0/8 

[edit]
lab@R1# show | compare 
[edit interfaces]
+    xe-0/0/0 {
+             speed 1g;
+              unit 0 {
+                      family inet {
+                              address 1.1.1.1/30;
+                      }
+               }
+    }
-     ge-1/0/8 {
-             speed 1g;
-             unit 0 {
-                    family inet {
-                            address 1.1.1.1/30;
-                      }
-               }
-     }

Commit is happening without error:

[edit]
lab@R1# commit 
commit complete

[edit]
lab@R1# show interfaces xe-0/0/0 
speed 1g;
unit 0 {
    family inet {
        address 1.1.1.1/30;
    }
}

The same configuration using the CLI shows a "syntax error," as seen below:

lab@R1# set interfaces xe-0/0/0 speed  
                                     
syntax error.
Cause:

The replace command replaces a particular pattern or string with another pattern in the configuration database. As per the current design, any object value in the database matching the pattern is replaced with user-provided text, similar to text replace. The current design of the replace pattern command does  not validate or substantiate the replaced text against the  "action acceptable" or "match." However, if the same is tried from the CLI, it will fail.

Solution:

User should be cautious when using the replace pattern command due to lack of validation for the changed entries. Users should understand the consequence of change in the text  using replace pattern before using it.
Engineering will enhance this behavior in future releases; as of now, there is no ETA available.

Related Links: