6
6
7
7
import config .main as config
8
8
import show .main as show
9
+ import threading
9
10
11
+ DEFAULT_NAMESPACE = ''
10
12
test_path = os .path .dirname (os .path .abspath (__file__ ))
11
13
mock_db_path = os .path .join (test_path , "vrf_input" )
12
14
@@ -16,6 +18,11 @@ def setup_class(cls):
16
18
print ("SETUP" )
17
19
os .environ ["UTILITIES_UNIT_TESTING" ] = "1"
18
20
21
+ def update_statedb (self , db , db_name , key ):
22
+ import time
23
+ time .sleep (0.5 )
24
+ db .delete (db_name , key )
25
+
19
26
def test_vrf_show (self ):
20
27
from .mock_tables import dbconnector
21
28
jsonfile_config = os .path .join (mock_db_path , "config_db" )
@@ -64,59 +71,81 @@ def test_vrf_bind_unbind(self):
64
71
assert result .exit_code == 0
65
72
assert result .output == expected_output
66
73
67
- obj = {'config_db' :db .cfgdb }
74
+
75
+ vrf_obj = {'config_db' :db .cfgdb , 'namespace' :db .db .namespace }
68
76
69
77
expected_output_unbind = "Interface Ethernet4 IP disabled and address(es) removed due to unbinding VRF.\n "
70
- result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["Ethernet4" ], obj = obj )
78
+ result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["Ethernet4" ], obj = vrf_obj )
79
+
71
80
print (result .exit_code , result .output )
72
81
assert result .exit_code == 0
73
82
assert 'Ethernet4' not in db .cfgdb .get_table ('INTERFACE' )
74
83
assert result .output == expected_output_unbind
75
84
76
85
expected_output_unbind = "Interface Loopback0 IP disabled and address(es) removed due to unbinding VRF.\n "
77
- result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["Loopback0" ], obj = obj )
86
+
87
+ result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["Loopback0" ], obj = vrf_obj )
88
+
78
89
print (result .exit_code , result .output )
79
90
assert result .exit_code == 0
80
91
assert 'Loopback0' not in db .cfgdb .get_table ('LOOPBACK_INTERFACE' )
81
92
assert result .output == expected_output_unbind
82
93
83
94
expected_output_unbind = "Interface Vlan40 IP disabled and address(es) removed due to unbinding VRF.\n "
84
- result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["Vlan40" ], obj = obj )
95
+
96
+ result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["Vlan40" ], obj = vrf_obj )
97
+
85
98
print (result .exit_code , result .output )
86
99
assert result .exit_code == 0
87
100
assert 'Vlan40' not in db .cfgdb .get_table ('VLAN_INTERFACE' )
88
101
assert result .output == expected_output_unbind
89
102
90
103
expected_output_unbind = "Interface PortChannel0002 IP disabled and address(es) removed due to unbinding VRF.\n "
91
- result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["PortChannel0002" ], obj = obj )
104
+
105
+ result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["PortChannel0002" ], obj = vrf_obj )
106
+
92
107
print (result .exit_code , result .output )
93
108
assert result .exit_code == 0
94
109
assert 'PortChannel002' not in db .cfgdb .get_table ('PORTCHANNEL_INTERFACE' )
95
110
assert result .output == expected_output_unbind
96
111
112
+ vrf_obj = {'config_db' :db .cfgdb , 'namespace' :DEFAULT_NAMESPACE }
113
+ state_db = SonicV2Connector (use_unix_socket_path = True , namespace = '' )
114
+ state_db .connect (state_db .STATE_DB , False )
115
+ _hash = "INTERFACE_TABLE|Eth36.10"
116
+ state_db .set (db .db .STATE_DB , _hash , "state" , "ok" )
117
+ vrf_obj ['state_db' ] = state_db
118
+
97
119
expected_output_unbind = "Interface Eth36.10 IP disabled and address(es) removed due to unbinding VRF.\n "
98
- result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["Eth36.10" ], obj = obj )
120
+ T1 = threading .Thread ( target = self .update_statedb , args = (state_db , db .db .STATE_DB , _hash ))
121
+ T1 .start ()
122
+ result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["Eth36.10" ], obj = vrf_obj )
123
+ T1 .join ()
99
124
print (result .exit_code , result .output )
100
125
assert result .exit_code == 0
101
126
assert ('vrf_name' , 'Vrf102' ) not in db .cfgdb .get_table ('VLAN_SUB_INTERFACE' )['Eth36.10' ]
102
127
assert result .output == expected_output_unbind
103
128
129
+ vrf_obj = {'config_db' :db .cfgdb , 'namespace' :DEFAULT_NAMESPACE }
130
+
104
131
expected_output_unbind = "Interface Ethernet0.10 IP disabled and address(es) removed due to unbinding VRF.\n "
105
- result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["Ethernet0.10" ], obj = obj )
132
+
133
+ result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["Ethernet0.10" ], obj = vrf_obj )
134
+
106
135
print (result .exit_code , result .output )
107
136
assert result .exit_code == 0
108
137
assert ('vrf_name' , 'Vrf101' ) not in db .cfgdb .get_table ('VLAN_SUB_INTERFACE' )['Ethernet0.10' ]
109
138
assert result .output == expected_output_unbind
110
139
111
140
expected_output_unbind = "Interface Po0002.101 IP disabled and address(es) removed due to unbinding VRF.\n "
112
- result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["Po0002.101" ], obj = obj )
141
+
142
+ result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["unbind" ], ["Po0002.101" ], obj = vrf_obj )
143
+
113
144
print (result .exit_code , result .output )
114
145
assert result .exit_code == 0
115
146
assert ('vrf_name' , 'Vrf103' ) not in db .cfgdb .get_table ('VLAN_SUB_INTERFACE' )['Po0002.101' ]
116
147
assert result .output == expected_output_unbind
117
148
118
- vrf_obj = {'config_db' :db .cfgdb , 'namespace' :db .db .namespace }
119
-
120
149
expected_output_bind = "Interface Ethernet0 IP disabled and address(es) removed due to binding VRF Vrf1.\n "
121
150
result = runner .invoke (config .config .commands ["interface" ].commands ["vrf" ].commands ["bind" ], ["Ethernet0" , "Vrf1" ], obj = vrf_obj )
122
151
assert result .exit_code == 0
0 commit comments