11
11
12
12
TEMPLATE_PATH = os .path .abspath ('../../dockers/docker-fpm-frr/frr' )
13
13
BASE_PATH = os .path .abspath ('../sonic-bgpcfgd/tests/data/general/peer-group.conf/' )
14
+ INTERNAL_BASE_PATH = os .path .abspath ('../sonic-bgpcfgd/tests/data/internal/peer-group.conf/' )
14
15
global_constants = {
15
16
"bgp" : {
16
17
"traffic_shift_community" :"12345:12345" ,
17
18
"internal_community_match_tag" : "1001"
18
19
}
19
20
}
20
21
21
- def constructor ():
22
+ def constructor (check_internal = False ):
22
23
cfg_mgr = MagicMock ()
23
24
def get_text ():
24
25
text = []
@@ -29,7 +30,10 @@ def get_text():
29
30
text += [" " ]
30
31
return text
31
32
def update ():
32
- cfg_mgr .changes = get_string_from_file ("/result_all.conf" )
33
+ if check_internal :
34
+ cfg_mgr .changes = get_string_from_file ("/result_chasiss_packet.conf" , INTERNAL_BASE_PATH )
35
+ else :
36
+ cfg_mgr .changes = get_string_from_file ("/result_all.conf" )
33
37
def push (cfg ):
34
38
cfg_mgr .changes += cfg + "\n "
35
39
def get_config ():
@@ -60,13 +64,31 @@ def test_isolate_device(mocked_log_info):
60
64
assert m .cfg_mgr .get_config () == get_string_from_file ("/result_all_isolate.conf" )
61
65
62
66
@patch ('bgpcfgd.managers_device_global.log_debug' )
63
- def test_unisolate_device (mocked_log_info ):
67
+ def test_isolate_device_internal_session (mocked_log_info ):
68
+ m = constructor (check_internal = True )
69
+ res = m .set_handler ("STATE" , {"tsa_enabled" : "true" })
70
+ assert res , "Expect True return value for set_handler"
71
+ mocked_log_info .assert_called_with ("DeviceGlobalCfgMgr::Done" )
72
+ assert m .cfg_mgr .get_config () == get_string_from_file ("/result_chassis_packet_isolate.conf" , INTERNAL_BASE_PATH )
73
+
74
+
75
+ @patch ('bgpcfgd.managers_device_global.log_debug' )
76
+ def test_unisolate_device (mocked_log_info ):
64
77
m = constructor ()
65
78
res = m .set_handler ("STATE" , {"tsa_enabled" : "false" })
66
79
assert res , "Expect True return value for set_handler"
67
80
mocked_log_info .assert_called_with ("DeviceGlobalCfgMgr::Done" )
68
81
assert m .cfg_mgr .get_config () == get_string_from_file ("/result_all_unisolate.conf" )
69
82
83
+ @patch ('bgpcfgd.managers_device_global.log_debug' )
84
+ def test_unisolate_device_internal_session (mocked_log_info ):
85
+ m = constructor (check_internal = True )
86
+ res = m .set_handler ("STATE" , {"tsa_enabled" : "false" })
87
+ assert res , "Expect True return value for set_handler"
88
+ mocked_log_info .assert_called_with ("DeviceGlobalCfgMgr::Done" )
89
+ assert m .cfg_mgr .get_config () == get_string_from_file ("/result_chassis_packet_unisolate.conf" , INTERNAL_BASE_PATH )
90
+
91
+
70
92
def test_check_state_and_get_tsa_routemaps ():
71
93
m = constructor ()
72
94
m .set_handler ("STATE" , {"tsa_enabled" : "true" })
@@ -93,8 +115,8 @@ def test_get_tsb_routemaps():
93
115
expected_res = get_string_from_file ("/result_unisolate.conf" )
94
116
assert res == expected_res
95
117
96
- def get_string_from_file (filename ):
97
- fp = open (BASE_PATH + filename , "r" )
118
+ def get_string_from_file (filename , base_path = BASE_PATH ):
119
+ fp = open (base_path + filename , "r" )
98
120
cfg = fp .read ()
99
121
fp .close ()
100
122
0 commit comments