Exemplo n.º 1
0
 def testResponseBody(self):
     test_data = {
         "Hello": "World",
         "xyz": range(10),
     }
     resolver = rpc._StaticResolver(["192.0.2.84"])
     http_proc = _FakeRequestProcessor(
         compat.partial(self._GetBodyTestResponse, test_data))
     proc = rpc._RpcProcessor(resolver, 18700)
     host = "node19759"
     body = {host: serializer.DumpJson(test_data)}
     result = proc([host],
                   "upload_file",
                   body,
                   30,
                   NotImplemented,
                   _req_process_fn=http_proc)
     self.assertEqual(result.keys(), [host])
     lhresp = result[host]
     self.assertFalse(lhresp.offline)
     self.assertEqual(lhresp.node, host)
     self.assertFalse(lhresp.fail_msg)
     self.assertEqual(lhresp.payload, None)
     self.assertEqual(lhresp.call, "upload_file")
     lhresp.Raise("should not raise")
     self.assertEqual(http_proc.reqcount, 1)
Exemplo n.º 2
0
    def testOfflineNode(self):
        resolver = rpc._StaticResolver([rpc._OFFLINE])
        http_proc = _FakeRequestProcessor(NotImplemented)
        proc = rpc._RpcProcessor(resolver, 30668)
        host = "n17296"
        body = {host: ""}
        result = proc([host],
                      "version",
                      body,
                      60,
                      NotImplemented,
                      _req_process_fn=http_proc)
        self.assertEqual(result.keys(), [host])
        lhresp = result[host]
        self.assertTrue(lhresp.offline)
        self.assertEqual(lhresp.node, host)
        self.assertTrue(lhresp.fail_msg)
        self.assertFalse(lhresp.payload)
        self.assertEqual(lhresp.call, "version")

        # With a message
        self.assertRaises(errors.OpExecError, lhresp.Raise, "should raise")

        # No message
        self.assertRaises(errors.OpExecError, lhresp.Raise, None)

        self.assertEqual(http_proc.reqcount, 0)
Exemplo n.º 3
0
 def testVersionSuccess(self):
   resolver = rpc._StaticResolver(["127.0.0.1"])
   http_proc = _FakeRequestProcessor(self._GetVersionResponse)
   proc = rpc._RpcProcessor(resolver, 24094)
   result = proc(["localhost"], "version", {"localhost": ""}, 60,
                 NotImplemented, _req_process_fn=http_proc)
   self.assertEqual(result.keys(), ["localhost"])
   lhresp = result["localhost"]
   self.assertFalse(lhresp.offline)
   self.assertEqual(lhresp.node, "localhost")
   self.assertFalse(lhresp.fail_msg)
   self.assertEqual(lhresp.payload, 123)
   self.assertEqual(lhresp.call, "version")
   lhresp.Raise("should not raise")
   self.assertEqual(http_proc.reqcount, 1)
Exemplo n.º 4
0
 def testVersionSuccess(self):
   resolver = rpc._StaticResolver(["127.0.0.1"])
   http_proc = _FakeRequestProcessor(self._GetVersionResponse)
   proc = rpc._RpcProcessor(resolver, 24094)
   result = proc(["localhost"], "version", {"localhost": ""}, 60,
                 NotImplemented, _req_process_fn=http_proc)
   self.assertEqual(result.keys(), ["localhost"])
   lhresp = result["localhost"]
   self.assertFalse(lhresp.offline)
   self.assertEqual(lhresp.node, "localhost")
   self.assertFalse(lhresp.fail_msg)
   self.assertEqual(lhresp.payload, 123)
   self.assertEqual(lhresp.call, "version")
   lhresp.Raise("should not raise")
   self.assertEqual(http_proc.reqcount, 1)
