fog-brightbox 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +1 -0
  4. data/CHANGELOG.md +18 -0
  5. data/fog-brightbox.gemspec +1 -0
  6. data/lib/fog/brightbox/compute/shared.rb +1 -1
  7. data/lib/fog/brightbox/oauth2.rb +16 -13
  8. data/lib/fog/brightbox/version.rb +1 -1
  9. data/spec/fog/brightbox/oauth2/client_credentials_strategy_spec.rb +30 -0
  10. data/spec/fog/brightbox/oauth2/credential_set_spec.rb +86 -0
  11. data/spec/fog/brightbox/oauth2/grant_type_strategy_spec.rb +24 -0
  12. data/spec/fog/brightbox/oauth2/refresh_token_strategy_spec.rb +33 -0
  13. data/spec/fog/brightbox/oauth2/user_credentials_strategy_spec.rb +40 -0
  14. data/spec/fog/compute/brightbox/database_server_spec.rb +3 -3
  15. data/spec/fog/compute/brightbox/server_spec.rb +3 -3
  16. data/tests/brightbox/compute/helper.rb +1 -0
  17. data/tests/brightbox/compute/schema.rb +794 -0
  18. data/tests/brightbox/compute_tests.rb +98 -0
  19. data/tests/brightbox/helper.rb +1 -0
  20. data/tests/brightbox/models/compute/account_tests.rb +15 -0
  21. data/tests/brightbox/models/compute/cloud_ip_tests.rb +32 -0
  22. data/tests/brightbox/models/compute/database_server_tests.rb +78 -0
  23. data/tests/brightbox/models/compute/database_snapshot_tests.rb +26 -0
  24. data/tests/brightbox/models/compute/database_type_tests.rb +27 -0
  25. data/tests/brightbox/models/compute/server_tests.rb +19 -0
  26. data/tests/brightbox/requests/compute/account_tests.rb +59 -0
  27. data/tests/brightbox/requests/compute/api_client_tests.rb +59 -0
  28. data/tests/brightbox/requests/compute/application_test.rb +58 -0
  29. data/tests/brightbox/requests/compute/cloud_ip_tests.rb +79 -0
  30. data/tests/brightbox/requests/compute/collaboration_tests.rb +36 -0
  31. data/tests/brightbox/requests/compute/database_server_tests.rb +53 -0
  32. data/tests/brightbox/requests/compute/database_snapsnot_tests.rb +46 -0
  33. data/tests/brightbox/requests/compute/database_type_tests.rb +16 -0
  34. data/tests/brightbox/requests/compute/firewall_policy_tests.rb +39 -0
  35. data/tests/brightbox/requests/compute/firewall_rule_tests.rb +42 -0
  36. data/tests/brightbox/requests/compute/helper.rb +42 -0
  37. data/tests/brightbox/requests/compute/image_tests.rb +54 -0
  38. data/tests/brightbox/requests/compute/interface_tests.rb +30 -0
  39. data/tests/brightbox/requests/compute/load_balancer_tests.rb +116 -0
  40. data/tests/brightbox/requests/compute/server_group_tests.rb +91 -0
  41. data/tests/brightbox/requests/compute/server_tests.rb +93 -0
  42. data/tests/brightbox/requests/compute/server_type_tests.rb +28 -0
  43. data/tests/brightbox/requests/compute/user_collaboration_tests.rb +65 -0
  44. data/tests/brightbox/requests/compute/user_tests.rb +32 -0
  45. data/tests/brightbox/requests/compute/zone_tests.rb +28 -0
  46. data/tests/helper.rb +8 -0
  47. data/tests/helpers/collection_helper.rb +91 -0
  48. data/tests/helpers/compute/flavors_helper.rb +28 -0
  49. data/tests/helpers/compute/server_helper.rb +23 -0
  50. data/tests/helpers/compute/servers_helper.rb +8 -0
  51. data/tests/helpers/formats_helper.rb +98 -0
  52. data/tests/helpers/formats_helper_tests.rb +106 -0
  53. data/tests/helpers/mock_helper.rb +98 -0
  54. data/tests/helpers/model_helper.rb +29 -0
  55. data/tests/helpers/responds_to_helper.rb +11 -0
  56. data/tests/helpers/schema_validator_tests.rb +101 -0
  57. data/tests/helpers/succeeds_helper.rb +9 -0
  58. metadata +68 -2
