2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
6 from __future__ import absolute_import, print_function
11 import arvnodeman.nodelist as nodelist
12 from libcloud.compute.base import NodeSize
13 from . import testutil
15 class ArvadosNodeListMonitorActorTestCase(testutil.RemotePollLoopActorTestMixin,
17 TEST_CLASS = nodelist.ArvadosNodeListMonitorActor
19 def build_monitor(self, side_effect, *args, **kwargs):
20 super(ArvadosNodeListMonitorActorTestCase, self).build_monitor(
22 self.client.nodes().list().execute.side_effect = side_effect
24 @mock.patch("subprocess.check_output")
25 def test_uuid_is_subscription_key(self, sinfo_mock):
26 sinfo_mock.return_value = ""
27 node = testutil.arvados_node_mock()
37 self.monitor.subscribe_to(node['uuid'],
38 self.subscriber).get(self.TIMEOUT)
39 self.stop_proxy(self.monitor)
40 self.subscriber.assert_called_with(node)
41 self.assertEqual("down", node["crunch_worker_state"])
43 @mock.patch("subprocess.check_output")
44 def test_update_from_sinfo(self, sinfo_mock):
45 sinfo_mock.return_value = "compute99 alloc"
46 node = testutil.arvados_node_mock()
56 self.monitor.subscribe_to(node['uuid'],
57 self.subscriber).get(self.TIMEOUT)
58 self.stop_proxy(self.monitor)
59 self.subscriber.assert_called_with(node)
60 self.assertEqual("busy", node["crunch_worker_state"])
63 class CloudNodeListMonitorActorTestCase(testutil.RemotePollLoopActorTestMixin,
65 TEST_CLASS = nodelist.CloudNodeListMonitorActor
67 class MockNode(object):
68 def __init__(self, count):
70 self.name = 'test{}.example.com'.format(count)
71 self.private_ips = ['10.0.0.{}'.format(count)]
73 self.size = testutil.MockSize(1)
77 def build_monitor(self, side_effect, *args, **kwargs):
78 super(CloudNodeListMonitorActorTestCase, self).build_monitor(
80 self.client.list_nodes.side_effect = side_effect
82 def test_id_is_subscription_key(self):
83 node = self.MockNode(1)
84 mock_calc = mock.MagicMock()
85 mock_calc.find_size.return_value = testutil.MockSize(2)
86 self.build_monitor([[node]], mock_calc)
87 self.monitor.subscribe_to('1', self.subscriber).get(self.TIMEOUT)
88 self.stop_proxy(self.monitor)
89 self.subscriber.assert_called_with(node)
90 self.assertEqual(testutil.MockSize(2), node.size)
92 if __name__ == '__main__':