diff options
author | Aleksander Mistewicz <a.mistewicz@samsung.com> | 2017-06-08 15:29:10 +0200 |
---|---|---|
committer | Maciej Wereski <m.wereski@partner.samsung.com> | 2017-09-20 12:48:53 +0200 |
commit | 1249262bb79526bdc47fca79d0a344a4d8b7a64e (patch) | |
tree | e29c7398516b380c3e98484d78caf79410aff6f3 | |
parent | 7f1e7b6096002ff38c07bfb286bcc8eb7eca7b60 (diff) | |
download | boruta-1249262bb79526bdc47fca79d0a344a4d8b7a64e.tar.gz boruta-1249262bb79526bdc47fca79d0a344a4d8b7a64e.tar.bz2 boruta-1249262bb79526bdc47fca79d0a344a4d8b7a64e.zip |
Implement setting groups for worker
One of the assumptions of Boruta system is that every user will have
access to the limited amount of resources. It is done by groups.
Initially Worker is not assigned to any. In order to add or remove
group from the list a new list should be created and SetGroups used
to replace it.
Change-Id: Id17eb5feab091dbaa90404d8a09bf4e52537fc61
Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com>
Reviewed-on: https://mcdsrvbld02.digital.local/review/49060
Reviewed-by: Maciej Wereski <m.wereski@partner.samsung.com>
Tested-by: Maciej Wereski <m.wereski@partner.samsung.com>
-rw-r--r-- | workers/worker_list_test.go | 24 | ||||
-rw-r--r-- | workers/workers.go | 7 | ||||
-rw-r--r-- | workers/workers_test.go | 4 |
3 files changed, 30 insertions, 5 deletions
diff --git a/workers/worker_list_test.go b/workers/worker_list_test.go index 92ce1fa..96b85cb 100644 --- a/workers/worker_list_test.go +++ b/workers/worker_list_test.go @@ -261,5 +261,29 @@ var _ = Describe("WorkerList", func() { } }) }) + + Describe("SetGroups", func() { + It("should fail to SetGroup of nonexistent worker", func() { + uuid := randomUUID() + err := wl.SetGroups(uuid, nil) + Expect(err).To(Equal(ErrWorkerNotFound)) + }) + + It("should work to SetGroup", func() { + var group Groups = []Group{ + Group("group1"), + } + + By("setting it") + err := wl.SetGroups(worker, group) + Expect(err).ToNot(HaveOccurred()) + Expect(wl.workers[worker].Groups).To(Equal(group)) + + By("setting it to nil") + err = wl.SetGroups(worker, nil) + Expect(err).ToNot(HaveOccurred()) + Expect(wl.workers[worker].Groups).To(BeNil()) + }) + }) }) }) diff --git a/workers/workers.go b/workers/workers.go index b265f73..220950b 100644 --- a/workers/workers.go +++ b/workers/workers.go @@ -96,7 +96,12 @@ func (wl *WorkerList) SetState(uuid WorkerUUID, state WorkerState) error { // SetGroups is an implementation of SetGroups from Workers interface. func (wl *WorkerList) SetGroups(uuid WorkerUUID, groups Groups) error { - return ErrNotImplemented + worker, ok := wl.workers[uuid] + if !ok { + return ErrWorkerNotFound + } + worker.Groups = groups + return nil } // Deregister is an implementation of Deregister from Workers interface. diff --git a/workers/workers_test.go b/workers/workers_test.go index 8247544..f9674ee 100644 --- a/workers/workers_test.go +++ b/workers/workers_test.go @@ -38,10 +38,6 @@ var _ = Describe("WorkerList", func() { groups Groups = nil ) - By("SetGroups") - err = wl.SetGroups(uuid, groups) - Expect(err).To(Equal(ErrNotImplemented)) - By("ListWorkers") _, err = wl.ListWorkers(groups, caps) Expect(err).To(Equal(ErrNotImplemented)) |