Module: BoshVerifyManifest::Assertions
Defined Under Namespace
Modules: Helpers
Instance Method Summary
collapse
Methods included from Helpers
#addresses_in_range?, #network, #pool_names, #pool_sizes, #pool_usage, #undeclared_pools
Instance Method Details
#assert_declares_all_resource_pools(manifest) ⇒ Object
10
11
12
13
14
|
# File 'lib/bosh-verify-manifest/assertions.rb', line 10
def assert_declares_all_resource_pools(manifest)
undeclared_pools(manifest).each do |pool|
flunk "The '#{pool}' pool referred to does not exist"
end
end
|
#assert_fills_resource_pools(manifest) ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/bosh-verify-manifest/assertions.rb', line 16
def assert_fills_resource_pools(manifest)
usage = pool_usage(manifest)
pool_sizes(manifest).each_pair do |pool, instances|
assert instances == usage[pool],
"The '#{pool}' pool is not full (size: #{instances}, wanted: #{usage[pool]})"
end
end
|
#assert_has_name(manifest) ⇒ Object
24
25
26
|
# File 'lib/bosh-verify-manifest/assertions.rb', line 24
def assert_has_name(manifest)
assert manifest.key?('name'), 'The manifest does not have a name'
end
|
#assert_job_addresses_are_appropriate(manifest) ⇒ Object
28
29
30
31
32
33
34
35
36
|
# File 'lib/bosh-verify-manifest/assertions.rb', line 28
def assert_job_addresses_are_appropriate(manifest)
manifest['jobs'].each do |job|
job['networks'].select{|n| n['static_ips']}.each do |network|
ranges = network(manifest, network['name'])['subnets'].map{|s| s['range']}
assert ranges.any?{|r| addresses_in_range?(network['static_ips'], r)},
"The job '#{job['name']}' has static_ips that are not valid for the network '#{network['name']}'"
end
end
end
|
#assert_range_includes_gateway(subnet) ⇒ Object
38
39
40
41
42
|
# File 'lib/bosh-verify-manifest/assertions.rb', line 38
def assert_range_includes_gateway(subnet)
if subnet['gateway']
assert IPAddr.new(subnet['range']).include?(IPAddr.new(subnet['gateway']))
end
end
|
#assert_specifies_director_uuid(manifest) ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/bosh-verify-manifest/assertions.rb', line 44
def assert_specifies_director_uuid(manifest)
assert manifest.key?('director_uuid'), 'The manifest does not specify the UUID of the bosh director'
begin
UUIDTools::UUID.parse(manifest['director_uuid'])
rescue ArgumentError
flunk 'The bosh director UUID is not a well-formed UUID'
end
end
|
#assert_subnet_addresses_in_range(subnet) ⇒ Object
53
54
55
56
57
58
59
60
|
# File 'lib/bosh-verify-manifest/assertions.rb', line 53
def assert_subnet_addresses_in_range(subnet)
%w{reserved static}.each do |address_type|
Array(subnet[address_type]).each do |addresses|
assert addresses_in_range?(addresses, subnet['range']),
"The subnet #{address_type} addresses are not within the range #{subnet['range']}"
end
end
end
|
#assert_subnet_ranges_do_not_overlap(subnets) ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/bosh-verify-manifest/assertions.rb', line 62
def assert_subnet_ranges_do_not_overlap(subnets)
ranges = subnets.map{|s| s['range']}
ranges.permutation(2).each do |range_a, range_b|
refute IPAddr.new(range_a).include?(IPAddr.new(range_b)),
"The subnet ranges #{[range_a, range_b].sort.join(' and ')} overlap"
end
end
|
#assert_subnets_are_consistent(networks) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/bosh-verify-manifest/assertions.rb', line 70
def assert_subnets_are_consistent(networks)
networks.each do |network|
if network['subnets']
network['subnets'].each do |subnet|
assert_range_includes_gateway(subnet)
assert_subnet_addresses_in_range(subnet)
end
assert_subnet_ranges_do_not_overlap(network['subnets'])
end
end
end
|
#refute_exceeds_resource_pools(manifest) ⇒ Object
82
83
84
85
86
87
88
|
# File 'lib/bosh-verify-manifest/assertions.rb', line 82
def refute_exceeds_resource_pools(manifest)
usage = pool_usage(manifest)
pool_sizes(manifest).each_pair do |pool, instances|
assert instances >= usage[pool],
"The '#{pool}' pool is not large enough (size: #{instances}, wanted: #{usage[pool]})"
end
end
|