File crmsh.spec of Package crmsh

#
# spec file for package crmsh
#
# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


%bcond_with regression_tests

%global gname haclient
%global uname hacluster
%global crmsh_docdir %{_defaultdocdir}/%{name}

%global upstream_version tip
%global upstream_prefix crmsh
%global crmsh_release 1

%if 0%{?fedora_version} || 0%{?centos_version} || 0%{?rhel_version} || 0%{?rhel} || 0%{?fedora}
%define pkg_group System Environment/Daemons
%else
%define pkg_group Productivity/Clustering/HA
%endif

%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")}

Name:           crmsh
Summary:        High Availability cluster command-line interface
License:        GPL-2.0+
Group:          %{pkg_group}
Version:        3.0.0
Release:        0
Url:            http://crmsh.github.io
Source0:        %{name}-%{version}.tar.bz2
# PATCH-FIX-UPSTREAM: Allow empty fencing topology (bsc#1025393)
Patch1:         0001-Allow-empty-fencing_topology-bsc-1025393.patch
# PATCH-FIX-UPSTREAM: low: bootstrap: Fix warning for formatting SBD device (bsc#1028704)
Patch2:         0002-low-bootstrap-Fix-warning-for-formatting-SBD-device-.patch
# PATCH-FIX-UPSTREAM: medium: ui_cluster: Fix init with no arguments (bsc#1028735)
Patch3:         0003-medium-ui_cluster-Fix-init-with-no-arguments-bsc-102.patch
# PATCH-FIX-UPSTREAM: low: utils: Use /proc for process discovery
Patch4:         0004-low-utils-Use-proc-for-process-discovery.patch
# PATCH-FIX-UPSTREAM: medium: scripts/health: Make health script available as wizard (fate#320848) (fate#320866)
Patch5:         0005-medium-scripts-health-Make-health-script-available-a.patch
# PATCH-FIX-UPSTREAM: low: remove bindnetaddr for unicast(bsc#1030437)
Patch6:         0006-remove-bindnetaddr-for-unicast-bsc-1030437.patch
# PATCH-FIX-UPSTREAM: medium: bootstrap: Set expected votes based on actual node count (bsc#1033288)
Patch7:         0007-medium-bootstrap-Set-expected_votes-based-on-actual-.patch
# PATCH-FIX-UPSTREAM: high: cibconfig: Graph file output option was reversed (bsc#1036595)
Patch8:         0008-high-cibconfig-Graph-file-output-option-was-reversed.patch
# PATCH-FIX-UPSTREAM: medium: bootstrap: Enable "help geo-init" etc. (bsc#1037417)
Patch9:         0009-medium-bootstrap-Enable-help-geo-init-etc.-bsc-10374.patch
# PATCH-FIX-UPSTREAM: medium: bootstrap: Handle failure to fetch config gracefully (bsc#1037423)
Patch10:        0010-medium-bootstrap-Handle-failure-to-fetch-config-grac.patch
# PATCH-FIX-UPSTREAM: medium: bootstrap: Check required arguments to geo-join (bsc#1037421)
Patch11:        0011-medium-bootstrap-Check-required-arguments-to-geo-joi.patch
# PATCH-FIX-UPSTREAM: doc: geo-join requires --clusters argument (bsc#1037442)
Patch12:        0012-doc-geo-join-requires-clusters-argument-bsc-1037442.patch
# PATCH-FIX-UPSTREAM: medium: bootstrap: Make arbitrator argument optional (bsc#1038386)
Patch13:        0013-medium-bootstrap-Make-arbitrator-argument-optional-b.patch
# PATCH-FIX-UPSTREAM: medium: history: Revert preference of messages over ha-log.txt (bsc#1031138)
Patch14:        0014-medium-history-Revert-preference-of-messages-over-ha.patch
# PATCH-FIX-UPSTREAM: medium: ui_cluster: Add --force to ha-cluster-remove (bsc#1044071)
Patch15:        0015-medium-ui_cluster-Add-force-to-ha-cluster-remove-bsc.patch
# PATCH-FIX-UPSTREAM: high: bootstrap: Add option to enable diskless SBD mode to cluster init (bsc#1045118)
Patch16:        0016-high-bootstrap-Add-option-to-enable-diskless-SBD-mod.patch
# PATCH-FIX-UPSTREAM: medium: scripts: Clarify help text for NFS wizard (bsc#1044244)
Patch17:        0017-medium-scripts-Clarify-help-text-for-NFS-wizard-bsc-.patch
# PATCH-FIX-UPSTREAM: medium: scripts: Relax broadcast IP validation (bsc#1044233)
Patch18:        0018-medium-scripts-Relax-broadcast-IP-validation-bsc-104.patch
# PATCH-FIX-UPSTREAM: medium: bootstrap: Fix watchdog SBD envvars (bsc#1045118)
Patch19:        0019-medium-bootstrap-Fix-watchdog-SBD-envvars-bsc-104511.patch

BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%if 0%{?suse_version}
# Requiring pacemaker makes crmsh harder to build on other distributions,
# and is mostly a convenience feature. So only do it for SUSE.
Requires(pre):  pacemaker
%endif
Requires:       %{name}-scripts >= %{version}-%{release}
Requires:       /usr/bin/which
Requires:       python >= 2.6
Requires:       python-dateutil
Requires:       python-lxml
Requires:       python-parallax
BuildRequires:  python-lxml
BuildRequires:  python-setuptools

%if 0%{?suse_version}
# only require csync2 on SUSE since bootstrap
# only works for SUSE at the moment anyway
Requires:       csync2
%endif

%if 0%{?suse_version}
Requires:       python-PyYAML
# Suse splits this off into a separate package
Requires:       python-curses
BuildRequires:  fdupes
BuildRequires:  python-curses
%endif

