File openstack-watcher.spec of Package openstack-watcher

#
# spec file for package openstack-watcher
#
# Copyright (c) 2024 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:        12.0.0.0~xrc2~dev3
Release:        0
Epoch:          0
Summary:        Resource optimization service for OpenStack. (Wathcer)
License:        Apache-2.0
Group:          Development/Languages/Python
URL:            https://docs.openstack.org/watcher
Source0:        watcher-master.tar.gz
Source1:        openstack-watcher-applier.service
Source2:        openstack-watcher-decision-engine.service
Source3:        openstack-watcher-api.service
BuildRequires:  openstack-macros
BuildRequires:  python3-APScheduler
BuildRequires:  python3-PrettyTable
BuildRequires:  python3-SQLAlchemy
BuildRequires:  python3-WSME
BuildRequires:  python3-WebOb
BuildRequires:  python3-cinderclient
BuildRequires:  python3-coverage
BuildRequires:  python3-croniter
BuildRequires:  python3-freezegun
BuildRequires:  python3-glanceclient
BuildRequires:  python3-gnocchiclient
BuildRequires:  python3-ironicclient
BuildRequires:  python3-jsonpatch
BuildRequires:  python3-jsonschema
BuildRequires:  python3-keystoneauth1
BuildRequires:  python3-keystoneclient
BuildRequires:  python3-keystonemiddleware
BuildRequires:  python3-lxml
BuildRequires:  python3-microversion_parse
BuildRequires:  python3-monascaclient
BuildRequires:  python3-networkx
BuildRequires:  python3-neutronclient
BuildRequires:  python3-novaclient
BuildRequires:  python3-openstackclient
BuildRequires:  python3-os-api-ref
BuildRequires:  python3-oslo.cache
BuildRequires:  python3-oslo.concurrency
BuildRequires:  python3-oslo.context
BuildRequires:  python3-oslo.db
BuildRequires:  python3-oslo.log
BuildRequires:  python3-oslo.messaging
BuildRequires:  python3-oslo.policy
BuildRequires:  python3-oslo.reports
BuildRequires:  python3-oslo.serialization
BuildRequires:  python3-oslo.service
BuildRequires:  python3-oslo.upgradecheck
BuildRequires:  python3-oslo.utils
BuildRequires:  python3-oslo.versionedobjects
BuildRequires:  python3-oslotest
BuildRequires:  python3-pbr
BuildRequires:  python3-pecan
BuildRequires:  python3-stestr
BuildRequires:  python3-stevedore
BuildRequires:  python3-taskflow
Requires:       python3-watcher = %{epoch}:%{version}-%{release}
BuildArch:      noarch
%if 0%{?suse_version}
BuildRequires:  apache2-mod_wsgi
BuildRequires:  systemd-rpm-macros
Requires:       apache2-mod_wsgi
%{?systemd_requires}
%else
BuildRequires:  python3-mod_wsgi
BuildRequires:  systemd
Requires:       python3-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 python3-watcher
Summary:        Resource optimization service for OpenStack. (Wathcer) - Python Module
Group:          Applications/System
Requires:       python3-APScheduler
Requires:       python3-PasteDeploy
Requires:       python3-PrettyTable
Requires:       python3-SQLAlchemy
Requires:       python3-WSME
Requires:       python3-WebOb
Requires:       python3-cinderclient
Requires:       python3-croniter
Requires:       python3-enum34
Requires:       python3-glanceclient
Requires:       python3-gnocchiclient
Requires:       python3-ironicclient
Requires:       python3-jsonpatch
Requires:       python3-jsonschema
Requires:       python3-keystoneauth1
Requires:       python3-keystoneclient
Requires:       python3-keystonemiddleware
Requires:       python3-lxml
Requires:       python3-microversion_parse
Requires:       python3-monascaclient
Requires:       python3-networkx
Requires:       python3-neutronclient
Requires:       python3-novaclient
Requires:       python3-openstackclient
Requires:       python3-oslo.cache
Requires:       python3-oslo.db
Requires:       python3-oslo.messaging
Requires:       python3-oslo.policy
Requires:       python3-oslo.reports
Requires:       python3-oslo.serialization
Requires:       python3-oslo.service
Requires:       python3-oslo.upgradecheck
Requires:       python3-oslo.versionedobjects
Requires:       python3-pbr
Requires:       python3-pecan
Requires:       python3-six
Requires:       python3-stevedore
Requires:       python3-taskflow
Recommends:     python3-ceilometerclient
BuildArch:      noarch

%description -n python3-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} = %{epoch}:%{version}-%{release}

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

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

%description applier
This package contains the OpenStack Watcher Applier.

%package api
Summary:        OpenStack Watcher - Api
Group:          System/Management
Requires:       %{name} = %{epoch}:%{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:  python3-Sphinx
BuildRequires:  python3-keystoneclient
BuildRequires:  python3-os-api-ref
BuildRequires:  python3-sphinxcontrib-apidoc
BuildRequires:  python3-sphinxcontrib-pecanwsme
BuildRequires:  python3-sphinxcontrib-seqdiag
BuildRequires:  python3-sphinxcontrib-svg2pdfconverter
BuildArch:      noarch

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

This package contains the documentation
%endif

%prep
%autosetup -n python-watcher-12.0.0.0rc2.dev3
%py_req_cleanup

%build
%{py3_build}

%if 0%{?with_doc}
PYTHONPATH=.  PBR_VERSION=12.0.0.0rc2.dev3 %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
%{py3_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-api-wsgi
%{_bindir}/watcher-db-manage
%{_bindir}/watcher-sync
%{_bindir}/watcher-status
%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 python3-watcher
%license LICENSE
%doc AUTHORS README.rst
%{python3_sitelib}/watcher/
%{python3_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
%license LICENSE
%doc doc/build/html
%endif

%changelog
openSUSE Build Service is sponsored by