File openstack-watcher.spec of Package openstack-watcher

#
# spec file for package openstack-watcher
#
# 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 with_doc 1
%if 0%{?rhel} || 0%{?fedora}
%global rdo 1
%endif
%if 0%{?rhel} || 0%{?fedora}
%global wsgi_dir %{_datarootdir}/watcher
%else
%global wsgi_dir /srv/www/watcher
%endif
Name:           openstack-watcher
Version:        1.12.1~dev19
Release:        0
Summary:        Resource optimization service for OpenStack. (Wathcer)
License:        Apache-2.0
Group:          Development/Languages/Python
URL:            https://launchpad.net/watcher
Source0:        watcher-stable-rocky.tar.gz
Source1:        openstack-watcher-applier.service
Source2:        openstack-watcher-decision-engine.service
Source3:        openstack-watcher-api.service
BuildRequires:  openstack-macros
BuildRequires:  python-PrettyTable >= 0.7.2
BuildRequires:  python-microversion_parse
BuildRequires:  python-os-api-ref
BuildRequires:  python2-APScheduler
BuildRequires:  python2-SQLAlchemy >= 1.2.5
BuildRequires:  python2-WSME >= 0.9.2
BuildRequires:  python2-WebOb >= 1.7.4
BuildRequires:  python2-cinderclient
BuildRequires:  python2-coverage
BuildRequires:  python2-croniter >= 0.3.20
BuildRequires:  python2-freezegun
BuildRequires:  python2-glanceclient
BuildRequires:  python2-gnocchiclient >= 7.0.1
BuildRequires:  python2-ironicclient
BuildRequires:  python2-jsonpatch >= 1.21
BuildRequires:  python2-jsonschema >= 2.6.0
BuildRequires:  python2-keystoneauth1 >= 3.4.0
BuildRequires:  python2-keystoneclient
BuildRequires:  python2-keystonemiddleware >= 4.21.0
BuildRequires:  python2-lxml >= 4.1.1
BuildRequires:  python2-mock
BuildRequires:  python2-monascaclient
BuildRequires:  python2-networkx >= 1.11
BuildRequires:  python2-neutronclient
BuildRequires:  python2-novaclient
BuildRequires:  python2-openstackclient
BuildRequires:  python2-oslo.cache >= 1.29.0
BuildRequires:  python2-oslo.concurrency >= 3.26.0
BuildRequires:  python2-oslo.context >= 2.20.0
BuildRequires:  python2-oslo.db >= 4.35.0
BuildRequires:  python2-oslo.messaging >= 5.36.0
BuildRequires:  python2-oslo.policy >= 1.34.0
BuildRequires:  python2-oslo.reports >= 1.27.0
BuildRequires:  python2-oslo.serialization >= 2.25.0
BuildRequires:  python2-oslo.service >= 1.30.0
BuildRequires:  python2-oslo.utils >= 3.36.0
BuildRequires:  python2-oslo.versionedobjects >= 1.32.0
BuildRequires:  python2-oslotest
BuildRequires:  python2-pbr >= 3.1.1
BuildRequires:  python2-pecan >= 1.2.1
BuildRequires:  python2-six >= 1.11.0
BuildRequires:  python2-stestr
BuildRequires:  python2-stevedore >= 1.28.0
BuildRequires:  python2-taskflow >= 3.1.0
Requires:       python-watcher = %{version}-%{release}
BuildArch:      noarch
%if 0%{?suse_version}
BuildRequires:  apache2-mod_wsgi
BuildRequires:  systemd-rpm-macros
Requires:       apache2-mod_wsgi
%{?systemd_requires}
%else
BuildRequires:  mod_wsgi
BuildRequires:  systemd
Requires:       mod_wsgi
Requires(post): systemd
Requires(postun): systemd
Requires(preun): systemd
%endif

%description
OpenStack Watcher provides a flexible and scalable resource optimization
service for multi-tenant OpenStack-based clouds.
Watcher provides a robust framework to realize a wide range of cloud
optimization goals, including the reduction of data center
operating costs, increased system performance via intelligent virtual machine
migration, increased energy efficiency and more!

