%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:          15.6.0
Release:          1
Summary:          OpenStack Volume service
License:          ASL 2.0
URL:              http://www.openstack.org/software/openstack-storage/
BuildArch:        noarch

Source0:          https://tarballs.openstack.org/cinder/cinder-15.6.0.tar.gz

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

Source20:         %{service}-sudoers
Source21:         %{service}.logrotate

BuildRequires:         openstack-macros
BuildRequires:         python3-os-win
BuildRequires:         python3-pbr
BuildRequires:         python3-jsonschema
BuildRequires:         python3-castellan
BuildRequires:         python3-cursive
BuildRequires:         python3-routes
BuildRequires:         python3-webob
BuildRequires:         python3-barbicanclient
BuildRequires:         python3-glanceclient
BuildRequires:         python3-keystoneclient
BuildRequires:         python3-novaclient
BuildRequires:         python3-swiftclient
BuildRequires:         python3-google-api-client
BuildRequires:         python3-keystonemiddleware
BuildRequires:         python3-keystoneauth1
BuildRequires:         python3-osprofiler
BuildRequires:         python3-oslo-middleware
BuildRequires:         python3-oslo-messaging
BuildRequires:         python3-oslo-policy
BuildRequires:         python3-oslo-reports
BuildRequires:         python3-oslo-vmware
BuildRequires:         python3-oauth2client
BuildRequires:         python3-packaging
BuildRequires:         python3-paste
BuildRequires:         python3-paste-deploy
BuildRequires:         python3-paramiko
BuildRequires:         python3-eventlet
BuildRequires:         python3-greenlet
BuildRequires:         python3-iso8601
BuildRequires:         python3-stevedore
BuildRequires:         python3-tooz
BuildRequires:         python3-sqlalchemy
BuildRequires:         python3-six
BuildRequires:         python3-psutil
BuildRequires:         python3-os-brick
BuildRequires:         python3-oslo-config
BuildRequires:         python3-oslo-concurrency
BuildRequires:         python3-oslo-context
BuildRequires:         python3-oslo-db
BuildRequires:         python3-oslo-i18n
BuildRequires:         python3-oslo-log
BuildRequires:         python3-oslo-privsep
BuildRequires:         python3-oslo-rootwrap
BuildRequires:         python3-oslo-serialization
BuildRequires:         python3-oslo-service
BuildRequires:         python3-oslo-utils
BuildRequires:         python3-oslo-versionedobjects
BuildRequires:         python3-oslo-upgradecheck
BuildRequires:         python3-taskflow
BuildRequires:         python3-requests
BuildRequires:         python3-pyparsing
BuildRequires:         python3-pytz
BuildRequires:         python3-tabulate
BuildRequires:         python3-cryptography
BuildRequires:         python3-lxml
BuildRequires:         python3-sqlalchemy-migrate
BuildRequires:         python3-httplib2
BuildRequires:         python3-tenacity
BuildRequires:         python3-decorator
BuildRequires:         python3-rtslib
BuildRequires:         python3-zstd
BuildRequires:         python3-importlib_metadata
BuildRequires:         python3-boto3
# Needed for unit tests
BuildRequires:         python3-hacking
BuildRequires:         python3-flake8-logging-format
BuildRequires:         python3-coverage
BuildRequires:         python3-PyMySQL
BuildRequires:         python3-psycopg2
BuildRequires:         python3-SQLAlchemy-Utils
BuildRequires:         python3-ddt
BuildRequires:         python3-fixtures
BuildRequires:         python3-oslotest
BuildRequires:         python3-testtools
BuildRequires:         python3-stestr
BuildRequires:         python3-bandit
BuildRequires:         python3-doc8
BuildRequires:         python3-mypy

Requires:         python3-cinderclient
Requires:         python3-pyudev
Requires(pre):    shadow-utils
Requires:         openstack-%{service}-api = %{version}-%{release}
Requires:         openstack-%{service}-scheduler = %{version}-%{release}
Requires:         openstack-%{service}-volume = %{version}-%{release}
Requires:         openstack-%{service}-backup = %{version}-%{release}

%description
%{common_desc}

%package api
Summary:          OpenStack Volume service (Cinder) - API
Requires:         %{name}-common = %{version}-%{release}

%description api
%{common_desc}
This package contains the %{name} API server.

%package scheduler
Summary:          OpenStack Volume service (Cinder) - Scheduler
Requires:         %{name}-common = %{version}-%{release}

