%{!?upstream_version: %global upstream_version %{version}%{?milestone}}
%global with_doc %{!?_without_doc:0}%{?_without_doc:1}
%global service cinder

%global common_desc \
OpenStack Volume (codename Cinder) provides services to manage and \
access block storage volumes for use by Virtual Machine instances.

Name:             openstack-%{service}
Version:          17.0.0
Release:          4
Summary:          OpenStack Volume service

License:          Apache-2.0
URL:              http://www.openstack.org/software/openstack-storage/
Source0:          https://tarballs.openstack.org/%{service}/%{service}-%{upstream_version}.tar.gz


Source1:          %{service}-dist.conf
Source2:          %{service}.logrotate

Source10:         openstack-%{service}-api.service
Source11:         openstack-%{service}-scheduler.service
Source12:         openstack-%{service}-volume.service
Source13:         openstack-%{service}-backup.service
Source20:         %{service}-sudoers


BuildArch:        noarch

BuildRequires:    intltool
BuildRequires:    python3-pbr
BuildRequires:    python3-reno
BuildRequires:    python3-devel
BuildRequires:    python3-setuptools
BuildRequires:    python3-netaddr
BuildRequires:    systemd
BuildRequires:    python3-os-brick
BuildRequires:    python3-pyparsing
BuildRequires:    python3-pytz
BuildRequires:    openstack-macros
BuildRequires:    python3-cursive
BuildRequires:    python3-google-api-client >= 1.4.2
BuildRequires:    python3-keystonemiddleware
BuildRequires:    python3-glanceclient >= 2.15.0
BuildRequires:    python3-novaclient >= 9.1.0
BuildRequires:    python3-swiftclient >= 3.2.0
BuildRequires:    python3-oslo-db
BuildRequires:    python3-oslo-config
BuildRequires:    python3-oslo-policy
BuildRequires:    python3-oslo-privsep
BuildRequires:    python3-oslo-reports
BuildRequires:    python3-oslotest
BuildRequires:    python3-oslo-utils
BuildRequires:    python3-oslo-versionedobjects
BuildRequires:    python3-oslo-vmware
BuildRequires:    python3-os-win
BuildRequires:    python3-castellan
BuildRequires:    python3-cryptography
BuildRequires:    python3-osprofiler
BuildRequires:    python3-paramiko
BuildRequires:    python3-suds
BuildRequires:    python3-taskflow
BuildRequires:    python3-tooz
BuildRequires:    python3-oslo-log
BuildRequires:    python3-oslo-i18n
BuildRequires:    python3-barbicanclient
BuildRequires:    python3-requests
BuildRequires:    python3-defusedxml
BuildRequires:    python3-pip

BuildRequires:    python3-babel

BuildRequires:    python3-ddt
BuildRequires:    python3-fixtures
BuildRequires:    python3-mock
BuildRequires:    python3-oslotest
BuildRequires:    python3-packaging
BuildRequires:    python3-subunit
BuildRequires:    python3-testtools
BuildRequires:    python3-testrepository
BuildRequires:    python3-testresources
BuildRequires:    python3-testscenarios
BuildRequires:    python3-os-testr
BuildRequires:    python3-tabulate

BuildRequires:    python3-decorator
BuildRequires:    python3-lxml
BuildRequires:    python3-rtslib
BuildRequires:    python3-tenacity


Requires:         python3-%{service} = %{version}-%{release}

Requires:         python3-pbr

Requires:         python3-cinderclient

Requires(pre):    shadow-utils

Requires:         python3-osprofiler

Requires:         python3-pyudev

%description
%{common_desc}


%package -n       python3-%{service}
Summary:          OpenStack Volume Python libraries
%{?python_provide:%python_provide python3-%{service}}
Group:            Applications/System

Requires:         python3-%{service}-common = %{version}-%{release}

Requires:         cryptsetup
Requires:         cracklib-dicts
Requires:         qemu-img >= 2.10.0
Requires:         python3-jsonschema >= 2.6.0

Requires:         python3-castellan >= 1.3.0
Requires:         python3-cursive >= 0.2.1
Requires:         python3-etcd3gw

Requires:         python3-routes >= 2.3.1
Requires:         python3-webob >= 1.7.1

