opsmgr 0.26.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/LEGAL.txt +13 -0
  3. data/README.md +21 -0
  4. data/lib/opsmgr.rb +12 -0
  5. data/lib/opsmgr/api/client.rb +85 -0
  6. data/lib/opsmgr/api/endpoints_factory.rb +39 -0
  7. data/lib/opsmgr/api/http_client.rb +204 -0
  8. data/lib/opsmgr/api/results.rb +257 -0
  9. data/lib/opsmgr/api/version20/endpoints.rb +93 -0
  10. data/lib/opsmgr/cmd/bosh_command.rb +213 -0
  11. data/lib/opsmgr/cmd/ops_manager.rb +100 -0
  12. data/lib/opsmgr/environments.rb +77 -0
  13. data/lib/opsmgr/errand_runner.rb +75 -0
  14. data/lib/opsmgr/log.rb +70 -0
  15. data/lib/opsmgr/product_upload_wrapper.rb +69 -0
  16. data/lib/opsmgr/renderer.rb +23 -0
  17. data/lib/opsmgr/renderer/aws.rb +147 -0
  18. data/lib/opsmgr/renderer/noop.rb +21 -0
  19. data/lib/opsmgr/settings/microbosh/installation_settings.rb +84 -0
  20. data/lib/opsmgr/settings/microbosh/job.rb +54 -0
  21. data/lib/opsmgr/settings/microbosh/job_list.rb +27 -0
  22. data/lib/opsmgr/settings/microbosh/network.rb +21 -0
  23. data/lib/opsmgr/settings/microbosh/product.rb +88 -0
  24. data/lib/opsmgr/settings/microbosh/product_list.rb +27 -0
  25. data/lib/opsmgr/settings/microbosh/property.rb +31 -0
  26. data/lib/opsmgr/settings/microbosh/property_list.rb +27 -0
  27. data/lib/opsmgr/tasks.rb +16 -0
  28. data/lib/opsmgr/tasks/bosh.rake +70 -0
  29. data/lib/opsmgr/tasks/destroy.rake +42 -0
  30. data/lib/opsmgr/tasks/info.rake +19 -0
  31. data/lib/opsmgr/tasks/opsmgr.rake +179 -0
  32. data/lib/opsmgr/tasks/product.rake +53 -0
  33. data/lib/opsmgr/teapot.rb +51 -0
  34. data/lib/opsmgr/teapot/app.rb +50 -0
  35. data/lib/opsmgr/teapot/spec_helper.rb +33 -0
  36. data/lib/opsmgr/ui_helpers/add_first_user_spec.rb +25 -0
  37. data/lib/opsmgr/ui_helpers/config_helper.rb +151 -0
  38. data/lib/opsmgr/ui_helpers/delete_installation_spec.rb +41 -0
  39. data/lib/opsmgr/ui_helpers/delete_product_if_present_spec.rb +43 -0
  40. data/lib/opsmgr/ui_helpers/delete_product_spec.rb +39 -0
  41. data/lib/opsmgr/ui_helpers/export_installation_spec.rb +31 -0
  42. data/lib/opsmgr/ui_helpers/get_latest_install_log_spec.rb +29 -0
  43. data/lib/opsmgr/ui_helpers/import_installation_spec.rb +29 -0
  44. data/lib/opsmgr/ui_helpers/import_stemcell_spec.rb +30 -0
  45. data/lib/opsmgr/ui_helpers/microbosh/configure_microbosh_spec.rb +31 -0
  46. data/lib/opsmgr/ui_helpers/trigger_install_spec.rb +35 -0
  47. data/lib/opsmgr/ui_helpers/ui_spec_runner.rb +117 -0
  48. data/lib/opsmgr/ui_helpers/uncheck_errands_spec.rb +29 -0
  49. data/lib/opsmgr/ui_helpers/upload_and_add_product_spec.rb +27 -0
  50. data/lib/opsmgr/ui_helpers/upload_and_upgrade_product_spec.rb +36 -0
  51. data/lib/opsmgr/version.rb +11 -0
  52. metadata +360 -0