%description scheduler
%{common_desc}
This package contains the %{name} Scheduler server.

%package volume
Summary:          OpenStack Volume service (Cinder) - Volume
Requires:         %{name}-common = %{version}-%{release}

%description volume
%{common_desc}
This package contains the %{name} Volume server.

%package backup
Summary:          OpenStack Volume service (Cinder) - Backup
Requires:         %{name}-common = %{version}-%{release}
Requires:         targetcli

%description backup
%{common_desc}
This package contains the %{name} Backup server.

%package common
Summary:          OpenStack Volume service (Cinder) - Common
Requires:         python3-cinder = %{version}-%{release}

%description common
%{common_desc}
This package contains scripts, config and dependencies shared between all the ${name} services

%package -n python3-%{service}
Summary:          OpenStack Volume Python libraries
Requires:         python3-os-win
Requires:         python3-pbr
Requires:         python3-jsonschema
Requires:         python3-castellan
Requires:         python3-cursive
Requires:         python3-routes
Requires:         python3-webob
Requires:         python3-barbicanclient
Requires:         python3-glanceclient
Requires:         python3-keystoneclient
Requires:         python3-novaclient
Requires:         python3-swiftclient
Requires:         python3-google-api-client
Requires:         python3-keystonemiddleware
Requires:         python3-keystoneauth1
Requires:         python3-osprofiler
Requires:         python3-oslo-middleware
Requires:         python3-oslo-messaging
Requires:         python3-oslo-policy
Requires:         python3-oslo-reports
Requires:         python3-oslo-vmware
Requires:         python3-oslo-upgradecheck
Requires:         python3-oauth2client
Requires:         python3-packaging
Requires:         python3-paste
Requires:         python3-paste-deploy
Requires:         python3-paramiko
Requires:         python3-eventlet
Requires:         python3-greenlet
Requires:         python3-iso8601
Requires:         python3-stevedore
Requires:         python3-tooz
Requires:         python3-sqlalchemy
Requires:         python3-six
Requires:         python3-psutil
Requires:         python3-os-brick
Requires:         python3-oslo-config
Requires:         python3-oslo-concurrency
Requires:         python3-oslo-context
Requires:         python3-oslo-db
Requires:         python3-oslo-i18n
Requires:         python3-oslo-log
Requires:         python3-oslo-privsep
Requires:         python3-oslo-rootwrap
Requires:         python3-oslo-serialization
Requires:         python3-oslo-service
Requires:         python3-oslo-utils
Requires:         python3-oslo-versionedobjects
Requires:         python3-taskflow
Requires:         python3-requests
Requires:         python3-pyparsing
Requires:         python3-pytz
Requires:         python3-tabulate
Requires:         python3-cryptography
Requires:         python3-lxml
Requires:         python3-sqlalchemy-migrate
Requires:         python3-httplib2
Requires:         python3-tenacity
Requires:         python3-decorator
Requires:         python3-rtslib
Requires:         lvm2
Requires:         sudo
Requires:         sysfsutils
Requires:         cryptsetup
Requires:         cracklib-dicts
Requires:         qemu-img
Requires:         iscsi-initiator-utils
Requires:         python3-zstd
Requires:         python3-importlib_metadata
Requires:         python3-boto3

%description -n python3-%{service}
%{common_desc}
This package contains the %{service} Python library.

%package -n python3-%{service}-tests
Summary:        Cinder tests

Requires:       python3-hacking
Requires:       python3-flake8-logging-format
Requires:       python3-coverage
Requires:       python3-PyMySQL
Requires:       python3-psycopg2
Requires:       python3-SQLAlchemy-Utils
Requires:       python3-ddt
Requires:       python3-fixtures
Requires:       python3-oslotest
Requires:       python3-subunit
Requires:       python3-testtools
Requires:       python3-stestr
Requires:       python3-bandit
Requires:       python3-doc8
Requires:       python3-mypy
Requires:       python3-%{service}

%description -n python3-%{service}-tests
%{common_desc}
This package contains the Cinder test files.

%prep
%autosetup -n %{service}-%{version}
%py_req_cleanup

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

