File openstack-monasca-agent.spec of Package openstack-monasca-agent

#
# spec file for package openstack-monasca-agent
#
# Copyright (c) 2020 SUSE LLC
#
# 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 https://bugs.opensuse.org/
#


%global sname monasca-agent

%define username            monasca-agent
%define groupname           monasca

Name:           openstack-monasca-agent
Version:        1.10.1~dev4
Release:        0
Summary:        OpenStack Monasca metrics agent
License:        Apache-2.0
Group:          Development/Languages/Python
URL:            https://wiki.openstack.org/wiki/Monasca
Source0:        monasca-agent-stable-ocata.tar.gz
Source1:        %{name}-sudoers
Source2:        %{name}.service
Source3:        %{name}.tmpfiles
Source4:        %{name}.polkit
BuildRequires:  fdupes
BuildRequires:  openstack-macros

%if 0%{?suse_version}
BuildRequires:  systemd-rpm-macros
Requires(pre):  pwdutils
%{?systemd_requires}
%else
BuildRequires:  systemd
Requires(post): systemd
Requires(preun):    systemd
Requires(pre):  shadow-utils
Requires(postun):   systemd
%endif

BuildRequires:  python-PyYAML >= 3.1.0
BuildRequires:  python-devel
BuildRequires:  python-gevent
BuildRequires:  python-httplib2 >= 0.7.5
BuildRequires:  python-mock >= 2.0
BuildRequires:  python-monascaclient >= 1.1.0
BuildRequires:  python-netaddr >= 0.7.13
BuildRequires:  python-nose
BuildRequires:  python-ntplib
BuildRequires:  python-oslo.concurrency >= 3.8.0
BuildRequires:  python-oslo.config >= 3.14.0
BuildRequires:  python-oslo.i18n >= 2.1.0
BuildRequires:  python-oslo.middleware >= 3.0.0
BuildRequires:  python-oslo.utils >= 3.16.0
BuildRequires:  python-oslo.vmware >= 2.11.0
BuildRequires:  python-oslotest >= 1.10.0
BuildRequires:  python-psutil >= 1.1.1
BuildRequires:  python-pymongo >= 3.0.2
BuildRequires:  python-python-memcached >= 1.56
BuildRequires:  python-redis >= 2.10.0
BuildRequires:  python-requests >= 2.10.0
BuildRequires:  python-stevedore >= 1.16.0
BuildRequires:  python-supervisor
BuildRequires:  python-tornado
BuildRequires:  sudo
Requires:       python-%{sname} = %{version}-%{release}
BuildArch:      noarch
# These patches cannot be merged into monasca-agent's stable/ocata upstream
# branch: only bug and security fixes are accepted into stable/ocata at this
# stage, so adding them here:
Patch1:         ceph-plugin.patch
Patch2:         ceph-use-sudo.patch
Patch3:         libvirt-aggregate-status.patch

%description
The Monasca Agent is a modern Python monitoring agent for gathering metrics and
sending them to the Monasca API.

%package -n python-%{sname}
Summary:        Python module for monasca-agent
Group:          Development/Languages/Python
Requires:       python-PyYAML >= 3.1.0
Requires:       python-gevent
Requires:       python-httplib2 >= 0.7.5
Requires:       python-monascaclient >= 1.1.0
Requires:       python-netaddr >= 0.7.13
Requires:       python-ntplib
Requires:       python-oslo.concurrency >= 3.8.0
Requires:       python-oslo.config >= 3.14.0
Requires:       python-oslo.i18n >= 2.1.0
Requires:       python-oslo.middleware >= 3.0.0
Requires:       python-oslo.utils >= 3.16.0
Requires:       python-oslo.vmware >= 2.11.0
Requires:       python-psutil >= 1.1.1
Requires:       python-pymongo >= 3.0.2
Requires:       python-python-memcached >= 1.56
Requires:       python-redis >= 2.10.0
Requires:       python-requests >= 2.10.0
Requires:       python-stevedore >= 1.16.0
Requires:       python-supervisor
Requires:       python-tornado

