File openstack-magnum.spec of Package openstack-magnum

#
# spec file for package openstack-magnum
#
# 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/
#


%define component magnum
%define groupname %{component}
%define username %{component}

%define version_unconverted 3.3.2.dev7

Name:           openstack-%{component}
Version:        3.3.2~dev7
Release:        0
Summary:        OpenStack container orchestration engines (Magnum)
License:        Apache-2.0
Group:          System/Management
URL:            https://launchpad.net/magnum
Source0:        http://tarballs.openstack.org/magnum/magnum-stable-newton.tar.gz
Source1:        %{name}.logrotate
Source2:        magnum-sudoers
Source3:        %name.conf
Source10:       %{name}-api.service
Source11:       %{name}-conductor.service
Source12:       %{component}-api.conf.sample
# https://bugs.launchpad.net/magnum/+bug/1477444
# https://review.openstack.org/#/c/427723/
Source13:       %{component}-api-app.wsgi
Source50:       README.config
# https://blueprints.launchpad.net/magnum/+spec/k8s-opensuse-support
# https://bugs.launchpad.net/magnum/+bug/1622949
# All changes were cherry-picked from following PR's
# https://review.openstack.org/#/c/397743/
# https://review.openstack.org/#/c/400842/
# https://review.openstack.org/#/c/411856/
# https://review.openstack.org/#/c/411857/
# https://review.openstack.org/#/c/411859/
# https://review.openstack.org/#/c/411862/
# https://review.openstack.org/#/c/411863/
# https://review.openstack.org/#/c/411865/
# https://review.openstack.org/#/c/411866/
# https://review.openstack.org/#/c/411867/
# https://review.openstack.org/#/c/411868/
# https://review.openstack.org/#/c/411869/
Patch1:         0001-Update-for-k8s_opensuse_v1-driver.patch
# https://bugs.launchpad.net/heat/+bug/1564327
# https://bugzilla.redhat.com/show_bug.cgi?id=964006
Patch2:         0001-Fix-magnum-functional-api-v1-tests.patch
Patch3:         0001-Fix-magnum-functional-k8s-tests.patch
# https://review.openstack.org/#/c/458149/
Patch4:         0001-Increase-Wait-Condition-Timeout.patch
# 0002-fix-bad-scope-for-cert-generation.patch -- https://review.openstack.org/#/c/545208/
Patch5:         0002-fix-bad-scope-for-cert-generation.patch
BuildRequires:  apache2
BuildRequires:  crudini
BuildRequires:  fdupes
BuildRequires:  openstack-suse-macros
BuildRequires:  openstack-suse-sudo
BuildRequires:  python-Babel
BuildRequires:  python-Routes
BuildRequires:  python-Sphinx
BuildRequires:  python-WSME
BuildRequires:  python-WebOb
BuildRequires:  python-argparse
BuildRequires:  python-barbicanclient
BuildRequires:  python-base
BuildRequires:  python-docker-py
BuildRequires:  python-eventlet
BuildRequires:  python-fixtures
BuildRequires:  python-glanceclient
BuildRequires:  python-heatclient
BuildRequires:  python-iso8601
BuildRequires:  python-k8sclient
BuildRequires:  python-keystonemiddleware
BuildRequires:  python-mock
BuildRequires:  python-netaddr
BuildRequires:  python-neutronclient
BuildRequires:  python-novaclient
BuildRequires:  python-oslo.concurrency
BuildRequires:  python-oslo.config
BuildRequires:  python-oslo.db
BuildRequires:  python-oslo.i18n
BuildRequires:  python-oslo.log
BuildRequires:  python-oslo.messaging
BuildRequires:  python-oslo.policy
BuildRequires:  python-oslo.utils
BuildRequires:  python-oslo.versionedobjects
BuildRequires:  python-oslosphinx
BuildRequires:  python-paramiko
BuildRequires:  python-pbr
BuildRequires:  python-pecan
BuildRequires:  python-setuptools
BuildRequires:  python-six
BuildRequires:  python-sqlalchemy
BuildRequires:  python-stevedore
BuildRequires:  python-testtools
BuildRequires:  python-urllib3
BuildRequires:  systemd-rpm-macros
%{?systemd_requires}
Requires:       logrotate
Requires:       openstack-suse-sudo
Requires:       python >= 2.7
Requires:       python-magnum = %{version}
Requires:       python-oslo.config >= 3.14.0
Requires(pre):  pwdutils
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildArch:      noarch

%description
Magnum is an OpenStack project which offers container orchestration engines for
deploying and managing containers as first class resources in OpenStack.


