vcloud-edge_gateway 0.5.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,14 +5,8 @@ module Vcloud
5
5
  describe EdgeGateway::Configure do
6
6
 
7
7
  before(:all) do
8
- IntegrationHelper.verify_env_vars
9
- @edge_name = ENV['VCLOUD_EDGE_GATEWAY']
10
- @ext_net_id = ENV['VCLOUD_PROVIDER_NETWORK_ID']
11
- @ext_net_ip = ENV['VCLOUD_PROVIDER_NETWORK_IP']
12
- @ext_net_name = ENV['VCLOUD_PROVIDER_NETWORK_NAME']
13
- @int_net_id = ENV['VCLOUD_NETWORK1_ID']
14
- @int_net_ip = ENV['VCLOUD_NETWORK1_IP']
15
- @int_net_name = ENV['VCLOUD_NETWORK1_NAME']
8
+ config_file = File.join(File.dirname(__FILE__), "../vcloud_tools_testing_config.yaml")
9
+ @test_data = Vcloud::Tools::Tester::TestParameters.new(config_file)
16
10
  @files_to_delete = []
17
11
  end
18
12
 
@@ -22,7 +16,7 @@ module Vcloud
22
16
  reset_edge_gateway
23
17
  @vars_config_file = generate_vars_file(edge_gateway_vars_hash)
24
18
  @initial_firewall_config_file = IntegrationHelper.fixture_file('firewall_config.yaml.mustache')
25
- @edge_gateway = Vcloud::Core::EdgeGateway.get_by_name(@edge_name)
19
+ @edge_gateway = Vcloud::Core::EdgeGateway.get_by_name(@test_data.edge_gateway)
26
20
  @firewall_service = {}
27
21
  end
28
22
 
@@ -44,7 +38,10 @@ module Vcloud
44
38
 
45
39
  it "should only need to make one call to Core::EdgeGateway.update_configuration" do
46
40
  expect_any_instance_of(Core::EdgeGateway).to receive(:update_configuration).exactly(1).times.and_call_original
47
- EdgeGateway::Configure.new(@initial_firewall_config_file, @vars_config_file).update
41
+ diff = EdgeGateway::Configure.new(@initial_firewall_config_file, @vars_config_file).update
42
+
43
+ expect(diff.keys).to eq([:FirewallService])
44
+ expect(diff[:FirewallService]).to have_at_least(1).items
48
45
  end
49
46
 
50
47
  it "should have configured at least one firewall rule" do
@@ -60,32 +57,9 @@ module Vcloud
60
57
 
61
58
  it "and then should not configure the firewall service if updated again with the same configuration (idempotency)" do
62
59
  expect(Vcloud::Core.logger).to receive(:info).with('EdgeGateway::Configure.update: Configuration is already up to date. Skipping.')
63
- EdgeGateway::Configure.new(@initial_firewall_config_file, @vars_config_file).update
64
- end
60
+ diff = EdgeGateway::Configure.new(@initial_firewall_config_file, @vars_config_file).update
65
61
 
66
- it "ConfigurationDiffer should return empty if local and remote firewall configs match" do
67
- remote_vcloud_config = @edge_gateway.vcloud_attributes[:Configuration][:EdgeGatewayServiceConfiguration][:FirewallService]
68
- differ = EdgeGateway::ConfigurationDiffer.new(@local_vcloud_config, remote_vcloud_config)
69
- diff_output = differ.diff
70
- expect(diff_output).to eq([])
71
- end
72
-
73
- it "should highlight a difference if local firewall config has been updated" do
74
- local_config = Core::ConfigLoader.new.load_config(
75
- IntegrationHelper.fixture_file('firewall_config_updated_rule.yaml.mustache'),
76
- Vcloud::EdgeGateway::Schema::EDGE_GATEWAY_SERVICES,
77
- @vars_config_file
78
- )
79
- local_firewall_config = EdgeGateway::ConfigurationGenerator::FirewallService.new.generate_fog_config(local_config[:firewall_service])
80
-
81
- edge_gateway = Core::EdgeGateway.get_by_name local_config[:gateway]
82
- remote_config = edge_gateway.vcloud_attributes[:Configuration][:EdgeGatewayServiceConfiguration]
83
- remote_firewall_config = remote_config[:FirewallService]
84
-
85
- differ = EdgeGateway::ConfigurationDiffer.new(local_firewall_config, remote_firewall_config)
86
- diff_output = differ.diff
87
-
88
- expect(diff_output.empty?).to be_false
62
+ expect(diff).to eq({})
89
63
  end
