| 
									
										
										
										
											2015-11-03 11:46:54 +03:00
										 |  |  | require 'db/mongo/models/deploy_env/deploy_env_ec2' | 
					
						
							| 
									
										
										
										
											2015-12-10 01:24:23 +03:00
										 |  |  | require_relative 'shared_deploy_env_specs' | 
					
						
							|  |  |  | require_relative 'shared_cloud_deploy_env_specs' | 
					
						
							| 
									
										
										
										
											2015-11-03 11:46:54 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | RSpec.describe Devops::Model::DeployEnvEc2, type: :model do | 
					
						
							|  |  |  |   let(:env) { build(:deploy_env_ec2) } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-21 20:46:15 +03:00
										 |  |  |   describe 'it inherits from cloud deploy_env', stubbed_connector: true, stubbed_logger: true do | 
					
						
							| 
									
										
										
										
											2016-01-20 17:47:07 +03:00
										 |  |  |     before do | 
					
						
							|  |  |  |       provider_double = instance_double('Provider::Ec2', | 
					
						
							|  |  |  |         flavors: [{'id' => 'flavor'}], | 
					
						
							|  |  |  |         networks: [{'default' => {'vpcId' => 'foo'}}], | 
					
						
							|  |  |  |         groups: {'default' => nil}, | 
					
						
							|  |  |  |         images: [{'id' => 'image'}] | 
					
						
							|  |  |  |       ) | 
					
						
							|  |  |  |       allow(Provider::ProviderFactory).to receive(:providers) { %w(ec2) } | 
					
						
							|  |  |  |       allow(Provider::ProviderFactory).to receive(:get) { provider_double } | 
					
						
							|  |  |  |       allow(stubbed_connector).to receive(:users_names) { %w(root) } | 
					
						
							|  |  |  |       allow(stubbed_connector).to receive(:available_images) { %w(image) } | 
					
						
							|  |  |  |       allow(stubbed_connector).to receive(:stack_templates) { [build(:stack_template_ec2, id: 'template')] } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-10 01:24:23 +03:00
										 |  |  |     it_behaves_like 'deploy env' | 
					
						
							|  |  |  |     it_behaves_like 'cloud deploy env' | 
					
						
							| 
									
										
										
										
											2016-02-24 14:33:02 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it 'raises Devops::NonExistingUser when passing non existing user' do | 
					
						
							|  |  |  |       env = build(:deploy_env_ec2, users: %w(wrong)) | 
					
						
							|  |  |  |       expect { | 
					
						
							|  |  |  |         env.validate! | 
					
						
							|  |  |  |       }.to raise_error Devops::NonExistingUser | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-04-18 21:24:26 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it "isn't valid if provider_account isn't present" do | 
					
						
							|  |  |  |       allow(stubbed_connector).to receive(:provider_accounts) do |provider| | 
					
						
							|  |  |  |         if provider == 'ec2' | 
					
						
							|  |  |  |           account_name = 'ec2_account' | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           account_name = 'static_account' | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |         [Provider::ProviderFactory.get_account_class(provider).new('account_name' => account_name)] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       env.provider_account = 'static_account' | 
					
						
							|  |  |  |       expect(env).not_to be_valid | 
					
						
							|  |  |  |       env.provider_account = 'ec2_account' | 
					
						
							|  |  |  |       expect(env).to be_valid | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-12-10 01:24:23 +03:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-11-03 11:46:54 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe '#initialize' do | 
					
						
							|  |  |  |     it 'keep only first subnet in given array' do | 
					
						
							|  |  |  |       env = described_class.new('subnets' => %w(foo bar)) | 
					
						
							|  |  |  |       expect(env.subnets).to match_array(%w(foo)) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe '.create' do | 
					
						
							|  |  |  |     it 'returns instance of DeployEnvEc2' do | 
					
						
							|  |  |  |       expect(described_class.create({})).to be_an_instance_of(described_class) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe '#subnets_filter' do | 
					
						
							|  |  |  |     before do | 
					
						
							|  |  |  |       allow_any_instance_of(described_class).to receive_message_chain('provider_instance.networks') { | 
					
						
							|  |  |  |         [{'name' => 'foo', 'vpcId' => 'bar'}] | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it 'returns nil if #subnets are empty' do | 
					
						
							|  |  |  |       expect(build(:deploy_env_ec2, subnets: []).subnets_filter).to be_nil | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "when provider has env's network" do | 
					
						
							|  |  |  |       it 'returns hash with vpcId of that network' do | 
					
						
							|  |  |  |         env = build(:deploy_env_ec2, subnets: ['foo']) | 
					
						
							|  |  |  |         expect(env.subnets_filter).to eq({'vpc-id' => 'bar'}) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "when provider hasn't env's network" do | 
					
						
							|  |  |  |       it 'returns nil' do | 
					
						
							|  |  |  |         env = build(:deploy_env_ec2, subnets: ['wrong']) | 
					
						
							|  |  |  |         expect(env.subnets_filter).to be nil | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | end |