config_changed complexity too high - refactor needed

Bug #1888692 reported by Drew Freiberger
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MongoDB Charm
Won't Fix
Low
Unassigned

Bug Description

While linting the charm, it was found there is a lot of complexity and duplicate code in the config_changed hook code in hooks/hooks.py that should be refactored.

for instance, these are two different sections of the that function that could be simplified.

    # current ports
    current_mongodb_port = re.search(r'^#*port\s+=\s+(\w+)',
                                     mongodb_config,
                                     re.MULTILINE).group(1)

    current_web_admin_ui_port = int(current_mongodb_port) + 1000
    new_web_admin_ui_port = int(config_data['port']) + 1000
    ****SNIP****
    # web_admin_ui
    if config_data['web_admin_ui']:
        open_port(new_web_admin_ui_port)
    else:
        close_port(current_web_admin_ui_port)

and later in the function:

    if config_data['web_admin_ui']:
        current_web_admin_ui_port = int(current_mongodb_port) + 1000
        new_web_admin_ui_port = int(config_data['port']) + 1000
        close_port(current_web_admin_ui_port)
        open_port(new_web_admin_ui_port)

Also, most functions in this hooks.py should be pulled out into another library.

This bug is to track the need for a general refactoring of hooks.py.

summary: - config_changed hook has too much complexity and duplicate code
+ config_changed complexity too high - refactor needed
Changed in charm-mongodb:
importance: Undecided → Low
Revision history for this message
Eric Chen (eric-chen) wrote :

This charm is no longer being actively maintained. Please consider using the new mongodb-k8s-operator instead.
https://github.com/canonical/mongodb-k8s-operator
I will close this feature request

Changed in charm-mongodb:
status: New → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.