90
64
 
91
65
  end
@@ -151,14 +125,11 @@ module Vcloud
151
125
  end
152
126
 
153
127
  after(:all) do
154
- reset_edge_gateway unless ENV['VCLOUD_NO_RESET_VSE_AFTER']
155
- @files_to_delete.each { |f|
156
- f.unlink
157
- }
128
+ IntegrationHelper.remove_temp_config_files(@files_to_delete)
158
129
  end
159
130
 
160
131
  def reset_edge_gateway
161
- edge_gateway = Core::EdgeGateway.get_by_name @edge_name
132
+ edge_gateway = Core::EdgeGateway.get_by_name @test_data.edge_gateway
162
133
  edge_gateway.update_configuration({
163
134
  FirewallService: {IsEnabled: false, FirewallRule: []},
164
135
  })
@@ -175,9 +146,9 @@ module Vcloud
175
146
 
176
147
  def edge_gateway_vars_hash
177
148
  {
178
- :edge_gateway_name => @edge_name,
179
- :edge_gateway_ext_network_id => @ext_net_id,
180
- :edge_gateway_ext_network_ip => @ext_net_ip,
149
+ :edge_gateway_name => @test_data.edge_gateway,
150
+ :edge_gateway_ext_network_id => @test_data.provider_network_id,
151
+ :edge_gateway_ext_network_ip => @test_data.provider_network_ip,
181
152
  }
182
153
  end
183
154
 
@@ -5,14 +5,8 @@ module Vcloud
5
5
  describe EdgeGateway::Configure do
6
6
 
7
7
  before(:all) do
8
- IntegrationHelper.verify_env_vars
9
- @edge_name = ENV['VCLOUD_EDGE_GATEWAY']
10
- @ext_net_id = ENV['VCLOUD_PROVIDER_NETWORK_ID']
11
- @ext_net_ip = ENV['VCLOUD_PROVIDER_NETWORK_IP']
12
- @ext_net_name = ENV['VCLOUD_PROVIDER_NETWORK_NAME']
13
- @int_net_id = ENV['VCLOUD_NETWORK1_ID']
14
- @int_net_ip = ENV['VCLOUD_NETWORK1_IP']
15
- @int_net_name = ENV['VCLOUD_NETWORK1_NAME']
8
+ config_file = File.join(File.dirname(__FILE__), "../vcloud_tools_testing_config.yaml")
9
+ @test_data = Vcloud::Tools::Tester::TestParameters.new(config_file)
16
10
  @files_to_delete = []
17
11
  end
18
12
 
@@ -22,7 +16,7 @@ module Vcloud
22
16
  reset_edge_gateway
23
17
  @vars_config_file = generate_vars_file(edge_gateway_vars_hash)
24
18
  @initial_load_balancer_config_file = IntegrationHelper.fixture_file('load_balancer_config.yaml.mustache')
25
- @edge_gateway = Vcloud::Core::EdgeGateway.get_by_name(@edge_name)
19
+ @edge_gateway = Vcloud::Core::EdgeGateway.get_by_name(@test_data.edge_gateway)
26
20
  end
27
21
 
28
22
  context "Check update is functional" do
@@ -48,8 +42,11 @@ module Vcloud
48
42
  it "should only make one EdgeGateway update task, to minimise EdgeGateway reload events" do
49
43
  start_time = Time.now.getutc
50
44
  task_list_before_update = get_all_edge_gateway_update_tasks_ordered_by_start_date_since_time(start_time)
51
- EdgeGateway::Configure.new(@initial_load_balancer_config_file, @vars_config_file).update
45
+ diff = EdgeGateway::Configure.new(@initial_load_balancer_config_file, @vars_config_file).update
52
46
  task_list_after_update = get_all_edge_gateway_update_tasks_ordered_by_start_date_since_time(start_time)
47
+
48
+ expect(diff.keys).to eq([:LoadBalancerService])
49
+ expect(diff[:LoadBalancerService]).to have_at_least(1).items
53
50
  expect(task_list_after_update.size - task_list_before_update.size).to be(1)
54
51
  end
55
52
 
@@ -79,18 +76,12 @@ module Vcloud
79
76
  to eq(@local_vcloud_config[:VirtualServer].size)
80
77
  end
81
78
 
