本文整理汇总了Python中stubs._fake_instance函数的典型用法代码示例。如果您正苦于以下问题:Python _fake_instance函数的具体用法?Python _fake_instance怎么用?Python _fake_instance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_fake_instance函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_container_pause_fail
def test_container_pause_fail(self, tag, side_effect, expected):
"""
container_pause pauses a contianer on a LXD host. Verify
that an exception.NovaException is raised when there
is an APIError.
"""
instance = stubs._fake_instance()
instance = stubs._fake_instance()
self.ml.container_suspend.side_effect = side_effect
self.assertRaises(expected,
self.session.container_pause,
instance.name, instance)
示例2: test_container_destroy
def test_container_destroy(self, tag, container_defined, side_effect):
"""
container_destroy delete a container from the LXD Host. Check
that the approiate pylxd calls are made.
"""
instance = stubs._fake_instance()
if container_defined:
self.ml.container_defined.return_value = container_defined
self.ml.container_stop.return_value = side_effect
self.ml.container_destroy.return_value = side_effect
self.assertEqual(None,
self.session.container_destroy(instance.name,
instance))
calls = [mock.call.container_defined(instance.name),
mock.call.container_defined(instance.name),
mock.call.container_stop(instance.name, -1),
mock.call.wait_container_operation(
'/1.0/operation/1234', 200, -1),
mock.call.container_destroy(instance.name),
mock.call.wait_container_operation(
'/1.0/operation/1234', 200, -1)]
self.assertEqual(calls, self.ml.method_calls)
if not container_defined:
self.ml.container_defined.return_value = container_defined
self.assertEqual(None,
self.session.container_destroy(instance.name,
instance))
calls = [mock.call.container_defined(instance.name)]
self.assertEqual(calls, self.ml.method_calls)
示例3: test_confirm_migration
def test_confirm_migration(self):
migration = mock.Mock()
instance = stubs._fake_instance()
network_info = mock.Mock()
with test.nested(
mock.patch.object(session.LXDAPISession, 'container_defined'),
mock.patch.object(session.LXDAPISession, 'profile_delete'),
mock.patch.object(session.LXDAPISession, 'container_destroy'),
mock.patch.object(operations.LXDContainerOperations,
'unplug_vifs'),
) as (
mock_container_defined,
mock_profile_delete,
mock_container_destroy,
mock_unplug_vifs):
self.assertEqual(None,
self.migrate.confirm_migration(migration,
instance,
network_info))
mock_container_defined.assert_called_once_with(instance.name,
instance)
mock_profile_delete.assert_called_once_with(instance)
mock_unplug_vifs.assert_called_once_with(instance,
network_info)
示例4: test_profile_delete
def test_profile_delete(self):
instance = stubs._fake_instance()
self.ml.profile_defined.return_value = True
self.ml.profile_delete.return_value = \
(200, fake_api.fake_standard_return())
self.assertEqual(None,
self.session.profile_delete(instance))
示例5: test_get_config_bridge
def test_get_config_bridge(self):
instance = stubs._fake_instance()
vif_data = copy.deepcopy(self.vif_data)
vif_type = self.vif_driver.get_config(instance, vif_data)
self.assertEqual(vif_type, {'bridge': 'qbr0123456789a',
'mac_address': '00:11:22:33:44:55'})
示例6: test_container_wait
def test_container_wait(self):
instance = stubs._fake_instance()
operation_id = mock.Mock()
self.ml.wait_container_operation.return_value = True
self.assertIsNone(self.session.operation_wait(operation_id, instance))
self.ml.wait_container_operation.assert_called_with(operation_id,
200, -1)
示例7: test_migrate_disk_power_off_resize
def test_migrate_disk_power_off_resize(self):
self.flags(my_ip='fakeip')
instance = stubs._fake_instance()
network_info = mock.Mock()
flavor = mock.Mock()
context = mock.Mock()
dest = 'fakeip'
with test.nested(
mock.patch.object(session.LXDAPISession, 'container_defined'),
mock.patch.object(config.LXDContainerConfig, 'create_profile'),
mock.patch.object(session.LXDAPISession, 'profile_update')
) as (
mock_container_defined,
mock_create_profile,
mock_profile_update
):
self.assertEqual('',
self.migrate.migrate_disk_and_power_off(
context, instance, dest, flavor,
network_info))
mock_container_defined.assert_called_once_with(instance.name,
instance)
mock_create_profile.assert_called_once_with(instance,
network_info)
示例8: test_container_snapshot_fail
def test_container_snapshot_fail(self, tag, side_effect, expected):
snapshot = mock.Mock()
instance = stubs._fake_instance()
self.ml.container_snapshot_create.side_effect = side_effect
self.assertRaises(expected,
self.session.container_snapshot,
instance.name, snapshot)
示例9: test_image_defined
def test_image_defined(self):
"""Test the image is defined in the LXD hypervisor."""
instance = stubs._fake_instance()
self.ml.alias_defined.return_value = True
self.assertTrue(self.session.image_defined(instance))
calls = [mock.call.alias_defined(instance.image_ref)]
self.assertEqual(calls, self.ml.method_calls)
示例10: test_create_container
def test_create_container(self, tag, key, expected):
"""Tests the create_container methond on LXDContainerConfig.
Inspect that the correct dictionary is returned for a given
instance.
"""
instance = stubs._fake_instance()
container_config = self.config.create_container(instance)
self.assertEqual(container_config[key], expected)
示例11: test_alias_create
def test_alias_create(self):
"""Test the alias is created."""
instance = stubs._fake_instance()
alias = mock.Mock()
self.ml.alias_create.return_value = True
self.assertTrue(self.session.create_alias(alias, instance))
calls = [mock.call.alias_create(alias)]
self.assertEqual(calls, self.ml.method_calls)
示例12: test_create_disk_path
def test_create_disk_path(self):
instance = stubs._fake_instance()
config = self.config.configure_disk_path('/fake/src_path',
'/fake/dest_path',
'fake_disk', instance)
self.assertEqual({'fake_disk': {'path': '/fake/dest_path',
'source': '/fake/src_path',
'type': 'disk',
'optional': 'True'}}, config)
示例13: test_get_info
def test_get_info(self, tag, side_effect, expected):
instance = stubs._fake_instance()
with mock.patch.object(session.LXDAPISession,
"container_state",
) as state:
state.return_value = side_effect
info = self.connection.get_info(instance)
self.assertEqual(dir(hardware.InstanceInfo(state=expected,
num_cpu=2)), dir(info))
示例14: test_container_suspend
def test_container_suspend(self):
instance = stubs._fake_instance()
context = mock.Mock()
with test.nested(
mock.patch.object(session.LXDAPISession, 'container_pause')
) as (mock_container_suspend):
self.assertEqual(None,
self.operations.suspend(context, instance))
self.assertTrue(mock_container_suspend)
示例15: test_container_publish
def test_container_publish(self, tag, side_effect):
image = mock.Mock()
instance = stubs._fake_instance()
self.ml.image_export.return_value = True
self.assertTrue(
self.session.container_publish(image, instance))
calls = [
mock.call.container_publish(image)]
self.assertEqual(calls, self.ml.method_calls)