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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
|
require "test_helper"
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
describe "Fog::OpenStack::Compute | server requests" do
def self.compute
class_variable_get(:@@compute)
end
class_variable_set(:@@compute, Fog::OpenStack::Compute.new)
def compute
self.class.compute
end
describe "success" do
before do
@create_format = {
'adminPass' => String,
'id' => String,
'links' => Array,
'security_groups' => Fog::Nullable::Array,
}
@base_server_format = {
'id' => String,
'addresses' => Hash,
'flavor' => Hash,
'hostId' => String,
'metadata' => Hash,
'name' => String,
'progress' => Integer,
'status' => String,
'accessIPv4' => Fog::Nullable::String,
'accessIPv6' => Fog::Nullable::String,
'links' => Array,
'created' => String,
'updated' => String,
'user_id' => String,
'config_drive' => String,
}
@reservation_format = {'reservation_id' => String}
@server_from_image_format = @base_server_format.merge('image' => Hash)
@image_format = {
'created' => Fog::Nullable::String,
'id' => String,
'name' => String,
'progress' => Fog::Nullable::Integer,
'status' => String,
'updated' => String,
'minRam' => Integer,
'minDisk' => Integer,
'server' => Hash,
'metadata' => Hash,
'links' => Array
}
@image_id = get_image_ref
@snapshot_id = nil
@flavor_id = get_flavor_ref
@security_group_name = get_security_group_ref
@volume1_id = compute.create_volume('test', 'this is a test volume', 1).body["volume"]["id"]
volume_data = {
:delete_on_termination => true,
:device_name => "vda",
:volume_id => @volume1_id,
:volume_size => 1
}
@data = compute.create_server("test", nil, @flavor_id, "block_device_mapping" => volume_data).body['server']
@server_id = @data['id']
end
it "#create_server('test', nil, #{@flavor_id}) with a block_device_mapping" do
@data.must_match_schema(@create_format,
nil,
:allow_extra_keys => true,
:allow_optional_rules => true)
end
it "#get_server_details(#{@server_id})" do
compute.get_server_details(@server_id).body['server'].
must_match_schema(@base_server_format,
nil,
:allow_extra_keys => true,
:allow_optional_rules => true)
end
it "#block_device_mapping" do
compute.servers.get(@server_id).volumes.first.id.must_equal @volume1_id
end
describe "with multiple block_device_mapping_v2" do
before do
@volume2_id = compute.create_volume('test', 'this is a test volume', 1).body["volume"]["id"]
volume_data = [
{
:boot_index => 0,
:uuid => @volume1_id,
:device_name => "vda",
:source_type => "volume",
:destination_type => "volume",
:delete_on_termination => true,
:volume_size => 20
},
{
:boot_index => 1,
:uuid => @volume2_id,
:device_name => "vdb",
:source_type => "volume",
:destination_type => "volume",
:delete_on_termination => true,
:volume_size => 10
}
]
data = compute.create_server("test",
nil,
@flavor_id,
"block_device_mapping_v2" => volume_data
).body['server']
@server_id = data['id']
end
it "#create_server('test', nil, #{@flavor_id})" do
@data.must_match_schema(@create_format,
nil,
:allow_extra_keys => true,
:allow_optional_rules => true)
end
it "#get_server_details(#{@server_id})" do
compute.get_server_details(@server_id).body['server'].
must_match_schema(@base_server_format,
nil,
:allow_extra_keys => true,
:allow_optional_rules => true)
end
it "#block_device_mapping_v2" do
# Breaks sometimes: "Expected: ["56", "56"] <=> Actual: ["56"]"
skip unless Minitest::Test::UNIT_TESTS_CLEAN
compute.servers.get(@server_id).volumes.collect(&:id).sort.
must_equal [@volume1_id, @volume2_id].sort
end
end
describe "single server from image" do
before do
@data = compute.create_server("test", @image_id, @flavor_id).body['server']
@server_id = @data['id']
compute.servers.get(@server_id).wait_for { ready? } unless Fog.mocking?
# Fog::OpenStack::Compute.new.servers.get(@server_id).wait_for { ready? }
end
it "#create_server('test', #{@image_id}, 19)" do
@data.must_match_schema(@create_format,
nil,
:allow_extra_keys => true,
:allow_optional_rules => true)
end
it "#get_server_details(#{@server_id})" do
compute.get_server_details(@server_id).body['server'].
must_match_schema(@server_from_image_format,
nil,
:allow_extra_keys => true,
:allow_optional_rules => true)
end
end
describe "Multiple create from image" do
before do
@data = compute.create_server("test", @image_id, @flavor_id,
"min_count" => 2, "return_reservation_id" => "True").body
@reservation_id = @data['reservation_id']
@multi_create_servers = []
if Fog.mocking?
@multi_create_servers = [Fog::Mock.random_numbers(6).to_s, Fog::Mock.random_numbers(6).to_s]
else
@multi_create_servers = compute.list_servers_detail(
'reservation_id' => @reservation_id
).body['servers'].collect { |server| server['id'] }
end
end
it "#create_server('test', @image_id , 19, {'min_count' => 2, 'return_reservation_id' => 'True'})" do
@data.must_match_schema(@reservation_format,
nil,
:allow_extra_keys => true,
:allow_optional_rules => true)
end
it "#validate_multi_create" do
@multi_create_servers.size.must_equal 2
end
end
# LIST
it "#list_servers" do
compute.list_servers.body.
must_match_schema({'servers' => [OpenStack::Compute::Formats::SUMMARY]},
nil,
:allow_extra_keys => true,
:allow_optional_rules => true)
end
# DETAILS
it "#list_servers_detail" do
compute.list_servers_detail.body["servers"][0].
must_match_schema(@server_from_image_format,
nil,
:allow_extra_keys => true,
:allow_optional_rules => true)
end
# CHANGE PASSWORD
it "#change_server_password(#{@server_id}, 'fogupdatedserver')" do
if set_password_enabled
compute.change_server_password(@server_id, 'foggy').status.must_equal 202
compute.servers.get(@server_id).wait_for { ready? } unless Fog.mocking?
end
end
# UPDATE SERVER NAME
it "#update_server(#{@server_id}, :name => 'fogupdatedserver')" do
compute.update_server(@server_id, :name => 'fogupdatedserver').status.must_equal 200
compute.servers.get(@server_id).wait_for { ready? } unless Fog.mocking?
end
# ADD SECURITY GROUP
it "#add_security_group(#{@server_id}, #{@security_group_name})" do
compute.add_security_group(@server_id, @security_group_name).status.must_equal 200
end
# REMOVE SECURITY GROUP
it "#remove_security_group(#{@server_id}, #{@security_group_name})" do
compute.remove_security_group(@server_id, @security_group_name).status.must_equal 200
end
describe "Create image with metadata" do
before do
@data = compute.create_image(@server_id, 'fog', "foo" => "bar").body
@snapshot_id = @data['image']['id']
# compute.images.get(@snapshot_id).wait_for { ready? }
end
it "#create_image(#{@server_id}, 'fog')" do
@data.must_match_schema('image' => @image_format)
end
it "#rebuild_server(#{@server_id}, #{@snapshot_id}, 'fog')" do
compute.rebuild_server(
@server_id, @snapshot_id, 'fog', 'newpass', "foo" => "bar"
).body.must_match_schema({'server' => @server_from_image_format},
nil,
:allow_extra_keys => true,
:allow_optional_rules => true)
compute.servers.get(@server_id).wait_for { ready? } unless Fog.mocking?
end
# RESIZE
it "#resize_server(#{@server_id}, #{get_flavor_ref_resize})" do
compute.resize_server(@server_id, get_flavor_ref_resize).status.must_equal 202
unless Fog.mocking?
compute.servers.get(@server_id).wait_for { state == 'VERIFY_RESIZE' }
end
end
# RESIZE CONFIRM
it "#resize_confirm(#{@server_id}, #{get_flavor_ref_resize})" do
compute.confirm_resize_server(@server_id).status.must_equal 204
unless Fog.mocking?
compute.servers.get(@server_id).wait_for { ready? }
end
end
# REBOOT - HARD
it "#reboot_server(#{@server_id}, 'HARD')" do
compute.reboot_server(@server_id, 'HARD').status.must_equal 202
unless Fog.mocking?
compute.servers.get(@server_id).wait_for { ready? }
end
end
# REBOOT - SOFT
it "#reboot_server(#{@server_id}, 'SOFT')" do
compute.reboot_server(@server_id, 'SOFT').status.must_equal 202
unless Fog.mocking?
compute.servers.get(@server_id).wait_for { ready? }
end
end
# STOP
it "#stop_server(#{@server_id})" do
compute.stop_server(@server_id).must_equal true
end
# START
it "#start_server(#{@server_id})" do
compute.start_server(@server_id).must_equal true
unless Fog.mocking?
compute.servers.get(@server_id).wait_for { ready? }
end
end
it "#shelve_server(#{@server_id}" do
compute.shelve_server(@server_id).must_equal true
unless Fog.mocking?
compute.servers.get(@server_id).wait_for { ready? }
end
end
it "#unshelve_server(#{@server_id})" do
compute.unshelve_server(@server_id).must_equal true
unless Fog.mocking?
compute.servers.get(@server_id).wait_for { ready? }
end
end
# DELETE
it "#servers.delete(#{@server_id})" do
compute.servers.delete(@server_id)
end
# DELETE IMAGE
it "#delete_image(#{@snapshot_id})" do
Fog::OpenStack::Compute.new.servers.get(@server_id).wait_for { ready? }
assert(compute.delete_image(@snapshot_id))
end
end
end
describe "failure" do
it "#delete_server(0)" do
proc do
self.class.compute.delete_server(0)
end.must_raise Fog::OpenStack::Compute::NotFound
end
it "#get_server_details(0)" do
proc do
self.class.compute.get_server_details(0)
end.must_raise Fog::OpenStack::Compute::NotFound
end
it "#update_server(0, :name => 'fogupdatedserver', :adminPass => 'fogupdatedserver')" do
proc do
self.class.compute.update_server(0, :name => 'fogupdatedserver', :adminPass => 'fogupdatedserver')
end.must_raise Fog::OpenStack::Compute::NotFound
end
it "#reboot_server(0)" do
unless Fog.mocking?
proc do
self.class.compute.reboot_server(0)
end.must_raise Fog::OpenStack::Compute::NotFound
end
end
it "#start_server(0)" do
unless Fog.mocking?
proc do
self.class.compute.start_server(0)
end.must_raise Fog::OpenStack::Compute::NotFound
end
end
it "#stop_server(0)" do
unless Fog.mocking?
proc do
self.class.compute.stop_server(0)
end.must_raise Fog::OpenStack::Compute::NotFound
end
end
end
end
|