fog-softlayer 0.0.4 → 0.0.5

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.
Files changed (37) hide show
  1. checksums.yaml +15 -7
  2. data/.gitignore +28 -0
  3. data/Gemfile +7 -0
  4. data/Rakefile +225 -1
  5. data/fog-softlayer.gemspec +15 -5
  6. data/lib/fog.rb +29 -0
  7. data/lib/fog/softlayer.rb +8 -0
  8. data/lib/fog/softlayer/compute.rb +0 -15
  9. data/lib/fog/softlayer/core.rb +6 -8
  10. data/lib/fog/softlayer/version.rb +7 -1
  11. data/spec/fog/compute/softlayer_spec.rb +6 -0
  12. data/tests/compute/flavors_helper.rb +40 -0
  13. data/tests/compute/server_helper.rb +33 -0
  14. data/tests/compute/servers_helper.rb +18 -0
  15. data/tests/helper.rb +68 -0
  16. data/tests/helpers/collection_helper.rb +102 -0
  17. data/tests/helpers/compute/flavors_helper.rb +34 -0
  18. data/tests/helpers/compute/server_helper.rb +27 -0
  19. data/tests/helpers/compute/servers_helper.rb +12 -0
  20. data/tests/helpers/formats_helper.rb +99 -0
  21. data/tests/helpers/formats_helper_tests.rb +111 -0
  22. data/tests/helpers/mock_helper.rb +111 -0
  23. data/tests/helpers/model_helper.rb +35 -0
  24. data/tests/helpers/responds_to_helper.rb +13 -0
  25. data/tests/helpers/schema_validator_tests.rb +107 -0
  26. data/tests/helpers/succeeds_helper.rb +11 -0
  27. data/tests/lorem.txt +1 -0
  28. data/tests/softlayer/compute/helper.rb +7 -0
  29. data/tests/softlayer/compute/schema.rb +133 -0
  30. data/tests/softlayer/compute_tests.rb +34 -0
  31. data/tests/softlayer/helper.rb +9 -0
  32. data/tests/softlayer/models/compute/flavor_tests.rb +24 -0
  33. data/tests/softlayer/models/compute/image_tests.rb +25 -0
  34. data/tests/softlayer/models/compute/server_tests.rb +80 -0
  35. data/tests/softlayer/requests/compute/bmc_tests.rb +62 -0
  36. data/tests/softlayer/requests/compute/vm_tests.rb +90 -0
  37. metadata +254 -59
