Merge lp:~gz/goamz/secgroups_on_instance into lp:goamz

Proposed by Martin Packman
Status: Merged
Merged at revision: 41
Proposed branch: lp:~gz/goamz/secgroups_on_instance
Merge into: lp:goamz
Diff against target: 120 lines (+33/-22)
4 files modified
ec2/ec2.go (+17/-16)
ec2/ec2_test.go (+3/-1)
ec2/ec2test/server.go (+7/-5)
ec2/responses_test.go (+6/-0)
To merge this branch: bzr merge lp:~gz/goamz/secgroups_on_instance
Reviewer Review Type Date Requested Status
goamz maintainers Pending
Review via email: mp+188906@code.launchpad.net

Description of the change

ec2: Support groups at instance and reservation

Per the 2011-12-15 wsdl description of the EC2 api, the
GroupSetType containing security group details appears
on both ReservationInfoType and RunningInstancesSetType
inside it.

This branch updates the code to parse the details at both
levels in a RunInstances or DescribeInstances response,
and updates the mock server to return the same details
at both levels.

Change is required as it seems the reservation group set
is empty, while the instance group set is not in some
circumstances.

https://codereview.appspot.com/14302043/

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :
Download full text (6.1 KiB)

Reviewers: mp+188906_code.launchpad.net,

Message:
Please take a look.

Description:
ec2: Support groups at instance and reservation

Per the 2011-12-15 wsdl description of the EC2 api, the
GroupSetType containing security group details appears
on both ReservationInfoType and RunningInstancesSetType
inside it.

This branch updates the code to parse the details at both
levels in a RunInstances or DescribeInstances response,
and updates the mock server to return the same details
at both levels.

Change is required as it seems the reservation group set
is empty, while the instance group set is not in some
circumstances.

https://code.launchpad.net/~gz/goamz/secgroups_on_instance/+merge/188906

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/14302043/

Affected files (+35, -22 lines):
   A [revision details]
   M ec2/ec2.go
   M ec2/ec2_test.go
   M ec2/ec2test/server.go
   M ec2/responses_test.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>

