Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[config] Add ConfigMgmt class for config validation, delete ports, add ports #765

Merged
merged 15 commits into from
Jul 2, 2020

Conversation

praveen-li
Copy link
Member

@praveen-li praveen-li commented Dec 13, 2019

- What I did
Provided a class in sonic_util config for
-- Config Validation,
-- BreakOut Ports

Note: It depends on sonic-net/sonic-buildimage#3861

Test cases are added in this PR but described in a dummy PR #947

- How I did it
--ConfigMgmt Class uploads config data from config_Db.json or from config db using SONiC-py-swsssdk APIs .
--Port, vlan and acl related config is cropped out of entire config, this is because yang models are available only for Vlan, Acl and Port as of now.
--Cropped portion of config DB will be given as input to Python Yang LIB while loading config data.

--ConfigMgmt Class provides APIs to breakout, delete and add Ports.
--Using Python yang LIB APIs, this class finds dependencies for each of the port which must be deleted and will delete dependencies.
-- At last after successful validation, new config is written in config DB.
-- While addition, relevant default config is found for ports which are being added. Then entire new config [default + port] is added to current config in data tree.
-- At last after successful validation, new config is written in config DB.

- How to verify it
On Sonic Switch Ran below Tests

Note: Below tests are done with PR 766 and PR 857 changes.

:::Lock Acquired:::
:::Lock Timer Extended:::

Running Breakout Mode : 4x25G 
Target Breakout Mode : 2x50G

Ports to be deleted : 
 {
    "Ethernet2": "25000", 
    "Ethernet3": "25000", 
    "Ethernet0": "25000", 
    "Ethernet1": "25000"
}
Ports to be added : 
 {
    "Ethernet2": "50000", 
    "Ethernet0": "50000"
}

After running Logic to limit the impact

Final list of ports to be deleted : 
 {
    "Ethernet2": "25000", 
    "Ethernet3": "25000", 
    "Ethernet0": "25000", 
    "Ethernet1": "25000"
} 
Final list of ports to be added :  
 {
    "Ethernet2": "50000", 
    "Ethernet0": "50000"
}
Loaded below Yang Models
['sonic-acl', 'sonic-extension', 'sonic-head', 'sonic-interface', 'sonic-loopback-interface', 'sonic-port', 'sonic-portchannel', 'sonic-vlan']
Reading data from Redis configDb
Note: Below table(s) have no YANG models:
VERSIONS, DEVICE_METADATA, DEVICE_NEIGHBOR, LOCK, FLEX_COUNTER_TABLE, BREAKOUT_CFG, 
Below Config can not be verified, It may cause harm to the system
 {
  "BREAKOUT_CFG": {
    "Ethernet0": {
      "brkout_mode": "4x25G"
    }
  }
}
Do you wish to Continue? [y/N]: 
Start Port Deletion
Find dependecies for port Ethernet2
Find dependecies for port Ethernet3
Find dependecies for port Ethernet0
Find dependecies for port Ethernet1
Deleting Port: Ethernet2
Deleting Port: Ethernet3
Deleting Port: Ethernet0
Deleting Port: Ethernet1
Data Validation successful
Generate Final Config to write in DB

Start Port Addition
Generating default config for ['Ethernet2', 'Ethernet0']
Merge Default Config for ['Ethernet2', 'Ethernet0']
Data Validation successful
Generate Final Config to write in DB
Writing in Config DB
Verify Port Deletion from Asic DB, Wait...
Writing in Config DB
Breakout process got successfully completed.
:::Lock Released:::
+-----------+------------------------+------------+----------------+-----------------------+
|   VLAN ID | IP Address             | Ports      | Port Tagging   | DHCP Helper Address   |
+===========+========================+============+================+=======================+
|       100 | 2a04:f547:43:6a0::1/64 | Ethernet0  | untagged       | 10.186.72.116         |
|           | 10.187.40.1/26         | Ethernet2  | untagged       |                       |
|           | fe80::1/10             | Ethernet4  | untagged       |                       |
|           |                        | Ethernet5  | untagged       |                       |
|           |                        | Ethernet6  | untagged       |                       |
|           |                        | Ethernet7  | untagged       |                       |
|           |                        | Ethernet8  | untagged       |                       |
ps

                 ena/        speed/ link auto    STP                  lrn  inter   max   cut   loop
           port  link  Lns   duplex scan neg?   state   pause  discrd ops   face frame  thru?  back
       xe0( 68)  down   2   50G  FD   SW  No   Forward          None   FA    KR2  9412    No      
       xe1( 69)  !ena   1     -       SW  No   Forward          None    D   None  9412    No      
       xe2( 70)  down   2   50G  FD   SW  No   Forward          None   FA    KR2  9412    No      
       xe3( 71)  !ena   1     -       SW  No   Forward          None    D   None  9412    No      
       xe4( 72)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      
       xe5( 73)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      
       xe6( 74)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      
