Fix tests to run on python3.
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import contextlib
|
||||
from nova import test
|
||||
import os
|
||||
|
||||
@@ -53,7 +52,7 @@ class LXDTestContainerImage(test.NoDBTestCase):
|
||||
context = mock.Mock()
|
||||
instance = stubs._fake_instance()
|
||||
image_meta = {'name': 'new_image', 'id': 'fake_image'}
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(container_image.LXDContainerImage,
|
||||
'_image_defined'),
|
||||
mock.patch.object(container_image.IMAGE_API,
|
||||
@@ -91,7 +90,7 @@ class LXDTestContainerImage(test.NoDBTestCase):
|
||||
context = mock.Mock()
|
||||
instance = stubs._fake_instance()
|
||||
image_meta = {'name': 'new_image', 'id': 'fake_image'}
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(container_image.LXDContainerImage,
|
||||
'_image_defined'),
|
||||
mock.patch.object(container_image.IMAGE_API,
|
||||
|
||||
@@ -13,8 +13,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import contextlib
|
||||
|
||||
import mock
|
||||
|
||||
from nova import test
|
||||
@@ -44,7 +42,7 @@ class LXDTestContainerMigrate(test.NoDBTestCase):
|
||||
bdevice_info = mock.Mock()
|
||||
disk_info = mock.Mock()
|
||||
network_info = mock.Mock()
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
'client'),
|
||||
mock.patch.object(container_utils.LXDContainerUtils,
|
||||
@@ -59,6 +57,15 @@ class LXDTestContainerMigrate(test.NoDBTestCase):
|
||||
container_init,
|
||||
container_destroy
|
||||
):
|
||||
def side_effect(*args, **kwargs):
|
||||
# XXX: rockstar (7 Dec 2015) - This mock is a little greedy,
|
||||
# and hits too many interfaces. It should become more specific
|
||||
# to the single places it needs to fully mocked. Truthiness of
|
||||
# the mock changes in py3.
|
||||
if args[0] == 'defined':
|
||||
return false
|
||||
return container_defined
|
||||
container_defined.side_effect = side_effect
|
||||
self.assertEqual(None,
|
||||
(self.migrate.finish_migration(context,
|
||||
migration,
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
import ddt
|
||||
import mock
|
||||
|
||||
import contextlib
|
||||
from nova import exception
|
||||
from nova import test
|
||||
from nova.virt import fake
|
||||
@@ -86,7 +85,7 @@ class LXDTestContainerOps(test.NoDBTestCase):
|
||||
need_vif_plugged = mock.Mock()
|
||||
self.ml.container_defined.return_value = True
|
||||
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(container_config.LXDContainerConfig,
|
||||
'create_container'),
|
||||
mock.patch.object(container_utils.LXDContainerUtils,
|
||||
@@ -179,4 +178,4 @@ class LXDTestContainerOps(test.NoDBTestCase):
|
||||
mock.call.container_start('fake-uuid', 5),
|
||||
mock.call.wait_container_operation('0123456789', 200, -1)
|
||||
]
|
||||
self.assertEqual(calls, self.ml.method_calls[-2:])
|
||||
self.assertEqual(calls, self.ml.method_calls[-2:])
|
||||
|
||||
@@ -12,9 +12,6 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import contextlib
|
||||
|
||||
import mock
|
||||
|
||||
from nova import exception
|
||||
@@ -38,7 +35,7 @@ class LXDTestContainerUtils(test.NoDBTestCase):
|
||||
def test_container_start(self):
|
||||
instance = stubs._fake_instance()
|
||||
instance_name = 'fake-uuid'
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
'container_start'),
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
@@ -57,7 +54,7 @@ class LXDTestContainerUtils(test.NoDBTestCase):
|
||||
def test_container_stop(self):
|
||||
instance = stubs._fake_instance()
|
||||
instance_name = 'fake-uuid'
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
'container_stop'),
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
@@ -75,7 +72,7 @@ class LXDTestContainerUtils(test.NoDBTestCase):
|
||||
|
||||
def test_container_reboot(self):
|
||||
instance = stubs._fake_instance()
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
'container_reboot'),
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
@@ -93,7 +90,7 @@ class LXDTestContainerUtils(test.NoDBTestCase):
|
||||
def test_container_destroy(self):
|
||||
instance_name = mock.Mock()
|
||||
host = mock.Mock()
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
'container_defined'),
|
||||
mock.patch.object(container_utils.LXDContainerUtils,
|
||||
@@ -121,7 +118,7 @@ class LXDTestContainerUtils(test.NoDBTestCase):
|
||||
def test_container_pause(self):
|
||||
instance = stubs._fake_instance()
|
||||
instance_name = 'fake-uuid'
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
'container_pause'),
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
@@ -140,7 +137,7 @@ class LXDTestContainerUtils(test.NoDBTestCase):
|
||||
def test_container_unpause(self):
|
||||
instance = stubs._fake_instance()
|
||||
instance_name = 'fake-uuid'
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
'container_pause'),
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
@@ -159,7 +156,7 @@ class LXDTestContainerUtils(test.NoDBTestCase):
|
||||
def test_container_suspend(self):
|
||||
instance = stubs._fake_instance()
|
||||
snapshot = mock.Mock()
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
'container_snapshot_create'),
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
@@ -179,7 +176,7 @@ class LXDTestContainerUtils(test.NoDBTestCase):
|
||||
instance = stubs._fake_instance()
|
||||
config = mock.Mock()
|
||||
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
'container_local_copy'),
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
@@ -200,7 +197,7 @@ class LXDTestContainerUtils(test.NoDBTestCase):
|
||||
config = mock.Mock()
|
||||
old_name = mock.Mock()
|
||||
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
'container_local_move'),
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
@@ -221,7 +218,7 @@ class LXDTestContainerUtils(test.NoDBTestCase):
|
||||
config = mock.Mock()
|
||||
instance = stubs._fake_instance()
|
||||
host = mock.Mock()
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
'container_init'),
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
@@ -249,7 +246,7 @@ class LXDTestContainerUtils(test.NoDBTestCase):
|
||||
config = mock.Mock()
|
||||
instance = stubs._fake_instance()
|
||||
host = mock.Mock()
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
'container_init'),
|
||||
mock.patch.object(container_client.LXDContainerClient,
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import contextlib
|
||||
import inspect
|
||||
import json
|
||||
import os
|
||||
@@ -178,7 +177,7 @@ class LXDTestDriver(test.NoDBTestCase):
|
||||
block_device_info = mock.Mock()
|
||||
self.ml.container_defined.side_effect = [side_effect]
|
||||
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(self.connection.container_ops,
|
||||
'create_container'),
|
||||
) as (
|
||||
@@ -195,7 +194,7 @@ class LXDTestDriver(test.NoDBTestCase):
|
||||
network_info = mock.Mock()
|
||||
self.ml.container_destroy.side_effect = (
|
||||
lxd_exceptions.APIError('Fake', 500))
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(container_utils.LXDContainerUtils,
|
||||
'container_destroy'),
|
||||
mock.patch.object(container_utils.LXDContainerUtils,
|
||||
@@ -216,7 +215,7 @@ class LXDTestDriver(test.NoDBTestCase):
|
||||
instance = stubs._fake_instance()
|
||||
context = mock.Mock()
|
||||
network_info = mock.Mock()
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(container_utils.LXDContainerUtils,
|
||||
'container_stop'),
|
||||
mock.patch.object(container_utils.LXDContainerUtils,
|
||||
@@ -456,7 +455,7 @@ class LXDTestDriver(test.NoDBTestCase):
|
||||
image_meta = mock.Mock()
|
||||
network_info = mock.Mock()
|
||||
self.ml.container_defined.return_value = True
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(container_utils.LXDContainerUtils,
|
||||
'container_stop'),
|
||||
mock.patch.object(self.connection.container_ops,
|
||||
@@ -482,7 +481,7 @@ class LXDTestDriver(test.NoDBTestCase):
|
||||
def test_container_unrescue(self):
|
||||
instance = stubs.MockInstance()
|
||||
network_info = mock.Mock()
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(container_utils.LXDContainerUtils,
|
||||
'container_move'),
|
||||
mock.patch.object(container_utils.LXDContainerUtils,
|
||||
@@ -558,7 +557,7 @@ class LXDTestDriver(test.NoDBTestCase):
|
||||
context = mock.Mock()
|
||||
network_info = mock.Mock()
|
||||
reboot_type = 'SOFT'
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(self.connection.container_ops,
|
||||
'reboot')
|
||||
) as (
|
||||
@@ -570,7 +569,7 @@ class LXDTestDriver(test.NoDBTestCase):
|
||||
|
||||
def test_container_power_off(self):
|
||||
instance = stubs._fake_instance()
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(self.connection.container_ops,
|
||||
'power_off')
|
||||
) as (
|
||||
@@ -583,7 +582,7 @@ class LXDTestDriver(test.NoDBTestCase):
|
||||
context = mock.Mock()
|
||||
instance = stubs._fake_instance()
|
||||
network_info = mock.Mock()
|
||||
with contextlib.nested(
|
||||
with test.nested(
|
||||
mock.patch.object(self.connection.container_ops,
|
||||
'power_on')
|
||||
) as (
|
||||
|
||||
Reference in New Issue
Block a user