%package -n     python-watcher
Summary:        Resource optimization service for OpenStack. (Wathcer) - Python Module
Group:          Applications/System
BuildRequires:  fdupes
# NOTE: python2-PrettyTable is not provided on SLES so use python-PrettyTable
Requires:       python-PrettyTable >= 0.7.2
Requires:       python-microversion_parse
Requires:       python2-APScheduler
Requires:       python2-PasteDeploy >= 1.5.2
Requires:       python2-SQLAlchemy >= 1.2.5
Requires:       python2-WSME >= 0.9.2
Requires:       python2-WebOb >= 1.7.4
Requires:       python2-cinderclient >= 3.5.0
Requires:       python2-croniter >= 0.3.20
Requires:       python2-enum34 >= 1.1.6
Requires:       python2-glanceclient >= 2.9.1
Requires:       python2-gnocchiclient >= 7.0.1
Requires:       python2-ironicclient >= 2.3.0
Requires:       python2-jsonpatch >= 1.21
Requires:       python2-jsonschema >= 2.6.0
Requires:       python2-keystoneauth1 >= 3.4.0
Requires:       python2-keystoneclient >= 3.15.0
Requires:       python2-keystonemiddleware >= 4.21.0
Requires:       python2-lxml >= 4.1.1
Requires:       python2-monascaclient >= 1.12.0
Requires:       python2-networkx >= 1.11
Requires:       python2-neutronclient >= 6.7.0
Requires:       python2-novaclient >= 10.1.0
Requires:       python2-openstackclient
Requires:       python2-oslo.cache >= 1.29.0
Requires:       python2-oslo.db >= 4.35.0
Requires:       python2-oslo.messaging >= 5.36.0
Requires:       python2-oslo.policy >= 1.34.0
Requires:       python2-oslo.reports >= 1.27.0
Requires:       python2-oslo.serialization >= 2.25.0
Requires:       python2-oslo.service >= 1.30.0
Requires:       python2-oslo.versionedobjects >= 1.32.0
Requires:       python2-pbr >= 3.1.1
Requires:       python2-pecan >= 1.2.1
Requires:       python2-six >= 1.11.0
Requires:       python2-stevedore >= 1.28.0
Requires:       python2-taskflow >= 3.1.0
BuildArch:      noarch
%if ! 0%{?rhel}
Recommends:     python2-ceilometerclient >= 2.9.0
%endif

%description -n     python-watcher
OpenStack Watcher provides a flexible and scalable resource optimization
service for multi-tenant OpenStack-based clouds.
Watcher provides a robust framework to realize a wide range of cloud
optimization goals, including the reduction of data center
operating costs, increased system performance via intelligent virtual machine
migration, increased energy efficiency and more!

This package contains the Watcher Python library.

%package decision-engine
Summary:        OpenStack Watcher - Decision-Engine
Group:          System/Management
Requires:       %{name} = %{version}-%{release}

%description decision-engine
This package contains the OpenStack Watcher decision-engine.

%package applier
Summary:        OpenStack Watcher - Applier
Group:          System/Management
Requires:       %{name} = %{version}-%{release}

%description applier
This package contains the OpenStack Watcher Applier.

%package api
Summary:        OpenStack Watcher - Api
Group:          System/Management
Requires:       %{name} = %{version}-%{release}

%description api
This package contains the OpenStack Watcher Api.

%if 0%{?with_doc}
%package -n openstack-watcher-doc
Summary:        Documentation for OpenStack Watcher Service
Group:          Documentation/HTML
BuildRequires:  fdupes
BuildRequires:  python-Sphinx
BuildRequires:  python-os-api-ref
BuildRequires:  python-sphinxcontrib-apidoc
BuildRequires:  python-sphinxcontrib-pecanwsme
BuildRequires:  python-sphinxcontrib-seqdiag
BuildArch:      noarch

%description -n openstack-watcher-doc
OpenStack Watcher documentation.

This package contains the documentation
%endif

%prep
%autosetup -n python-watcher-1.12.1.dev19
%py_req_cleanup

%build
%{py2_build}

%if 0%{?with_doc}
PYTHONPATH=.  PBR_VERSION=1.12.1.dev19 sphinx-build -b html doc/source doc/build/html
rm -rf doc/build/html/.{doctrees,buildinfo}
%fdupes doc/build/html/
%endif

# policy/config file generation
PYTHONPATH=. oslo-config-generator --config-file=etc/watcher/oslo-config-generator/watcher.conf \
    --output-file etc/watcher/watcher.conf.sample
PYTHONPATH=. oslopolicy-sample-generator --config-file=etc/watcher/oslo-policy-generator/watcher-policy-generator.conf  \
    --output-file etc/watcher/policy.yaml.sample