:::Lock Acquired:::
:::Lock Timer Extended:::

Running Breakout Mode : 2x50G 
Target Breakout Mode : 1x100G

Ports to be deleted : 
 {
    "Ethernet2": "50000", 
    "Ethernet0": "50000"
}
Ports to be added : 
 {
    "Ethernet0": "100000"
}

After running Logic to limit the impact

Final list of ports to be deleted : 
 {
    "Ethernet2": "50000", 
    "Ethernet0": "50000"
} 
Final list of ports to be added :  
 {
    "Ethernet0": "100000"
}
Loaded below Yang Models
['sonic-acl', 'sonic-extension', 'sonic-head', 'sonic-interface', 'sonic-loopback-interface', 'sonic-port', 'sonic-portchannel', 'sonic-vlan']
Reading data from Redis configDb
Note: Below table(s) have no YANG models:
VERSIONS, DEVICE_METADATA, DEVICE_NEIGHBOR, LOCK, FLEX_COUNTER_TABLE, BREAKOUT_CFG, 
Below Config can not be verified, It may cause harm to the system
 {
  "BREAKOUT_CFG": {
    "Ethernet0": {
      "brkout_mode": "2x50G"
    }
  }
}
Do you wish to Continue? [y/N]: 
Start Port Deletion
Find dependecies for port Ethernet2
Find dependecies for port Ethernet0
Dependecies Exist. No further action will be taken
*** Printing dependecies ***
/sonic-vlan:sonic-vlan/VLAN/VLAN_LIST[vlan_name='Vlan100']/members[.='Ethernet2']
/sonic-vlan:sonic-vlan/VLAN/VLAN_LIST[vlan_name='Vlan777']/members[.='Ethernet2']
/sonic-vlan:sonic-vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlan_name='Vlan100'][port='Ethernet2']/port
/sonic-vlan:sonic-vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlan_name='Vlan777'][port='Ethernet2']/port
/sonic-vlan:sonic-vlan/VLAN/VLAN_LIST[vlan_name='Vlan100']/members[.='Ethernet0']
/sonic-vlan:sonic-vlan/VLAN/VLAN_LIST[vlan_name='Vlan777']/members[.='Ethernet0']
/sonic-vlan:sonic-vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlan_name='Vlan100'][port='Ethernet0']/port
/sonic-vlan:sonic-vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlan_name='Vlan777'][port='Ethernet0']/port
:::Lock PID: None and self.pid:29100:::
+-----------+------------------------+------------+----------------+-----------------------+
|   VLAN ID | IP Address             | Ports      | Port Tagging   | DHCP Helper Address   |
+===========+========================+============+================+=======================+
|       100 | 2a04:f547:43:6a0::1/64 | Ethernet0  | untagged       | 10.186.72.116         |
|           | 10.187.40.1/26         | Ethernet2  | untagged       |                       |
|           | fe80::1/10             | Ethernet4  | untagged       |                       |
|           |                        | Ethernet5  | untagged       |                       |
|           |                        | Ethernet6  | untagged       |                       |
|           |                        | Ethernet7  | untagged       |                       |
|           |                        | Ethernet8  | untagged       |                       |
ps

                 ena/        speed/ link auto    STP                  lrn  inter   max   cut   loop
           port  link  Lns   duplex scan neg?   state   pause  discrd ops   face frame  thru?  back
       xe0( 68)  !ena   2   50G  FD   SW  No   Forward          None   FA    KR2  9412    No      
       xe1( 69)  !ena   1     -       SW  No   Forward          None    D   None  9412    No      
       xe2( 70)  !ena   2   50G  FD   SW  No   Forward          None   FA    KR2  9412    No      
       xe3( 71)  !ena   1     -       SW  No   Forward          None    D   None  9412    No      
       xe4( 72)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      
       xe5( 73)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      
       xe6( 74)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      
:::Lock Acquired:::
:::Lock Timer Extended:::

Running Breakout Mode : 2x50G 
Target Breakout Mode : 1x100G

Ports to be deleted : 
 {
    "Ethernet2": "50000", 
    "Ethernet0": "50000"
}
Ports to be added : 
 {
    "Ethernet0": "100000"
}

After running Logic to limit the impact

