1. 名称使用 loongnix 而不是 loongnix-server 是由于部分脚本是通过 /etc/loongnix-release 的文件名去判断版本的,这样只 能匹配到 loongnix. 2. loongnix-server 修改LD_LIBRARY_PATH 之后,会导致 sudo ,su等命令失 效,只好在执行su命令的时候 export LD_LIBRARY_PATH=/usr/lib64, 保证su 命令成功, 试过 alias su='export LD_LIBRARY_PATH=/usr/lib64; su' 但是 py 需要 subprocess.run(cmd, shell=True) 才能读取这种环境变量,还是 全部替换了。
83 lines
3.3 KiB
Python
83 lines
3.3 KiB
Python
# -*- coding:utf-8 -*-
|
|
# Copyright (c) 2020 Huawei Technologies Co.,Ltd.
|
|
#
|
|
# openGauss is licensed under Mulan PSL v2.
|
|
# You can use this software according to the terms
|
|
# and conditions of the Mulan PSL v2.
|
|
# You may obtain a copy of Mulan PSL v2 at:
|
|
#
|
|
# http://license.coscl.org.cn/MulanPSL2
|
|
#
|
|
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OF ANY KIND,
|
|
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
# See the Mulan PSL v2 for more details.
|
|
# ----------------------------------------------------------------------------
|
|
import os
|
|
import subprocess
|
|
from gspylib.inspection.common import SharedFuncs
|
|
from gspylib.inspection.common.CheckItem import BaseItem
|
|
from gspylib.inspection.common.CheckResult import ResultStatus
|
|
from base_utils.os.file_util import FileUtil
|
|
from base_utils.os.net_util import NetUtil
|
|
from os_platform.linux_distro import LinuxDistro
|
|
|
|
networkCards = []
|
|
|
|
|
|
class CheckBond(BaseItem):
|
|
def __init__(self):
|
|
super(CheckBond, self).__init__(self.__class__.__name__)
|
|
|
|
def doCheck(self):
|
|
global networkCards
|
|
if (self.cluster):
|
|
# Get node information
|
|
LocalNodeInfo = self.cluster.getDbNodeByName(self.host)
|
|
# Get the IP address
|
|
serviceIP = LocalNodeInfo.backIps[0]
|
|
elif (self.ipAddr):
|
|
serviceIP = self.ipAddr
|
|
else:
|
|
serviceIP = SharedFuncs.getIpByHostName(self.host)
|
|
networkCards = NetUtil.getAllNetworkInfo()
|
|
for network in networkCards:
|
|
if (network.ipAddress == serviceIP):
|
|
networkCardNum = network.NICNum
|
|
netBondMode = network.networkBondModeInfo
|
|
break
|
|
|
|
self.result.val = netBondMode
|
|
self.result.rst = ResultStatus.OK
|
|
self.result.raw = "%s\n%s\n" % (networkCardNum, netBondMode)
|
|
|
|
bondFile = '/proc/net/bonding/%s' % networkCardNum
|
|
if (os.path.exists(bondFile)):
|
|
self.result.raw += bondFile
|
|
flag1 = FileUtil.readFile(bondFile, 'BONDING_OPTS')
|
|
flag2 = FileUtil.readFile(bondFile, 'BONDING_MODULE_OPTS')
|
|
if (not flag1 and not flag2):
|
|
self.result.rst = ResultStatus.NG
|
|
self.result.val += "\nNo 'BONDING_OPTS' or" \
|
|
" 'BONDING_MODULE_OPTS' in bond" \
|
|
" config file[%s]." % bondFile
|
|
|
|
def doSet(self):
|
|
ifcfgFileSuse = "/etc/sysconfig/network/ifcfg-%s" % networkCards
|
|
ifcfgFileRedhat = "/etc/sysconfig/network-scripts/ifcfg-%s" \
|
|
% networkCards
|
|
distname, version, idnum = LinuxDistro.linux_distribution()
|
|
if (distname in ["redhat", "centos", "euleros", "openEuler", "FusionOS", "loongnix"]):
|
|
cmd = "echo BONDING_MODULE_OPTS='mode=%d " \
|
|
"miimon=100 use_carrier=0' >> %s " % (1, ifcfgFileRedhat)
|
|
else:
|
|
cmd = "echo BONDING_MODULE_OPTS='mode=%d miimon=100" \
|
|
" use_carrier=0' >> %s" % (1, ifcfgFileSuse)
|
|
(status, output) = subprocess.getstatusoutput(cmd)
|
|
if (status != 0):
|
|
self.result.val = "Failed to set bond mode.\n" + \
|
|
"The cmd is %s " % cmd
|
|
else:
|
|
self.result.val = "set bond mode successfully.\n"
|