~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/apiserver/modelmanager/modelinfo_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
        "github.com/juju/juju/environs"
26
26
        "github.com/juju/juju/environs/config"
27
27
        "github.com/juju/juju/instance"
 
28
        "github.com/juju/juju/permission"
28
29
        "github.com/juju/juju/state"
29
30
        "github.com/juju/juju/status"
30
31
        coretesting "github.com/juju/juju/testing"
75
76
                life:  state.Alive,
76
77
                cfg:   coretesting.ModelConfig(c),
77
78
                status: status.StatusInfo{
78
 
                        Status: status.StatusAvailable,
 
79
                        Status: status.Available,
79
80
                        Since:  &time.Time{},
80
81
                },
81
82
                users: []*mockModelUser{{
82
83
                        userName: "admin",
83
 
                        access:   description.AdminAccess,
 
84
                        access:   permission.AdminAccess,
84
85
                }, {
85
86
                        userName: "otheruser",
86
 
                        access:   description.AdminAccess,
 
87
                        access:   permission.AdminAccess,
87
88
                }},
88
89
        }
89
90
 
92
93
                cfg:   coretesting.ModelConfig(c),
93
94
                life:  state.Dying,
94
95
                status: status.StatusInfo{
95
 
                        Status: status.StatusDestroying,
 
96
                        Status: status.Destroying,
96
97
                        Since:  &time.Time{},
97
98
                },
98
99
 
99
100
                users: []*mockModelUser{{
100
101
                        userName: "admin",
101
 
                        access:   description.AdminAccess,
 
102
                        access:   permission.AdminAccess,
102
103
                }, {
103
104
                        userName:    "bob@local",
104
105
                        displayName: "Bob",
105
 
                        access:      description.ReadAccess,
 
106
                        access:      permission.ReadAccess,
106
107
                }, {
107
108
                        userName:    "charlotte@local",
108
109
                        displayName: "Charlotte",
109
 
                        access:      description.ReadAccess,
 
110
                        access:      permission.ReadAccess,
110
111
                }, {
111
112
                        userName:    "mary@local",
112
113
                        displayName: "Mary",
113
 
                        access:      description.WriteAccess,
 
114
                        access:      permission.WriteAccess,
114
115
                }},
115
116
        }
