cloudstack_spec 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +13 -0
  5. data/README.md +127 -0
  6. data/Rakefile +2 -0
  7. data/bin/cloudstackspec-init +7 -0
  8. data/cloudstack_spec.gemspec +29 -0
  9. data/examples/output_example.txt +56 -0
  10. data/lib/cloudstack_spec.rb +56 -0
  11. data/lib/cloudstack_spec/helper.rb +9 -0
  12. data/lib/cloudstack_spec/helper/api.rb +40 -0
  13. data/lib/cloudstack_spec/helper/resource.rb +19 -0
  14. data/lib/cloudstack_spec/matcher.rb +12 -0
  15. data/lib/cloudstack_spec/matcher/be_allocated.rb +23 -0
  16. data/lib/cloudstack_spec/matcher/be_created.rb +30 -0
  17. data/lib/cloudstack_spec/matcher/be_ready.rb +17 -0
  18. data/lib/cloudstack_spec/matcher/be_running.rb +17 -0
  19. data/lib/cloudstack_spec/matcher/be_set.rb +18 -0
  20. data/lib/cloudstack_spec/resource.rb +1 -0
  21. data/lib/cloudstack_spec/resource/account.rb +102 -0
  22. data/lib/cloudstack_spec/resource/base.rb +58 -0
  23. data/lib/cloudstack_spec/resource/domain.rb +71 -0
  24. data/lib/cloudstack_spec/resource/network.rb +90 -0
  25. data/lib/cloudstack_spec/resource/project.rb +66 -0
  26. data/lib/cloudstack_spec/resource/snapshot.rb +53 -0
  27. data/lib/cloudstack_spec/resource/system_vm.rb +55 -0
  28. data/lib/cloudstack_spec/resource/template.rb +41 -0
  29. data/lib/cloudstack_spec/resource/template_from_snapshot.rb +73 -0
  30. data/lib/cloudstack_spec/resource/virtual_machine.rb +245 -0
  31. data/lib/cloudstack_spec/resource/vpc.rb +139 -0
  32. data/lib/cloudstack_spec/resource/vpc_tier.rb +81 -0
  33. data/lib/cloudstack_spec/resource/zone.rb +51 -0
  34. data/lib/cloudstack_spec/setup.rb +191 -0
  35. data/lib/cloudstack_spec/version.rb +3 -0
  36. data/spec/config.yml +5 -0
  37. data/spec/lib/1_zone_spec.rb +18 -0
  38. data/spec/lib/domain_spec.rb +20 -0
  39. data/spec/lib/network_spec.rb +45 -0
  40. data/spec/lib/snapshot_spec.rb +41 -0
  41. data/spec/lib/template_spec.rb +11 -0
  42. data/spec/lib/virtual_machine_spec.rb +17 -0
  43. data/spec/lib/vpc_spec.rb +40 -0
  44. data/spec/preprod/001_zone_spec.rb +65 -0
  45. data/spec/preprod/010_domain_spec.rb +18 -0
  46. data/spec/preprod/snapshot_spec.rb +27 -0
  47. data/spec/spec_helper.rb +31 -0
  48. metadata +207 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 61f87ea881f5a0783f43f8e36f9b2f8dc259bdfc