@@ -0,0 +1,40 @@
1
+ #
2
+ # Author:: Matt Eldridge (<matt.eldridge@us.ibm.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+ def flavors_tests(connection, params = {}, mocks_implemented = true)
8
+
9
+ tests('success') do
10
+
11
+ tests("#all").succeeds do
12
+ pending if Fog.mocking? && !mocks_implemented
13
+ connection.flavors.all
14
+ end
15
+
16
+ if !Fog.mocking? || mocks_implemented
17
+ @identity = connection.flavors.first.identity
18
+ end
19
+
20
+ tests("#get('#{@identity}')").succeeds do
21
+ pending if Fog.mocking? && !mocks_implemented
22
+ connection.flavors.get(@identity)
23
+ end
24
+
25
+ end
26
+
27
+ tests('failure') do
28
+
29
+ if !Fog.mocking? || mocks_implemented
30
+ invalid_flavor_identity = connection.flavors.first.identity.to_s.gsub(/\w/, '0')
31
+ end
32
+
33
+ tests("#get('#{invalid_flavor_identity}')").returns(nil) do
34
+ pending if Fog.mocking? && !mocks_implemented
35
+ connection.flavors.get(invalid_flavor_identity)
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,33 @@
1
+ #
2
+ # Author:: Matt Eldridge (<matt.eldridge@us.ibm.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+ def server_tests(connection, params = {}, mocks_implemented = true)
8
+
9
+ model_tests(connection.servers, params, mocks_implemented) do
10
+
11
+ tests('#reload').returns(true) do
12
+ pending if Fog.mocking? && !mocks_implemented
13
+ @instance.wait_for { ready? }
14
+ identity = @instance.identity
15
+ !identity.nil? && identity == @instance.reload.identity
16
+ end
17
+
18
+ responds_to([:ready?, :state])
19
+ yield if block_given?
20
+
21
+ tests('#reboot').succeeds do
22
+ pending if Fog.mocking? && !mocks_implemented
23
+ @instance.wait_for { ready? }
24
+ @instance.reboot
25
+ end
26
+
27
+ if !Fog.mocking? || mocks_implemented
28
+ @instance.wait_for { ready? }
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,18 @@
1
+ #
2
+ # Author:: Matt Eldridge (<matt.eldridge@us.ibm.com>)
3
+ # © Copyright IBM Corporation 2014.
4
+ #
5
+ # LICENSE: MIT (http://opensource.org/licenses/MIT)
6
+ #
7
+ def servers_tests(connection, params = {}, mocks_implemented = true)
8
+
9
+ collection_tests(connection.servers, params, mocks_implemented) do
10
+
11
+ if !Fog.mocking? || mocks_implemented
12
+ @instance.wait_for { ready? }
13
+ yield if block_given?
14
+ end
15
+
16
+ end
17
+
18
+ end
data/tests/helper.rb ADDED
@@ -0,0 +1,68 @@
1
+ require 'simplecov'
2
+
3
+ if ENV['COVERAGE'] == 'true' && RUBY_VERSION != "1.9.2"
4
+ require 'coveralls'
5
+ SimpleCov.command_name "shindo:#{Process.pid.to_s}"
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
10
+ SimpleCov.merge_timeout 3600
11
+ SimpleCov.start
12
+ end
13
+
14
+ ENV['FOG_RC'] = ENV['FOG_RC'] || File.expand_path('../.fog', __FILE__)
15
+ ENV['FOG_CREDENTIAL'] = ENV['FOG_CREDENTIAL'] || 'default'
16
+
17
+ require 'fog'
18
+ require 'fog/bin' # for available_providers and registered_providers
19
+
20
+ Excon.defaults.merge!(:debug_request => true, :debug_response => true)
21
+
22
+ require File.expand_path(File.join(File.dirname(__FILE__), 'helpers', 'mock_helper'))
23
+
24
+ # This overrides the default 600 seconds timeout during live test runs
25
+ if Fog.mocking?
26
+ FOG_TESTING_TIMEOUT = ENV['FOG_TEST_TIMEOUT'] || 2000
27
+ Fog.timeout = 2000
28
+ Fog::Logger.warning "Setting default fog timeout to #{Fog.timeout} seconds"
29
+ else
30
+ FOG_TESTING_TIMEOUT = Fog.timeout
31
+ end
32
+
33
+ def lorem_file
34
+ File.open(File.dirname(__FILE__) + '/lorem.txt', 'r')
35
+ end
36
+
37
+ def array_differences(array_a, array_b)
38
+ (array_a - array_b) | (array_b - array_a)
39
+ end
40
+
41
+ # check to see which credentials are available and add others to the skipped tags list
42
+ all_providers = Fog.registered_providers.map {|provider| provider.downcase}
43
+
44
+ # Manually remove these providers since they are local applications, not lacking credentials
45
+ all_providers = all_providers - ["libvirt", "vmfusion", "openvz"]
46
+
47
+ available_providers = Fog.available_providers.map {|provider| provider.downcase}
48
+
49
+ unavailable_providers = all_providers - available_providers
50
+
51
+ if !ENV['PROVIDER'].nil? && unavailable_providers.include?(ENV['PROVIDER'])
52
+ Formatador.display_line("[red]Requested provider #{ENV['PROVIDER']} is not available.[/]" +
53
+ "[red]Check if .fog file has correct configuration (see '#{Fog.credentials_path}')[/]")
54
+ exit(0)
55
+ end
56
+
57
+ for provider in unavailable_providers
58
+ Formatador.display_line("[yellow]Skipping tests for [bold]#{provider}[/] [yellow]due to lacking credentials (add some to '#{Fog.credentials_path}' to run them)[/]")
59
+ Thread.current[:tags] << ('-' << provider)
60
+ end
61
+
62
+ # mark libvirt tests pending if not setup
63
+ begin
64
+ require('libvirt')
65
+ rescue LoadError
66
+ Formatador.display_line("[yellow]Skipping tests for [bold]libvirt[/] [yellow]due to missing `ruby-libvirt` gem.[/]")
67
+ Thread.current[:tags] << '-libvirt'
68
+ end
@@ -0,0 +1,102 @@
1
+ def collection_tests(collection, params = {}, mocks_implemented = true)
2
+
3
+ tests('success') do
4
+
5
+ tests("#new(#{params.inspect})").succeeds do
6
+ pending if Fog.mocking? && !mocks_implemented
7
+ collection.new(params)
8
+ end
9
+
10
+ tests("#create(#{params.inspect})").succeeds do
11
+ pending if Fog.mocking? && !mocks_implemented
12
+ @instance = collection.create(params)
13
+ end
14
+
15
+ # FIXME: work around for timing issue on AWS describe_instances mocks
16
+ if Fog.mocking? && @instance.respond_to?(:ready?)
17
+ @instance.wait_for { ready? }
18
+ end
19
+
20
+ tests("#all").succeeds do
21
+ pending if Fog.mocking? && !mocks_implemented
22
+ collection.all
23
+ end
24
+
25
+
26
+
27
+ if !Fog.mocking? || mocks_implemented
28
+ @identity = @instance.identity
29
+ end
30
+
31
+ tests("#get(#{@identity})").succeeds do
32
+ pending if Fog.mocking? && !mocks_implemented
33
+ collection.get(@identity)
34
+ end
35
+
36
+ tests('Enumerable') do
37
+ pending if Fog.mocking? && !mocks_implemented
38
+
39
+ methods = [
40
+ 'all?', 'any?', 'find', 'detect', 'collect', 'map',
41
+ 'find_index', 'flat_map', 'collect_concat', 'group_by',
42
+ 'none?', 'one?'
43
+ ]
44
+
45
+ # JRuby 1.7.5+ issue causes a SystemStackError: stack level too deep
46
+ # https://github.com/jruby/jruby/issues/1265
47
+ if RUBY_PLATFORM == "java" and JRUBY_VERSION =~ /1\.7\.[5-8]/
48
+ methods.delete('all?')
49
+ end
50
+
51
+ methods.each do |enum_method|
52
+ if collection.respond_to?(enum_method)
53
+ tests("##{enum_method}").succeeds do
54
+ block_called = false
55
+ collection.send(enum_method) {|x| block_called = true }
56
+ block_called
57
+ end
58
+ end
59
+ end
60
+
61
+ [
62
+ 'max_by','min_by'
63
+ ].each do |enum_method|
64
+ if collection.respond_to?(enum_method)
65
+ tests("##{enum_method}").succeeds do
66
+ block_called = false
67
+ collection.send(enum_method) {|x| block_called = true; 0 }
68
+ block_called
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+
76
+
77
+ if block_given?
78
+ yield
79
+ end
80
+
81
+ if !Fog.mocking? || mocks_implemented
82
+ @instance.destroy
83
+ end
84
+ end
85
+
86
+ tests('failure') do
87
+
88
+ if !Fog.mocking? || mocks_implemented
89
+ @identity = @identity.to_s
90
+ @identity = @identity.gsub(/[a-zA-Z]/) { Fog::Mock.random_letters(1) }
91
+ @identity = @identity.gsub(/\d/) { Fog::Mock.random_numbers(1) }
92
+ @identity
93
+ end
94
+
95
+ tests("#get('#{@identity}')").returns(nil) do
96
+ pending if Fog.mocking? && !mocks_implemented
97
+ collection.get(@identity)
98
+ end
99
+
100
+ end
101
+
102
+ end
@@ -0,0 +1,34 @@
1
+ def flavors_tests(connection, params = {}, mocks_implemented = true)
2
+
3
+ tests('success') do
4
+
5
+ tests("#all").succeeds do
6
+ pending if Fog.mocking? && !mocks_implemented
7
+ connection.flavors.all
8
+ end
9
+
10
+ if !Fog.mocking? || mocks_implemented
11
+ @identity = connection.flavors.first.identity
12
+ end
13
+
14
+ tests("#get('#{@identity}')").succeeds do
15
+ pending if Fog.mocking? && !mocks_implemented
16
+ connection.flavors.get(@identity)
17
+ end
18
+
19
+ end
20
+
21
+ tests('failure') do
22
+
23
+ if !Fog.mocking? || mocks_implemented
24
+ invalid_flavor_identity = connection.flavors.first.identity.to_s.gsub(/\w/, '0')
25
+ end
26
+
27
+ tests("#get('#{invalid_flavor_identity}')").returns(nil) do
28
+ pending if Fog.mocking? && !mocks_implemented
29
+ connection.flavors.get(invalid_flavor_identity)
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,27 @@
1
+ def server_tests(connection, params = {}, mocks_implemented = true)
2
+
3
+ model_tests(connection.servers, params, mocks_implemented) do
4
+
5
+ tests('#reload').returns(true) do
6
+ pending if Fog.mocking? && !mocks_implemented
7
+ @instance.wait_for { ready? }
8
+ identity = @instance.identity
9
+ !identity.nil? && identity == @instance.reload.identity
10
+ end
11
+
12
+ responds_to([:ready?, :state])
13
+ yield if block_given?
14
+
15
+ tests('#reboot').succeeds do
16
+ pending if Fog.mocking? && !mocks_implemented
17
+ @instance.wait_for { ready? }
18
+ @instance.reboot
19
+ end
20
+
21
+ if !Fog.mocking? || mocks_implemented
22
+ @instance.wait_for { ready? }
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,12 @@
1
+ def servers_tests(connection, params = {}, mocks_implemented = true)
2
+
3
+ collection_tests(connection.servers, params, mocks_implemented) do
4
+
5
+ if !Fog.mocking? || mocks_implemented
6
+ @instance.wait_for { ready? }
7
+ yield if block_given?
8
+ end
9
+
10
+ end
11
+
12
+ end
@@ -0,0 +1,99 @@
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
+
30
+ # Generates a Shindo test that compares a hash schema to the result
31
+ # of the passed in block returning true if they match.
32
+ #
33
+ # The schema that is passed in is a Hash or Array of hashes that
34
+ # have Classes in place of values. When checking the schema the
35
+ # value should match the Class.
36
+ #
37
+ # Strict mode will fail if the data has additional keys. Setting
38
+ # +strict+ to +false+ will allow additional keys to appear.
39
+ #
40
+ # @param [Hash] schema A Hash schema
41
+ # @param [Hash] options Options to change validation rules
42
+ # @option options [Boolean] :allow_extra_keys
43
+ # If +true+ does not fail when keys are in the data that are
44
+ # not specified in the schema. This allows new values to
45
+ # appear in API output without breaking the check.
46
+ # @option options [Boolean] :allow_optional_rules
47
+ # If +true+ does not fail if extra keys are in the schema
48
+ # that do not match the data. Not recommended!
49
+ # @yield Data to check with schema
50
+ #
51
+ # @example Using in a test
52
+ # Shindo.tests("comparing welcome data against schema") do
53
+ # data = {:welcome => "Hello" }
54
+ # data_matches_schema(:welcome => String) { data }
55
+ # end
56
+ #
57
+ # comparing welcome data against schema
58
+ # + data matches schema
59
+ #
60
+ # @example Example schema
61
+ # {
62
+ # "id" => String,
63
+ # "ram" => Integer,
64
+ # "disks" => [
65
+ # {
66
+ # "size" => Float
67
+ # }
68
+ # ],
69
+ # "dns_name" => Fog::Nullable::String,
70
+ # "active" => Fog::Boolean,
71
+ # "created" => DateTime
72
+ # }
73
+ #
74
+ # @return [Boolean]
75
+ def data_matches_schema(schema, options = {})
76
+ test('data matches schema') do
77
+ validator = Fog::Schema::DataValidator.new
78
+ valid = validator.validate(yield, schema, options)
79
+ @message = validator.message unless valid
80
+ valid
81
+ end
82
+ end
83
+
84
+ # @deprecated #formats is deprecated. Use #data_matches_schema instead
85
+ def formats(format, strict = true)
86
+ test('has proper format') do
87
+ if strict
88
+ options = {:allow_extra_keys => false, :allow_optional_rules => true}
89
+ else
90
+ options = {:allow_extra_keys => true, :allow_optional_rules => true}
91
+ end
92
+ validator = Fog::Schema::DataValidator.new
93
+ valid = validator.validate(yield, format, options)
94
+ @message = validator.message unless valid
95
+ valid
96
+ end
97
+ end
98
+ end
99
+ end