Exemplo n.º 1
0
 def mock_rpcs(self, rpcs):
     """rpcs is a list of tuples, each representing one RPC:
     (op, **dargs, success, expected)"""
     for (op, dargs, success, expected) in rpcs:
         comm = rpc.afe_comm.run
         if success:
             comm.expect_call(op, **dargs).and_return(expected)
         else:
             comm.expect_call(op, **dargs).and_raises(proxy.JSONRPCException(expected))
 def test_commit_labels_raises(self):
     """Test that exception while committing is translated properly."""
     self.mock_afe.get_hosts.return_value = [
         self._create_mock_host(['label1'], {})
     ]
     self.mock_afe.run.side_effect = rpc_proxy.JSONRPCException(
         'some error')
     info = host_info.HostInfo(['label2'], {})
     with self.assertRaises(host_info.StoreError):
         self.store._commit_impl(info)
Exemplo n.º 3
0
    def mock_rpcs(self, rpcs):
        """Expect and mock the results of a list of RPCs.

        @param rpcs: A list of tuples, each representing one RPC:
                     (op, args(dict), success, expected)
        """
        for (op, dargs, success, expected) in rpcs:
            comm = rpc.afe_comm.run
            if success:
                comm.expect_call(op, **dargs).and_return(expected)
            else:
                (comm.expect_call(op, **dargs).
                 and_raises(proxy.JSONRPCException(expected)))
 def test_exception(self):
     """Test exceptions raised by `last_diagnosis()`."""
     history = _FakeHostHistory('', '', _BROKEN)
     history.exception = proxy.JSONRPCException('exception for testing')
     self.assertIsNone(self._get_diagnosis_status(history))