1
// Copyright 2013 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
4
package firewaller_test
7
jc "github.com/juju/testing/checkers"
8
"github.com/juju/utils"
11
"github.com/juju/juju/api"
12
"github.com/juju/juju/api/firewaller"
13
"github.com/juju/juju/juju/testing"
14
"github.com/juju/juju/state"
17
// NOTE: This suite is intended for embedding into other suites,
18
// so common code can be reused. Do not add test cases to it,
19
// otherwise they'll be run by each other suite that embeds it.
20
type firewallerSuite struct {
24
machines []*state.Machine
25
application *state.Application
29
firewaller *firewaller.State
32
var _ = gc.Suite(&firewallerSuite{})
34
func (s *firewallerSuite) SetUpTest(c *gc.C) {
35
s.JujuConnSuite.SetUpTest(c)
37
// Reset previous machines and units (if any) and create 3
38
// machines for the tests. The first one is a manager node.
39
s.machines = make([]*state.Machine, 3)
40
s.units = make([]*state.Unit, 3)
43
s.machines[0], err = s.State.AddMachine("quantal", state.JobManageModel, state.JobHostUnits)
44
c.Assert(err, jc.ErrorIsNil)
45
password, err := utils.RandomPassword()
46
c.Assert(err, jc.ErrorIsNil)
47
err = s.machines[0].SetPassword(password)
48
c.Assert(err, jc.ErrorIsNil)
49
err = s.machines[0].SetProvisioned("i-manager", "fake_nonce", nil)
50
c.Assert(err, jc.ErrorIsNil)
51
s.st = s.OpenAPIAsMachine(c, s.machines[0].Tag(), password, "fake_nonce")
52
c.Assert(s.st, gc.NotNil)
54
// Note that the specific machine ids allocated are assumed
55
// to be numerically consecutive from zero.
56
for i := 1; i <= 2; i++ {
57
s.machines[i], err = s.State.AddMachine("quantal", state.JobHostUnits)
58
c.Check(err, jc.ErrorIsNil)
60
// Create a service and three units for these machines.
61
s.charm = s.AddTestingCharm(c, "wordpress")
62
s.application = s.AddTestingService(c, "wordpress", s.charm)
63
// Add the rest of the units and assign them.
64
for i := 0; i <= 2; i++ {
65
s.units[i], err = s.application.AddUnit()
66
c.Check(err, jc.ErrorIsNil)
67
err = s.units[i].AssignToMachine(s.machines[i])
68
c.Check(err, jc.ErrorIsNil)
71
// Create the firewaller API facade.
72
s.firewaller = firewaller.NewState(s.st)
73
c.Assert(s.firewaller, gc.NotNil)