Requires:         python3-barbicanclient >= 4.9.0
Requires:         python3-glanceclient >= 2.15.0
Requires:         python3-keystoneclient >= 3.15.0
Requires:         python3-novaclient >= 9.1.0
Requires:         python3-swiftclient >= 3.2.0

Requires:         python3-google-api-client >= 1.4.2

Requires:         python3-keystonemiddleware >= 4.21.0
Requires:         python3-keystoneauth1 >= 3.14.0
Requires:         python3-osprofiler >= 1.4.0

Requires:         python3-os-win >= 4.2.0

Requires:         python3-oslo-middleware >= 3.31.0
Requires:         python3-oslo-messaging >= 6.4.0
Requires:         python3-oslo-policy >= 1.44.1
Requires:         python3-oslo-reports >= 1.18.0
Requires:         python3-oslo-upgradecheck >= 0.1.0
Requires:         python3-oslo-vmware >= 2.35.0

Requires:         python3-oauth2client >= 1.5.0
Requires:         python3-packaging
Requires:         python3-paste
Requires:         python3-paste-deploy

%description -n   python3-%{service}
%{common_desc}

This package contains the %{service} Python library.

%package -n python3-%{service}-common
Summary:        Cinder common code
%{?python_provide:%python_provide python3-%{service}-common}

Requires:         sudo

Requires:         sysfsutils
Requires:         python3-paramiko >= 2.7.1

Requires:         python3-eventlet >= 0.25.0
Requires:         python3-greenlet >= 0.4.13
Requires:         python3-iso8601 
Requires:         python3-stevedore >= 1.31.0
Requires:         python3-tooz >= 1.58.0

Requires:         python3-sqlalchemy

Requires:         python3-six >= 1.11.0
Requires:         python3-psutil >= 3.2.2

Requires:         python3-os-brick >= 4.0.1
Requires:         python3-oslo-config 
Requires:         python3-oslo-concurrency >= 3.26.0
Requires:         python3-oslo-context >= 2.23.0
Requires:         python3-oslo-db >= 6.0.0
Requires:         python3-oslo-i18n >= 3.24.0
Requires:         python3-oslo-log >= 3.44.0
Requires:         python3-oslo-privsep >= 2.3.0
Requires:         python3-oslo-rootwrap >= 5.8.0
Requires:         python3-oslo-serialization >= 2.25.0
Requires:         python3-oslo-service >= 2.0.0
Requires:         python3-oslo-utils >= 3.40.2
Requires:         python3-oslo-versionedobjects >= 1.31.2
Requires:         python3-zstd >= 1.4.5
Requires:         python3-importlib_metadata

Requires:         python3-taskflow >= 3.8.0

Requires:         iscsi-initiator-utils

Requires:         python3-requests >= 2.18.0
Requires:         python3-pyparsing >= 2.2.1
Requires:         python3-pytz
Requires:         python3-tabulate >= 0.8.5

Requires:         python3-cryptography >= 2.1.4


Requires:         python3-lxml >= 4.2.0
Requires:         python3-sqlalchemy-migrate >= 0.13.0
Requires:         python3-httplib2 >= 0.9.1
Requires:         python3-tenacity
Requires:         python3-decorator

Requires:         lvm2
Requires:         python3-rtslib


%description -n   python3-%{service}-common
Common code for Cinder.

%package -n python3-%{service}-tests
Summary:        Cinder tests
%{?python_provide:%python_provide python3-%{service}-tests}
Requires:       openstack-%{service} = %{version}-%{release}

Requires:       python3-hacking
Requires:       python3-ddt
Requires:       python3-fixtures
Requires:       python3-mock
Requires:       python3-oslotest
Requires:       python3-subunit
Requires:       python3-testtools
Requires:       python3-testrepository
Requires:       python3-testresources
Requires:       python3-testscenarios
Requires:       python3-stestr


%description -n python3-%{service}-tests
%{common_desc}

This package contains the Cinder test files.

%if 0%{?with_doc}
%package doc
Summary:          Documentation for OpenStack Volume
Group:            Documentation

Requires:         %{name} = %{version}-%{release}

