[mux]: Fix mark_dhcp_packet
(#9373)
- Consolidate the two [Service] sections by moving the ExecStartPre line for mark_dhcp_packet.py to the first section and removing the second. - Make the mark_dhcp_packet.py file executable - Also clean up mark_dhcp_packet.py - Remove unused imports - Fix spacing and line lengths to conform to PEP8 Signed-off-by: Lawrence Lee <lawlee@microsoft.com>
This commit is contained in:
parent
9f0fc89cff
commit
b3a3aa0c38
@ -10,6 +10,7 @@ StartLimitBurst=3
|
|||||||
[Service]
|
[Service]
|
||||||
User={{ sonicadmin_user }}
|
User={{ sonicadmin_user }}
|
||||||
ExecStartPre=/usr/local/bin/write_standby.py
|
ExecStartPre=/usr/local/bin/write_standby.py
|
||||||
|
ExecStartPre=/usr/local/bin/mark_dhcp_packet.py
|
||||||
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start
|
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start
|
||||||
ExecStart=/usr/bin/{{docker_container_name}}.sh wait
|
ExecStart=/usr/bin/{{docker_container_name}}.sh wait
|
||||||
ExecStop=/usr/bin/{{docker_container_name}}.sh stop
|
ExecStop=/usr/bin/{{docker_container_name}}.sh stop
|
||||||
@ -17,15 +18,5 @@ ExecStopPost=/usr/local/bin/write_standby.py
|
|||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=30
|
RestartSec=30
|
||||||
|
|
||||||
[Service]
|
|
||||||
User={{ sonicadmin_user }}
|
|
||||||
ExecStartPre=/usr/local/bin/mark_dhcp_packet.py
|
|
||||||
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start
|
|
||||||
ExecStart=/usr/bin/{{docker_container_name}}.sh wait
|
|
||||||
ExecStop=/usr/bin/{{docker_container_name}}.sh stop
|
|
||||||
ExecStopPost=/usr/local/bin/mark_dhcp_packet.py
|
|
||||||
Restart=always
|
|
||||||
RestartSec=30
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=sonic.target
|
WantedBy=sonic.target
|
||||||
|
22
files/scripts/mark_dhcp_packet.py
Normal file → Executable file
22
files/scripts/mark_dhcp_packet.py
Normal file → Executable file
@ -1,15 +1,13 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import os
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
|
|
||||||
from sonic_py_common import logger
|
from sonic_py_common import logger
|
||||||
from swsscommon import swsscommon
|
from swsscommon import swsscommon
|
||||||
|
|
||||||
log = logger.Logger('mark_dhcp_packet')
|
log = logger.Logger('mark_dhcp_packet')
|
||||||
|
|
||||||
|
|
||||||
class MarkDhcpPacket(object):
|
class MarkDhcpPacket(object):
|
||||||
"""
|
"""
|
||||||
Class used to configure dhcp packet mark in ebtables
|
Class used to configure dhcp packet mark in ebtables
|
||||||
@ -38,7 +36,9 @@ class MarkDhcpPacket(object):
|
|||||||
Initializes the connector during the first call
|
Initializes the connector during the first call
|
||||||
"""
|
"""
|
||||||
if self.state_db_connector is None:
|
if self.state_db_connector is None:
|
||||||
self.state_db_connector = swsscommon.SonicV2Connector(host='127.0.0.1')
|
self.state_db_connector = swsscommon.SonicV2Connector(
|
||||||
|
host='127.0.0.1'
|
||||||
|
)
|
||||||
self.state_db_connector.connect(self.state_db_connector.STATE_DB)
|
self.state_db_connector.connect(self.state_db_connector.STATE_DB)
|
||||||
|
|
||||||
return self.state_db_connector
|
return self.state_db_connector
|
||||||
@ -51,7 +51,8 @@ class MarkDhcpPacket(object):
|
|||||||
localhost_key = self.config_db.get_keys('DEVICE_METADATA')[0]
|
localhost_key = self.config_db.get_keys('DEVICE_METADATA')[0]
|
||||||
metadata = self.config_db.get_entry('DEVICE_METADATA', localhost_key)
|
metadata = self.config_db.get_entry('DEVICE_METADATA', localhost_key)
|
||||||
|
|
||||||
return 'subtype' in metadata and 'dualtor' in metadata['subtype'].lower()
|
return 'subtype' in metadata and \
|
||||||
|
'dualtor' in metadata['subtype'].lower()
|
||||||
|
|
||||||
def get_mux_intfs(self):
|
def get_mux_intfs(self):
|
||||||
"""
|
"""
|
||||||
@ -82,10 +83,16 @@ class MarkDhcpPacket(object):
|
|||||||
self.run_command("sudo ebtables -F INPUT")
|
self.run_command("sudo ebtables -F INPUT")
|
||||||
|
|
||||||
def apply_mark_in_ebtables(self, intf, mark):
|
def apply_mark_in_ebtables(self, intf, mark):
|
||||||
self.run_command("sudo ebtables -A INPUT -i {} -j mark --mark-set {}".format(intf, mark))
|
self.run_command("sudo ebtables -A INPUT -i {} -j mark --mark-set {}"
|
||||||
|
.format(intf, mark))
|
||||||
|
|
||||||
def update_mark_in_state_db(self, intf, mark):
|
def update_mark_in_state_db(self, intf, mark):
|
||||||
self.state_db.set(self.state_db.STATE_DB, 'DHCP_PACKET_MARK|' + intf, 'mark', mark)
|
self.state_db.set(
|
||||||
|
self.state_db.STATE_DB,
|
||||||
|
'DHCP_PACKET_MARK|' + intf,
|
||||||
|
'mark',
|
||||||
|
mark
|
||||||
|
)
|
||||||
|
|
||||||
def apply_marks(self):
|
def apply_marks(self):
|
||||||
"""
|
"""
|
||||||
@ -103,6 +110,7 @@ class MarkDhcpPacket(object):
|
|||||||
|
|
||||||
log.log_info("Finish marking dhcp packets in ebtables.")
|
log.log_info("Finish marking dhcp packets in ebtables.")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
mark_dhcp_packet = MarkDhcpPacket()
|
mark_dhcp_packet = MarkDhcpPacket()
|
||||||
mark_dhcp_packet.apply_marks()
|
mark_dhcp_packet.apply_marks()
|
||||||
|
Reference in New Issue
Block a user