Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve container checker for gnmi/telemetry container #18529

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions files/image_config/monit/container_checker
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ from swsscommon import swsscommon
EVENTS_PUBLISHER_SOURCE = "sonic-events-host"
EVENTS_PUBLISHER_TAG = "event-down-ctr"

def check_docker_image(image_name):
"""
@summary: This function will check if docker image exists.
@return: True if the image exists, otherwise False.
"""
try:
DOCKER_CLIENT = docker.DockerClient(base_url='unix://var/run/docker.sock')
DOCKER_CLIENT.images.get(image_name)
return True
except (docker.errors.ImageNotFound, docker.errors.APIError) as err:
print("Failed to get image '{}'. Error: '{}'".format(image_name, err))
return False

def get_expected_running_containers():
"""
@summary: This function will get the expected running & always-enabled containers by following the rule:
Expand Down Expand Up @@ -55,7 +68,24 @@ def get_expected_running_containers():
# it will be removed from exception list.
run_all_instance_list = ['database', 'bgp']

container_list = []
for container_name in feature_table.keys():
# slim image does not have telemetry container and corresponding docker image
if container_name == "telemetry":
ret = check_docker_image("docker-sonic-telemetry")
if not ret:
# If telemetry container image is not present, check gnmi container image
# If gnmi container image is not present, ignore telemetry container check
# if gnmi container image is present, check gnmi container instead of telemetry
ret = check_docker_image("docker-sonic-gnmi")
if not ret:
print("Ignoring telemetry container check on image which has no corresponding docker image")
else:
container_list.append("gnmi")
continue
container_list.append(container_name)

for container_name in container_list:
if feature_table[container_name]["state"] not in ["disabled", "always_disabled"]:
if multi_asic.is_multi_asic():
if feature_table[container_name].get("has_global_scope", "True") == "True":
Expand Down
Loading