Skip to content

Commit

Permalink
Fixed building on RHEL-7/CentOS 7
Browse files Browse the repository at this point in the history
Also fixed building with python-2.7.

Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
  • Loading branch information
yarda committed Jun 19, 2020
1 parent 1d0dd6e commit 89e670c
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ PYLINT = pylint-3
ifeq ($(PYTHON),python2)
PYLINT = pylint-2
endif
SHEBANG_REWRITE_REGEX= '1s|^\#!/usr/bin/\<python\>|\#!$(PYTHON)|'
SHEBANG_REWRITE_REGEX= '1s|^\#!/usr/bin/\<python3\>|\#!$(PYTHON)|'
PYTHON_SITELIB = $(shell $(PYTHON) -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib());')
ifeq ($(PYTHON_SITELIB),)
$(error Failed to determine python library directory)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/exports/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import tests.unit.globals
import globals
6 changes: 4 additions & 2 deletions tests/unit/exports/test_controller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import unittest
from unittest.mock import Mock

try:
from unittest.mock import Mock
except ImportError:
from mock import Mock
from tuned.exports.controller import ExportsController
import tuned.exports as exports

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/hardware/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import tests.unit.globals
import globals
5 changes: 4 additions & 1 deletion tests/unit/hardware/test_inventory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import unittest
from unittest.mock import Mock
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock
import pyudev

from tuned.hardware.inventory import Inventory
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/monitors/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import tests.unit.globals
import globals
2 changes: 1 addition & 1 deletion tests/unit/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import tests.unit.globals
import globals
2 changes: 1 addition & 1 deletion tests/unit/profiles/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import tests.unit.globals
import globals
2 changes: 1 addition & 1 deletion tests/unit/storage/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import tests.unit.globals
import globals
5 changes: 4 additions & 1 deletion tests/unit/storage/test_factory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import unittest
from unittest.mock import Mock
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock
import tuned.storage

class StorageFactoryTestCase(unittest.TestCase):
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/storage/test_storage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import unittest
from unittest.mock import Mock
from unittest.mock import call
try:
from unittest.mock import Mock
from unittest.mock import call
except ImportError:
from mock import Mock
from mock import call
import tuned.storage

class StorageStorageTestCase(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import tests.unit.globals
import globals
14 changes: 12 additions & 2 deletions tuned.spec
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
%global make_python_arg PYTHON=%{__python3}
%else
%{!?python2_sitelib:%global python2_sitelib %{python_sitelib}}
%global make_python_arg PYTHON=%{__python2}
%if 0%{?rhel} && 0%{?rhel} < 8
%global make_python_arg PYTHON=%{__python}
%global _py python
%else
%global make_python_arg PYTHON=%{__python2}
%global _py python2
%endif
%endif
Expand Down Expand Up @@ -60,6 +61,10 @@ Requires(preun): systemd
Requires(postun): systemd
BuildRequires: %{_py}, %{_py}-devel
# BuildRequires for 'make test'
# python-mock is needed for python-2.7, but it's not available on RHEL-7
%if %{without python3} && ( ! 0%{?rhel} || 0%{?rhel} >= 8 )
BuildRequires: %{_py}-mock
%endif
BuildRequires: %{_py}-configobj
BuildRequires: %{_py}-decorator, %{_py}-pyudev
Requires: %{_py}-decorator, %{_py}-pyudev, %{_py}-configobj
Expand Down Expand Up @@ -275,8 +280,13 @@ touch %{buildroot}%{_sysconfdir}/modprobe.d/kvm.rt.tuned.conf
# validate desktop file
desktop-file-validate %{buildroot}%{_datadir}/applications/tuned-gui.desktop

# Run tests on RHEL > 7 or non RHEL
# We cannot run tests on RHEL-7 because there is no python-mock package and
# python-2.7 doesn't have mock built-in
%if 0%{?rhel} > 7 || ! 0%{?rhel}
%check
make test
make test %{make_python_arg}
%endif

%post
%systemd_post tuned.service
Expand Down

0 comments on commit 89e670c

Please sign in to comment.