Final list of ports to be deleted : 
 {
    "Ethernet2": "50000", 
    "Ethernet0": "50000"
} 
Final list of ports to be added :  
 {
    "Ethernet0": "100000"
}
Loaded below Yang Models
['sonic-acl', 'sonic-extension', 'sonic-head', 'sonic-interface', 'sonic-loopback-interface', 'sonic-port', 'sonic-portchannel', 'sonic-vlan']
Reading data from Redis configDb
Note: Below table(s) have no YANG models:
VERSIONS, DEVICE_METADATA, DEVICE_NEIGHBOR, LOCK, FLEX_COUNTER_TABLE, BREAKOUT_CFG, 
Below Config can not be verified, It may cause harm to the system
 {
  "BREAKOUT_CFG": {
    "Ethernet0": {
      "brkout_mode": "2x50G"
    }
  }
}
Do you wish to Continue? [y/N]: 
Start Port Deletion
Find dependecies for port Ethernet2
Find dependecies for port Ethernet0
Deleting Port: Ethernet2
Deleting Port: Ethernet0
Data Validation successful
Generate Final Config to write in DB

Start Port Addition
Data Validation successful
Generate Final Config to write in DB
Writing in Config DB
Verify Port Deletion from Asic DB, Wait...
Writing in Config DB
Breakout process got successfully completed.
:::Lock Released:::
+-----------+------------------------+------------+----------------+-----------------------+
|   VLAN ID | IP Address             | Ports      | Port Tagging   | DHCP Helper Address   |
+===========+========================+============+================+=======================+
|       100 | 2a04:f547:43:6a0::1/64 | Ethernet4  | untagged       | 10.186.72.116         |
|           | 10.187.40.1/26         | Ethernet5  | untagged       |                       |
|           | fe80::1/10             | Ethernet6  | untagged       |                       |
|           |                        | Ethernet7  | untagged       |                       |
|           |                        | Ethernet8  | untagged       |                       |
|           |                        | Ethernet9  | untagged       |                       |
|           |                        | Ethernet10 | untagged       |                       |
ps

                 ena/        speed/ link auto    STP                  lrn  inter   max   cut   loop
           port  link  Lns   duplex scan neg?   state   pause  discrd ops   face frame  thru?  back
       ce0( 68)  down   4  100G  FD   SW  No   Forward          None    D    KR4  9412    No      
       xe0( 69)  !ena   1     -       SW  No   Forward          None    D   None  9412    No      
       xe1( 70)  !ena   2     -       SW  No   Forward          None    D   None  9412    No      
       xe2( 71)  !ena   1     -       SW  No   Forward          None    D   None  9412    No      
       xe3( 72)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      
       xe4( 73)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      
       xe5( 74)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      
:::Lock Acquired:::
:::Lock Timer Extended:::

Running Breakout Mode : 1x100G 
Target Breakout Mode : 4x25G

Ports to be deleted : 
 {
    "Ethernet0": "100000"
}
Ports to be added : 
 {
    "Ethernet2": "25000", 
    "Ethernet3": "25000", 
    "Ethernet0": "25000", 
    "Ethernet1": "25000"
}

After running Logic to limit the impact

Final list of ports to be deleted : 
 {
    "Ethernet0": "100000"
} 
Final list of ports to be added :  
 {
    "Ethernet2": "25000", 
    "Ethernet3": "25000", 
    "Ethernet0": "25000", 
    "Ethernet1": "25000"
}
Loaded below Yang Models
['sonic-acl', 'sonic-extension', 'sonic-head', 'sonic-interface', 'sonic-loopback-interface', 'sonic-port', 'sonic-portchannel', 'sonic-vlan']
Reading data from Redis configDb
Note: Below table(s) have no YANG models:
VERSIONS, DEVICE_METADATA, DEVICE_NEIGHBOR, LOCK, FLEX_COUNTER_TABLE, BREAKOUT_CFG, 
Below Config can not be verified, It may cause harm to the system
 {
  "BREAKOUT_CFG": {
    "Ethernet0": {
      "brkout_mode": "1x100G"
    }
  }
}
Do you wish to Continue? [y/N]: 
Start Port Deletion
Find dependecies for port Ethernet0
Deleting Port: Ethernet0
Data Validation successful
Generate Final Config to write in DB

Start Port Addition
Data Validation successful
Generate Final Config to write in DB
Writing in Config DB
Verify Port Deletion from Asic DB, Wait...
Writing in Config DB
Breakout process got successfully completed.
:::Lock Released:::
+-----------+------------------------+------------+----------------+-----------------------+
|   VLAN ID | IP Address             | Ports      | Port Tagging   | DHCP Helper Address   |
+===========+========================+============+================+=======================+
|       100 | 2a04:f547:43:6a0::1/64 | Ethernet4  | untagged       | 10.186.72.116         |
|           | 10.187.40.1/26         | Ethernet5  | untagged       |                       |
|           | fe80::1/10             | Ethernet6  | untagged       |                       |
|           |                        | Ethernet7  | untagged       |                       |
|           |                        | Ethernet8  | untagged       |                       |
|           |                        | Ethernet9  | untagged       |                       |
|           |                        | Ethernet10 | untagged       |                       |
ps

                 ena/        speed/ link auto    STP                  lrn  inter   max   cut   loop
           port  link  Lns   duplex scan neg?   state   pause  discrd ops   face frame  thru?  back
       xe0( 68)  down   1   25G  FD   SW  No   Forward          None    D     KR  9412    No      
       xe1( 69)  down   1   25G  FD   SW  No   Forward          None    D     KR  9412    No      
       xe2( 70)  down   1   25G  FD   SW  No   Forward          None    D     KR  9412    No      
       xe3( 71)  down   1   25G  FD   SW  No   Forward          None    D     KR  9412    No      
       xe4( 72)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      
       xe5( 73)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      
       xe6( 74)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      