Index: ec2/ec2.go
=== modified file 'ec2/ec2.go'
--- ec2/ec2.go 2013-08-15 15:39:51 +0000
+++ ec2/ec2.go 2013-10-02 19:10:36 +0000
@@ -226,22 +226,23 @@
  //
  // See http://goo.gl/OCH8a for more details.
  type Instance struct {
- InstanceId string `xml:"instanceId"`
- InstanceType string `xml:"instanceType"`
- ImageId string `xml:"imageId"`
- PrivateDNSName string `xml:"privateDnsName"`
- DNSName string `xml:"dnsName"`
- IPAddress string `xml:"ipAddress"`
- PrivateIPAddress string `xml:"privateIpAddress"`
- KeyName string `xml:"keyName"`
- AMILaunchIndex int `xml:"amiLaunchIndex"`
- Hypervisor string `xml:"hypervisor"`
- VirtType string `xml:"virtualizationType"`
- Monitoring string `xml:"monitoring>state"`
- AvailZone string `xml:"placement>availabilityZone"`
- PlacementGroupName string `xml:"placement>groupName"`
- State InstanceState `xml:"instanceState"`
- Tags []Tag `xml:"tagSet>item"`
+ InstanceId string `xml:"instanceId"`
+ InstanceType string `xml:"instanceType"`
+ ImageId string `xml:"imageId"`
+ PrivateDNSName string `xml:"privateDnsName"`
+ DNSName string `xml:"dnsName"`
+ IPAddress string `xml:"ipAddress"`
+ PrivateIPAddress string `xml:"privateIpAddress"`
+ KeyName string `xml:"keyName"`
+ AMILaunchIndex int `xml:"amiLaunchIndex"`
+ Hypervisor string `xml:"hypervisor"`
+ VirtType string `xml:"virtualizationType"`
+ Monitoring string `xml:"monitoring>state"`
+ AvailZone string `xml:"placement>availabilityZone"`
...

Read more...

Revision history for this message
Roger Peppe (rogpeppe) wrote :

On 2013/10/02 19:18:08, gz wrote:
> Please take a look.

LGTM but perhaps a test in ec2i_test.go might be appropriate too?

https://codereview.appspot.com/14302043/

Revision history for this message
Martin Packman (gz) wrote :

On 2013/10/02 19:59:34, rog wrote:

> LGTM but perhaps a test in ec2i_test.go might be appropriate too?

There doesn't seem to be a suitable existing test there,
TestRunAndTerminate doesn't give the instance a security group, and
TestSecurityGroups doesn't run an instance. I'm somewhat loath to add a
new test in that style, especially as we have some coverage via the
juju-core live tests.

https://codereview.appspot.com/14302043/

Revision history for this message
Martin Packman (gz) wrote :

*** Submitted:

ec2: Support groups at instance and reservation

Per the 2011-12-15 wsdl description of the EC2 api, the
GroupSetType containing security group details appears
on both ReservationInfoType and RunningInstancesSetType
inside it.

This branch updates the code to parse the details at both
levels in a RunInstances or DescribeInstances response,
and updates the mock server to return the same details
at both levels.

Change is required as it seems the reservation group set
is empty, while the instance group set is not in some
circumstances.

R=rog
CC=
https://codereview.appspot.com/14302043

https://codereview.appspot.com/14302043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ec2/ec2.go'
2--- ec2/ec2.go 2013-08-15 15:39:51 +0000
3+++ ec2/ec2.go 2013-10-02 19:18:28 +0000
4@@ -226,22 +226,23 @@
5 //
6 // See http://goo.gl/OCH8a for more details.
7 type Instance struct {
8- InstanceId string `xml:"instanceId"`
9- InstanceType string `xml:"instanceType"`
10- ImageId string `xml:"imageId"`
11- PrivateDNSName string `xml:"privateDnsName"`
12- DNSName string `xml:"dnsName"`
13- IPAddress string `xml:"ipAddress"`
14- PrivateIPAddress string `xml:"privateIpAddress"`
15- KeyName string `xml:"keyName"`
16- AMILaunchIndex int `xml:"amiLaunchIndex"`
17- Hypervisor string `xml:"hypervisor"`
18- VirtType string `xml:"virtualizationType"`
19- Monitoring string `xml:"monitoring>state"`
20- AvailZone string `xml:"placement>availabilityZone"`
21- PlacementGroupName string `xml:"placement>groupName"`
22- State InstanceState `xml:"instanceState"`
23- Tags []Tag `xml:"tagSet>item"`
24+ InstanceId string `xml:"instanceId"`
25+ InstanceType string `xml:"instanceType"`
26+ ImageId string `xml:"imageId"`
27+ PrivateDNSName string `xml:"privateDnsName"`
28+ DNSName string `xml:"dnsName"`
29+ IPAddress string `xml:"ipAddress"`
30+ PrivateIPAddress string `xml:"privateIpAddress"`
31+ KeyName string `xml:"keyName"`
32+ AMILaunchIndex int `xml:"amiLaunchIndex"`
33+ Hypervisor string `xml:"hypervisor"`
34+ VirtType string `xml:"virtualizationType"`
35+ Monitoring string `xml:"monitoring>state"`
36+ AvailZone string `xml:"placement>availabilityZone"`
37+ PlacementGroupName string `xml:"placement>groupName"`
38+ State InstanceState `xml:"instanceState"`
39+ Tags []Tag `xml:"tagSet>item"`
40+ SecurityGroups []SecurityGroup `xml:"groupSet>item"`
41 }
42
43 // RunInstances starts new instances in EC2.
44
45=== modified file 'ec2/ec2_test.go'
46--- ec2/ec2_test.go 2013-08-15 15:39:51 +0000
47+++ ec2/ec2_test.go 2013-10-02 19:18:28 +0000
48@@ -207,11 +207,12 @@
49 c.Assert(resp.RequestId, Equals, "98e3c9a4-848c-4d6d-8e8a-b1bdEXAMPLE")
50 c.Assert(resp.Reservations, HasLen, 2)
51
52+ expectedGroups := []ec2.SecurityGroup{{Name: "default", Id: "sg-67ad940e"}}
53 r0 := resp.Reservations[0]
54 c.Assert(r0.ReservationId, Equals, "r-b27e30d9")
55 c.Assert(r0.OwnerId, Equals, "999988887777")
56 c.Assert(r0.RequesterId, Equals, "854251627541")
57- c.Assert(r0.SecurityGroups, DeepEquals, []ec2.SecurityGroup{{Name: "default", Id: "sg-67ad940e"}})
58+ c.Assert(r0.SecurityGroups, DeepEquals, expectedGroups)
59 c.Assert(r0.Instances, HasLen, 1)
60
61 r0i := r0.Instances[0]
62@@ -221,6 +222,7 @@
63 c.Assert(r0i.PrivateIPAddress, Equals, "10.198.85.190")
64 c.Assert(r0i.IPAddress, Equals, "174.129.165.232")
65 c.Assert(r0i.AvailZone, Equals, "us-east-1b")
66+ c.Assert(r0i.SecurityGroups, DeepEquals, expectedGroups)
67 }
68
69 func (s *S) TestDescribeInstancesExample2(c *C) {
70
71=== modified file 'ec2/ec2test/server.go'
72--- ec2/ec2test/server.go 2013-08-15 16:29:50 +0000
73+++ ec2/ec2test/server.go 2013-10-02 19:18:28 +0000
74@@ -664,22 +664,24 @@
75 resp.RequestId = reqId
76 for _, r := range srv.reservations {
77 var instances []ec2.Instance
78+ var groups []ec2.SecurityGroup
79+ for _, g := range r.groups {
80+ groups = append(groups, g.ec2SecurityGroup())
81+ }
82 for _, inst := range r.instances {
83 if len(insts) > 0 && !insts[inst] {
84 continue
85 }
86 ok, err := f.ok(inst)
87 if ok {
88- instances = append(instances, inst.ec2instance())
89+ instance := inst.ec2instance()
90+ instance.SecurityGroups = groups
91+ instances = append(instances, instance)
92 } else if err != nil {
93 fatalf(400, "InvalidParameterValue", "describe instances: %v", err)
94 }
95 }
96 if len(instances) > 0 {
97- var groups []ec2.SecurityGroup
98- for _, g := range r.groups {
99- groups = append(groups, g.ec2SecurityGroup())
100- }
101 resp.Reservations = append(resp.Reservations, ec2.Reservation{
102 ReservationId: r.id,
103 OwnerId: ownerId,
104
105=== modified file 'ec2/responses_test.go'
106--- ec2/responses_test.go 2012-10-17 22:47:42 +0000
107+++ ec2/responses_test.go 2013-10-02 19:18:28 +0000
108@@ -177,6 +177,12 @@
109 <clientToken/>
110 <tagSet/>
111 <hypervisor>xen</hypervisor>
112+ <groupSet>
113+ <item>
114+ <groupId>sg-67ad940e</groupId>
115+ <groupName>default</groupName>
116+ </item>
117+ </groupSet>
118 </item>
119 </instancesSet>
120 <requesterId>854251627541</requesterId>

Subscribers

People subscribed via source and target branches