Top Level Namespace
Defined Under Namespace
Modules: Miasma
Constant Summary collapse
- MIASMA_COMPUTE_ABSTRACT =
->{ # Required `let`s: # * compute: compute API # * build_args: server build arguments [Smash] describe Miasma::Models::Compute, :vcr do it 'should provide #servers collection' do compute.servers.must_be_kind_of Miasma::Models::Compute::Servers end describe Miasma::Models::Compute::Servers do it 'should provide instance class used within collection' do compute.servers.model.must_equal Miasma::Models::Compute::Server end it 'should build new instance for collection' do instance = compute.servers.build(:name => 'test') instance.must_be_kind_of Miasma::Models::Compute::Server end it 'should provide #all servers' do compute.servers.all.must_be_kind_of Array end end describe Miasma::Models::Compute::Server do before do unless($miasma_instance) VCR.use_cassette('Miasma_Models_Compute_Global/GLOBAL_compute_instance_create') do @instance = compute.servers.build(build_args) @instance.save until(@instance.state == :running) miasma_spec_sleep @instance.reload end $miasma_instance = @instance end Kernel.at_exit do VCR.use_cassette('Miasma_Models_Compute_Global/GLOBAL_compute_instance_destroy') do $miasma_instance.destroy end end else @instance = $miasma_instance end @instance.reload end let(:instance){ @instance } describe 'instance methods' do it 'should have a name' do instance.name.must_equal build_args[:name] end it 'should have an image_id' do instance.image_id.must_equal build_args[:image_id] end it 'should have a flavor_id' do instance.flavor_id.must_equal build_args[:flavor_id] end it 'should have an address' do instance.addresses.detect do |addr| addr.version == 4 end.address.must_match /^(\d+)+\.(\d+)\.(\d+)\.(\d+)$/ end it 'should have a status' do instance.status.wont_be_nil end it 'should be in :running state' do instance.state.must_equal :running end end end describe 'instance lifecycle' do it 'should create new server, reload details and destroy server' do instance = compute.servers.build(build_args) instance.save instance.id.wont_be_nil instance.state.must_equal :pending compute.servers.reload.get(instance.id).wont_be_nil until(instance.state == :running) miasma_spec_sleep instance.reload end instance.state.must_equal :running instance.destroy while(instance.state == :running) miasma_spec_sleep instance.reload end [:pending, :terminated].must_include instance.state if(instance.state == :pending) until(instance.state == :terminated) miasma_spec_sleep instance.reload end instance.state.must_equal :terminated end end end end }
- MIASMA_STORAGE_ABSTRACT =
->{ # Required `let`s: # * storage: storage API describe Miasma::Models::Storage, :vcr do it 'should provide #buckets collection' do storage.buckets.must_be_kind_of Miasma::Models::Storage::Buckets end describe Miasma::Models::Storage::Buckets do it 'should provide instance class used within collection' do storage.buckets.model.must_equal Miasma::Models::Storage::Bucket end it 'should build new instance for collection' do storage.buckets.build.must_be_kind_of Miasma::Models::Storage::Bucket end it 'should provide #all buckets' do storage.buckets.all.must_be_kind_of Array end end describe Miasma::Models::Storage::Bucket do it 'should act like a bucket' do bucket = storage.buckets.build(:name => 'miasma-test-bucket-010') bucket.save bucket.reload # should include the bucket storage.buckets.reload.get('miasma-test-bucket-010').wont_be_nil # should have a name bucket.name.must_equal 'miasma-test-bucket-010' # should have a #files collection bucket.files.must_be_kind_of Miasma::Models::Storage::Files #should provide #all files bucket.files.all.must_be_kind_of Array # should include reference to containing bucket bucket.files.bucket.must_equal bucket # should build new instance for collection bucket.files.build.must_be_kind_of Miasma::Models::Storage::File file_content = 'blahblahblah' file = bucket.files.build file.name = 'miasma-test-file' file.body = file_content file.save file.reload # should have a name file.name.must_equal 'miasma-test-file' # should have a size file.size.must_equal file_content.size # should have an updated timestamp file.updated.must_be_kind_of Time # should create a valid url open(file.url).read.must_equal file_content # should have a body file.body.must_respond_to :readpartial file.body.readpartial(Miasma::Models::Storage::READ_BODY_CHUNK_SIZE).must_equal file_content file.destroy big_file_content = '*' * Miasma::Models::Storage::MAX_BODY_SIZE_FOR_STRINGIFY big_file = bucket.files.build big_file.name = 'miasma-test-file-big' big_file.body = big_file_content big_file.save big_file.reload # should be the correct size big_file.size.must_equal big_file.size # should provide streaming body big_file.body.must_respond_to :readpartial content = big_file.body.readpartial(big_file.size) content.must_equal big_file_content big_file.destroy require 'tempfile' local_io_file = Tempfile.new('miasma-storage-test') big_io_content = '*' * (Miasma::Models::Storage::MAX_BODY_SIZE_FOR_STRINGIFY * 1.3) local_io_file.write big_io_content local_io_file.flush local_io_file.rewind remote_file = bucket.files.build remote_file.name = 'miasma-test-io-object-010' remote_file.body = local_io_file remote_file.save remote_file.reload # should be the correct size remote_file.size.must_equal local_io_file.size # should provide streaming body remote_file.body.must_respond_to :readpartial content = '' while(chunk = remote_file.body.readpartial(1024)) content << chunk end content.must_equal big_io_content remote_file.destroy bucket.destroy end end end }
- MIASMA_LOAD_BALANCER_ABSTRACT =
->{ # Required `let`s: # * load_balancer: load balancer API # * build_args: load balancer build arguments [Smash] describe Miasma::Models::LoadBalancer, :vcr do it 'should provide #balancers collection' do load_balancer.balancers.must_be_kind_of Miasma::Models::LoadBalancer::Balancers end describe Miasma::Models::LoadBalancer::Balancers do it 'should provide instance class used within collection' do load_balancer.balancers.model.must_equal Miasma::Models::LoadBalancer::Balancer end it 'should build new instance for collection' do instance = load_balancer.balancers.build instance.must_be_kind_of Miasma::Models::LoadBalancer::Balancer end it 'should provide #all balancers' do load_balancer.balancers.all.must_be_kind_of Array end end describe Miasma::Models::LoadBalancer::Balancer do before do unless($miasma_balancer) VCR.use_cassette('Miasma_Models_LoadBalancer_Global/GLOBAL_load_balancer_create') do @balancer = load_balancer.balancers.build(build_args) @balancer.save until(@balancer.state == :active) miasma_spec_sleep @balancer.reload end $miasma_balancer = @balancer end Kernel.at_exit do VCR.use_cassette('Miasma_Models_LoadBalancer_Global/GLOBAL_load_balancer_destroy') do $miasma_balancer.destroy end end else @balancer = $miasma_balancer end @balancer.reload end let(:balancer){ @balancer } describe 'collection' do it 'should include balancer' do load_balancer.balancers.reload.get(balancer.id).wont_be_nil end end describe 'balancer methods' do it 'should have a name' do balancer.name.must_equal build_args[:name] end it 'should be in :active state' do balancer.state.must_equal :active end it 'should have a status' do balancer.status.wont_be_nil balancer.status.must_be_kind_of String end it 'should have a public address' do balancer.public_addresses.wont_be :empty? end end end end }
- MIASMA_ORCHESTRATION_ABSTRACT =
->{ # Required `let`s: # * orchestration: orchestration API # * build_args: stack build arguments [Smash] describe Miasma::Models::Orchestration, :vcr do it 'should provide #stacks collection' do orchestration.stacks.must_be_kind_of Miasma::Models::Orchestration::Stacks end describe Miasma::Models::Orchestration::Stacks do it 'should provide instance class used within collection' do orchestration.stacks.model.must_equal Miasma::Models::Orchestration::Stack end it 'should build new instance for collection' do instance = orchestration.stacks.build instance.must_be_kind_of Miasma::Models::Orchestration::Stack end it 'should provide #all stacks' do orchestration.stacks.all.must_be_kind_of Array end end describe Miasma::Models::Orchestration::Stacks do before do unless($miasma_stack) VCR.use_cassette('Miasma_Models_Orchestration_Global/GLOBAL_orchestration_stack_create') do @stack = orchestration.stacks.build(build_args) @stack.save Timeout.timeout(500) do until(@stack.state == :create_complete) miasma_spec_sleep @stack.reload end end @stack.template orchestration.stacks.reload $miasma_stack = @stack end Kernel.at_exit do VCR.use_cassette('Miasma_Models_Compute_Global/GLOBAL_orchestration_stack_destroy') do $miasma_stack.destroy end end else @stack = $miasma_stack end @stack.reload end let(:stack){ @stack } describe 'collection' do it 'should include stack' do orchestration.stacks.all.detect{|s| s.id == stack.id}.wont_be_nil orchestration.stacks.get(stack.id).wont_be_nil end end describe 'instance methods' do it 'should have a name' do stack.name.must_equal build_args[:name] end it 'should be in :create_complete state' do stack.state.must_equal :create_complete end it 'should have a status' do stack.status.must_be_kind_of String end it 'should have a creation time' do stack.created.must_be_kind_of Time end it 'should have parameters used for creation' do stack.parameters.to_smash.must_equal build_args[:parameters].to_smash end it 'should include the templated used for creation' do stack.template.to_smash.must_equal build_args[:template].to_smash end end end describe 'instance lifecycle' do it 'should create new stack, reload details and destroy stack' do stack = orchestration.stacks.build(build_args.merge(:name => 'miasma-test-stack-2')) stack.save stack.id.wont_be_nil stack.state.must_equal :create_in_progress orchestration.stacks.reload.get(stack.id).wont_be_nil until(stack.state == :create_complete) miasma_spec_sleep stack.reload end stack.state.must_equal :create_complete stack.destroy [:delete_in_progress, :delete_complete].must_include stack.state Timeout.timeout(500) do until(stack.state == :delete_complete) miasma_spec_sleep stack.reload end end stack.state.must_equal :delete_complete end end end }
Instance Method Summary collapse
Instance Method Details
#miasma_spec_sleep(interval = 20) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/miasma/specs.rb', line 6 def miasma_spec_sleep(interval=20) if(ENV['MIASMA_TEST_LIVE_REQUESTS']) sleep(20) else sleep(0.1) end end |