|
606 | 606 | before do |
607 | 607 | app1_model.web_processes.first.update(state: VCAP::CloudController::ProcessModel::STARTED, instances: 4) |
608 | 608 | space.update(space_quota_definition: |
609 | | - VCAP::CloudController::SpaceQuotaDefinition.make(organization: space.organization, log_rate_limit: 0)) |
| 609 | + VCAP::CloudController::SpaceQuotaDefinition.make(organization: space.organization, log_rate_limit: 0)) |
610 | 610 | end |
611 | 611 |
|
612 | 612 | it 'successfully applies the manifest' do |
|
625 | 625 | end |
626 | 626 |
|
627 | 627 | describe 'route options' do |
628 | | - context 'when an empty route options hash is provided' do |
| 628 | + context 'when an invalid route option is provided' do |
629 | 629 | let(:yml_manifest) do |
630 | 630 | { |
631 | 631 | 'applications' => [ |
632 | 632 | { |
633 | 633 | 'name' => app1_model.name, |
634 | 634 | 'routes' => [ |
635 | 635 | { 'route' => "https://#{route.host}.#{route.domain.name}", |
636 | | - 'options' => {} } |
| 636 | + 'options' => { |
| 637 | + 'doesnt-exist' => 'doesnt-exist' |
| 638 | + } } |
637 | 639 | ] |
638 | 640 | } |
639 | 641 | ] |
640 | 642 | }.to_yaml |
641 | 643 | end |
642 | 644 |
|
643 | | - it 'applies the manifest' do |
| 645 | + it 'returns a 422' do |
644 | 646 | post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header) |
645 | 647 |
|
646 | | - expect(last_response.status).to eq(202) |
| 648 | + expect(last_response).to have_status_code(422) |
| 649 | + expect(last_response).to have_error_message('Routes contains invalid route options') |
647 | 650 | end |
648 | 651 | end |
649 | 652 |
|
650 | | - context 'when an invalid route option is provided' do |
651 | | - let(:yml_manifest) do |
652 | | - { |
| 653 | + context 'updating existing route options' do |
| 654 | + # using loadbalancing-algorithm as an example since it is the only route option currently supported |
| 655 | + before do |
| 656 | + yml_manifest = { |
653 | 657 | 'applications' => [ |
654 | | - { |
655 | | - 'name' => app1_model.name, |
| 658 | + { 'name' => app1_model.name, |
656 | 659 | 'routes' => [ |
657 | | - { 'route' => "https://#{route.host}.#{route.domain.name}", |
| 660 | + { 'route' => "https://round-robin-app.#{shared_domain.name}", |
658 | 661 | 'options' => { |
659 | | - 'doesnt-exist' => 'doesnt-exist' |
| 662 | + 'loadbalancing-algorithm' => 'round-robin' |
660 | 663 | } } |
661 | | - ] |
662 | | - } |
| 664 | + ] } |
663 | 665 | ] |
664 | 666 | }.to_yaml |
| 667 | + |
| 668 | + # apply the manifest with the route option |
| 669 | + post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header) |
| 670 | + |
| 671 | + expect(last_response.status).to eq(202) |
| 672 | + job_guid = VCAP::CloudController::PollableJobModel.last.guid |
| 673 | + |
| 674 | + Delayed::Worker.new.work_off |
| 675 | + expect(VCAP::CloudController::PollableJobModel.find(guid: job_guid)).to be_complete, VCAP::CloudController::PollableJobModel.find(guid: job_guid).cf_api_error |
| 676 | + app1_model.reload |
| 677 | + expect(app1_model.routes.first.options).to eq({ 'lb_algo' => 'round-robin' }) |
665 | 678 | end |
666 | 679 |
|
667 | | - it 'returns a 422' do |
| 680 | + it 'updates the route option when a new value is provided' do |
| 681 | + yml_manifest = { |
| 682 | + 'applications' => [ |
| 683 | + { 'name' => app1_model.name, |
| 684 | + 'routes' => [ |
| 685 | + { 'route' => "https://round-robin-app.#{shared_domain.name}", |
| 686 | + 'options' => { |
| 687 | + 'loadbalancing-algorithm' => 'least-connections' |
| 688 | + } } |
| 689 | + ] } |
| 690 | + ] |
| 691 | + }.to_yaml |
| 692 | + |
668 | 693 | post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header) |
669 | 694 |
|
670 | | - expect(last_response).to have_status_code(422) |
671 | | - expect(last_response).to have_error_message('Routes contains invalid route options') |
| 695 | + expect(last_response.status).to eq(202) |
| 696 | + job_guid = VCAP::CloudController::PollableJobModel.last.guid |
| 697 | + |
| 698 | + Delayed::Worker.new.work_off |
| 699 | + expect(VCAP::CloudController::PollableJobModel.find(guid: job_guid)).to be_complete, VCAP::CloudController::PollableJobModel.find(guid: job_guid).cf_api_error |
| 700 | + app1_model.reload |
| 701 | + expect(app1_model.routes.first.options).to eq({ 'lb_algo' => 'least-connections' }) |
| 702 | + end |
| 703 | + |
| 704 | + it 'does not modify any route options when the options hash is not provided' do |
| 705 | + yml_manifest = { |
| 706 | + 'applications' => [ |
| 707 | + { 'name' => app1_model.name, |
| 708 | + 'routes' => [ |
| 709 | + { 'route' => "https://round-robin-app.#{shared_domain.name}" } |
| 710 | + ] } |
| 711 | + ] |
| 712 | + }.to_yaml |
| 713 | + |
| 714 | + # apply the manifest with the route option |
| 715 | + post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header) |
| 716 | + |
| 717 | + expect(last_response.status).to eq(202) |
| 718 | + job_guid = VCAP::CloudController::PollableJobModel.last.guid |
| 719 | + |
| 720 | + Delayed::Worker.new.work_off |
| 721 | + expect(VCAP::CloudController::PollableJobModel.find(guid: job_guid)).to be_complete, VCAP::CloudController::PollableJobModel.find(guid: job_guid).cf_api_error |
| 722 | + app1_model.reload |
| 723 | + expect(app1_model.routes.first.options).to eq({ 'lb_algo' => 'round-robin' }) |
| 724 | + end |
| 725 | + |
| 726 | + it 'does not modify any route options options: nil is provided' do |
| 727 | + yml_manifest = { |
| 728 | + 'applications' => [ |
| 729 | + { 'name' => app1_model.name, |
| 730 | + 'routes' => [ |
| 731 | + { 'route' => "https://round-robin-app.#{shared_domain.name}", |
| 732 | + 'options' => nil } |
| 733 | + ] } |
| 734 | + ] |
| 735 | + }.to_yaml |
| 736 | + |
| 737 | + # apply the manifest with the route option |
| 738 | + post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header) |
| 739 | + |
| 740 | + expect(last_response.status).to eq(202) |
| 741 | + job_guid = VCAP::CloudController::PollableJobModel.last.guid |
| 742 | + |
| 743 | + Delayed::Worker.new.work_off |
| 744 | + expect(VCAP::CloudController::PollableJobModel.find(guid: job_guid)).to be_complete, VCAP::CloudController::PollableJobModel.find(guid: job_guid).cf_api_error |
| 745 | + app1_model.reload |
| 746 | + expect(app1_model.routes.first.options).to eq({ 'lb_algo' => 'round-robin' }) |
| 747 | + end |
| 748 | + |
| 749 | + it 'does not modify any route options if an empty options hash is provided' do |
| 750 | + yml_manifest = { |
| 751 | + 'applications' => [ |
| 752 | + { 'name' => app1_model.name, |
| 753 | + 'routes' => [ |
| 754 | + { 'route' => "https://round-robin-app.#{shared_domain.name}", |
| 755 | + 'options' => {} } |
| 756 | + ] } |
| 757 | + ] |
| 758 | + }.to_yaml |
| 759 | + |
| 760 | + # apply the manifest with the route option |
| 761 | + post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header) |
| 762 | + |
| 763 | + expect(last_response.status).to eq(202) |
| 764 | + job_guid = VCAP::CloudController::PollableJobModel.last.guid |
| 765 | + |
| 766 | + Delayed::Worker.new.work_off |
| 767 | + expect(VCAP::CloudController::PollableJobModel.find(guid: job_guid)).to be_complete, VCAP::CloudController::PollableJobModel.find(guid: job_guid).cf_api_error |
| 768 | + app1_model.reload |
| 769 | + expect(app1_model.routes.first.options).to eq({ 'lb_algo' => 'round-robin' }) |
| 770 | + end |
| 771 | + |
| 772 | + it 'removes a specific route option when options: { key: nil } is provided' do |
| 773 | + yml_manifest = { |
| 774 | + 'applications' => [ |
| 775 | + { 'name' => app1_model.name, |
| 776 | + 'routes' => [ |
| 777 | + { 'route' => "https://round-robin-app.#{shared_domain.name}", |
| 778 | + 'options' => { |
| 779 | + 'loadbalancing-algorithm' => nil |
| 780 | + } } |
| 781 | + ] } |
| 782 | + ] |
| 783 | + }.to_yaml |
| 784 | + |
| 785 | + # apply the manifest with the route option |
| 786 | + post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header) |
| 787 | + |
| 788 | + expect(last_response.status).to eq(202) |
| 789 | + job_guid = VCAP::CloudController::PollableJobModel.last.guid |
| 790 | + |
| 791 | + Delayed::Worker.new.work_off |
| 792 | + expect(VCAP::CloudController::PollableJobModel.find(guid: job_guid)).to be_complete, VCAP::CloudController::PollableJobModel.find(guid: job_guid).cf_api_error |
| 793 | + app1_model.reload |
| 794 | + expect(app1_model.routes.first.options).to eq({}) |
672 | 795 | end |
673 | 796 | end |
674 | 797 |
|
675 | | - context 'loadbalancing-algorithm' do |
| 798 | + context 'route-option: loadbalancing-algorithm' do |
676 | 799 | context 'when the loadbalancing-algorithm is not supported' do |
677 | 800 | let(:yml_manifest) do |
678 | 801 | { |
|
713 | 836 | }.to_yaml |
714 | 837 | end |
715 | 838 |
|
716 | | - it 'adds and updates the loadbalancing-algorithm' do |
| 839 | + it 'adds the loadbalancing-algorithm' do |
717 | 840 | post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header) |
718 | 841 |
|
719 | 842 | expect(last_response.status).to eq(202) |
|
724 | 847 |
|
725 | 848 | app1_model.reload |
726 | 849 | expect(app1_model.routes.first.options).to eq({ 'lb_algo' => 'round-robin' }) |
727 | | - |
728 | | - ### update the loadbalancing-algorithm from the route |
729 | | - |
730 | | - yml_manifest = { |
731 | | - 'applications' => [ |
732 | | - { 'name' => app1_model.name, |
733 | | - 'routes' => [ |
734 | | - { 'route' => "https://round-robin-app.#{shared_domain.name}", |
735 | | - 'options' => { |
736 | | - 'loadbalancing-algorithm' => 'least-connections' |
737 | | - } } |
738 | | - ] } |
739 | | - ] |
740 | | - }.to_yaml |
741 | | - |
742 | | - post "/v3/spaces/#{space.guid}/actions/apply_manifest", yml_manifest, yml_headers(user_header) |
743 | | - |
744 | | - expect(last_response.status).to eq(202) |
745 | | - job_guid = VCAP::CloudController::PollableJobModel.last.guid |
746 | | - |
747 | | - Delayed::Worker.new.work_off |
748 | | - expect(VCAP::CloudController::PollableJobModel.find(guid: job_guid)).to be_complete, VCAP::CloudController::PollableJobModel.find(guid: job_guid).cf_api_error |
749 | | - |
750 | | - app1_model.reload |
751 | | - expect(app1_model.routes.first.options).to eq({ 'lb_algo' => 'least-connections' }) |
752 | 850 | end |
753 | 851 | end |
754 | 852 | end |
|
0 commit comments