Merge "Remove deprecated datetime.utcnow()"
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
# under the License.
|
||||
|
||||
from concurrent import futures
|
||||
import datetime
|
||||
import socket
|
||||
import time
|
||||
import timeit
|
||||
@@ -21,6 +20,7 @@ import timeit
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import excutils
|
||||
from oslo_utils import timeutils
|
||||
import sqlalchemy
|
||||
from stevedore import driver as stevedore_driver
|
||||
|
||||
@@ -417,7 +417,7 @@ class UpdateHealthDb:
|
||||
try:
|
||||
self.amphora_health_repo.replace(
|
||||
lock_session, health['id'],
|
||||
last_update=datetime.datetime.utcnow())
|
||||
last_update=timeutils.utcnow())
|
||||
lock_session.commit()
|
||||
except Exception:
|
||||
with excutils.save_and_reraise_exception():
|
||||
|
@@ -23,6 +23,7 @@ from cryptography.hazmat.primitives import serialization
|
||||
from cryptography import x509
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import timeutils
|
||||
|
||||
from octavia.certificates.common import local as local_common
|
||||
from octavia.certificates.generator import cert_gen
|
||||
@@ -120,8 +121,8 @@ class LocalCertGenerator(cert_gen.CertGenerator):
|
||||
backend=backends.default_backend())
|
||||
new_cert = x509.CertificateBuilder()
|
||||
new_cert = new_cert.serial_number(cls._new_serial())
|
||||
valid_from_datetime = datetime.datetime.utcnow()
|
||||
valid_to_datetime = (datetime.datetime.utcnow() +
|
||||
valid_from_datetime = timeutils.utcnow()
|
||||
valid_to_datetime = (timeutils.utcnow() +
|
||||
datetime.timedelta(seconds=validity))
|
||||
new_cert = new_cert.not_valid_before(valid_from_datetime)
|
||||
new_cert = new_cert.not_valid_after(valid_to_datetime)
|
||||
|
@@ -13,7 +13,6 @@
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import datetime
|
||||
import signal
|
||||
import sys
|
||||
import threading
|
||||
@@ -21,6 +20,7 @@ import threading
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_reports import guru_meditation_report as gmr
|
||||
from oslo_utils import timeutils
|
||||
|
||||
from octavia.common import service
|
||||
from octavia.controller.housekeeping import house_keeping
|
||||
@@ -83,7 +83,7 @@ def main():
|
||||
|
||||
gmr.TextGuruMeditation.setup_autorun(version)
|
||||
|
||||
timestamp = str(datetime.datetime.utcnow())
|
||||
timestamp = str(timeutils.utcnow())
|
||||
LOG.info("Starting house keeping at %s", timestamp)
|
||||
|
||||
threads = []
|
||||
|
@@ -26,6 +26,7 @@ from oslo_db import api as oslo_db_api
|
||||
from oslo_db import exception as db_exception
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
from sqlalchemy.orm import noload
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -215,7 +216,7 @@ class BaseRepository:
|
||||
:returns: A list of resource IDs
|
||||
"""
|
||||
|
||||
expiry_time = datetime.datetime.utcnow() - exp_age
|
||||
expiry_time = timeutils.utcnow() - exp_age
|
||||
|
||||
query = session.query(self.model_class).filter(
|
||||
self.model_class.updated_at < expiry_time)
|
||||
@@ -1335,7 +1336,7 @@ class AmphoraRepository(BaseRepository):
|
||||
# get amphorae with certs that will expire within the
|
||||
# configured buffer period, so we can rotate their certs ahead of time
|
||||
expired_seconds = CONF.house_keeping.cert_expiry_buffer
|
||||
expired_date = datetime.datetime.utcnow() + datetime.timedelta(
|
||||
expired_date = timeutils.utcnow() + datetime.timedelta(
|
||||
seconds=expired_seconds)
|
||||
|
||||
amp = (session.query(self.model_class)
|
||||
@@ -1581,7 +1582,7 @@ class AmphoraHealthRepository(BaseRepository):
|
||||
exp_age = datetime.timedelta(
|
||||
seconds=CONF.house_keeping.amphora_expiry_age)
|
||||
|
||||
expiry_time = datetime.datetime.utcnow() - exp_age
|
||||
expiry_time = timeutils.utcnow() - exp_age
|
||||
|
||||
amphora_model = (
|
||||
session.query(models.AmphoraHealth)
|
||||
@@ -1609,7 +1610,7 @@ class AmphoraHealthRepository(BaseRepository):
|
||||
:returns: [octavia.common.data_model]
|
||||
"""
|
||||
timeout = CONF.health_manager.heartbeat_timeout
|
||||
expired_time = datetime.datetime.utcnow() - datetime.timedelta(
|
||||
expired_time = timeutils.utcnow() - datetime.timedelta(
|
||||
seconds=timeout)
|
||||
|
||||
# Update any amphora that were previously FAILOVER_STOPPED
|
||||
|
@@ -14,6 +14,7 @@
|
||||
|
||||
import datetime
|
||||
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from octavia.common import constants
|
||||
@@ -157,7 +158,7 @@ class ModelTestMixin:
|
||||
'vrrp_port_id': self.FAKE_UUID_1,
|
||||
'ha_port_id': self.FAKE_UUID_2,
|
||||
'lb_network_ip': self.FAKE_IP,
|
||||
'cert_expiration': datetime.datetime.utcnow(),
|
||||
'cert_expiration': timeutils.utcnow(),
|
||||
'cert_busy': False,
|
||||
'cached_zone': self.FAKE_AZ}
|
||||
kwargs.update(overrides)
|
||||
|
@@ -20,6 +20,7 @@ from unittest import mock
|
||||
from oslo_config import cfg
|
||||
from oslo_config import fixture as oslo_fixture
|
||||
from oslo_db import exception as db_exception
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
from sqlalchemy.orm import defer
|
||||
from sqlalchemy.orm import exc as sa_exception
|
||||
@@ -3635,7 +3636,7 @@ class LoadBalancerRepositoryTest(BaseRepositoryTest):
|
||||
|
||||
def test_get_all_deleted_expiring_load_balancer(self):
|
||||
exp_age = datetime.timedelta(seconds=self.FAKE_EXP_AGE)
|
||||
updated_at = datetime.datetime.utcnow() - exp_age
|
||||
updated_at = timeutils.utcnow() - exp_age
|
||||
lb1 = self.create_loadbalancer(
|
||||
self.FAKE_UUID_1, updated_at=updated_at,
|
||||
provisioning_status=constants.DELETED)
|
||||
@@ -3807,7 +3808,7 @@ class AmphoraRepositoryTest(BaseRepositoryTest):
|
||||
'vrrp_ip': self.FAKE_IP,
|
||||
'ha_ip': self.FAKE_IP,
|
||||
'role': constants.ROLE_MASTER,
|
||||
'cert_expiration': datetime.datetime.utcnow(),
|
||||
'cert_expiration': timeutils.utcnow(),
|
||||
'cert_busy': False
|
||||
}
|
||||
settings.update(overrides)
|
||||
@@ -3913,7 +3914,7 @@ class AmphoraRepositoryTest(BaseRepositoryTest):
|
||||
|
||||
def test_get_all_deleted_expiring_amphora(self):
|
||||
exp_age = datetime.timedelta(seconds=self.FAKE_EXP_AGE)
|
||||
updated_at = datetime.datetime.utcnow() - exp_age
|
||||
updated_at = timeutils.utcnow() - exp_age
|
||||
amphora1 = self.create_amphora(
|
||||
self.FAKE_UUID_1, updated_at=updated_at, status=constants.DELETED)
|
||||
amphora2 = self.create_amphora(
|
||||
@@ -3932,7 +3933,7 @@ class AmphoraRepositoryTest(BaseRepositoryTest):
|
||||
amphora = self.create_amphora(self.FAKE_UUID_1)
|
||||
|
||||
expired_interval = CONF.house_keeping.cert_expiry_buffer
|
||||
expiration = datetime.datetime.utcnow() + datetime.timedelta(
|
||||
expiration = timeutils.utcnow() + datetime.timedelta(
|
||||
seconds=2 * expired_interval)
|
||||
|
||||
self.amphora_repo.update(self.session, amphora.id,
|
||||
@@ -3944,7 +3945,7 @@ class AmphoraRepositoryTest(BaseRepositoryTest):
|
||||
# test with expired amphora
|
||||
amphora2 = self.create_amphora(self.FAKE_UUID_2)
|
||||
|
||||
expiration = datetime.datetime.utcnow() + datetime.timedelta(
|
||||
expiration = timeutils.utcnow() + datetime.timedelta(
|
||||
seconds=1)
|
||||
self.amphora_repo.update(self.session, amphora2.id,
|
||||
cert_expiration=expiration)
|
||||
@@ -3957,7 +3958,7 @@ class AmphoraRepositoryTest(BaseRepositoryTest):
|
||||
|
||||
def test_get_cert_expired_amphora_deleted(self):
|
||||
amphora = self.create_amphora(self.FAKE_UUID_3)
|
||||
expiration = datetime.datetime.utcnow() + datetime.timedelta(seconds=1)
|
||||
expiration = timeutils.utcnow() + datetime.timedelta(seconds=1)
|
||||
self.amphora_repo.update(self.session, amphora.id,
|
||||
status=constants.DELETED,
|
||||
cert_expiration=expiration)
|
||||
@@ -4093,7 +4094,7 @@ class AmphoraHealthRepositoryTest(BaseRepositoryTest):
|
||||
'vrrp_ip': fake_ip,
|
||||
'ha_ip': fake_ip,
|
||||
'role': constants.ROLE_MASTER,
|
||||
'cert_expiration': datetime.datetime.utcnow(),
|
||||
'cert_expiration': timeutils.utcnow(),
|
||||
'cert_busy': False
|
||||
}
|
||||
settings.update(overrides)
|
||||
@@ -4101,7 +4102,7 @@ class AmphoraHealthRepositoryTest(BaseRepositoryTest):
|
||||
return amphora
|
||||
|
||||
def create_amphora_health(self, amphora_id):
|
||||
newdate = datetime.datetime.utcnow() - datetime.timedelta(minutes=10)
|
||||
newdate = timeutils.utcnow() - datetime.timedelta(minutes=10)
|
||||
|
||||
amphora_health = self.amphora_health_repo.create(
|
||||
self.session, amphora_id=amphora_id,
|
||||
@@ -4111,7 +4112,7 @@ class AmphoraHealthRepositoryTest(BaseRepositoryTest):
|
||||
|
||||
def test_replace(self):
|
||||
amphora_id = uuidutils.generate_uuid()
|
||||
now = datetime.datetime.utcnow()
|
||||
now = timeutils.utcnow()
|
||||
self.assertIsNone(self.amphora_health_repo.get(
|
||||
self.session, amphora_id=amphora_id))
|
||||
self.amphora_health_repo.replace(self.session, amphora_id,
|
||||
@@ -4220,7 +4221,7 @@ class AmphoraHealthRepositoryTest(BaseRepositoryTest):
|
||||
# Two "busy", One fully healthy, three in FAILOVER_STOPPED
|
||||
amp = self.session.query(db_models.AmphoraHealth).filter_by(
|
||||
amphora_id=stale_uuids[2]).first()
|
||||
amp.last_update = datetime.datetime.utcnow()
|
||||
amp.last_update = timeutils.utcnow()
|
||||
self.session.flush()
|
||||
stale_amphora = self.amphora_health_repo.get_stale_amphora(
|
||||
self.session)
|
||||
@@ -4234,7 +4235,7 @@ class AmphoraHealthRepositoryTest(BaseRepositoryTest):
|
||||
# Two are "busy", Two are fully healthy, Two are in FAILOVER_STOPPED
|
||||
amp = self.session.query(db_models.AmphoraHealth).filter_by(
|
||||
amphora_id=stale_uuids[3]).first()
|
||||
amp.last_update = datetime.datetime.utcnow()
|
||||
amp.last_update = timeutils.utcnow()
|
||||
stale_amphora = self.amphora_health_repo.get_stale_amphora(
|
||||
self.session)
|
||||
self.assertIsNotNone(stale_amphora)
|
||||
@@ -4244,7 +4245,7 @@ class AmphoraHealthRepositoryTest(BaseRepositoryTest):
|
||||
self.assertEqual(2, num_fo_stopped)
|
||||
|
||||
# After error recovery all amps should be allocated again
|
||||
now = datetime.datetime.utcnow()
|
||||
now = timeutils.utcnow()
|
||||
for amp in self.session.query(db_models.AmphoraHealth).all():
|
||||
amp.last_update = now
|
||||
stale_amphora = self.amphora_health_repo.get_stale_amphora(
|
||||
@@ -4258,7 +4259,7 @@ class AmphoraHealthRepositoryTest(BaseRepositoryTest):
|
||||
def test_create(self):
|
||||
amphora_health = self.create_amphora_health(self.FAKE_UUID_1)
|
||||
self.assertEqual(self.FAKE_UUID_1, amphora_health.amphora_id)
|
||||
newcreatedtime = datetime.datetime.utcnow()
|
||||
newcreatedtime = timeutils.utcnow()
|
||||
oldcreatetime = amphora_health.last_update
|
||||
|
||||
diff = newcreatedtime - oldcreatetime
|
||||
|
@@ -18,6 +18,7 @@ from cryptography.hazmat import backends
|
||||
from cryptography.hazmat.primitives import hashes
|
||||
from cryptography.hazmat.primitives import serialization
|
||||
from cryptography import x509
|
||||
from oslo_utils import timeutils
|
||||
|
||||
import octavia.certificates.generator.local as local_cert_gen
|
||||
from octavia.tests.unit.certificates.generator import local_csr
|
||||
@@ -31,8 +32,8 @@ class TestLocalGenerator(local_csr.BaseLocalCSRTestCase):
|
||||
# Setup CA data
|
||||
|
||||
ca_cert = x509.CertificateBuilder()
|
||||
valid_from_datetime = datetime.datetime.utcnow()
|
||||
valid_until_datetime = (datetime.datetime.utcnow() +
|
||||
valid_from_datetime = timeutils.utcnow()
|
||||
valid_until_datetime = (timeutils.utcnow() +
|
||||
datetime.timedelta(
|
||||
seconds=2 * 365 * 24 * 60 * 60))
|
||||
ca_cert = ca_cert.not_valid_before(valid_from_datetime)
|
||||
@@ -78,7 +79,7 @@ class TestLocalGenerator(local_csr.BaseLocalCSRTestCase):
|
||||
data=signed_cert, backend=backends.default_backend())
|
||||
|
||||
# Make sure expiry time is accurate
|
||||
should_expire = (datetime.datetime.utcnow() +
|
||||
should_expire = (timeutils.utcnow() +
|
||||
datetime.timedelta(seconds=2 * 365 * 24 * 60 * 60))
|
||||
diff = should_expire - cert.not_valid_after
|
||||
self.assertLess(diff, datetime.timedelta(seconds=10))
|
||||
@@ -123,7 +124,7 @@ class TestLocalGenerator(local_csr.BaseLocalCSRTestCase):
|
||||
data=signed_cert, backend=backends.default_backend())
|
||||
|
||||
# Make sure expiry time is accurate
|
||||
should_expire = (datetime.datetime.utcnow() +
|
||||
should_expire = (timeutils.utcnow() +
|
||||
datetime.timedelta(seconds=2 * 365 * 24 * 60 * 60))
|
||||
diff = should_expire - cert.not_valid_after
|
||||
self.assertLess(diff, datetime.timedelta(seconds=10))
|
||||
|
@@ -17,6 +17,7 @@ import datetime
|
||||
import json
|
||||
import random
|
||||
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from octavia.common import constants
|
||||
@@ -33,7 +34,7 @@ class TestDataModels(base.TestCase):
|
||||
self.PROJECT_ID = uuidutils.generate_uuid()
|
||||
self.SERVER_GROUP_ID = uuidutils.generate_uuid()
|
||||
self.CREATED_AT = datetime.datetime.now()
|
||||
self.UPDATED_AT = datetime.datetime.utcnow()
|
||||
self.UPDATED_AT = timeutils.utcnow()
|
||||
self.VIP_IP = '192.0.2.10'
|
||||
self.VIP_SUBNET_ID = uuidutils.generate_uuid()
|
||||
self.VIP_NETWORK_ID = uuidutils.generate_uuid()
|
||||
|
@@ -16,6 +16,7 @@ from unittest import mock
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_config import fixture as oslo_fixture
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from octavia.common import constants
|
||||
@@ -61,7 +62,7 @@ class TestDatabaseCleanup(base.TestCase):
|
||||
session.return_value = session
|
||||
self.CONF.config(group="house_keeping",
|
||||
amphora_expiry_age=self.FAKE_EXP_AGE)
|
||||
expired_time = datetime.datetime.utcnow() - datetime.timedelta(
|
||||
expired_time = timeutils.utcnow() - datetime.timedelta(
|
||||
seconds=self.FAKE_EXP_AGE + 1)
|
||||
amphora = self.amp.create(session, id=self.FAKE_UUID_1,
|
||||
compute_id=self.FAKE_UUID_2,
|
||||
@@ -109,7 +110,7 @@ class TestDatabaseCleanup(base.TestCase):
|
||||
session.return_value = session
|
||||
self.CONF.config(group="house_keeping",
|
||||
amphora_expiry_age=self.FAKE_EXP_AGE)
|
||||
expired_time = datetime.datetime.utcnow() - datetime.timedelta(
|
||||
expired_time = timeutils.utcnow() - datetime.timedelta(
|
||||
seconds=self.FAKE_EXP_AGE + 1)
|
||||
amphora = self.amp.create(session, id=self.FAKE_UUID_1,
|
||||
compute_id=self.FAKE_UUID_2,
|
||||
|
Reference in New Issue
Block a user