BuildRequires:    graphviz
BuildRequires:    python3-sphinx
BuildRequires:    python3-openstackdocstheme
BuildRequires:    python3-sphinxcontrib-apidoc
BuildRequires:    python3-sphinx-feature-classification
BuildRequires:    python3-eventlet
BuildRequires:    python3-routes
BuildRequires:    python3-sqlalchemy
BuildRequires:    python3-webob
BuildRequires:    python3-iso8601 >= 0.1.9

BuildRequires:    python3-sqlalchemy-migrate

%description      doc
%{common_desc}

This package contains documentation files for %{service}.
%endif

%prep
%autosetup -n %{service}-%{upstream_version} -p1

find . \( -name .gitignore -o -name .placeholder \) -delete

find %{service} -name \*.py -exec sed -i '/\/usr\/bin\/env python/{d;q}' {} +
sed -i 's/\/usr\/bin\/env python/\/usr\/bin\/env python3/' tools/generate_driver_list.py

sed -i 's/%{version}.%{milestone}/%{version}/' PKG-INFO

%py_req_cleanup

%build
PYTHONPATH=. oslo-config-generator --config-file=tools/config/%{service}-config-generator.conf

%{py3_build}

%{__python3} setup.py compile_catalog -d build/lib/%{service}/locale -D cinder

%install
%{py3_install}

export PYTHONPATH="$( pwd ):$PYTHONPATH"

