1
// Copyright 2011, 2012, 2013 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
7
amzec2 "gopkg.in/amz.v3/ec2"
10
"github.com/juju/juju/constraints"
11
"github.com/juju/juju/environs"
12
"github.com/juju/juju/environs/simplestreams"
13
"github.com/juju/juju/instance"
14
"github.com/juju/juju/network"
15
"github.com/juju/juju/state"
18
// Ensure EC2 provider supports the expected interfaces,
20
_ environs.NetworkingEnviron = (*environ)(nil)
21
_ simplestreams.HasRegion = (*environ)(nil)
22
_ state.Prechecker = (*environ)(nil)
23
_ instance.Distributor = (*environ)(nil)
28
var _ = gc.Suite(&Suite{})
30
type RootDiskTest struct {
34
device amzec2.BlockDeviceMapping
37
var commonInstanceStoreDisks = []amzec2.BlockDeviceMapping{{
38
DeviceName: "/dev/sdb",
39
VirtualName: "ephemeral0",
41
DeviceName: "/dev/sdc",
42
VirtualName: "ephemeral1",
44
DeviceName: "/dev/sdd",
45
VirtualName: "ephemeral2",
47
DeviceName: "/dev/sde",
48
VirtualName: "ephemeral3",
51
func (*Suite) TestRootDiskBlockDeviceMapping(c *gc.C) {
52
var rootDiskTests = []RootDiskTest{{
54
"nil constraint ubuntu",
56
amzec2.BlockDeviceMapping{VolumeSize: 8, DeviceName: "/dev/sda1"},
59
"too small constraint ubuntu",
61
amzec2.BlockDeviceMapping{VolumeSize: 8, DeviceName: "/dev/sda1"},
64
"big constraint ubuntu",
66
amzec2.BlockDeviceMapping{VolumeSize: 20, DeviceName: "/dev/sda1"},
69
"round up constraint ubuntu",
71
amzec2.BlockDeviceMapping{VolumeSize: 21, DeviceName: "/dev/sda1"},
74
"nil constraint windows",
76
amzec2.BlockDeviceMapping{VolumeSize: 40, DeviceName: "/dev/sda1"},
79
"too small constraint windows",
81
amzec2.BlockDeviceMapping{VolumeSize: 40, DeviceName: "/dev/sda1"},
84
"big constraint windows",
86
amzec2.BlockDeviceMapping{VolumeSize: 50, DeviceName: "/dev/sda1"},
89
"round up constraint windows",
91
amzec2.BlockDeviceMapping{VolumeSize: 51, DeviceName: "/dev/sda1"},
94
for _, t := range rootDiskTests {
95
c.Logf("Test %s", t.name)
96
cons := constraints.Value{RootDisk: t.constraint}
97
mappings := getBlockDeviceMappings(cons, t.series)
98
expected := append([]amzec2.BlockDeviceMapping{t.device}, commonInstanceStoreDisks...)
99
c.Assert(mappings, gc.DeepEquals, expected)
103
func pInt(i uint64) *uint64 {
107
func (*Suite) TestPortsToIPPerms(c *gc.C) {
108
testCases := []struct {
110
ports []network.PortRange
111
expected []amzec2.IPPerm
113
about: "single port",
114
ports: []network.PortRange{{
119
expected: []amzec2.IPPerm{{
123
SourceIPs: []string{"0.0.0.0/0"},
126
about: "multiple ports",
127
ports: []network.PortRange{{
132
expected: []amzec2.IPPerm{{
136
SourceIPs: []string{"0.0.0.0/0"},
139
about: "multiple port ranges",
140
ports: []network.PortRange{{
149
expected: []amzec2.IPPerm{{
153
SourceIPs: []string{"0.0.0.0/0"},
158
SourceIPs: []string{"0.0.0.0/0"},
162
for i, t := range testCases {
163
c.Logf("test %d: %s", i, t.about)
164
ipperms := portsToIPPerms(t.ports)
165
c.Assert(ipperms, gc.DeepEquals, t.expected)