Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Side by Side Diff: environs/jujutest/livetests.go

Issue 6589073: ec2: integrated firewall mode configuration (Closed)
Patch Set: ec2: integrated firewall mode configuration Created 12 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « environs/ec2/ec2.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package jujutest 1 package jujutest
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 . "launchpad.net/gocheck" 5 . "launchpad.net/gocheck"
6 "launchpad.net/juju-core/charm" 6 "launchpad.net/juju-core/charm"
7 "launchpad.net/juju-core/environs" 7 "launchpad.net/juju-core/environs"
8 "launchpad.net/juju-core/environs/config" 8 "launchpad.net/juju-core/environs/config"
9 "launchpad.net/juju-core/juju" 9 "launchpad.net/juju-core/juju"
10 "launchpad.net/juju-core/state" 10 "launchpad.net/juju-core/state"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 63 }
64 c.Assert(err, Equals, environs.ErrNoInstances) 64 c.Assert(err, Equals, environs.ErrNoInstances)
65 c.Assert(insts, HasLen, 0) 65 c.Assert(insts, HasLen, 0)
66 } 66 }
67 67
68 func (t *LiveTests) TestPorts(c *C) { 68 func (t *LiveTests) TestPorts(c *C) {
69 inst1, err := t.Env.StartInstance(1, InvalidStateInfo, nil) 69 inst1, err := t.Env.StartInstance(1, InvalidStateInfo, nil)
70 c.Assert(err, IsNil) 70 c.Assert(err, IsNil)
71 c.Assert(inst1, NotNil) 71 c.Assert(inst1, NotNil)
72 defer t.Env.StopInstances([]environs.Instance{inst1}) 72 defer t.Env.StopInstances([]environs.Instance{inst1})
73
74 ports, err := inst1.Ports(1) 73 ports, err := inst1.Ports(1)
75 c.Assert(err, IsNil) 74 c.Assert(err, IsNil)
76 c.Assert(ports, HasLen, 0) 75 c.Assert(ports, HasLen, 0)
77 76
78 inst2, err := t.Env.StartInstance(2, InvalidStateInfo, nil) 77 inst2, err := t.Env.StartInstance(2, InvalidStateInfo, nil)
79 c.Assert(err, IsNil) 78 c.Assert(err, IsNil)
80 c.Assert(inst2, NotNil) 79 c.Assert(inst2, NotNil)
81 ports, err = inst2.Ports(2) 80 ports, err = inst2.Ports(2)
82 c.Assert(err, IsNil) 81 c.Assert(err, IsNil)
83 c.Assert(ports, HasLen, 0) 82 c.Assert(ports, HasLen, 0)
84 defer t.Env.StopInstances([]environs.Instance{inst2}) 83 defer t.Env.StopInstances([]environs.Instance{inst2})
85 84
86 // Open some ports and check they're there. 85 // Open some ports and check they're there.
87 err = inst1.OpenPorts(1, []state.Port{{"udp", 67}, {"tcp", 45}}) 86 err = inst1.OpenPorts(1, []state.Port{{"udp", 67}, {"tcp", 45}})
88 c.Assert(err, IsNil) 87 c.Assert(err, IsNil)
89 ports, err = inst1.Ports(1) 88 ports, err = inst1.Ports(1)
90 c.Assert(err, IsNil) 89 c.Assert(err, IsNil)
91 c.Assert(ports, DeepEquals, []state.Port{{"tcp", 45}, {"udp", 67}}) 90 c.Assert(ports, DeepEquals, []state.Port{{"tcp", 45}, {"udp", 67}})
92 ports, err = inst2.Ports(2) 91 ports, err = inst2.Ports(2)
93 c.Assert(err, IsNil) 92 c.Assert(err, IsNil)
94 c.Assert(ports, HasLen, 0) 93 c.Assert(ports, HasLen, 0)
95 94
96 // Check there's no crosstalk to another machine
97 err = inst2.OpenPorts(2, []state.Port{{"tcp", 89}, {"tcp", 45}}) 95 err = inst2.OpenPorts(2, []state.Port{{"tcp", 89}, {"tcp", 45}})
98 c.Assert(err, IsNil) 96 c.Assert(err, IsNil)
97
98 // Check there's no crosstalk to another machine
99 ports, err = inst2.Ports(2) 99 ports, err = inst2.Ports(2)
100 c.Assert(err, IsNil) 100 c.Assert(err, IsNil)
101 c.Assert(ports, DeepEquals, []state.Port{{"tcp", 45}, {"tcp", 89}}) 101 c.Assert(ports, DeepEquals, []state.Port{{"tcp", 45}, {"tcp", 89}})
102 ports, err = inst1.Ports(1) 102 ports, err = inst1.Ports(1)
103 c.Assert(err, IsNil) 103 c.Assert(err, IsNil)
104 c.Assert(ports, DeepEquals, []state.Port{{"tcp", 45}, {"udp", 67}}) 104 c.Assert(ports, DeepEquals, []state.Port{{"tcp", 45}, {"udp", 67}})
105 105
106 // Check that opening the same port again is ok. 106 // Check that opening the same port again is ok.
107 oldPorts, err := inst2.Ports(2)
108 c.Assert(err, IsNil)
107 err = inst2.OpenPorts(2, []state.Port{{"tcp", 45}}) 109 err = inst2.OpenPorts(2, []state.Port{{"tcp", 45}})
108 c.Assert(err, IsNil) 110 c.Assert(err, IsNil)
109 ports, err = inst2.Ports(2) 111 ports, err = inst2.Ports(2)
110 c.Assert(err, IsNil) 112 c.Assert(err, IsNil)
111 » c.Assert(ports, DeepEquals, []state.Port{{"tcp", 45}, {"tcp", 89}}) 113 » c.Assert(ports, DeepEquals, oldPorts)
112 114
113 // Check that opening the same port again and another port is ok. 115 // Check that opening the same port again and another port is ok.
114 err = inst2.OpenPorts(2, []state.Port{{"tcp", 45}, {"tcp", 99}}) 116 err = inst2.OpenPorts(2, []state.Port{{"tcp", 45}, {"tcp", 99}})
115 c.Assert(err, IsNil) 117 c.Assert(err, IsNil)
116 ports, err = inst2.Ports(2) 118 ports, err = inst2.Ports(2)
117 c.Assert(err, IsNil) 119 c.Assert(err, IsNil)
118 c.Assert(ports, DeepEquals, []state.Port{{"tcp", 45}, {"tcp", 89}, {"tcp ", 99}}) 120 c.Assert(ports, DeepEquals, []state.Port{{"tcp", 45}, {"tcp", 89}, {"tcp ", 99}})
119 121
120 // Check that we can close ports and that there's no crosstalk.
121 err = inst2.ClosePorts(2, []state.Port{{"tcp", 45}, {"tcp", 99}}) 122 err = inst2.ClosePorts(2, []state.Port{{"tcp", 45}, {"tcp", 99}})
122 c.Assert(err, IsNil) 123 c.Assert(err, IsNil)
124
125 // Check that we can close ports and that there's no crosstalk.
123 ports, err = inst2.Ports(2) 126 ports, err = inst2.Ports(2)
124 c.Assert(err, IsNil) 127 c.Assert(err, IsNil)
125 c.Assert(ports, DeepEquals, []state.Port{{"tcp", 89}}) 128 c.Assert(ports, DeepEquals, []state.Port{{"tcp", 89}})
126 ports, err = inst1.Ports(1) 129 ports, err = inst1.Ports(1)
127 c.Assert(err, IsNil) 130 c.Assert(err, IsNil)
128 c.Assert(ports, DeepEquals, []state.Port{{"tcp", 45}, {"udp", 67}}) 131 c.Assert(ports, DeepEquals, []state.Port{{"tcp", 45}, {"udp", 67}})
129 132
130 // Check that we can close multiple ports. 133 // Check that we can close multiple ports.
131 err = inst1.ClosePorts(1, []state.Port{{"tcp", 45}, {"udp", 67}}) 134 err = inst1.ClosePorts(1, []state.Port{{"tcp", 45}, {"udp", 67}})
132 c.Assert(err, IsNil) 135 c.Assert(err, IsNil)
133 ports, err = inst1.Ports(1) 136 ports, err = inst1.Ports(1)
134 c.Assert(ports, HasLen, 0) 137 c.Assert(ports, HasLen, 0)
135 138
136 // Check that we can close ports that aren't there. 139 // Check that we can close ports that aren't there.
137 err = inst2.ClosePorts(2, []state.Port{{"tcp", 111}, {"udp", 222}}) 140 err = inst2.ClosePorts(2, []state.Port{{"tcp", 111}, {"udp", 222}})
138 c.Assert(err, IsNil) 141 c.Assert(err, IsNil)
139 ports, err = inst2.Ports(2) 142 ports, err = inst2.Ports(2)
140 c.Assert(ports, DeepEquals, []state.Port{{"tcp", 89}}) 143 c.Assert(ports, DeepEquals, []state.Port{{"tcp", 89}})
141 } 144 }
142 145
146 func (t *LiveTests) TestGlobalPorts(c *C) {
147 // Change configuration.
148 oldConfig := t.Env.Config()
149 defer func() {
150 err := t.Env.SetConfig(oldConfig)
151 c.Assert(err, IsNil)
152 }()
153
154 attrs := t.Env.Config().AllAttrs()
155 attrs["firewall-mode"] = "global"
156 newConfig, err := t.Env.Config().Apply(attrs)
157 c.Assert(err, IsNil)
158 err = t.Env.SetConfig(newConfig)
159 c.Assert(err, IsNil)
160
161 // Create instances and check open ports on both instances.
162 inst1, err := t.Env.StartInstance(1, InvalidStateInfo, nil)
163 c.Assert(err, IsNil)
164 defer t.Env.StopInstances([]environs.Instance{inst1})
165 ports, err := inst1.Ports(1)
166 c.Assert(err, IsNil)
167 c.Assert(ports, HasLen, 0)
168
169 inst2, err := t.Env.StartInstance(2, InvalidStateInfo, nil)
170 c.Assert(err, IsNil)
171 ports, err = inst2.Ports(2)
172 c.Assert(err, IsNil)
173 c.Assert(ports, HasLen, 0)
174 defer t.Env.StopInstances([]environs.Instance{inst2})
175
176 err = inst1.OpenPorts(1, []state.Port{{"udp", 67}, {"tcp", 45}})
177 c.Assert(err, IsNil)
178 err = inst2.OpenPorts(2, []state.Port{{"tcp", 89}, {"tcp", 99}})
179 c.Assert(err, IsNil)
180
181 ports1, err := inst1.Ports(1)
182 c.Assert(err, IsNil)
183 c.Assert(ports1, HasLen, 4)
184 ports2, err := inst2.Ports(2)
185 c.Assert(err, IsNil)
186 c.Assert(ports1, HasLen, 4)
187 c.Assert(ports1, DeepEquals, ports2)
188
189 // Check that closing ports on one instance effect on both.
190 err = inst1.ClosePorts(1, []state.Port{{"tcp", 99}, {"udp", 67}})
191 c.Assert(err, IsNil)
192
193 ports1, err = inst1.Ports(1)
194 c.Assert(err, IsNil)
195 c.Assert(ports1, HasLen, 2)
196 ports2, err = inst2.Ports(2)
197 c.Assert(err, IsNil)
198 c.Assert(ports1, HasLen, 2)
199 c.Assert(ports1, DeepEquals, ports2)
200
201 // Check that we can close ports that aren't there.
202 err = inst1.ClosePorts(1, []state.Port{{"tcp", 111}, {"udp", 222}})
203 c.Assert(err, IsNil)
204
205 ports1, err = inst1.Ports(1)
206 c.Assert(err, IsNil)
207 c.Assert(ports1, HasLen, 2)
208 ports2, err = inst2.Ports(2)
209 c.Assert(err, IsNil)
210 c.Assert(ports1, HasLen, 2)
211 c.Assert(ports1, DeepEquals, ports2)
212 }
213
143 func (t *LiveTests) TestBootstrapMultiple(c *C) { 214 func (t *LiveTests) TestBootstrapMultiple(c *C) {
144 t.BootstrapOnce(c) 215 t.BootstrapOnce(c)
145 216
146 // Wait for a while to let eventual consistency catch up, hopefully. 217 // Wait for a while to let eventual consistency catch up, hopefully.
147 time.Sleep(t.ConsistencyDelay) 218 time.Sleep(t.ConsistencyDelay)
148 err := t.Env.Bootstrap(false) 219 err := t.Env.Bootstrap(false)
149 c.Assert(err, ErrorMatches, "environment is already bootstrapped") 220 c.Assert(err, ErrorMatches, "environment is already bootstrapped")
150 221
151 c.Logf("destroy env") 222 c.Logf("destroy env")
152 t.Destroy(c) 223 t.Destroy(c)
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 573 }
503 574
504 inst, err := t.Env.StartInstance(4, InvalidStateInfo, tools) 575 inst, err := t.Env.StartInstance(4, InvalidStateInfo, tools)
505 if inst != nil { 576 if inst != nil {
506 err := t.Env.StopInstances([]environs.Instance{inst}) 577 err := t.Env.StopInstances([]environs.Instance{inst})
507 c.Check(err, IsNil) 578 c.Check(err, IsNil)
508 } 579 }
509 c.Assert(inst, IsNil) 580 c.Assert(inst, IsNil)
510 c.Assert(err, ErrorMatches, "cannot find image.*") 581 c.Assert(err, ErrorMatches, "cannot find image.*")
511 } 582 }
OLDNEW
« no previous file with comments | « environs/ec2/ec2.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b