:::Lock Acquired:::
:::Lock Timer Extended:::

Running Breakout Mode : 4x25G 
Target Breakout Mode : 1x100G

Ports to be deleted : 
 {
    "Ethernet2": "25000", 
    "Ethernet3": "25000", 
    "Ethernet0": "25000", 
    "Ethernet1": "25000"
}
Ports to be added : 
 {
    "Ethernet0": "100000"
}

After running Logic to limit the impact

Final list of ports to be deleted : 
 {
    "Ethernet2": "25000", 
    "Ethernet3": "25000", 
    "Ethernet0": "25000", 
    "Ethernet1": "25000"
} 
Final list of ports to be added :  
 {
    "Ethernet0": "100000"
}
Loaded below Yang Models
['sonic-acl', 'sonic-extension', 'sonic-head', 'sonic-interface', 'sonic-loopback-interface', 'sonic-port', 'sonic-portchannel', 'sonic-vlan']
Reading data from Redis configDb
Note: Below table(s) have no YANG models:
VERSIONS, DEVICE_METADATA, DEVICE_NEIGHBOR, LOCK, FLEX_COUNTER_TABLE, BREAKOUT_CFG, 
Below Config can not be verified, It may cause harm to the system
 {
  "BREAKOUT_CFG": {
    "Ethernet0": {
      "brkout_mode": "4x25G"
    }
  }
}
Do you wish to Continue? [y/N]: 
Start Port Deletion
Find dependecies for port Ethernet2
Find dependecies for port Ethernet3
Find dependecies for port Ethernet0
Find dependecies for port Ethernet1
Deleting Port: Ethernet2
Deleting Port: Ethernet3
Deleting Port: Ethernet0
Deleting Port: Ethernet1
Data Validation successful
Generate Final Config to write in DB

Start Port Addition
Data Validation successful
Generate Final Config to write in DB
Writing in Config DB
Verify Port Deletion from Asic DB, Wait...
Writing in Config DB
Breakout process got successfully completed.
:::Lock Released:::
+-----------+------------------------+------------+----------------+-----------------------+
|   VLAN ID | IP Address             | Ports      | Port Tagging   | DHCP Helper Address   |
+===========+========================+============+================+=======================+
|       100 | 2a04:f547:43:6a0::1/64 | Ethernet4  | untagged       | 10.186.72.116         |
|           | 10.187.40.1/26         | Ethernet5  | untagged       |                       |
|           | fe80::1/10             | Ethernet6  | untagged       |                       |
|           |                        | Ethernet7  | untagged       |                       |
|           |                        | Ethernet8  | untagged       |                       |
|           |                        | Ethernet9  | untagged       |                       |
|           |                        | Ethernet10 | untagged       |                       |
ps

                 ena/        speed/ link auto    STP                  lrn  inter   max   cut   loop
           port  link  Lns   duplex scan neg?   state   pause  discrd ops   face frame  thru?  back
       ce0( 68)  down   4  100G  FD   SW  No   Forward          None    D    KR4  9412    No      
       xe0( 69)  !ena   1     -       SW  No   Forward          None    D   None  9412    No      
       xe1( 70)  !ena   2     -       SW  No   Forward          None    D   None  9412    No      
       xe2( 71)  !ena   1     -       SW  No   Forward          None    D   None  9412    No      
       xe3( 72)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      
       xe4( 73)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      
       xe5( 74)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      
:::Lock Acquired:::
:::Lock Timer Extended:::

Running Breakout Mode : 1x100G 
Target Breakout Mode : 2x50G

Ports to be deleted : 
 {
    "Ethernet0": "100000"
}
Ports to be added : 
 {
    "Ethernet2": "50000", 
    "Ethernet0": "50000"
}

After running Logic to limit the impact

