1
// Copyright 2013 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
4
package firewaller_test
9
gc "launchpad.net/gocheck"
11
"launchpad.net/juju-core/juju/testing"
12
"launchpad.net/juju-core/state"
13
"launchpad.net/juju-core/state/api"
14
"launchpad.net/juju-core/state/api/firewaller"
15
coretesting "launchpad.net/juju-core/testing"
16
"launchpad.net/juju-core/utils"
19
// NOTE: This suite is intended for embedding into other suites,
20
// so common code can be reused. Do not add test cases to it,
21
// otherwise they'll be run by each other suite that embeds it.
22
type firewallerSuite struct {
26
machines []*state.Machine
27
service *state.Service
31
firewaller *firewaller.State
34
var _ = gc.Suite(&firewallerSuite{})
36
func TestAll(t *stdtesting.T) {
37
coretesting.MgoTestPackage(t)
40
func (s *firewallerSuite) SetUpTest(c *gc.C) {
41
s.JujuConnSuite.SetUpTest(c)
43
// Reset previous machines and units (if any) and create 3
44
// machines for the tests. The first one is a manager node.
45
s.machines = make([]*state.Machine, 3)
46
s.units = make([]*state.Unit, 3)
49
s.machines[0], err = s.State.AddMachine("quantal", state.JobManageEnviron, state.JobHostUnits)
50
c.Assert(err, gc.IsNil)
51
password, err := utils.RandomPassword()
52
c.Assert(err, gc.IsNil)
53
err = s.machines[0].SetPassword(password)
54
c.Assert(err, gc.IsNil)
55
err = s.machines[0].SetProvisioned("i-manager", "fake_nonce", nil)
56
c.Assert(err, gc.IsNil)
57
s.st = s.OpenAPIAsMachine(c, s.machines[0].Tag(), password, "fake_nonce")
58
c.Assert(s.st, gc.NotNil)
60
// Note that the specific machine ids allocated are assumed
61
// to be numerically consecutive from zero.
62
for i := 1; i <= 2; i++ {
63
s.machines[i], err = s.State.AddMachine("quantal", state.JobHostUnits)
64
c.Check(err, gc.IsNil)
66
// Create a service and three units for these machines.
67
s.charm = s.AddTestingCharm(c, "wordpress")
68
s.service = s.AddTestingService(c, "wordpress", s.charm)
69
// Add the rest of the units and assign them.
70
for i := 0; i <= 2; i++ {
71
s.units[i], err = s.service.AddUnit()
72
c.Check(err, gc.IsNil)
73
err = s.units[i].AssignToMachine(s.machines[i])
74
c.Check(err, gc.IsNil)
77
// Create the firewaller API facade.
78
s.firewaller = s.st.Firewaller()
79
c.Assert(s.firewaller, gc.NotNil)