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

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


%global sname monasca-agent
%define username            monasca-agent
%define groupname           monasca
%if 0%{?rhel} || 0%{?fedora}
%global rdo 1
%endif
Name:           openstack-monasca-agent
Version:        2.8.1~dev10
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-rocky.tar.gz
Source1:        %{name}-sudoers
Source2:        %{name}.target
Source3:        %{name}.tmpfiles
Source4:        %{name}.polkit
Source5:        %{name}-collector.service
Source6:        %{name}-forwarder.service
Source7:        %{name}-statsd.service
BuildRequires:  fdupes
BuildRequires:  openstack-macros
BuildRequires:  python-PyYAML >= 3.10
BuildRequires:  python-devel
BuildRequires:  python-eventlet >= 0.18.2
BuildRequires:  python-futures >= 3.0.0
BuildRequires:  python-httplib2 >= 0.9.1
BuildRequires:  python-mock
BuildRequires:  python-monasca-common >= 2.7.0
BuildRequires:  python-monascaclient >= 1.7.0
BuildRequires:  python-netaddr >= 0.7.18
BuildRequires:  python-ntplib >= 0.3.2
BuildRequires:  python-os-testr
BuildRequires:  python-oslo.concurrency >= 3.25.0
BuildRequires:  python-oslo.config >= 5.2.0
BuildRequires:  python-oslo.i18n >= 3.15.3
BuildRequires:  python-oslo.middleware
BuildRequires:  python-oslo.utils >= 3.33.0
BuildRequires:  python-oslo.vmware >= 2.17.0
BuildRequires:  python-oslotest
BuildRequires:  python-psutil >= 3.2.2
BuildRequires:  python-pymongo >= 3.0.2
BuildRequires:  python-python-memcached >= 1.56
BuildRequires:  python-redis >= 2.10.0
BuildRequires:  python-requests >= 2.14.2
BuildRequires:  python-stevedore >= 1.20.0
BuildRequires:  python-testrepository
BuildRequires:  python-tornado >= 4.5.3
BuildRequires:  sudo
Requires:       python-%{sname} = %{version}-%{release}
BuildArch:      noarch
%if 0%{?suse_version}
BuildRequires:  systemd-rpm-macros
%{?systemd_requires}
%else
BuildRequires:  systemd
Requires(post): systemd
Requires(postun):   systemd
Requires(preun):    systemd
%endif

%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.10
Requires:       python-eventlet >= 0.18.2
Requires:       python-futures >= 3.0.0
Requires:       python-httplib2 >= 0.9.1
Requires:       python-keystoneclient >= 3.8.0
Requires:       python-monasca-common >= 2.7.0
Requires:       python-monascaclient >= 1.7.0
Requires:       python-netaddr >= 0.7.18
Requires:       python-neutronclient
Requires:       python-novaclient
Requires:       python-ntplib >= 0.3.2
Requires:       python-oslo.concurrency >= 3.25.0
Requires:       python-oslo.config >= 5.2.0
Requires:       python-oslo.i18n >= 3.15.3
Requires:       python-oslo.utils >= 3.33.0
Requires:       python-oslo.vmware >= 2.17.0
Requires:       python-psutil >= 3.2.2
Requires:       python-pymongo >= 3.0.2
Requires:       python-python-memcached >= 1.56
Requires:       python-redis >= 2.10.0
Requires:       python-requests >= 2.14.2
Requires:       python-stevedore >= 1.20.0
# FIXME(jpena): Remove this conditional once python-toml is available in RDO
%if 0%{?rdo}
Requires:       python-tornado >= 4.5.3
%else
Requires:       python-toml
Requires:       python-tornado >= 4.5.3
%endif

%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 -n %{sname}-2.8.1.dev10
%py_req_cleanup
# contains various binary files etc that we don't need
rm -rf packaging/monasca-agent{,-deb}

%build
%py2_build

%install
%py2_install

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

# /usr/lib
install -d -m 750 %{buildroot}%{_prefix}/lib/monasca/agent/custom_checks.d
install -d -m 750 %{buildroot}%{_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}.target
install -D -m 644 %{SOURCE5} %{buildroot}%{_unitdir}/%{name}-collector.service
install -D -m 644 %{SOURCE6} %{buildroot}%{_unitdir}/%{name}-forwarder.service
install -D -m 644 %{SOURCE7} %{buildroot}%{_unitdir}/%{name}-statsd.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}.target
%systemd_post %{name}-collector.service
%systemd_post %{name}-forwarder.service
%systemd_post %{name}-statsd.service

%preun
%systemd_preun %{name}.target
%systemd_preun %{name}-collector.service
%systemd_preun %{name}-forwarder.service
%systemd_preun %{name}-statsd.service

%postun
%systemd_postun %{name}.target
%systemd_postun %{name}-collector.service
%systemd_postun %{name}-forwarder.service
%systemd_postun %{name}-statsd.service

%check
find . -type f -name *.pyc -delete
find . -type f -name '*test_service_plugin.py' -delete
python setup.py test

%files
%dir %attr(-, root, monasca) %{_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
%config %{_sysconfdir}/monasca/agent
%config %{_sysconfdir}/sudoers.d/%{name}
%dir %{_prefix}/lib/monasca
%{_prefix}/lib/monasca/agent
%dir %attr(0750, %{username}, %{groupname}) %{_localstatedir}/log/%{sname}
%{_unitdir}/%{name}.target
%{_unitdir}/%{name}-collector.service
%{_unitdir}/%{name}-forwarder.service
%{_unitdir}/%{name}-statsd.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.rst
%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