This repository was archived by the owner on Aug 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 501
Expand file tree
/
Copy pathmulti_ha_func_test.rb
More file actions
104 lines (80 loc) · 3.13 KB
/
multi_ha_func_test.rb
File metadata and controls
104 lines (80 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#--
# Copyright 2013 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#++
require_relative '../test_helper'
require 'fileutils'
class MultiHaFuncTest < OpenShift::NodeBareTestCase
def setup
@api = FunctionalApi.new
@namespace = @api.create_domain
@api.up_gears(10)
@api.enable_ha
@framework_cartridge = ENV['CART_TO_TEST'] || 'mock-0.1'
logger.info("Using framework cartridge: #{@framework_cartridge}")
end
def teardown
@api.delete_domain unless @api.nil? || ENV['PRESERVE']
end
def test_ha_enable
app_name = "app#{@api.random_string}"
app_id = @api.create_application(app_name, [@framework_cartridge], true)
app_container = OpenShift::Runtime::ApplicationContainer.from_uuid(app_id)
gear_registry = OpenShift::Runtime::GearRegistry.new(app_container)
entries = gear_registry.entries
logger.info("Gear registry contents: #{entries}")
web_entries = entries[:web]
assert_equal 1, web_entries.keys.size
proxy_entries = entries[:proxy]
assert_equal 1, proxy_entries.keys.size
logger.info "Enabling HA for #{app_name}"
@api.make_ha(app_name)
gear_registry.load
entries = gear_registry.entries
logger.info("Gear registry contents: #{entries}")
web_entries = entries[:web]
assert_equal 2, web_entries.keys.size
proxy_entries = entries[:proxy]
assert_equal 2, proxy_entries.keys.size
@api.assert_scales_to(app_name, @framework_cartridge, 3)
@api.assert_scales_to(app_name, @framework_cartridge, 4)
@api.assert_scales_to(app_name, @framework_cartridge, 5)
gear_registry.load
entries = gear_registry.entries
proxy_entries = entries[:proxy]
# test restart
assert_proxies_disabled(proxy_entries)
@api.restart_cartridge(app_name, @framework_cartridge)
assert_proxies_disabled(proxy_entries)
@api.add_env_vars(app_name,[{name:"OPENSHIFT_HAPROXY_GEAR_RATIO",value:"4"}])
@api.assert_scales_to(app_name, @framework_cartridge, 6)
assert_proxies_not_disabled(proxy_entries)
@api.assert_scales_to(app_name, @framework_cartridge, 7)
assert_proxies_disabled(proxy_entries)
end
def assert_proxies_status(proxy_entries, status)
proxy_entries.values.each do |proxy|
logger.info "Checking target gears " +
proxy_entries.values.map {|p| p.dns}.join(', ') +
" status from proxy #{proxy.dns}"
@api.assert_gear_status_in_proxy(proxy, proxy_entries.values, status)
end
end
def assert_proxies_disabled(proxy_entries)
assert_proxies_status(proxy_entries, 'MAINT')
end
def assert_proxies_not_disabled(proxy_entries)
assert_proxies_status(proxy_entries, 'UP')
end
end