Skip to content

Commit

Permalink
Revert "[dualtor] Improve mux_simulator (#16164)" (#16478)
Browse files Browse the repository at this point in the history
This reverts commit 9f2412d.
  • Loading branch information
lolyu authored Jan 13, 2025
1 parent 90dd44b commit af61468
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 71 deletions.
76 changes: 24 additions & 52 deletions ansible/roles/vm_set/files/mux_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
import traceback
import time

if sys.version_info.major == 2:
from multiprocessing.pool import ThreadPool
else:
from concurrent.futures import ThreadPoolExecutor as ThreadPool

from collections import defaultdict
from logging.handlers import RotatingFileHandler

Expand Down Expand Up @@ -56,19 +51,6 @@
unicode = str


MUX_SIMULATOR_LOGO = [
'',
'## ## ## ## ## ## ###### #### ## ## ## ## ## ### ######## ####### ######## ', # noqa E501
'### ### ## ## ## ## ## ## ## ### ### ## ## ## ## ## ## ## ## ## ## ', # noqa E501
'#### #### ## ## ## ## ## ## #### #### ## ## ## ## ## ## ## ## ## ## ', # noqa E501
'## ### ## ## ## ### ###### ## ## ### ## ## ## ## ## ## ## ## ## ######## ', # noqa E501
'## ## ## ## ## ## ## ## ## ## ## ## ## ######### ## ## ## ## ## ', # noqa E501
'## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ', # noqa E501
'## ## ####### ## ## ###### #### ## ## ####### ######## ## ## ## ####### ## ## ', # noqa E501
'',
]


# ============================================ Error Handlers ============================================ #

@app.errorhandler(Exception)
Expand Down Expand Up @@ -577,12 +559,9 @@ def clear_flap_counter(self):

class Muxes(object):

MUXES_CONCURRENCY = 4

def __init__(self, vm_set):
self.vm_set = vm_set
self.muxes = {}
self.thread_pool = ThreadPool(Muxes.MUXES_CONCURRENCY)
for bridge in self._mux_bridges():
bridge_fields = bridge.split('-')
port_index = int(bridge_fields[-1])
Expand Down Expand Up @@ -617,8 +596,7 @@ def set_active_side(self, new_active_side, port_index=None):
mux.set_active_side(new_active_side)
return mux.status
else:
list(self.thread_pool.map(lambda args: Mux.set_active_side(*args),
[(mux, new_active_side) for mux in self.muxes.values()]))
[mux.set_active_side(new_active_side) for mux in self.muxes.values()]
return {mux.bridge: mux.status for mux in self.muxes.values()}

def update_flows(self, new_action, out_sides, port_index=None):
Expand All @@ -627,8 +605,7 @@ def update_flows(self, new_action, out_sides, port_index=None):
mux.update_flows(new_action, out_sides)
return mux.status
else:
list(self.thread_pool.map(lambda args: Mux.update_flows(*args),
[(mux, new_action, out_sides) for mux in self.muxes.values()]))
[mux.update_flows(new_action, out_sides) for mux in self.muxes.values()]
return {mux.bridge: mux.status for mux in self.muxes.values()}

def reset_flows(self, port_index=None):
Expand Down Expand Up @@ -954,21 +931,6 @@ def log_message(vm_set):
return {"success": True}


def setup_mux_simulator(http_port, vm_set, verbose):
if verbose == 1:
app.logger.setLevel(logging.DEBUG)
app.config['VERBOSE'] = True
else:
app.logger.setLevel(logging.INFO)
app.config['VERBOSE'] = False

config_logging(http_port)
app.logger.info('\n'.join(MUX_SIMULATOR_LOGO))
app.logger.info('Starting server on port {}'.format(http_port))
create_muxes(vm_set)
app.logger.info('####################### STARTING HTTP SERVER #######################')


if __name__ == '__main__':
usage = '\n'.join([
'Start mux simulator server at specified port:',
Expand All @@ -981,19 +943,29 @@ def setup_mux_simulator(http_port, vm_set, verbose):

http_port = sys.argv[1]
arg_vm_set = sys.argv[2]
verbose = ('-v' in sys.argv)

setup_mux_simulator(http_port, arg_vm_set, verbose)
if '-v' in sys.argv:
app.logger.setLevel(logging.DEBUG)
app.config['VERBOSE'] = True
else:
app.logger.setLevel(logging.INFO)
app.config['VERBOSE'] = False

config_logging(http_port)
MUX_LOGO = '\n'.join([
'',
'## ## ## ## ## ## ###### #### ## ## ## ## ## ### ######## ####### ######## ', # noqa E501
'### ### ## ## ## ## ## ## ## ### ### ## ## ## ## ## ## ## ## ## ## ', # noqa E501
'#### #### ## ## ## ## ## ## #### #### ## ## ## ## ## ## ## ## ## ## ', # noqa E501
'## ### ## ## ## ### ###### ## ## ### ## ## ## ## ## ## ## ## ## ######## ', # noqa E501
'## ## ## ## ## ## ## ## ## ## ## ## ## ######### ## ## ## ## ## ', # noqa E501
'## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ', # noqa E501
'## ## ####### ## ## ###### #### ## ## ####### ######## ## ## ## ####### ## ## ', # noqa E501
'',
])
app.logger.info(MUX_LOGO)
app.logger.info('Starting server on port {}'.format(sys.argv[1]))
create_muxes(arg_vm_set)
app.logger.info('####################### STARTING HTTP SERVER #######################')
socket.setdefaulttimeout(60)
app.run(host='0.0.0.0', port=http_port, threaded=True) # nosemgrep
else:
http_port = os.environ.get("MUX_SIMULATOR_HTTP_PORT")
arg_vm_set = os.environ.get("MUX_SIMULATOR_VM_SET")
if http_port is None:
raise RuntimeError("No http port is provided.")
if arg_vm_set is None:
raise RuntimeError("No VM set is provided.")
verbose = int(os.environ.get("MUX_SIMULATOR_VERBOSITY", "1"))

setup_mux_simulator(http_port, arg_vm_set, verbose)
18 changes: 0 additions & 18 deletions ansible/roles/vm_set/tasks/control_mux_simulator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
set_fact:
flask_version: "1.1.2"
werkzeug_version: "1.0.1"
gunicorn_version: "19.10.0"
python_command: "python"
futures_version: "3.4.0"

- name: Use newer Flask version for pip3
set_fact:
flask_version: "2.3.3"
python_command: "python3"
gunicorn_version: "23.0.0"
when: pip_executable == "pip3"

- name: Use newer Werkzeug version for pip3
Expand All @@ -42,21 +39,6 @@
become: yes
environment: "{{ proxy_env | default({}) }}"

- name: Install gunicorn
pip: name=gunicorn version={{ gunicorn_version }} state=forcereinstall executable={{ pip_executable }}
become: yes
environment: "{{ proxy_env | default({}) }}"

- name: Install futures
pip: name=futures version={{ futures_version }} state=forcereinstall executable={{ pip_executable }}
become: yes
environment: "{{ proxy_env | default({}) }}"
when: pip_executable == "pip"

- name: Increase backlog
shell: sysctl -w net.core.somaxconn=1024
become: true

- name: Copy the mux simulator to test server
copy:
src: mux_simulator.py
Expand Down
2 changes: 1 addition & 1 deletion ansible/roles/vm_set/templates/mux-simulator.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Description=mux simulator
After=network.target

[Service]
ExecStart=/usr/local/bin/gunicorn --timeout 60 --preload --bind 0.0.0.0:{{ mux_simulator_port }} --chdir {{ abs_root_path }} mux_simulator_{{ mux_simulator_port }}:app -w 1 --threads 8 --env MUX_SIMULATOR_HTTP_PORT={{ mux_simulator_port }} --env MUX_SIMULATOR_VM_SET={{ vm_set_name }} --env MUX_SIMULATOR_VERBOSITY=1
ExecStart=/usr/bin/env {{python_command}} {{ abs_root_path }}/mux_simulator_{{ mux_simulator_port }}.py {{ mux_simulator_port }} {{ vm_set_name }} -v

0 comments on commit af61468

Please sign in to comment.