示例#1
0
    def checked_call(self, vdsm_method, *args, **kwargs):
        try:
            return Optional(vdsm_method(*args, **kwargs))

        except client.ServerError as e:
            self._logger.error(str(e))

        return Optional.missing()
    def getAllVmIoTunePolicies(self):
        try:
            ret = self.vdsm_api.getAllVmIoTunePolicies()
            self._check_status(ret)
        except socket.error as e:
            self.handle_connection_error(e)
            return Optional.empty()
        except vdsmException as e:
            e.handle_exception()
            return Optional.empty()

        vms = ret['io_tune_policies_dict']
        return Optional(vms)
示例#3
0
    def getAllVmIoTunePolicies(self):
        try:
            ret = self.vdsm_api.getAllVmIoTunePolicies()
            self._check_status(ret)
        except socket.error as e:
            self.handle_connection_error(e)
            return Optional.empty()
        except vdsmException as e:
            e.handle_exception()
            return Optional.empty()

        vms = ret["io_tune_policies_dict"]
        return Optional(vms)
示例#4
0
 def checked_call(self, vdsm_method, *args, **kwargs):
     try:
         response = vdsm_method(*args, **kwargs)
         self._check_status(response)
         return Optional(response)
     except socket.error as e:
         self.logger.error("Cannot connect to VDSM! {0}".format(e))
         return Optional.missing()
     except vdsmException as e:
         e.handle_exception()
         return Optional.missing()
     except jsonrpcvdscli.JsonRpcNoResponseError as e:
         self.logger.error("No response from VDSM arrived! {0}".format(e))
         return Optional.missing()
示例#5
0
 def checked_call(self, vdsm_method, *args, **kwargs):
     try:
         response = vdsm_method(*args, **kwargs)
         self._check_status(response)
         return Optional(response)
     except socket.error as e:
         self._logger.error("Cannot connect to VDSM! {0}".format(e))
         return Optional.missing()
     except vdsmException as e:
         e.handle_exception()
         return Optional.missing()
     except jsonrpcvdscli.JsonRpcNoResponseError as e:
         self._logger.error("No response from VDSM arrived! {0}".format(e))
         return Optional.missing()
示例#6
0
    def checked_call(self, vdsm_method, *args, **kwargs):
        try:
            return Optional(vdsm_method(*args, **kwargs))

        except client.ServerError as e:
            self._logger.error(str(e))

        return Optional.missing()
示例#7
0
 def test_raise(self):
     self.assertEqual(Optional("val").orRaise(RuntimeError, "error"), "val")
示例#8
0
 def test_map(self):
     self.assertEqual("VAL", Optional("val").map(str.upper).value)
示例#9
0
 def test_missing_else(self):
     self.assertEqual(False, Optional.missing().orElse(False))
示例#10
0
 def test_missing_iter(self):
     self.assertRaises(StopIteration, iter(Optional.missing()).next)
示例#11
0
 def test_get_default_item(self):
     self.assertEqual(False, Optional({"key": "val"})["key2"].present)
示例#12
0
 def test_missing_none(self):
     self.assertEqual(None, Optional.missing().orNone())
示例#13
0
 def test_missing_raise(self):
     with self.assertRaises(RuntimeError):
         Optional.missing().orRaise(RuntimeError, "error")
示例#14
0
 def test_missing(self):
     self.assertEqual(False, Optional.missing().present)
示例#15
0
 def test_missing_map(self):
     self.assertEqual(False, Optional.missing().map(lambda val: 5 / 0).present)
示例#16
0
 def test_missing_else(self):
     self.assertEqual(False, Optional.missing().orElse(False))
示例#17
0
 def test_missing_get(self):
     self.assertEqual(False, Optional.missing().get("key").present)
示例#18
0
 def test_missing_none(self):
     self.assertEqual(None, Optional.missing().orNone())
示例#19
0
 def test_missing(self):
     self.assertEqual(False, Optional.missing().present)
示例#20
0
 def test_get(self):
     self.assertEqual("val", Optional({"key": "val"}).get("key").value)
示例#21
0
 def test_missing_map(self):
     self.assertEqual(False,
                      Optional.missing().map(lambda val: 5 / 0).present)
示例#22
0
 def test_get_default(self):
     self.assertEqual("default",
                      Optional({
                          "key": "val"
                      }).get("key2", "default").value)
示例#23
0
 def test_missing_iter(self):
     if sys.version_info[0] >= 3:
         self.assertRaises(StopIteration, iter(Optional.missing()).__next__)
     else:
         self.assertRaises(StopIteration, iter(Optional.missing()).next)
示例#24
0
 def test_item(self):
     self.assertEqual("val", Optional({"key": "val"})["key"].value)
示例#25
0
 def test_missing_item(self):
     self.assertEqual(False, Optional.missing()["key"].present)
示例#26
0
 def test_iter(self):
     self.assertEqual("val", iter(Optional(["val"])).next())
示例#27
0
 def test_missing_iter(self):
     self.assertRaises(StopIteration, iter(Optional.missing()).next)
示例#28
0
 def test_missing_raise(self):
     with self.assertRaises(RuntimeError):
         Optional.missing().orRaise(RuntimeError, "error")
示例#29
0
 def test_value(self):
     self.assertEqual(True, Optional("val").present)
     self.assertEqual("val", Optional("val").value)
示例#30
0
 def test_missing_get(self):
     self.assertEqual(False, Optional.missing().get("key").present)
示例#31
0
 def test_missing_item(self):
     self.assertEqual(False, Optional.missing()["key"].present)