Exemplo n.º 5
0
    def testHttpError(self):
        nodes = ["uaf6pbbv%s" % i for i in range(50)]
        body = dict((n, "") for n in nodes)
        resolver = rpc._StaticResolver(nodes)

        httperrnodes = set(nodes[1::7])
        self.assertEqual(len(httperrnodes), 7)

        failnodes = set(nodes[2::3]) - httperrnodes
        self.assertEqual(len(failnodes), 14)

        self.assertEqual(len(set(nodes) - failnodes - httperrnodes), 29)

        proc = rpc._RpcProcessor(resolver, 15165)
        http_proc = \
          _FakeRequestProcessor(compat.partial(self._GetHttpErrorResponse,
                                               httperrnodes, failnodes))
        result = proc(nodes,
                      "vg_list",
                      body,
                      constants.RPC_TMO_URGENT,
                      NotImplemented,
                      _req_process_fn=http_proc)
        self.assertEqual(sorted(result.keys()), sorted(nodes))

        for name in nodes:
            lhresp = result[name]
            self.assertFalse(lhresp.offline)
            self.assertEqual(lhresp.node, name)
            self.assertEqual(lhresp.call, "vg_list")

            if name in httperrnodes:
                self.assert_(lhresp.fail_msg)
                self.assertRaises(errors.OpExecError, lhresp.Raise, "failed")
            elif name in failnodes:
                self.assert_(lhresp.fail_msg)
                self.assertRaises(errors.OpPrereqError,
                                  lhresp.Raise,
                                  "failed",
                                  prereq=True,
                                  ecode=errors.ECODE_INVAL)
            else:
                self.assertFalse(lhresp.fail_msg)
                self.assertEqual(lhresp.payload, hash(name))
                lhresp.Raise("should not raise")

        self.assertEqual(http_proc.reqcount, len(nodes))
Exemplo n.º 6
0
 def testReadTimeout(self):
   resolver = rpc._StaticResolver(["192.0.2.13"])
   http_proc = _FakeRequestProcessor(self._ReadTimeoutResponse)
   proc = rpc._RpcProcessor(resolver, 19176)
   host = "node31856"
   body = {host: ""}
   result = proc([host], "version", body, 12356, NotImplemented,
                 _req_process_fn=http_proc)
   self.assertEqual(result.keys(), [host])
   lhresp = result[host]
   self.assertFalse(lhresp.offline)
   self.assertEqual(lhresp.node, host)
   self.assertFalse(lhresp.fail_msg)
   self.assertEqual(lhresp.payload, -1)
   self.assertEqual(lhresp.call, "version")
   lhresp.Raise("should not raise")
   self.assertEqual(http_proc.reqcount, 1)
Exemplo n.º 7
0
 def testReadTimeout(self):
   resolver = rpc._StaticResolver(["192.0.2.13"])
   http_proc = _FakeRequestProcessor(self._ReadTimeoutResponse)
   proc = rpc._RpcProcessor(resolver, 19176)
   host = "node31856"
   body = {host: ""}
   result = proc([host], "version", body, 12356, NotImplemented,
                 _req_process_fn=http_proc)
   self.assertEqual(result.keys(), [host])
   lhresp = result[host]
   self.assertFalse(lhresp.offline)
   self.assertEqual(lhresp.node, host)
   self.assertFalse(lhresp.fail_msg)
   self.assertEqual(lhresp.payload, -1)
   self.assertEqual(lhresp.call, "version")
   lhresp.Raise("should not raise")
   self.assertEqual(http_proc.reqcount, 1)
Exemplo n.º 8
0
  def testInvalidResponse(self):
    resolver = rpc._StaticResolver(["oqo7lanhly.example.com"])
    proc = rpc._RpcProcessor(resolver, 19978)

    for fn in [self._GetInvalidResponseA, self._GetInvalidResponseB]:
      http_proc = _FakeRequestProcessor(fn)
      host = "oqo7lanhly.example.com"
      body = {host: ""}
      result = proc([host], "version", body, 60, NotImplemented,
                    _req_process_fn=http_proc)
      self.assertEqual(result.keys(), [host])
      lhresp = result[host]
      self.assertFalse(lhresp.offline)
      self.assertEqual(lhresp.node, host)
      self.assert_(lhresp.fail_msg)
      self.assertFalse(lhresp.payload)
      self.assertEqual(lhresp.call, "version")
      self.assertRaises(errors.OpExecError, lhresp.Raise, "failed")
      self.assertEqual(http_proc.reqcount, 1)