%package -n python-magnum
Summary:        OpenStack container orchestration engines (Magnum) - Python module
Group:          Development/Languages/Python
Requires:       python >= 2.7
Requires:       python-Babel >= 2.3.4
Requires:       python-PrettyTable >= 0.7
Requires:       python-PyYAML >= 3.1.0
Requires:       python-SQLAlchemy >= 1.0.10
Requires:       python-WSME >= 0.8
Requires:       python-WebOb >= 1.2.3
Requires:       python-Werkzeug >= 0.7
Requires:       python-alembic >= 0.8.4
Requires:       python-barbicanclient >= 4.0.0
Requires:       python-cliff >= 1.15.0
Requires:       python-cryptography >= 1.0
Requires:       python-decorator >= 3.4.0
Requires:       python-docker-py >= 1.6.0
Requires:       python-enum34
Requires:       python-eventlet >= 0.18.2
Requires:       python-glanceclient >= 2.3.0
Requires:       python-greenlet >= 0.3.2
Requires:       python-heatclient >= 1.4.0
Requires:       python-iso8601 >= 0.1.11
Requires:       python-jsonpatch >= 1.1
Requires:       python-k8sclient >= 0.2.0
Requires:       python-keystoneauth1 >= 2.10.0
Requires:       python-keystoneclient >= 2.0.0
Requires:       python-keystonemiddleware >= 4.0.0
Requires:       python-neutronclient >= 5.1.0
Requires:       python-novaclient >= 2.29.0
Requires:       python-oslo.concurrency >= 3.8.0
Requires:       python-oslo.context >= 2.9.0
Requires:       python-oslo.db >= 4.10.0
Requires:       python-oslo.i18n >= 2.1.0
Requires:       python-oslo.log >= 1.14.0
Requires:       python-oslo.messaging >= 5.2.0
Requires:       python-oslo.middleware >= 3.0.0
Requires:       python-oslo.policy >= 1.9.0
Requires:       python-oslo.reports >= 0.6.0
Requires:       python-oslo.serialization >= 1.10.0
Requires:       python-oslo.service >= 1.10.0
Requires:       python-oslo.utils >= 3.16.0
Requires:       python-oslo.versionedobjects >= 1.13.0
Requires:       python-paramiko >= 2.0
Requires:       python-pecan >= 1.0.0
Requires:       python-pycadf >= 1.1.0
Requires:       python-requests >= 2.10.0
Requires:       python-six >= 1.9.0
Requires:       python-stevedore >= 1.16.0
Requires:       python-taskflow >= 1.26.0
Requires:       python-urllib3 >= 1.15.1

%description -n python-magnum
OpenStack container orchestration engines.

This package contains the core Python module of OpenStack Magnum.

%package api
Summary:        OpenStack container orchestration engines (Magnum) - API
Group:          Development/Languages/Python
Requires:       %{name} = %{version}
Requires:       apache2
Requires:       apache2-mod_wsgi

%description api
OpenStack container orchestration engines.

This package contains the OpenStack Magnum API.

%package conductor
Summary:        OpenStack container orchestration engines (Magnum) - Conductor
Group:          Development/Languages/Python
Requires:       %{name} = %{version}

%description conductor
OpenStack container orchestration engines.

This package contains the OpenStack Magnum Conductor.

%package test
Summary:        OpenStack container orchestration engines (Magnum) - Testsuite
Group:          Development/Languages/Python
Requires:       %{name} = %{version}
Requires:       git-core
Requires:       python-fixtures >= 3.0.0
Requires:       python-mock >= 2.0
Requires:       python-os-testr >= 0.7.0
Requires:       python-oslotest >= 1.10.0
Requires:       python-pbr >= 1.6
Requires:       python-python-subunit >= 0.0.18
Requires:       python-pytz >= 2013.6
Requires:       python-tempest-lib >= 0.14.0
Requires:       python-testrepository >= 0.0.18
Requires:       python-testscenarios >= 0.4
Requires:       python-testtools >= 1.4.0

%description test
The OpenStack Magnum testsuite. It is used to verify the
functionality of OpenStack Magnum.

%prep
%setup -q -n %{component}-%{version_unconverted}
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1

### copy k8s_opensuse_v1 driver to magnum/drivers
cp -r contrib/drivers/k8s_opensuse_v1 magnum/drivers/

%openstack_cleanup_prep

%build
python setup.py build
python setup.py build_sphinx -b man

### configuration files
PYTHONPATH=. oslo-config-generator --config-file etc/magnum/magnum-config-generator.conf \
                                            --output-file etc/magnum.conf.sample

%install
python setup.py install --skip-build --prefix=%{_prefix} --root=%{buildroot}

### directories
install -d -m 755 %{buildroot}%{_localstatedir}/{lib,log}/%{component}
install -d -m 755 %{buildroot}%{_localstatedir}/lib/%{component}/certificates
install -d -m 750 %{buildroot}%{_localstatedir}/cache/%{component}
install -d -m 700 %{buildroot}%{_localstatedir}/run/%{component}
install -d -m 755 %{buildroot}/srv/www/%{component}-api
install -d -m 755 %{buildroot}%{_sysconfdir}/%{component}/%{component}.conf.d

