fog-core 1.24.0 → 1.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +5 -13
  2. data/.rubocop.yml +20 -0
  3. data/changelog.md +17 -0
  4. data/fog-core.gemspec +2 -1
  5. data/lib/fog/account.rb +3 -5
  6. data/lib/fog/billing.rb +3 -4
  7. data/lib/fog/cdn.rb +3 -5
  8. data/lib/fog/compute.rb +17 -20
  9. data/lib/fog/compute/models/server.rb +21 -26
  10. data/lib/fog/core.rb +61 -60
  11. data/lib/fog/core/association.rb +15 -0
  12. data/lib/fog/core/associations/default.rb +21 -3
  13. data/lib/fog/core/associations/many_identities.rb +8 -2
  14. data/lib/fog/core/associations/many_models.rb +7 -2
  15. data/lib/fog/core/associations/one_identity.rb +6 -1
  16. data/lib/fog/core/associations/one_model.rb +5 -1
  17. data/lib/fog/core/attributes.rb +41 -44
  18. data/lib/fog/core/attributes/array.rb +5 -1
  19. data/lib/fog/core/attributes/boolean.rb +5 -1
  20. data/lib/fog/core/attributes/default.rb +12 -2
  21. data/lib/fog/core/attributes/float.rb +5 -1
  22. data/lib/fog/core/attributes/integer.rb +5 -1
  23. data/lib/fog/core/attributes/string.rb +5 -1
  24. data/lib/fog/core/attributes/time.rb +5 -1
  25. data/lib/fog/core/attributes/timestamp.rb +5 -1
  26. data/lib/fog/core/collection.rb +22 -27
  27. data/lib/fog/core/connection.rb +5 -6
  28. data/lib/fog/core/credentials.rb +7 -7
  29. data/lib/fog/core/current_machine.rb +10 -8
  30. data/lib/fog/core/deprecated_connection_accessors.rb +0 -1
  31. data/lib/fog/core/deprecation.rb +0 -2
  32. data/lib/fog/core/errors.rb +3 -5
  33. data/lib/fog/core/hmac.rb +4 -6
  34. data/lib/fog/core/logger.rb +10 -11
  35. data/lib/fog/core/mock.rb +19 -25
  36. data/lib/fog/core/model.rb +9 -20
  37. data/lib/fog/core/provider.rb +6 -9
  38. data/lib/fog/core/scp.rb +14 -24
  39. data/lib/fog/core/service.rb +28 -31
  40. data/lib/fog/core/ssh.rb +16 -24
  41. data/lib/fog/core/stringify_keys.rb +7 -9
  42. data/lib/fog/core/time.rb +5 -7
  43. data/lib/fog/core/utils.rb +24 -20
  44. data/lib/fog/core/uuid.rb +2 -3
  45. data/lib/fog/core/version.rb +3 -1
  46. data/lib/fog/core/wait_for.rb +2 -2
  47. data/lib/fog/core/wait_for_defaults.rb +13 -10
  48. data/lib/fog/core/whitelist_keys.rb +1 -1
  49. data/lib/fog/dns.rb +6 -8
  50. data/lib/fog/identity.rb +5 -6
  51. data/lib/fog/image.rb +3 -5
  52. data/lib/fog/metering.rb +3 -6
  53. data/lib/fog/monitoring.rb +3 -5
  54. data/lib/fog/network.rb +4 -6
  55. data/lib/fog/orchestration.rb +3 -5
  56. data/lib/fog/schema/data_validator.rb +17 -22
  57. data/lib/fog/storage.rb +22 -16
  58. data/lib/fog/support.rb +3 -6
  59. data/lib/fog/test_helpers.rb +10 -10
  60. data/lib/fog/test_helpers/collection_helper.rb +23 -43
  61. data/lib/fog/test_helpers/compute/flavors_helper.rb +4 -10
  62. data/lib/fog/test_helpers/compute/server_helper.rb +3 -9
  63. data/lib/fog/test_helpers/compute/servers_helper.rb +0 -4
  64. data/lib/fog/test_helpers/formats_helper.rb +13 -14
  65. data/lib/fog/test_helpers/helper.rb +9 -4
  66. data/lib/fog/test_helpers/mock_helper.rb +92 -94
  67. data/lib/fog/test_helpers/model_helper.rb +7 -15
  68. data/lib/fog/test_helpers/responds_to_helper.rb +1 -3
  69. data/lib/fog/test_helpers/succeeds_helper.rb +1 -3
  70. data/lib/fog/volume.rb +3 -6
  71. data/lib/fog/vpn.rb +3 -5
  72. data/lib/tasks/test_task.rb +2 -6
  73. data/spec/compute_spec.rb +11 -13
  74. data/spec/connection_spec.rb +24 -14
  75. data/spec/credentials_spec.rb +23 -23
  76. data/spec/current_machine_spec.rb +6 -6
  77. data/spec/fake_app/fake_service.rb +18 -0
  78. data/spec/fake_app/models/collection.rb +5 -0
  79. data/spec/fake_app/models/model.rb +2 -0
  80. data/spec/fake_app/requests/request.rb +11 -0
  81. data/spec/fog_attribute_spec.rb +178 -136
  82. data/spec/identity_spec.rb +11 -13
  83. data/spec/mocking_spec.rb +7 -8
  84. data/spec/service_spec.rb +21 -7
  85. data/spec/spec_helper.rb +14 -8
  86. data/spec/storage_spec.rb +25 -13
  87. data/spec/test_helpers/formats_helper_spec.rb +52 -52
  88. data/spec/test_helpers/schema_validator_spec.rb +45 -45
  89. data/spec/timeout_spec.rb +1 -2
  90. data/spec/utils_spec.rb +2 -2
  91. data/spec/uuid_spec.rb +1 -1
  92. data/spec/wait_for_spec.rb +7 -4
  93. metadata +57 -33
