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