%description -n python-%{sname}
The Monasca Agent is a modern Python monitoring agent for gathering metrics and
sending them to the Monasca API.

This package contains monasca-agent Python module.

%prep
%autosetup -p1 -n %{sname}-1.10.1.dev4
%py_req_cleanup
# contains various binary files etc that we don't need
rm -rf packaging/monasca-agent{,-deb}

%build
# Super hack: in a Newton env, make it Newton compatible
if rpm -q --qf "%{VERSION}\n" python-oslo.utils | grep -q 3.16; then
    sed -i -e "s,oslo.utils>=3.18.0,oslo.utils>=3.16.0," requirements.txt
fi
%py2_build

%install
%py2_install

# /etc
%{__install} -d -m 750 %{buildroot}%{_sysconfdir}/monasca/agent/conf.d

# /usr/lib
%{__install} -d -m 750 %{buildroot}%{_exec_prefix}/lib/monasca/agent/custom_checks.d
%{__install} -d -m 750 %{buildroot}%{_exec_prefix}/lib/monasca/agent/custom_detect.d

# /var
install -d -m 750  %{buildroot}%{_localstatedir}/log/%{sname}

# sudoers configuration
%{__install} -D -m 440 %{SOURCE1} %{buildroot}%{_sysconfdir}/sudoers.d/%{name}

# systemd unit file
install -D -m 644 %{SOURCE2} %{buildroot}%{_unitdir}/%{name}.service
%if 0%{?suse_version}
mkdir -p %{buildroot}%{_sbindir}
ln -sr %{buildroot}%{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}
%endif

# systemd tmpfile
install -D -m 644 %{SOURCE3} %{buildroot}%{_tmpfilesdir}/openstack-monasca-agent.conf

# polkit permissions
install -D -m 644 %{SOURCE4} %{buildroot}%{_sysconfdir}/polkit-1/rules.d/49-monasca-agent.rules

%fdupes %{buildroot}%{python2_sitelib}

%pre
# create user and groups
%openstack_pre_user_group_create %{username} %{groupname}

%post
%tmpfiles_create %{_tmpfilesdir}/openstack-monasca-agent.conf
%systemd_post %{name}.service

%preun
%systemd_preun %{name}.service

%postun
%systemd_postun %{name}.service

%check
find . -type f -name *.pyc -delete
rm -f tests/checks_d/test_ceph.py # Ceph tests depend on test environment from Pike and later

PYTHONPATH=. NOSE_EXCLUDE=test_override_values nosetests tests -v

%files
%dir %{_sysconfdir}/monasca
%dir %attr(0750, %{username}, %{groupname}) %{_sysconfdir}/monasca/agent
%dir %attr(0750, %{username}, %{groupname}) %{_sysconfdir}/monasca/agent/conf.d
%_tmpfilesdir/openstack-monasca-agent.conf
%dir %{_tmpfilesdir}
%config %{_sysconfdir}/monasca/agent
%config %{_sysconfdir}/sudoers.d/%{name}
%dir %{_exec_prefix}/lib/monasca
%{_exec_prefix}/lib/monasca/agent
%dir %attr(0750, %{username}, %{groupname}) %{_localstatedir}/log/%{sname}
%{_unitdir}/%{name}.service
%if 0%{?suse_version}
%{_sbindir}/rc%{name}
%endif
%{_sysconfdir}/polkit-1/
%{_sysconfdir}/polkit-1/rules.d/
%{_sysconfdir}/polkit-1/rules.d/49-monasca-agent.rules

%files -n python-%{sname}
%doc README.md
%license LICENSE
%{_bindir}/monasca-collector
%{_bindir}/monasca-forwarder
%{_bindir}/monasca-setup
%{_bindir}/monasca-statsd
%{python2_sitelib}/monasca_agent
%{python2_sitelib}/monasca_agent-*.egg-info
%{python2_sitelib}/monasca_setup
%dir %{_datadir}/monasca
%{_datadir}/monasca/agent

%changelog
openSUSE Build Service is sponsored by