116
117
        s.st.machines = []common.Machine{
151
152
                ControllerUUID:     "deadbeef-1bad-500d-9000-4b1d0d06f00d",
152
153
                OwnerTag:           "user-bob@local",
153
154
                ProviderType:       "someprovider",
154
 
                Cloud:              "some-cloud",
 
155
                CloudTag:           "cloud-some-cloud",
155
156
                CloudRegion:        "some-region",
156
157
                CloudCredentialTag: "cloudcred-some-cloud_bob@local_some-credential",
157
158
                DefaultSeries:      series.LatestLts(),
158
159
                Life:               params.Dying,
159
160
                Status: params.EntityStatus{
160
 
                        Status: status.StatusDestroying,
 
161
                        Status: status.Destroying,
161
162
                        Since:  &time.Time{},
162
163
                },
163
164
                Users: []params.ModelUserInfo{{
313
314
        clouds          map[names.CloudTag]cloud.Cloud
314
315
        model           *mockModel
315
316
        controllerModel *mockModel
316
 
        users           []description.UserAccess
 
317
        users           []permission.UserAccess
317
318
        cred            cloud.Credential
318
319
        machines        []common.Machine
319
320
        cfgDefaults     config.ModelDefaultAttributes
351
352
        }
352
353
 
353
354
        for _, u := range st.controllerModel.users {
354
 
                if user.Name() == u.userName && u.access == description.AdminAccess {
 
355
                if user.Name() == u.userName && u.access == permission.AdminAccess {
355
356
                        nextErr := st.NextErr()
356
357
                        if user.Name() != "admin" {
357
358
                                panic(user.Name())
450
451
        return st.NextErr()
451
452
}
452
453
 
453
 
func (st *mockState) AddModelUser(modelUUID string, spec state.UserAccessSpec) (description.UserAccess, error) {
 
454
func (st *mockState) AddModelUser(modelUUID string, spec state.UserAccessSpec) (permission.UserAccess, error) {
454
455
        st.MethodCall(st, "AddModelUser", modelUUID, spec)
455
 
        return description.UserAccess{}, st.NextErr()
 
456
        return permission.UserAccess{}, st.NextErr()
456
457
}
457
458
 
458
 
func (st *mockState) AddControllerUser(spec state.UserAccessSpec) (description.UserAccess, error) {
 
459
func (st *mockState) AddControllerUser(spec state.UserAccessSpec) (permission.UserAccess, error) {
459
460
        st.MethodCall(st, "AddControllerUser", spec)
460
 
        return description.UserAccess{}, st.NextErr()
 
461
        return permission.UserAccess{}, st.NextErr()
461
462
}
462
463
 
463
464
func (st *mockState) RemoveModelUser(tag names.UserTag) error {
465
466
        return st.NextErr()
466
467
}
467
468
 
468
 
func (st *mockState) UserAccess(tag names.UserTag, target names.Tag) (description.UserAccess, error) {
 
469
func (st *mockState) UserAccess(tag names.UserTag, target names.Tag) (permission.UserAccess, error) {
469
470
        st.MethodCall(st, "ModelUser", tag, target)
470
 
        return description.UserAccess{}, st.NextErr()
 
471
        return permission.UserAccess{}, st.NextErr()
471
472
}
472
473
 
473
474
func (st *mockState) LastModelConnection(user names.UserTag) (time.Time, error) {
480
481
        return st.NextErr()
481
482
}
482
483
 
483
 
func (st *mockState) SetUserAccess(subject names.UserTag, target names.Tag, access description.Access) (description.UserAccess, error) {
 
484
func (st *mockState) SetUserAccess(subject names.UserTag, target names.Tag, access permission.Access) (permission.UserAccess, error) {
484
485
        st.MethodCall(st, "SetUserAccess", subject, target, access)
485
 
        return description.UserAccess{}, st.NextErr()
 
486
        return permission.UserAccess{}, st.NextErr()
486
487
}
487
488
 
488
489
func (st *mockState) ModelConfigDefaultValues() (config.ModelDefaultAttributes, error) {
490
491
        return st.cfgDefaults, nil
491
492
}
492
493
 
493
 
func (st *mockState) UpdateModelConfigDefaultValues(update map[string]interface{}, remove []string) error {
494
 
        st.MethodCall(st, "UpdateModelConfigDefaultValues", update, remove)
 
494
func (st *mockState) UpdateModelConfigDefaultValues(update map[string]interface{}, remove []string, rspec *environs.RegionSpec) error {
 
495
        st.MethodCall(st, "UpdateModelConfigDefaultValues", update, remove, rspec)
495
496
        for k, v := range update {
496
 
                st.cfgDefaults[k] = config.AttributeDefaultValues{Controller: v}
 
497
                if rspec != nil {
 
498
                        adv := st.cfgDefaults[k]
 
499
                        adv.Regions = append(adv.Regions, config.RegionDefaultValue{
 
500
                                Name:  rspec.Region,
 
501
                                Value: v})
 
502
 
 
503
                } else {
 
504
                        st.cfgDefaults[k] = config.AttributeDefaultValues{Controller: v}
 
505
                }
497
506
        }
498
507
        for _, n := range remove {
499
 
                delete(st.cfgDefaults, n)
 
508
                if rspec != nil {
 
509
                        for i, r := range st.cfgDefaults[n].Regions {
 
510
                                if r.Name == rspec.Region {
 
511
                                        adv := st.cfgDefaults[n]
 
512
                                        adv.Regions = append(adv.Regions[:i], adv.Regions[i+1:]...)
 
513
                                        st.cfgDefaults[n] = adv
 
514
                                }
 
515
                        }
 
516
                } else {
 
517
                        if len(st.cfgDefaults[n].Regions) == 0 {
 
518
                                delete(st.cfgDefaults, n)
 
519
                        } else {
 
520
 
 
521
                                st.cfgDefaults[n] = config.AttributeDefaultValues{
 
522
                                        Regions: st.cfgDefaults[n].Regions}
 
523
                        }
 
524
                }
500
525
        }
501
526
        return nil
502
527
}
557
582
        return m.hw, nil
558
583
}
559
584
 
 
585
func (m *mockMachine) AgentPresence() (bool, error) {
 
586
        return true, nil
 
587
}
 
588
 
560
589
func (m *mockMachine) InstanceId() (instance.Id, error) {
561
590
        return "", nil
562
591
}
629
658
        return names.NewCloudCredentialTag("some-cloud/bob@local/some-credential"), true
630
659
}
631
660
 
632
 
func (m *mockModel) Users() ([]description.UserAccess, error) {
 
661
func (m *mockModel) Users() ([]permission.UserAccess, error) {
633
662
        m.MethodCall(m, "Users")
634
663
        if err := m.NextErr(); err != nil {
635
664
                return nil, err
636
665
        }
637
 
        users := make([]description.UserAccess, len(m.users))
 
666
        users := make([]permission.UserAccess, len(m.users))
638
667
        for i, user := range m.users {
639
 
                users[i] = description.UserAccess{
 
668
                users[i] = permission.UserAccess{
640
669
                        UserID:      strings.ToLower(user.userName),
641
670
                        UserTag:     names.NewUserTag(user.userName),
642
671
                        Object:      m.ModelTag(),
663
692
        userName       string
664
693
        displayName    string
665
694
        lastConnection time.Time
666
 
        access         description.Access
 
695
        access         permission.Access
667
696
}