本文整理汇总了Python中shade.meta.obj_to_dict函数的典型用法代码示例。如果您正苦于以下问题:Python obj_to_dict函数的具体用法?Python obj_to_dict怎么用?Python obj_to_dict使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了obj_to_dict函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_create_server_with_admin_pass_wait
def test_create_server_with_admin_pass_wait(self, mock_nova, mock_wait):
"""
Test that a server with an admin_pass passed returns the password
"""
fake_server = fakes.FakeServer('1234', '', 'BUILD')
fake_server_with_pass = fakes.FakeServer('1234', '', 'BUILD',
adminPass='ooBootheiX0edoh')
mock_nova.servers.create.return_value = fake_server
mock_nova.servers.get.return_value = fake_server
# The wait returns non-password server
mock_wait.return_value = _utils.normalize_server(
meta.obj_to_dict(fake_server), None, None)
server = self.client.create_server(
name='server-name', image='image-id',
flavor='flavor-id', admin_pass='ooBootheiX0edoh', wait=True)
# Assert that we did wait
self.assertTrue(mock_wait.called)
# Even with the wait, we should still get back a passworded server
self.assertEqual(
server,
_utils.normalize_server(meta.obj_to_dict(fake_server_with_pass),
None, None)
)
开发者ID:LIP-Computing,项目名称:shade,代码行数:27,代码来源:test_create_server.py
示例2: test_create_volume_snapshot_wait
def test_create_volume_snapshot_wait(self, mock_cinder):
"""
Test that create_volume_snapshot with a wait returns the volume
snapshot when its status changes to "available".
"""
build_snapshot = fakes.FakeVolumeSnapshot('1234', 'creating',
'foo', 'derpysnapshot')
fake_snapshot = fakes.FakeVolumeSnapshot('1234', 'available',
'foo', 'derpysnapshot')
mock_cinder.volume_snapshots.create.return_value = build_snapshot
mock_cinder.volume_snapshots.get.return_value = fake_snapshot
mock_cinder.volume_snapshots.list.return_value = [
build_snapshot, fake_snapshot]
self.assertEqual(
meta.obj_to_dict(fake_snapshot),
self.client.create_volume_snapshot(volume_id='1234',
wait=True)
)
mock_cinder.volume_snapshots.create.assert_called_with(
display_description=None, display_name=None, force=False,
volume_id='1234'
)
mock_cinder.volume_snapshots.get.assert_called_with(
snapshot_id=meta.obj_to_dict(build_snapshot)['id']
)
开发者ID:ruizink,项目名称:shade,代码行数:28,代码来源:test_create_volume_snapshot.py
示例3: test_has_volume
def test_has_volume(self):
mock_cloud = mock.MagicMock()
mock_volume = mock.MagicMock()
mock_volume.id = "volume1"
mock_volume.status = "available"
mock_volume.display_name = "Volume 1 Display Name"
mock_volume.attachments = [{"device": "/dev/sda0"}]
mock_volume_dict = meta.obj_to_dict(mock_volume)
mock_cloud.get_volumes.return_value = [mock_volume_dict]
hostvars = meta.get_hostvars_from_server(mock_cloud, meta.obj_to_dict(FakeServer()))
self.assertEquals("volume1", hostvars["volumes"][0]["id"])
self.assertEquals("/dev/sda0", hostvars["volumes"][0]["device"])
开发者ID:vaibhavmital,项目名称:shade,代码行数:12,代码来源:test_meta.py
示例4: test_list_volumes_creating_invalidates
def test_list_volumes_creating_invalidates(self, cinder_mock):
fake_volume = fakes.FakeVolume('volume1', 'creating',
'Volume 1 Display Name')
fake_volume_dict = meta.obj_to_dict(fake_volume)
cinder_mock.volumes.list.return_value = [fake_volume]
self.assertEqual([fake_volume_dict], self.cloud.list_volumes())
fake_volume2 = fakes.FakeVolume('volume2', 'available',
'Volume 2 Display Name')
fake_volume2_dict = meta.obj_to_dict(fake_volume2)
cinder_mock.volumes.list.return_value = [fake_volume, fake_volume2]
self.assertEqual([fake_volume_dict, fake_volume2_dict],
self.cloud.list_volumes())
开发者ID:jsmartin,项目名称:shade,代码行数:12,代码来源:test_caching.py
示例5: test_has_volume
def test_has_volume(self):
mock_cloud = mock.MagicMock()
mock_volume = mock.MagicMock()
mock_volume.id = 'volume1'
mock_volume.status = 'available'
mock_volume.display_name = 'Volume 1 Display Name'
mock_volume.attachments = [{'device': '/dev/sda0'}]
mock_volume_dict = meta.obj_to_dict(mock_volume)
mock_cloud.get_volumes.return_value = [mock_volume_dict]
hostvars = meta.get_hostvars_from_server(
mock_cloud, meta.obj_to_dict(FakeServer()))
self.assertEquals('volume1', hostvars['volumes'][0]['id'])
self.assertEquals('/dev/sda0', hostvars['volumes'][0]['device'])
开发者ID:jsmartin,项目名称:shade,代码行数:13,代码来源:test_meta.py
示例6: test_create_volume_invalidates
def test_create_volume_invalidates(self, cinder_mock):
mock_volb4 = mock.MagicMock()
mock_volb4.id = 'volume1'
mock_volb4.status = 'available'
mock_volb4.display_name = 'Volume 1 Display Name'
mock_volb4_dict = meta.obj_to_dict(mock_volb4)
cinder_mock.volumes.list.return_value = [mock_volb4]
self.assertEqual([mock_volb4_dict], self.cloud.list_volumes())
volume = dict(display_name='junk_vol',
size=1,
display_description='test junk volume')
mock_vol = mock.Mock()
mock_vol.status = 'creating'
mock_vol.id = '12345'
mock_vol_dict = meta.obj_to_dict(mock_vol)
cinder_mock.volumes.create.return_value = mock_vol
cinder_mock.volumes.list.return_value = [mock_volb4, mock_vol]
def creating_available():
def now_available():
mock_vol.status = 'available'
mock_vol_dict['status'] = 'available'
return mock.DEFAULT
cinder_mock.volumes.list.side_effect = now_available
return mock.DEFAULT
cinder_mock.volumes.list.side_effect = creating_available
self.cloud.create_volume(wait=True, timeout=None, **volume)
self.assertTrue(cinder_mock.volumes.create.called)
self.assertEqual(3, cinder_mock.volumes.list.call_count)
# If cache was not invalidated, we would not see our own volume here
# because the first volume was available and thus would already be
# cached.
self.assertEqual([mock_volb4_dict, mock_vol_dict],
self.cloud.list_volumes())
# And now delete and check same thing since list is cached as all
# available
mock_vol.status = 'deleting'
mock_vol_dict = meta.obj_to_dict(mock_vol)
def deleting_gone():
def now_gone():
cinder_mock.volumes.list.return_value = [mock_volb4]
return mock.DEFAULT
cinder_mock.volumes.list.side_effect = now_gone
return mock.DEFAULT
cinder_mock.volumes.list.return_value = [mock_volb4, mock_vol]
cinder_mock.volumes.list.side_effect = deleting_gone
cinder_mock.volumes.delete.return_value = mock_vol_dict
self.cloud.delete_volume('12345')
self.assertEqual([mock_volb4_dict], self.cloud.list_volumes())
开发者ID:emonty,项目名称:shade,代码行数:51,代码来源:test_caching.py
示例7: test_has_volume
def test_has_volume(self):
mock_cloud = mock.MagicMock()
fake_volume = fakes.FakeVolume(
id='volume1',
status='available',
name='Volume 1 Display Name',
attachments=[{'device': '/dev/sda0'}])
fake_volume_dict = meta.obj_to_dict(fake_volume)
mock_cloud.get_volumes.return_value = [fake_volume_dict]
hostvars = meta.get_hostvars_from_server(
mock_cloud, meta.obj_to_dict(standard_fake_server))
self.assertEquals('volume1', hostvars['volumes'][0]['id'])
self.assertEquals('/dev/sda0', hostvars['volumes'][0]['device'])
开发者ID:LIP-Computing,项目名称:shade,代码行数:14,代码来源:test_meta.py
示例8: test_list_images_ignores_unsteady_status
def test_list_images_ignores_unsteady_status(self, glance_mock):
steady_image = fakes.FakeImage('68', 'Jagr', 'active')
steady_image_dict = meta.obj_to_dict(steady_image)
for status in ('queued', 'saving', 'pending_delete'):
active_image = fakes.FakeImage(self.getUniqueString(),
self.getUniqueString(), status)
glance_mock.images.list.return_value = [active_image]
active_image_dict = meta.obj_to_dict(active_image)
self.assertEqual([active_image_dict],
self.cloud.list_images())
glance_mock.images.list.return_value = [active_image, steady_image]
# Should expect steady_image to appear if active wasn't cached
self.assertEqual([active_image_dict, steady_image_dict],
self.cloud.list_images())
开发者ID:jsmartin,项目名称:shade,代码行数:14,代码来源:test_caching.py
示例9: test_private_interface_ip
def test_private_interface_ip(self, mock_get_server_external_ipv4):
mock_get_server_external_ipv4.return_value = PUBLIC_V4
cloud = FakeCloud()
cloud.private = True
hostvars = meta.get_hostvars_from_server(cloud, meta.obj_to_dict(FakeServer()))
self.assertEqual(PRIVATE_V4, hostvars["interface_ip"])
开发者ID:vaibhavmital,项目名称:shade,代码行数:7,代码来源:test_meta.py
示例10: test_basic_hostvars
def test_basic_hostvars(
self, mock_get_server_external_ipv4,
mock_get_server_external_ipv6):
mock_get_server_external_ipv4.return_value = PUBLIC_V4
mock_get_server_external_ipv6.return_value = PUBLIC_V6
hostvars = meta.get_hostvars_from_server(
FakeCloud(), _utils.normalize_server(
meta.obj_to_dict(FakeServer()),
cloud_name='CLOUD_NAME',
region_name='REGION_NAME'))
self.assertNotIn('links', hostvars)
self.assertEqual(PRIVATE_V4, hostvars['private_v4'])
self.assertEqual(PUBLIC_V4, hostvars['public_v4'])
self.assertEqual(PUBLIC_V6, hostvars['public_v6'])
self.assertEqual(PUBLIC_V6, hostvars['interface_ip'])
self.assertEquals('REGION_NAME', hostvars['region'])
self.assertEquals('CLOUD_NAME', hostvars['cloud'])
self.assertEquals("test-image-name", hostvars['image']['name'])
self.assertEquals(FakeServer.image['id'], hostvars['image']['id'])
self.assertNotIn('links', hostvars['image'])
self.assertEquals(FakeServer.flavor['id'], hostvars['flavor']['id'])
self.assertEquals("test-flavor-name", hostvars['flavor']['name'])
self.assertNotIn('links', hostvars['flavor'])
# test having volumes
# test volume exception
self.assertEquals([], hostvars['volumes'])
开发者ID:insequent,项目名称:shade,代码行数:27,代码来源:test_meta.py
示例11: test_get_server_external_ipv4_neutron_accessIPv6
def test_get_server_external_ipv4_neutron_accessIPv6(self):
srv = meta.obj_to_dict(fakes.FakeServer(
id='test-id', name='test-name', status='ACTIVE',
accessIPv6=PUBLIC_V6))
ip = meta.get_server_external_ipv6(server=srv)
self.assertEqual(PUBLIC_V6, ip)
开发者ID:insequent,项目名称:shade,代码行数:7,代码来源:test_meta.py
示例12: test_update_domain
def test_update_domain(self, mock_keystone, mock_normalize):
mock_keystone.domains.update.return_value = domain_obj
self.cloud.update_domain("domain_id", name="new name", description="new description", enabled=False)
mock_keystone.domains.update.assert_called_once_with(
domain="domain_id", name="new name", description="new description", enabled=False
)
mock_normalize.assert_called_once_with([meta.obj_to_dict(domain_obj)])
开发者ID:jhedden,项目名称:shade,代码行数:7,代码来源:test_domains.py
示例13: test_create_volume_snapshot_with_error
def test_create_volume_snapshot_with_error(self, mock_cinder):
"""
Test that a error status while waiting for the volume snapshot to
create raises an exception in create_volume_snapshot.
"""
build_snapshot = fakes.FakeVolumeSnapshot('1234', 'creating',
'bar', 'derpysnapshot')
error_snapshot = fakes.FakeVolumeSnapshot('1234', 'error',
'blah', 'derpysnapshot')
mock_cinder.volume_snapshots.create.return_value = build_snapshot
mock_cinder.volume_snapshots.get.return_value = error_snapshot
mock_cinder.volume_snapshots.list.return_value = [error_snapshot]
self.assertRaises(
OpenStackCloudException,
self.client.create_volume_snapshot, volume_id='1234',
wait=True, timeout=5)
mock_cinder.volume_snapshots.create.assert_called_with(
display_description=None, display_name=None, force=False,
volume_id='1234'
)
mock_cinder.volume_snapshots.get.assert_called_with(
snapshot_id=meta.obj_to_dict(build_snapshot)['id']
)
开发者ID:ruizink,项目名称:shade,代码行数:26,代码来源:test_create_volume_snapshot.py
示例14: test_get_flavor_by_ram
def test_get_flavor_by_ram(self, mock_list):
class Flavor1(object):
id = '1'
name = 'vanilla ice cream'
ram = 100
class Flavor2(object):
id = '2'
name = 'chocolate ice cream'
ram = 200
vanilla = meta.obj_to_dict(Flavor1())
chocolate = meta.obj_to_dict(Flavor2())
mock_list.return_value = [vanilla, chocolate]
flavor = self.cloud.get_flavor_by_ram(ram=150)
self.assertEquals(chocolate, flavor)
开发者ID:vaibhavmital,项目名称:shade,代码行数:16,代码来源:test_shade.py
示例15: test_create_server_with_admin_pass_no_wait
def test_create_server_with_admin_pass_no_wait(self):
"""
Test that a server with an admin_pass passed returns the password
"""
with patch("shade.OpenStackCloud"):
fake_server = fakes.FakeServer('1234', '', 'BUILD')
fake_create_server = fakes.FakeServer('1234', '', 'BUILD',
adminPass='ooBootheiX0edoh')
fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool',
'1.1.1.1', '2.2.2.2',
'5678')
config = {
"servers.create.return_value": fake_create_server,
"servers.get.return_value": fake_server,
"floating_ips.list.return_value": [fake_floating_ip]
}
OpenStackCloud.nova_client = Mock(**config)
self.assertEqual(
_utils.normalize_server(
meta.obj_to_dict(fake_create_server),
cloud_name=self.client.name,
region_name=self.client.region_name),
self.client.create_server(
name='server-name', image='image=id',
flavor='flavor-id', admin_pass='ooBootheiX0edoh'))
开发者ID:Natrinicle,项目名称:shade,代码行数:25,代码来源:test_create_server.py
示例16: test_az
def test_az(self, mock_get_server_external_ipv4):
mock_get_server_external_ipv4.return_value = PUBLIC_V4
server = FakeServer()
server.__dict__["OS-EXT-AZ:availability_zone"] = "az1"
hostvars = meta.get_hostvars_from_server(FakeCloud(), meta.obj_to_dict(server))
self.assertEquals("az1", hostvars["az"])
开发者ID:vaibhavmital,项目名称:shade,代码行数:7,代码来源:test_meta.py
示例17: test_list_volumes
def test_list_volumes(self, cinder_mock):
fake_volume = fakes.FakeVolume('volume1', 'available',
'Volume 1 Display Name')
fake_volume_dict = _utils.normalize_volumes(
[meta.obj_to_dict(fake_volume)])[0]
cinder_mock.volumes.list.return_value = [fake_volume]
self.assertEqual([fake_volume_dict], self.cloud.list_volumes())
fake_volume2 = fakes.FakeVolume('volume2', 'available',
'Volume 2 Display Name')
fake_volume2_dict = _utils.normalize_volumes(
[meta.obj_to_dict(fake_volume2)])[0]
cinder_mock.volumes.list.return_value = [fake_volume, fake_volume2]
self.assertEqual([fake_volume_dict], self.cloud.list_volumes())
self.cloud.list_volumes.invalidate(self.cloud)
self.assertEqual([fake_volume_dict, fake_volume2_dict],
self.cloud.list_volumes())
开发者ID:major,项目名称:shade,代码行数:16,代码来源:test_caching.py
示例18: test_list_volumes_creating_invalidates
def test_list_volumes_creating_invalidates(self, cinder_mock):
mock_volume = mock.MagicMock()
mock_volume.id = 'volume1'
mock_volume.status = 'creating'
mock_volume.display_name = 'Volume 1 Display Name'
mock_volume_dict = meta.obj_to_dict(mock_volume)
cinder_mock.volumes.list.return_value = [mock_volume]
self.assertEqual([mock_volume_dict], self.cloud.list_volumes())
mock_volume2 = mock.MagicMock()
mock_volume2.id = 'volume2'
mock_volume2.status = 'available'
mock_volume2.display_name = 'Volume 2 Display Name'
mock_volume2_dict = meta.obj_to_dict(mock_volume2)
cinder_mock.volumes.list.return_value = [mock_volume, mock_volume2]
self.assertEqual([mock_volume_dict, mock_volume2_dict],
self.cloud.list_volumes())
开发者ID:emonty,项目名称:shade,代码行数:16,代码来源:test_caching.py
示例19: test_get_server_internal_provider_ipv4_neutron
def test_get_server_internal_provider_ipv4_neutron(
self, mock_list_networks, mock_list_subnets,
mock_has_service):
# Testing Clouds with Neutron
mock_has_service.return_value = True
mock_list_subnets.return_value = SUBNETS_WITH_NAT
mock_list_networks.return_value = [{
'id': 'test-net-id',
'name': 'test-net',
'router:external': False,
'provider:network_type': 'vxlan',
'provider:physical_network': None,
}]
srv = meta.obj_to_dict(fakes.FakeServer(
id='test-id', name='test-name', status='ACTIVE',
addresses={'test-net': [{
'addr': PRIVATE_V4,
'version': 4}]},
))
self.assertIsNone(
meta.get_server_external_ipv4(cloud=self.cloud, server=srv))
int_ip = meta.get_server_private_ip(cloud=self.cloud, server=srv)
self.assertEqual(PRIVATE_V4, int_ip)
开发者ID:LIP-Computing,项目名称:shade,代码行数:25,代码来源:test_meta.py
示例20: test_image_string
def test_image_string(self, mock_get_server_external_ipv4):
mock_get_server_external_ipv4.return_value = PUBLIC_V4
server = FakeServer()
server.image = "fake-image-id"
hostvars = meta.get_hostvars_from_server(FakeCloud(), meta.obj_to_dict(server))
self.assertEquals("fake-image-id", hostvars["image"]["id"])
开发者ID:vaibhavmital,项目名称:shade,代码行数:7,代码来源:test_meta.py
注:本文中的shade.meta.obj_to_dict函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论