@@ -1,7 +1,5 @@
1
1
  def model_tests(collection, params = {}, mocks_implemented = true)
2
-
3
- tests('success') do
4
-
2
+ tests("success") do
5
3
  @instance = collection.new(params)
6
4
 
7
5
  tests("#save").succeeds do
@@ -9,27 +7,21 @@ def model_tests(collection, params = {}, mocks_implemented = true)
9
7
  @instance.save
10
8
  end
11
9
 
12
- if block_given?
13
- yield
14
- end
10
+ yield if block_given?
15
11
 
16
12
  tests("#destroy").succeeds do
17
13
  pending if Fog.mocking? && !mocks_implemented
18
14
  @instance.destroy
19
15
  end
20
-
21
16
  end
22
-
23
17
  end
24
18
 
25
19
  # Generates a unique identifier with a random differentiator.
26
- # Useful when rapidly re-running tests, so we don't have to wait
20
+ # Useful when rapidly re-running tests, so we don"t have to wait
27
21
  # serveral minutes for deleted objects to disappear from the API
28
- # E.g. 'fog-test-1234'
29
- def uniq_id(base_name = 'fog-test')
22
+ # E.g. "fog-test-1234"
23
+ def uniq_id(base_name = "fog-test")
30
24
  # random_differentiator
31
- suffix = rand(65536).to_s(16).rjust(4, '0')
32
- [base_name, suffix] * '-'
25
+ suffix = rand(65_536).to_s(16).rjust(4, "0")
26
+ [base_name, suffix].join("-")
33
27
  end
34
-
35
-
@@ -1,13 +1,11 @@
1
1
  module Shindo
2
2
  class Tests
3
-
4
3
  def responds_to(method_names)
5
- for method_name in [*method_names]
4
+ method_names.each do |method_name|
6
5
  tests("#respond_to?(:#{method_name})").returns(true) do
7
6
  @instance.respond_to?(method_name)
8
7
  end
9
8
  end
10
9
  end
11
-
12
10
  end
13
11
  end
@@ -1,11 +1,9 @@
1
1
  module Shindo
2
2
  class Tests
3
-
4
3
  def succeeds
5
- test('succeeds') do
4
+ test("succeeds") do
6
5
  !!instance_eval(&Proc.new)
7
6
  end
8
7
  end
9
-
10
8
  end
11
9
  end
@@ -1,25 +1,22 @@
1
1
  module Fog
2
2
  module Volume
3
-
4
3
  def self.[](provider)
5
- self.new(:provider => provider)
4
+ new(:provider => provider)
6
5
  end
7
6
 
8
7
  def self.new(attributes)
9
8
  attributes = attributes.dup # Prevent delete from having side effects
10
9
  provider = attributes.delete(:provider).to_s.downcase.to_sym
11
- if self.providers.include?(provider)
10
+ if providers.include?(provider)
12
11
  require "fog/#{provider}/volume"
13
12
  return Fog::Volume.const_get(Fog.providers[provider]).new(attributes)
14
13
  end
15
14
 
16
- raise ArgumentError.new("#{provider} has no identity service")
15
+ raise ArgumentError, "#{provider} has no identity service"
17
16
  end
18
17
 
19
18
  def self.providers
20
19
  Fog.services[:volume]
21
20
  end
22
-
23
21
  end
24
22
  end
