File openstack-watcher.spec of Package openstack-watcher

#
# spec file for package openstack-watcher
#
# 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 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.2~dev2
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
BuildRequires:  python-microversion_parse
BuildRequires:  python-os-api-ref
BuildRequires:  python2-APScheduler
BuildRequires:  python2-SQLAlchemy
BuildRequires:  python2-WSME
BuildRequires:  python2-WebOb
BuildRequires:  python2-cinderclient
BuildRequires:  python2-coverage
BuildRequires:  python2-croniter
BuildRequires:  python2-freezegun
BuildRequires:  python2-glanceclient
BuildRequires:  python2-gnocchiclient
BuildRequires:  python2-ironicclient
BuildRequires:  python2-jsonpatch
BuildRequires:  python2-jsonschema
BuildRequires:  python2-keystoneauth1
BuildRequires:  python2-keystoneclient
BuildRequires:  python2-keystonemiddleware
BuildRequires:  python2-lxml
BuildRequires:  python2-mock
BuildRequires:  python2-monascaclient
BuildRequires:  python2-networkx
BuildRequires:  python2-neutronclient
BuildRequires:  python2-novaclient
BuildRequires:  python2-openstackclient
BuildRequires:  python2-oslo.cache
BuildRequires:  python2-oslo.concurrency
BuildRequires:  python2-oslo.context
BuildRequires:  python2-oslo.db
BuildRequires:  python2-oslo.messaging
BuildRequires:  python2-oslo.policy
BuildRequires:  python2-oslo.reports
BuildRequires:  python2-oslo.serialization
BuildRequires:  python2-oslo.service
BuildRequires:  python2-oslo.utils
BuildRequires:  python2-oslo.versionedobjects
BuildRequires:  python2-oslotest
BuildRequires:  python2-pbr
BuildRequires:  python2-pecan
BuildRequires:  python2-six
BuildRequires:  python2-stestr
BuildRequires:  python2-stevedore
BuildRequires:  python2-taskflow
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
Requires:       python-microversion_parse
Requires:       python2-APScheduler
Requires:       python2-PasteDeploy
Requires:       python2-SQLAlchemy
Requires:       python2-WSME
Requires:       python2-WebOb
Requires:       python2-cinderclient
Requires:       python2-croniter
Requires:       python2-enum34
Requires:       python2-glanceclient
Requires:       python2-gnocchiclient
Requires:       python2-ironicclient
Requires:       python2-jsonpatch
Requires:       python2-jsonschema
Requires:       python2-keystoneauth1
Requires:       python2-keystoneclient
Requires:       python2-keystonemiddleware
Requires:       python2-lxml
Requires:       python2-monascaclient
Requires:       python2-networkx
Requires:       python2-neutronclient
Requires:       python2-novaclient
Requires:       python2-openstackclient
Requires:       python2-oslo.cache
Requires:       python2-oslo.db
Requires:       python2-oslo.messaging
Requires:       python2-oslo.policy
Requires:       python2-oslo.reports
Requires:       python2-oslo.serialization
Requires:       python2-oslo.service
Requires:       python2-oslo.versionedobjects
Requires:       python2-pbr
Requires:       python2-pecan
Requires:       python2-six
Requires:       python2-stevedore
Requires:       python2-taskflow
BuildArch:      noarch
%if ! 0%{?rhel}
Recommends:     python2-ceilometerclient
%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.2.dev2
%py_req_cleanup

%build
%{py2_build}

%if 0%{?with_doc}
PYTHONPATH=.  PBR_VERSION=1.12.2.dev2 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