CentOS 8: update fm-common to use python3
1. change python2 rpms to python3 version. 2. update Cpython code to use new API in python3 Test: Could pass rpm package build for fm-common Story: 2007065 Task: 37942 Change-Id: Ie0490118bcc891c2e994b3eeb6efab24ac7951cb Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>
This commit is contained in:
parent
4dc4325ab0
commit
a2af71b867
@ -1,7 +1,7 @@
|
|||||||
%define local_dir /usr/local
|
%define local_dir /usr/local
|
||||||
%define local_bindir %{local_dir}/bin
|
%define local_bindir %{local_dir}/bin
|
||||||
%define cgcs_doc_deploy_dir /opt/deploy/cgcs_doc
|
%define cgcs_doc_deploy_dir /opt/deploy/cgcs_doc
|
||||||
%define pythonroot /usr/lib64/python2.7/site-packages
|
%define pythonroot %python3_sitearch
|
||||||
|
|
||||||
Summary: CGTS Platform Fault Management Common Package
|
Summary: CGTS Platform Fault Management Common Package
|
||||||
Name: fm-common
|
Name: fm-common
|
||||||
@ -15,10 +15,10 @@ Source0: %{name}-%{version}.tar.gz
|
|||||||
BuildRequires: util-linux
|
BuildRequires: util-linux
|
||||||
BuildRequires: postgresql-devel
|
BuildRequires: postgresql-devel
|
||||||
BuildRequires: libuuid-devel
|
BuildRequires: libuuid-devel
|
||||||
BuildRequires: python-devel
|
BuildRequires: python3-devel
|
||||||
BuildRequires: python-setuptools
|
BuildRequires: python3-setuptools
|
||||||
BuildRequires: python2-pip
|
BuildRequires: python3-pip
|
||||||
BuildRequires: python2-wheel
|
BuildRequires: python3-wheel
|
||||||
|
|
||||||
%package -n fm-common-dev
|
%package -n fm-common-dev
|
||||||
Summary: CGTS Platform Fault Management Common Package - Development files
|
Summary: CGTS Platform Fault Management Common Package - Development files
|
||||||
@ -51,8 +51,8 @@ VER=%{version}
|
|||||||
MAJOR=`echo $VER | awk -F . '{print $1}'`
|
MAJOR=`echo $VER | awk -F . '{print $1}'`
|
||||||
MINOR=`echo $VER | awk -F . '{print $2}'`
|
MINOR=`echo $VER | awk -F . '{print $2}'`
|
||||||
make MAJOR=$MAJOR MINOR=$MINOR %{?_smp_mflags}
|
make MAJOR=$MAJOR MINOR=$MINOR %{?_smp_mflags}
|
||||||
%{__python} setup.py build
|
%{__python3} setup.py build
|
||||||
%py2_build_wheel
|
%py3_build_wheel
|
||||||
|
|
||||||
%install
|
%install
|
||||||
rm -rf %{buildroot}
|
rm -rf %{buildroot}
|
||||||
@ -66,7 +66,7 @@ make DESTDIR=%{buildroot} \
|
|||||||
CGCS_DOC_DEPLOY=%{cgcs_doc_deploy_dir} \
|
CGCS_DOC_DEPLOY=%{cgcs_doc_deploy_dir} \
|
||||||
MAJOR=$MAJOR MINOR=$MINOR install
|
MAJOR=$MAJOR MINOR=$MINOR install
|
||||||
|
|
||||||
%{__python} setup.py install --root=%{buildroot} \
|
%{__python3} setup.py install --root=%{buildroot} \
|
||||||
--install-lib=%{pythonroot} \
|
--install-lib=%{pythonroot} \
|
||||||
--prefix=/usr \
|
--prefix=/usr \
|
||||||
--install-data=/usr/share
|
--install-data=/usr/share
|
||||||
@ -83,7 +83,9 @@ rm -rf %{buildroot}
|
|||||||
%{local_bindir}/*
|
%{local_bindir}/*
|
||||||
%{_libdir}/*.so.*
|
%{_libdir}/*.so.*
|
||||||
|
|
||||||
%{pythonroot}/fm_core.so
|
# with python3 PEP 3149, ABI version is tagged in so name.
|
||||||
|
# so the file name will be like: fm_core.cpython-36m-x86_64-linux-gnu.so
|
||||||
|
%{pythonroot}/fm_core.cpython-3*.so
|
||||||
%{pythonroot}/fm_core-*.egg-info
|
%{pythonroot}/fm_core-*.egg-info
|
||||||
|
|
||||||
%files -n fm-common-dev
|
%files -n fm-common-dev
|
||||||
|
@ -4,7 +4,7 @@ SRCS = fmAPI.cpp fmFile.cpp fmLog.cpp fmMsgServer.cpp fmMutex.cpp fmSocket.cpp f
|
|||||||
CLI_SRCS = fm_cli.cpp
|
CLI_SRCS = fm_cli.cpp
|
||||||
OBJS = $(SRCS:.cpp=.o)
|
OBJS = $(SRCS:.cpp=.o)
|
||||||
CLI_OBJS = fm_cli.o
|
CLI_OBJS = fm_cli.o
|
||||||
LDLIBS = -lstdc++ -lrt -luuid -lpq -lpthread -lpython2.7
|
LDLIBS = -lstdc++ -lrt -luuid -lpq -lpthread -lpython3.6m
|
||||||
INCLUDES = -I./ -I$(shell pg_config --includedir)
|
INCLUDES = -I./ -I$(shell pg_config --includedir)
|
||||||
CCFLAGS = -g -O2 -Wall -Werror -fPIC
|
CCFLAGS = -g -O2 -Wall -Werror -fPIC
|
||||||
EXTRACCFLAGS= -Wformat -Wformat-security
|
EXTRACCFLAGS= -Wformat -Wformat-security
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <python2.7/Python.h>
|
#include <python3.6m/Python.h>
|
||||||
|
|
||||||
|
|
||||||
#include "fmMutex.h"
|
#include "fmMutex.h"
|
||||||
@ -611,21 +611,32 @@ bool fm_db_util_sync_event_suppression(void){
|
|||||||
|
|
||||||
FILE* file;
|
FILE* file;
|
||||||
int argc;
|
int argc;
|
||||||
char * argv[2];
|
|
||||||
|
|
||||||
FM_INFO_LOG("Starting event suppression synchronization...\n");
|
FM_INFO_LOG("Starting event suppression synchronization...\n");
|
||||||
|
|
||||||
argc = 2;
|
argc = 2;
|
||||||
argv[0] = (char*)FM_DB_SYNC_EVENT_SUPPRESSION;
|
|
||||||
argv[1] = (char*)db_conn;
|
|
||||||
|
|
||||||
Py_SetProgramName(argv[0]);
|
wchar_t *py_argv[2];
|
||||||
|
py_argv[0] = Py_DecodeLocale(FM_DB_SYNC_EVENT_SUPPRESSION, NULL);
|
||||||
|
if (py_argv[0] == NULL) {
|
||||||
|
FM_ERROR_LOG("Fatal error: cannot decode argv[0]\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
py_argv[1] = Py_DecodeLocale(db_conn, NULL);
|
||||||
|
if (py_argv[1] == NULL) {
|
||||||
|
PyMem_RawFree(py_argv[0]);
|
||||||
|
FM_ERROR_LOG("Fatal error: cannot decode argv[1]\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Py_SetProgramName(py_argv[0]);
|
||||||
Py_Initialize();
|
Py_Initialize();
|
||||||
PySys_SetArgv(argc, argv);
|
PySys_SetArgv(argc, py_argv);
|
||||||
file = fopen(FM_DB_SYNC_EVENT_SUPPRESSION,"r");
|
file = fopen(FM_DB_SYNC_EVENT_SUPPRESSION,"r");
|
||||||
PyRun_SimpleFile(file, FM_DB_SYNC_EVENT_SUPPRESSION);
|
PyRun_SimpleFile(file, FM_DB_SYNC_EVENT_SUPPRESSION);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
Py_Finalize();
|
Py_Finalize();
|
||||||
|
PyMem_RawFree(py_argv[0]);
|
||||||
|
PyMem_RawFree(py_argv[1]);
|
||||||
|
|
||||||
FM_INFO_LOG("Completed event suppression synchronization.\n");
|
FM_INFO_LOG("Completed event suppression synchronization.\n");
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python3
|
||||||
# Copyright (c) 2016-2018 Wind River Systems, Inc.
|
# Copyright (c) 2016-2018 Wind River Systems, Inc.
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#define PY_SSIZE_T_CLEAN
|
||||||
#include <python2.7/Python.h>
|
#include <python3.6m/Python.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "fmAPI.h"
|
#include "fmAPI.h"
|
||||||
#include "fmAlarmUtils.h"
|
#include "fmAlarmUtils.h"
|
||||||
@ -84,7 +84,7 @@ static PyObject * _fm_set(PyObject * self, PyObject *args) {
|
|||||||
|
|
||||||
rc = fm_set_fault(&alm_data, &tmp_uuid);
|
rc = fm_set_fault(&alm_data, &tmp_uuid);
|
||||||
if (rc == FM_ERR_OK) {
|
if (rc == FM_ERR_OK) {
|
||||||
return PyString_FromString(&(tmp_uuid[0]));
|
return PyUnicode_FromString(&(tmp_uuid[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc == FM_ERR_NOCONNECT){
|
if (rc == FM_ERR_NOCONNECT){
|
||||||
@ -120,7 +120,7 @@ static PyObject * _fm_get(PyObject * self, PyObject *args) {
|
|||||||
rc = fm_get_fault(&af,&ad);
|
rc = fm_get_fault(&af,&ad);
|
||||||
if (rc == FM_ERR_OK) {
|
if (rc == FM_ERR_OK) {
|
||||||
fm_alarm_to_string(&ad,alm_str);
|
fm_alarm_to_string(&ad,alm_str);
|
||||||
return PyString_FromString(alm_str.c_str());
|
return PyUnicode_FromString(alm_str.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc == FM_ERR_ENTITY_NOT_FOUND) {
|
if (rc == FM_ERR_ENTITY_NOT_FOUND) {
|
||||||
@ -165,7 +165,7 @@ static PyObject * _fm_get_by_aid(PyObject * self, PyObject *args, PyObject* kwar
|
|||||||
std::string s;
|
std::string s;
|
||||||
fm_alarm_to_string(&lst[ix],s);
|
fm_alarm_to_string(&lst[ix],s);
|
||||||
if (s.size() > 0) {
|
if (s.size() > 0) {
|
||||||
if (PyList_Append(__lst, PyString_FromString(s.c_str())) != 0) {
|
if (PyList_Append(__lst, PyUnicode_FromString(s.c_str())) != 0) {
|
||||||
ERROR_LOG("Failed to append alarm to the list");
|
ERROR_LOG("Failed to append alarm to the list");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -214,7 +214,7 @@ static PyObject * _fm_get_by_eid(PyObject * self, PyObject *args, PyObject* kwar
|
|||||||
std::string s;
|
std::string s;
|
||||||
fm_alarm_to_string(&lst[ix], s);
|
fm_alarm_to_string(&lst[ix], s);
|
||||||
if (s.size() > 0) {
|
if (s.size() > 0) {
|
||||||
if (PyList_Append(__lst,PyString_FromString(s.c_str())) != 0) {
|
if (PyList_Append(__lst,PyUnicode_FromString(s.c_str())) != 0) {
|
||||||
ERROR_LOG("Failed to append alarm to the list");
|
ERROR_LOG("Failed to append alarm to the list");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -313,10 +313,20 @@ static PyMethodDef _methods [] = {
|
|||||||
{ NULL, NULL, 0, NULL }
|
{ NULL, NULL, 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static struct PyModuleDef cModPyDem =
|
||||||
|
{
|
||||||
|
PyModuleDef_HEAD_INIT,
|
||||||
|
"fm_core", /* name of module */
|
||||||
|
"", /* module documentation, may be NULL */
|
||||||
|
-1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */
|
||||||
|
_methods
|
||||||
|
};
|
||||||
|
|
||||||
PyMODINIT_FUNC initfm_core() {
|
PyMODINIT_FUNC initfm_core() {
|
||||||
PyObject *m = Py_InitModule("fm_core", _methods);
|
PyObject *m = PyModule_Create(&cModPyDem);
|
||||||
if (m == NULL){
|
if (m == NULL){
|
||||||
PySys_WriteStderr("Failed to initialize fm_core");
|
PySys_WriteStderr("Failed to initialize fm_core");
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user