25
-
@@ -1,8 +1,7 @@
1
1
  module Fog
2
2
  module VPN
3
-
4
3
  def self.[](provider)
5
- self.new(:provider => provider)
4
+ new(:provider => provider)
6
5
  end
7
6
 
8
7
  def self.new(attributes)
@@ -10,16 +9,15 @@ module Fog
10
9
  provider = attributes.delete(:provider).to_s.downcase.to_sym
11
10
 
12
11
  if provider == :stormondemand
13
- require 'fog/storm_on_demand/vpn'
12
+ require "fog/storm_on_demand/vpn"
14
13
  Fog::VPN::StormOnDemand.new(attributes)
15
14
  else
16
- raise ArgumentError.new("#{provider} has no vpn service")
15
+ raise ArgumentError, "#{provider} has no vpn service"
17
16
  end
18
17
  end
19
18
 
20
19
  def self.providers
21
20
  Fog.services[:vpn]
22
21
  end
23
-
24
22
  end
25
23
  end
@@ -4,7 +4,6 @@ require "rake/tasklib"
4
4
  module Fog
5
5
  module Rake
6
6
  class TestTask < ::Rake::TaskLib
7
-
8
7
  def initialize
9
8
  desc "Run the mocked tests"
10
9
  task :test do
@@ -33,14 +32,11 @@ module Fog
33
32
  }
34
33
  end
35
34
  end
36
- threads.each do |thread|
37
- thread.join
38
- end
39
- Formatador.display_table(Thread.main[:results].sort {|x,y| x[:provider] <=> y[:provider]})
35
+ threads.each(&:join)
36
+ Formatador.display_table(Thread.main[:results].sort { |x, y| x[:provider] <=> y[:provider] })
40
37
  Formatador.display_line("[bold]FOG_MOCK=#{mocked}[/] tests completed in [bold]#{Time.now.to_i - start}[/] seconds")
41
38
  Formatador.display_line
42
39
  end
43
-
44
40
  end
45
41
  end
46
42
  end
@@ -1,9 +1,8 @@
1
- require 'spec_helper'
2
-
1
+ require "spec_helper"
3
2
 
4
3
  module Fog
5
4
  module Compute
6
- def self.require(*args); end
5
+ def self.require(*_args); end
7
6
  end
8
7
  end
9
8
 
@@ -12,14 +11,14 @@ describe "Fog::Compute" do
12
11
  module Fog
13
12
  module TheRightWay
14
13
  extend Provider
15
- service(:compute, 'Compute')
14
+ service(:compute, "Compute")
16
15
  end
17
16
  end
18
17
 
19
18
  module Fog
20
19
  module Compute
21
20
  class TheRightWay
22
- def initialize(args); end
21
+ def initialize(_args); end
23
22
  end
24
23
  end
25
24
  end
@@ -29,18 +28,17 @@ describe "Fog::Compute" do
29
28
  assert_instance_of(Fog::Compute::TheRightWay, compute)
30
29
  end
31
30
 
32
-
33
31
  module Fog
34
32
  module TheWrongWay
35
33
  extend Provider
36
- service(:compute, 'Compute')
34
+ service(:compute, "Compute")
37
35
  end
38
36
  end
39
37
 
40
38
  module Fog
41
39
  module TheWrongWay
42
40
  class Compute
43
- def initialize(args); end
41
+ def initialize(_args); end
44
42
  end
45
43
  end
46
44
  end
@@ -53,14 +51,14 @@ describe "Fog::Compute" do
53
51
  module Fog
54
52
  module BothWays
55
53
  extend Provider
56
- service(:compute, 'Compute')
54
+ service(:compute, "Compute")
57
55
  end
58
56
  end
59
57
 
60
58
  module Fog
61
59
  module BothWays
62
60
  class Compute
63
- def initialize(args); end
61
+ def initialize(_args); end
64
62
  end
65
63
  end
66
64
  end
@@ -82,16 +80,16 @@ describe "Fog::Compute" do
82
80
  assert_instance_of(Fog::Compute::BothWays, compute)
83
81
  end
84
82
  end
85
-
83
+
86
84
  it "passes the supplied keyword args less :provider to Fog::Compute::<Provider>#new" do
87
85
  compute = Fog::Compute.new(:provider => :bothways, :extra => :stuff)
88
- assert_equal({:extra => :stuff}, compute.args)
86
+ assert_equal({ :extra => :stuff }, compute.args)
89
87
  end
90
88
 
91
89
  it "raises ArgumentError when given a :provider where a Fog::Compute::Provider that does not exist" do
92
90
  assert_raises(ArgumentError) do