%install
%{py3_install}
install -d -m 755 %{buildroot}%{_sharedstatedir}/%{service}
install -d -m 755 %{buildroot}%{_sharedstatedir}/%{service}/tmp
install -d -m 755 %{buildroot}%{_sysconfdir}/%{service}
install -d -m 755 %{buildroot}%{_sysconfdir}/%{service}/rootwrap.d
install -d -m 755 %{buildroot}%{_sysconfdir}/%{service}/volumes
install -d -m 755 %{buildroot}%{_localstatedir}/log/%{service}
install -d -m 755 %{buildroot}%{_localstatedir}/run/%{service}
install -d -m 755 %{buildroot}%{_datarootdir}
install -d -m 755 %{buildroot}%{_datarootdir}/%{service}
install -d -m 755 %{buildroot}%{_datarootdir}/%{service}/rootwrap/
install -p -D -m 640 %{SOURCE10} %{buildroot}%{_unitdir}/openstack-%{service}-api.service
install -p -D -m 640 %{SOURCE11} %{buildroot}%{_unitdir}/openstack-%{service}-scheduler.service
install -p -D -m 640 %{SOURCE12} %{buildroot}%{_unitdir}/openstack-%{service}-volume.service
install -p -D -m 640 %{SOURCE13} %{buildroot}%{_unitdir}/openstack-%{service}-backup.service
install -p -D -m 440 %{SOURCE20} %{buildroot}%{_sysconfdir}/sudoers.d/%{service}
install -p -D -m 644 %{SOURCE21} %{buildroot}%{_sysconfdir}/logrotate.d/openstack-%{service}
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}/%{service}.conf.sample %{buildroot}%{_sysconfdir}/%{service}/%{service}.conf
install -p -D -m 640 etc/%{service}/resource_filters.json %{buildroot}%{_sysconfdir}/%{service}/resource_filters.json
install -p -D -m 640 etc/%{service}/rootwrap.d/* %{buildroot}%{_datarootdir}/%{service}/rootwrap/
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}%{_datarootdir}/locale
rm -rf %{buildroot}%{_prefix}/etc

#%check
#OS_TEST_PATH=./%{service}/tests/unit ostestr --concurrency=2

%pre common
%openstack_pre_user_group_create %{service} %{service} /sbin/nologin
exit 0

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

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

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

%files

%files api
%{_bindir}/cinder-api
%{_unitdir}/openstack-cinder-api.service

%files scheduler
%{_bindir}/cinder-scheduler
%{_unitdir}/openstack-cinder-scheduler.service

%files volume
%{_bindir}/cinder-volume
%{_unitdir}/openstack-cinder-volume.service

%files backup
%{_bindir}/cinder-backup
%{_unitdir}/openstack-cinder-backup.service

%files common
%license LICENSE
%dir %attr(0750, %{service}, %{service}) %{_sysconfdir}/%{service}
%dir %attr(0750, %{service}, %{service}) %{_sysconfdir}/%{service}/volumes
%dir %attr(0750, %{service}, %{service}) %{_localstatedir}/log/%{service}
%dir %attr(0750, %{service}, %{service}) %{_localstatedir}/run/%{service}
%dir %attr(0750, %{service}, %{service}) %{_sharedstatedir}/%{service}
%dir %attr(0750, %{service}, %{service}) %{_sharedstatedir}/%{service}/tmp
%attr(-, %{service}, %{service}) %{_sysconfdir}/%{service}/rootwrap.d/
%attr(-, %{service}, %{service}) %{_datarootdir}/%{service}
%attr(0640, root, %{service}) %{_sysconfdir}/logrotate.d/openstack-%{service}
%attr(0440, root, root) %{_sysconfdir}/sudoers.d/%{service}
%config(noreplace) %attr(0640, %{service}, %{service}) %{_sysconfdir}/%{service}/%{service}.conf
%config(noreplace) %attr(0640, %{service}, %{service}) %{_sysconfdir}/%{service}/api-paste.ini
%config(noreplace) %attr(0640, %{service}, %{service}) %{_sysconfdir}/%{service}/rootwrap.conf
%config(noreplace) %attr(0640, %{service}, %{service}) %{_sysconfdir}/%{service}/resource_filters.json
%{_bindir}/%{service}-*
%exclude %{_bindir}/%{service}-api
%exclude %{_bindir}/%{service}-scheduler
%exclude %{_bindir}/%{service}-volume
%exclude %{_bindir}/%{service}-backup

%files -n python3-%{service}
%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

%changelog
* Fri Nov 05 2021 wangxiyuan <wangxiyuan1007@gmail.com> - 15.6.0-1
- Support OpenStack Train release
