Пример #1
0
 def test__call__doesnt_add_result_to_cache_for_not_cache_call(self):
     conn = DummyConnection()
     self.patch(conn, 'callRemote').return_value = (
         succeed(sentinel.boot_images))
     client = RackClient(conn, {})
     call_cache = client._getCallCache()
     result = yield client(cluster.ListBootImages)
     self.assertIs(sentinel.boot_images, result)
     self.assertNotIn(cluster.ListBootImages, call_cache)
Пример #2
0
 def test_getCallCache_returns_existing(self):
     conn = DummyConnection()
     cache = {}
     client = RackClient(conn, cache)
     call_cache = client._getCallCache()
     call_cache2 = client._getCallCache()
     self.assertIs(call_cache, cache["call_cache"])
     self.assertIs(call_cache2, cache["call_cache"])
     self.assertIs(call_cache2, call_cache)
Пример #3
0
 def test__call__adds_result_to_cache(self):
     conn = DummyConnection()
     self.patch(conn, 'callRemote').return_value = (
         succeed(sentinel.power_types))
     client = RackClient(conn, {})
     call_cache = client._getCallCache()
     result = yield client(cluster.DescribePowerTypes)
     self.assertIs(sentinel.power_types, result)
     self.assertIs(
         sentinel.power_types, call_cache[cluster.DescribePowerTypes])
Пример #4
0
 def test_call__adds_result_to_cache(self):
     conn = DummyConnection()
     conn.ident = factory.make_name("ident")
     self.patch(conn,
                "callRemote").return_value = succeed(sentinel.power_types)
     client = RackClient(conn, {})
     call_cache = client._getCallCache()
     result = yield client(cluster.DescribePowerTypes)
     self.assertIs(sentinel.power_types, result)
     self.assertIs(sentinel.power_types,
                   call_cache[cluster.DescribePowerTypes])
Пример #5
0
 def test_call__returns_cache_value(self):
     conn = DummyConnection()
     conn.ident = factory.make_name("ident")
     client = RackClient(conn, {})
     call_cache = client._getCallCache()
     power_types = {"power_types": [{"name": "ipmi"}, {"name": "wedge"}]}
     call_cache[cluster.DescribePowerTypes] = power_types
     result = yield client(cluster.DescribePowerTypes)
     # The result is a copy. It should equal the result but not be
     # the same object.
     self.assertEquals(power_types, result)
     self.assertIsNot(power_types, result)
Пример #6
0
 def test__call__returns_cache_value(self):
     conn = DummyConnection()
     client = RackClient(conn, {})
     call_cache = client._getCallCache()
     power_types = {
         "power_types": [
             {
                 'name': 'ipmi',
             },
             {
                 'name': 'wedge',
             },
         ]
     }
     call_cache[cluster.DescribePowerTypes] = power_types
     result = yield client(cluster.DescribePowerTypes)
     # The result is a copy. It should equal the result but not be
     # the same object.
     self.assertEquals(power_types, result)
     self.assertIsNot(power_types, result)
Пример #7
0
 def test__call__records_latency_metric(self):
     mock_metrics = self.patch(PROMETHEUS_METRICS, 'update')
     conn = DummyConnection()
     conn.ident = factory.make_name('ident')
     self.patch(conn,
                'callRemote').return_value = (succeed(sentinel.boot_images))
     client = RackClient(conn, {})
     yield client(cluster.ListBootImages)
     mock_metrics.assert_called_with('maas_region_rack_rpc_call_latency',
                                     'observe',
                                     labels={'call': 'ListBootImages'},
                                     value=ANY)
Пример #8
0
 def test_call__records_latency_metric(self):
     mock_metrics = self.patch(PROMETHEUS_METRICS, "update")
     conn = DummyConnection()
     conn.ident = factory.make_name("ident")
     self.patch(conn,
                "callRemote").return_value = succeed(sentinel.boot_images)
     client = RackClient(conn, {})
     yield client(cluster.ListBootImages)
     mock_metrics.assert_called_with(
         "maas_region_rack_rpc_call_latency",
         "observe",
         labels={"call": "ListBootImages"},
         value=ANY,
     )
Пример #9
0
 def test_getAllClients(self):
     service = RegionService(sentinel.ipcWorker)
     uuid1 = factory.make_UUID()
     c1 = DummyConnection()
     c2 = DummyConnection()
     service.connections[uuid1].update({c1, c2})
     uuid2 = factory.make_UUID()
     c3 = DummyConnection()
     c4 = DummyConnection()
     service.connections[uuid2].update({c3, c4})
     clients = service.getAllClients()
     self.assertThat(list(clients), MatchesAny(
         MatchesSetwise(
             Equals(RackClient(c1, {})), Equals(RackClient(c3, {}))),
         MatchesSetwise(
             Equals(RackClient(c1, {})), Equals(RackClient(c4, {}))),
         MatchesSetwise(
             Equals(RackClient(c2, {})), Equals(RackClient(c3, {}))),
         MatchesSetwise(
             Equals(RackClient(c2, {})), Equals(RackClient(c4, {}))),
     ))
Пример #10
0
 def check(client):
     self.assertThat(client, Equals(RackClient(chosen, {})))
     self.assertIs(client.cache, service.connectionsCache[client._conn])
Пример #11
0
 def test_getCallCache_adds_new_call_cache(self):
     conn = DummyConnection()
     cache = {}
     client = RackClient(conn, cache)
     call_cache = client._getCallCache()
     self.assertIs(call_cache, cache["call_cache"])