def test_find_sets_scheduler_id(self, client_class):
        client_class.side_effect = self.create_fake_client

        client = MagicMock()
        self._clients["bar"] = client

        scheduler = BranchScheduler("foo", 9)
        scheduler.configure([ChildInfo(id="bar", address="bar")])
        scheduler.find(FindRequest())

        client.find.assert_called_with(FindRequest(scheduler_id="bar"))
    def test_find_system_error(self):
        scheduler = MagicMock()
        scheduler.find.side_effect = ValueError

        handler = SchedulerHandler()
        handler._schedulers["foo"] = scheduler
        response = handler.find(FindRequest(scheduler_id="foo"))

        assert_that(response.result, is_(FindResultCode.SYSTEM_ERROR))
    def test_find_response(self):
        response = FindResponse(FindResultCode.OK)

        scheduler = MagicMock()
        scheduler.find.return_value = response

        handler = SchedulerHandler()
        handler._schedulers["foo"] = scheduler
        actual_response = handler.find(FindRequest(Locator(), "foo"))

        assert_that(actual_response, is_(same_instance(response)))
    def test_find_resource_not_found(self, client_class):
        client_class.side_effect = self.create_fake_client

        bar_client = MagicMock()
        bar_response = FindResponse(FindResultCode.NOT_FOUND)
        bar_client.find.return_value = bar_response
        self._clients["bar"] = bar_client

        baz_client = MagicMock()
        baz_response = FindResponse(FindResultCode.NOT_FOUND)
        baz_client.find.return_value = baz_response
        self._clients["baz"] = baz_client

        scheduler = BranchScheduler("foo", 9)
        scheduler.configure([ChildInfo(id="bar", address="bar"),
                             ChildInfo(id="baz", address="baz")])

        response = scheduler.find(FindRequest())
        assert_that(response.result, is_(FindResultCode.NOT_FOUND))
    def test_find_timeout(self, wait_fn, client_class):
        client_class.side_effect = self.create_fake_client

        client = MagicMock()
        response = FindResponse(FindResultCode.OK)
        client.find.return_value = response
        self._clients["baz"] = client

        scheduler = BranchScheduler("foo", 9)
        scheduler.configure([ChildInfo(id="baz", address="baz")])

        wait_fn.return_value = set(), set()

        response = scheduler.find(FindRequest())
        assert_that(response.result, is_(FindResultCode.NOT_FOUND))

        # must shutdown to join the futures since the patch lifecycle
        # ends when this method returns
        self._threadpool.shutdown()
Exemplo n.º 6
0
 def find_disk(self, disk_id, expect=FindResultCode.OK):
     request = FindRequest(Locator(disk=DiskLocator(disk_id)))
     response = rpc_call(self.host_client.find, request)
     assert_that(response.result, equal_to(expect))
     return response.datastore
Exemplo n.º 7
0
 def find(self, expect=FindResultCode.OK):
     request = FindRequest(Locator(VmLocator(self.id)))
     response = rpc_call(self.host_client.find, request)
     assert_that(response.result, equal_to(expect))
     return response
    def test_find_missing_scheduler(self):
        handler = SchedulerHandler()
        response = handler.find(FindRequest(Locator()))

        assert_that(response.result, is_(FindResultCode.INVALID_SCHEDULER))
Exemplo n.º 9
0
 def test_uninitialized_scheduler(self):
     scheduler = LeafScheduler("foo", 9, False)
     self.assertRaises(InvalidScheduler,
                       scheduler.place, self._place_request())
     self.assertRaises(InvalidScheduler,
                       scheduler.find, FindRequest())