4
+ data.tar.gz: 8f00617d2bb2afa76eb774d1a681a9cd40ffa668
5
+ SHA512:
6
+ metadata.gz: ccb5830c0d4742e25ab50502ac30ac58bf93869e7a83380f314ab6df177008b23736ecbe54c74e56c39b4ea35829a81b8eee25623aa080eab2385c123ce98245
7
+ data.tar.gz: cc861a825f3833307b487398bb6265802ec5968386af83526d7be96e6088b44aca63dcc710b81de3a19d3017d9e6437369d4c47244de21190896fd882cb92a4d
@@ -0,0 +1,16 @@
1
+ notes.txt
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
16
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cloudstack_spec.gemspec
4
+ gemspec
@@ -0,0 +1,13 @@
1
+ Copyright 2014 Pierre-Luc Dion
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain 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,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,127 @@
1
+ # CloudstackSpec
2
+
3
+ ...Work In Progress...
4
+
5
+ [Apache CloudStack](http://cloudstack.apache.org/) test framework based on Rspec library. Similar to [serverspec](http://serverspec.org/) it is used to test and validate CloudStack installation and configurations.
6
+
7
+
8
+ ## Installation
9
+
10
+ install as gem:
11
+
12
+ $ gem install cloudstack_spec
13
+
14
+ Create a test repo folder:
15
+
16
+ $ mkdir my_cloudstack_spec
17
+ $ cd my_cloudstack_spec
18
+
19
+ Initialize cloudstack_spec:
20
+
21
+ $ cloudstackspec-init
22
+ Create base for cloudstack_spec? y/n: y
23
+ + spec/
24
+ + spec/lib/
25
+ + spec/config.yml
26
+ + spec/lib/001_zone_spec.rb
27
+ + spec/spec_helper.rb
28
+ Make sure to Update file: spec/config.yml
29
+ $
30
+
31
+ or
32
+
33
+ Clone this repo:
34
+
35
+ $ git clone https://github.com/pdion891/cloudstack_spec.git
36
+ $ cd cloudstack_spec
37
+
38
+
39
+ ## Configuration
40
+
41
+ Update ``spec/config.yml`` to reflect your environment
42
+
43
+ ```yaml
44
+ cloudstack:
45
+ url: http://[cloustack_management_ip]:8080/client/api
46
+ api_key: rkVsYauTGYkR2I0aX3Qmh4s3cfdtR5LNnw7cNKCpHnzKsA-zaXUn7k__fbBga-l0BQl9Qlmq57tkaj67L7W_bg
47
+ secret_key: dS0grBtPMbg5PTr62VLeApd55pssU5fObcW-hmGjiUNyBWw67BRPWRJrXQ5OfO0LTzLRdN-pHiDz25K1o3qLeA
48
+ use_ssl: false
49
+ ```
50
+
51
+ ## Usage
52
+
53
+ Create test definition file in ``spec/lib/[test]_spec.rb`` as example in the directory.
54
+
55
+ ### test example
56
+
57
+ ```spec
58
+ require 'spec_helper'
59
+
60
+ describe zone do
61
+ it { should exist }
62
+ it { should be_allocated }
63
+ its(:local_storage) { should be_set }
64
+ its(:security_group) { should_not be_set }
65
+ its(:network_type) { should match("Advanced") }
66
+ end
67
+
68
+ %w(consoleproxy secondarystoragevm).each do |svm|
69
+ describe system_vm(svm) do
70
+ it { should exist }
71
+ it { should be_running }
72
+ it { should be_reachable }
73
+ end
74
+ end
75
+
76
+ ```
77
+
78
+ ### Execute test run
79
+
80
+ Simply run ``rspec`` or define test case file as follow:
81
+
82
+ ```bash
83
+ rspec spec/lib/[test_scenario]_spec.rb
84
+
85
+ #ex:
86
+
87
+ rspec spec/lib/001_zone_spec.rb
88
+ ```
89
+
90
+ Output example:
91
+
92
+ $ rspec spec/lib/1_zone_spec.rb
93
+ Testing system: http://123.123.123.123:8080/client/api
94
+ CloudStack version: 4.4.1
95
+ executed at: 2014-11-16 19:28:49 -0500
96
+
97
+ Zone "preprod2_zone1"
98
+ should exist
99
+ should be allocated (Enabled)
100
+ local_storage
101
+ should be enabled
102
+ security_group
103
+ should not be enabled
104
+ network_type
105
+ should match "Advanced"
106
+
107
+ System Vm "consoleproxy"
108
+ should exist
109
+ should be running
110
+ should be reachable
111
+
112
+ System Vm "secondarystoragevm"
113
+ should exist
114
+ should be running
115
+ should be reachable
116
+
117
+ Finished in 2.24 seconds (files took 1.2 seconds to load)
118
+ 11 examples, 0 failures
119
+
120
+
121
+ ## Contributing
122
+
123
+ 1. Fork it ( https://github.com/pdion891/cloudstack_spec/fork )
124
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
125
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
126
+ 4. Push to the branch (`git push origin my-new-feature`)
127
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib/cloudstack_spec/setup])
4
+
5
+ require 'cloudstack_spec/setup'
6
+
7
+ CloudstackSpec::Setup.run
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cloudstack_spec/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cloudstack_spec"
8
+ spec.version = CloudstackSpec::VERSION
9
+ spec.authors = ["Pierre-Luc Dion"]
10
+ spec.email = ["pdion891@apache.org"]
11
+ spec.summary = %q{RSpec tests for Apache CloudStack.}
12
+ spec.description = %q{Servespec like tests for Apache CloudStack using Rspec.}
13
+ spec.homepage = "https://github.com/pdion891/cloudstack_spec"
14
+ spec.license = "Apache 2.0"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency 'yaml', '~> 0'
24
+ spec.add_runtime_dependency "rspec-its", '~> 1'
25
+ spec.add_runtime_dependency "rspec", '~> 3'
26
+ spec.add_runtime_dependency "uuid", '~> 2'
27
+ spec.add_runtime_dependency "cloudstack_ruby_client", '~> 1.0', '>= 1.0.2'
28
+
29
+ end
@@ -0,0 +1,56 @@
1
+ Testing system: http://172.16.21.126:8080/client/api
2
+ CloudStack version: 4.4.1
3
+
4
+ Zone "preprod2_zone1"
5
+ should exist
6
+ should be allocated (Enabled)
7
+ local_storage
8
+ should be enabled
9
+ security_group
10
+ should not be enabled
11
+ network_type
12
+ should match "Advanced"
13
+
14
+ System Vm "consoleproxy"
15
+ should exist
16
+ should be running
17
+ should be reachable
18
+
19
+ System Vm "secondarystoragevm"
20
+ should exist
21
+ should be running
22
+ should be reachable
23
+
24
+ Network "test1"
25
+ should exist
26
+ should be ready (FAILED - 1)
27
+
28
+ Template "CentOS 5.6(64-bit) no GUI (XenServer)"
29
+ should exist
30
+ should be ready
31
+
32
+ Template "Ubuntu 14.04 LTS"
33
+ should exist
34
+ should be ready (FAILED - 2)
35
+
36
+ Failures:
37
+
38
+ 1) Network "test1" should be ready
39
+ Failure/Error: it { should be_ready }
40
+ status: VR state: Stopped
41
+
42
+ # ./spec/lib/network_spec.rb:3:in `block (2 levels) in <top (required)>'
43
+
44
+ 2) Template "Ubuntu 14.04 LTS" should be ready
45
+ Failure/Error: it { should be_ready }
46
+ status: 7% Downloaded
47
+
48
+ # ./spec/lib/template_spec.rb:10:in `block (2 levels) in <top (required)>'
49
+
50
+ Finished in 24.68 seconds (files took 1.47 seconds to load)
51
+ 17 examples, 2 failures
52
+
53
+ Failed examples:
54
+
55
+ rspec ./spec/lib/network_spec.rb:3 # Network "test1" should be ready
56
+ rspec ./spec/lib/template_spec.rb:10 # Template "Ubuntu 14.04 LTS" should be ready
@@ -0,0 +1,56 @@
1
+ require 'rspec'
2
+ require 'rspec/its'
3
+ require 'specinfra'
4
+ require 'cloudstack_spec/version'
5
+ require 'cloudstack_spec/resource'
6
+ require 'cloudstack_spec/helper'
7
+ require 'cloudstack_spec/matcher'
8
+ require 'cloudstack_spec/setup'
9
+ require 'cloudstack_spec/resource/base'
10
+
11
+
12
+ module CloudstackSpec
13
+
14
+ #output the url + version under test
15
+ @client = CloudstackSpec::Helper::Api.new
16
+ puts "Testing system: #{@client.url}"
17
+ puts "CloudStack version: #{@client.version}"
18
+ puts "executed at: " + Time.now.to_s
19
+
20
+ end
21
+
22
+ class String
23
+ def to_snake_case
24
+ self.gsub(/::/, '/').
25
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
26
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
27
+ tr("-", "_").
28
+ downcase
29
+ end
30
+
31
+ def to_camel_case
32
+ return self if self !~ /_/ && self =~ /[A-Z]+.*/
33
+ split('_').map{|e| e.capitalize}.join
34
+ end
35
+ end
36
+
37
+ module RSpec::Core::Notifications
38
+ class FailedExampleNotification
39
+ def failure_lines
40
+ @failure_lines ||=
41
+ begin
42
+ lines = []
43
+ # lines << "On host `#{host}'" if host
44
+ lines << "Failure/Error: #{read_failed_line.strip}"
45
+ # lines << "#{exception_class_name}:" unless exception_class_name =~ /RSpec/
46
+ exception.message.to_s.split("\n").each do |line|
47
+ lines << " #{line}" if exception.message
48
+ end
49
+ # lines << " #{example.metadata[:command]}"
50
+ # lines << " #{example.metadata[:stdout]}" if example.metadata[:stdout]
51
+ # lines << " #{example.metadata[:stderr]}" if example.metadata[:stderr]
52
+ # lines
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,9 @@
1
+ # Subject type helper
2
+ require 'cloudstack_spec/helper/resource'
3
+ require 'cloudstack_spec/helper/api'
4
+
5
+ extend CloudstackSpec::Helper::Resource
6
+ class RSpec::Core::ExampleGroup
7
+ extend CloudstackSpec::Helper::Resource
8
+ include CloudstackSpec::Helper::Resource
9
+ end
@@ -0,0 +1,40 @@
1
+ # API call to Apache CloudStack
2
+ module CloudstackSpec::Helper
3
+ class Api
4
+ def connection
5
+ configs = YAML.load_file("spec/config.yml")
6
+ _url = configs['cloudstack']['url']
7
+ _api_key = configs['cloudstack']['api_key']
8
+ _secret_key = configs['cloudstack']['secret_key']
9
+ _use_ssl = configs['cloudstack']['use_ssl']
10
+ @client = CloudstackRubyClient::Client.new(
11
+ "#{_url}",
12
+ "#{_api_key}",
13
+ "#{_secret_key}",
14
+ _use_ssl)
15
+ end
16
+
17
+ def connection2
18
+ configs = YAML.load_file("spec/config.yml")
19
+ _url = configs['cloudstack']['url']
20
+ _use_ssl = configs['cloudstack']['use_ssl']
21
+ _api_key = $api_key
22
+ _secret_key = $secret_key
23
+ @client = CloudstackRubyClient::Client.new(
24
+ "#{_url}",
25
+ "#{_api_key}",
26
+ "#{_secret_key}",
27
+ _use_ssl)
28
+ end
29
+
30
+ def url
31
+ connection.instance_variable_get(:@api_url)
32
+ end
33
+
34
+ def version
35
+ connection.list_capabilities["capability"]["cloudstackversion"]
36
+ end
37
+ end
38
+ end
39
+
40
+
@@ -0,0 +1,19 @@
1
+ module CloudstackSpec
2
+ module Helper
3
+ module Resource
4
+ resources = %w(
5
+ base template zone system_vm network virtual_machine vpc snapshot
6
+ template_from_snapshot vpc_tier domain account project
7
+ )
8
+
9
+ resources.each {|resource| require "cloudstack_spec/resource/#{resource}" }
10
+
11
+ resources.each do |resource|
12
+ define_method resource do |*args|
13
+ name = args.first
14
+ eval "CloudstackSpec::Resource::#{resource.to_camel_case}.new(name)"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ # GENERIC
2
+ require 'cloudstack_spec/matcher/be_set'
3
+ require 'cloudstack_spec/matcher/be_running'
4
+
5
+ # ZONE
6
+ require 'cloudstack_spec/matcher/be_allocated'
7
+
8
+ # TEMPLATE
9
+ require 'cloudstack_spec/matcher/be_ready'
10
+
11
+ # VIRTUAL-MACHINE
12
+ require 'cloudstack_spec/matcher/be_created'
@@ -0,0 +1,23 @@
1
+ # If the zone is allocated (Enabled)
2
+
3
+ RSpec::Matchers.define :be_allocated do |expected|
4
+ match do |actual|
5
+ actual.allocated? == true
6
+ end
7
+
8
+ failure_message do |actual|
9
+ "status: #{actual.allocated?}"
10
+ end
11
+
12
+ description do
13
+ "be allocated (Enabled)"
14
+ end
15
+
16
+ failure_message_when_negated do |actual|
17
+ "Status: #{actual}"
18
+ end
19
+
20
+ chain :with_level do |level|
21
+ @level = level
22
+ end
23
+ end
@@ -0,0 +1,30 @@
1
+ RSpec::Matchers.define :created do |expected|
2
+ match do |actual|
3
+ #UUID.validate(actualz) == true
4
+ #puts "actual = #{actual}"
5
+ #puts "#{actual.name}"
6
+ #if UUID.validate(actual.is_created?) == true
7
+ # jobstatus = @connection.query_async_job_result(jobid: actual)['jobstatus']
8
+ # until jobstatus != 0
9
+ # jobstatus = @connection.query_async_job_result(jobid: actual)['jobstatus']
10
+ # sleep(5)
11
+ # end
12
+ # jobstatus == 1
13
+ #else
14
+ # false
15
+ #end
16
+ end
17
+
18
+ failure_message do |actual|
19
+ "#{actual} status: #{actual.is_creating}"
20
+ end
21
+
22
+ description do
23
+ "#{actual} be created, #{actual.is_creating}"
24
+ end
25
+
26
+ failure_message_when_negated do |actual|
27
+ "VM creation not should not be possible"
28
+ end
29
+
30
+ end