Name: cloud-init
Version: 19.4
Release: 8
Summary: the defacto multi-distribution package that handles early initialization of a cloud instance.
License: ASL 2.0 or GPLv3
URL: http://launchpad.net/cloud-init
Source0: https://launchpad.net/%{name}/trunk/%{version}/+download/%{name}-%{version}.tar.gz
Source1: cloud-init-tmpfiles.conf

Patch0: cloud-init-19.4-disable-lxd-tests.patch
Patch1: cloud-init-19.4-nm-controlled.patch
Patch2: cloud-init-19.4-no-override-default-network.patch 
Patch3: bugfix-cloud-init-add-openEuler-os.patch
Patch4: bugfix-sort-requirements.patch
Patch5: add-variable-to-forbid-tmp-dir.patch
Patch6: backport-CVE-2020-8631-utils-use-SystemRandom-when-generating-random-passwo.patch
Patch7: backport-CVE-2020-8632-cc_set_password-increase-random-pwlength-from-9-to-2.patch
Patch8: backport-CVE-2021-3429-write-passwords-only-to-serial-console-lock-down-clo.patch
Patch9: backport-testing-add-additional-mocks-to-test_net-tests-1356.patch

Patch9000: Fix-the-error-level-logs-displayed-for-the-cloud-init-local-service.patch

BuildRequires: pkgconfig(systemd) python3-devel python3-setuptools systemd
BuildRequires: iproute python3-configobj python3-httpretty >= 0.8.14-2
BuildRequires: python3-jinja2 python3-jsonpatch python3-jsonschema
BuildRequires: python3-mock python3-nose python3-oauthlib python3-prettytable
BuildRequires: python3-pyserial python3-PyYAML python3-requests python3-six
BuildRequires: python3-unittest2 dnf %{_vendor}-release passwd

Requires: e2fsprogs iproute python3-libselinux net-tools python3-policycoreutils
Requires: procps python3-configobj python3-jinja2 python3-jsonpatch xfsprogs
Requires: python3-jsonschema python3-oauthlib python3-prettytable util-linux
Requires: python3-pyserial python3-pyyaml python3-requests python3-six shadow
%{?systemd_requires}

BuildArch: noarch

%description
Cloud-init is the defacto multi-distribution package that handles early
initialization of a cloud instance.

%package_help