Exemplo n.º 9
0
  def testInvalidResponse(self):
    resolver = rpc._StaticResolver(["oqo7lanhly.example.com"])
    proc = rpc._RpcProcessor(resolver, 19978)

    for fn in [self._GetInvalidResponseA, self._GetInvalidResponseB]:
      http_proc = _FakeRequestProcessor(fn)
      host = "oqo7lanhly.example.com"
      body = {host: ""}
      result = proc([host], "version", body, 60, NotImplemented,
                    _req_process_fn=http_proc)
      self.assertEqual(result.keys(), [host])
      lhresp = result[host]
      self.assertFalse(lhresp.offline)
      self.assertEqual(lhresp.node, host)
      self.assert_(lhresp.fail_msg)
      self.assertFalse(lhresp.payload)
      self.assertEqual(lhresp.call, "version")
      self.assertRaises(errors.OpExecError, lhresp.Raise, "failed")
      self.assertEqual(http_proc.reqcount, 1)
Exemplo n.º 10
0
 def testVersionFailure(self):
   resolver = rpc._StaticResolver(["aef9ur4i.example.com"])
   proc = rpc._RpcProcessor(resolver, 5903)
   for errinfo in [None, "Unknown error"]:
     http_proc = \
       _FakeRequestProcessor(compat.partial(self._GetVersionResponseFail,
                                            errinfo))
     host = "aef9ur4i.example.com"
     body = {host: ""}
     result = proc(body.keys(), "version", body, 60, NotImplemented,
                   _req_process_fn=http_proc)
     self.assertEqual(result.keys(), [host])
     lhresp = result[host]
     self.assertFalse(lhresp.offline)
     self.assertEqual(lhresp.node, host)
     self.assert_(lhresp.fail_msg)
     self.assertFalse(lhresp.payload)
     self.assertEqual(lhresp.call, "version")
     self.assertRaises(errors.OpExecError, lhresp.Raise, "failed")
     self.assertEqual(http_proc.reqcount, 1)
Exemplo n.º 11
0
  def testMultiVersionSuccess(self):
    nodes = ["node%s" % i for i in range(50)]
    body = dict((n, "") for n in nodes)
    resolver = rpc._StaticResolver(nodes)
    http_proc = _FakeRequestProcessor(self._GetMultiVersionResponse)
    proc = rpc._RpcProcessor(resolver, 23245)
    result = proc(nodes, "version", body, 60, NotImplemented,
                  _req_process_fn=http_proc)
    self.assertEqual(sorted(result.keys()), sorted(nodes))

    for name in nodes:
      lhresp = result[name]
      self.assertFalse(lhresp.offline)
      self.assertEqual(lhresp.node, name)
      self.assertFalse(lhresp.fail_msg)
      self.assertEqual(lhresp.payload, 987)
      self.assertEqual(lhresp.call, "version")
      lhresp.Raise("should not raise")

    self.assertEqual(http_proc.reqcount, len(nodes))
Exemplo n.º 12
0
 def testVersionFailure(self):
   resolver = rpc._StaticResolver(["aef9ur4i.example.com"])
   proc = rpc._RpcProcessor(resolver, 5903)
   for errinfo in [None, "Unknown error"]:
     http_proc = \
       _FakeRequestProcessor(compat.partial(self._GetVersionResponseFail,
                                            errinfo))
     host = "aef9ur4i.example.com"
     body = {host: ""}
     result = proc(body.keys(), "version", body, 60, NotImplemented,
                   _req_process_fn=http_proc)
     self.assertEqual(result.keys(), [host])
     lhresp = result[host]
     self.assertFalse(lhresp.offline)
     self.assertEqual(lhresp.node, host)
     self.assert_(lhresp.fail_msg)
     self.assertFalse(lhresp.payload)
     self.assertEqual(lhresp.call, "version")
     self.assertRaises(errors.OpExecError, lhresp.Raise, "failed")
     self.assertEqual(http_proc.reqcount, 1)
Exemplo n.º 13
0
  def testMultiVersionSuccess(self):
    nodes = ["node%s" % i for i in range(50)]
    body = dict((n, "") for n in nodes)
    resolver = rpc._StaticResolver(nodes)
    http_proc = _FakeRequestProcessor(self._GetMultiVersionResponse)
    proc = rpc._RpcProcessor(resolver, 23245)
    result = proc(nodes, "version", body, 60, NotImplemented,
                  _req_process_fn=http_proc)
    self.assertEqual(sorted(result.keys()), sorted(nodes))

    for name in nodes:
      lhresp = result[name]
      self.assertFalse(lhresp.offline)
      self.assertEqual(lhresp.node, name)
      self.assertFalse(lhresp.fail_msg)
      self.assertEqual(lhresp.payload, 987)
      self.assertEqual(lhresp.call, "version")
      lhresp.Raise("should not raise")

    self.assertEqual(http_proc.reqcount, len(nodes))
