21
22
"gopkg.in/mgo.v2/bson"
22
23
"gopkg.in/mgo.v2/txn"
24
"github.com/juju/juju/core/description"
25
25
"github.com/juju/juju/core/lease"
26
26
"github.com/juju/juju/mongo"
27
"github.com/juju/juju/mongo/utils"
27
28
"github.com/juju/juju/network"
29
"github.com/juju/juju/permission"
30
"github.com/juju/juju/status"
28
31
"github.com/juju/juju/testcharms"
29
32
"github.com/juju/juju/version"
49
52
ControllerAvailable = &controllerAvailable
50
53
GetOrCreatePorts = getOrCreatePorts
51
54
GetPorts = getPorts
52
NowToTheSecond = nowToTheSecond
53
55
AddVolumeOps = (*State).addVolumeOps
54
56
CombineMeterStatus = combineMeterStatus
55
57
ApplicationGlobalKey = applicationGlobalKey
457
459
var ActionNotificationIdToActionId = actionNotificationIdToActionId
459
func UpdateModelUserLastConnection(st *State, e description.UserAccess, when time.Time) error {
461
func UpdateModelUserLastConnection(st *State, e permission.UserAccess, when time.Time) error {
460
462
return st.updateLastModelConnection(e.UserTag, when)
509
511
err := st.runTransaction(ops)
510
512
c.Assert(err, jc.ErrorIsNil)
515
// PrimeUnitStatusHistory will add count history elements, advancing the test clock by
516
// one second for each entry.
517
func PrimeUnitStatusHistory(
518
c *gc.C, clock *testing.Clock,
519
unit *Unit, statusVal status.Status,
520
count, batchSize int,
521
nextData func(int) map[string]interface{},
523
globalKey := unit.globalKey()
525
history, closer := unit.st.getCollection(statusesHistoryC)
527
historyW := history.Writeable()
529
var data map[string]interface{}
530
for i := 0; i < count; {
531
var docs []interface{}
532
for j := 0; j < batchSize && i < count; j++ {
533
clock.Advance(time.Second)
535
data = utils.EscapeKeys(nextData(i))
537
docs = append(docs, &historicalStatusDoc{
540
Updated: clock.Now().UnixNano(),
541
GlobalKey: globalKey,
543
// Seems like you can't increment two values in one loop
546
err := historyW.Insert(docs...)
547
c.Assert(err, jc.ErrorIsNil)
549
// Set the status for the unit itself.
553
Updated: clock.Now().UnixNano(),
555
buildTxn := updateStatusSource(unit.st, globalKey, doc)
556
err := unit.st.run(buildTxn)
557
c.Assert(err, jc.ErrorIsNil)