| 1 |
# Unit tests for nova::compute::provider class |
| 2 |
# |
| 3 |
|
| 4 |
require 'spec_helper' |
| 5 |
|
| 6 |
describe 'nova::compute::provider' do |
| 7 |
|
| 8 |
let :params do |
| 9 |
{} |
| 10 |
end |
| 11 |
|
| 12 |
shared_examples_for 'nova custom resource providers' do |
| 13 |
|
| 14 |
it 'configure nova.conf with default parameters' do |
| 15 |
is_expected.to contain_nova_config('compute/provider_config_location').with_value('/etc/nova/provider_config') |
| 16 |
end |
| 17 |
|
| 18 |
context 'when overriding default parameters' do |
| 19 |
before :each do |
| 20 |
params.merge!( |
| 21 |
:config_location => '/etc/nova/custom_provider_config', |
| 22 |
) |
| 23 |
end |
| 24 |
|
| 25 |
it 'configure nova.conf with overridden parameters' do |
| 26 |
is_expected.to contain_nova_config('compute/provider_config_location').with_value('/etc/nova/custom_provider_config') |
| 27 |
end |
| 28 |
end |
| 29 |
|
| 30 |
context 'when providing custom inventory single inventory without uuid or name set' do |
| 31 |
before :each do |
| 32 |
params.merge!( |
| 33 |
:custom_inventories => [ |
| 34 |
{ |
| 35 |
'inventories' => { |
| 36 |
'CUSTOM_EXAMPLE_RESOURCE_CLASS_1' => { |
| 37 |
'total' => '100', |
| 38 |
'reserved' => '0', |
| 39 |
'min_unit' => '1', |
| 40 |
'max_unit' => '10', |
| 41 |
'step_size' => '1', |
| 42 |
'allocation_ratio' => '1.0' |
| 43 |
}, |
| 44 |
'CUSTOM_EXAMPLE_RESOURCE_CLASS_2' => { |
| 45 |
'total' => '100', |
| 46 |
}, |
| 47 |
}, |
| 48 |
'traits' => [ |
| 49 |
'CUSTOM_P_STATE_ENABLED', |
| 50 |
'CUSTOM_C_STATE_ENABLED', |
| 51 |
], |
| 52 |
}, |
| 53 |
] |
| 54 |
) |
| 55 |
end |
| 56 |
|
| 57 |
it 'configure provider.yaml on compute nodes' do |
| 58 |
is_expected.to contain_file('/etc/nova/provider_config/provider.yaml').with_content( <<EOS |
| 59 |
meta: |
| 60 |
schema_version: '1.0' |
| 61 |
providers: |
| 62 |
# for details check https://docs.openstack.org/nova/latest/admin/managing-resource-providers.html |
| 63 |
- identification: |
| 64 |
uuid: '$COMPUTE_NODE' |
| 65 |
inventories: |
| 66 |
additional: |
| 67 |
- CUSTOM_EXAMPLE_RESOURCE_CLASS_1: |
| 68 |
allocation_ratio: 1.0 |
| 69 |
max_unit: 10 |
| 70 |
min_unit: 1 |
| 71 |
reserved: 0 |
| 72 |
step_size: 1 |
| 73 |
total: 100 |
| 74 |
- CUSTOM_EXAMPLE_RESOURCE_CLASS_2: |
| 75 |
total: 100 |
| 76 |
traits: |
| 77 |
additional: |
| 78 |
- 'CUSTOM_P_STATE_ENABLED' |
| 79 |
- 'CUSTOM_C_STATE_ENABLED' |
| 80 |
EOS |
| 81 |
) |
| 82 |
end |
| 83 |
end |
| 84 |
|
| 85 |
context 'when providing custom inventory single inventory with uuid set' do |
| 86 |
before :each do |
| 87 |
params.merge!( |
| 88 |
:custom_inventories => [ |
| 89 |
{ |
| 90 |
'uuid' => '5213b75d-9260-42a6-b236-f39b0fd10561', |
| 91 |
'inventories' => { |
| 92 |
'CUSTOM_EXAMPLE_RESOURCE_CLASS_1' => { |
| 93 |
'total' => '100', |
| 94 |
'reserved' => '0', |
| 95 |
'min_unit' => '1', |
| 96 |
'max_unit' => '10', |
| 97 |
'step_size' => '1', |
| 98 |
'allocation_ratio' => '1.0' |
| 99 |
}, |
| 100 |
'CUSTOM_EXAMPLE_RESOURCE_CLASS_2' => { |
| 101 |
'total' => '100', |
| 102 |
}, |
| 103 |
}, |
| 104 |
'traits' => [ |
| 105 |
'CUSTOM_P_STATE_ENABLED', |
| 106 |
'CUSTOM_C_STATE_ENABLED', |
| 107 |
], |
| 108 |
}, |
| 109 |
] |
| 110 |
) |
| 111 |
end |
| 112 |
|
| 113 |
it 'configure provider.yaml on compute nodes' do |
| 114 |
is_expected.to contain_file('/etc/nova/provider_config/provider.yaml').with_content( <<EOS |
| 115 |
meta: |
| 116 |
schema_version: '1.0' |
| 117 |
providers: |
| 118 |
# for details check https://docs.openstack.org/nova/latest/admin/managing-resource-providers.html |
| 119 |
- identification: |
| 120 |
uuid: '5213b75d-9260-42a6-b236-f39b0fd10561' |
| 121 |
inventories: |
| 122 |
additional: |
| 123 |
- CUSTOM_EXAMPLE_RESOURCE_CLASS_1: |
| 124 |
allocation_ratio: 1.0 |
| 125 |
max_unit: 10 |
| 126 |
min_unit: 1 |
| 127 |
reserved: 0 |
| 128 |
step_size: 1 |
| 129 |
total: 100 |
| 130 |
- CUSTOM_EXAMPLE_RESOURCE_CLASS_2: |
| 131 |
total: 100 |
| 132 |
traits: |
| 133 |
additional: |
| 134 |
- 'CUSTOM_P_STATE_ENABLED' |
| 135 |
- 'CUSTOM_C_STATE_ENABLED' |
| 136 |
EOS |
| 137 |
) |
| 138 |
end |
| 139 |
end |
| 140 |
|
| 141 |
context 'when providing custom inventory single inventory with name set' do |
| 142 |
before :each do |
| 143 |
params.merge!( |
| 144 |
:custom_inventories => [ |
| 145 |
{ |
| 146 |
'name' => 'EXAMPLE_RESOURCE_PROVIDER', |
| 147 |
'inventories' => { |
| 148 |
'CUSTOM_EXAMPLE_RESOURCE_CLASS_1' => { |
| 149 |
'total' => '100', |
| 150 |
'reserved' => '0', |
| 151 |
'min_unit' => '1', |
| 152 |
'max_unit' => '10', |
| 153 |
'step_size' => '1', |
| 154 |
'allocation_ratio' => '1.0' |
| 155 |
}, |
| 156 |
'CUSTOM_EXAMPLE_RESOURCE_CLASS_2' => { |
| 157 |
'total' => '100', |
| 158 |
}, |
| 159 |
}, |
| 160 |
'traits' => [ |
| 161 |
'CUSTOM_P_STATE_ENABLED', |
| 162 |
'CUSTOM_C_STATE_ENABLED', |
| 163 |
], |
| 164 |
}, |
| 165 |
] |
| 166 |
) |
| 167 |
end |
| 168 |
|
| 169 |
it 'configure provider.yaml on compute nodes' do |
| 170 |
is_expected.to contain_file('/etc/nova/provider_config/provider.yaml').with_content( <<EOS |
| 171 |
meta: |
| 172 |
schema_version: '1.0' |
| 173 |
providers: |
| 174 |
# for details check https://docs.openstack.org/nova/latest/admin/managing-resource-providers.html |
| 175 |
- identification: |
| 176 |
name: 'EXAMPLE_RESOURCE_PROVIDER' |
| 177 |
inventories: |
| 178 |
additional: |
| 179 |
- CUSTOM_EXAMPLE_RESOURCE_CLASS_1: |
| 180 |
allocation_ratio: 1.0 |
| 181 |
max_unit: 10 |
| 182 |
min_unit: 1 |
| 183 |
reserved: 0 |
| 184 |
step_size: 1 |
| 185 |
total: 100 |
| 186 |
- CUSTOM_EXAMPLE_RESOURCE_CLASS_2: |
| 187 |
total: 100 |
| 188 |
traits: |
| 189 |
additional: |
| 190 |
- 'CUSTOM_P_STATE_ENABLED' |
| 191 |
- 'CUSTOM_C_STATE_ENABLED' |
| 192 |
EOS |
| 193 |
) |
| 194 |
end |
| 195 |
end |
| 196 |
|
| 197 |
context 'when providing custom inventory with multiple providers' do |
| 198 |
before :each do |
| 199 |
params.merge!( |
| 200 |
:custom_inventories => [ |
| 201 |
{ |
| 202 |
'inventories' => { |
| 203 |
'CUSTOM_EXAMPLE_RESOURCE_CLASS_1' => { |
| 204 |
'total' => '100', |
| 205 |
'reserved' => '0', |
| 206 |
'min_unit' => '1', |
| 207 |
'max_unit' => '10', |
| 208 |
'step_size' => '1', |
| 209 |
'allocation_ratio' => '1.0' |
| 210 |
}, |
| 211 |
'CUSTOM_EXAMPLE_RESOURCE_CLASS_2' => { |
| 212 |
'total' => '100', |
| 213 |
}, |
| 214 |
}, |
| 215 |
'traits' => [ |
| 216 |
'CUSTOM_P_STATE_ENABLED', |
| 217 |
'CUSTOM_C_STATE_ENABLED', |
| 218 |
], |
| 219 |
}, |
| 220 |
{ |
| 221 |
'name' => 'EXAMPLE_RESOURCE_PROVIDER', |
| 222 |
'inventories' => { |
| 223 |
'CUSTOM_EXAMPLE_RESOURCE_CLASS' => { |
| 224 |
'total' => '10000', |
| 225 |
'reserved' => '100', |
| 226 |
}, |
| 227 |
}, |
| 228 |
}, |
| 229 |
] |
| 230 |
) |
| 231 |
end |
| 232 |
|
| 233 |
it 'configure provider.yaml on compute nodes' do |
| 234 |
is_expected.to contain_file('/etc/nova/provider_config/provider.yaml').with_content( <<EOS |
| 235 |
meta: |
| 236 |
schema_version: '1.0' |
| 237 |
providers: |
| 238 |
# for details check https://docs.openstack.org/nova/latest/admin/managing-resource-providers.html |
| 239 |
- identification: |
| 240 |
uuid: '$COMPUTE_NODE' |
| 241 |
inventories: |
| 242 |
additional: |
| 243 |
- CUSTOM_EXAMPLE_RESOURCE_CLASS_1: |
| 244 |
allocation_ratio: 1.0 |
| 245 |
max_unit: 10 |
| 246 |
min_unit: 1 |
| 247 |
reserved: 0 |
| 248 |
step_size: 1 |
| 249 |
total: 100 |
| 250 |
- CUSTOM_EXAMPLE_RESOURCE_CLASS_2: |
| 251 |
total: 100 |
| 252 |
traits: |
| 253 |
additional: |
| 254 |
- 'CUSTOM_P_STATE_ENABLED' |
| 255 |
- 'CUSTOM_C_STATE_ENABLED' |
| 256 |
- identification: |
| 257 |
name: 'EXAMPLE_RESOURCE_PROVIDER' |
| 258 |
inventories: |
| 259 |
additional: |
| 260 |
- CUSTOM_EXAMPLE_RESOURCE_CLASS: |
| 261 |
reserved: 100 |
| 262 |
total: 10000 |
| 263 |
EOS |
| 264 |
) |
| 265 |
end |
| 266 |
end |
| 267 |
end |
| 268 |
|
| 269 |
on_supported_os({ |
| 270 |
:supported_os => OSDefaults.get_supported_os |
| 271 |
}).each do |os,facts| |
| 272 |
context "on #{os}" do |
| 273 |
let (:facts) do |
| 274 |
facts.merge!(OSDefaults.get_facts()) |
| 275 |
end |
| 276 |
|
| 277 |
it_configures 'nova custom resource providers' |
| 278 |
end |
| 279 |
end |
| 280 |
end |