awspec 0.36.0 → 0.36.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6df1c727f0aeffc393ecf79feba39041cd14b5c
4
- data.tar.gz: 247f84a0ffef96e9b51903bb58049821541b3b0b
3
+ metadata.gz: d3fddd77e3ed0bec352d8a53cfaa7f239b1fb896
4
+ data.tar.gz: f259c5bb2c4b5b90ab582c808d718d9f362a990d
5
5
  SHA512:
6
- metadata.gz: abcc9b2a6623cc2c012bfb4bb606c48455fecf0e999e3ffdb356061998f1a6e5d8a136e8e77780f98510cb2f5a63896dfa23447883ee55c1f38f094e59912754
7
- data.tar.gz: eaf78213317dd30bd9c39eb91c54b9f18814c519b809e685f1b85ff080386b49d960602a088c6fbcfb18be85e6d68f7e1aea9b96dd4d2bc44e13faebab5991d4
6
+ metadata.gz: 45c6af40e0ccbc9fd2d766dcd6df9dbf66168079e12893156ec5b7ece8190fe554b849f88c5eac54e80759ebe5c9bd47460790099356288da483123ba614cfbf
7
+ data.tar.gz: 32e845dd34c5dc984cf5959bef2bb9b9d2e59f86d65cda1d45b6b6de16d51bb61c24afb12d8aa2514e9ddbea530a8c181e166e78f192ccf90682b97e34e859ac
@@ -8,7 +8,7 @@ module Awspec
8
8
  class_option :secrets_path, default: 'secrets.yml'
9
9
 
10
10
  types = %w(
11
- vpc ec2 rds security_group elb network_acl route_table subnet nat_gateway
11
+ vpc ec2 rds security_group elb network_acl route_table subnet nat_gateway network_interface
12
12
  )
13
13
 
14
14
  types.each do |type|
@@ -15,6 +15,7 @@ require 'awspec/generator/spec/ebs'
15
15
  require 'awspec/generator/spec/s3_bucket'
16
16
  require 'awspec/generator/spec/nat_gateway'
17
17
  require 'awspec/generator/spec/lambda'
18
+ require 'awspec/generator/spec/network_interface'
18
19
 
19
20
  # Doc
20
21
  require 'awspec/generator/doc/type'
@@ -0,0 +1,80 @@
1
+ module Awspec::Generator
2
+ module Spec
3
+ class NetworkInterface
4
+ include Awspec::Helper::Finder
5
+ def generate_by_vpc_id(vpc_id)
6
+ describes = %w(
7
+ )
8
+ vpc = find_vpc(vpc_id)
9
+ raise 'Not Found VPC' unless vpc
10
+ @vpc_id = vpc[:vpc_id]
11
+ @vpc_tag_name = vpc.tag_name
12
+ network_interfaces = select_network_interface_by_vpc_id(@vpc_id)
13
+ specs = network_interfaces.map do |interface|
14
+ instance_spec = generate_instance_spec(interface)
15
+ subnet_spec = generate_subnet_spec(interface)
16
+ network_interface_id = interface[:network_interface_id]
17
+ linespecs = generate_linespecs(interface)
18
+ private_ip_addresses_count = interface.private_ip_addresses.count
19
+ content = ERB.new(network_interface_spec_template, nil, '-').result(binding).gsub(/^\n/, '')
20
+ end
21
+ specs.join("\n")
22
+ end
23
+
24
+ def generate_instance_spec(interface)
25
+ return unless interface.attachment.instance_id
26
+ instance = find_ec2(interface.attachment.instance_id)
27
+ instance_spec = if instance.tag_name
28
+ "it { should be_attached_to('#{instance.tag_name}')"
29
+ else
30
+ "it { should be_attached_to('#{instance.instance_id}')"
31
+ end
32
+ instance_spec += ".as_eth#{interface.attachment.device_index} }"
33
+ instance_spec
34
+ end
35
+
36
+ def generate_subnet_spec(interface)
37
+ return unless interface.subnet_id
38
+ subnet = find_subnet(interface.subnet_id)
39
+ subnet_spec = if subnet.tag_name
40
+ "it { should belong_to_subnet('#{subnet.tag_name}') }"
41
+ else
42
+ "it { should belong_to_subnet('#{subnet.subnet_id}') }"
43
+ end
44
+ subnet_spec
45
+ end
46
+
47
+ def generate_linespecs(interface)
48
+ linespecs = []
49
+ interface.private_ip_addresses.each do |ip_address|
50
+ line = "it { should have_private_ip_address('#{ip_address.private_ip_address}')"
51
+ line += '.primary' if ip_address.primary
52
+ line += ' }'
53
+ linespecs.push(line)
54
+ end
55
+ linespecs
56
+ end
57
+
58
+ def network_interface_spec_template
59
+ template = <<-'EOF'
60
+ describe network_interface('<%= network_interface_id %>') do
61
+ it { should exist }
62
+ it { should be_<%= interface.status.tr('-', '_') %> }
63
+ <%- if instance_spec -%>
64
+ <%= instance_spec %>
65
+ <%- end -%>
66
+ it { should belong_to_vpc('<%= @vpc_tag_name %>') }
67
+ <%- if subnet_spec -%>
68
+ <%= subnet_spec %>
69
+ <%- end -%>
70
+ <% linespecs.each do |line| %>
71
+ <%= line %>
72
+ <% end %>
73
+ its(:private_ip_addresses_count) { should eq <%= interface.private_ip_addresses.count %> }
74
+ end
75
+ EOF
76
+ template
77
+ end
78
+ end
79
+ end
80
+ end
@@ -94,6 +94,13 @@ module Awspec::Helper
94
94
  })
95
95
  res.nat_gateways
96
96
  end
97
+
98
+ def select_network_interface_by_vpc_id(vpc_id)
99
+ res = ec2_client.describe_network_interfaces({
100
+ filters: [{ name: 'vpc-id', values: [vpc_id] }]
101
+ })
102
+ res.network_interfaces
103
+ end
97
104
  end
98
105
  end
99
106
  end
@@ -1,3 +1,3 @@
1
1
  module Awspec
2
- VERSION = '0.36.0'
2
+ VERSION = '0.36.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.36.0
4
+ version: 0.36.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW
@@ -276,6 +276,7 @@ files:
276
276
  - lib/awspec/generator/spec/lambda.rb
277
277
  - lib/awspec/generator/spec/nat_gateway.rb
278
278
  - lib/awspec/generator/spec/network_acl.rb
279
+ - lib/awspec/generator/spec/network_interface.rb
279
280
  - lib/awspec/generator/spec/rds.rb
280
281
  - lib/awspec/generator/spec/route53_hosted_zone.rb
281
282
  - lib/awspec/generator/spec/route_table.rb