Fix python3 compatibility
Change-Id: If818ca92467de3f00cb065670f3dd17b8547de71
This commit is contained in:
parent
7b24765f4a
commit
efa5f318d3
@ -11,6 +11,7 @@
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
import math
|
||||
import time
|
||||
import uuid
|
||||
|
||||
@ -209,7 +210,7 @@ class SwiftBankPlugin(BankPlugin, LeasePlugin):
|
||||
obj=obj,
|
||||
contents=contents,
|
||||
headers=headers)
|
||||
self.lease_expire_time = long(
|
||||
self.lease_expire_time = math.floor(
|
||||
time.time()) + self.lease_expire_window
|
||||
except SwiftConnectionFailed as err:
|
||||
LOG.error(_LE("acquire lease failed, err:%s."), err)
|
||||
@ -223,13 +224,13 @@ class SwiftBankPlugin(BankPlugin, LeasePlugin):
|
||||
self._post_object(container=container,
|
||||
obj=obj,
|
||||
headers=headers)
|
||||
self.lease_expire_time = long(
|
||||
self.lease_expire_time = math.floor(
|
||||
time.time()) + self.lease_expire_window
|
||||
except SwiftConnectionFailed as err:
|
||||
LOG.error(_LE("acquire lease failed, err:%s."), err)
|
||||
|
||||
def check_lease_validity(self):
|
||||
if (self.lease_expire_time - long(time.time()) >=
|
||||
if (self.lease_expire_time - math.floor(time.time()) >=
|
||||
self.lease_validity_window):
|
||||
return True
|
||||
else:
|
||||
|
@ -156,6 +156,6 @@ class GraphWalkerTest(base.TestCase):
|
||||
listener = _TestGraphWalkerListener(expected_calls, self)
|
||||
walker = graph.GraphWalker()
|
||||
walker.register_listener(listener)
|
||||
keys = g.keys()
|
||||
keys = list(g.keys())
|
||||
keys.sort()
|
||||
walker.walk_graph(graph.build_graph(keys, g.__getitem__))
|
||||
|
@ -10,6 +10,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import math
|
||||
import mock
|
||||
import os
|
||||
from oslo_config import cfg
|
||||
@ -46,21 +47,21 @@ class SwiftBankPluginTest(base.TestCase):
|
||||
|
||||
def test_acquire_lease(self):
|
||||
self.swift_bank_plugin.acquire_lease()
|
||||
expire_time = long(time.time()) + self.conf.lease_expire_window
|
||||
expire_time = math.floor(time.time()) + self.conf.lease_expire_window
|
||||
self.assertEqual(self.swift_bank_plugin.lease_expire_time, expire_time)
|
||||
|
||||
def test_renew_lease(self):
|
||||
self.swift_bank_plugin.acquire_lease()
|
||||
expire_time = long(time.time()) + self.conf.lease_expire_window
|
||||
expire_time = math.floor(time.time()) + self.conf.lease_expire_window
|
||||
self.assertEqual(self.swift_bank_plugin.lease_expire_time, expire_time)
|
||||
time.sleep(5)
|
||||
self.swift_bank_plugin.acquire_lease()
|
||||
expire_time = long(time.time()) + self.conf.lease_expire_window
|
||||
expire_time = math.floor(time.time()) + self.conf.lease_expire_window
|
||||
self.assertEqual(self.swift_bank_plugin.lease_expire_time, expire_time)
|
||||
|
||||
def test_check_lease_validity(self):
|
||||
self.swift_bank_plugin.acquire_lease()
|
||||
expire_time = long(time.time()) + self.conf.lease_expire_window
|
||||
expire_time = math.floor(time.time()) + self.conf.lease_expire_window
|
||||
self.assertEqual(self.swift_bank_plugin.lease_expire_time, expire_time)
|
||||
is_valid = self.swift_bank_plugin.check_lease_validity()
|
||||
self.assertEqual(is_valid, True)
|
||||
|
Loading…
Reference in New Issue
Block a user