Implement setting groups for worker
authorAleksander Mistewicz <a.mistewicz@samsung.com>
Thu, 8 Jun 2017 13:29:10 +0000 (15:29 +0200)
committerMaciej Wereski <m.wereski@partner.samsung.com>
Wed, 20 Sep 2017 10:48:53 +0000 (12:48 +0200)
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>
workers/worker_list_test.go
workers/workers.go
workers/workers_test.go

index 92ce1fa..96b85cb 100644 (file)
@@ -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())
+                       })
+               })
        })
 })
index b265f73..220950b 100644 (file)
@@ -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.
index 8247544..f9674ee 100644 (file)
@@ -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))