Exemplo n.º 14
0
  def testHttpError(self):
    nodes = ["uaf6pbbv%s" % i for i in range(50)]
    body = dict((n, "") for n in nodes)
    resolver = rpc._StaticResolver(nodes)

    httperrnodes = set(nodes[1::7])
    self.assertEqual(len(httperrnodes), 7)

    failnodes = set(nodes[2::3]) - httperrnodes
    self.assertEqual(len(failnodes), 14)

    self.assertEqual(len(set(nodes) - failnodes - httperrnodes), 29)

    proc = rpc._RpcProcessor(resolver, 15165)
    http_proc = \
      _FakeRequestProcessor(compat.partial(self._GetHttpErrorResponse,
                                           httperrnodes, failnodes))
    result = proc(nodes, "vg_list", body,
                  constants.RPC_TMO_URGENT, NotImplemented,
                  _req_process_fn=http_proc)
    self.assertEqual(sorted(result.keys()), sorted(nodes))

    for name in nodes:
      lhresp = result[name]
      self.assertFalse(lhresp.offline)
      self.assertEqual(lhresp.node, name)
      self.assertEqual(lhresp.call, "vg_list")

      if name in httperrnodes:
        self.assert_(lhresp.fail_msg)
        self.assertRaises(errors.OpExecError, lhresp.Raise, "failed")
      elif name in failnodes:
        self.assert_(lhresp.fail_msg)
        self.assertRaises(errors.OpPrereqError, lhresp.Raise, "failed",
                          prereq=True, ecode=errors.ECODE_INVAL)
      else:
        self.assertFalse(lhresp.fail_msg)
        self.assertEqual(lhresp.payload, hash(name))
        lhresp.Raise("should not raise")

    self.assertEqual(http_proc.reqcount, len(nodes))
Exemplo n.º 15
0
 def testResponseBody(self):
   test_data = {
     "Hello": "World",
     "xyz": range(10),
     }
   resolver = rpc._StaticResolver(["192.0.2.84"])
   http_proc = _FakeRequestProcessor(compat.partial(self._GetBodyTestResponse,
                                                    test_data))
   proc = rpc._RpcProcessor(resolver, 18700)
   host = "node19759"
   body = {host: serializer.DumpJson(test_data)}
   result = proc([host], "upload_file", body, 30, NotImplemented,
                 _req_process_fn=http_proc)
   self.assertEqual(result.keys(), [host])
   lhresp = result[host]
   self.assertFalse(lhresp.offline)
   self.assertEqual(lhresp.node, host)
   self.assertFalse(lhresp.fail_msg)
   self.assertEqual(lhresp.payload, None)
   self.assertEqual(lhresp.call, "upload_file")
   lhresp.Raise("should not raise")
   self.assertEqual(http_proc.reqcount, 1)
Exemplo n.º 16
0
  def testOfflineNode(self):
    resolver = rpc._StaticResolver([rpc._OFFLINE])
    http_proc = _FakeRequestProcessor(NotImplemented)
    proc = rpc._RpcProcessor(resolver, 30668)
    host = "n17296"
    body = {host: ""}
    result = proc([host], "version", body, 60, NotImplemented,
                  _req_process_fn=http_proc)
    self.assertEqual(result.keys(), [host])
    lhresp = result[host]
    self.assertTrue(lhresp.offline)
    self.assertEqual(lhresp.node, host)
    self.assertTrue(lhresp.fail_msg)
    self.assertFalse(lhresp.payload)
    self.assertEqual(lhresp.call, "version")

    # With a message
    self.assertRaises(errors.OpExecError, lhresp.Raise, "should raise")

    # No message
    self.assertRaises(errors.OpExecError, lhresp.Raise, None)

    self.assertEqual(http_proc.reqcount, 0)