%if 0%{?fedora_version}
Requires:       PyYAML
%endif

# Required for core functionality
BuildRequires:  asciidoc
BuildRequires:  autoconf
BuildRequires:  automake
BuildRequires:  pkgconfig
BuildRequires:  python

%if 0%{?suse_version} > 1210
# xsltproc is necessary for manpage generation; this is split out into
# libxslt-tools as of openSUSE 12.2.  Possibly strictly should be
# required by asciidoc
BuildRequires:  libxslt-tools
%endif

%if 0%{?suse_version} > 1110 || 0%{?fedora_version} || 0%{?centos_version} || 0%{?rhel_version} || 0%{?rhel} || 0%{?fedora}
BuildArch:      noarch
%endif

%description
The crm shell is a command-line interface for High-Availability
cluster management on GNU/Linux systems. It simplifies the
configuration, management and troubleshooting of Pacemaker-based
clusters, by providing a powerful and intuitive set of features.

%package test
Summary:        Test package for crmsh
Group:          %{pkg_group}
Requires:       crmsh
%if %{with regression_tests}
Requires(post):  mailx
Requires(post):  procps
Requires(post):  python-dateutil
Requires(post):  python-nose
Requires(post):  python-parallax
Requires(post):  pacemaker
%if 0%{?suse_version} > 1110
BuildArch:      noarch
%endif
%if 0%{?suse_version}
Requires(post):  libglue-devel
%else
Requires(post):  cluster-glue-libs-devel
%endif
%if 0%{?fedora_version}
Requires(post):  PyYAML
%else
Requires(post):  python-PyYAML
%endif
%endif

%description test
The crm shell is a command-line interface for High-Availability
cluster management on GNU/Linux systems. It simplifies the
configuration, management and troubleshooting of Pacemaker-based
clusters, by providing a powerful and intuitive set of features.
This package contains the regression test suite for crmsh.

%package scripts
Summary:        Crm Shell Cluster Scripts
Group:          Productivity/Clustering/HA

%description scripts
Cluster scripts for crmsh. The cluster scripts can be run
directly from the crm command line, or used by user interfaces
like hawk to implement configuration wizards.

%prep
%setup -q
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1
%patch9 -p1
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1
%patch14 -p1
%patch15 -p1
%patch16 -p1
%patch17 -p1
%patch18 -p1
%patch19 -p1

# Force the local time
#
# 'hg archive' sets the file date to the date of the last commit.
# This can result in files having been created in the future
# when building on machines in timezones 'behind' the one the
# commit occurred in - which seriously confuses 'make'
find . -mtime -0 -exec touch \{\} \;

%build
./autogen.sh

%{configure}            \
    --sysconfdir=%{_sysconfdir} \
    --localstatedir=%{_var}             \
    --with-version=%{version}    \
    --docdir=%{crmsh_docdir}

make %{_smp_mflags} VERSION="%{version}" sysconfdir=%{_sysconfdir} localstatedir=%{_var}

%if %{with regression_tests}
./test/run --quiet
if [ ! $? ]; then
    echo "Unit tests failed."
    exit 1
fi
%endif

%install
make DESTDIR=%{buildroot} docdir=%{crmsh_docdir} install
install -Dm0644 contrib/bash_completion.sh %{buildroot}%{_sysconfdir}/bash_completion.d/crm.sh
if [ -f %{buildroot}%{_bindir}/crm ]; then
	install -Dm0755 %{buildroot}%{_bindir}/crm %{buildroot}%{_sbindir}/crm
	rm %{buildroot}%{_bindir}/crm
fi
%if 0%{?suse_version}
%fdupes %{buildroot}
%endif

%if %{with regression_tests}
# Run regression tests after installing the package
# NB: this is called twice by OBS, that's why we touch the file
%post test
testfile=/tmp/.crmsh_regression_tests_ran
# check if time in file is less than 2 minutes ago
if [ -e $testfile ] && [ "$(( $(date +%s) - $(cat $testfile) ))" -lt 120 ]; then
	echo "Skipping regression tests..."
	exit 0
fi
# write current time to file
rm -f "$testfile"
echo "$(date +%s)" > "$testfile"
%{_datadir}/%{name}/tests/regression.sh
result1=$?
cd %{_datadir}/%{name}/tests
./cib-tests.sh
result2=$?
[ $result1 -ne 0 ] && (echo "Regression tests failed."; cat ${buildroot}/crmtestout/regression.out)
[ $result2 -ne 0 ] && echo "CIB tests failed."
[ $result1 -eq 0 -a $result2 -eq 0 ]
%endif

%files
###########################################################
%defattr(-,root,root)

%{_sbindir}/crm
%{python_sitelib}/crmsh*

%{_datadir}/%{name}
%exclude %{_datadir}/%{name}/tests
%exclude %{_datadir}/%{name}/scripts

%doc %{_mandir}/man8/*
%{crmsh_docdir}/COPYING
%{crmsh_docdir}/AUTHORS
%{crmsh_docdir}/crm.8.html
%{crmsh_docdir}/crmsh_hb_report.8.html
%{crmsh_docdir}/ChangeLog
%{crmsh_docdir}/README.md
%{crmsh_docdir}/contrib/*

%config %{_sysconfdir}/crm

%dir %{crmsh_docdir}
%dir %{crmsh_docdir}/contrib
%dir %attr (770, %{uname}, %{gname}) %{_var}/cache/crm
%config %{_sysconfdir}/bash_completion.d/crm.sh

%files scripts
%defattr(-,root,root)
%{_datadir}/%{name}/scripts

%files test
%defattr(-,root,root)
%{_datadir}/%{name}/tests

%changelog
openSUSE Build Service is sponsored by