93
91
  Fog::Compute.new(:provider => :wat)
94
92
  end
95
- end
93
+ end
96
94
  end
97
95
  end
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
- describe Fog::Core::Connection do
3
+ describe Fog::Core::Connection do
4
4
  it "raises ArgumentError when no arguments given" do
5
5
  assert_raises(ArgumentError) do
6
6
  Fog::Core::Connection.new
@@ -14,10 +14,20 @@ describe Fog::Core::Connection do
14
14
  end
15
15
  end
16
16
 
17
- it "writes the Fog::VERSION to the User-Agent header" do
17
+ it "writes the Fog::Core::VERSION to the User-Agent header" do
18
18
  connection = Fog::Core::Connection.new("http://example.com")
19
- assert_equal "fog/#{Fog::VERSION}",
20
- connection.instance_variable_get(:@excon).data[:headers]["User-Agent"]
19
+ assert_equal "fog-core/#{Fog::Core::VERSION}",
20
+ connection.instance_variable_get(:@excon).data[:headers]["User-Agent"]
21
+ end
22
+
23
+ describe "when Fog is installed" do
24
+ it "writes the Fog::VERSION to the User-Agent header" do
25
+ Fog::VERSION = 'Version'
26
+ connection = Fog::Core::Connection.new("http://example.com")
27
+ assert_equal "fog/Version fog-core/#{Fog::Core::VERSION}",
28
+ connection.instance_variable_get(:@excon).data[:headers]["User-Agent"]
29
+ Fog.send(:remove_const, :VERSION)
30
+ end
21
31
  end
22
32
 
23
33
  it "doesn't error when persistence is enabled" do
@@ -34,9 +44,9 @@ describe Fog::Core::Connection do
34
44
  describe ":path_prefix" do
35
45
  it "does not emit a warning when provided this argument in the initializer" do
36
46
  $stderr = StringIO.new
37
-
47
+
38
48
  Fog::Core::Connection.new("http://example.com", false, :path_prefix => "foo")
39
-
49
+
40
50
  assert_empty($stderr.string)
41
51
  end
42
52
 
@@ -61,24 +71,24 @@ describe Fog::Core::Connection do
61
71
  end
62
72
 
63
73
  Object.stub_const("Excon", spy) do
64
- c = Fog::Core::Connection.new("http://example.com", false, :path => "bar")
74
+ Fog::Core::Connection.new("http://example.com", false, :path => "bar")
65
75
  assert_equal("bar", spy.params[:path])
66
76
  end
67
77
  end
68
78
  end
69
79
 
70
80
  describe "with path_prefix supplied to the initializer" do
71
- let(:spy) {
72
- Object.new.tap { |spy|
81
+ let(:spy) do
82
+ Object.new.tap do |spy|
73
83
  spy.instance_eval do
74
- def new(*args); self; end
84
+ def new(*_args); self; end
75
85
  def params; @params; end
76
86
  def request(params)
77
87
  @params = params
78
88
  end
79
89
  end
80
- }
81
- }
90
+ end
91
+ end
82
92
 
83
93
  it "uses the initializer-supplied :path_prefix arg with #request :arg to formulate a path to send to Excon.request" do
84
94
  Object.stub_const("Excon", spy) do
@@ -87,7 +97,7 @@ describe Fog::Core::Connection do
87
97
  assert_equal("foo/bar", spy.params[:path])
88
98
  end
89
99
  end
90
-
100
+
91
101
  it "does not introduce consecutive '/'s into the path if 'path' starts with a '/'" do
92
102
  Object.stub_const("Excon", spy) do
93
103
  c = Fog::Core::Connection.new("http://example.com", false, :path_prefix => "foo")
@@ -1,19 +1,19 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe "credentials" do
4
4
  before do
5
- @old_home = ENV['HOME']
6
- @old_rc = ENV['FOG_RC']
7
- @old_credential = ENV['FOG_CREDENTIAL']
5
+ @old_home = ENV["HOME"]
6
+ @old_rc = ENV["FOG_RC"]
7
+ @old_credential = ENV["FOG_CREDENTIAL"]
8
8
  @old_credentials = Fog.credentials
9
- Fog.instance_variable_set('@credential_path', nil) # kill memoization
10
- Fog.instance_variable_set('@credential', nil) # kill memoization
9
+ Fog.instance_variable_set("@credential_path", nil) # kill memoization
10
+ Fog.instance_variable_set("@credential", nil) # kill memoization
11
11
  end
12
12
 
13
13
  after do