sed -e "
    s|%WATCHER_SERVICE_PORT%|9322|g;
    s|%WATCHER_WSGI_DIR%|%{wsgi_dir}|g;
    s|%USER%|%{apache_user}|g;
    s|%APIWORKERS%|2|g;
    s|%APACHE_NAME%|apache2|g;
" -i devstack/files/apache-watcher-api.template

%install
%{py2_install}
%python_expand %fdupes %{buildroot}%{$python_sitelib}

# Install service configuration files
install -d -m 755 %{buildroot}%{_sysconfdir}/watcher
install -d -m 755 %{buildroot}%{_sysconfdir}/watcher/watcher.conf.d

# (re)move install artifacts
mv %{buildroot}%{_prefix}%{_sysconfdir}/watcher/* %{buildroot}%{_sysconfdir}/watcher
rm -r %{buildroot}%{_prefix}%{_sysconfdir}/apache2
rm -r %{buildroot}%{_sysconfdir}/watcher/oslo-{config,policy}-generator/
rm %{buildroot}%{_sysconfdir}/watcher/README-watcher.conf.txt

# Install apache configuration files
install -d -m 755 %{buildroot}%{apache_conf_dir}/
install -p -D -m 644 devstack/files/apache-watcher-api.template %{buildroot}%{apache_conf_dir}/watcher.conf.sample

# Install wsgi file
install -d -m 755 %{buildroot}%{wsgi_dir}
install -p -D -m 644 watcher/api/app.wsgi %{buildroot}%{wsgi_dir}

# Install service file
install -p -D -m 755 %{SOURCE1} %{buildroot}%{_unitdir}/openstack-watcher-applier.service
install -p -D -m 755 %{SOURCE2} %{buildroot}%{_unitdir}/openstack-watcher-decision-engine.service
install -p -D -m 755 %{SOURCE3} %{buildroot}%{_unitdir}/openstack-watcher-api.service

%pre
%openstack_pre_user_group_create watcher watcher /sbin/nologin

%post decision-engine
%systemd_post openstack-watcher-decision-engine.service

%preun decision-engine
%systemd_preun openstack-watcher-decision-engine.service

%postun decision-engine
%systemd_postun_with_restart openstack-watcher-decision-engine.service

%post applier
%systemd_post openstack-watcher-applier.service

%preun applier
%systemd_preun openstack-watcher-applier.service

%postun applier
%systemd_postun_with_restart openstack-watcher-applier.service

%post api
%systemd_post openstack-watcher-api.service

%preun api
%systemd_preun openstack-watcher-api.service

%postun api
%systemd_postun_with_restart openstack-watcher-api.service

%files
%{_bindir}/watcher-db-manage
%{_bindir}/watcher-sync
%dir %attr(0770, root, %{apache_group}) %{wsgi_dir}
%attr(0770, root, %{apache_group}) %{wsgi_dir}/app.wsgi
%attr(0770, root, %{apache_group}) %{apache_conf_dir}/watcher.conf.sample
%dir %config(noreplace) %attr(0750, root, watcher) %{_sysconfdir}/watcher
%config(noreplace) %attr(0640, root, watcher) %{_sysconfdir}/watcher/policy.yaml.sample
%config(noreplace) %attr(0640, root, watcher) %{_sysconfdir}/watcher/watcher.conf.sample
%dir %attr(0750, root, watcher) %{_sysconfdir}/watcher/watcher.conf.d/

%files -n python-watcher
%defattr(-,root,root,-)
%license LICENSE
%doc AUTHORS README.rst
%{python2_sitelib}/watcher/
%{python2_sitelib}/python_watcher-*.egg-info

%files decision-engine
%defattr(-,root,root,-)
%{_bindir}/watcher-decision-engine
%{_unitdir}/openstack-watcher-decision-engine.service

%files applier
%defattr(-,root,root,-)
%{_bindir}/watcher-applier
%{_unitdir}/openstack-watcher-applier.service

%files api
%defattr(-,root,root,-)
%{_bindir}/watcher-api
%{_unitdir}/openstack-watcher-api.service

%if 0%{?with_doc}
%files -n openstack-watcher-doc
%defattr(-,root,root,-)
%license LICENSE
%doc doc/build/html
%endif

%changelog
openSUSE Build Service is sponsored by