fog-google 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +5 -5
  2. data/.codecov.yml +2 -0
  3. data/.rubocop.yml +4 -1
  4. data/CHANGELOG.md +51 -0
  5. data/CONTRIBUTING.md +85 -17
  6. data/CONTRIBUTORS.md +6 -4
  7. data/Gemfile +6 -0
  8. data/MIGRATING.md +1 -11
  9. data/README.md +15 -4
  10. data/ci/credentials.yml.template +2 -0
  11. data/ci/docker-image/Dockerfile +1 -3
  12. data/ci/pipeline.yml +117 -12
  13. data/ci/tasks/run-int.sh +3 -2
  14. data/ci/tasks/run-int.yml +1 -1
  15. data/examples/create_instance.rb +40 -25
  16. data/examples/get_list_images.rb +1 -1
  17. data/examples/load-balance.rb +1 -1
  18. data/examples/metadata.rb +1 -1
  19. data/examples/network.rb +1 -1
  20. data/fog-google.gemspec +8 -6
  21. data/lib/fog/compute/google/models/address.rb +1 -1
  22. data/lib/fog/compute/google/models/backend_service.rb +1 -1
  23. data/lib/fog/compute/google/models/disk.rb +2 -2
  24. data/lib/fog/compute/google/models/firewall.rb +23 -3
  25. data/lib/fog/compute/google/models/forwarding_rule.rb +1 -1
  26. data/lib/fog/compute/google/models/global_address.rb +1 -1
  27. data/lib/fog/compute/google/models/global_forwarding_rule.rb +1 -1
  28. data/lib/fog/compute/google/models/http_health_check.rb +2 -2
  29. data/lib/fog/compute/google/models/image.rb +1 -1
  30. data/lib/fog/compute/google/models/instance_group_manager.rb +1 -1
  31. data/lib/fog/compute/google/models/instance_template.rb +1 -1
  32. data/lib/fog/compute/google/models/route.rb +1 -1
  33. data/lib/fog/compute/google/models/server.rb +59 -5
  34. data/lib/fog/compute/google/models/servers.rb +1 -1
  35. data/lib/fog/compute/google/models/ssl_certificate.rb +1 -1
  36. data/lib/fog/compute/google/models/subnetwork.rb +1 -1
  37. data/lib/fog/compute/google/models/target_http_proxy.rb +1 -1
  38. data/lib/fog/compute/google/models/target_https_proxy.rb +14 -1
  39. data/lib/fog/compute/google/models/target_instance.rb +1 -1
  40. data/lib/fog/compute/google/models/target_pool.rb +1 -1
  41. data/lib/fog/compute/google/models/url_map.rb +1 -1
  42. data/lib/fog/compute/google/requests/insert_server.rb +1 -1
  43. data/lib/fog/dns/google/models/record.rb +1 -1
  44. data/lib/fog/google/models/sql/instance.rb +1 -1
  45. data/lib/fog/google/models/sql/user.rb +1 -1
  46. data/lib/fog/google/version.rb +1 -1
  47. data/lib/fog/storage/google_json.rb +4 -1
  48. data/lib/fog/storage/google_json/mock.rb +3 -0
  49. data/lib/fog/storage/google_json/models/file.rb +2 -2
  50. data/lib/fog/storage/google_json/models/files.rb +2 -2
  51. data/lib/fog/storage/google_json/real.rb +3 -0
  52. data/lib/fog/storage/google_json/requests/get_object_http_url.rb +6 -7
  53. data/lib/fog/storage/google_json/requests/get_object_https_url.rb +6 -7
  54. data/lib/fog/storage/google_json/requests/get_object_url.rb +4 -4
  55. data/lib/fog/storage/google_json/utils.rb +7 -1
  56. data/lib/fog/storage/google_xml/models/file.rb +2 -2
  57. data/lib/fog/storage/google_xml/models/files.rb +4 -4
  58. data/lib/fog/storage/google_xml/requests/get_object_http_url.rb +8 -7
  59. data/lib/fog/storage/google_xml/requests/get_object_https_url.rb +7 -7
  60. data/lib/fog/storage/google_xml/requests/get_object_url.rb +5 -4
  61. data/lib/fog/storage/google_xml/utils.rb +7 -1
  62. data/tasks/test.rake +45 -23
  63. data/test/helpers/integration_test_helper.rb +67 -0
  64. data/test/helpers/test_helper.rb +14 -10
  65. data/test/integration/compute/core_compute/test_coverage.rb +6 -0
  66. data/test/integration/compute/{test_disk_types.rb → core_compute/test_disk_types.rb} +0 -0
  67. data/test/integration/compute/{disks/test_compute_disk_models.rb → core_compute/test_disks.rb} +0 -0
  68. data/test/integration/compute/{test_images.rb → core_compute/test_images.rb} +0 -0
  69. data/test/integration/compute/core_compute/test_machine_types.rb +42 -0
  70. data/test/integration/compute/core_compute/test_operations.rb +27 -0
  71. data/test/integration/compute/core_compute/test_projects.rb +19 -0
  72. data/test/integration/compute/{test_regions.rb → core_compute/test_regions.rb} +0 -0
  73. data/test/integration/compute/core_compute/test_servers.rb +109 -0
  74. data/test/integration/compute/{test_snapshots.rb → core_compute/test_snapshots.rb} +0 -0
  75. data/test/integration/compute/core_compute/test_zones.rb +35 -0
  76. data/test/integration/compute/core_networking/test_addresses.rb +84 -0
  77. data/test/integration/compute/core_networking/test_coverage.rb +6 -0
  78. data/test/integration/compute/core_networking/test_firewalls.rb +11 -0
  79. data/test/integration/compute/core_networking/test_networks.rb +41 -0
  80. data/test/integration/compute/core_networking/test_routes.rb +26 -0
  81. data/test/integration/compute/core_networking/test_subnetworks.rb +11 -0
  82. data/test/integration/compute/instance_groups/test_coverage.rb +6 -0
  83. data/test/integration/compute/{test_instance_group_managers.rb → instance_groups/test_instance_group_managers.rb} +0 -0
  84. data/test/integration/compute/instance_groups/test_instance_groups.rb +11 -0
  85. data/test/integration/compute/{test_instance_templates.rb → instance_groups/test_instance_templates.rb} +0 -0
  86. data/test/integration/compute/{test_backend_services.rb → loadbalancing/test_backend_services.rb} +0 -0
  87. data/test/integration/compute/loadbalancing/test_coverage.rb +6 -0
  88. data/test/integration/compute/{test_forwarding_rules.rb → loadbalancing/test_forwarding_rules.rb} +0 -0
  89. data/test/integration/compute/loadbalancing/test_global_addresses.rb +11 -0
  90. data/test/integration/compute/{test_global_forwarding_rules.rb → loadbalancing/test_global_forwarding_rules.rb} +0 -0
  91. data/test/integration/compute/{test_http_health_checks.rb → loadbalancing/test_http_health_checks.rb} +0 -0
  92. data/test/integration/compute/loadbalancing/test_ssl_certificates.rb +11 -0
  93. data/test/integration/compute/{test_target_http_proxies.rb → loadbalancing/test_target_http_proxies.rb} +0 -0
  94. data/test/integration/compute/loadbalancing/test_target_https_proxies.rb +11 -0
  95. data/test/integration/compute/{test_target_instances.rb → loadbalancing/test_target_instances.rb} +0 -0
  96. data/test/integration/compute/loadbalancing/test_target_pools.rb +55 -0
  97. data/test/integration/compute/{test_url_maps.rb → loadbalancing/test_url_maps.rb} +0 -0
  98. data/test/integration/factories/addresses_factory.rb +16 -0
  99. data/test/integration/factories/collection_factory.rb +24 -3
  100. data/test/integration/factories/disks_factory.rb +1 -0
  101. data/test/integration/factories/firewalls_factory.rb +13 -0
  102. data/test/integration/factories/global_addresses_factory.rb +15 -0
  103. data/test/integration/factories/instance_groups_factory.rb +16 -0
  104. data/test/integration/factories/instance_template_factory.rb +1 -0
  105. data/test/integration/factories/networks_factory.rb +16 -0
  106. data/test/integration/factories/ssl_certificates_factory.rb +13 -0
  107. data/test/integration/factories/subnetworks_factory.rb +22 -0
  108. data/test/integration/factories/target_https_proxies_factory.rb +26 -0
  109. data/test/integration/factories/target_pools_factory.rb +2 -2
  110. data/test/integration/monitoring/test_coverage.rb +6 -0
  111. data/test/integration/monitoring/test_timeseries.rb +1 -1
  112. data/test/integration/pubsub/test_coverage.rb +6 -0
  113. data/test/integration/sql/{test_common_flags.rb → sqlv1/test_common_flags.rb} +0 -0
  114. data/test/integration/sql/{test_common_tiers.rb → sqlv1/test_common_tiers.rb} +0 -0
  115. data/test/integration/sql/sqlv1/test_coverage.rb +6 -0
  116. data/test/integration/sql/{test_v1_certs.rb → sqlv1/test_v1_certs.rb} +0 -0
  117. data/test/integration/sql/{test_v1_instances.rb → sqlv1/test_v1_instances.rb} +0 -0
  118. data/test/integration/sql/{test_v1_users.rb → sqlv1/test_v1_users.rb} +0 -0
  119. data/test/integration/sql/sqlv2/test_coverage.rb +6 -0
  120. data/test/integration/sql/{test_v2_instances.rb → sqlv2/test_v2_instances.rb} +0 -0
  121. data/test/integration/storage/test_coverage.rb +6 -0
  122. data/test/unit/storage/test_json_requests.rb +45 -0
  123. data/test/unit/storage/test_xml_requests.rb +20 -0
  124. metadata +115 -92
  125. data/test/integration/compute/addresses/addresses_shared.rb +0 -59
  126. data/test/integration/compute/addresses/test_compute_address_models.rb +0 -105
  127. data/test/integration/compute/addresses/test_compute_address_requests.rb +0 -52
  128. data/test/integration/compute/disks/test_compute_disk_requests.rb +0 -92
  129. data/test/integration/compute/test_compute_addresses_collection.rb +0 -75
  130. data/test/integration/compute/test_compute_networks_collection.rb +0 -69
  131. data/test/integration/compute/test_servers.rb +0 -54
  132. data/test/integration/compute/test_target_pools.rb +0 -38
