<commit_before>require_relative '../../spec_helper'

describe 'deleting deployment', type: :integration do
  with_reset_sandbox_before_each

  it 'should clean environment properly and free up resources' do
    expect(current_sandbox.cpi.all_stemcells).to eq []
    expect(current_sandbox.cpi.vm_cids.count).to eq 0
    expect(current_sandbox.cpi.disk_cids.count).to eq 0
    expect(current_sandbox.cpi.all_ips.count).to eq 0
    expect(current_sandbox.cpi.all_snapshots.count).to eq 0

    expect(bosh_runner.run('deployments', failure_expected: true)).to match /0 deployments/

    manifest_hash = Bosh::Spec::NewDeployments.simple_manifest_with_instance_groups
    manifest_hash['instance_groups'].first['instances'] = 1

    cloud_config_hash = Bosh::Spec::NewDeployments.simple_cloud_config
    cloud_config_hash['disk_types'] = [{'name' => 'disk_a', 'disk_size' => 123}]
    manifest_hash['instance_groups'].first['persistent_disk_type'] = 'disk_a'

    deploy_from_scratch(manifest_hash: manifest_hash, cloud_config_hash: cloud_config_hash)
    expect(bosh_runner.run('take-snapshot foobar/0', deployment_name: 'simple')).to include('Succeeded')

    expect(bosh_runner.run('deployments')).to include('1 deployments')
    expect(bosh_runner.run('vms', deployment_name: 'simple')).to include('1 vms')
    expect(bosh_runner.run('instances', deployment_name: 'simple')).to include('1 instances')
    expect(bosh_runner.run('releases', deployment_name: 'simple')).to include('1 releases')

    expect(current_sandbox.cpi.all_stemcells.count).to eq 1
    expect(current_sandbox.cpi.vm_cids.count).to eq 1
    expect(current_sandbox.cpi.disk_cids.count).to eq 1
    expect(current_sandbox.cpi.all_ips.count).to eq 1
    expect(current_sandbox.cpi.all_snapshots.count).to eq 1

    # Delete Deployment
    deployment_deletion_output = bosh_runner.run('delete-deployment', deployment_name: 'simple', json: true)
    expect(deployment_deletion_output).to match /Deleting instances: foobar/
    expect(deployment_deletion_output).to include('Succeeded')

    # Stemcells and releases remain after deletion of deployment
    expect(current_sandbox.cpi.all_stemcells.count).to eq 1
    expect(bosh_runner.run('releases')).to include('1 releases')

    expect(current_sandbox.cpi.vm_cids.count).to eq 0
    expect(current_sandbox.cpi.disk_cids.count).to eq 1
    expect(current_sandbox.cpi.all_ips.count).to eq 0
    expect(current_sandbox.cpi.all_snapshots.count).to eq 1

    #deployments
    expect(bosh_runner.run('deployments', failure_expected: true)).to match /0 deployments/
  end

  it 'should clean environment properly and free up resources even after a failed deployment' do
    current_sandbox.cpi.commands.make_create_vm_always_fail

    expect(current_sandbox.cpi.all_stemcells).to eq []
    expect(current_sandbox.cpi.vm_cids.count).to eq 0
    expect(current_sandbox.cpi.disk_cids.count).to eq 0
    expect(current_sandbox.cpi.all_ips.count).to eq 0
    expect(current_sandbox.cpi.all_snapshots.count).to eq 0

    expect(bosh_runner.run('deployments', failure_expected: true)).to match /0 deployments/

    manifest_hash = Bosh::Spec::NewDeployments.simple_manifest_with_instance_groups
    manifest_hash['instance_groups'].first['instances'] = 1

    cloud_config_hash = Bosh::Spec::NewDeployments.simple_cloud_config
    cloud_config_hash['disk_types'] = [{'name' => 'disk_a', 'disk_size' => 123}]
    manifest_hash['instance_groups'].first['persistent_disk_type'] = 'disk_a'

    deploy_from_scratch(manifest_hash: manifest_hash, cloud_config_hash: cloud_config_hash, failure_expected: true)

    expect(bosh_runner.run('deployments')).to include('1 deployments')
    expect(bosh_runner.run('vms', deployment_name: 'simple')).to include('0 vms')
    output = scrub_random_ids(table(bosh_runner.run('instances', deployment_name: 'simple', json: true)))
    expect(output).to contain_exactly({'instance' => 'foobar/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'process_state' => '', 'az' => '', 'ips' => '192.168.1.2' })
    expect(bosh_runner.run('releases')).to include('1 releases')

    expect(current_sandbox.cpi.all_stemcells.count).to eq 1
    expect(current_sandbox.cpi.vm_cids.count).to eq 0
    expect(current_sandbox.cpi.disk_cids.count).to eq 0
    expect(current_sandbox.cpi.all_ips.count).to eq 0

    # Delete Deployment
    deployment_deletion_output = bosh_runner.run('delete-deployment', deployment_name: 'simple', json: true)
    expect(deployment_deletion_output).to match /Deleting instances: foobar/
    expect(deployment_deletion_output).to include('Succeeded')
    # puts bosh_runner.run('delete deployment simple', failure_expected: true)

    # Stemcells and releases remain after deletion of deployment
    expect(current_sandbox.cpi.all_stemcells.count).to eq 1
    expect(bosh_runner.run('releases')).to include('1 releases')

    expect(current_sandbox.cpi.vm_cids.count).to eq 0
    expect(current_sandbox.cpi.disk_cids.count).to eq 0
    expect(current_sandbox.cpi.all_ips.count).to eq 0
    expect(current_sandbox.cpi.all_snapshots.count).to eq 0

    #deployments
    expect(bosh_runner.run('deployments', failure_expected: true)).to include('0 deployments')
  end
end
<commit_msg>Fix integration test<commit_after>require_relative '../../spec_helper'

describe 'deleting deployment', type: :integration do
  with_reset_sandbox_before_each

  it 'should clean environment properly and free up resources' do
    expect(current_sandbox.cpi.all_stemcells).to eq []
    expect(current_sandbox.cpi.vm_cids.count).to eq 0
    expect(current_sandbox.cpi.disk_cids.count).to eq 0
    expect(current_sandbox.cpi.all_ips.count).to eq 0
    expect(current_sandbox.cpi.all_snapshots.count).to eq 0

    expect(bosh_runner.run('deployments', failure_expected: true)).to match /0 deployments/

    manifest_hash = Bosh::Spec::NewDeployments.simple_manifest_with_instance_groups
    manifest_hash['instance_groups'].first['instances'] = 1

    cloud_config_hash = Bosh::Spec::NewDeployments.simple_cloud_config
    cloud_config_hash['disk_types'] = [{'name' => 'disk_a', 'disk_size' => 123}]
    manifest_hash['instance_groups'].first['persistent_disk_type'] = 'disk_a'

    deploy_from_scratch(manifest_hash: manifest_hash, cloud_config_hash: cloud_config_hash)
    expect(bosh_runner.run('take-snapshot foobar/0', deployment_name: 'simple')).to include('Succeeded')

    expect(bosh_runner.run('deployments')).to include('1 deployments')
    expect(bosh_runner.run('vms', deployment_name: 'simple')).to include('1 vms')
    expect(bosh_runner.run('instances', deployment_name: 'simple')).to include('1 instances')
    expect(bosh_runner.run('releases', deployment_name: 'simple')).to include('1 releases')

    expect(current_sandbox.cpi.all_stemcells.count).to eq 1
    expect(current_sandbox.cpi.vm_cids.count).to eq 1
    expect(current_sandbox.cpi.disk_cids.count).to eq 1
    expect(current_sandbox.cpi.all_ips.count).to eq 1
    expect(current_sandbox.cpi.all_snapshots.count).to eq 1

    # Delete Deployment
    deployment_deletion_output = bosh_runner.run('delete-deployment', deployment_name: 'simple', json: true)
    expect(deployment_deletion_output).to match /Deleting instances: foobar/
    expect(deployment_deletion_output).to include('Succeeded')

    # Stemcells and releases remain after deletion of deployment
    expect(current_sandbox.cpi.all_stemcells.count).to eq 1
    expect(bosh_runner.run('releases')).to include('1 releases')

    expect(current_sandbox.cpi.vm_cids.count).to eq 0
    expect(current_sandbox.cpi.disk_cids.count).to eq 1
    expect(current_sandbox.cpi.all_ips.count).to eq 0
    expect(current_sandbox.cpi.all_snapshots.count).to eq 1

    #deployments
    expect(bosh_runner.run('deployments', failure_expected: true)).to match /0 deployments/
  end

  it 'should clean environment properly and free up resources even after a failed deployment' do
    current_sandbox.cpi.commands.make_create_vm_always_fail

    expect(current_sandbox.cpi.all_stemcells).to eq []
    expect(current_sandbox.cpi.vm_cids.count).to eq 0
    expect(current_sandbox.cpi.disk_cids.count).to eq 0
    expect(current_sandbox.cpi.all_ips.count).to eq 0
    expect(current_sandbox.cpi.all_snapshots.count).to eq 0

    expect(bosh_runner.run('deployments', failure_expected: true)).to match /0 deployments/

    manifest_hash = Bosh::Spec::NewDeployments.simple_manifest_with_instance_groups
    manifest_hash['instance_groups'].first['instances'] = 1

    cloud_config_hash = Bosh::Spec::NewDeployments.simple_cloud_config
    cloud_config_hash['disk_types'] = [{'name' => 'disk_a', 'disk_size' => 123}]
    manifest_hash['instance_groups'].first['persistent_disk_type'] = 'disk_a'

    deploy_from_scratch(manifest_hash: manifest_hash, cloud_config_hash: cloud_config_hash, failure_expected: true)

    expect(bosh_runner.run('deployments')).to include('1 deployments')
    expect(bosh_runner.run('vms', deployment_name: 'simple')).to include('0 vms')
    output = scrub_random_ids(table(bosh_runner.run('instances', deployment_name: 'simple', json: true)))
    expect(output).to contain_exactly({'instance' => 'foobar/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'process_state' => '', 'az' => '', 'ips' => '' })
    expect(bosh_runner.run('releases')).to include('1 releases')

    expect(current_sandbox.cpi.all_stemcells.count).to eq 1
    expect(current_sandbox.cpi.vm_cids.count).to eq 0
    expect(current_sandbox.cpi.disk_cids.count).to eq 0
    expect(current_sandbox.cpi.all_ips.count).to eq 0

    # Delete Deployment
    deployment_deletion_output = bosh_runner.run('delete-deployment', deployment_name: 'simple', json: true)
    expect(deployment_deletion_output).to match /Deleting instances: foobar/
    expect(deployment_deletion_output).to include('Succeeded')
    # puts bosh_runner.run('delete deployment simple', failure_expected: true)

    # Stemcells and releases remain after deletion of deployment
    expect(current_sandbox.cpi.all_stemcells.count).to eq 1
    expect(bosh_runner.run('releases')).to include('1 releases')

    expect(current_sandbox.cpi.vm_cids.count).to eq 0
    expect(current_sandbox.cpi.disk_cids.count).to eq 0
    expect(current_sandbox.cpi.all_ips.count).to eq 0
    expect(current_sandbox.cpi.all_snapshots.count).to eq 0

    #deployments
    expect(bosh_runner.run('deployments', failure_expected: true)).to include('0 deployments')
  end
end

{'fraction_non_alphanumeric': 0.12133690863819192, 'fraction_numerical': 0.010151312009193642, 'mean_word_length': 5.306159420289855, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2562648', 'n_tokens_mistral': 3689, 'n_tokens_neox': 3412, 'n_words': 579}