Skip to content

Commit

Permalink
Add missing makefile for docker-pit; replace some function with sonic…
Browse files Browse the repository at this point in the history
…_py_common modules'; remove some similar functions.
  • Loading branch information
clarklee-guizhao committed Feb 15, 2023
1 parent 38ba32b commit 71a7e69
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 112 deletions.
31 changes: 31 additions & 0 deletions rules/docker-pit.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# docker image for docker-pit

ifeq ($(SONIC_INCLUDE_PIT), y)

DOCKER_PIT = docker-pit.gz
$(DOCKER_PIT)_PATH = $(DOCKERS_PATH)/docker-pit
$(DOCKER_PIT)_PYTHON_WHEELS += $(SONIC_PLATFORM_COMMON_PY2) $(SONIC_PIT_PY3) $(SONIC_PY_COMMON_PY3)

$(DOCKER_PIT)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_BUSTER)_DBG_DEPENDS)

$(DOCKER_PIT)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_BUSTER)

SONIC_DOCKER_IMAGES += $(DOCKER_PIT)
SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_PIT)

$(DOCKER_PIT)_CONTAINER_NAME = pit
$(DOCKER_PIT)_RUN_OPT += --privileged -t
$(DOCKER_PIT)_RUN_OPT += -v /etc/sonic:/etc/sonic:rw
$(DOCKER_PIT)_RUN_OPT += -v /var/log/wtmp:/var/log/wtmp:ro
$(DOCKER_PIT)_RUN_OPT += -v /var/run/frr:/var/run/frr:rw
$(DOCKER_PIT)_RUN_OPT += -v /usr/share/sonic/device:/usr/share/sonic/device:rw
$(DOCKER_PIT)_RUN_OPT += -v /host:/host:rw
$(DOCKER_PIT)_RUN_OPT += -v /root/.ssh:/usr/share/host_ssh:rw
$(DOCKER_PIT)_RUN_OPT += -v /etc/default/locale:/etc/default/locale:ro

# enable docker cmd inside the alinos-monitor container
$(DOCKER_PIT)_RUN_OPT += -v /var/run/docker.sock:/var/run/docker.sock:rw
$(DOCKER_PIT)_RUN_OPT += -v /usr/bin/docker:/usr/bin/docker
$(DOCKER_PIT)_RUN_OPT += -v /usr/lib/x86_64-linux-gnu/libapparmor.so.1:/usr/lib/x86_64-linux-gnu/libapparmor.so.1
$(DOCKER_PIT)_RUN_OPT += -v /usr/lib/x86_64-linux-gnu/libltdl.so.7:/usr/lib/x86_64-linux-gnu/libltdl.so.7
endif
38 changes: 1 addition & 37 deletions src/sonic-pit/pit-sysdiag/src/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,12 @@
import imp
import json
import requests
from sonic_py_common.device_info import get_platform_and_hwsku


PLATFORM_ROOT_PATH = "/usr/share/sonic/device"
PLATFORM_ROOT_PATH_DOCKER = "/usr/share/sonic/platform"

SONIC_CFGGEN_PATH = "/usr/local/bin/sonic-cfggen"
HWSKU_KEY = "DEVICE_METADATA['localhost']['hwsku']"
PLATFORM_KEY = "DEVICE_METADATA['localhost']['platform']"


def get_platform_and_hwsku():
try:
proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-H', '-v', PLATFORM_KEY],
stdout=subprocess.PIPE,
shell=False,
stderr=subprocess.STDOUT)
stdout = proc.communicate()[0].decode()
proc.wait()
platform = stdout.rstrip("\n")
# platform = platform.lower().rstrip("-r0")

proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-d', '-v', HWSKU_KEY],
stdout=subprocess.PIPE,
shell=False,
stderr=subprocess.STDOUT)
stdout = proc.communicate()[0].decode()
proc.wait()
hwsku = stdout.rstrip("\n")
except OSError as e:
raise OSError("Cannot detect platform")

return (platform, hwsku)


def load_platform_util_module(module_name):
platform_util_module = None
Expand Down Expand Up @@ -64,15 +37,6 @@ def convert_unicode(input):
return input


def exec_cmd(cmd_str):
output = None
try:
output = subprocess.check_output(cmd_str, shell=True,)
except Exception as err:
print("{} exec cmd failed.{}".format(cmd_str, err))
return output


def run_command(cmd):
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = proc.communicate()
Expand Down
75 changes: 1 addition & 74 deletions src/sonic-pit/pit-sysdiag/src/pit_util_common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding:utf-8 -*-
from __future__ import print_function
#from subprocess import PIPE, Popen
from errcode import E
import subprocess
import threading
Expand All @@ -11,79 +10,7 @@
import imp
import re
import json

# from threading import Lock, Thread
PLATFORM_ROOT_PATH = "/usr/share/sonic/device"
PLATFORM_ROOT_PATH_DOCKER = "/usr/share/sonic/platform"

SONIC_CFGGEN_PATH = "/usr/local/bin/sonic-cfggen"
HWSKU_KEY = "DEVICE_METADATA['localhost']['hwsku']"
PLATFORM_KEY = "DEVICE_METADATA['localhost']['platform']"


def get_platform_and_hwsku():
try:
proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-H', '-v', PLATFORM_KEY],
stdout=subprocess.PIPE,
shell=False,
stderr=subprocess.STDOUT)
stdout = proc.communicate()[0]
proc.wait()
platform = stdout.decode().rstrip("\n")

proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-d', '-v', HWSKU_KEY],
stdout=subprocess.PIPE,
shell=False,
stderr=subprocess.STDOUT)
stdout = proc.communicate()[0]
proc.wait()
hwsku = stdout.decode().rstrip("\n")
except OSError as e:
raise OSError("Cannot detect platform")

return (platform, hwsku)


def load_platform_util_module(module_name):
platform_util_module = None

(platform, hwsku) = get_platform_and_hwsku()
platform_path = ''
if len(platform) != 0:
platform_path = "/".join([PLATFORM_ROOT_PATH, platform])
else:
platform_path = PLATFORM_ROOT_PATH_DOCKER

try:
module_file = "/".join([platform_path, "plugins", module_name + ".py"])
platform_util_module = imp.load_source(module_name, module_file)
except IOError as e:
return None

return platform_util_module


def run_command(cmd):
proc = subprocess.Popen(cmd, shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = proc.communicate()
if err and proc.returncode != 0:
return proc.returncode, err
return 0, out.decode().rstrip('\n')


def execute_cmd(cmdlist):
for cmd in cmdlist:
proc = Popen(cmd, stdin=PIPE, shell=True,
stderr=sys.stderr,
close_fds=True,
stdout=sys.stdout,
universal_newlines=True,
bufsize=1)
proc.communicate()
signal.signal(signal.SIGINT, quit)
return proc.returncode
from sonic_py_common.device_info import get_platform_and_hwsku


def execute_cmd_return_match(cmd, pattern, linemode=True):
Expand Down
3 changes: 2 additions & 1 deletion src/sonic-pit/pit-sysdiag/src/sysdiag.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/python3
# -*- coding: UTF-8 -*-

from function import get_platform_and_hwsku, run_command
from function import run_command
from sonic_py_common.device_info import get_platform_and_hwsku
import imp
import inspect
import os
Expand Down

0 comments on commit 71a7e69

Please sign in to comment.