data/tests/helper.rb ADDED
@@ -0,0 +1,8 @@
1
+ ENV["FOG_RC"] = ENV["FOG_RC"] || File.expand_path("../.fog", __FILE__)
2
+ ENV["FOG_CREDENTIAL"] = ENV["FOG_CREDENTIAL"] || "default"
3
+
4
+ require "fog/brightbox"
5
+
6
+ Excon.defaults.merge!(:debug_request => true, :debug_response => true)
7
+
8
+ require File.expand_path(File.join(File.dirname(__FILE__), "helpers", "mock_helper"))
@@ -0,0 +1,91 @@
1
+ def collection_tests(collection, params = {}, mocks_implemented = true)
2
+ tests("success") do
3
+ tests("#new(#{params.inspect})").succeeds do
4
+ pending if Fog.mocking? && !mocks_implemented
5
+ collection.new(params)
6
+ end
7
+
8
+ tests("#create(#{params.inspect})").succeeds do
9
+ pending if Fog.mocking? && !mocks_implemented
10
+ @instance = collection.create(params)
11
+ end
12
+ # FIXME: work around for timing issue on AWS describe_instances mocks
13
+
14
+ if Fog.mocking? && @instance.respond_to?(:ready?)
15
+ @instance.wait_for { ready? }
16
+ end
17
+
18
+ tests("#all").succeeds do
19
+ pending if Fog.mocking? && !mocks_implemented
20
+ collection.all
21
+ end
22
+
23
+ if !Fog.mocking? || mocks_implemented
24
+ @identity = @instance.identity
25
+ end
26
+
27
+ tests("#get(#{@identity})").succeeds do
28
+ pending if Fog.mocking? && !mocks_implemented
29
+ collection.get(@identity)
30
+ end
31
+
32
+ tests("Enumerable") do
33
+ pending if Fog.mocking? && !mocks_implemented
34
+
35
+ methods = [
36
+ "all?", "any?", "find", "detect", "collect", "map",
37
+ "find_index", "flat_map", "collect_concat", "group_by",
38
+ "none?", "one?"
39
+ ]
40
+
41
+ # JRuby 1.7.5+ issue causes a SystemStackError: stack level too deep
42
+ # https://github.com/jruby/jruby/issues/1265
43
+ if RUBY_PLATFORM == "java" && JRUBY_VERSION =~ /1\.7\.[5-8]/
44
+ methods.delete("all?")
45
+ end
46
+
47
+ methods.each do |enum_method|
48
+ if collection.respond_to?(enum_method)
49
+ tests("##{enum_method}").succeeds do
50
+ block_called = false
51
+ collection.send(enum_method) { |_x| block_called = true }
52
+ block_called
53
+ end
54
+ end
55
+ end
56
+
57
+ %w(
58
+ max_by min_by).each do |enum_method|
59
+ if collection.respond_to?(enum_method)
60
+ tests("##{enum_method}").succeeds do
61
+ block_called = false
62
+ collection.send(enum_method) { |_x| block_called = true; 0 }
63
+ block_called
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ if block_given?
70
+ yield(@instance)
71
+ end
72
+
73
+ if !Fog.mocking? || mocks_implemented
74
+ @instance.destroy
75
+ end
76
+ end
77
+
78
+ tests("failure") do
79
+ if !Fog.mocking? || mocks_implemented
80
+ @identity = @identity.to_s
81
+ @identity = @identity.gsub(/[a-zA-Z]/) { Fog::Mock.random_letters(1) }
82
+ @identity = @identity.gsub(/\d/) { Fog::Mock.random_numbers(1) }
83
+ @identity
84
+ end
85
+
86
+ tests("#get('#{@identity}')").returns(nil) do
87
+ pending if Fog.mocking? && !mocks_implemented
88
+ collection.get(@identity)
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,28 @@
1
+ def flavors_tests(connection, _params = {}, mocks_implemented = true)
2
+ tests("success") do
3
+ tests("#all").succeeds do
4
+ pending if Fog.mocking? && !mocks_implemented
5
+ connection.flavors.all
6
+ end
7
+
8
+ if !Fog.mocking? || mocks_implemented
9
+ @identity = connection.flavors.first.identity
10
+ end
11
+
12
+ tests("#get('#{@identity}')").succeeds do
13
+ pending if Fog.mocking? && !mocks_implemented
14
+ connection.flavors.get(@identity)
15
+ end
16
+ end
17
+
18
+ tests("failure") do
19
+ if !Fog.mocking? || mocks_implemented
20
+ invalid_flavor_identity = connection.flavors.first.identity.to_s.gsub(/\w/, "0")
21
+ end
22
+
23
+ tests("#get('#{invalid_flavor_identity}')").returns(nil) do
24
+ pending if Fog.mocking? && !mocks_implemented
25
+ connection.flavors.get(invalid_flavor_identity)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ def server_tests(connection, params = {}, mocks_implemented = true)
2
+ model_tests(connection.servers, params, mocks_implemented) do
3
+ tests('#reload').returns(true) do
4
+ pending if Fog.mocking? && !mocks_implemented
5
+ @instance.wait_for { ready? }
6
+ identity = @instance.identity
7
+ !identity.nil? && identity == @instance.reload.identity
8
+ end
9
+
10
+ responds_to([:ready?, :state])
11
+ yield if block_given?
12
+
13
+ tests('#reboot').succeeds do
14
+ pending if Fog.mocking? && !mocks_implemented
15
+ @instance.wait_for { ready? }
16
+ @instance.reboot
17
+ end
18
+
19
+ if !Fog.mocking? || mocks_implemented
20
+ @instance.wait_for { ready? }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,8 @@
1
+ def servers_tests(connection, params = {}, mocks_implemented = true)
2
+ collection_tests(connection.servers, params, mocks_implemented) do
3
+ if !Fog.mocking? || mocks_implemented
4
+ @instance.wait_for { ready? }
5
+ yield if block_given?
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,98 @@
1
+ require "fog/schema/data_validator"
2
+
3
+ # format related hackery
4
+ # allows both true.is_a?(Fog::Boolean) and false.is_a?(Fog::Boolean)
5
+ # allows both nil.is_a?(Fog::Nullable::String) and ''.is_a?(Fog::Nullable::String)
6
+ module Fog
7
+ module Boolean; end
8
+ module Nullable
9
+ module Boolean; end
10
+ module Integer; end
11
+ module String; end
12
+ module Time; end
13
+ module Float; end
14
+ module Hash; end
15
+ module Array; end
16
+ end
17
+ end
18
+ [FalseClass, TrueClass].each { |klass| klass.send(:include, Fog::Boolean) }
19
+ [FalseClass, TrueClass, NilClass, Fog::Boolean].each { |klass| klass.send(:include, Fog::Nullable::Boolean) }
20
+ [NilClass, String].each { |klass| klass.send(:include, Fog::Nullable::String) }
21
+ [NilClass, Time].each { |klass| klass.send(:include, Fog::Nullable::Time) }
22
+ [Integer, NilClass].each { |klass| klass.send(:include, Fog::Nullable::Integer) }
23
+ [Float, NilClass].each { |klass| klass.send(:include, Fog::Nullable::Float) }
24
+ [Hash, NilClass].each { |klass| klass.send(:include, Fog::Nullable::Hash) }
25
+ [Array, NilClass].each { |klass| klass.send(:include, Fog::Nullable::Array) }
26
+
27
+ module Shindo
28
+ class Tests
29
+ # Generates a Shindo test that compares a hash schema to the result
30
+ # of the passed in block returning true if they match.
31
+ #
32
+ # The schema that is passed in is a Hash or Array of hashes that
33
+ # have Classes in place of values. When checking the schema the
34
+ # value should match the Class.
35
+ #
36
+ # Strict mode will fail if the data has additional keys. Setting
37
+ # +strict+ to +false+ will allow additional keys to appear.
38
+ #
39
+ # @param [Hash] schema A Hash schema
40
+ # @param [Hash] options Options to change validation rules
41
+ # @option options [Boolean] :allow_extra_keys
42
+ # If +true+ does not fail when keys are in the data that are
43
+ # not specified in the schema. This allows new values to
44
+ # appear in API output without breaking the check.
45
+ # @option options [Boolean] :allow_optional_rules
46
+ # If +true+ does not fail if extra keys are in the schema
47
+ # that do not match the data. Not recommended!
48
+ # @yield Data to check with schema
49
+ #
50
+ # @example Using in a test
51
+ # Shindo.tests("comparing welcome data against schema") do
52
+ # data = {:welcome => "Hello" }
53
+ # data_matches_schema(:welcome => String) { data }
54
+ # end
55
+ #
56
+ # comparing welcome data against schema
57
+ # + data matches schema
58
+ #
59
+ # @example Example schema
60
+ # {
61
+ # "id" => String,
62
+ # "ram" => Integer,
63
+ # "disks" => [
64
+ # {
65
+ # "size" => Float
66
+ # }
67
+ # ],
68
+ # "dns_name" => Fog::Nullable::String,
69
+ # "active" => Fog::Boolean,
70
+ # "created" => DateTime
71
+ # }
72
+ #
73
+ # @return [Boolean]
74
+ def data_matches_schema(schema, options = {})
75
+ test("data matches schema") do
76
+ validator = Fog::Schema::DataValidator.new
77
+ valid = validator.validate(yield, schema, options)
78
+ @message = validator.message unless valid
79
+ valid
80
+ end
81
+ end
82
+
83
+ # @deprecated #formats is deprecated. Use #data_matches_schema instead
84
+ def formats(format, strict = true)
85
+ test("has proper format") do
86
+ if strict
87
+ options = { :allow_extra_keys => false, :allow_optional_rules => true }
88
+ else
89
+ options = { :allow_extra_keys => true, :allow_optional_rules => true }
90
+ end
91
+ validator = Fog::Schema::DataValidator.new
92
+ valid = validator.validate(yield, format, options)
93
+ @message = validator.message unless valid
94
+ valid
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,106 @@
1
+ Shindo.tests("test_helper", "meta") do
2
+ tests("comparing welcome data against schema") do
3
+ data = { :welcome => "Hello" }
4
+ data_matches_schema(:welcome => String) { data }
5
+ end
6
+
7
+ tests('#data_matches_schema') do
8
+ tests("when value matches schema expectation") do
9
+ data_matches_schema("key" => String) { { "key" => "Value" } }
10
+ end
11
+
12
+ tests("when values within an array all match schema expectation") do
13
+ data_matches_schema({ "key" => [Integer] }) { { "key" => [1, 2] } }
14
+ end
15
+
16
+ tests("when nested values match schema expectation") do
17
+ data_matches_schema("key" => { :nested_key => String }) { { "key" => { :nested_key => "Value" } } }
18
+ end
19
+
20
+ tests("when collection of values all match schema expectation") do
21
+ data_matches_schema([{ "key" => String }]) { [{ "key" => "Value" }, { "key" => "Value" }] }
22
+ end
23
+
24
+ tests("when collection is empty although schema covers optional members") do
25
+ data_matches_schema([{ "key" => String }], :allow_optional_rules => true) { [] }
26
+ end
27
+
28
+ tests("when additional keys are passed and not strict") do
29
+ data_matches_schema({ "key" => String }, :allow_extra_keys => true) { { "key" => "Value", :extra => "Bonus" } }
30
+ end
31
+
32
+ tests("when value is nil and schema expects NilClass") do
33
+ data_matches_schema("key" => NilClass) { { "key" => nil } }
34
+ end
35
+
36
+ tests("when value and schema match as hashes") do
37
+ data_matches_schema({}) { {} }
38
+ end
39
+
40
+ tests("when value and schema match as arrays") do
41
+ data_matches_schema([]) { [] }
42
+ end
43
+
44
+ tests("when value is a Time") do
45
+ data_matches_schema("time" => Time) { { "time" => Time.now } }
46
+ end
47
+
48
+ tests('when key is missing but value should be NilClass (#1477)') do
49
+ data_matches_schema({ "key" => NilClass }, :allow_optional_rules => true) { {} }
50
+ end
51
+
52
+ tests('when key is missing but value is nullable (#1477)') do
53
+ data_matches_schema({ "key" => Fog::Nullable::String }, :allow_optional_rules => true) { {} }
54
+ end
55
+ end
56
+
57
+ tests('#formats backwards compatible changes') do
58
+ tests("when value matches schema expectation") do
59
+ formats("key" => String) { { "key" => "Value" } }
60
+ end
61
+
62
+ tests("when values within an array all match schema expectation") do
63
+ formats("key" => [Integer]) { { "key" => [1, 2] } }
64
+ end
65
+
66
+ tests("when nested values match schema expectation") do
67
+ formats("key" => { :nested_key => String }) { { "key" => { :nested_key => "Value" } } }
68
+ end
69
+
70
+ tests("when collection of values all match schema expectation") do
71
+ formats([{ "key" => String }]) { [{ "key" => "Value" }, { "key" => "Value" }] }
72
+ end
73
+
74
+ tests("when collection is empty although schema covers optional members") do
75
+ formats([{ "key" => String }]) { [] }
76
+ end
77
+
78
+ tests("when additional keys are passed and not strict") do
79
+ formats({ "key" => String }, false) { { "key" => "Value", :extra => "Bonus" } }
80
+ end
81
+
82
+ tests("when value is nil and schema expects NilClass") do
83
+ formats("key" => NilClass) { { "key" => nil } }
84
+ end
85
+
86
+ tests("when value and schema match as hashes") do
87
+ formats({}) { {} }
88
+ end
89
+
90
+ tests("when value and schema match as arrays") do
91
+ formats([]) { [] }
92
+ end
93
+
94
+ tests("when value is a Time") do
95
+ formats("time" => Time) { { "time" => Time.now } }
96
+ end
97
+
98
+ tests('when key is missing but value should be NilClass (#1477)') do
99
+ formats("key" => NilClass) { {} }
100
+ end
101
+
102
+ tests('when key is missing but value is nullable (#1477)') do
103
+ formats({ "key" => Fog::Nullable::String }) { {} }
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,98 @@
1
+ # Use so you can run in mock mode from the command line
2
+ #
3
+ # FOG_MOCK=true fog
4
+
5
+ if ENV["FOG_MOCK"] == "true"
6
+ Fog.mock!
7
+ end
8
+
9
+ # if in mocked mode, fill in some fake credentials for us
10
+ if Fog.mock?
11
+ Fog.credentials = {
12
+ :aws_access_key_id => "aws_access_key_id",
13
+ :aws_secret_access_key => "aws_secret_access_key",
14
+ :ia_access_key_id => "aws_access_key_id",
15
+ :ia_secret_access_key => "aws_secret_access_key",
16
+ :bluebox_api_key => "bluebox_api_key",
17
+ :bluebox_customer_id => "bluebox_customer_id",
18
+ :brightbox_client_id => "brightbox_client_id",
19
+ :brightbox_secret => "brightbox_secret",
20
+ :cloudstack_disk_offering_id => "",
21
+ :cloudstack_host => "http://cloudstack.example.org",
22
+ :cloudstack_network_ids => "",
23
+ :cloudstack_service_offering_id => "4437ac6c-9fe3-477a-57ec-60a5a45896a4",
24
+ :cloudstack_template_id => "8a31cf9c-f248-0588-256e-9dbf58785216",
25
+ :cloudstack_zone_id => "c554c592-e09c-9df5-7688-4a32754a4305",
26
+ :cloudstack_project_id => "f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1f1",
27
+ :clodo_api_key => "clodo_api_key",
28
+ :clodo_username => "clodo_username",
29
+ :digitalocean_api_key => "digitalocean_api_key",
30
+ :digitalocean_client_id => "digitalocean_client_id",
31
+ :dnsimple_email => "dnsimple_email",
32
+ :dnsimple_password => "dnsimple_password",
33
+ :dnsmadeeasy_api_key => "dnsmadeeasy_api_key",
34
+ :dnsmadeeasy_secret_key => "dnsmadeeasy_secret_key",
35
+ :glesys_username => "glesys_username",
36
+ :glesys_api_key => "glesys_api_key",
37
+ :go_grid_api_key => "go_grid_api_key",
38
+ :go_grid_shared_secret => "go_grid_shared_secret",
39
+ :hp_access_key => "hp_access_key",
40
+ :hp_secret_key => "hp_secret_key",
41
+ :hp_tenant_id => "hp_tenant_id",
42
+ :hp_avl_zone => "hp_avl_zone",
43
+ :hp_auth_uri => "http://hp/v2.0/tokens",
44
+ :os_account_meta_temp_url_key => "os_account_meta_temp_url_key",
45
+ :ibm_username => "ibm_username",
46
+ :ibm_password => "ibm_password",
47
+ :joyent_username => "joyentuser",
48
+ :joyent_password => "joyentpass",
49
+ :linode_api_key => "linode_api_key",
50
+ :local_root => "~/.fog",
51
+ :bare_metal_cloud_password => "bare_metal_cloud_password",
52
+ :bare_metal_cloud_username => "bare_metal_cloud_username",
53
+ :ninefold_compute_key => "ninefold_compute_key",
54
+ :ninefold_compute_secret => "ninefold_compute_secret",
55
+ :ninefold_storage_secret => "ninefold_storage_secret",
56
+ :ninefold_storage_token => "ninefold_storage_token",
57
+ # :public_key_path => '~/.ssh/id_rsa.pub',
58
+ # :private_key_path => '~/.ssh/id_rsa',
59
+ :opennebula_endpoint => "http://opennebula:2633/RPC2",
60
+ :opennebula_username => "oneadmin",
61
+ :opennebula_password => "oneadmin",
62
+ :openstack_api_key => "openstack_api_key",
63
+ :openstack_username => "openstack_username",
64
+ :openstack_tenant => "openstack_tenant",
65
+ :openstack_auth_url => "http://openstack:35357/v2.0/tokens",
66
+ :ovirt_url => "http://ovirt:8080/api",
67
+ :ovirt_username => "admin@internal",
68
+ :ovirt_password => "123123",
69
+ :profitbricks_username => "profitbricks_username",
70
+ :profitbricks_password => "profitbricks_password",
71
+ :rackspace_api_key => "rackspace_api_key",
72
+ :rackspace_region => "dfw",
73
+ :rackspace_username => "rackspace_username",
74
+ :sakuracloud_api_token => "sakuracloud_api_token",
75
+ :sakuracloud_api_token_secret => "sakuracloud_api_token_secret",
76
+ :vcloud_host => "vcloud_host",
77
+ :vcloud_password => "vcloud_password",
78
+ :vcloud_username => "vcloud_username",
79
+ :vcloud_director_host => "vcloud-director-host",
80
+ :vcloud_director_password => "vcloud_director_password",
81
+ :vcloud_director_username => "vcd_user@vcd_org_name",
82
+ :zerigo_email => "zerigo_email",
83
+ :zerigo_token => "zerigo_token",
84
+ :dynect_customer => "dynect_customer",
85
+ :dynect_username => "dynect_username",
86
+ :dynect_password => "dynect_password",
87
+ :vsphere_server => "virtualcenter.lan",
88
+ :vsphere_username => "apiuser",
89
+ :vsphere_password => "apipassword",
90
+ :vsphere_expected_pubkey_hash => "abcdef1234567890",
91
+ :cloudsigma_username => "csuname",
92
+ :cloudsigma_password => "cspass",
93
+ :docker_username => "docker-fan",
94
+ :docker_password => "i<3docker",
95
+ :docker_email => "dockerfan@gmail.com",
96
+ :docker_url => "unix://var/run/docker.sock"
97
+ }.merge(Fog.credentials)
98
+ end