%prep
%autosetup -n %{name}-%{version} -p1
echo %{_vendor}
sed -i -e 's|#!/usr/bin/env python|#!/usr/bin/env python3|' \
       -e 's|#!/usr/bin/python|#!/usr/bin/python3|' tools/* cloudinit/ssh_util.py
sed -i 's/\/etc\/redhat-release/\/etc\/%{_vendor}-release/g' setup.py

%build
%py3_build

%install
%py3_install -- --init-system=systemd
python3 tools/render-cloudcfg --variant openeuler > %{buildroot}/%{_sysconfdir}/cloud/cloud.cfg
install -d %{buildroot}/var/lib/cloud
install -d %{buildroot}/run/%{name}
install -D -m 0644 %{SOURCE1} %{buildroot}/%{_tmpfilesdir}/%{name}.conf
install -D -m 0644 tools/21-cloudinit.conf %{buildroot}/%{_sysconfdir}/rsyslog.d/21-cloudinit.conf

%check
rm -f $RPM_BUILD_DIR/%{name}-%{version}/tests/unittests/test_handler/test_handler_ntp.py
rm -f $RPM_BUILD_DIR/%{name}-%{version}/tests/unittests/test_datasource/test_opennebula.py

nosetests-%{python3_version} tests/unittests/

%pre

%preun
%systemd_preun cloud-config.service cloud-config.target cloud-final.service cloud-init.service cloud-init.target cloud-init-local.service

%post
if [ $1 -eq 1 ] ; then
    /bin/systemctl enable cloud-config.service     >/dev/null 2>&1 || :
    /bin/systemctl enable cloud-final.service      >/dev/null 2>&1 || :
    /bin/systemctl enable cloud-init.service       >/dev/null 2>&1 || :
    /bin/systemctl enable cloud-init-local.service >/dev/null 2>&1 || :
elif [ $1 -eq 2 ]; then
    /bin/systemctl is-enabled cloud-config.service >/dev/null 2>&1 &&
    /bin/systemctl reenable cloud-config.service >/dev/null 2>&1 || :
    /bin/systemctl is-enabled cloud-final.service >/dev/null 2>&1 &&
    /bin/systemctl reenable cloud-final.service >/dev/null 2>&1 || :
    /bin/systemctl is-enabled cloud-init.service >/dev/null 2>&1 &&
    /bin/systemctl reenable cloud-init.service >/dev/null 2>&1 || :
    /bin/systemctl is-enabled cloud-init-local.service >/dev/null 2>&1 &&
    /bin/systemctl reenable cloud-init-local.service >/dev/null 2>&1 || :
fi

%postun
%systemd_postun cloud-config.service cloud-config.target cloud-final.service cloud-init.service cloud-init.target cloud-init-local.service

%files
%doc ChangeLog
%license LICENSE LICENSE-Apache2.0 LICENSE-GPLv3
%config(noreplace) %{_sysconfdir}/cloud/cloud.cfg
%dir %{_sysconfdir}/cloud/cloud.cfg.d
%config(noreplace) %{_sysconfdir}/cloud/cloud.cfg.d/*.cfg
%doc %{_sysconfdir}/cloud/cloud.cfg.d/README
%dir %{_sysconfdir}/rsyslog.d
%config(noreplace) %{_sysconfdir}/rsyslog.d/21-cloudinit.conf
%{_sysconfdir}/NetworkManager/dispatcher.d/hook-network-manager
%{_sysconfdir}/dhcp/dhclient-exit-hooks.d/hook-dhclient
/lib/udev/rules.d/66-azure-ephemeral.rules
%{_unitdir}/cloud-config.service
%{_unitdir}/cloud-final.service
%{_unitdir}/cloud-init.service
%{_unitdir}/cloud-init-local.service
%{_unitdir}/cloud-config.target
%{_unitdir}/cloud-init.target
/usr/lib/systemd/system-generators/cloud-init-generator
%{_tmpfilesdir}/%{name}.conf
%{_libexecdir}/%{name}
%{_bindir}/cloud-init*
%{_bindir}/cloud-id
%{python3_sitelib}/*
%dir /run/%{name}
%dir /var/lib/cloud
%{_datadir}/bash-completion/completions/cloud-init

%files help
%doc doc/*
%dir %{_sysconfdir}/cloud/templates
%config(noreplace) %{_sysconfdir}/cloud/templates/*
%exclude /usr/share/doc/*

%changelog
* Thu Oct 13 2022 fuanan <fuanan3@h-partners.com> - 19.4-8
- DESC:fix the changelog exception macro

* Fri Apr 1 2022 yangzhuangzhuang <yangzhuangzhuang1@h-partners.com> - 19.4-7
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:Fix test_net.py testcase fail

* Sat Dec 4 2021 yangzhuangzhuang <yangzhuangzhuang1@huawei.com> - 19.4-6
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:change openEuler to openeuler

* Wed Sep 22 2021 yangzhuangzhuang <yangzhuangzhuang1@huawei.com> - 19.4-5
- Type:CVE
- ID:CVE-2021-3429
- SUG:NA
- DESC:Fix CVE-2021-3429

* Tue May 25 2021 yangzhuangzhuang <yangzhuangzhuang1@huawei.com> - 19.4-4
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:Fix the error level logs displayed for the cloud-init-local service

* Sat May 22 2021 yangzhuangzhuang <yangzhuangzhuang1@huawei.com> - 19.4-3
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:enable make check

* Wed Dec 9 2020 yangzhuangzhuang <yangzhuangzhuang1@huawei.com> - 19.4-2
- Type:bugfix
- ID:CVE-2020-8631 CVE-2020-8632
- SUG:NA
- DESC:fix CVE-2020-8631 CVE-2020-8632

* Mon Aug 3 2020 chengquan <chengquan3@huawei.com> - 19.4-1
- Update software to v19.4

* Sat Mar 14 2020 chengquan <chengquan3@huawei.com> - 17.1-12
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:fixbug in self-building

* Mon Dec 23 2019 chengquan <chengquan3@huawei.com> - 17.1-11
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:add openEuler into distros

* Thu Oct 31 2019 chengquan <chengquan3@huawei.com> - 17.1-10
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:fix postun marco and change OS realease

* Tue Oct 22 2019 openEuler Buildteam <buildteam@openeuler.org> - 17.1-9
- Package rebuild.

* Tue Sep 17 2019 openEuler Buildteam <buildteam@openeuler.org> - 17.1-8
- Package init.