82
- it "ConfigurationDiffer should return empty if local and remote LoadBalancer configs match" do
83
- edge_service_config = @edge_gateway.vcloud_attributes[:Configuration][:EdgeGatewayServiceConfiguration]
84
- remote_vcloud_config = edge_service_config[:LoadBalancerService]
85
- differ = EdgeGateway::LoadBalancerConfigurationDiffer.new(@local_vcloud_config, remote_vcloud_config)
86
- diff_output = differ.diff
87
- expect(diff_output).to eq([])
88
- end
89
-
90
79
  it "should not then configure the LoadBalancerService if updated again with the same configuration" do
91
- expect(Vcloud::Core.logger).
92
- to receive(:info).with('EdgeGateway::Configure.update: Configuration is already up to date. Skipping.')
93
- EdgeGateway::Configure.new(@initial_load_balancer_config_file, @vars_config_file).update
80
+ expect(Vcloud::Core.logger).to receive(:info).
81
+ with('EdgeGateway::Configure.update: Configuration is already up to date. Skipping.')
82
+ diff = EdgeGateway::Configure.new(@initial_load_balancer_config_file, @vars_config_file).update
83
+
84
+ expect(diff).to eq({})
94
85
  end
95
86
 
96
87
  end
@@ -99,18 +90,24 @@ module Vcloud
99
90
 
100
91
  it "should be able to configure with no pools and virtual_servers" do
101
92
  config_file = IntegrationHelper.fixture_file('load_balancer_empty.yaml.mustache')
102
- EdgeGateway::Configure.new(config_file, @vars_config_file).update
93
+ diff = EdgeGateway::Configure.new(config_file, @vars_config_file).update
103
94
  edge_config = @edge_gateway.vcloud_attributes[:Configuration]
104
95
  remote_vcloud_config = edge_config[:EdgeGatewayServiceConfiguration][:LoadBalancerService]
96
+
97
+ expect(diff.keys).to eq([:LoadBalancerService])
98
+ expect(diff[:LoadBalancerService]).to have_at_least(1).items
105
99
  expect(remote_vcloud_config[:Pool].size).to be == 0
106
100
  expect(remote_vcloud_config[:VirtualServer].size).to be == 0
107
101
  end
108
102
 
109
103
  it "should be able to configure with a single Pool and no VirtualServers" do
110
104
  config_file = IntegrationHelper.fixture_file('load_balancer_single_pool.yaml.mustache')
111
- EdgeGateway::Configure.new(config_file, @vars_config_file).update
105
+ diff = EdgeGateway::Configure.new(config_file, @vars_config_file).update
112
106
  edge_config = @edge_gateway.vcloud_attributes[:Configuration]
113
107
  remote_vcloud_config = edge_config[:EdgeGatewayServiceConfiguration][:LoadBalancerService]
108
+
109
+ expect(diff.keys).to eq([:LoadBalancerService])
110
+ expect(diff[:LoadBalancerService]).to have_at_least(1).items
114
111
  expect(remote_vcloud_config[:Pool].size).to be == 1
115
112
  end
116
113
 
@@ -131,14 +128,11 @@ module Vcloud
131
128
  end
132
129
 
133
130
  after(:all) do
134
- reset_edge_gateway unless ENV['VCLOUD_NO_RESET_VSE_AFTER']
135
- @files_to_delete.each { |f|
136
- f.unlink
137
- }
131
+ IntegrationHelper.remove_temp_config_files(@files_to_delete)
138
132
  end
139
133
 
140
134
  def reset_edge_gateway