Final list of ports to be deleted : 
 {
    "Ethernet0": "100000"
} 
Final list of ports to be added :  
 {
    "Ethernet2": "50000", 
    "Ethernet0": "50000"
}
Loaded below Yang Models
['sonic-acl', 'sonic-extension', 'sonic-head', 'sonic-interface', 'sonic-loopback-interface', 'sonic-port', 'sonic-portchannel', 'sonic-vlan']
Reading data from Redis configDb
Note: Below table(s) have no YANG models:
VERSIONS, DEVICE_METADATA, DEVICE_NEIGHBOR, LOCK, FLEX_COUNTER_TABLE, BREAKOUT_CFG, 
Below Config can not be verified, It may cause harm to the system
 {
  "BREAKOUT_CFG": {
    "Ethernet0": {
      "brkout_mode": "1x100G"
    }
  }
}
Do you wish to Continue? [y/N]: 
Start Port Deletion
Find dependecies for port Ethernet0
Deleting Port: Ethernet0
Data Validation successful
Generate Final Config to write in DB

Start Port Addition
Generating default config for ['Ethernet2', 'Ethernet0']
Merge Default Config for ['Ethernet2', 'Ethernet0']
Data Validation successful
Generate Final Config to write in DB
Writing in Config DB
Verify Port Deletion from Asic DB, Wait...
Writing in Config DB
Breakout process got successfully completed.
:::Lock Released:::
+-----------+------------------------+------------+----------------+-----------------------+
|   VLAN ID | IP Address             | Ports      | Port Tagging   | DHCP Helper Address   |
+===========+========================+============+================+=======================+
|       100 | 2a04:f547:43:6a0::1/64 | Ethernet0  | untagged       | 10.186.72.116         |
|           | 10.187.40.1/26         | Ethernet2  | untagged       |                       |
|           | fe80::1/10             | Ethernet4  | untagged       |                       |
|           |                        | Ethernet5  | untagged       |                       |
|           |                        | Ethernet6  | untagged       |                       |
|           |                        | Ethernet7  | untagged       |                       |
|           |                        | Ethernet8  | untagged       |                       |
ps

                 ena/        speed/ link auto    STP                  lrn  inter   max   cut   loop
           port  link  Lns   duplex scan neg?   state   pause  discrd ops   face frame  thru?  back
       xe0( 68)  down   2   50G  FD   SW  No   Forward          None   FA    KR2  9412    No      
       xe1( 69)  !ena   1     -       SW  No   Forward          None    D   None  9412    No      
       xe2( 70)  down   2   50G  FD   SW  No   Forward          None   FA    KR2  9412    No      
       xe3( 71)  !ena   1     -       SW  No   Forward          None    D   None  9412    No      
       xe4( 72)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      
       xe5( 73)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      
       xe6( 74)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      
:::Lock Acquired:::
:::Lock Timer Extended:::

Running Breakout Mode : 2x50G 
Target Breakout Mode : 4x25G

Ports to be deleted : 
 {
    "Ethernet2": "50000", 
    "Ethernet0": "50000"
}
Ports to be added : 
 {
    "Ethernet2": "25000", 
    "Ethernet3": "25000", 
    "Ethernet0": "25000", 
    "Ethernet1": "25000"
}

After running Logic to limit the impact

Final list of ports to be deleted : 
 {
    "Ethernet2": "50000", 
    "Ethernet0": "50000"
} 
Final list of ports to be added :  
 {
    "Ethernet2": "25000", 
    "Ethernet3": "25000", 
    "Ethernet0": "25000", 
    "Ethernet1": "25000"
}
Loaded below Yang Models
['sonic-acl', 'sonic-extension', 'sonic-head', 'sonic-interface', 'sonic-loopback-interface', 'sonic-port', 'sonic-portchannel', 'sonic-vlan']
Reading data from Redis configDb
Note: Below table(s) have no YANG models:
VERSIONS, DEVICE_METADATA, DEVICE_NEIGHBOR, LOCK, FLEX_COUNTER_TABLE, BREAKOUT_CFG, 
Below Config can not be verified, It may cause harm to the system
 {
  "BREAKOUT_CFG": {
    "Ethernet0": {
      "brkout_mode": "2x50G"
    }
  }
}
Do you wish to Continue? [y/N]: 
Start Port Deletion
Find dependecies for port Ethernet2
Find dependecies for port Ethernet0
Deleting Port: Ethernet2
Deleting Port: Ethernet0
Data Validation successful
Generate Final Config to write in DB

