python-openstackclient 6.6.0__py3-none-any.whl → 7.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openstackclient/api/api.py +7 -8
- openstackclient/api/compute_v2.py +352 -638
- openstackclient/api/image_v1.py +1 -1
- openstackclient/api/object_store_v1.py +3 -4
- openstackclient/common/availability_zone.py +1 -1
- openstackclient/common/clientmanager.py +16 -4
- openstackclient/common/configuration.py +1 -1
- openstackclient/common/extension.py +1 -1
- openstackclient/common/limits.py +66 -32
- openstackclient/common/module.py +3 -3
- openstackclient/common/progressbar.py +2 -2
- openstackclient/common/project_cleanup.py +5 -2
- openstackclient/common/quota.py +281 -410
- openstackclient/common/versions.py +1 -1
- openstackclient/compute/client.py +7 -116
- openstackclient/compute/v2/agent.py +75 -49
- openstackclient/compute/v2/aggregate.py +9 -9
- openstackclient/compute/v2/console.py +2 -2
- openstackclient/compute/v2/flavor.py +6 -6
- openstackclient/compute/v2/host.py +38 -33
- openstackclient/compute/v2/hypervisor.py +4 -3
- openstackclient/compute/v2/keypair.py +7 -8
- openstackclient/compute/v2/server.py +478 -396
- openstackclient/compute/v2/server_backup.py +1 -1
- openstackclient/compute/v2/server_group.py +4 -4
- openstackclient/compute/v2/server_image.py +1 -1
- openstackclient/compute/v2/server_migration.py +3 -4
- openstackclient/compute/v2/service.py +4 -4
- openstackclient/compute/v2/usage.py +3 -3
- openstackclient/identity/common.py +34 -0
- openstackclient/identity/v2_0/catalog.py +2 -2
- openstackclient/identity/v2_0/ec2creds.py +4 -4
- openstackclient/identity/v2_0/endpoint.py +4 -4
- openstackclient/identity/v2_0/project.py +6 -6
- openstackclient/identity/v2_0/role.py +5 -5
- openstackclient/identity/v2_0/role_assignment.py +1 -1
- openstackclient/identity/v2_0/service.py +4 -4
- openstackclient/identity/v2_0/token.py +2 -2
- openstackclient/identity/v2_0/user.py +7 -7
- openstackclient/identity/v3/access_rule.py +3 -3
- openstackclient/identity/v3/application_credential.py +127 -45
- openstackclient/identity/v3/catalog.py +2 -2
- openstackclient/identity/v3/consumer.py +4 -4
- openstackclient/identity/v3/credential.py +5 -5
- openstackclient/identity/v3/domain.py +5 -5
- openstackclient/identity/v3/ec2creds.py +4 -4
- openstackclient/identity/v3/endpoint.py +7 -7
- openstackclient/identity/v3/endpoint_group.py +8 -10
- openstackclient/identity/v3/federation_protocol.py +5 -5
- openstackclient/identity/v3/group.py +8 -8
- openstackclient/identity/v3/identity_provider.py +5 -5
- openstackclient/identity/v3/implied_role.py +3 -3
- openstackclient/identity/v3/limit.py +5 -5
- openstackclient/identity/v3/mapping.py +5 -5
- openstackclient/identity/v3/policy.py +5 -5
- openstackclient/identity/v3/project.py +5 -5
- openstackclient/identity/v3/region.py +5 -5
- openstackclient/identity/v3/registered_limit.py +5 -5
- openstackclient/identity/v3/role.py +7 -7
- openstackclient/identity/v3/role_assignment.py +92 -140
- openstackclient/identity/v3/service.py +64 -34
- openstackclient/identity/v3/service_provider.py +4 -4
- openstackclient/identity/v3/tag.py +2 -2
- openstackclient/identity/v3/token.py +5 -5
- openstackclient/identity/v3/trust.py +3 -3
- openstackclient/identity/v3/user.py +144 -80
- openstackclient/image/client.py +4 -4
- openstackclient/image/v1/image.py +8 -9
- openstackclient/image/v2/cache.py +12 -10
- openstackclient/image/v2/metadef_objects.py +44 -0
- openstackclient/image/v2/metadef_resource_type_association.py +189 -0
- openstackclient/image/v2/task.py +1 -1
- openstackclient/network/common.py +6 -5
- openstackclient/network/utils.py +2 -2
- openstackclient/network/v2/address_group.py +6 -6
- openstackclient/network/v2/address_scope.py +5 -5
- openstackclient/network/v2/default_security_group_rule.py +1 -1
- openstackclient/network/v2/floating_ip.py +8 -10
- openstackclient/network/v2/floating_ip_pool.py +6 -15
- openstackclient/network/v2/floating_ip_port_forwarding.py +5 -13
- openstackclient/network/v2/ip_availability.py +2 -2
- openstackclient/network/v2/l3_conntrack_helper.py +5 -5
- openstackclient/network/v2/network.py +8 -8
- openstackclient/network/v2/network_agent.py +8 -8
- openstackclient/network/v2/network_auto_allocated_topology.py +2 -2
- openstackclient/network/v2/network_flavor.py +6 -8
- openstackclient/network/v2/network_flavor_profile.py +4 -4
- openstackclient/network/v2/network_meter.py +3 -3
- openstackclient/network/v2/network_meter_rule.py +3 -3
- openstackclient/network/v2/network_qos_policy.py +5 -5
- openstackclient/network/v2/network_qos_rule.py +9 -9
- openstackclient/network/v2/network_qos_rule_type.py +1 -1
- openstackclient/network/v2/network_rbac.py +5 -5
- openstackclient/network/v2/network_segment.py +5 -5
- openstackclient/network/v2/network_segment_range.py +7 -7
- openstackclient/network/v2/network_trunk.py +7 -7
- openstackclient/network/v2/port.py +26 -12
- openstackclient/network/v2/router.py +403 -54
- openstackclient/network/v2/security_group.py +18 -14
- openstackclient/network/v2/security_group_rule.py +18 -15
- openstackclient/network/v2/subnet.py +15 -8
- openstackclient/network/v2/subnet_pool.py +6 -6
- openstackclient/object/v1/account.py +2 -2
- openstackclient/object/v1/container.py +7 -7
- openstackclient/object/v1/object.py +7 -7
- openstackclient/shell.py +4 -6
- openstackclient/tests/functional/base.py +1 -1
- openstackclient/tests/functional/common/test_extension.py +1 -1
- openstackclient/tests/functional/common/test_help.py +2 -2
- openstackclient/tests/functional/common/test_module.py +1 -1
- openstackclient/tests/functional/common/test_quota.py +43 -61
- openstackclient/tests/functional/compute/v2/common.py +2 -2
- openstackclient/tests/functional/compute/v2/test_flavor.py +2 -2
- openstackclient/tests/functional/compute/v2/test_keypair.py +1 -1
- openstackclient/tests/functional/compute/v2/test_server.py +5 -5
- openstackclient/tests/functional/compute/v2/test_server_event.py +1 -1
- openstackclient/tests/functional/identity/v2/common.py +3 -3
- openstackclient/tests/functional/identity/v3/common.py +14 -6
- openstackclient/tests/functional/identity/v3/test_application_credential.py +13 -19
- openstackclient/tests/functional/identity/v3/test_domain.py +1 -3
- openstackclient/tests/functional/identity/v3/test_endpoint.py +1 -1
- openstackclient/tests/functional/identity/v3/test_idp.py +1 -1
- openstackclient/tests/functional/identity/v3/test_limit.py +2 -2
- openstackclient/tests/functional/identity/v3/test_region.py +1 -3
- openstackclient/tests/functional/identity/v3/test_registered_limit.py +1 -1
- openstackclient/tests/functional/identity/v3/test_role.py +2 -2
- openstackclient/tests/functional/identity/v3/test_role_assignment.py +210 -0
- openstackclient/tests/functional/identity/v3/test_service.py +4 -6
- openstackclient/tests/functional/identity/v3/test_service_provider.py +1 -3
- openstackclient/tests/functional/image/base.py +1 -1
- openstackclient/tests/functional/image/v2/test_image.py +1 -1
- openstackclient/tests/functional/image/v2/test_info.py +1 -1
- openstackclient/tests/functional/network/v2/common.py +4 -6
- openstackclient/tests/functional/network/v2/test_network.py +5 -3
- openstackclient/tests/functional/network/v2/test_network_agent.py +7 -5
- openstackclient/tests/functional/network/v2/test_network_qos_rule.py +4 -4
- openstackclient/tests/functional/network/v2/test_port.py +11 -7
- openstackclient/tests/functional/network/v2/test_router.py +2 -2
- openstackclient/tests/functional/object/v1/common.py +1 -1
- openstackclient/tests/functional/object/v1/test_container.py +3 -3
- openstackclient/tests/functional/object/v1/test_object.py +9 -13
- openstackclient/tests/functional/volume/base.py +1 -1
- openstackclient/tests/functional/volume/v1/test_service.py +1 -1
- openstackclient/tests/functional/volume/v1/test_snapshot.py +2 -2
- openstackclient/tests/functional/volume/v1/test_transfer_request.py +2 -2
- openstackclient/tests/functional/volume/v1/test_volume_type.py +1 -1
- openstackclient/tests/functional/volume/v2/test_service.py +2 -2
- openstackclient/tests/functional/volume/v2/test_volume_backup.py +2 -2
- openstackclient/tests/functional/volume/v2/test_volume_snapshot.py +2 -2
- openstackclient/tests/functional/volume/v2/test_volume_type.py +1 -1
- openstackclient/tests/functional/volume/v3/test_volume_snapshot.py +2 -2
- openstackclient/tests/functional/volume/v3/test_volume_type.py +1 -1
- openstackclient/tests/unit/api/fakes.py +1 -1
- openstackclient/tests/unit/api/test_api.py +2 -2
- openstackclient/tests/unit/api/test_compute_v2.py +522 -707
- openstackclient/tests/unit/api/test_image_v1.py +1 -1
- openstackclient/tests/unit/api/test_image_v2.py +1 -1
- openstackclient/tests/unit/api/test_object_store_v1.py +4 -4
- openstackclient/tests/unit/common/test_limits.py +73 -35
- openstackclient/tests/unit/common/test_logs.py +2 -2
- openstackclient/tests/unit/common/test_module.py +4 -2
- openstackclient/tests/unit/common/test_project_cleanup.py +31 -6
- openstackclient/tests/unit/common/test_quota.py +490 -630
- openstackclient/tests/unit/compute/v2/fakes.py +37 -286
- openstackclient/tests/unit/compute/v2/test_agent.py +189 -147
- openstackclient/tests/unit/compute/v2/test_aggregate.py +18 -16
- openstackclient/tests/unit/compute/v2/test_console.py +4 -5
- openstackclient/tests/unit/compute/v2/test_flavor.py +59 -68
- openstackclient/tests/unit/compute/v2/test_host.py +83 -54
- openstackclient/tests/unit/compute/v2/test_hypervisor.py +28 -31
- openstackclient/tests/unit/compute/v2/test_hypervisor_stats.py +2 -2
- openstackclient/tests/unit/compute/v2/test_keypair.py +65 -50
- openstackclient/tests/unit/compute/v2/test_server.py +2895 -2459
- openstackclient/tests/unit/compute/v2/test_server_backup.py +1 -1
- openstackclient/tests/unit/compute/v2/test_server_event.py +14 -39
- openstackclient/tests/unit/compute/v2/test_server_group.py +28 -29
- openstackclient/tests/unit/compute/v2/test_server_migration.py +43 -68
- openstackclient/tests/unit/compute/v2/test_server_volume.py +17 -34
- openstackclient/tests/unit/compute/v2/test_service.py +34 -52
- openstackclient/tests/unit/compute/v2/test_usage.py +4 -4
- openstackclient/tests/unit/fakes.py +11 -11
- openstackclient/tests/unit/identity/v2_0/fakes.py +27 -10
- openstackclient/tests/unit/identity/v2_0/test_catalog.py +3 -3
- openstackclient/tests/unit/identity/v2_0/test_endpoint.py +7 -7
- openstackclient/tests/unit/identity/v2_0/test_project.py +8 -8
- openstackclient/tests/unit/identity/v2_0/test_role.py +10 -10
- openstackclient/tests/unit/identity/v2_0/test_role_assignment.py +4 -4
- openstackclient/tests/unit/identity/v2_0/test_service.py +6 -6
- openstackclient/tests/unit/identity/v2_0/test_token.py +4 -4
- openstackclient/tests/unit/identity/v2_0/test_user.py +8 -8
- openstackclient/tests/unit/identity/v3/fakes.py +59 -20
- openstackclient/tests/unit/identity/v3/test_access_rule.py +5 -5
- openstackclient/tests/unit/identity/v3/test_application_credential.py +212 -235
- openstackclient/tests/unit/identity/v3/test_catalog.py +3 -3
- openstackclient/tests/unit/identity/v3/test_consumer.py +7 -8
- openstackclient/tests/unit/identity/v3/test_credential.py +9 -9
- openstackclient/tests/unit/identity/v3/test_domain.py +8 -8
- openstackclient/tests/unit/identity/v3/test_endpoint.py +13 -13
- openstackclient/tests/unit/identity/v3/test_endpoint_group.py +12 -14
- openstackclient/tests/unit/identity/v3/test_group.py +12 -12
- openstackclient/tests/unit/identity/v3/test_identity_provider.py +8 -8
- openstackclient/tests/unit/identity/v3/test_implied_role.py +5 -5
- openstackclient/tests/unit/identity/v3/test_limit.py +7 -7
- openstackclient/tests/unit/identity/v3/test_mappings.py +7 -7
- openstackclient/tests/unit/identity/v3/test_oauth.py +5 -5
- openstackclient/tests/unit/identity/v3/test_project.py +16 -16
- openstackclient/tests/unit/identity/v3/test_protocol.py +7 -7
- openstackclient/tests/unit/identity/v3/test_region.py +7 -7
- openstackclient/tests/unit/identity/v3/test_registered_limit.py +12 -13
- openstackclient/tests/unit/identity/v3/test_role.py +13 -13
- openstackclient/tests/unit/identity/v3/test_role_assignment.py +410 -331
- openstackclient/tests/unit/identity/v3/test_service.py +93 -97
- openstackclient/tests/unit/identity/v3/test_service_provider.py +7 -7
- openstackclient/tests/unit/identity/v3/test_token.py +4 -4
- openstackclient/tests/unit/identity/v3/test_trust.py +9 -9
- openstackclient/tests/unit/identity/v3/test_unscoped_saml.py +4 -4
- openstackclient/tests/unit/identity/v3/test_user.py +299 -327
- openstackclient/tests/unit/image/v1/test_image.py +6 -6
- openstackclient/tests/unit/image/v2/fakes.py +46 -9
- openstackclient/tests/unit/image/v2/test_cache.py +2 -2
- openstackclient/tests/unit/image/v2/test_image.py +3 -3
- openstackclient/tests/unit/image/v2/test_metadef_objects.py +62 -0
- openstackclient/tests/unit/image/v2/test_metadef_resource_type_association.py +131 -0
- openstackclient/tests/unit/integ/base.py +1 -1
- openstackclient/tests/unit/integ/cli/test_project.py +4 -4
- openstackclient/tests/unit/integ/cli/test_shell.py +7 -7
- openstackclient/tests/unit/network/test_common.py +12 -21
- openstackclient/tests/unit/network/v2/fakes.py +64 -130
- openstackclient/tests/unit/network/v2/test_address_group.py +15 -15
- openstackclient/tests/unit/network/v2/test_address_scope.py +13 -13
- openstackclient/tests/unit/network/v2/test_default_security_group_rule.py +49 -27
- openstackclient/tests/unit/network/v2/test_floating_ip_compute.py +40 -38
- openstackclient/tests/unit/network/v2/test_floating_ip_network.py +15 -15
- openstackclient/tests/unit/network/v2/test_floating_ip_pool_compute.py +4 -7
- openstackclient/tests/unit/network/v2/test_floating_ip_pool_network.py +3 -5
- openstackclient/tests/unit/network/v2/test_floating_ip_port_forwarding.py +11 -11
- openstackclient/tests/unit/network/v2/test_ip_availability.py +6 -6
- openstackclient/tests/unit/network/v2/test_l3_conntrack_helper.py +11 -21
- openstackclient/tests/unit/network/v2/test_local_ip.py +7 -7
- openstackclient/tests/unit/network/v2/test_local_ip_association.py +3 -5
- openstackclient/tests/unit/network/v2/test_ndp_proxy.py +13 -13
- openstackclient/tests/unit/network/v2/test_network.py +23 -28
- openstackclient/tests/unit/network/v2/test_network_agent.py +17 -21
- openstackclient/tests/unit/network/v2/test_network_auto_allocated_topology.py +8 -8
- openstackclient/tests/unit/network/v2/test_network_compute.py +66 -65
- openstackclient/tests/unit/network/v2/test_network_flavor.py +17 -19
- openstackclient/tests/unit/network/v2/test_network_flavor_profile.py +13 -13
- openstackclient/tests/unit/network/v2/test_network_meter.py +11 -11
- openstackclient/tests/unit/network/v2/test_network_meter_rule.py +11 -11
- openstackclient/tests/unit/network/v2/test_network_qos_policy.py +11 -21
- openstackclient/tests/unit/network/v2/test_network_qos_rule.py +51 -77
- openstackclient/tests/unit/network/v2/test_network_qos_rule_type.py +5 -9
- openstackclient/tests/unit/network/v2/test_network_rbac.py +12 -12
- openstackclient/tests/unit/network/v2/test_network_segment.py +11 -15
- openstackclient/tests/unit/network/v2/test_network_segment_range.py +11 -13
- openstackclient/tests/unit/network/v2/test_network_service_provider.py +3 -5
- openstackclient/tests/unit/network/v2/test_network_trunk.py +11 -11
- openstackclient/tests/unit/network/v2/test_port.py +22 -25
- openstackclient/tests/unit/network/v2/test_router.py +721 -51
- openstackclient/tests/unit/network/v2/test_security_group_compute.py +65 -49
- openstackclient/tests/unit/network/v2/test_security_group_network.py +15 -15
- openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py +57 -45
- openstackclient/tests/unit/network/v2/test_security_group_rule_network.py +11 -19
- openstackclient/tests/unit/network/v2/test_subnet.py +29 -25
- openstackclient/tests/unit/network/v2/test_subnet_pool.py +15 -15
- openstackclient/tests/unit/object/v1/fakes.py +1 -1
- openstackclient/tests/unit/object/v1/test_container.py +5 -5
- openstackclient/tests/unit/object/v1/test_container_all.py +6 -6
- openstackclient/tests/unit/object/v1/test_object.py +3 -3
- openstackclient/tests/unit/object/v1/test_object_all.py +5 -5
- openstackclient/tests/unit/test_shell.py +5 -5
- openstackclient/tests/unit/utils.py +4 -1
- openstackclient/tests/unit/volume/test_find_resource.py +2 -2
- openstackclient/tests/unit/volume/v1/fakes.py +5 -6
- openstackclient/tests/unit/volume/v1/test_volume.py +5 -4
- openstackclient/tests/unit/volume/v2/fakes.py +39 -259
- openstackclient/tests/unit/volume/v2/test_consistency_group_snapshot.py +5 -5
- openstackclient/tests/unit/volume/v2/test_qos_specs.py +9 -9
- openstackclient/tests/unit/volume/v2/test_volume.py +21 -87
- openstackclient/tests/unit/volume/v2/test_volume_backup.py +7 -368
- openstackclient/tests/unit/volume/v2/test_volume_snapshot.py +1 -1
- openstackclient/tests/unit/volume/v2/test_volume_transfer_request.py +0 -44
- openstackclient/tests/unit/volume/v2/test_volume_type.py +6 -87
- openstackclient/tests/unit/volume/v3/fakes.py +505 -22
- openstackclient/tests/unit/volume/v3/test_block_storage_cleanup.py +2 -3
- openstackclient/tests/unit/volume/v3/test_block_storage_cluster.py +10 -11
- openstackclient/tests/unit/volume/v3/test_block_storage_log_level.py +10 -6
- openstackclient/tests/unit/volume/v3/test_block_storage_manage.py +25 -17
- openstackclient/tests/unit/volume/v3/test_block_storage_resource_filter.py +6 -32
- openstackclient/tests/unit/volume/v3/test_service.py +271 -0
- openstackclient/tests/unit/volume/v3/test_volume.py +2177 -33
- openstackclient/tests/unit/volume/v3/test_volume_attachment.py +48 -52
- openstackclient/tests/unit/volume/v3/test_volume_backup.py +892 -0
- openstackclient/tests/unit/volume/v3/test_volume_group.py +19 -20
- openstackclient/tests/unit/volume/v3/test_volume_group_snapshot.py +14 -34
- openstackclient/tests/unit/volume/v3/test_volume_group_type.py +13 -16
- openstackclient/tests/unit/volume/v3/test_volume_message.py +10 -11
- openstackclient/tests/unit/volume/v3/test_volume_snapshot.py +161 -0
- openstackclient/tests/unit/volume/v3/test_volume_transfer_request.py +425 -0
- openstackclient/tests/unit/volume/v3/test_volume_type.py +1109 -0
- openstackclient/volume/v1/qos_specs.py +7 -7
- openstackclient/volume/v1/service.py +2 -2
- openstackclient/volume/v1/volume.py +12 -12
- openstackclient/volume/v1/volume_backup.py +7 -7
- openstackclient/volume/v1/volume_snapshot.py +8 -8
- openstackclient/volume/v1/volume_transfer_request.py +5 -5
- openstackclient/volume/v1/volume_type.py +7 -7
- openstackclient/volume/v2/backup_record.py +2 -2
- openstackclient/volume/v2/consistency_group.py +7 -9
- openstackclient/volume/v2/consistency_group_snapshot.py +4 -12
- openstackclient/volume/v2/qos_specs.py +7 -7
- openstackclient/volume/v2/service.py +2 -2
- openstackclient/volume/v2/volume.py +80 -80
- openstackclient/volume/v2/volume_backend.py +2 -2
- openstackclient/volume/v2/volume_backup.py +7 -217
- openstackclient/volume/v2/volume_host.py +2 -2
- openstackclient/volume/v2/volume_snapshot.py +8 -8
- openstackclient/volume/v2/volume_transfer_request.py +5 -37
- openstackclient/volume/v2/volume_type.py +7 -89
- openstackclient/volume/v3/service.py +56 -0
- openstackclient/volume/v3/volume.py +971 -0
- openstackclient/volume/v3/volume_attachment.py +31 -29
- openstackclient/volume/v3/volume_backup.py +670 -0
- openstackclient/volume/v3/volume_message.py +1 -1
- openstackclient/volume/v3/volume_snapshot.py +97 -0
- openstackclient/volume/v3/volume_transfer_request.py +233 -0
- openstackclient/volume/v3/volume_type.py +967 -0
- {python_openstackclient-6.6.0.dist-info → python_openstackclient-7.0.0.dist-info}/AUTHORS +4 -0
- {python_openstackclient-6.6.0.dist-info → python_openstackclient-7.0.0.dist-info}/METADATA +3 -3
- python_openstackclient-7.0.0.dist-info/RECORD +502 -0
- {python_openstackclient-6.6.0.dist-info → python_openstackclient-7.0.0.dist-info}/entry_points.txt +33 -27
- python_openstackclient-7.0.0.dist-info/pbr.json +1 -0
- python_openstackclient-6.6.0.dist-info/RECORD +0 -489
- python_openstackclient-6.6.0.dist-info/pbr.json +0 -1
- {python_openstackclient-6.6.0.dist-info → python_openstackclient-7.0.0.dist-info}/LICENSE +0 -0
- {python_openstackclient-6.6.0.dist-info → python_openstackclient-7.0.0.dist-info}/WHEEL +0 -0
- {python_openstackclient-6.6.0.dist-info → python_openstackclient-7.0.0.dist-info}/top_level.txt +0 -0
|
@@ -13,746 +13,561 @@
|
|
|
13
13
|
|
|
14
14
|
"""Compute v2 API Library Tests"""
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
import http
|
|
17
|
+
from unittest import mock
|
|
18
|
+
import uuid
|
|
19
|
+
|
|
20
|
+
from openstack.compute.v2 import _proxy
|
|
17
21
|
from osc_lib import exceptions as osc_lib_exceptions
|
|
18
|
-
from requests_mock.contrib import fixture
|
|
19
22
|
|
|
20
23
|
from openstackclient.api import compute_v2 as compute
|
|
24
|
+
from openstackclient.tests.unit import fakes
|
|
21
25
|
from openstackclient.tests.unit import utils
|
|
22
26
|
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
FAKE_URL = 'http://gopher.com/v2'
|
|
26
|
-
|
|
28
|
+
class TestSecurityGroup(utils.TestCase):
|
|
27
29
|
|
|
28
|
-
class TestComputeAPIv2(utils.TestCase):
|
|
29
30
|
def setUp(self):
|
|
30
|
-
super(
|
|
31
|
-
|
|
32
|
-
self.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
'pool': 'nova',
|
|
49
|
-
'instance_id': None,
|
|
50
|
-
}
|
|
51
|
-
LIST_FLOATING_IP_RESP = [
|
|
52
|
-
FAKE_FLOATING_IP_RESP,
|
|
53
|
-
FAKE_FLOATING_IP_RESP_2,
|
|
54
|
-
]
|
|
55
|
-
|
|
56
|
-
FAKE_SERVER_RESP_1 = {
|
|
57
|
-
'id': 1,
|
|
58
|
-
'name': 'server1',
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
def test_floating_ip_add_id(self):
|
|
62
|
-
self.requests_mock.register_uri(
|
|
63
|
-
'POST',
|
|
64
|
-
FAKE_URL + '/servers/1/action',
|
|
65
|
-
json={'server': {}},
|
|
66
|
-
status_code=200,
|
|
67
|
-
)
|
|
68
|
-
self.requests_mock.register_uri(
|
|
69
|
-
'GET',
|
|
70
|
-
FAKE_URL + '/servers/1',
|
|
71
|
-
json={'server': self.FAKE_SERVER_RESP_1},
|
|
72
|
-
status_code=200,
|
|
73
|
-
)
|
|
74
|
-
ret = self.api.floating_ip_add('1', '1.0.1.0')
|
|
75
|
-
self.assertEqual(200, ret.status_code)
|
|
76
|
-
|
|
77
|
-
def test_floating_ip_add_name(self):
|
|
78
|
-
self.requests_mock.register_uri(
|
|
79
|
-
'POST',
|
|
80
|
-
FAKE_URL + '/servers/1/action',
|
|
81
|
-
json={'server': {}},
|
|
82
|
-
status_code=200,
|
|
83
|
-
)
|
|
84
|
-
self.requests_mock.register_uri(
|
|
85
|
-
'GET',
|
|
86
|
-
FAKE_URL + '/servers/server1',
|
|
87
|
-
json={'server': self.FAKE_SERVER_RESP_1},
|
|
88
|
-
status_code=200,
|
|
89
|
-
)
|
|
90
|
-
ret = self.api.floating_ip_add('server1', '1.0.1.0')
|
|
91
|
-
self.assertEqual(200, ret.status_code)
|
|
92
|
-
|
|
93
|
-
def test_floating_ip_create(self):
|
|
94
|
-
self.requests_mock.register_uri(
|
|
95
|
-
'POST',
|
|
96
|
-
FAKE_URL + '/os-floating-ips',
|
|
97
|
-
json={'floating_ip': self.FAKE_FLOATING_IP_RESP},
|
|
98
|
-
status_code=200,
|
|
99
|
-
)
|
|
100
|
-
ret = self.api.floating_ip_create('nova')
|
|
101
|
-
self.assertEqual(self.FAKE_FLOATING_IP_RESP, ret)
|
|
102
|
-
|
|
103
|
-
def test_floating_ip_create_not_found(self):
|
|
104
|
-
self.requests_mock.register_uri(
|
|
105
|
-
'POST',
|
|
106
|
-
FAKE_URL + '/os-floating-ips',
|
|
107
|
-
status_code=404,
|
|
31
|
+
super().setUp()
|
|
32
|
+
|
|
33
|
+
self.compute_sdk_client = mock.Mock(_proxy.Proxy)
|
|
34
|
+
|
|
35
|
+
def test_create_security_group(self):
|
|
36
|
+
sg_name = 'name-' + uuid.uuid4().hex
|
|
37
|
+
sg_description = 'description-' + uuid.uuid4().hex
|
|
38
|
+
data = {
|
|
39
|
+
'security_group': {
|
|
40
|
+
'id': uuid.uuid4().hex,
|
|
41
|
+
'name': sg_name,
|
|
42
|
+
'description': sg_description,
|
|
43
|
+
'tenant_id': 'project-id-' + uuid.uuid4().hex,
|
|
44
|
+
'rules': [],
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
self.compute_sdk_client.post.return_value = fakes.FakeResponse(
|
|
48
|
+
data=data
|
|
108
49
|
)
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
self.
|
|
112
|
-
'not-nova',
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
def test_floating_ip_delete(self):
|
|
116
|
-
self.requests_mock.register_uri(
|
|
117
|
-
'DELETE',
|
|
118
|
-
FAKE_URL + '/os-floating-ips/1',
|
|
119
|
-
status_code=202,
|
|
120
|
-
)
|
|
121
|
-
ret = self.api.floating_ip_delete('1')
|
|
122
|
-
self.assertEqual(202, ret.status_code)
|
|
123
|
-
self.assertEqual("", ret.text)
|
|
124
|
-
|
|
125
|
-
def test_floating_ip_delete_none(self):
|
|
126
|
-
ret = self.api.floating_ip_delete()
|
|
127
|
-
self.assertIsNone(ret)
|
|
128
|
-
|
|
129
|
-
def test_floating_ip_find_id(self):
|
|
130
|
-
self.requests_mock.register_uri(
|
|
131
|
-
'GET',
|
|
132
|
-
FAKE_URL + '/os-floating-ips/1',
|
|
133
|
-
json={'floating_ip': self.FAKE_FLOATING_IP_RESP},
|
|
134
|
-
status_code=200,
|
|
135
|
-
)
|
|
136
|
-
ret = self.api.floating_ip_find('1')
|
|
137
|
-
self.assertEqual(self.FAKE_FLOATING_IP_RESP, ret)
|
|
138
|
-
|
|
139
|
-
def test_floating_ip_find_ip(self):
|
|
140
|
-
self.requests_mock.register_uri(
|
|
141
|
-
'GET',
|
|
142
|
-
FAKE_URL + '/os-floating-ips/' + self.FAKE_FLOATING_IP_RESP['ip'],
|
|
143
|
-
status_code=404,
|
|
144
|
-
)
|
|
145
|
-
self.requests_mock.register_uri(
|
|
146
|
-
'GET',
|
|
147
|
-
FAKE_URL + '/os-floating-ips',
|
|
148
|
-
json={'floating_ips': self.LIST_FLOATING_IP_RESP},
|
|
149
|
-
status_code=200,
|
|
150
|
-
)
|
|
151
|
-
ret = self.api.floating_ip_find(self.FAKE_FLOATING_IP_RESP['ip'])
|
|
152
|
-
self.assertEqual(self.FAKE_FLOATING_IP_RESP, ret)
|
|
153
|
-
|
|
154
|
-
def test_floating_ip_find_not_found(self):
|
|
155
|
-
self.requests_mock.register_uri(
|
|
156
|
-
'GET',
|
|
157
|
-
FAKE_URL + '/os-floating-ips/1.2.3.4',
|
|
158
|
-
status_code=404,
|
|
159
|
-
)
|
|
160
|
-
self.requests_mock.register_uri(
|
|
161
|
-
'GET',
|
|
162
|
-
FAKE_URL + '/os-floating-ips',
|
|
163
|
-
json={'floating_ips': self.LIST_FLOATING_IP_RESP},
|
|
164
|
-
status_code=200,
|
|
50
|
+
|
|
51
|
+
result = compute.create_security_group(
|
|
52
|
+
self.compute_sdk_client, sg_name, sg_description
|
|
165
53
|
)
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
'
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
FAKE_URL + '/servers/1/action',
|
|
186
|
-
status_code=200,
|
|
187
|
-
)
|
|
188
|
-
self.requests_mock.register_uri(
|
|
189
|
-
'GET',
|
|
190
|
-
FAKE_URL + '/servers/1',
|
|
191
|
-
json={'server': self.FAKE_SERVER_RESP_1},
|
|
192
|
-
status_code=200,
|
|
193
|
-
)
|
|
194
|
-
ret = self.api.floating_ip_remove('1', '1.0.1.0')
|
|
195
|
-
self.assertEqual(200, ret.status_code)
|
|
196
|
-
|
|
197
|
-
def test_floating_ip_remove_name(self):
|
|
198
|
-
self.requests_mock.register_uri(
|
|
199
|
-
'POST',
|
|
200
|
-
FAKE_URL + '/servers/1/action',
|
|
201
|
-
status_code=200,
|
|
202
|
-
)
|
|
203
|
-
self.requests_mock.register_uri(
|
|
204
|
-
'GET',
|
|
205
|
-
FAKE_URL + '/servers/server1',
|
|
206
|
-
json={'server': self.FAKE_SERVER_RESP_1},
|
|
207
|
-
status_code=200,
|
|
208
|
-
)
|
|
209
|
-
ret = self.api.floating_ip_remove('server1', '1.0.1.0')
|
|
210
|
-
self.assertEqual(200, ret.status_code)
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
class TestFloatingIPPool(TestComputeAPIv2):
|
|
214
|
-
LIST_FLOATING_IP_POOL_RESP = [
|
|
215
|
-
{"name": "tide"},
|
|
216
|
-
{"name": "press"},
|
|
217
|
-
]
|
|
218
|
-
|
|
219
|
-
def test_floating_ip_pool_list(self):
|
|
220
|
-
self.requests_mock.register_uri(
|
|
221
|
-
'GET',
|
|
222
|
-
FAKE_URL + '/os-floating-ip-pools',
|
|
223
|
-
json={'floating_ip_pools': self.LIST_FLOATING_IP_POOL_RESP},
|
|
224
|
-
status_code=200,
|
|
225
|
-
)
|
|
226
|
-
ret = self.api.floating_ip_pool_list()
|
|
227
|
-
self.assertEqual(self.LIST_FLOATING_IP_POOL_RESP, ret)
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
class TestHost(TestComputeAPIv2):
|
|
231
|
-
FAKE_HOST_RESP_1 = {
|
|
232
|
-
"zone": "internal",
|
|
233
|
-
"host_name": "myhost",
|
|
234
|
-
"service": "conductor",
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
FAKE_HOST_RESP_2 = {
|
|
238
|
-
"zone": "internal",
|
|
239
|
-
"host_name": "myhost",
|
|
240
|
-
"service": "scheduler",
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
FAKE_HOST_RESP_3 = {
|
|
244
|
-
"zone": "nova",
|
|
245
|
-
"host_name": "myhost",
|
|
246
|
-
"service": "compute",
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
LIST_HOST_RESP = [
|
|
250
|
-
FAKE_HOST_RESP_1,
|
|
251
|
-
FAKE_HOST_RESP_2,
|
|
252
|
-
FAKE_HOST_RESP_3,
|
|
253
|
-
]
|
|
254
|
-
|
|
255
|
-
def test_host_list_no_options(self):
|
|
256
|
-
self.requests_mock.register_uri(
|
|
257
|
-
'GET',
|
|
258
|
-
FAKE_URL + '/os-hosts',
|
|
259
|
-
json={'hosts': self.LIST_HOST_RESP},
|
|
260
|
-
status_code=200,
|
|
261
|
-
)
|
|
262
|
-
ret = self.api.host_list()
|
|
263
|
-
self.assertEqual(self.LIST_HOST_RESP, ret)
|
|
264
|
-
|
|
265
|
-
def test_host_list_zone(self):
|
|
266
|
-
self.requests_mock.register_uri(
|
|
267
|
-
'GET',
|
|
268
|
-
FAKE_URL + '/os-hosts?zone=nova',
|
|
269
|
-
json={'hosts': [self.FAKE_HOST_RESP_3]},
|
|
270
|
-
status_code=200,
|
|
271
|
-
)
|
|
272
|
-
self.requests_mock.register_uri(
|
|
273
|
-
'GET',
|
|
274
|
-
FAKE_URL + '/os-hosts',
|
|
275
|
-
json={'hosts': [self.FAKE_HOST_RESP_3]},
|
|
276
|
-
status_code=200,
|
|
277
|
-
)
|
|
278
|
-
ret = self.api.host_list(zone='nova')
|
|
279
|
-
self.assertEqual([self.FAKE_HOST_RESP_3], ret)
|
|
280
|
-
|
|
281
|
-
def test_host_set_none(self):
|
|
282
|
-
ret = self.api.host_set(host='myhost')
|
|
283
|
-
self.assertIsNone(ret)
|
|
284
|
-
|
|
285
|
-
def test_host_set(self):
|
|
286
|
-
self.requests_mock.register_uri(
|
|
287
|
-
'PUT',
|
|
288
|
-
FAKE_URL + '/os-hosts/myhost',
|
|
289
|
-
json={},
|
|
290
|
-
status_code=200,
|
|
291
|
-
)
|
|
292
|
-
ret = self.api.host_set(host='myhost', status='enabled')
|
|
293
|
-
self.assertEqual({}, ret)
|
|
294
|
-
|
|
295
|
-
def test_host_show(self):
|
|
296
|
-
FAKE_RESOURCE_1 = {
|
|
297
|
-
"cpu": 2,
|
|
298
|
-
"disk_gb": 1028,
|
|
299
|
-
"host": "c1a7de0ac9d94e4baceae031d05caae3",
|
|
300
|
-
"memory_mb": 8192,
|
|
301
|
-
"project": "(total)",
|
|
302
|
-
}
|
|
303
|
-
FAKE_RESOURCE_2 = {
|
|
304
|
-
"cpu": 0,
|
|
305
|
-
"disk_gb": 0,
|
|
306
|
-
"host": "c1a7de0ac9d94e4baceae031d05caae3",
|
|
307
|
-
"memory_mb": 512,
|
|
308
|
-
"project": "(used_now)",
|
|
54
|
+
|
|
55
|
+
self.compute_sdk_client.post.assert_called_once_with(
|
|
56
|
+
'/os-security-groups',
|
|
57
|
+
data={'name': sg_name, 'description': sg_description},
|
|
58
|
+
microversion='2.1',
|
|
59
|
+
)
|
|
60
|
+
self.assertEqual(data['security_group'], result)
|
|
61
|
+
|
|
62
|
+
def test_list_security_groups(self):
|
|
63
|
+
data = {
|
|
64
|
+
'security_groups': [
|
|
65
|
+
{
|
|
66
|
+
'id': uuid.uuid4().hex,
|
|
67
|
+
'name': uuid.uuid4().hex,
|
|
68
|
+
'description': 'description-' + uuid.uuid4().hex,
|
|
69
|
+
'tenant_id': 'project-id-' + uuid.uuid4().hex,
|
|
70
|
+
'rules': [],
|
|
71
|
+
}
|
|
72
|
+
],
|
|
309
73
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
74
|
+
self.compute_sdk_client.get.return_value = fakes.FakeResponse(
|
|
75
|
+
data=data
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
result = compute.list_security_groups(self.compute_sdk_client)
|
|
79
|
+
|
|
80
|
+
self.compute_sdk_client.get.assert_called_once_with(
|
|
81
|
+
'/os-security-groups', microversion='2.1'
|
|
82
|
+
)
|
|
83
|
+
self.assertEqual(data['security_groups'], result)
|
|
84
|
+
|
|
85
|
+
def test_find_security_group_by_id(self):
|
|
86
|
+
sg_id = uuid.uuid4().hex
|
|
87
|
+
sg_name = 'name-' + uuid.uuid4().hex
|
|
88
|
+
data = {
|
|
89
|
+
'security_group': {
|
|
90
|
+
'id': sg_id,
|
|
91
|
+
'name': sg_name,
|
|
92
|
+
'description': 'description-' + uuid.uuid4().hex,
|
|
93
|
+
'tenant_id': 'project-id-' + uuid.uuid4().hex,
|
|
94
|
+
'rules': [],
|
|
95
|
+
}
|
|
316
96
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
{'resource': FAKE_RESOURCE_2},
|
|
320
|
-
{'resource': FAKE_RESOURCE_3},
|
|
97
|
+
self.compute_sdk_client.get.side_effect = [
|
|
98
|
+
fakes.FakeResponse(data=data),
|
|
321
99
|
]
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
100
|
+
|
|
101
|
+
result = compute.find_security_group(self.compute_sdk_client, sg_id)
|
|
102
|
+
|
|
103
|
+
self.compute_sdk_client.get.assert_has_calls(
|
|
104
|
+
[
|
|
105
|
+
mock.call(f'/os-security-groups/{sg_id}', microversion='2.1'),
|
|
106
|
+
]
|
|
107
|
+
)
|
|
108
|
+
self.assertEqual(data['security_group'], result)
|
|
109
|
+
|
|
110
|
+
def test_find_security_group_by_name(self):
|
|
111
|
+
sg_id = uuid.uuid4().hex
|
|
112
|
+
sg_name = 'name-' + uuid.uuid4().hex
|
|
113
|
+
data = {
|
|
114
|
+
'security_groups': [
|
|
115
|
+
{
|
|
116
|
+
'id': sg_id,
|
|
117
|
+
'name': sg_name,
|
|
118
|
+
'description': 'description-' + uuid.uuid4().hex,
|
|
119
|
+
'tenant_id': 'project-id-' + uuid.uuid4().hex,
|
|
120
|
+
'rules': [],
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
}
|
|
124
|
+
self.compute_sdk_client.get.side_effect = [
|
|
125
|
+
fakes.FakeResponse(status_code=http.HTTPStatus.NOT_FOUND),
|
|
126
|
+
fakes.FakeResponse(data=data),
|
|
326
127
|
]
|
|
327
128
|
|
|
328
|
-
self.
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
class TestNetwork(TestComputeAPIv2):
|
|
339
|
-
FAKE_NETWORK_RESP = {
|
|
340
|
-
'id': '1',
|
|
341
|
-
'label': 'label1',
|
|
342
|
-
'cidr': '1.2.3.0/24',
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
FAKE_NETWORK_RESP_2 = {
|
|
346
|
-
'id': '2',
|
|
347
|
-
'label': 'label2',
|
|
348
|
-
'cidr': '4.5.6.0/24',
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
LIST_NETWORK_RESP = [
|
|
352
|
-
FAKE_NETWORK_RESP,
|
|
353
|
-
FAKE_NETWORK_RESP_2,
|
|
354
|
-
]
|
|
355
|
-
|
|
356
|
-
def test_network_create_default(self):
|
|
357
|
-
self.requests_mock.register_uri(
|
|
358
|
-
'POST',
|
|
359
|
-
FAKE_URL + '/os-networks',
|
|
360
|
-
json={'network': self.FAKE_NETWORK_RESP},
|
|
361
|
-
status_code=200,
|
|
362
|
-
)
|
|
363
|
-
ret = self.api.network_create('label1')
|
|
364
|
-
self.assertEqual(self.FAKE_NETWORK_RESP, ret)
|
|
365
|
-
|
|
366
|
-
def test_network_create_options(self):
|
|
367
|
-
self.requests_mock.register_uri(
|
|
368
|
-
'POST',
|
|
369
|
-
FAKE_URL + '/os-networks',
|
|
370
|
-
json={'network': self.FAKE_NETWORK_RESP},
|
|
371
|
-
status_code=200,
|
|
372
|
-
)
|
|
373
|
-
ret = self.api.network_create(
|
|
374
|
-
name='label1',
|
|
375
|
-
subnet='1.2.3.0/24',
|
|
376
|
-
)
|
|
377
|
-
self.assertEqual(self.FAKE_NETWORK_RESP, ret)
|
|
378
|
-
|
|
379
|
-
def test_network_delete_id(self):
|
|
380
|
-
self.requests_mock.register_uri(
|
|
381
|
-
'GET',
|
|
382
|
-
FAKE_URL + '/os-networks/1',
|
|
383
|
-
json={'network': self.FAKE_NETWORK_RESP},
|
|
384
|
-
status_code=200,
|
|
385
|
-
)
|
|
386
|
-
self.requests_mock.register_uri(
|
|
387
|
-
'DELETE',
|
|
388
|
-
FAKE_URL + '/os-networks/1',
|
|
389
|
-
status_code=202,
|
|
390
|
-
)
|
|
391
|
-
ret = self.api.network_delete('1')
|
|
392
|
-
self.assertEqual(202, ret.status_code)
|
|
393
|
-
self.assertEqual("", ret.text)
|
|
394
|
-
|
|
395
|
-
def test_network_delete_name(self):
|
|
396
|
-
self.requests_mock.register_uri(
|
|
397
|
-
'GET',
|
|
398
|
-
FAKE_URL + '/os-networks/label1',
|
|
399
|
-
status_code=404,
|
|
400
|
-
)
|
|
401
|
-
self.requests_mock.register_uri(
|
|
402
|
-
'GET',
|
|
403
|
-
FAKE_URL + '/os-networks',
|
|
404
|
-
json={'networks': self.LIST_NETWORK_RESP},
|
|
405
|
-
status_code=200,
|
|
406
|
-
)
|
|
407
|
-
self.requests_mock.register_uri(
|
|
408
|
-
'DELETE',
|
|
409
|
-
FAKE_URL + '/os-networks/1',
|
|
410
|
-
status_code=202,
|
|
411
|
-
)
|
|
412
|
-
ret = self.api.network_delete('label1')
|
|
413
|
-
self.assertEqual(202, ret.status_code)
|
|
414
|
-
self.assertEqual("", ret.text)
|
|
415
|
-
|
|
416
|
-
def test_network_delete_not_found(self):
|
|
417
|
-
self.requests_mock.register_uri(
|
|
418
|
-
'GET',
|
|
419
|
-
FAKE_URL + '/os-networks/label3',
|
|
420
|
-
status_code=404,
|
|
421
|
-
)
|
|
422
|
-
self.requests_mock.register_uri(
|
|
423
|
-
'GET',
|
|
424
|
-
FAKE_URL + '/os-networks',
|
|
425
|
-
json={'networks': self.LIST_NETWORK_RESP},
|
|
426
|
-
status_code=200,
|
|
129
|
+
result = compute.find_security_group(self.compute_sdk_client, sg_name)
|
|
130
|
+
|
|
131
|
+
self.compute_sdk_client.get.assert_has_calls(
|
|
132
|
+
[
|
|
133
|
+
mock.call(
|
|
134
|
+
f'/os-security-groups/{sg_name}', microversion='2.1'
|
|
135
|
+
),
|
|
136
|
+
mock.call('/os-security-groups', microversion='2.1'),
|
|
137
|
+
]
|
|
427
138
|
)
|
|
139
|
+
self.assertEqual(data['security_groups'][0], result)
|
|
140
|
+
|
|
141
|
+
def test_find_security_group_not_found(self):
|
|
142
|
+
data = {'security_groups': []}
|
|
143
|
+
self.compute_sdk_client.get.side_effect = [
|
|
144
|
+
fakes.FakeResponse(status_code=http.HTTPStatus.NOT_FOUND),
|
|
145
|
+
fakes.FakeResponse(data=data),
|
|
146
|
+
]
|
|
428
147
|
self.assertRaises(
|
|
429
148
|
osc_lib_exceptions.NotFound,
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
self.requests_mock.register_uri(
|
|
461
|
-
'GET',
|
|
462
|
-
FAKE_URL + '/os-networks/label3',
|
|
463
|
-
status_code=404,
|
|
464
|
-
)
|
|
465
|
-
self.requests_mock.register_uri(
|
|
466
|
-
'GET',
|
|
467
|
-
FAKE_URL + '/os-networks',
|
|
468
|
-
json={'networks': self.LIST_NETWORK_RESP},
|
|
469
|
-
status_code=200,
|
|
470
|
-
)
|
|
149
|
+
compute.find_security_group,
|
|
150
|
+
self.compute_sdk_client,
|
|
151
|
+
'invalid-sg',
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
def test_find_security_group_by_name_duplicate(self):
|
|
155
|
+
sg_name = 'name-' + uuid.uuid4().hex
|
|
156
|
+
data = {
|
|
157
|
+
'security_groups': [
|
|
158
|
+
{
|
|
159
|
+
'id': uuid.uuid4().hex,
|
|
160
|
+
'name': sg_name,
|
|
161
|
+
'description': 'description-' + uuid.uuid4().hex,
|
|
162
|
+
'tenant_id': 'project-id-' + uuid.uuid4().hex,
|
|
163
|
+
'rules': [],
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
'id': uuid.uuid4().hex,
|
|
167
|
+
'name': sg_name,
|
|
168
|
+
'description': 'description-' + uuid.uuid4().hex,
|
|
169
|
+
'tenant_id': 'project-id-' + uuid.uuid4().hex,
|
|
170
|
+
'rules': [],
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
}
|
|
174
|
+
self.compute_sdk_client.get.side_effect = [
|
|
175
|
+
fakes.FakeResponse(status_code=http.HTTPStatus.NOT_FOUND),
|
|
176
|
+
fakes.FakeResponse(data=data),
|
|
177
|
+
]
|
|
178
|
+
|
|
471
179
|
self.assertRaises(
|
|
472
180
|
osc_lib_exceptions.NotFound,
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
'tenant_id': '0123456789',
|
|
494
|
-
'rules': [],
|
|
495
|
-
}
|
|
496
|
-
FAKE_SECURITY_GROUP_RESP_2 = {
|
|
497
|
-
'id': '2',
|
|
498
|
-
'name': 'sg2',
|
|
499
|
-
'description': 'another test security group',
|
|
500
|
-
'tenant_id': '0123456789',
|
|
501
|
-
'rules': [],
|
|
502
|
-
}
|
|
503
|
-
LIST_SECURITY_GROUP_RESP = [
|
|
504
|
-
FAKE_SECURITY_GROUP_RESP_2,
|
|
505
|
-
FAKE_SECURITY_GROUP_RESP,
|
|
506
|
-
]
|
|
507
|
-
|
|
508
|
-
def test_security_group_create_default(self):
|
|
509
|
-
self.requests_mock.register_uri(
|
|
510
|
-
'POST',
|
|
511
|
-
FAKE_URL + '/os-security-groups',
|
|
512
|
-
json={'security_group': self.FAKE_SECURITY_GROUP_RESP},
|
|
513
|
-
status_code=200,
|
|
514
|
-
)
|
|
515
|
-
ret = self.api.security_group_create('sg1')
|
|
516
|
-
self.assertEqual(self.FAKE_SECURITY_GROUP_RESP, ret)
|
|
517
|
-
|
|
518
|
-
def test_security_group_create_options(self):
|
|
519
|
-
self.requests_mock.register_uri(
|
|
520
|
-
'POST',
|
|
521
|
-
FAKE_URL + '/os-security-groups',
|
|
522
|
-
json={'security_group': self.FAKE_SECURITY_GROUP_RESP},
|
|
523
|
-
status_code=200,
|
|
524
|
-
)
|
|
525
|
-
ret = self.api.security_group_create(
|
|
526
|
-
name='sg1',
|
|
527
|
-
description='desc',
|
|
528
|
-
)
|
|
529
|
-
self.assertEqual(self.FAKE_SECURITY_GROUP_RESP, ret)
|
|
530
|
-
|
|
531
|
-
def test_security_group_delete_id(self):
|
|
532
|
-
self.requests_mock.register_uri(
|
|
533
|
-
'GET',
|
|
534
|
-
FAKE_URL + '/os-security-groups/1',
|
|
535
|
-
json={'security_group': self.FAKE_SECURITY_GROUP_RESP},
|
|
536
|
-
status_code=200,
|
|
537
|
-
)
|
|
538
|
-
self.requests_mock.register_uri(
|
|
539
|
-
'DELETE',
|
|
540
|
-
FAKE_URL + '/os-security-groups/1',
|
|
541
|
-
status_code=202,
|
|
542
|
-
)
|
|
543
|
-
ret = self.api.security_group_delete('1')
|
|
544
|
-
self.assertEqual(202, ret.status_code)
|
|
545
|
-
self.assertEqual("", ret.text)
|
|
546
|
-
|
|
547
|
-
def test_security_group_delete_name(self):
|
|
548
|
-
self.requests_mock.register_uri(
|
|
549
|
-
'GET',
|
|
550
|
-
FAKE_URL + '/os-security-groups/sg1',
|
|
551
|
-
status_code=404,
|
|
552
|
-
)
|
|
553
|
-
self.requests_mock.register_uri(
|
|
554
|
-
'GET',
|
|
555
|
-
FAKE_URL + '/os-security-groups',
|
|
556
|
-
json={'security_groups': self.LIST_SECURITY_GROUP_RESP},
|
|
557
|
-
status_code=200,
|
|
558
|
-
)
|
|
559
|
-
self.requests_mock.register_uri(
|
|
560
|
-
'DELETE',
|
|
561
|
-
FAKE_URL + '/os-security-groups/1',
|
|
562
|
-
status_code=202,
|
|
563
|
-
)
|
|
564
|
-
ret = self.api.security_group_delete('sg1')
|
|
565
|
-
self.assertEqual(202, ret.status_code)
|
|
566
|
-
self.assertEqual("", ret.text)
|
|
567
|
-
|
|
568
|
-
def test_security_group_delete_not_found(self):
|
|
569
|
-
self.requests_mock.register_uri(
|
|
570
|
-
'GET',
|
|
571
|
-
FAKE_URL + '/os-security-groups/sg3',
|
|
572
|
-
status_code=404,
|
|
573
|
-
)
|
|
574
|
-
self.requests_mock.register_uri(
|
|
575
|
-
'GET',
|
|
576
|
-
FAKE_URL + '/os-security-groups',
|
|
577
|
-
json={'security_groups': self.LIST_SECURITY_GROUP_RESP},
|
|
578
|
-
status_code=200,
|
|
181
|
+
compute.find_security_group,
|
|
182
|
+
self.compute_sdk_client,
|
|
183
|
+
sg_name,
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
def test_update_security_group(self):
|
|
187
|
+
sg_id = uuid.uuid4().hex
|
|
188
|
+
sg_name = 'name-' + uuid.uuid4().hex
|
|
189
|
+
sg_description = 'description-' + uuid.uuid4().hex
|
|
190
|
+
data = {
|
|
191
|
+
'security_group': {
|
|
192
|
+
'id': sg_id,
|
|
193
|
+
'name': sg_name,
|
|
194
|
+
'description': sg_description,
|
|
195
|
+
'tenant_id': 'project-id-' + uuid.uuid4().hex,
|
|
196
|
+
'rules': [],
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
self.compute_sdk_client.put.return_value = fakes.FakeResponse(
|
|
200
|
+
data=data
|
|
579
201
|
)
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
self.
|
|
583
|
-
'sg3',
|
|
584
|
-
)
|
|
585
|
-
|
|
586
|
-
def test_security_group_find_id(self):
|
|
587
|
-
self.requests_mock.register_uri(
|
|
588
|
-
'GET',
|
|
589
|
-
FAKE_URL + '/os-security-groups/1',
|
|
590
|
-
json={'security_group': self.FAKE_SECURITY_GROUP_RESP},
|
|
591
|
-
status_code=200,
|
|
592
|
-
)
|
|
593
|
-
ret = self.api.security_group_find('1')
|
|
594
|
-
self.assertEqual(self.FAKE_SECURITY_GROUP_RESP, ret)
|
|
595
|
-
|
|
596
|
-
def test_security_group_find_name(self):
|
|
597
|
-
self.requests_mock.register_uri(
|
|
598
|
-
'GET',
|
|
599
|
-
FAKE_URL + '/os-security-groups/sg2',
|
|
600
|
-
status_code=404,
|
|
601
|
-
)
|
|
602
|
-
self.requests_mock.register_uri(
|
|
603
|
-
'GET',
|
|
604
|
-
FAKE_URL + '/os-security-groups',
|
|
605
|
-
json={'security_groups': self.LIST_SECURITY_GROUP_RESP},
|
|
606
|
-
status_code=200,
|
|
607
|
-
)
|
|
608
|
-
ret = self.api.security_group_find('sg2')
|
|
609
|
-
self.assertEqual(self.FAKE_SECURITY_GROUP_RESP_2, ret)
|
|
610
|
-
|
|
611
|
-
def test_security_group_find_not_found(self):
|
|
612
|
-
self.requests_mock.register_uri(
|
|
613
|
-
'GET',
|
|
614
|
-
FAKE_URL + '/os-security-groups/sg3',
|
|
615
|
-
status_code=404,
|
|
616
|
-
)
|
|
617
|
-
self.requests_mock.register_uri(
|
|
618
|
-
'GET',
|
|
619
|
-
FAKE_URL + '/os-security-groups',
|
|
620
|
-
json={'security_groups': self.LIST_SECURITY_GROUP_RESP},
|
|
621
|
-
status_code=200,
|
|
202
|
+
|
|
203
|
+
result = compute.update_security_group(
|
|
204
|
+
self.compute_sdk_client, sg_id, sg_name, sg_description
|
|
622
205
|
)
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
'
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
status_code=
|
|
635
|
-
)
|
|
636
|
-
ret = self.api.security_group_list()
|
|
637
|
-
self.assertEqual(self.LIST_SECURITY_GROUP_RESP, ret)
|
|
638
|
-
|
|
639
|
-
def test_security_group_set_options_id(self):
|
|
640
|
-
self.requests_mock.register_uri(
|
|
641
|
-
'GET',
|
|
642
|
-
FAKE_URL + '/os-security-groups/1',
|
|
643
|
-
json={'security_group': self.FAKE_SECURITY_GROUP_RESP},
|
|
644
|
-
status_code=200,
|
|
645
|
-
)
|
|
646
|
-
self.requests_mock.register_uri(
|
|
647
|
-
'PUT',
|
|
648
|
-
FAKE_URL + '/os-security-groups/1',
|
|
649
|
-
json={'security_group': self.FAKE_SECURITY_GROUP_RESP},
|
|
650
|
-
status_code=200,
|
|
651
|
-
)
|
|
652
|
-
ret = self.api.security_group_set(
|
|
653
|
-
security_group='1', description='desc2'
|
|
654
|
-
)
|
|
655
|
-
self.assertEqual(self.FAKE_SECURITY_GROUP_RESP, ret)
|
|
656
|
-
|
|
657
|
-
def test_security_group_set_options_name(self):
|
|
658
|
-
self.requests_mock.register_uri(
|
|
659
|
-
'GET',
|
|
660
|
-
FAKE_URL + '/os-security-groups/sg2',
|
|
661
|
-
status_code=404,
|
|
662
|
-
)
|
|
663
|
-
self.requests_mock.register_uri(
|
|
664
|
-
'GET',
|
|
665
|
-
FAKE_URL + '/os-security-groups',
|
|
666
|
-
json={'security_groups': self.LIST_SECURITY_GROUP_RESP},
|
|
667
|
-
status_code=200,
|
|
668
|
-
)
|
|
669
|
-
self.requests_mock.register_uri(
|
|
670
|
-
'PUT',
|
|
671
|
-
FAKE_URL + '/os-security-groups/2',
|
|
672
|
-
json={'security_group': self.FAKE_SECURITY_GROUP_RESP_2},
|
|
673
|
-
status_code=200,
|
|
674
|
-
)
|
|
675
|
-
ret = self.api.security_group_set(
|
|
676
|
-
security_group='sg2', description='desc2'
|
|
677
|
-
)
|
|
678
|
-
self.assertEqual(self.FAKE_SECURITY_GROUP_RESP_2, ret)
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
class TestSecurityGroupRule(TestComputeAPIv2):
|
|
682
|
-
FAKE_SECURITY_GROUP_RULE_RESP = {
|
|
683
|
-
'id': '1',
|
|
684
|
-
'name': 'sgr1',
|
|
685
|
-
'tenant_id': 'proj-1',
|
|
686
|
-
'ip_protocol': 'TCP',
|
|
687
|
-
'from_port': 1,
|
|
688
|
-
'to_port': 22,
|
|
689
|
-
'group': {},
|
|
690
|
-
# 'ip_range': ,
|
|
691
|
-
# 'cidr': ,
|
|
692
|
-
# 'parent_group_id': ,
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
def test_security_group_create_no_options(self):
|
|
696
|
-
self.requests_mock.register_uri(
|
|
697
|
-
'POST',
|
|
698
|
-
FAKE_URL + '/os-security-group-rules',
|
|
699
|
-
json={'security_group_rule': self.FAKE_SECURITY_GROUP_RULE_RESP},
|
|
700
|
-
status_code=200,
|
|
701
|
-
)
|
|
702
|
-
ret = self.api.security_group_rule_create(
|
|
703
|
-
security_group_id='1',
|
|
704
|
-
ip_protocol='tcp',
|
|
206
|
+
|
|
207
|
+
self.compute_sdk_client.put.assert_called_once_with(
|
|
208
|
+
f'/os-security-groups/{sg_id}',
|
|
209
|
+
data={'name': sg_name, 'description': sg_description},
|
|
210
|
+
microversion='2.1',
|
|
211
|
+
)
|
|
212
|
+
self.assertEqual(data['security_group'], result)
|
|
213
|
+
|
|
214
|
+
def test_delete_security_group(self):
|
|
215
|
+
sg_id = uuid.uuid4().hex
|
|
216
|
+
self.compute_sdk_client.delete.return_value = fakes.FakeResponse(
|
|
217
|
+
status_code=http.HTTPStatus.NO_CONTENT
|
|
705
218
|
)
|
|
706
|
-
self.assertEqual(self.FAKE_SECURITY_GROUP_RULE_RESP, ret)
|
|
707
219
|
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
status_code=200,
|
|
220
|
+
result = compute.delete_security_group(self.compute_sdk_client, sg_id)
|
|
221
|
+
|
|
222
|
+
self.compute_sdk_client.delete.assert_called_once_with(
|
|
223
|
+
f'/os-security-groups/{sg_id}',
|
|
224
|
+
microversion='2.1',
|
|
714
225
|
)
|
|
715
|
-
|
|
716
|
-
|
|
226
|
+
self.assertIsNone(result)
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
class TestSecurityGroupRule(utils.TestCase):
|
|
230
|
+
|
|
231
|
+
def setUp(self):
|
|
232
|
+
super().setUp()
|
|
233
|
+
|
|
234
|
+
self.compute_sdk_client = mock.Mock(_proxy.Proxy)
|
|
235
|
+
|
|
236
|
+
def test_create_security_group_rule(self):
|
|
237
|
+
sg_id = uuid.uuid4().hex
|
|
238
|
+
data = {
|
|
239
|
+
'security_group_rule': {
|
|
240
|
+
'parent_group_id': sg_id,
|
|
241
|
+
'ip_protocol': 'tcp',
|
|
242
|
+
'from_port': 22,
|
|
243
|
+
'to_port': 22,
|
|
244
|
+
'cidr': '10.0.0.0/24',
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
self.compute_sdk_client.post.return_value = fakes.FakeResponse(
|
|
248
|
+
data=data
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
result = compute.create_security_group_rule(
|
|
252
|
+
self.compute_sdk_client,
|
|
253
|
+
security_group_id=sg_id,
|
|
717
254
|
ip_protocol='tcp',
|
|
718
255
|
from_port=22,
|
|
719
256
|
to_port=22,
|
|
720
|
-
remote_ip='
|
|
257
|
+
remote_ip='10.0.0.0/24',
|
|
258
|
+
remote_group=None,
|
|
721
259
|
)
|
|
722
|
-
self.assertEqual(self.FAKE_SECURITY_GROUP_RULE_RESP, ret)
|
|
723
260
|
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
261
|
+
self.compute_sdk_client.post.assert_called_once_with(
|
|
262
|
+
'/os-security-group-rules',
|
|
263
|
+
data={
|
|
264
|
+
'parent_group_id': sg_id,
|
|
265
|
+
'ip_protocol': 'tcp',
|
|
266
|
+
'from_port': 22,
|
|
267
|
+
'to_port': 22,
|
|
268
|
+
'cidr': '10.0.0.0/24',
|
|
269
|
+
'group_id': None,
|
|
270
|
+
},
|
|
271
|
+
microversion='2.1',
|
|
730
272
|
)
|
|
731
|
-
self.
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
273
|
+
self.assertEqual(data['security_group_rule'], result)
|
|
274
|
+
|
|
275
|
+
def test_delete_security_group_rule(self):
|
|
276
|
+
sg_id = uuid.uuid4().hex
|
|
277
|
+
self.compute_sdk_client.delete.return_value = fakes.FakeResponse(
|
|
278
|
+
status_code=http.HTTPStatus.NO_CONTENT
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
result = compute.delete_security_group_rule(
|
|
282
|
+
self.compute_sdk_client, sg_id
|
|
739
283
|
)
|
|
284
|
+
|
|
285
|
+
self.compute_sdk_client.delete.assert_called_once_with(
|
|
286
|
+
f'/os-security-group-rules/{sg_id}',
|
|
287
|
+
microversion='2.1',
|
|
288
|
+
)
|
|
289
|
+
self.assertIsNone(result)
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
class TestNetwork(utils.TestCase):
|
|
293
|
+
|
|
294
|
+
def setUp(self):
|
|
295
|
+
super().setUp()
|
|
296
|
+
|
|
297
|
+
self.compute_sdk_client = mock.Mock(_proxy.Proxy)
|
|
298
|
+
|
|
299
|
+
def test_create_network(self):
|
|
300
|
+
net_name = 'name-' + uuid.uuid4().hex
|
|
301
|
+
net_subnet = '10.0.0.0/24'
|
|
302
|
+
data = {
|
|
303
|
+
'network': {
|
|
304
|
+
'id': uuid.uuid4().hex,
|
|
305
|
+
'label': net_name,
|
|
306
|
+
'cidr': net_subnet,
|
|
307
|
+
'share_address': True,
|
|
308
|
+
# other fields omitted for brevity
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
self.compute_sdk_client.post.return_value = fakes.FakeResponse(
|
|
312
|
+
data=data
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
result = compute.create_network(
|
|
316
|
+
self.compute_sdk_client,
|
|
317
|
+
name=net_name,
|
|
318
|
+
subnet=net_subnet,
|
|
319
|
+
share_subnet=True,
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
self.compute_sdk_client.post.assert_called_once_with(
|
|
323
|
+
'/os-networks',
|
|
324
|
+
data={
|
|
325
|
+
'label': net_name,
|
|
326
|
+
'cidr': net_subnet,
|
|
327
|
+
'share_address': True,
|
|
328
|
+
},
|
|
329
|
+
microversion='2.1',
|
|
330
|
+
)
|
|
331
|
+
self.assertEqual(data['network'], result)
|
|
332
|
+
|
|
333
|
+
def test_list_networks(self):
|
|
334
|
+
data = {
|
|
335
|
+
'networks': [
|
|
336
|
+
{
|
|
337
|
+
'id': uuid.uuid4().hex,
|
|
338
|
+
'label': f'name-{uuid.uuid4().hex}',
|
|
339
|
+
# other fields omitted for brevity
|
|
340
|
+
}
|
|
341
|
+
],
|
|
342
|
+
}
|
|
343
|
+
self.compute_sdk_client.get.return_value = fakes.FakeResponse(
|
|
344
|
+
data=data
|
|
345
|
+
)
|
|
346
|
+
|
|
347
|
+
result = compute.list_networks(self.compute_sdk_client)
|
|
348
|
+
|
|
349
|
+
self.compute_sdk_client.get.assert_called_once_with(
|
|
350
|
+
'/os-networks', microversion='2.1'
|
|
351
|
+
)
|
|
352
|
+
self.assertEqual(data['networks'], result)
|
|
353
|
+
|
|
354
|
+
def test_find_network_by_id(self):
|
|
355
|
+
net_id = uuid.uuid4().hex
|
|
356
|
+
net_name = 'name-' + uuid.uuid4().hex
|
|
357
|
+
data = {
|
|
358
|
+
'network': {
|
|
359
|
+
'id': net_id,
|
|
360
|
+
'label': net_name,
|
|
361
|
+
# other fields omitted for brevity
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
self.compute_sdk_client.get.side_effect = [
|
|
365
|
+
fakes.FakeResponse(data=data),
|
|
366
|
+
]
|
|
367
|
+
|
|
368
|
+
result = compute.find_network(self.compute_sdk_client, net_id)
|
|
369
|
+
|
|
370
|
+
self.compute_sdk_client.get.assert_has_calls(
|
|
371
|
+
[
|
|
372
|
+
mock.call(f'/os-networks/{net_id}', microversion='2.1'),
|
|
373
|
+
]
|
|
374
|
+
)
|
|
375
|
+
self.assertEqual(data['network'], result)
|
|
376
|
+
|
|
377
|
+
def test_find_network_by_name(self):
|
|
378
|
+
net_id = uuid.uuid4().hex
|
|
379
|
+
net_name = 'name-' + uuid.uuid4().hex
|
|
380
|
+
data = {
|
|
381
|
+
'networks': [
|
|
382
|
+
{
|
|
383
|
+
'id': net_id,
|
|
384
|
+
'label': net_name,
|
|
385
|
+
# other fields omitted for brevity
|
|
386
|
+
}
|
|
387
|
+
],
|
|
388
|
+
}
|
|
389
|
+
self.compute_sdk_client.get.side_effect = [
|
|
390
|
+
fakes.FakeResponse(status_code=http.HTTPStatus.NOT_FOUND),
|
|
391
|
+
fakes.FakeResponse(data=data),
|
|
392
|
+
]
|
|
393
|
+
|
|
394
|
+
result = compute.find_network(self.compute_sdk_client, net_name)
|
|
395
|
+
|
|
396
|
+
self.compute_sdk_client.get.assert_has_calls(
|
|
397
|
+
[
|
|
398
|
+
mock.call(f'/os-networks/{net_name}', microversion='2.1'),
|
|
399
|
+
mock.call('/os-networks', microversion='2.1'),
|
|
400
|
+
]
|
|
401
|
+
)
|
|
402
|
+
self.assertEqual(data['networks'][0], result)
|
|
403
|
+
|
|
404
|
+
def test_find_network_not_found(self):
|
|
405
|
+
data = {'networks': []}
|
|
406
|
+
self.compute_sdk_client.get.side_effect = [
|
|
407
|
+
fakes.FakeResponse(status_code=http.HTTPStatus.NOT_FOUND),
|
|
408
|
+
fakes.FakeResponse(data=data),
|
|
409
|
+
]
|
|
740
410
|
self.assertRaises(
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
411
|
+
osc_lib_exceptions.NotFound,
|
|
412
|
+
compute.find_network,
|
|
413
|
+
self.compute_sdk_client,
|
|
414
|
+
'invalid-net',
|
|
415
|
+
)
|
|
416
|
+
|
|
417
|
+
def test_find_network_by_name_duplicate(self):
|
|
418
|
+
net_name = 'name-' + uuid.uuid4().hex
|
|
419
|
+
data = {
|
|
420
|
+
'networks': [
|
|
421
|
+
{
|
|
422
|
+
'id': uuid.uuid4().hex,
|
|
423
|
+
'label': net_name,
|
|
424
|
+
# other fields omitted for brevity
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
'id': uuid.uuid4().hex,
|
|
428
|
+
'label': net_name,
|
|
429
|
+
# other fields omitted for brevity
|
|
430
|
+
},
|
|
431
|
+
],
|
|
432
|
+
}
|
|
433
|
+
self.compute_sdk_client.get.side_effect = [
|
|
434
|
+
fakes.FakeResponse(status_code=http.HTTPStatus.NOT_FOUND),
|
|
435
|
+
fakes.FakeResponse(data=data),
|
|
436
|
+
]
|
|
437
|
+
|
|
438
|
+
self.assertRaises(
|
|
439
|
+
osc_lib_exceptions.NotFound,
|
|
440
|
+
compute.find_network,
|
|
441
|
+
self.compute_sdk_client,
|
|
442
|
+
net_name,
|
|
443
|
+
)
|
|
444
|
+
|
|
445
|
+
def test_delete_network(self):
|
|
446
|
+
net_id = uuid.uuid4().hex
|
|
447
|
+
self.compute_sdk_client.delete.return_value = fakes.FakeResponse(
|
|
448
|
+
status_code=http.HTTPStatus.NO_CONTENT
|
|
449
|
+
)
|
|
450
|
+
|
|
451
|
+
result = compute.delete_network(self.compute_sdk_client, net_id)
|
|
452
|
+
|
|
453
|
+
self.compute_sdk_client.delete.assert_called_once_with(
|
|
454
|
+
f'/os-networks/{net_id}', microversion='2.1'
|
|
455
|
+
)
|
|
456
|
+
self.assertIsNone(result)
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
class TestFloatingIP(utils.TestCase):
|
|
460
|
+
|
|
461
|
+
def setUp(self):
|
|
462
|
+
super().setUp()
|
|
463
|
+
|
|
464
|
+
self.compute_sdk_client = mock.Mock(_proxy.Proxy)
|
|
465
|
+
|
|
466
|
+
def test_create_floating_ip(self):
|
|
467
|
+
network = 'network-' + uuid.uuid4().hex
|
|
468
|
+
data = {
|
|
469
|
+
'floating_ip': {
|
|
470
|
+
'fixed_ip': None,
|
|
471
|
+
'id': uuid.uuid4().hex,
|
|
472
|
+
'instance_id': None,
|
|
473
|
+
'ip': '172.24.4.17',
|
|
474
|
+
'pool': network,
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
self.compute_sdk_client.post.return_value = fakes.FakeResponse(
|
|
478
|
+
data=data
|
|
748
479
|
)
|
|
749
480
|
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
481
|
+
result = compute.create_floating_ip(
|
|
482
|
+
self.compute_sdk_client, network=network
|
|
483
|
+
)
|
|
484
|
+
|
|
485
|
+
self.compute_sdk_client.post.assert_called_once_with(
|
|
486
|
+
'/os-floating-ips', data={'pool': network}, microversion='2.1'
|
|
487
|
+
)
|
|
488
|
+
self.assertEqual(data['floating_ip'], result)
|
|
489
|
+
|
|
490
|
+
def test_list_floating_ips(self):
|
|
491
|
+
data = {
|
|
492
|
+
'floating_ips': [
|
|
493
|
+
{
|
|
494
|
+
'fixed_ip': None,
|
|
495
|
+
'id': uuid.uuid4().hex,
|
|
496
|
+
'instance_id': None,
|
|
497
|
+
'ip': '172.24.4.17',
|
|
498
|
+
'pool': f'network-{uuid.uuid4().hex}',
|
|
499
|
+
}
|
|
500
|
+
],
|
|
501
|
+
}
|
|
502
|
+
self.compute_sdk_client.get.return_value = fakes.FakeResponse(
|
|
503
|
+
data=data
|
|
504
|
+
)
|
|
505
|
+
|
|
506
|
+
result = compute.list_floating_ips(self.compute_sdk_client)
|
|
507
|
+
|
|
508
|
+
self.compute_sdk_client.get.assert_called_once_with(
|
|
509
|
+
'/os-floating-ips', microversion='2.1'
|
|
510
|
+
)
|
|
511
|
+
self.assertEqual(data['floating_ips'], result)
|
|
512
|
+
|
|
513
|
+
def test_get_floating_ip(self):
|
|
514
|
+
fip_id = uuid.uuid4().hex
|
|
515
|
+
data = {
|
|
516
|
+
'floating_ip': {
|
|
517
|
+
'fixed_ip': None,
|
|
518
|
+
'id': fip_id,
|
|
519
|
+
'instance_id': None,
|
|
520
|
+
'ip': '172.24.4.17',
|
|
521
|
+
'pool': f'network-{uuid.uuid4().hex}',
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
self.compute_sdk_client.get.side_effect = [
|
|
525
|
+
fakes.FakeResponse(data=data),
|
|
526
|
+
]
|
|
527
|
+
|
|
528
|
+
result = compute.get_floating_ip(self.compute_sdk_client, fip_id)
|
|
529
|
+
|
|
530
|
+
self.compute_sdk_client.get.assert_called_once_with(
|
|
531
|
+
f'/os-floating-ips/{fip_id}', microversion='2.1'
|
|
532
|
+
)
|
|
533
|
+
self.assertEqual(data['floating_ip'], result)
|
|
534
|
+
|
|
535
|
+
def test_delete_floating_ip(self):
|
|
536
|
+
fip_id = uuid.uuid4().hex
|
|
537
|
+
self.compute_sdk_client.delete.return_value = fakes.FakeResponse(
|
|
538
|
+
status_code=http.HTTPStatus.NO_CONTENT
|
|
539
|
+
)
|
|
540
|
+
|
|
541
|
+
result = compute.delete_floating_ip(self.compute_sdk_client, fip_id)
|
|
542
|
+
|
|
543
|
+
self.compute_sdk_client.delete.assert_called_once_with(
|
|
544
|
+
f'/os-floating-ips/{fip_id}', microversion='2.1'
|
|
545
|
+
)
|
|
546
|
+
self.assertIsNone(result)
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
class TestFloatingIPPool(utils.TestCase):
|
|
550
|
+
|
|
551
|
+
def setUp(self):
|
|
552
|
+
super().setUp()
|
|
553
|
+
|
|
554
|
+
self.compute_sdk_client = mock.Mock(_proxy.Proxy)
|
|
555
|
+
|
|
556
|
+
def test_list_floating_ip_pools(self):
|
|
557
|
+
data = {
|
|
558
|
+
'floating_ip_pools': [
|
|
559
|
+
{
|
|
560
|
+
'name': f'pool-{uuid.uuid4().hex}',
|
|
561
|
+
}
|
|
562
|
+
],
|
|
563
|
+
}
|
|
564
|
+
self.compute_sdk_client.get.return_value = fakes.FakeResponse(
|
|
565
|
+
data=data
|
|
566
|
+
)
|
|
567
|
+
|
|
568
|
+
result = compute.list_floating_ip_pools(self.compute_sdk_client)
|
|
569
|
+
|
|
570
|
+
self.compute_sdk_client.get.assert_called_once_with(
|
|
571
|
+
'/os-floating-ip-pools', microversion='2.1'
|
|
755
572
|
)
|
|
756
|
-
|
|
757
|
-
self.assertEqual(202, ret.status_code)
|
|
758
|
-
self.assertEqual("", ret.text)
|
|
573
|
+
self.assertEqual(data['floating_ip_pools'], result)
|