### configuration files
install -p -D -m 644 %{SOURCE3} %{buildroot}/%_tmpfilesdir/%name.conf
install -p -D -m 640 %{SOURCE50} %{buildroot}%{_sysconfdir}/%{component}/README.config
install -p -D -m 644 etc/%{component}.conf.sample %{buildroot}%{_sysconfdir}/%{component}/%{component}.conf
install -p -D -m 644 etc/%{component}/{api-paste.ini,policy.json} %{buildroot}%{_sysconfdir}/%{component}/
install -p -D -m 644 %{SOURCE12} %{buildroot}%{_sysconfdir}/apache2/conf.d/%{component}-api.conf.sample
install -p -D -m 644 %{SOURCE13} %{buildroot}/srv/www/%{component}-api/app.wsgi

# bash-completion/logrotate/etc.
install -p -D -m 644 %{SOURCE1} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}

# Install systemd unit services
mkdir -p %{buildroot}%{_sbindir} %{buildroot}%{_unitdir}
install -p -D -m 444 %{SOURCE10} %{buildroot}%{_unitdir}/%{name}-api.service
install -p -D -m 444 %{SOURCE11} %{buildroot}%{_unitdir}/%{name}-conductor.service
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}-api
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}-conductor

### sudoers configuration for magnum-rootwrap:
install -D -m 440 %{SOURCE2} %{buildroot}%{_sysconfdir}/sudoers.d/openstack-magnum

### documentation
install -d %{buildroot}%{_mandir}/man1
install -m 644 doc/build/man/*.1 %{buildroot}%{_mandir}/man1

### test subpackage
%openstack_test_package_install
%fdupes %{buildroot}%{_localstatedir}/lib/%{name}-test

### misc
%fdupes %{buildroot}%{python_sitelib}/%{component}

### set default configuration
%define magnum_conf %{buildroot}%{_sysconfdir}/%{component}/%{component}.conf.d/010-%{component}.conf
crudini --set %{magnum_conf} DEFAULT log_dir /var/log/%{component}
crudini --set %{magnum_conf} DEFAULT state_path /var/lib/%{component}
crudini --set %{magnum_conf} oslo_concurrency lock_path /var/run/%{component}
crudini --set %{magnum_conf} oslo_policy policy_file /etc/magnum/policy.json
crudini --set %{magnum_conf} certificates cert_manager_type local

%pre
%openstack_pre_user_group_create %{username} %{groupname}

%post
%tmpfiles_create %{_tmpfilesdir}/%{name}.conf

%pre api
%service_add_pre %{name}-api.service

%post api
%service_add_post %{name}-api.service

%preun api
%service_del_preun %{name}-api.service

%postun api
%restart_on_update %{name}-api.service
%service_del_postun %{name}-api.service

%pre conductor
%service_add_pre %{name}-conductor.service

%post conductor
%service_add_post %{name}-conductor.service

%preun conductor
%service_del_preun %{name}-conductor.service

%postun conductor
%restart_on_update %{name}-conductor.service
%service_del_postun %{name}-conductor.service

%files
%defattr(-,root,root)
%doc LICENSE README.rst
%dir %attr(0755, %{username}, %{groupname}) %{_localstatedir}/lib/%{component}
%dir %attr(0750, %{username}, %{groupname}) %{_localstatedir}/lib/%{component}/certificates
%dir %attr(0750, %{username}, %{groupname}) %{_localstatedir}/cache/%{component}
%dir %attr(0750, %{username}, %{groupname}) %{_localstatedir}/log/%{component}
%_tmpfilesdir/%name.conf
%dir %{_tmpfilesdir}
%dir %{_sysconfdir}/%{component}
%dir %{_sysconfdir}/%{component}/%{component}.conf.d/
%{_sysconfdir}/%{component}/README.config
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%config %{_sysconfdir}/sudoers.d/openstack-magnum
%config %attr(0640, root, %{groupname}) %{_sysconfdir}/%{component}/api-paste.ini
%config(noreplace) %attr(0640, root, %{groupname}) %{_sysconfdir}/%{component}/%{component}.conf
%config(noreplace) %attr(0640, root, %{groupname}) %{_sysconfdir}/%{component}/%{component}.conf.d/010-%{component}.conf
%config %{_sysconfdir}/%{component}/policy.json
%{_bindir}/%{component}-db-manage
%{_bindir}/%{component}-template-manage
%{_mandir}/man1/%{component}.1%{?ext_man}

%files -n python-%{component}
%defattr(-,root,root,-)
%doc LICENSE
%{python_sitelib}/%{component}/
%{python_sitelib}/%{component}-*.egg-info
%exclude %{python_sitelib}/%{component}/tests/unit

%files api
%defattr(-,root,root,-)
%doc LICENSE
%{_unitdir}/%{name}-api.service
%{_sbindir}/rc%{name}-api
%{_bindir}/%{component}-api
/srv/www/%{component}-api/
/srv/www/%{component}-api/app.wsgi
%config %{_sysconfdir}/apache2/conf.d/%{component}-api.conf.sample

%files conductor
%defattr(-,root,root,-)
%doc LICENSE
%{_unitdir}/%{name}-conductor.service
%{_sbindir}/rc%{name}-conductor
%{_bindir}/%{component}-conductor

%files test
%defattr(-,root,root)
%{_localstatedir}/lib/%{name}-test/
%{python_sitelib}/%{component}/tests/unit/

%changelog
openSUSE Build Service is sponsored by