%global full_release ironic-%{version}

%{!?upstream_version: %global upstream_version %{version}%{?milestone}}

Name:           openstack-ironic
# Liberty semver reset
# https://review.openstack.org/#/q/I1a161b2c1d1e27268065b6b4be24c8f7a5315afb,n,z
Summary:        OpenStack Baremetal Hypervisor API (ironic)
Version:        13.0.7
Release:        1
License:        ASL 2.0
URL:            http://www.openstack.org
Source0:        https://tarballs.openstack.org/ironic/ironic-%{version}.tar.gz

Source1:        openstack-ironic-api.service
Source2:        openstack-ironic-conductor.service
Source3:        ironic-rootwrap-sudoers
Source4:        ironic-dist.conf
Source5:        ironic.logrotate

BuildArch:      noarch
BuildRequires:  openstack-macros
BuildRequires:  python3-setuptools
BuildRequires:  python3-devel
BuildRequires:  python3-pbr
BuildRequires:  openssl-devel
BuildRequires:  libxml2-devel
BuildRequires:  libxslt-devel
BuildRequires:  gmp-devel
BuildRequires:  python3-sphinx
BuildRequires:  systemd
# Required to run unit tests
BuildRequires:  python3-alembic
BuildRequires:  python3-automaton
BuildRequires:  python3-cinderclient
BuildRequires:  python3-ddt
BuildRequires:  python3-eventlet
BuildRequires:  python3-futurist
BuildRequires:  python3-glanceclient
BuildRequires:  python3-jinja2
BuildRequires:  python3-jsonpatch
BuildRequires:  python3-jsonschema
BuildRequires:  python3-keystoneauth1
BuildRequires:  python3-keystonemiddleware
BuildRequires:  python3-mock
BuildRequires:  python3-neutronclient
BuildRequires:  python3-openstacksdk
BuildRequires:  python3-oslo-concurrency
BuildRequires:  python3-oslo-config
BuildRequires:  python3-oslo-context
BuildRequires:  python3-oslo-db
BuildRequires:  python3-oslo-i18n
BuildRequires:  python3-oslo-log
BuildRequires:  python3-oslo-messaging
BuildRequires:  python3-oslo-middleware
BuildRequires:  python3-oslo-policy
BuildRequires:  python3-oslo-reports
BuildRequires:  python3-oslo-rootwrap
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-osprofiler
BuildRequires:  python3-os-traits
BuildRequires:  python3-pbr
BuildRequires:  python3-pecan
BuildRequires:  python3-psutil
BuildRequires:  python3-pysnmp
BuildRequires:  python3-pytz
BuildRequires:  python3-requests
BuildRequires:  python3-scciclient
BuildRequires:  python3-sqlalchemy
BuildRequires:  python3-stestr
BuildRequires:  python3-stevedore
BuildRequires:  python3-sushy
BuildRequires:  python3-swiftclient
BuildRequires:  python3-testresources
BuildRequires:  python3-testscenarios
BuildRequires:  python3-testtools
BuildRequires:  python3-tooz
BuildRequires:  python3-dracclient
BuildRequires:  python3-ironic-lib
BuildRequires:  python3-proliantutils
BuildRequires:  python3-tenacity
BuildRequires:  python3-webob

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

%description
Ironic provides an API for management and provisioning of physical machines

%package -n python3-ironic
Summary: OpenStack shared file system service (ironic) - Python module

Requires:   python3-alembic
Requires:   python3-automaton
Requires:   python3-cinderclient
Requires:   python3-eventlet
Requires:   python3-futurist
Requires:   python3-glanceclient
Requires:   python3-ironic-lib
Requires:   python3-jinja2
Requires:   python3-jsonpatch
Requires:   python3-jsonschema
Requires:   python3-keystoneauth1
Requires:   python3-keystonemiddleware
Requires:   python3-openstacksdk
Requires:   python3-oslo-concurrency
Requires:   python3-oslo-config
Requires:   python3-oslo-context
Requires:   python3-oslo-db
Requires:   python3-oslo-log
Requires:   python3-oslo-messaging
Requires:   python3-oslo-middleware
Requires:   python3-oslo-policy
Requires:   python3-oslo-rootwrap
Requires:   python3-oslo-serialization
Requires:   python3-oslo-service
Requires:   python3-oslo-upgradecheck
Requires:   python3-oslo-utils
Requires:   python3-oslo-versionedobjects
Requires:   python3-osprofiler
Requires:   python3-os-traits
Requires:   python3-pbr
Requires:   python3-pecan
Requires:   python3-psutil
Requires:   python3-pytz
Requires:   python3-requests
Requires:   python3-rfc3986
Requires:   python3-sqlalchemy
Requires:   python3-stevedore
Requires:   python3-swiftclient
Requires:   python3-tenacity
Requires:   python3-tooz
Requires:   python3-webob
Requires(pre):  shadow-utils