141
- edge_gateway = Core::EdgeGateway.get_by_name @edge_name
135
+ edge_gateway = Core::EdgeGateway.get_by_name @test_data.edge_gateway
142
136
  edge_gateway.update_configuration({
143
137
  LoadBalancerService: {
144
138
  IsEnabled: "false",
@@ -159,9 +153,9 @@ module Vcloud
159
153
 
160
154
  def edge_gateway_vars_hash
161
155
  {
162
- :edge_gateway_name => @edge_name,
163
- :edge_gateway_ext_network_id => @ext_net_id,
164
- :edge_gateway_ext_network_ip => @ext_net_ip,
156
+ :edge_gateway_name => @test_data.edge_gateway,
157
+ :edge_gateway_ext_network_id => @test_data.provider_network_id,
158
+ :edge_gateway_ext_network_ip => @test_data.provider_network_ip,
165
159
  }
166
160
  end
167
161
 
@@ -170,7 +164,7 @@ module Vcloud
170
164
  q = Vcloud::Core::QueryRunner.new
171
165
  q.run('task',
172
166
  :filter =>
173
- "name==networkConfigureEdgeGatewayServices;objectName==#{@edge_name};startDate=ge=#{vcloud_time}",
167
+ "name==networkConfigureEdgeGatewayServices;objectName==#{@test_data.edge_gateway};startDate=ge=#{vcloud_time}",
174
168
  :sortDesc => 'startDate',
175
169
  )
176
170
  end
@@ -5,14 +5,8 @@ module Vcloud
5
5
  describe EdgeGateway::Configure do
6
6
 
7
7
  before(:all) do
8
- IntegrationHelper.verify_env_vars
9
- @edge_name = ENV['VCLOUD_EDGE_GATEWAY']
10
- @ext_net_id = ENV['VCLOUD_PROVIDER_NETWORK_ID']
11
- @ext_net_ip = ENV['VCLOUD_PROVIDER_NETWORK_IP']
12
- @ext_net_name = ENV['VCLOUD_PROVIDER_NETWORK_NAME']
13
- @int_net_id = ENV['VCLOUD_NETWORK1_ID']
14
- @int_net_ip = ENV['VCLOUD_NETWORK1_IP']
15
- @int_net_name = ENV['VCLOUD_NETWORK1_NAME']
8
+ config_file = File.join(File.dirname(__FILE__), "../vcloud_tools_testing_config.yaml")
9
+ @test_data = Vcloud::Tools::Tester::TestParameters.new(config_file)
16
10
  @files_to_delete = []
17
11
  end
18
12
 
@@ -22,7 +16,7 @@ module Vcloud
22
16
  reset_edge_gateway
23
17
  @vars_config_file = generate_vars_file(edge_gateway_vars_hash)
24
18
  @initial_nat_config_file = IntegrationHelper.fixture_file('nat_config.yaml.mustache')
25
- @edge_gateway = Vcloud::Core::EdgeGateway.get_by_name(@edge_name)
19
+ @edge_gateway = Vcloud::Core::EdgeGateway.get_by_name(@test_data.edge_gateway)
26
20
  end
27
21
 
28
22
  context "Check update is functional" do
@@ -47,8 +41,11 @@ module Vcloud
47
41
  it "should only make one EdgeGateway update task, to minimise EdgeGateway reload events" do
48
42
  start_time = Time.now.getutc
49
43
  task_list_before_update = get_all_edge_gateway_update_tasks_ordered_by_start_date_since_time(start_time)
50
- EdgeGateway::Configure.new(@initial_nat_config_file, @vars_config_file).update
44
+ diff = EdgeGateway::Configure.new(@initial_nat_config_file, @vars_config_file).update
51
45
  task_list_after_update = get_all_edge_gateway_update_tasks_ordered_by_start_date_since_time(start_time)
46
+
47
+ expect(diff.keys).to eq([:NatService])
48
+ expect(diff[:NatService]).to have_at_least(1).items
52
49
  expect(task_list_after_update.size - task_list_before_update.size).to be(1)
53
50
  end
54
51
 
@@ -63,16 +60,11 @@ module Vcloud
63
60
  to eq(@local_vcloud_config[:NatRule].size)
64
61
  end
65
62
 
66
- it "ConfigurationDiffer should return empty if local and remote nat configs match" do
67
- remote_vcloud_config = @edge_gateway.vcloud_attributes[:Configuration][:EdgeGatewayServiceConfiguration][:NatService]
68
- differ = EdgeGateway::ConfigurationDiffer.new(@local_vcloud_config, remote_vcloud_config)
69
- diff_output = differ.diff
70
- expect(diff_output).to eq([])
71
- end
72
-
73
63
  it "and then should not configure the firewall service if updated again with the same configuration (idempotency)" do
74
64
  expect(Vcloud::Core.logger).to receive(:info).with('EdgeGateway::Configure.update: Configuration is already up to date. Skipping.')
75
- EdgeGateway::Configure.new(@initial_nat_config_file, @vars_config_file).update
65
+ diff = EdgeGateway::Configure.new(@initial_nat_config_file, @vars_config_file).update
66
+
67
+ expect(diff).to eq({})
76
68
  end
77
69
 
78
70
  end
@@ -88,8 +80,8 @@ module Vcloud
88
80
  expect(dnat_rule[:RuleType]).to eq('DNAT')
89
81
  expect(dnat_rule[:Id]).to eq('65537')
90
82
  expect(dnat_rule[:IsEnabled]).to eq('true')
91
- expect(dnat_rule[:GatewayNatRule][:Interface][:href]).to include(@ext_net_id)
92
- expect(dnat_rule[:GatewayNatRule][:OriginalIp]).to eq(@ext_net_ip)
83
+ expect(dnat_rule[:GatewayNatRule][:Interface][:href]).to include(@test_data.provider_network_id)
84
+ expect(dnat_rule[:GatewayNatRule][:OriginalIp]).to eq(@test_data.provider_network_ip)
93
85
  expect(dnat_rule[:GatewayNatRule][:OriginalPort]).to eq('3412')
94
86
  expect(dnat_rule[:GatewayNatRule][:TranslatedIp]).to eq('10.10.1.2-10.10.1.3')
95
87
  expect(dnat_rule[:GatewayNatRule][:TranslatedPort]).to eq('3412')
@@ -102,9 +94,9 @@ module Vcloud
102
94
  expect(snat_rule[:RuleType]).to eq('SNAT')
103
95
  expect(snat_rule[:Id]).to eq('65538')
104
96
  expect(snat_rule[:IsEnabled]).to eq('true')
105
- expect(snat_rule[:GatewayNatRule][:Interface][:href]).to include(@ext_net_id)
97
+ expect(snat_rule[:GatewayNatRule][:Interface][:href]).to include(@test_data.provider_network_id)
106
98
  expect(snat_rule[:GatewayNatRule][:OriginalIp]).to eq('10.10.1.2-10.10.1.3')
107
- expect(snat_rule[:GatewayNatRule][:TranslatedIp]).to eq(@ext_net_ip)
99
+ expect(snat_rule[:GatewayNatRule][:TranslatedIp]).to eq(@test_data.provider_network_ip)
108
100
  end
109
101
 
110
102
  end
@@ -113,17 +105,20 @@ module Vcloud
113
105
 
114
106
  it "and then should configure hairpin NATting with orgVdcNetwork" do
115
107
  vars_file = generate_vars_file({
116
- edge_gateway_name: @edge_name,
117
- org_vdc_network_id: @int_net_id,
118
- original_ip: @int_net_ip,
108
+ edge_gateway_name: @test_data.edge_gateway,
109
+ org_vdc_network_id: @test_data.network_1_id,
110
+ original_ip: @test_data.network_1_ip,
119
111
  })
120
112
 
121
- EdgeGateway::Configure.new(
113
+ diff = EdgeGateway::Configure.new(
122
114
  IntegrationHelper.fixture_file('hairpin_nat_config.yaml.mustache'),
123
115
  vars_file
124
116
  ).update
125
117
 
126
- edge_gateway = Vcloud::Core::EdgeGateway.get_by_name(@edge_name)
118
+ expect(diff.keys).to eq([:NatService])
119
+ expect(diff[:NatService]).to have_at_least(1).items
120
+
121
+ edge_gateway = Vcloud::Core::EdgeGateway.get_by_name(@test_data.edge_gateway)
127
122
  nat_service = edge_gateway.vcloud_attributes[:Configuration][:EdgeGatewayServiceConfiguration][:NatService]
128
123
  expected_rule = nat_service[:NatRule].first
129
124
  expect(expected_rule).not_to be_nil
@@ -131,8 +126,8 @@ module Vcloud
131
126
  expect(expected_rule[:Id]).to eq('65537')
132
127
  expect(expected_rule[:RuleType]).to eq('DNAT')
133
128
  expect(expected_rule[:IsEnabled]).to eq('true')
134
- expect(expected_rule[:GatewayNatRule][:Interface][:name]).to eq(@int_net_name)
135
- expect(expected_rule[:GatewayNatRule][:OriginalIp]).to eq(@int_net_ip)
129
+ expect(expected_rule[:GatewayNatRule][:Interface][:name]).to eq(@test_data.network_1)
130
+ expect(expected_rule[:GatewayNatRule][:OriginalIp]).to eq(@test_data.network_1_ip)
136
131
  expect(expected_rule[:GatewayNatRule][:OriginalPort]).to eq('3412')
137
132
  expect(expected_rule[:GatewayNatRule][:TranslatedIp]).to eq('10.10.1.2')
138
133
  expect(expected_rule[:GatewayNatRule][:TranslatedPort]).to eq('3412')
@@ -142,9 +137,9 @@ module Vcloud
142
137
  it "should raise error if network provided in rule does not exist" do
143
138
  random_network_id = SecureRandom.uuid
144
139
  vars_file = generate_vars_file({
145
- edge_gateway_name: @edge_name,
140
+ edge_gateway_name: @test_data.edge_gateway,
146
141
  network_id: random_network_id,
147
- original_ip: @int_net_ip,
142
+ original_ip: @test_data.network_1_ip,
148
143
  })
149
144
 
150
145
  expect {
@@ -157,18 +152,11 @@ module Vcloud
157
152
  end
158
153
 
159
154
  after(:all) do
160
- reset_edge_gateway unless ENV['VCLOUD_NO_RESET_VSE_AFTER']
161
- remove_temp_config_files
162
- end
163
-
164
- def remove_temp_config_files
165
- @files_to_delete.each { |f|
166
- f.unlink
167
- }
155
+ IntegrationHelper.remove_temp_config_files(@files_to_delete)
168
156
  end
169
157
 
170
158
  def reset_edge_gateway
171
- edge_gateway = Core::EdgeGateway.get_by_name @edge_name
159
+ edge_gateway = Core::EdgeGateway.get_by_name @test_data.edge_gateway
172
160
  edge_gateway.update_configuration({
173
161
  NatService: {:IsEnabled => "true", :NatRule => []},
174
162
  })
@@ -185,9 +173,9 @@ module Vcloud
185
173
 
186
174
  def edge_gateway_vars_hash
187
175
  {
188
- :edge_gateway_name => @edge_name,
189
- :network_id => @ext_net_id,
190
- :original_ip => @ext_net_ip,
176
+ :edge_gateway_name => @test_data.edge_gateway,
177
+ :network_id => @test_data.provider_network_id,
178
+ :original_ip => @test_data.provider_network_ip,
191
179
  }
192
180
  end
193
181
 
@@ -195,7 +183,7 @@ module Vcloud
195
183
  vcloud_time = timestamp.strftime('%FT%T.000Z')
196
184
  q = Vcloud::Core::QueryRunner.new
197
185
  q.run('task',
198
- :filter => "name==networkConfigureEdgeGatewayServices;objectName==#{@edge_name};startDate=ge=#{vcloud_time}",
186
+ :filter => "name==networkConfigureEdgeGatewayServices;objectName==#{@test_data.edge_gateway};startDate=ge=#{vcloud_time}",
199
187
  :sortDesc => 'startDate',
200
188
  )
201
189
  end
@@ -5,14 +5,8 @@ module Vcloud
5
5
  describe EdgeGateway::Configure do
6
6
 
7
7
  before(:all) do
8
- IntegrationHelper.verify_env_vars
9
- @edge_name = ENV['VCLOUD_EDGE_GATEWAY']
10
- @ext_net_id = ENV['VCLOUD_PROVIDER_NETWORK_ID']
11
- @ext_net_ip = ENV['VCLOUD_PROVIDER_NETWORK_IP']
12
- @ext_net_name = ENV['VCLOUD_PROVIDER_NETWORK_NAME']
13
- @int_net_id = ENV['VCLOUD_NETWORK1_ID']
14
- @int_net_ip = ENV['VCLOUD_NETWORK1_IP']
15
- @int_net_name = ENV['VCLOUD_NETWORK1_NAME']
8
+ config_file = File.join(File.dirname(__FILE__), "../vcloud_tools_testing_config.yaml")
9
+ @test_data = Vcloud::Tools::Tester::TestParameters.new(config_file)
16
10
  @files_to_delete = []
17
11
  end
18
12
 
@@ -23,7 +17,7 @@ module Vcloud
23
17
  @vars_config_file = generate_vars_file(edge_gateway_vars_hash)
24
18
  @initial_config_file = IntegrationHelper.fixture_file('nat_and_firewall_config.yaml.mustache')
25
19
  @adding_load_balancer_config_file = IntegrationHelper.fixture_file('nat_and_firewall_plus_load_balancer_config.yaml.mustache')
26
- @edge_gateway = Vcloud::Core::EdgeGateway.get_by_name(@edge_name)
20
+ @edge_gateway = Vcloud::Core::EdgeGateway.get_by_name(@test_data.edge_gateway)
27
21
  end
28
22
 
29
23
  context "Check update is functional" do
@@ -39,8 +33,12 @@ module Vcloud
39
33
  it "should only create one edgeGateway update task when updating the configuration" do
40
34
  start_time = Time.now.getutc
41
35
  task_list_before_update = get_all_edge_gateway_update_tasks_ordered_by_start_date_since_time(start_time)
42
- EdgeGateway::Configure.new(@initial_config_file, @vars_config_file).update
36
+ diff = EdgeGateway::Configure.new(@initial_config_file, @vars_config_file).update
43
37
  task_list_after_update = get_all_edge_gateway_update_tasks_ordered_by_start_date_since_time(start_time)
38
+
39
+ expect(diff.keys).to eq([:FirewallService, :NatService])
40
+ expect(diff[:FirewallService]).to have_at_least(1).items
41
+ expect(diff[:NatService]).to have_at_least(1).items
44
42
  expect(task_list_after_update.size - task_list_before_update.size).to be(1)
45
43
  end
46
44
 
@@ -55,42 +53,42 @@ module Vcloud
55
53
  it "should not update the EdgeGateway again if the config hasn't changed" do
56
54
  start_time = Time.now.getutc
57
55
  task_list_before_update = get_all_edge_gateway_update_tasks_ordered_by_start_date_since_time(start_time)
58
- EdgeGateway::Configure.new(@initial_config_file, @vars_config_file).update
56
+ diff = EdgeGateway::Configure.new(@initial_config_file, @vars_config_file).update
59
57
  task_list_after_update = get_all_edge_gateway_update_tasks_ordered_by_start_date_since_time(start_time)
58
+
59
+ expect(diff).to eq({})
60
60
  expect(task_list_after_update.size - task_list_before_update.size).to be(0)
61
61
  end
62
62
 
63
63
  it "should only create one additional edgeGateway update task when adding the LoadBalancer config" do
64
64
  start_time = Time.now.getutc
65
65
  task_list_before_update = get_all_edge_gateway_update_tasks_ordered_by_start_date_since_time(start_time)
66
- EdgeGateway::Configure.new(@adding_load_balancer_config_file, @vars_config_file).update
66
+ diff = EdgeGateway::Configure.new(@adding_load_balancer_config_file, @vars_config_file).update
67
67
  task_list_after_update = get_all_edge_gateway_update_tasks_ordered_by_start_date_since_time(start_time)
68
+
69
+ expect(diff.keys).to eq([:LoadBalancerService])
70
+ expect(diff[:LoadBalancerService]).to have_at_least(1).items
68
71
  expect(task_list_after_update.size - task_list_before_update.size).to be(1)
69
72
  end
70
73
 
71
74
  it "should not update the EdgeGateway again if we reapply the 'adding load balancer' config" do
72
75
  start_time = Time.now.getutc
73
76
  task_list_before_update = get_all_edge_gateway_update_tasks_ordered_by_start_date_since_time(start_time)
74
- EdgeGateway::Configure.new(@adding_load_balancer_config_file, @vars_config_file).update
77
+ diff = EdgeGateway::Configure.new(@adding_load_balancer_config_file, @vars_config_file).update
75
78
  task_list_after_update = get_all_edge_gateway_update_tasks_ordered_by_start_date_since_time(start_time)
79
+
80
+ expect(diff).to eq({})
76
81
  expect(task_list_after_update.size - task_list_before_update.size).to be(0)
77
82
  end
78
83
 
79
84
  end
80
85
 
81
86
  after(:all) do
82
- reset_edge_gateway unless ENV['VCLOUD_NO_RESET_VSE_AFTER']
83
- remove_temp_config_files
84
- end
85
-
86
- def remove_temp_config_files
87
- @files_to_delete.each { |f|
88
- f.unlink
89
- }
87
+ IntegrationHelper.remove_temp_config_files(@files_to_delete)
90
88
  end
91
89
 
92
90
  def reset_edge_gateway
93
- edge_gateway = Core::EdgeGateway.get_by_name @edge_name
91
+ edge_gateway = Core::EdgeGateway.get_by_name @test_data.edge_gateway
94
92
  edge_gateway.update_configuration({
95
93
  FirewallService: {IsEnabled: false, FirewallRule: []},
96
94
  NatService: {:IsEnabled => "true", :NatRule => []},
@@ -113,11 +111,11 @@ module Vcloud
113
111
 
114
112
  def edge_gateway_vars_hash
115
113
  {
116
- edge_gateway_name: @edge_name,
117
- network_id: @ext_net_id,
118
- original_ip: @ext_net_ip,
119
- edge_gateway_ext_network_id: @ext_net_id,
120
- edge_gateway_ext_network_ip: @ext_net_ip,
114
+ edge_gateway_name: @test_data.edge_gateway,
115
+ network_id: @test_data.provider_network_id,
116
+ original_ip: @test_data.provider_network_ip,
117
+ edge_gateway_ext_network_id: @test_data.provider_network_id,
118
+ edge_gateway_ext_network_ip: @test_data.provider_network_ip,
121
119
  }
122
120
  end
123
121
 
@@ -127,7 +125,7 @@ module Vcloud
127
125
 
128
126
  q.run('task',
129
127
  :filter =>
130
- "name==networkConfigureEdgeGatewayServices;objectName==#{@edge_name};startDate=ge=#{vcloud_time}",
128
+ "name==networkConfigureEdgeGatewayServices;objectName==#{@test_data.edge_gateway};startDate=ge=#{vcloud_time}",
131
129
  :sortDesc => 'startDate',
132
130
  )
133
131
  end
@@ -0,0 +1,8 @@
1
+ default:
2
+ network_1:
3
+ network_1_id:
4
+ network_1_ip:
5
+ edge_gateway:
6
+ provider_network:
7
+ provider_network_id:
8
+ provider_network_ip:
data/spec/spec_helper.rb CHANGED
@@ -1,26 +1,37 @@
1
- require 'simplecov'
2
1
  require 'support/integration_helper'
3
2
 
4
- SimpleCov.profiles.define 'gem' do
5
- add_filter '/spec/'
6
- add_filter '/features/'
7
- add_filter '/vendor/'
3
+ if ENV['COVERAGE']
4
+ require 'simplecov'
8
5
 
9
- add_group 'Libraries', '/lib/'
10
- end
6
+ SimpleCov.profiles.define 'gem' do
7
+ add_filter '/spec/'
8
+ add_filter '/features/'
9
+ add_filter '/vendor/'
10
+
11
+ add_group 'Libraries', '/lib/'
12
+ end
11
13
 
12
- SimpleCov.start 'gem'
14
+ SimpleCov.start 'gem'
15
+ end
13
16
 
14
17
  require 'bundler/setup'
15
18
  require 'vcloud/edge_gateway'
19
+ require 'vcloud/tools/tester'
16
20
 
21
+ RSpec.configure do |config|
22
+ config.expect_with :rspec do |c|
23
+ c.syntax = :expect
24
+ end
25
+ end
17
26
 
18
- SimpleCov.at_exit do
19
- SimpleCov.result.format!
20
- # do not change the coverage percentage, instead add more unit tests to fix coverage failures.
21
- if SimpleCov.result.covered_percent < 90
22
- print "ERROR::BAD_COVERAGE\n"
23
- print "Coverage is less than acceptable limit(90%). Please add more tests to improve the coverage\n"
24
- exit(1)
27
+ if ENV['COVERAGE']
28
+ SimpleCov.at_exit do
29
+ SimpleCov.result.format!
30
+ # do not change the coverage percentage, instead add more unit tests to fix coverage failures.
31
+ if SimpleCov.result.covered_percent < 90
32
+ print "ERROR::BAD_COVERAGE\n"
33
+ print "Coverage is less than acceptable limit(90%). Please add more tests to improve the coverage\n"
34
+ exit(1)
35
+ end
25
36
  end
26
37
  end
@@ -1,24 +1,4 @@
1
1
  module IntegrationHelper
2
- REQUIRED_ENV = {
3
- 'VCLOUD_EDGE_GATEWAY' => 'to name of VSE',
4
- 'VCLOUD_PROVIDER_NETWORK_ID' => 'to ID of VSE external network',
5
- 'VCLOUD_PROVIDER_NETWORK_IP' => 'to an available IP on VSE external network',
6
- 'VCLOUD_NETWORK1_ID' => 'to the ID of a VSE internal network',
7
- 'VCLOUD_NETWORK1_NAME' => 'to the name of the VSE internal network',
8
- 'VCLOUD_NETWORK1_IP' => 'to an ID on the VSE internal network',
9
- }
10
-
11
- def self.verify_env_vars
12
- error = false
13
- REQUIRED_ENV.each do |var,message|
14
- unless ENV[var]
15
- puts "Must set #{var} #{message}" unless ENV[var]
16
- error = true
17
- end
18
- end
19
- Kernel.exit(2) if error
20
- end
21
-
22
2
  def self.fixture_path
23
3
  File.expand_path("../integration/edge_gateway/data", File.dirname(__FILE__))
24
4
  end
@@ -26,4 +6,12 @@ module IntegrationHelper
26
6
  def self.fixture_file(path)
27
7
  File.join(self.fixture_path, path)
28
8
  end
9
+
10
+ def self.remove_temp_config_files(files_to_delete)
11
+ files_to_delete.each { |f|
12
+ f.unlink
13
+ }
14
+ end
15
+
16
+
29
17
  end