Ken'ichi Ohmichi | d7df383 | 2015-01-22 02:56:54 +0000 | [diff] [blame] | 1 | # Copyright 2015 NEC Corporation. All rights reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | import mock |
| 16 | import random |
| 17 | import six |
| 18 | |
| 19 | from tempest.services.compute.json import agents_client |
| 20 | from tempest.services.compute.json import aggregates_client |
| 21 | from tempest.services.compute.json import availability_zone_client |
| 22 | from tempest.services.compute.json import certificates_client |
| 23 | from tempest.services.compute.json import extensions_client |
| 24 | from tempest.services.compute.json import fixed_ips_client |
| 25 | from tempest.services.compute.json import flavors_client |
| 26 | from tempest.services.compute.json import floating_ips_client |
| 27 | from tempest.services.compute.json import hosts_client |
| 28 | from tempest.services.compute.json import hypervisor_client |
| 29 | from tempest.services.compute.json import images_client |
| 30 | from tempest.services.compute.json import instance_usage_audit_log_client |
| 31 | from tempest.services.compute.json import interfaces_client |
| 32 | from tempest.services.compute.json import keypairs_client |
| 33 | from tempest.services.compute.json import limits_client |
| 34 | from tempest.services.compute.json import migrations_client |
| 35 | from tempest.services.compute.json import networks_client as nova_net_client |
| 36 | from tempest.services.compute.json import quotas_client |
| 37 | from tempest.services.compute.json import security_group_default_rules_client \ |
| 38 | as nova_secgrop_default_client |
| 39 | from tempest.services.compute.json import security_groups_client |
| 40 | from tempest.services.compute.json import servers_client |
| 41 | from tempest.services.compute.json import services_client |
| 42 | from tempest.services.compute.json import tenant_usages_client |
| 43 | from tempest.services.compute.json import volumes_extensions_client |
| 44 | from tempest.services.database.json import flavors_client as db_flavor_client |
| 45 | from tempest.services.database.json import versions_client as db_version_client |
| 46 | from tempest.services.network.json import network_client |
| 47 | from tempest.services.orchestration.json import orchestration_client |
| 48 | from tempest.tests import base |
| 49 | |
| 50 | |
| 51 | class TestServiceClient(base.TestCase): |
| 52 | |
| 53 | @mock.patch('tempest_lib.common.rest_client.RestClient.__init__') |
| 54 | def test_service_client_creations_with_specified_args(self, mock_init): |
| 55 | test_clients = [ |
| 56 | agents_client.AgentsClientJSON, |
| 57 | aggregates_client.AggregatesClientJSON, |
| 58 | availability_zone_client.AvailabilityZoneClientJSON, |
| 59 | certificates_client.CertificatesClientJSON, |
| 60 | extensions_client.ExtensionsClientJSON, |
| 61 | fixed_ips_client.FixedIPsClientJSON, |
| 62 | flavors_client.FlavorsClientJSON, |
| 63 | floating_ips_client.FloatingIPsClientJSON, |
| 64 | hosts_client.HostsClientJSON, |
| 65 | hypervisor_client.HypervisorClientJSON, |
| 66 | images_client.ImagesClientJSON, |
| 67 | instance_usage_audit_log_client.InstanceUsagesAuditLogClientJSON, |
| 68 | interfaces_client.InterfacesClientJSON, |
| 69 | keypairs_client.KeyPairsClientJSON, |
| 70 | limits_client.LimitsClientJSON, |
| 71 | migrations_client.MigrationsClientJSON, |
| 72 | nova_net_client.NetworksClientJSON, |
| 73 | quotas_client.QuotasClientJSON, |
| 74 | quotas_client.QuotaClassesClientJSON, |
| 75 | nova_secgrop_default_client.SecurityGroupDefaultRulesClientJSON, |
| 76 | security_groups_client.SecurityGroupsClientJSON, |
| 77 | servers_client.ServersClientJSON, |
| 78 | services_client.ServicesClientJSON, |
| 79 | tenant_usages_client.TenantUsagesClientJSON, |
| 80 | volumes_extensions_client.VolumesExtensionsClientJSON, |
| 81 | db_flavor_client.DatabaseFlavorsClientJSON, |
| 82 | db_version_client.DatabaseVersionsClientJSON, |
| 83 | network_client.NetworkClientJSON, |
| 84 | orchestration_client.OrchestrationClient] |
| 85 | |
| 86 | for client in test_clients: |
| 87 | fake_string = six.text_type(random.randint(1, 0x7fffffff)) |
| 88 | auth = 'auth' + fake_string |
| 89 | service = 'service' + fake_string |
| 90 | region = 'region' + fake_string |
| 91 | params = { |
| 92 | 'endpoint_type': 'URL' + fake_string, |
| 93 | 'build_interval': random.randint(1, 100), |
| 94 | 'build_timeout': random.randint(1, 100), |
| 95 | 'disable_ssl_certificate_validation': |
| 96 | True if random.randint(0, 1) else False, |
| 97 | 'ca_certs': None, |
| 98 | 'trace_requests': 'foo' + fake_string |
| 99 | } |
| 100 | client(auth, service, region, **params) |
| 101 | mock_init.assert_called_once_with(auth, service, region, **params) |
| 102 | mock_init.reset_mock() |