Merge pull request #1981 from ogayot/utcnow
Replace deprecated uses of datetime.datetime.utcnow
This commit is contained in:
commit
65f8ef50d4
|
@ -13,6 +13,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import datetime
|
||||
import fnmatch
|
||||
import json
|
||||
import re
|
||||
|
@ -264,11 +265,13 @@ class TestSubiquityModel(unittest.IsolatedAsyncioTestCase):
|
|||
self.assertEqual(expected_error, str(ctx.exception))
|
||||
|
||||
@mock.patch("subiquity.models.subiquity.lsb_release")
|
||||
@mock.patch("subiquitycore.file_util.datetime.datetime")
|
||||
@mock.patch("subiquitycore.file_util.datetime.datetime", wraps=datetime.datetime)
|
||||
def test_cloud_init_files_emits_datasource_config_and_clean_script(
|
||||
self, datetime, lsb_release
|
||||
self, m_datetime, lsb_release
|
||||
):
|
||||
datetime.utcnow.return_value = "2004-03-05 ..."
|
||||
m_datetime.now.return_value = datetime.datetime(
|
||||
2004, 3, 5, tzinfo=datetime.timezone.utc
|
||||
)
|
||||
main_user = IdentityData(
|
||||
username="mainuser", crypted_password="sample_pass", hostname="somehost"
|
||||
)
|
||||
|
@ -296,7 +299,7 @@ grub_dpkg:
|
|||
# NETPLAN_CONFIG_ROOT_READ_ONLY is True
|
||||
"/etc/cloud/cloud.cfg.d/90-installer-network.cfg"
|
||||
)
|
||||
header = "# Autogenerated by Subiquity: 2004-03-05 ... UTC\n"
|
||||
header = "# Autogenerated by Subiquity: 2004-03-05 00:00:00 UTC\n"
|
||||
with self.subTest(
|
||||
"Stable releases Jammy do not disable cloud-init."
|
||||
" NETPLAN_ROOT_READ_ONLY=True uses cloud-init networking"
|
||||
|
|
|
@ -17,6 +17,7 @@ helper. """
|
|||
|
||||
import asyncio
|
||||
import contextlib
|
||||
import datetime
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
|
@ -328,10 +329,10 @@ class UAInterface:
|
|||
info = await self.get_subscription_status(token)
|
||||
|
||||
# Sometimes, a time zone offset of 0 is replaced by the letter Z. This
|
||||
# is specified in RFC 3339 but not supported by fromisoformat.
|
||||
# See https://bugs.python.org/issue35829
|
||||
# is specified in RFC 3339 but not supported by fromisoformat before
|
||||
# Python 3.11. See https://bugs.python.org/issue35829
|
||||
expiration = dt.fromisoformat(info["expires"].replace("Z", "+00:00"))
|
||||
if expiration.timestamp() <= dt.utcnow().timestamp():
|
||||
if expiration <= dt.now(datetime.timezone.utc):
|
||||
raise ExpiredTokenError(token, expires=info["expires"])
|
||||
|
||||
def is_activable_service(service: dict) -> bool:
|
||||
|
|
|
@ -70,7 +70,7 @@ def write_file(filename, content, **kwargs):
|
|||
|
||||
|
||||
def generate_timestamped_header() -> str:
|
||||
now = datetime.datetime.utcnow()
|
||||
now = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
|
||||
return f"# Autogenerated by Subiquity: {now} UTC\n"
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue