Skip to content

Commit

Permalink
update device syncstatus if primary group settings files changed
Browse files Browse the repository at this point in the history
  • Loading branch information
indy-independence committed Nov 27, 2023
1 parent cedd1d7 commit ce82f8a
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/cnaas_nms/db/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import enum
import os
import shutil
from typing import Optional, Set, Tuple
from typing import Dict, Optional, Set, Tuple
from urllib.parse import urldefrag

import yaml
Expand All @@ -13,7 +13,14 @@
from cnaas_nms.db.job import Job, JobStatus
from cnaas_nms.db.joblock import Joblock, JoblockError
from cnaas_nms.db.session import redis_session, sqla_session
from cnaas_nms.db.settings import DIR_STRUCTURE, SettingsSyntaxError, VlanConflictError, rebuild_settings_cache
from cnaas_nms.db.settings import (
DIR_STRUCTURE,
SettingsSyntaxError,
VlanConflictError,
get_device_primary_groups,
get_groups,
rebuild_settings_cache,
)
from cnaas_nms.devicehandler.sync_history import add_sync_event
from cnaas_nms.tools.log import get_logger
from git import InvalidGitRepositoryError, Repo
Expand Down Expand Up @@ -343,6 +350,18 @@ def settings_syncstatus(updated_settings: set) -> Tuple[Set[DeviceType], Set[str
unsynced_hostnames.add(hostname)
except Exception as e:
logger.exception("Error in settings devices directory: {}".format(str(e)))
elif basedir.startswith("groups"):
try:
groupname = filename.split(os.path.sep)[1]
if groupname not in get_groups():
logger.warning("Group {} not found in database, syncstatus not updated".format(groupname))

Check warning on line 357 in src/cnaas_nms/db/git.py

View check run for this annotation

Codecov / codecov/patch

src/cnaas_nms/db/git.py#L353-L357

Added lines #L353 - L357 were not covered by tests
else:
primary_group_mapping: Dict[str, str] = get_device_primary_groups()
for map_hostname, map_groupname in primary_group_mapping.items():
if groupname == map_groupname:
unsynced_hostnames.add(map_hostname)
except Exception as e:
logger.exception("Error in settings groups directory {}: {}".format(filename, str(e)))

Check warning on line 364 in src/cnaas_nms/db/git.py

View check run for this annotation

Codecov / codecov/patch

src/cnaas_nms/db/git.py#L359-L364

Added lines #L359 - L364 were not covered by tests
else:
logger.warn("Unhandled settings file found {}, syncstatus not updated".format(filename))
return (unsynced_devtypes, unsynced_hostnames)
Expand Down

0 comments on commit ce82f8a

Please sign in to comment.