Start Port Addition
Generating default config for ['Ethernet2', 'Ethernet3', 'Ethernet0', 'Ethernet1']
Merge Default Config for ['Ethernet2', 'Ethernet3', 'Ethernet0', 'Ethernet1']
Data Validation successful
Generate Final Config to write in DB
Writing in Config DB
Verify Port Deletion from Asic DB, Wait...
Writing in Config DB
Breakout process got successfully completed.
:::Lock Released:::
+-----------+------------------------+------------+----------------+-----------------------+
|   VLAN ID | IP Address             | Ports      | Port Tagging   | DHCP Helper Address   |
+===========+========================+============+================+=======================+
|       100 | 2a04:f547:43:6a0::1/64 | Ethernet0  | untagged       | 10.186.72.116         |
|           | 10.187.40.1/26         | Ethernet1  | untagged       |                       |
|           | fe80::1/10             | Ethernet2  | untagged       |                       |
|           |                        | Ethernet3  | untagged       |                       |
|           |                        | Ethernet4  | untagged       |                       |
|           |                        | Ethernet5  | untagged       |                       |
|           |                        | Ethernet6  | untagged       |                       |
ps

                 ena/        speed/ link auto    STP                  lrn  inter   max   cut   loop
           port  link  Lns   duplex scan neg?   state   pause  discrd ops   face frame  thru?  back
       xe0( 68)  down   1   25G  FD   SW  No   Forward          None   FA     KR  9412    No      
       xe1( 69)  down   1   25G  FD   SW  No   Forward          None   FA     KR  9412    No      
       xe2( 70)  down   1   25G  FD   SW  No   Forward          None   FA     KR  9412    No      
       xe3( 71)  down   1   25G  FD   SW  No   Forward          None   FA     KR  9412    No      
       xe4( 72)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      
       xe5( 73)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      
       xe6( 74)  !ena   1   25G  FD   SW  No   Forward          None   FA     KR  9122    No      

Description for Test cases:

- What I did
Write Unit tests for Config_mgmt library introduced in PR #765.

- How I did it
Key Decisions:
-- Config_mgmt interaction with Redis DB:
These tests will be executed at build time, the entire interaction with Redis DB is mocked using:
import mock_tables.dbconnector
This mocks below classes used in config_mgmt
from swsssdk import ConfigDBConnector, SonicV2Connector, port_util