%description -n python3-ironic
This package contains the core code of OpenStack Ironic.

%package common
Summary: Ironic common
Requires:       python3-ironic = %{version}-%{release}

%description common
Components common to all OpenStack Ironic services

%package api
Summary:        OpenStack Ironic - API
Requires:       %{name}-common = %{version}-%{release}

%description api
This package contains the OpenStack Ironic API Daemon.

%package conductor
Summary:        OpenStack Ironic - Conductor
Requires:       %{name}-common = %{version}-%{release}

%description conductor
This package contains the OpenStack Ironic Conductor Manager Daemon.

%package -n python3-ironic-tests
Summary:        Ironic unit tests
Requires:       %{name}-common = %{version}-%{release}
Requires:       python3-mock
Requires:       python3-oslotest
Requires:       python3-stestr
Requires:       python3-testresources
Requires:       python3-testscenarios
Requires:       python3-testtools


%description -n python3-ironic-tests
This package contains the Ironic test files.

%prep
# Required for tarball sources verification
%setup -q -n ironic-%{upstream_version}
# Let RPM handle the requirements
%py_req_cleanup
# Remove tempest plugin entrypoint as a workaround
sed -i '/tempest/d' setup.cfg
rm -rf ironic_tempest_plugin
%build
%{py3_build}

%install
%{py3_install}

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

# install systemd scripts
mkdir -p %{buildroot}%{_unitdir}
install -p -D -m 644 %{SOURCE1} %{buildroot}%{_unitdir}
install -p -D -m 644 %{SOURCE2} %{buildroot}%{_unitdir}

# install sudoers file
mkdir -p %{buildroot}%{_sysconfdir}/sudoers.d
install -p -D -m 440 %{SOURCE3} %{buildroot}%{_sysconfdir}/sudoers.d/ironic

mkdir -p %{buildroot}%{_sharedstatedir}/ironic/
mkdir -p %{buildroot}%{_localstatedir}/log/ironic/
mkdir -p %{buildroot}%{_sysconfdir}/ironic/rootwrap.d

#Populate the conf dir
export PYTHONPATH=.
oslo-config-generator --config-file tools/config/ironic-config-generator.conf --output-file %{buildroot}/%{_sysconfdir}/ironic/ironic.conf
oslopolicy-sample-generator --config-file tools/policy/ironic-policy-generator.conf
mv %{buildroot}%{_prefix}/etc/ironic/rootwrap.conf %{buildroot}/%{_sysconfdir}/ironic/rootwrap.conf
mv %{buildroot}%{_prefix}/etc/ironic/rootwrap.d/* %{buildroot}/%{_sysconfdir}/ironic/rootwrap.d/
# Remove duplicate config files under /usr/etc/ironic
rmdir %{buildroot}%{_prefix}/etc/ironic/rootwrap.d
rmdir %{buildroot}%{_prefix}/etc/ironic

# Install distribution config
install -p -D -m 640 %{SOURCE4} %{buildroot}/%{_datadir}/ironic/ironic-dist.conf

%check
PYTHON=%{__python3} stestr run

%files
%license LICENSE

%files -n python3-ironic
%doc README.rst
%license LICENSE
%{python3_sitelib}/ironic
%{python3_sitelib}/ironic-*.egg-info
%exclude %{python3_sitelib}/ironic/tests

%files common
%doc README.rst
%doc etc/ironic/policy.yaml.sample
%license LICENSE
%{_bindir}/ironic-dbsync
%{_bindir}/ironic-rootwrap
%{_bindir}/ironic-status
%{_sysconfdir}/sudoers.d/ironic
%config(noreplace) %{_sysconfdir}/logrotate.d/openstack-ironic
%config(noreplace) %attr(-,root,ironic) %{_sysconfdir}/ironic
%attr(-,ironic,ironic) %{_sharedstatedir}/ironic
%attr(0750,ironic,ironic) %{_localstatedir}/log/ironic
%attr(-, root, ironic) %{_datadir}/ironic/ironic-dist.conf

%pre common
getent group ironic >/dev/null || groupadd -r ironic
getent passwd ironic >/dev/null || \
    useradd -r -g ironic -d %{_sharedstatedir}/ironic -s /sbin/nologin \
-c "OpenStack Ironic Daemons" ironic
exit 0


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

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

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

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

%files conductor
%{_bindir}/ironic-conductor
%{_unitdir}/openstack-ironic-conductor.service

%post conductor
%systemd_post openstack-ironic-conductor.service

%preun conductor
%systemd_preun openstack-ironic-conductor.service

%postun conductor
%systemd_postun_with_restart openstack-ironic-conductor.service

%files -n python3-ironic-tests
%{python3_sitelib}/ironic/tests


%changelog
* Fri Nov 05 2021 lijiawei <ljw1101.vip@gmail.com> - 13.0.7-1
- Support OpenStack Train release