%if 0%{?with_doc}
sphinx-build -b html doc/source doc/build/html
rm -fr doc/build/html/.{doctrees,buildinfo}
sphinx-build -b man doc/source doc/build/man
mkdir -p %{buildroot}%{_mandir}/man1
install -p -D -m 644 doc/build/man/*.1 %{buildroot}%{_mandir}/man1/
%endif


install -d -m 755 %{buildroot}%{_sharedstatedir}/%{service}
install -d -m 755 %{buildroot}%{_sharedstatedir}/%{service}/tmp
install -d -m 755 %{buildroot}%{_localstatedir}/log/%{service}

install -d -m 755 %{buildroot}%{_sysconfdir}/%{service}
install -p -D -m 640 %{SOURCE1} %{buildroot}%{_datadir}/%{service}/%{service}-dist.conf
install -d -m 755 %{buildroot}%{_sysconfdir}/%{service}/volumes
install -p -D -m 640 etc/%{service}/rootwrap.conf %{buildroot}%{_sysconfdir}/%{service}/rootwrap.conf
install -p -D -m 640 etc/%{service}/api-paste.ini %{buildroot}%{_sysconfdir}/%{service}/api-paste.ini
install -p -D -m 640 etc/%{service}/resource_filters.json %{buildroot}%{_sysconfdir}/%{service}/resource_filters.json
install -p -D -m 640 etc/%{service}/%{service}.conf.sample %{buildroot}%{_sysconfdir}/%{service}/%{service}.conf

install -p -D -m 644 %{SOURCE10} %{buildroot}%{_unitdir}/openstack-%{service}-api.service
install -p -D -m 644 %{SOURCE11} %{buildroot}%{_unitdir}/openstack-%{service}-scheduler.service
install -p -D -m 644 %{SOURCE12} %{buildroot}%{_unitdir}/openstack-%{service}-volume.service
install -p -D -m 644 %{SOURCE13} %{buildroot}%{_unitdir}/openstack-%{service}-backup.service

install -p -D -m 440 %{SOURCE20} %{buildroot}%{_sysconfdir}/sudoers.d/%{service}

install -p -D -m 644 %{SOURCE2} %{buildroot}%{_sysconfdir}/logrotate.d/openstack-%{service}

install -d -m 755 %{buildroot}%{_localstatedir}/run/%{service}

mkdir -p %{buildroot}%{_datarootdir}/%{service}/rootwrap/
install -p -D -m 644 etc/%{service}/rootwrap.d/* %{buildroot}%{_datarootdir}/%{service}/rootwrap/


mkdir -p %{buildroot}%{_sysconfdir}/%{service}/rootwrap.d
for filter in %{_datarootdir}/os-brick/rootwrap/*.filters; do
ln -s $filter %{buildroot}%{_sysconfdir}/%{service}/rootwrap.d/
done

install -d -m 755 %{buildroot}%{_datadir}
rm -f %{buildroot}%{python3_sitelib}/%{service}/locale/*/LC_*/%{service}*po
rm -f %{buildroot}%{python3_sitelib}/%{service}/locale/*pot
mv %{buildroot}%{python3_sitelib}/%{service}/locale %{buildroot}%{_datadir}/locale

%find_lang %{service} --all-name

rm -f %{buildroot}/usr/share/doc/%{service}/README*

rm -rf %{buildroot}%{_prefix}/etc

%if 0%{!?dlrn}
%check
OS_TEST_PATH=./%{service}/tests/unit ostestr --concurrency=2
%endif

%pre
getent group %{service} >/dev/null || groupadd -r %{service} --gid 165
if ! getent passwd %{service} >/dev/null; then
  useradd -u 165 -r -g %{service} -G %{service},nobody -d %{_sharedstatedir}/%{service} -s /sbin/nologin -c "OpenStack Cinder Daemons" %{service}
fi
exit 0

%post
%systemd_post openstack-%{service}-volume
%systemd_post openstack-%{service}-api
%systemd_post openstack-%{service}-scheduler
%systemd_post openstack-%{service}-backup

%preun
%systemd_preun openstack-%{service}-volume
%systemd_preun openstack-%{service}-api
%systemd_preun openstack-%{service}-scheduler
%systemd_preun openstack-%{service}-backup

%postun
%systemd_postun_with_restart openstack-%{service}-volume
%systemd_postun_with_restart openstack-%{service}-api
%systemd_postun_with_restart openstack-%{service}-scheduler
%systemd_postun_with_restart openstack-%{service}-backup

%files
%dir %{_sysconfdir}/%{service}
%config(noreplace) %attr(-, root, %{service}) %{_sysconfdir}/%{service}/%{service}.conf
%config(noreplace) %attr(-, root, %{service}) %{_sysconfdir}/%{service}/api-paste.ini
%config(noreplace) %attr(-, root, %{service}) %{_sysconfdir}/%{service}/rootwrap.conf
%config(noreplace) %attr(-, root, %{service}) %{_sysconfdir}/%{service}/resource_filters.json
%config(noreplace) %{_sysconfdir}/logrotate.d/openstack-%{service}
%config(noreplace) %{_sysconfdir}/sudoers.d/%{service}
%{_sysconfdir}/%{service}/rootwrap.d/
%attr(-, root, %{service}) %{_datadir}/%{service}/%{service}-dist.conf

%dir %attr(0750, %{service}, root) %{_localstatedir}/log/%{service}
%dir %attr(0755, %{service}, root) %{_localstatedir}/run/%{service}
%dir %attr(0755, %{service}, root) %{_sysconfdir}/%{service}/volumes

%exclude %{_bindir}/%{service}-rtstool
%{_bindir}/%{service}-*
%{_unitdir}/*.service
%{_datarootdir}/%{service}
%if 0%{?with_doc}
%{_mandir}/man1/%{service}*.1.gz
%endif

%defattr(-, %{service}, %{service}, -)
%dir %{_sharedstatedir}/%{service}
%dir %{_sharedstatedir}/%{service}/tmp

%files -n python3-%{service}

%files -n python3-%{service}-common -f %{service}.lang
%license LICENSE
%{python3_sitelib}/%{service}
%{python3_sitelib}/%{service}-*.egg-info
%{_bindir}/%{service}-rtstool
%exclude %{python3_sitelib}/%{service}/tests

%files -n python3-%{service}-tests
%license LICENSE
%{python3_sitelib}/%{service}/tests

%if 0%{?with_doc}
%files doc
%doc doc/build/html
%endif

%changelog
* Fri Aug 06 2021 wangxiyuan <wangxiyuan1007@gmail.com> - 17.0.0-4
- Remove epoch tag

* Fri Jul 30 2021 chenyanpanHW <chenyanpan@huawei.com> - 17.0.0-3
- DESC: delete -S git from %autosetup, and delete BuildRequires git-core

* Sat Feb 20 2021 yaozc701 <yaozc7@foxmail.com>
- update spec file python3-migrate —> python3-sqlalchemy-migrate

* Tue Feb 02 2021 yaozc701 <yaozc7@foxmail.com>
- update spec file