@@ -0,0 +1,53 @@
1
+ namespace :opsmgr do
2
+ namespace :product do
3
+ desc 'Upload and Add a Pivotal Product'
4
+ task :upload_add, [:environment, :_om_version, :product_path, :product_name] do |_, args|
5
+ require 'opsmgr/product_upload_wrapper'
6
+
7
+ ProductUploadWrapper.wrap_add(
8
+ environment: args.environment,
9
+ product_path: args.product_path,
10
+ product_name: args.product_name
11
+ )
12
+ end
13
+
14
+ desc 'Upgrade a Generic Pivotal Product'
15
+ task :upload_upgrade, [:environment, :_om_version, :product_path, :product_name] do |_, args|
16
+ require 'opsmgr/product_upload_wrapper'
17
+
18
+ ProductUploadWrapper.wrap_upgrade(
19
+ environment: args.environment,
20
+ product_path: args.product_path,
21
+ product_name: args.product_name
22
+ )
23
+ end
24
+
25
+ desc 'Import a stemcell for a Generic Pivotal Product'
26
+ task :import_stemcell, [:environment, :om_version, :stemcell_path, :product_name] do |_, args|
27
+ require 'opsmgr/ui_helpers/ui_spec_runner'
28
+
29
+ UiSpecRunner.new(
30
+ environment: args.environment,
31
+ om_version: args.om_version
32
+ ).import_stemcell(args.stemcell_path, args.product_name)
33
+ end
34
+
35
+ desc 'Uncheck errands for a Generic Pivotal Product'
36
+ task :uncheck_errands, [:environment, :om_version, :product_name] do |_, args|
37
+ require 'opsmgr/ui_helpers/ui_spec_runner'
38
+
39
+ UiSpecRunner.new(
40
+ environment: args.environment,
41
+ om_version: args.om_version
42
+ ).uncheck_errands(args.product_name, args.extras)
43
+ end
44
+ end
45
+ end
46
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
47
+ # All rights reserved.
48
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
49
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
50
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
51
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
52
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
53
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ require 'socket'
2
+ require 'timeout'
3
+
4
+ require 'opsmgr/teapot/app'
5
+
6
+ module Opsmgr
7
+ module Teapot
8
+ class << self
9
+ attr_accessor :configured_components
10
+
11
+ def start(components)
12
+ @configured_components = components
13
+ @teapot_tempest_thread = Thread.new do
14
+ silence(:stderr) do # Teapot's Sinatra is very chatty on stderr.
15
+ Opsmgr::Teapot::App.run!
16
+ end
17
+ end
18
+
19
+ fail 'Teapot never started!' unless listening?
20
+ end
21
+
22
+ def stop
23
+ @teapot_tempest_thread.kill
24
+ end
25
+
26
+ private
27
+
28
+ def listening?
29
+ # inspired by http://stackoverflow.com/a/9017896
30
+ Timeout.timeout(5) do
31
+ begin
32
+ TCPSocket.new('localhost', App.port).close
33
+ true
34
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
35
+ retry
36
+ end
37
+ end
38
+ rescue Timeout::Error
39
+ false
40
+ end
41
+ end
42
+ end
43
+ end
44
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
45
+ # All rights reserved.
46
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
47
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
48
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
49
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
50
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
51
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,50 @@
1
+ require 'sinatra/base'
2
+ require 'json'
3
+
4
+ module Opsmgr
5
+ module Teapot
6
+ class App < Sinatra::Base
7
+ set :port, 8741
8
+ enable :sessions
9
+ set :server, 'webrick'
10
+
11
+ get '/api/api_version' do
12
+ content_type :json
13
+ case @@version
14
+ when '1.4'
15
+ api_version = '2.0'
16
+ end
17
+ { 'version' => api_version }.to_json
18
+ end
19
+
20
+ get '/teapot/reset' do
21
+ @@installs = nil
22
+ @@components = nil
23
+ @@products = nil
24
+ @@logged_in_users = nil
25
+ @@everyone_logged_in = false
26
+ @@enable_number_of_cores_error = nil
27
+ end
28
+
29
+ post '/teapot/version' do
30
+ Teapot.configured_components.components_for(params['version']).each do |component|
31
+ components << component
32
+ end
33
+ @@version = params['version']
34
+ { version: params['version'] }.to_json
35
+ end
36
+
37
+ def components
38
+ @@components ||= []
39
+ end
40
+ end
41
+ end
42
+ end
43
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
44
+ # All rights reserved.
45
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
46
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
47
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
48
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
49
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
50
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ require 'net/http'
2
+
3
+ module Opsmgr
4
+ module Teapot
5
+ module SpecHelper
6
+ def set_teapot_version(version)
7
+ post('/teapot/version', version: version)
8
+ end
9
+
10
+ def post(path, params = {})
11
+ req = Net::HTTP::Post.new(path)
12
+ req.set_form_data(params)
13
+ response = teapot_client.request(req)
14
+
15
+ fail "Teapot gave HTTP response #{response.code} POST of #{path} with #{params.inspect}" if response.is_a?(Net::HTTPInternalServerError)
16
+
17
+ response
18
+ end
19
+
20
+ def teapot_client
21
+ Net::HTTP.new('localhost', App.port)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
27
+ # All rights reserved.
28
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
29
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
30
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
32
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
33
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,25 @@
1
+ require_relative 'config_helper'
2
+
3
+ RSpec.describe 'Adding the first user', order: :defined do
4
+ let!(:current_ops_manager) { ops_manager_driver }
5
+ let!(:env_settings) { fetch_environment_settings }
6
+
7
+ it 'creates the admin user and logs in' do
8
+ poll_up_to_mins(10) do
9
+ current_ops_manager.setup_page.setup_or_login(
10
+ user: env_settings.ops_manager.username,
11
+ password: env_settings.ops_manager.password,
12
+ )
13
+
14
+ expect(page).to have_content('Installation Dashboard')
15
+ end
16
+ end
17
+ end
18
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
19
+ # All rights reserved.
20
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,151 @@
1
+ PROJECT_ROOT = File.expand_path(File.join(__dir__, '..'))
2
+
3
+ require 'rspec'
4
+ require 'ops_manager_ui_drivers'
5
+ require 'recursive-open-struct'
6
+ require 'capybara/webkit'
7
+ require 'yaml'
8
+ require 'opsmgr/environments'
9
+ require 'json'
10
+
11
+ module SettingsHelper
12
+ def product_path
13
+ ENV.fetch('PRODUCT_PATH')
14
+ end
15
+
16
+ def product_name
17
+ ENV.fetch('PRODUCT_NAME')
18
+ end
19
+
20
+ def export_destination_path
21
+ ENV.fetch('EXPORT_DESTINATION')
22
+ end
23
+
24
+ def import_file_path
25
+ ENV.fetch('IMPORT_FILE')
26
+ end
27
+
28
+ def stemcell_file_path
29
+ ENV.fetch('STEMCELL_FILE')
30
+ end
31
+
32
+ def om_version
33
+ ENV.fetch('OM_VERSION')
34
+ end
35
+
36
+ def install_timeout
37
+ ENV.fetch('INSTALL_TIMEOUT').to_i
38
+ end
39
+
40
+ def delete_timeout
41
+ Integer(ENV.fetch('DELETE_TIMEOUT'))
42
+ end
43
+
44
+ def errand_names
45
+ JSON.parse(ENV.fetch('ERRAND_NAMES'))
46
+ end
47
+
48
+ def ops_manager_driver
49
+ configure_capybara(fetch_environment_settings.ops_manager.url)
50
+ case om_version
51
+ when '1.4'
52
+ om_1_4(fetch_environment_settings.ops_manager.url)
53
+ when '1.5'
54
+ om_1_5(fetch_environment_settings.ops_manager.url)
55
+ when '1.6'
56
+ om_1_6(fetch_environment_settings.ops_manager.url)
57
+ when '1.7'
58
+ om_1_7(fetch_environment_settings.ops_manager.url)
59
+ else
60
+ fail "Unsupported Ops Manager Version #{om_version.inspect}"
61
+ end
62
+ end
63
+
64
+ def ops_manager_api_driver
65
+ env_settings = fetch_environment_settings
66
+ case om_version
67
+ when '1.4'
68
+ api_1_4(
69
+ host: env_settings.ops_manager.url,
70
+ username: env_settings.ops_manager.username,
71
+ password: env_settings.ops_manager.password,
72
+ )
73
+ when '1.5'
74
+ api_1_5(
75
+ host: env_settings.ops_manager.url,
76
+ username: env_settings.ops_manager.username,
77
+ password: env_settings.ops_manager.password,
78
+ )
79
+ when '1.6'
80
+ api_1_6(
81
+ host: env_settings.ops_manager.url,
82
+ username: env_settings.ops_manager.username,
83
+ password: env_settings.ops_manager.password,
84
+ )
85
+ when '1.7'
86
+ api_1_7(
87
+ host: env_settings.ops_manager.url,
88
+ username: env_settings.ops_manager.username,
89
+ password: env_settings.ops_manager.password,
90
+ )
91
+ else
92
+ fail "Unsupported Ops Manager Version #{om_version.inspect}"
93
+ end
94
+ end
95
+
96
+ def environment_name
97
+ ENV.fetch('ENVIRONMENT_NAME')
98
+ end
99
+
100
+ def fetch_environment_settings
101
+ Opsmgr::Environments.for(environment_name).settings
102
+ end
103
+
104
+ def configure_capybara(ops_manager_url)
105
+ Capybara.configure do |c|
106
+ c.default_driver = :webkit
107
+ end
108
+
109
+ begin
110
+ Capybara::Webkit.configure do |c|
111
+ c.allow_url(ops_manager_url)
112
+ c.ignore_ssl_errors
113
+ end
114
+ rescue
115
+ # Capybara says, "All configuration must take place before the driver starts"
116
+ end
117
+
118
+ page.current_window.resize_to(1024, 1600) # avoid overlapping footer spec failures
119
+ end
120
+ end
121
+
122
+ RSpec.configure do |config|
123
+ config.fail_fast = true
124
+ config.default_formatter = 'documentation'
125
+
126
+ config.include(SettingsHelper)
127
+ config.include(Capybara::DSL)
128
+ config.include(OpsManagerUiDrivers::PageHelpers)
129
+ config.include(OpsManagerUiDrivers::WaitHelper)
130
+
131
+ config.after(:each) do |example|
132
+ if example.exception
133
+ page = save_page
134
+ screenshot = save_screenshot(nil)
135
+
136
+ exception = example.exception
137
+ exception.define_singleton_method :message do
138
+ super() +
139
+ "\nHTML page: #{page}\nScreenshot: #{screenshot}"
140
+ end
141
+ end
142
+ end
143
+ end
144
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
145
+ # All rights reserved.
146
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
147
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
148
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
149
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
150
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
151
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ require_relative 'config_helper'
2
+
3
+ RSpec.describe 'Deleting the installation', order: :defined do
4
+ let!(:current_ops_manager) { ops_manager_driver }
5
+ let!(:env_settings) { fetch_environment_settings }
6
+
7
+ it 'creates the admin user and logs in' do
8
+ # if the ops manager is not up, fail earlier than other cases and
9
+ # let the caller handle the error
10
+ poll_up_to_mins(1) do
11
+ current_ops_manager.setup_page.setup_or_login(
12
+ user: env_settings.ops_manager.username,
13
+ password: env_settings.ops_manager.password,
14
+ )
15
+
16
+ expect(page).to have_content('Installation Dashboard')
17
+ end
18
+ end
19
+
20
+ it 'deletes the installation' do
21
+ if current_ops_manager.product_dashboard.delete_installation_available?
22
+ current_ops_manager.product_dashboard.delete_whole_installation
23
+
24
+ expect(current_ops_manager.product_dashboard).not_to be_delete_installation_available
25
+
26
+ poll_up_to_mins(45) do
27
+ expect(current_ops_manager.state_change_progress).to be_state_change_success
28
+ end
29
+ else
30
+ puts 'no installation to delete'
31
+ end
32
+ end
33
+ end
34
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
35
+ # All rights reserved.
36
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
37
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
38
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
39
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
40
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
41
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ require_relative 'config_helper'
2
+
3
+ RSpec.describe 'Deleting a product if it is present', order: :defined do
4
+ let!(:current_ops_manager) { ops_manager_driver }
5
+ let!(:env_settings) { fetch_environment_settings }
6
+
7
+ it 'creates the admin user and logs in' do
8
+ poll_up_to_mins(10) do
9
+ current_ops_manager.setup_page.setup_or_login(
10
+ user: env_settings.ops_manager.username,
11
+ password: env_settings.ops_manager.password,
12
+ )
13
+
14
+ expect(page).to have_content('Installation Dashboard')
15
+ end
16
+ end
17
+
18
+ it 'removes the product if it exists on the dashboard' do
19
+ if current_ops_manager.product_dashboard.product_on_dashboard?(product_name)
20
+ current_ops_manager.product_dashboard.delete_product(product_name)
21
+ else
22
+ puts "#{product_name} does not exist on dashboard, skipping deletion"
23
+ end
24
+ end
25
+
26
+ it 'deletes' do
27
+ current_ops_manager.product_dashboard.apply_updates
28
+ end
29
+
30
+ it 'waits for a successful installation' do
31
+ poll_up_to_mins(delete_timeout) do
32
+ expect(current_ops_manager.state_change_progress).to be_state_change_success
33
+ end
34
+ end
35
+ end
36
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
37
+ # All rights reserved.
38
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
39
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
40
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
41
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
42
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
43
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.