From 930862a97c2cd4425172c0e3273af2876a9a9f9b Mon Sep 17 00:00:00 2001 From: lijia Date: Mon, 19 Aug 2019 09:53:40 +0800 Subject: sync --- deploy_etc/tsg_chassis_port.json | 12 +++++----- py_cmd/tsg_hardware_reboot.py | 21 ++++++++++++++++- py_common/common_args.py | 16 ------------- py_common/common_get_tags.py | 30 ----------------------- py_common/common_influxdb.py | 41 -------------------------------- py_common/common_json.py | 20 ---------------- py_common/common_telegraf.py | 10 -------- py_test/syslog_test.py | 6 ++--- py_tools/tsg_get_sn.py | 21 ----------------- py_tools/tsg_update_tags.py | 51 ---------------------------------------- service_script/tsgenv.service | 17 ++++++++++++++ service_script/tsgenv.setup | 28 ++++++++++++++++++++++ service_script/tsgtfe.service | 14 +++++++++++ 13 files changed, 88 insertions(+), 199 deletions(-) delete mode 100644 py_common/common_args.py delete mode 100644 py_common/common_get_tags.py delete mode 100644 py_common/common_influxdb.py delete mode 100644 py_common/common_json.py delete mode 100644 py_common/common_telegraf.py delete mode 100644 py_tools/tsg_get_sn.py delete mode 100644 py_tools/tsg_update_tags.py create mode 100644 service_script/tsgenv.service create mode 100644 service_script/tsgenv.setup create mode 100644 service_script/tsgtfe.service diff --git a/deploy_etc/tsg_chassis_port.json b/deploy_etc/tsg_chassis_port.json index 7deae44..ae8c1d9 100644 --- a/deploy_etc/tsg_chassis_port.json +++ b/deploy_etc/tsg_chassis_port.json @@ -33,25 +33,25 @@ "port_id": 43, "type": "backplane", "function": "intercomm", - "description": "to mcn 1" + "description": "to mcn 0" }, { "port_id": 41, "type": "backplane", "function": "intercomm", - "description": "to mcn 2" + "description": "to mcn 1" }, { "port_id": 39, "type": "backplane", - "function": " intercomm ", - "description": "to mcn 3" + "function": "intercomm", + "description": "to mcn 2" }, { "port_id": 37, "type": "backplane", - "function": " intercomm ", - "description": "to mcn 4" + "function": "intercomm", + "description": "to mcn 3" } ] } diff --git a/py_cmd/tsg_hardware_reboot.py b/py_cmd/tsg_hardware_reboot.py index 786d166..1594565 100644 --- a/py_cmd/tsg_hardware_reboot.py +++ b/py_cmd/tsg_hardware_reboot.py @@ -3,6 +3,11 @@ import sys import re import syslog import subprocess +from sys import path +path.append(r'../py_common') #将存放module的路径添加进来 +path.append(r'./py_common') #将存放module的路径添加进来 +from common_modules_operator import * +from common_whoami import * ##define KERN_EMERG "<0>" /* system is unusable */ ##define KERN_ALERT "<1>" /* action must be taken immediately */ @@ -37,14 +42,28 @@ def system_cmd_run(cmd_str): return 1, e return exitcode, output + + +def tsg_grace_down(): + system_cmd_run("echo 0 > /sys/class/net/ens1/device/sriov_numvfs") + time.sleep(1) + system_cmd_run("ifconfig ens1.100 down") + time.sleep(1) + system_cmd_run("vconfig rem ens1.100") + time.sleep(1) + system_cmd_run("ifconfig ens1 down") def tsg_hardware_reboot(): #G_LOCAL_NODE_NAME = get_local_node_name() - G_LOCAL_NODE_NAME = "TSG_MCN1" + #G_LOCAL_NODE_NAME = "TSG_MCN1" + + type, id, G_LOCAL_NODE_NAME = tsg_whoami() log_handle = syslog.openlog(G_LOCAL_NODE_NAME) msg = "[%s] %s" %(MSG_PREFIX[syslog.LOG_NOTICE], "call tsg_hardware_reboot...") syslog.syslog(syslog.LOG_NOTICE, msg) + + tsg_grace_down() ret = system_cmd_run("reboot") if ret != 0: diff --git a/py_common/common_args.py b/py_common/common_args.py deleted file mode 100644 index 406a5b4..0000000 --- a/py_common/common_args.py +++ /dev/null @@ -1,16 +0,0 @@ -#coding=utf-8 -import argparse - -def setup_common_args(): - parser = argparse.ArgumentParser(description='TSG OAM Argument Parser') - - parser.add_argument('-g', '--debug', help = 'debug mode, default is disable', - action='store_true', default = 0) - parser.add_argument('-l', '--log-level', help = 'debug log level, support:10,20,30,40,50, default is:30', - type=int, default = 30) - parser.add_argument('--telegraf-ip', help = 'send log to telegraf ip address, default is:192.168.200.5', - type=str, default = '192.168.200.5') - parser.add_argument('--telegraf-port', help = 'send log to telegraf port, default is:8126', - type=int, default = 8126) - - return parser \ No newline at end of file diff --git a/py_common/common_get_tags.py b/py_common/common_get_tags.py deleted file mode 100644 index 7e3d148..0000000 --- a/py_common/common_get_tags.py +++ /dev/null @@ -1,30 +0,0 @@ -import json - -SN_JSON_PATH = '/opt/tsg/etc/tsg_tags.json' - -def tsg_get_tags_json(): - try: - with open(SN_JSON_PATH) as json_fp: - json_dict = json.load(json_fp) - return json_dict['tags'] - except IOError: - return "" - -def tsg_get_tags(): - tags = {} - json_fp = tsg_get_tags_json() - if len(json_fp) > 0: - for tag_item in json_fp: - #print(tag_item) - tags[tag_item['tag']] = tag_item['value'] - - return tags - -def main(): - tags = {} - - tags = tsg_get_tags() - print(tags) - -if __name__ == '__main__': - main() \ No newline at end of file diff --git a/py_common/common_influxdb.py b/py_common/common_influxdb.py deleted file mode 100644 index c8ca799..0000000 --- a/py_common/common_influxdb.py +++ /dev/null @@ -1,41 +0,0 @@ -# coding: utf-8 - -import sys -from influxdb import InfluxDBClient - - -#return value -#ret, result_array, message -def tsg_influxb_query(influxdb_client, sql_str): - try: - result = influxdb_client.query(sql_str) - except Exception as e: - return 1, {}, e - - return 0, result.get_points(), "succ" - -#return value: -#ret, client, error_msg -def tsg_influxdb_init(arg_host,arg_port,arg_username,arg_password,arg_db): - try: - influxdb_client = InfluxDBClient(host=arg_host,port=arg_port,username=arg_username,password=arg_password,database=arg_db, timeout=3) - except Exception as e: - print("InfluxDBClient error: %s" %(e)) - return 1, None, e - - return 0, influxdb_client, "succ" - -if __name__ == '__main__': - ret, influxdb_client, msg = tsg_influxdb_init('127.0.0.1', 8086, 'admin', 'tsg2019', 'tsg_stat') - if ret != 0: - sys.exit(1) - - ret, points,msg = tsg_influxb_query(influxdb_client, "select * from interface order by time desc limit 1") - if ret == 0: - print("--for xxx in points:-----------------") - for point in points: - print("--------%s, %s" %(point['PhyRXBits'], point['PhyRXMissed'])) - - else: - print("query error, %s" %(res)) - diff --git a/py_common/common_json.py b/py_common/common_json.py deleted file mode 100644 index 61aec60..0000000 --- a/py_common/common_json.py +++ /dev/null @@ -1,20 +0,0 @@ -# coding: utf-8 - -import sys -import psutil -import time -import json - -#return value: -# 0, error msg, json_dict : succ -# 1, error msg, "" : error -def tsg_json_parse(file_name): - try: - with open(file_name) as json_fp: - try: - json_dict = json.load(json_fp) - return 0, "", json_dict - except Exception as e: - return 1, e, "" - except Exception as e: - return 1, e , "" \ No newline at end of file diff --git a/py_common/common_telegraf.py b/py_common/common_telegraf.py deleted file mode 100644 index e3e5744..0000000 --- a/py_common/common_telegraf.py +++ /dev/null @@ -1,10 +0,0 @@ -# coding: utf-8 - -import telegraf - -def telegraf_init(arg_host, arg_port, arg_tags): - #global telegraf_client - #global_tags = {'host' : "lijia", 'local_ip_addr': "127.0.0.1"} - telegraf_client = telegraf.TelegrafClient(host = arg_host, port = arg_port, tags = arg_tags) - return telegraf_client - diff --git a/py_test/syslog_test.py b/py_test/syslog_test.py index 6c56283..f1be9ea 100644 --- a/py_test/syslog_test.py +++ b/py_test/syslog_test.py @@ -5,6 +5,6 @@ import syslog if __name__ == '__main__': - log_handle = syslog.openlog("TSG-MCN0") - syslog.syslog(syslog.LOG_ERR, "[ERR][APP][STAT]app process not exit.") - syslog.syslog(syslog.LOG_ERR, "[NOTICE][CLI][CMD]call reboot.") \ No newline at end of file + log_handle = syslog.openlog("mcn0") + syslog.syslog(syslog.LOG_ERR, "<12>[WARNING][KNI][NETWORK][eth1]More than 100 packets were lost") + syslog.syslog(syslog.LOG_ERR, "<189>[NOTICE][KNI][NETWORK][eth1]clear event list") \ No newline at end of file diff --git a/py_tools/tsg_get_sn.py b/py_tools/tsg_get_sn.py deleted file mode 100644 index e0bf4f3..0000000 --- a/py_tools/tsg_get_sn.py +++ /dev/null @@ -1,21 +0,0 @@ -import json - -SN_JSON_PATH = '/opt/tsg/etc/tsg_sn.json' - -def tsg_get_sn(): - try: - with open(SN_JSON_PATH) as json_fp: - json_dict = json.load(json_fp) - return json_dict['sn'] - except IOError: - return "" - -def main(): - sn = tsg_get_sn() - if len(sn) > 0: - print("%s" %(sn)) - else: - print("can't get sn") - -if __name__ == '__main__': - main() diff --git a/py_tools/tsg_update_tags.py b/py_tools/tsg_update_tags.py deleted file mode 100644 index c56ed12..0000000 --- a/py_tools/tsg_update_tags.py +++ /dev/null @@ -1,51 +0,0 @@ -import sys -import subprocess -import json -from tsg_get_sn import * -import shutil - -class CommandException(Exception): - pass - -def tsg_get_device_list_info_by_sn(sn): - command = "consul kv get device_list/%s" %(sn) - exitcode, output = subprocess.getstatusoutput(command) - #print("%d" %(exitcode)) - if exitcode != 0: - raise CommandException(output) - return "" - else: - return output - -def tsg_get_tags_by_sn(sn): - dev_list_info = tsg_get_device_list_info_by_sn(sn) - if len(dev_list_info) <= 0: - #返回空json - return "{}" - - json_dict = json.loads(dev_list_info) - tags = json_dict['tags'] - #重新组织成合法的json格式 - dict_to_json = json.dumps(tags) - json_tags = "{\"tags\":%s}" %(dict_to_json) - return json_tags - -def update_tags_json_file(json_cont): - fp = open('/opt/tsg/etc/tsg_tags.json.tmp', 'w') - fp.write(json_cont) - fp.close() - shutil.copyfile('/opt/tsg/etc/tsg_tags.json.tmp', '/opt/tsg/etc/tsg_tags.json') - -if __name__ == '__main__': - # call function in file tsg_get_sn.py - sn = tsg_get_sn() - if len(sn) <= 0: - sys.exit(2) - - json_cont = tsg_get_tags_by_sn(sn) - if len(json_cont) <= 0: - sys.exit(2) - - #print(json_cont) - update_tags_json_file(json_cont) - sys.exit(0) diff --git a/service_script/tsgenv.service b/service_script/tsgenv.service new file mode 100644 index 0000000..6327df4 --- /dev/null +++ b/service_script/tsgenv.service @@ -0,0 +1,17 @@ +[Unit] +Description=tsg env init +Requires=network.target +After=network.target + +[Service] +WorkingDirectory=/opt/tsg/env +ExecStart=/opt/tsg/env/setup +#ExecStop=/home/tsg/kni/kni_service_scipt stop +#ExecStop=/bin/kill -9 $MAINPID +Type=oneshot +RemainAfterExit=yes +#Restart=always +#RestartSec=5s + +[Install] +WantedBy=multi-user.target diff --git a/service_script/tsgenv.setup b/service_script/tsgenv.setup new file mode 100644 index 0000000..7b45f0b --- /dev/null +++ b/service_script/tsgenv.setup @@ -0,0 +1,28 @@ +#!/bin/bash +# + ifconfig ens1 up + + modprobe 8021q + vconfig add ens1 100 + vconfig set_flag ens1.100 1 1 + ifconfig ens1.100 192.168.100.1 netmask 255.255.255.0 up + + echo 0 > /sys/class/net/ens1/device/sriov_numvfs + sleep 1 + echo 8 > /sys/class/net/ens1/device/sriov_numvfs + sleep 1 + + ifconfig ens1f3 up + ip link set ens1 vf 2 vlan 200 + ifconfig ens1f3 192.168.200.1 netmask 255.255.255.0 + +ifconfig enp7s0 up +ifconfig enp8s0 up +ifconfig ens1f1 up +ifconfig ens1f2 up +ifconfig ens1f3 up +ifconfig ens1f4 up +ifconfig ens1f5 up +ifconfig ens1f6 up +ifconfig ens1f7 up +ifconfig enp1s1 up diff --git a/service_script/tsgtfe.service b/service_script/tsgtfe.service new file mode 100644 index 0000000..5e09b68 --- /dev/null +++ b/service_script/tsgtfe.service @@ -0,0 +1,14 @@ +[Unit] +Description=tsg tfe module +Requires=tfe-env.service +#After=tfe-env.service + +[Service] +WorkingDirectory=/home/tsg/tfe/ +ExecStart=/home/tsg/tfe/bin/tfe +ExecStop=/bin/kill -9 $MAINPID +Restart=always +RestartSec=5s + +[Install] +WantedBy=multi-user.target -- cgit v1.2.3