14
- ENV['HOME'] = @old_home
15
- ENV['FOG_RC'] = @old_rc
16
- ENV['FOG_CREDENTIAL'] = @old_credential
14
+ ENV["HOME"] = @old_home
15
+ ENV["FOG_RC"] = @old_rc
16
+ ENV["FOG_CREDENTIAL"] = @old_credential
17
17
  Fog.credentials = @old_credentials
18
18
  end
19
19
 
@@ -35,33 +35,33 @@ describe "credentials" do
35
35
 
36
36
  describe "credentials_path" do
37
37
  it "has FOG_RC takes precedence over HOME" do
38
- ENV['HOME'] = '/home/path'
39
- ENV['FOG_RC'] = '/rc/path'
38
+ ENV["HOME"] = "/home/path"
39
+ ENV["FOG_RC"] = "/rc/path"
40
40
 
41
- assert_equal '/rc/path', Fog.credentials_path
41
+ assert_equal "/rc/path", Fog.credentials_path
42
42
  end
43
43
 
44
44
  it "properly expands paths" do
45
- ENV['FOG_RC'] = '/expanded/subdirectory/../path'
46
- assert_equal '/expanded/path', Fog.credentials_path
45
+ ENV["FOG_RC"] = "/expanded/subdirectory/../path"
46
+ assert_equal "/expanded/path", Fog.credentials_path
47
47
  end
48
48
 
49
49
  it "falls back to home path if FOG_RC not set" do
50
- ENV.delete('FOG_RC')
51
- assert_equal File.join(ENV['HOME'], '.fog'), Fog.credentials_path
50
+ ENV.delete("FOG_RC")
51
+ assert_equal File.join(ENV["HOME"], ".fog"), Fog.credentials_path
52
52
  end
53
53
 
54
54
  it "ignores home path if it does not exist" do
55
- ENV.delete('FOG_RC')
56
- ENV['HOME'] = '/no/such/path'
55
+ ENV.delete("FOG_RC")
56
+ ENV["HOME"] = "/no/such/path"
57
57
  assert_nil Fog.credentials_path
58
58
  end
59
59
 
60
60
  it "File.expand_path raises because of non-absolute path" do
61
- ENV.delete('FOG_RC')
62
- ENV['HOME'] = '.'
61
+ ENV.delete("FOG_RC")
62
+ ENV["HOME"] = "."
63
63
 
64
- if RUBY_PLATFORM == 'java'
64
+ if RUBY_PLATFORM == "java"
65
65
  Fog::Logger.warning("Stubbing out non-absolute path credentials test due to JRuby bug: https://github.com/jruby/jruby/issues/1163")
66
66
  else
67
67
  assert_nil Fog.credentials_path
@@ -69,8 +69,8 @@ describe "credentials" do
69
69
  end
70
70
 
71
71
  it "returns nil when neither FOG_RC or HOME are set" do
72
- ENV.delete('HOME')
73
- ENV.delete('FOG_RC')
72
+ ENV.delete("HOME")
73
+ ENV.delete("FOG_RC")
74
74
  assert_nil Fog.credentials_path
75
75
  end
76
76
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Fog::CurrentMachine do
4
4
  before do
@@ -19,16 +19,16 @@ describe Fog::CurrentMachine do
19
19
 
20
20
  describe "ip_address" do
21
21
  it "should be thread safe" do
22
- Excon.stub({:method => :get, :path => "/"}, {:body => ""})
22
+ Excon.stub({ :method => :get, :path => "/" }, { :body => "" })
23
23
 
24
- (1..10).map {
24
+ (1..10).map do
25
25
  Thread.new { Fog::CurrentMachine.ip_address }
26
- }.each{ |t| t.join }
26
+ end.each(&:join)
27
27
  end
28
28
 
29
29
  it "should remove trailing endline characters" do
30
- Excon.stub({:method => :get, :path => "/"}, {:body => "192.168.0.1\n"})
30
+ Excon.stub({ :method => :get, :path => "/" }, { :body => "192.168.0.1\n" })
31
31
  assert_equal "192.168.0.1", Fog::CurrentMachine.ip_address
32
32
  end
33
- end
33
+ end
34
34
  end
@@ -0,0 +1,18 @@
1
+ class FakeService < Fog::Service
2
+ class Real
3
+ def initialize(_options)
4
+ end
5
+ end
6
+
7
+ class Mock
8
+ def initialize(_options)
9
+ end
10
+ end
11
+
12
+ model_path File.join(File.dirname(__FILE__), "models")
13
+ model :model
14
+ collection :collection
15
+
16
+ request_path File.join(File.dirname(__FILE__), "requests")
17
+ request :request
18
+ end