X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/7a6f2613d38bf9fb99a919b3875d2851a23a253a..3dad67f271492790f63e72ffcbba432cf8e00fa5:/services/nodemanager/tests/test_nodelist.py diff --git a/services/nodemanager/tests/test_nodelist.py b/services/nodemanager/tests/test_nodelist.py index 5346e7ab7b..11f41b8d9a 100644 --- a/services/nodemanager/tests/test_nodelist.py +++ b/services/nodemanager/tests/test_nodelist.py @@ -1,10 +1,15 @@ #!/usr/bin/env python +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 from __future__ import absolute_import, print_function import unittest +import mock import arvnodeman.nodelist as nodelist +from libcloud.compute.base import NodeSize from . import testutil class ArvadosNodeListMonitorActorTestCase(testutil.RemotePollLoopActorTestMixin, @@ -16,13 +21,43 @@ class ArvadosNodeListMonitorActorTestCase(testutil.RemotePollLoopActorTestMixin, *args, **kwargs) self.client.nodes().list().execute.side_effect = side_effect - def test_uuid_is_subscription_key(self): + @mock.patch("subprocess.check_output") + def test_uuid_is_subscription_key(self, sinfo_mock): + sinfo_mock.return_value = "" node = testutil.arvados_node_mock() - self.build_monitor([{'items': [node]}]) + self.build_monitor([{ + 'items': [node], + 'items_available': 1, + 'offset': 0 + }, { + 'items': [], + 'items_available': 1, + 'offset': 1 + }]) self.monitor.subscribe_to(node['uuid'], self.subscriber).get(self.TIMEOUT) self.stop_proxy(self.monitor) self.subscriber.assert_called_with(node) + self.assertEqual("down", node["crunch_worker_state"]) + + @mock.patch("subprocess.check_output") + def test_update_from_sinfo(self, sinfo_mock): + sinfo_mock.return_value = "compute99 alloc" + node = testutil.arvados_node_mock() + self.build_monitor([{ + 'items': [node], + 'items_available': 1, + 'offset': 0 + }, { + 'items': [], + 'items_available': 1, + 'offset': 1 + }]) + self.monitor.subscribe_to(node['uuid'], + self.subscriber).get(self.TIMEOUT) + self.stop_proxy(self.monitor) + self.subscriber.assert_called_with(node) + self.assertEqual("busy", node["crunch_worker_state"]) class CloudNodeListMonitorActorTestCase(testutil.RemotePollLoopActorTestMixin, @@ -35,7 +70,7 @@ class CloudNodeListMonitorActorTestCase(testutil.RemotePollLoopActorTestMixin, self.name = 'test{}.example.com'.format(count) self.private_ips = ['10.0.0.{}'.format(count)] self.public_ips = [] - self.size = None + self.size = testutil.MockSize(1) self.state = 0 @@ -46,12 +81,13 @@ class CloudNodeListMonitorActorTestCase(testutil.RemotePollLoopActorTestMixin, def test_id_is_subscription_key(self): node = self.MockNode(1) - self.build_monitor([[node]]) + mock_calc = mock.MagicMock() + mock_calc.find_size.return_value = testutil.MockSize(2) + self.build_monitor([[node]], mock_calc) self.monitor.subscribe_to('1', self.subscriber).get(self.TIMEOUT) self.stop_proxy(self.monitor) self.subscriber.assert_called_with(node) - + self.assertEqual(testutil.MockSize(2), node.size) if __name__ == '__main__': unittest.main() -