@@ -1,59 +0,0 @@
1
- require "helpers/integration_test_helper"
2
- require "helpers/client_helper"
3
- require "securerandom"
4
-
5
- class TestComputeAddressShared < FogIntegrationTest
6
- DEFAULT_REGION = "us-central1".freeze
7
- ADDRESS_RESOURCE_PREFIX = "fog-int-test-address".freeze
8
-
9
- include ClientHelper
10
-
11
- def delete_test_resources
12
- client = Fog::Compute::Google.new
13
- addresses = client.addresses.all(:region => DEFAULT_REGION)
14
- unless addresses.nil?
15
- addresses
16
- .select { |a| a.name.start_with?(ADDRESS_RESOURCE_PREFIX) }
17
- .each do |a|
18
- Fog.wait_for do
19
- unless a.ready?
20
- false
21
- end
22
-
23
- begin
24
- client.delete_address(a.name, DEFAULT_REGION)
25
- rescue ::Google::Apis::ClientError => e
26
- if e.status_code == 400 || e.status_code == 404
27
- return e.status_code == 404
28
- end
29
- raise e
30
- else
31
- true
32
- end
33
- end
34
- end
35
- end
36
- end
37
-
38
- attr_reader :client
39
-
40
- def setup
41
- @client = Fog::Compute::Google.new
42
- end
43
-
44
- def teardown
45
- delete_test_resources
46
- end
47
-
48
- def new_address_name
49
- "#{ADDRESS_RESOURCE_PREFIX}-#{SecureRandom.uuid}"
50
- end
51
-
52
- def some_address_name
53
- # created lazily to speed tests up
54
- @some_address ||= new_address_name.tap do |a|
55
- result = @client.insert_address(a, DEFAULT_REGION)
56
- Fog.wait_for { operation_finished?(result) }
57
- end
58
- end
59
- end
@@ -1,105 +0,0 @@
1
- require "helpers/integration_test_helper"
2
- require "integration/compute/addresses/addresses_shared"
3
- require "helpers/client_helper"
4
- require "securerandom"
5
-
6
- class TestComputeAddressModels < TestComputeAddressShared
7
- def test_addresses_create
8
- address_name = new_address_name
9
- address = @client.addresses.create(
10
- :name => address_name,
11
- :region => DEFAULT_REGION
12
- )
13
- assert_equal(address_name, address.name, "address should have same name")
14
- assert_nil(address.users, "new address should have no users")
15
- end
16
-
17
- def test_addresses_get
18
- address = @client.addresses.get(some_address_name, DEFAULT_REGION)
19
-
20
- assert_equal(some_address_name, address.name, "address should have same name")
21
- end
22
-
23
- def test_addresses_get_address_by_ip
24
- # Fetch a preexisting address to learn its IP
25
- address = @client.addresses.get(some_address_name, DEFAULT_REGION)
26
-
27
- found = @client.addresses.get_by_ip_address(address.address)
28
-
29
- assert_equal(address.name, found.name, "address should have same name")
30
- assert_equal(address.address, found.address, "addresses should match")
31
- end
32
-
33
- def test_addresses_get_address_by_name
34
- # Fetch a preexisting address to learn its IP
35
- address = @client.addresses.get(some_address_name, DEFAULT_REGION)
36
-
37
- found = @client.addresses.get_by_name(some_address_name)
38
-
39
- assert_equal(address.name, found.name, "address should have same name")
40
- assert_equal(address.address, found.address, "addresses should match")
41
- end
42
-
43
- def test_addresses_get_by_ip_address_or_name
44
- # Fetch a preexisting address to learn its IP
45
- address = @client.addresses.get(some_address_name, DEFAULT_REGION)
46
-
47
- # Ensure we find the same addresses through both codepaths
48
- with_name = @client.addresses.get_by_ip_address_or_name(some_address_name)
49
- with_ip = @client.addresses.get_by_ip_address_or_name(address.address)
50
-
51
- assert_equal(address.name, with_name.name, "address should have same name")
52
- assert_equal(address.address, with_name.address, "addresses should match")
53
-
54
- assert_equal(with_name.name, with_ip.name, "address should have same name")
55
- assert_equal(with_name.address, with_ip.address, "addresses should match")
56
- end
57
-
58
- def test_addresses_all
59
- # Fetch a preexisting address to learn its IP
60
- address = @client.addresses.get(some_address_name, DEFAULT_REGION)
61
-
62
- found = @client.addresses.all
63
-
64
- assert_operator(found.size, :>, 0, "address count should be positive")
65
- assert_includes(found.map(&:name), address.name, "pre-existing address should be present")
66
- end
67
-
68
- def test_addresses_destroy
69
- # Make a existing address to delete
70
- address_name = new_address_name
71
- address = @client.addresses.create(
72
- :name => address_name,
73
- :region => DEFAULT_REGION
74
- )
75
-
76
- # Force synchronous for easier testing
77
- address.destroy(false)
78
-
79
- assert_raises(Google::Apis::ClientError) do
80
- @client.get_address(address_name, DEFAULT_REGION)
81
- end
82
- end
83
-
84
- def test_addresses_in_use
85
- # Make a existing address to delete
86
- address = @client.addresses.get(some_address_name, DEFAULT_REGION)
87
-
88
- assert_equal(false, address.in_use?, "address should not be in use")
89
- end
90
-
91
- def test_address_associate
92
- # TODO: implement when servers are implemented @everlag
93
- skip
94
- end
95
-
96
- def test_address_disassociate
97
- # TODO: implement when servers are implemented @everlag
98
- skip
99
- end
100
-
101
- def test_address_server_set
102
- # TODO: implement when servers are implemented @everlag
103
- skip
104
- end
105
- end
@@ -1,52 +0,0 @@
1
- require "helpers/integration_test_helper"
2
- require "integration/compute/addresses/addresses_shared"
3
- require "helpers/client_helper"
4
- require "securerandom"
5
-
6
- class TestComputeAddressRequests < TestComputeAddressShared
7
- def test_insert_address
8
- result = wait_until_complete { @client.insert_address(new_address_name, DEFAULT_REGION) }
9
-
10
- assert_equal("DONE", result.status, "request should be successful")
11
- assert_nil(result.error, "result should contain no errors")
12
- end
13
-
14
- def test_get_address
15
- result = @client.get_address(some_address_name, DEFAULT_REGION)
16
-
17
- assert_equal("RESERVED", result.status, "request should be successful")
18
- assert_includes(result.name, some_address_name, "resulting address should have expected name")
19
- end
20
-
21
- def test_list_address
22
- # Let's create at least one address so there's something to view
23
- known_address = new_address_name
24
- wait_until_complete { @client.insert_address(known_address, DEFAULT_REGION) }
25
-
26
- result = @client.list_addresses(DEFAULT_REGION)
27
- assert_operator(result.items.size, :>, 0, "address count should be positive")
28
- assert_includes(result.items.map(&:name), known_address, "pre-existing address should be present")
29
- end
30
-
31
- def test_delete_address
32
- # Create something to delete
33
- address_to_delete = new_address_name
34
- wait_until_complete { @client.insert_address(address_to_delete, DEFAULT_REGION) }
35
-
36
- result = wait_until_complete { @client.delete_address(address_to_delete, DEFAULT_REGION) }
37
-
38
- assert_nil(result.error, "result should contain no errors")
39
-
40
- assert_raises(Google::Apis::ClientError) do
41
- @client.get_address(address_to_delete, DEFAULT_REGION)
42
- end
43
- end
44
-
45
- def test_list_aggregated_addresses
46
- @client.get_address(some_address_name, DEFAULT_REGION)
47
- result = @client.list_aggregated_addresses
48
-
49
- assert_operator(result.items.size, :>, 0, "address count should be positive")
50
- assert_includes(result.items.keys, "global", "'items' subset should contain global keyword")
51
- end
52
- end
@@ -1,92 +0,0 @@
1
- require "helpers/integration_test_helper"
2
- require "helpers/client_helper"
3
- require "securerandom"
4
-
5
- class TestComputeDiskRequests < FogIntegrationTest
6
- DEFAULT_ZONE = "us-central1-a".freeze
7
- DISK_RESOURCE_PREFIX = "fog-test-disk".freeze
8
-
9
- include ClientHelper
10
-
11
- def delete_test_resources
12
- client = Fog::Compute::Google.new
13
- disks = client.disks.all(:zone => DEFAULT_ZONE)
14
- unless disks.nil?
15
- disks
16
- .select { |d| d.name.start_with?(DISK_RESOURCE_PREFIX) }
17
- .each do |d|
18
- d.wait_for { ready? }
19
- client.delete_disk(d.name, DEFAULT_ZONE)
20
- end
21
- end
22
- end
23
-
24
- attr_reader :client
25
-
26
- def setup
27
- @client = Fog::Compute::Google.new
28
- end
29
-
30
- def teardown
31
- delete_test_resources
32
- end
33
-
34
- def new_disk_name
35
- "#{DISK_RESOURCE_PREFIX}-#{SecureRandom.uuid}"
36
- end
37
-
38
- def some_disk_name
39
- # created lazily to speed tests up
40
- @some_disk ||= new_disk_name.tap do |a|
41
- result = @client.insert_disk(a, DEFAULT_ZONE, nil, :size_gb => 10)
42
- Fog.wait_for { operation_finished?(result) }
43
- end
44
- end
45
-
46
- def test_insert_disk
47
- result = wait_until_complete do
48
- @client.insert_disk(new_disk_name, DEFAULT_ZONE, nil, :size_gb => 10)
49
- end
50
-
51
- assert_equal("DONE", result.status, "request should be successful")
52
- assert_nil(result.error, "result should contain no errors")
53
- end
54
-
55
- def test_get_disk
56
- result = @client.get_disk(some_disk_name, DEFAULT_ZONE)
57
-
58
- assert_equal("READY", result.status, "request should be successful")
59
- assert_includes(result.name, some_disk_name, "resulting disk should have expected name")
60
- end
61
-
62
- def test_list_disks
63
- # Let's create at least one disk so there's something to view
64
- known_disk = some_disk_name
65
-
66
- result = @client.list_disks(DEFAULT_ZONE)
67
- assert_operator(result.items.size, :>, 0, "disk count should be positive")
68
- assert_includes(result.items.map(&:name), known_disk, "pre-existing disk should be present")
69
- end
70
-
71
- def test_delete_disk
72
- # Create something to delete
73
- disk_to_delete = new_disk_name
74
- wait_until_complete { @client.insert_disk(disk_to_delete, DEFAULT_ZONE, nil, :size_gb => 10) }
75
-
76
- result = wait_until_complete { @client.delete_disk(disk_to_delete, DEFAULT_ZONE) }
77
-
78
- assert_nil(result.error, "result should contain no errors")
79
-
80
- assert_raises(Google::Apis::ClientError) do
81
- @client.get_disk(disk_to_delete, DEFAULT_ZONE)
82
- end
83
- end
84
-
85
- def test_list_aggregated_disks
86
- @client.get_disk(some_disk_name, DEFAULT_ZONE)
87
- result = @client.list_aggregated_disks
88
-
89
- assert_operator(result.items.size, :>, 0, "address count should be positive")
90
- assert_includes(result.items.keys, "zones/#{DEFAULT_ZONE}", "'items' subset should contain zones/#{DEFAULT_ZONE} keyword")
91
- end
92
- end
@@ -1,75 +0,0 @@
1
- require "helpers/integration_test_helper"
2
- require "securerandom"
3
-
4
- class TestComputeAddressesCollection < FogIntegrationTest
5
- DEFAULT_REGION = "us-central1".freeze
6
- DEFAULT_ZONE = "us-central1-b".freeze
7
- RESOURCE_PREFIX = "fog-test-addresscol".freeze
8
- TEST_ASYNC = false
9
-
10
- # Ensure we clean up any created resources
11
- Minitest.after_run do
12
- client = Fog::Compute::Google.new
13
- client.addresses.each { |a| a.destroy(TEST_ASYNC) if a.name.start_with?(RESOURCE_PREFIX) }
14
- client.servers.each { |s| s.destroy(TEST_ASYNC) if s.name.start_with?(RESOURCE_PREFIX) }
15
- end
16
-
17
- def test_address_workflow
18
- client = Fog::Compute::Google.new
19
-
20
- my_address_name = new_resource_name
21
- # An address can be created by specifying a name and a region
22
- my_address = client.addresses.create(
23
- :name => my_address_name,
24
- :region => DEFAULT_REGION
25
- )
26
- # TODO: Shouldn't this be returning an operation object that we have to explicitly wait for?
27
- assert_equal(my_address_name, my_address.name, "My address should have the provided name")
28
- assert_equal("RESERVED", my_address.status, "My address should not be in use")
29
-
30
- # It should also be visible when listing addresses
31
- assert_includes(client.addresses.all.map(&:name), my_address_name)
32
-
33
- # Be aware that although the address resource is created, it might not yet
34
- # have an ip address. You can poll until the address has been assigned.
35
- my_address.wait_for { !my_address.address.nil? }
36
- assert_match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/,
37
- my_address.address,
38
- "My address's address should have a valid ipv4 address")
39
-
40
- # Now that we have an address, we can create a server using the static ip
41
- my_server = client.servers.create(
42
- :name => new_resource_name,
43
- :machine_type => "f1-micro",
44
- :zone => client.zones.get(DEFAULT_ZONE).self_link,
45
- :disks => [
46
- :boot => true,
47
- :auto_delete => true,
48
- :initialize_params => {
49
- :source_image => "projects/debian-cloud/global/images/family/debian-8"
50
- }
51
- ],
52
- :external_ip => my_address.address
53
- )
54
- my_server.wait_for { staging? }
55
-
56
- # And verify that it's correctly assigned
57
- assert_equal(
58
- my_address.address,
59
- my_server.network_interfaces[0][:access_configs][0][:nat_ip],
60
- "My created server should have the same ip as my address"
61
- )
62
-
63
- # If we look up the address again by name, we should see that it is now
64
- # in use
65
- assert_equal(
66
- "IN_USE",
67
- client.addresses.get(my_address_name, DEFAULT_REGION).status,
68
- "Address should now be in use"
69
- )
70
- end
71
-
72
- def new_resource_name
73
- "#{RESOURCE_PREFIX}-#{SecureRandom.uuid}"
74
- end
75
- end
@@ -1,69 +0,0 @@
1
- require "helpers/integration_test_helper"
2
- require "securerandom"
3
-
4
- class TestComputeNetworksCollection < FogIntegrationTest
5
- DEFAULT_REGION = "us-central1".freeze
6
- DEFAULT_ZONE = "us-central1-b".freeze
7
- RESOURCE_PREFIX = "fog-test-networkscol".freeze
8
- TEST_ASYNC = false
9
-
10
- # Ensure we clean up any created resources
11
- Minitest.after_run do
12
- client = Fog::Compute::Google.new
13
- client.networks.each { |a| a.destroy(TEST_ASYNC) if a.name.start_with?(RESOURCE_PREFIX) }
14
- client.servers.each { |s| s.destroy(TEST_ASYNC) if s.name.start_with?(RESOURCE_PREFIX) }
15
- end
16
-
17
- def test_network_workflow
18
- client = Fog::Compute::Google.new
19
-
20
- my_network_name = new_resource_name
21
- # An address can be created by specifying a name and a region
22
- my_network = client.networks.create(
23
- :name => my_network_name,
24
- :ipv4_range => "10.240.#{rand(255)}.0/24"
25
- )
26
-
27
- assert_equal(my_network_name, my_network.name, "My network should have the provided name")
28
-
29
- # It should also be visible when listing addresses
30
- assert_includes(client.networks.all.map(&:name), my_network_name)
31
-
32
- # Be aware that although the address resource is created, it might not yet
33
- # have an ip address. You can poll until the address has been assigned.
34
- my_network.wait_for(60) { !my_network.ipv4_range.nil? }
35
- assert_match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,2}/,
36
- my_network.ipv4_range,
37
- "My address's address should have a valid ipv4 address")
38
-
39
- # Now that we have an address, we can create a server using the static ip
40
- server_name = new_resource_name
41
-
42
- my_server = client.servers.create(
43
- :name => server_name,
44
- :machine_type => "f1-micro",
45
- :zone => client.zones.get(DEFAULT_ZONE).self_link,
46
- :disks => [
47
- :boot => true,
48
- :auto_delete => true,
49
- :initialize_params => {
50
- :source_image => "projects/debian-cloud/global/images/family/debian-8"
51
- }
52
- ],
53
- :network_interfaces => [my_network.get_as_interface_config]
54
- )
55
-
56
- my_server.wait_for { ready? }
57
-
58
- # We need to verify that the network has been correctly assigned
59
- assert_equal(
60
- my_network.self_link,
61
- my_server.network_interfaces[0][:network],
62
- "My created server should have the network specified as the network"
63
- )
64
- end
65
-
66
- def new_resource_name
67
- "#{RESOURCE_PREFIX}-#{SecureRandom.uuid}"
68
- end
69
- end