From f19af02e47d104ea029971ce17874828470da1b2 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Thu, 30 May 2019 13:21:08 +0200 Subject: [PATCH 1/6] Bump version 0.14 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a7e217446..02610ed3c 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup -VERSION = "0.13" +VERSION = "0.14" setup( name="hass-nabucasa", From c7f3c5a5e557ba26118b50bb6f0db74c66bef7af Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Thu, 30 May 2019 17:14:09 +0200 Subject: [PATCH 2/6] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 9dccb5f56..7daef813f 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -65,6 +65,15 @@ jobs: displayName: 'Use Python 3.7' inputs: versionSpec: '3.7' + - script: | + setup_version="$(python setup.py -V)" + branch_version="$(Build.SourceBranchName)" + + if [ "${setup_version}" != "${branch_version}" ]; then + echo "Version of tag ${branch_version} don't match with ${setup_version}!" + exit 1 + fi + displayName: 'Check version of branch/tag' - script: pip install twine displayName: 'Install twine' - script: python setup.py sdist From 77d41c9ff0ecd770b87f9deb131ae0727cc7b5b3 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Wed, 5 Jun 2019 11:26:25 +0200 Subject: [PATCH 3/6] renew-wait (#62) --- hass_nabucasa/remote.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hass_nabucasa/remote.py b/hass_nabucasa/remote.py index 73b0843d2..c30e6b810 100644 --- a/hass_nabucasa/remote.py +++ b/hass_nabucasa/remote.py @@ -322,6 +322,9 @@ async def _certificate_handler(self) -> None: try: await self._acme.issue_certificate() await self.close_backend() + + # Wait until backend is cleaned + await asyncio.sleep(5) await self.load_backend() except AcmeClientError: _LOGGER.warning( From e348b8af762731ec1b7521cd452bd96913ae2f62 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Wed, 5 Jun 2019 12:01:21 +0200 Subject: [PATCH 4/6] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 7daef813f..24346e07f 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -74,9 +74,9 @@ jobs: exit 1 fi displayName: 'Check version of branch/tag' - - script: pip install twine + - script: pip install twine wheel displayName: 'Install twine' - - script: python setup.py sdist + - script: python setup.py sdist bdist_wheel displayName: 'Build package' - script: | export TWINE_USERNAME="$(twineUser)" From 9f1a02028e79e87ce485cd27f68b3fab36cd946c Mon Sep 17 00:00:00 2001 From: cogneato Date: Mon, 10 Jun 2019 14:06:59 -0600 Subject: [PATCH 5/6] Renewal error message fix (#64) Grammar fix for error message --- hass_nabucasa/remote.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hass_nabucasa/remote.py b/hass_nabucasa/remote.py index c30e6b810..fb660ddac 100644 --- a/hass_nabucasa/remote.py +++ b/hass_nabucasa/remote.py @@ -328,7 +328,7 @@ async def _certificate_handler(self) -> None: await self.load_backend() except AcmeClientError: _LOGGER.warning( - "Renew of ACME certificate fails. Try it lager again" + "Renewal of ACME certificate failed. Please try again later." ) except asyncio.CancelledError: From 44f0bb6846b579a26f265b25c2097bf58fd0a845 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 11 Jun 2019 11:09:35 -0700 Subject: [PATCH 6/6] Spread out cert renew (#66) * Spread out renew * fix test * Finish comment --- hass_nabucasa/remote.py | 23 ++++++++++++++++++----- tests/test_remote.py | 8 ++++++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/hass_nabucasa/remote.py b/hass_nabucasa/remote.py index fb660ddac..1c710d608 100644 --- a/hass_nabucasa/remote.py +++ b/hass_nabucasa/remote.py @@ -17,6 +17,9 @@ _LOGGER = logging.getLogger(__name__) +RENEW_IF_EXPIRES_DAYS = 25 +WARN_RENEW_FAILED_DAYS = 18 + class RemoteError(Exception): """General remote error.""" @@ -307,7 +310,7 @@ async def _certificate_handler(self) -> None: """Handle certification ACME Tasks.""" try: while True: - await asyncio.sleep(utils.next_midnight()) + await asyncio.sleep(utils.next_midnight() + random.randint(1, 3600)) # Backend not initialize / No certificate issue now if not self._snitun: @@ -315,7 +318,9 @@ async def _certificate_handler(self) -> None: continue # Renew certificate? - if self._acme.expire_date > utils.utcnow() + timedelta(days=25): + if self._acme.expire_date > utils.utcnow() + timedelta( + days=RENEW_IF_EXPIRES_DAYS + ): continue # Renew certificate @@ -327,9 +332,17 @@ async def _certificate_handler(self) -> None: await asyncio.sleep(5) await self.load_backend() except AcmeClientError: - _LOGGER.warning( - "Renewal of ACME certificate failed. Please try again later." - ) + # Only log as warning if we have a certain amount of days left + if ( + self._acme.expire_date + > utils.utcnow() + < timedelta(days=WARN_RENEW_FAILED_DAYS) + ): + meth = _LOGGER.warning + else: + meth = _LOGGER.debug + + meth("Renewal of ACME certificate failed. Please try again later.") except asyncio.CancelledError: pass diff --git a/tests/test_remote.py b/tests/test_remote.py index 5e58b4733..55319adec 100644 --- a/tests/test_remote.py +++ b/tests/test_remote.py @@ -420,7 +420,9 @@ async def test_certificate_task_no_backend( acme_mock.expire_date = valid - with patch("hass_nabucasa.utils.next_midnight", return_value=0) as mock_midnight: + with patch( + "hass_nabucasa.utils.next_midnight", return_value=0 + ) as mock_midnight, patch("random.randint", return_value=0): remote._acme_task = loop.create_task(remote._certificate_handler()) await asyncio.sleep(0.1) @@ -457,7 +459,9 @@ async def test_certificate_task_renew_cert( acme_mock.expire_date = utcnow() + timedelta(days=-40) - with patch("hass_nabucasa.utils.next_midnight", return_value=0) as mock_midnight: + with patch("hass_nabucasa.utils.next_midnight", return_value=0), patch( + "random.randint", return_value=0 + ): remote._acme_task = loop.create_task(remote._certificate_handler()) await remote.load_backend()