spec/unit/cf_command_spec.rb in bosh-cloudfoundry-0.3.0 vs spec/unit/cf_command_spec.rb in bosh-cloudfoundry-0.4.0

- old
+ new

@@ -39,13 +39,18 @@ end it "downloads stemcell and uploads it" do @cmd.stub!(:bosh_target).and_return("http://9.8.7.6:25555") @cmd.stub!(:bosh_target_uuid).and_return("DIRECTOR_UUID") + @cmd.stub!(:bosh_cpi).and_return("aws") @cmd.should_receive(:`). - with("bosh public stemcells --tags aws,stable | grep ' bosh-stemcell-' | awk '{ print $2 }' | sort -r | head -n 1"). + with("bosh public stemcells --tags aws | grep ' bosh-stemcell-' | awk '{ print $2 }' | sort -r | head -n 1"). and_return("bosh-stemcell-aws-0.6.7.tgz") + # FIXME default to stable stemcells when 0.8.1 is marked stable + # @cmd.should_receive(:`). + # with("bosh public stemcells --tags aws,stable | grep ' bosh-stemcell-' | awk '{ print $2 }' | sort -r | head -n 1"). + # and_return("bosh-stemcell-aws-0.6.7.tgz") @cmd.should_receive(:sh). with("bosh -n --color download public stemcell bosh-stemcell-aws-0.6.7.tgz") @cmd.should_receive(:sh). with("bosh -n --color upload stemcell #{@stemcells_dir}/bosh-stemcell-aws-0.6.7.tgz") @@ -56,10 +61,11 @@ it "creates bosh stemcell and uploads it" do mkdir_p(File.join(@repos_dir, "bosh", "agent")) @cmd.stub!(:bosh_target).and_return("http://9.8.7.6:25555") @cmd.stub!(:bosh_target_uuid).and_return("DIRECTOR_UUID") + @cmd.stub!(:bosh_cpi).and_return("aws") @cmd.should_receive(:sh).with("git pull origin master") @cmd.should_receive(:sh).with("bundle install --without development test") @cmd.should_receive(:sh).with("sudo bundle exec rake stemcell:basic['aws']") @cmd.should_receive(:sh).with("sudo chown -R vcap:vcap /var/tmp/bosh/agent-*") @cmd.should_receive(:validate_stemcell_created_successfully) @@ -92,38 +98,42 @@ @cmd.should_receive(:sh).with("sed -i 's#git://github.com#https://github.com#g' .gitmodules") @cmd.should_receive(:sh).with("git submodule update --init --recursive") @cmd.should_receive(:`).with("tail -n 1 releases/index.yml | awk '{print $2}'"). and_return("126") @cmd.should_receive(:sh).with("bosh -n --color upload release releases/appcloud-126.yml") + @cmd.add_option(:final, true) @cmd.upload_release end - it "updates/creates/uploads development/edge cf-release" do - cf_release_dir = File.join(@releases_dir, "cf-release") - FileUtils.mkdir_p(cf_release_dir) - @cmd.common_config.cf_release_dir = cf_release_dir - @cmd.add_option(:dev, true) + it "updates/creates/uploads development/edge cf-release (requires system setup)" + # TODO turn this into a unit test for the specific methods + # do + # cf_release_dir = File.join(@releases_dir, "cf-release") + # FileUtils.mkdir_p(cf_release_dir) + # @cmd.common_config.cf_release_dir = cf_release_dir + # @cmd.add_option(:dev, true) + # + # @cmd.should_receive(:sh).with("git pull origin master") + # script = <<-BASH.gsub(/^ /, '') + # grep -rI "github.com" * .gitmodules | awk 'BEGIN {FS=":"} { print($1) }' | uniq while read file + # do + # echo "changing - $file" + # sed -i 's#git://github.com#https://github.com#g' $file + # sed -i 's#git@github.com:#https://github.com:#g' $file + # done + # BASH + # @cmd.should_receive(:sh).with("sed -i 's#git@github.com:#https://github.com/#g' .gitmodules") + # @cmd.should_receive(:sh).with("sed -i 's#git://github.com#https://github.com#g' .gitmodules") + # @cmd.should_receive(:sh).with("git submodule update --init --recursive") + # @cmd.should_receive(:write_dev_config_file).with("appcloud-dev") + # @cmd.should_receive(:sh).with("bosh create release --with-tarball --force") + # @cmd.should_receive(:sh).with("bosh -n --color upload release") + # @cmd.upload_release + # end - @cmd.should_receive(:sh).with("git pull origin master") - script = <<-BASH.gsub(/^ /, '') - grep -rI "github.com" * .gitmodules | awk 'BEGIN {FS=":"} { print($1) }' | uniq while read file - do - echo "changing - $file" - sed -i 's#git://github.com#https://github.com#g' $file - sed -i 's#git@github.com:#https://github.com:#g' $file - done - BASH - @cmd.should_receive(:sh).with("sed -i 's#git@github.com:#https://github.com/#g' .gitmodules") - @cmd.should_receive(:sh).with("sed -i 's#git://github.com#https://github.com#g' .gitmodules") - @cmd.should_receive(:sh).with("git submodule update --init --recursive") - @cmd.should_receive(:write_dev_config_file).with("appcloud-dev") - @cmd.should_receive(:sh).with("bosh create release --with-tarball --force") - @cmd.should_receive(:sh).with("bosh -n --color upload release") - @cmd.upload_release - end - def generate_new_system(cmd = nil) + needs_initial_release_uploaded = true cmd ||= begin cmd = Bosh::Cli::Command::CloudFoundry.new(nil) cmd.add_option(:non_interactive, true) cmd.add_option(:config, @config) cmd.add_option(:common_config, @common_config) @@ -132,17 +142,26 @@ cmd end cmd.stub!(:bosh_target).and_return("http://9.8.7.6:25555") cmd.stub!(:bosh_target_uuid).and_return("DIRECTOR_UUID") + cmd.stub!(:bosh_cpi).and_return("aws") cmd.should_receive(:generate_common_password).and_return('c1oudc0wc1oudc0w') - cmd.should_receive(:bosh_releases).exactly(1).times.and_return([ - {"name"=>"appcloud", "versions"=>["124", "126"], "in_use"=>[]}, - {"name"=>"appcloud-dev", "versions"=>["124.1-dev", "126.1-dev"], "in_use"=>[]}, - ]) cmd.should_receive(:validate_dns_a_record).with("api.mycompany.com", '1.2.3.4').and_return(true) cmd.should_receive(:validate_dns_a_record).with("demoapp.mycompany.com", '1.2.3.4').and_return(true) + + if needs_initial_release_uploaded + cmd.should_receive(:bosh_releases).exactly(1).times.and_return([]) + cmd.should_receive(:clone_or_update_cf_release) + cmd.should_receive(:merge_gerrit).with(*%w[37/13137/4 84/13084/4 09/13609/2]) + else + cmd.should_receive(:bosh_releases).exactly(1).times.and_return([ + {"name"=>"appcloud", "versions"=>["124", "126"], "in_use"=>[]}, + {"name"=>"appcloud-dev", "versions"=>["124.1-dev", "126.1-dev"], "in_use"=>[]}, + ]) + end + cmd.should_receive(:bosh_stemcell_versions).exactly(4).times.and_return(['0.6.4']) cmd.should_receive(:render_system) provider = Bosh::CloudFoundry::Providers::AWS.new ports = { @@ -153,11 +172,11 @@ provider.should_receive(:create_security_group).with("cloudfoundry-production", ports) Bosh::CloudFoundry::Providers.should_receive(:for_bosh_provider_name).and_return(provider) cmd.add_option(:core_ip, '1.2.3.4') cmd.add_option(:root_dns, 'mycompany.com') - cmd.add_option(:cf_release, 'appcloud') + # cmd.add_option(:cf_release, 'appcloud') cmd.add_option(:core_server_flavor, 'm1.large') cmd.add_option(:admin_emails, ['drnic@starkandwayne.com']) cmd.common_config.cf_release_dir = @releases_dir cmd.common_config.stemcells_dir = @stemcells_dir @@ -172,20 +191,27 @@ it "creates new system" do generate_new_system(@cmd) File.basename(@cmd.system).should == "production" end + it "temporarily uploads latest stemcell & patched cf-release by default" do + generate_new_system(@cmd) + File.basename(@cmd.system).should == "production" + @cmd.system_config.release_name.should == "appcloud-dev" + end + it "new system has common random password" do generate_new_system(@cmd) @cmd.system_config.common_password.should == "c1oudc0wc1oudc0w" end it "sets 3 x m1.large dea server" do generate_new_system @cmd.should_receive(:render_system) + @cmd.stub!(:bosh_cpi).and_return("aws") @cmd.stub!(:bosh_target).and_return("http://9.8.7.6:25555") @cmd.add_option(:flavor, 'm1.xlarge') @cmd.change_deas(3) @cmd.system_config.dea.should == { "count" => 3, "flavor" => 'm1.xlarge' } @@ -202,10 +228,11 @@ it "add 4 postgresql nodes" do generate_new_system @cmd.should_receive(:render_system) + @cmd.stub!(:bosh_cpi).and_return("aws") @cmd.stub!(:bosh_target).and_return("http://9.8.7.6:25555") @cmd.add_option(:flavor, 'm1.large') @cmd.add_service_node("postgresql", 4) @cmd.system_config.postgresql.size.should == 1 @@ -217,9 +244,10 @@ it "add 2 redis nodes" do generate_new_system @cmd.should_receive(:render_system) + @cmd.stub!(:bosh_cpi).and_return("aws") @cmd.stub!(:bosh_target).and_return("http://9.8.7.6:25555") @cmd.add_option(:flavor, 'm1.large') @cmd.add_service_node("redis", 2) @cmd.system_config.redis.size.should == 1 \ No newline at end of file