-- Mock sonic_yang or not:
Most of the functions in config_mgmt calls APIs from sonic_yang_mgmt (https://github.com/Azure/sonic-buildimage/tree/master/src/sonic-yang-mgmt) library. It is important to catch any compatibility issues during build time rather than run time. So it is decided not to mock sonic_yang but use real instance. Due to this sonic_utilities will have a build time dependency on sonic_yang_mgmt.

-- Unit Test each function or the functions exposed to caller:
1. To unit test each function, we need to mock sonic_yang, which is against the previous decision. 

2. Also calling the functions which are exposed to the caller is sufficient to unit test all functions. Because functions like breakOutPort internally call every function in the library, and the expected result is not produced if internal functions are not working properly.

3. In the real scenario, the caller will use this library for config validation and to break out the port in a continuous manner. To emulate a real scenario it is decided to exercise only the functions exposed to the caller.


Check Result:
-- How to check expected result for breakout Command:
1. A successful call to breakOutPort API results in a call to writeConfigDB API twice.

One time with config to be deleted and second time with config to be added. Both calls are necessary and should be done in order. This is tested by mocking writeConfigDB API as below:

cmdpb = config_mgmt.ConfigMgmtDPB(source=config_mgmt.CONFIG_DB_JSON_FILE)
cmdpb.writeConfigDB = MagicMock(return_value=True)

Then we can check result as below:

calls = [call(dConfig), call(aConfig)]
        assert cmdpb.writeConfigDB.call_count == 2
        cmdpb.writeConfigDB.assert_has_calls(calls, any_order=False)

Note: it is important to check that both calls are done, rather than just checking final config.

Tests:
-- Create the configMgmt Class object and validate config.

-- Have a table without yang model in config, Check if this table is returned by tablesWithoutYang()

-- Test configWithKeys() to search ports in the config.

-- Important Test case, Test below sequence for port breakout:

        #Ethernet8: start from 4x25G-->2x50G with -f -l

        #Ethernet8: move from 2x50G-->1x100G without force, list deps

        # Ethernet8: move from 2x50G-->1x100G with force, where deps exists

        # Ethernet8: move from 1x100G-->4x25G without force, no deps

        # Ethernet8: move from 4x25G-->1x100G with force, no deps

        # Ethernet8: move from 1x100G-->1x50G(2)+2x25G(2) with -f -l,

        # Ethernet4: breakout from 4x25G to 2x50G with -f -l

Note: this is important to do this sequence in one test case, because it is good to test with continuous change in Config. Also this way, a new configuration for each test is not needed.

Expected Result:
All automated tests should pass.

Each breakout test is checked for expected result as below:
Have a hard coded value of expected dConfig and aConfig, where
dConfig: Config to be deleted.
aConfig: Config to be deleted.

And check if writeConfigDB is called using the above configurations.

Example:

dConfig = {u'PORT': {u'Ethernet8': None}}

aConfig = {u'ACL_TABLE': {u'NO-NSW-PACL-V4': {u'ports': ['Ethernet0', \
        'Ethernet4', 'Ethernet8', 'Ethernet10']}, u'NO-NSW-PACL-TEST': {u'ports': \
        ['Ethernet11']}}, u'INTERFACE': {u'Ethernet11|2a04:1111:40:a709::1/126': \
        {u'scope': u'global', u'family': u'IPv6'}, u'Ethernet11': {}}, \
        u'VLAN_MEMBER': {u'Vlan100|Ethernet8': {u'tagging_mode': u'untagged'}, \
        u'Vlan100|Ethernet11': {u'tagging_mode': u'untagged'}}, u'PORT': \
        {'Ethernet8': {'speed': '50000', 'lanes': '73,74'}, 'Ethernet10': \
        {'speed': '25000', 'lanes': '75'}, 'Ethernet11': {'speed': '25000', 'lanes': '76'}}}
        
self.checkResult(cmdpb, dConfig, aConfig)

Actual Result:

============================================================ test session starts ============================================================
platform linux2 -- Python 2.7.13, pytest-3.0.6, py-1.4.32, pluggy-0.4.0
rootdir: /sonic/src/sonic-utilities/sonic-utilities-tests, inifile: pytest.ini
plugins: cov-2.4.0
collected 4 items

config_mgmt_test.py ....

========================================================= 4 passed in 0.67 seconds ==========================================================

- How to verify it
Actual Result:

============================================================ test session starts ============================================================
platform linux2 -- Python 2.7.13, pytest-3.0.6, py-1.4.32, pluggy-0.4.0
rootdir: /sonic/src/sonic-utilities/sonic-utilities-tests, inifile: pytest.ini
plugins: cov-2.4.0
collected 4 items

config_mgmt_test.py ....

========================================================= 4 passed in 0.67 seconds ==========================================================

- Previous command output (if the output of a command-line utility has changed)

- New command output (if the output of a command-line utility has changed)

@praveen-li
Copy link
Member Author

Gentle Reminder, Kindly Review.
Let me know If we need a meeting for it.

@praveen-li
Copy link
Member Author

@renukamanavalan
Gentle Reminder, Kindly Review. This can be review irrespective of YANG changes.
Let me know If we need a meeting for it.

@jleveque
Copy link
Contributor

@samaity: Please fix conflicts.

@jleveque jleveque self-requested a review May 11, 2020 22:54
config/config_mgmt.py Outdated Show resolved Hide resolved
@praveen-li praveen-li force-pushed the config_mgmt_class_msft branch from 796704d to 412d162 Compare May 13, 2020 22:51
@lgtm-com
Copy link

lgtm-com bot commented May 13, 2020

This pull request introduces 8 alerts when merging 412d162d6005bb89f68d6639e6fbf7e3a36b404e into 7e52ef9 - view on LGTM.com

new alerts:

  • 5 for Unused import
  • 2 for Variable defined multiple times
  • 1 for Unreachable code

@praveen-li
Copy link
Member Author

@jleveque : This PR now has only new file config_mgmt.py which will be used only from config/main.py.

main.py changes will be part of PR 766. Thx.

config/config_mgmt.py Outdated Show resolved Hide resolved
config/config_mgmt.py Outdated Show resolved Hide resolved
config/config_mgmt.py Outdated Show resolved Hide resolved
config/config_mgmt.py Outdated Show resolved Hide resolved
config/config_mgmt.py Outdated Show resolved Hide resolved
config/config_mgmt.py Outdated Show resolved Hide resolved
@praveen-li praveen-li force-pushed the config_mgmt_class_msft branch from 74c32dc to 779e9d0 Compare May 21, 2020 17:46
config/config_mgmt.py Outdated Show resolved Hide resolved
renukamanavalan
renukamanavalan previously approved these changes Jun 4, 2020
config/config_mgmt.py Outdated Show resolved Hide resolved
config/config_mgmt.py Outdated Show resolved Hide resolved
config/config_mgmt.py Outdated Show resolved Hide resolved
config/config_mgmt.py Outdated Show resolved Hide resolved
Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com
config/config_mgmt.py Show resolved Hide resolved
config/config_mgmt.py Outdated Show resolved Hide resolved
config/config_mgmt.py Outdated Show resolved Hide resolved
config/config_mgmt.py Outdated Show resolved Hide resolved
config/config_mgmt.py Outdated Show resolved Hide resolved
config/config_mgmt.py Outdated Show resolved Hide resolved
config/config_mgmt.py Outdated Show resolved Hide resolved
config/config_mgmt.py Show resolved Hide resolved
config/config_mgmt.py Outdated Show resolved Hide resolved
config/config_mgmt.py Outdated Show resolved Hide resolved
Praveen Chaudhary added 2 commits June 25, 2020 10:37
…lowed servers by Azure.

Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com
Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com
@lgtm-com
Copy link

lgtm-com bot commented Jun 26, 2020

This pull request introduces 3 alerts when merging 2a8d16c into 90efd62 - view on LGTM.com

new alerts:

  • 2 for Unused import
  • 1 for Wrong name for an argument in a call

@renukamanavalan
Copy link
Contributor

Build failure:

[2020-06-26T06:31:41.117Z] No local packages or working download links found for xmltodict==0.12.0
[2020-06-26T06:31:41.117Z] error: Could not find suitable distribution for Requirement.parse('xmltodict==0.12.0')

Praveen Chaudhary added 2 commits June 26, 2020 09:08
… breakOutPort API.

Changes:
-- Remove addPorts Arg from breakOutPort API.
-- Change Test Code accordingly.

Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com
this pkg will come from sonic-net/sonic-buildimage#4740.

Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com
@praveen-li
Copy link
Member Author

Build failure:

[2020-06-26T06:31:41.117Z] No local packages or working download links found for xmltodict==0.12.0
[2020-06-26T06:31:41.117Z] error: Could not find suitable distribution for Requirement.parse('xmltodict==0.12.0')

@renukamanavalan : yeah I am replying on sonic-net/sonic-buildimage#4740 for this.

@praveen-li
Copy link
Member Author

retest this please

@renukamanavalan
Copy link
Contributor

E ImportError: No module named jsondiff - required module not found

@daall
Copy link
Contributor

daall commented Jun 29, 2020

retest this please

@renukamanavalan
Copy link
Contributor

libyang[0]: Unable to use search directory "./../../../sonic-yang-models/yang-models/" (No such file or directory)

@praveen-li
Copy link
Member Author

libyang[0]: Unable to use search directory "./../../../sonic-yang-models/yang-models/" (No such file or directory)

@jleveque
Seems, On Azure, we do not checkout entire sonic-buildimage repo while testing sonic-utilities. Let me know if that is the case, I will try to solve it by adding dependency on sonic-yang-models PKG.

@jleveque
Copy link
Contributor

@praveen-li: We copy artifacts from the last successful build of buildimage-vs-all. I haven't done a lot of work with the new Jenkins infrastructure. @daall or @lguohan can comment further.

…ic_yang_models now we do not need relative path to yang models.

Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com
Copy link
Contributor

@renukamanavalan renukamanavalan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two concerns only.

  1. What if we abort after port delete, before add, which has higher probability as we wait for asynchronous sync of delete up to ASIC-DB -- For this we have filed an active issue.

  2. The time point of collection of diffs for delete & add and the application of the same, are not atomic. Just concerned, any in-the-middle change , that could affect
    At the least, can we get a advisory lock, to the least that no two port-break commands can run concurrently. May be not for this PR. But to give some attention,

config/config_mgmt.py Outdated Show resolved Hide resolved
config/config_mgmt.py Outdated Show resolved Hide resolved
Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com
@praveen-li
Copy link
Member Author

praveen-li commented Jul 2, 2020

Just two concerns only.

1. What if we abort after port delete, before add, which has higher probability as we wait for asynchronous sync of delete up to ASIC-DB -- For this we have filed an active issue.

2. The time point  of collection of diffs for delete & add and the application of the same, are not atomic. Just concerned, any in-the-middle change , that could affect
   At the  least, can we get a advisory lock, to the least that no two port-break commands can run  concurrently. May be not for this PR. But to give some attention,

@renukamanavalan
+1 for Point 1.

-- for 2., we have config lock, but from Azure branch it is removed, so we will come up with approach which caters all.

@jleveque jleveque self-requested a review July 2, 2020 17:52
@jleveque
Copy link
Contributor

jleveque commented Jul 2, 2020

Check build failure appears to be unrelated to this PR. Merging in spite of it.

@jleveque jleveque changed the title [config_mgmt.py]: Class in sonic_util config for Config Validation, Delete Ports, Add Ports. [config] Add ConfigMgmt class for config validation, delete ports, add ports Jul 2, 2020
@jleveque jleveque merged commit 60e5410 into sonic-net:master Jul 2, 2020
abdosi pushed a commit to abdosi/sonic-utilities that referenced this pull request Aug 4, 2020
…d ports (sonic-net#765)

Provided a new ConfigMgmt class for
- Config Validation
- Adding ports
- Deleting ports

Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com
CharlieChenEC pushed a commit to CharlieChenEC/sonic-utilities that referenced this pull request May 14, 2021
…d ports (sonic-net#765)

Provided a new ConfigMgmt class for
- Config Validation
- Adding ports
- Deleting ports

Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants