2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
6 from __future__ import absolute_import, print_function
12 import libcloud.common.types as cloud_types
15 import arvnodeman.computenode.driver.ec2 as ec2
16 from . import testutil
18 class EC2ComputeNodeDriverTestCase(testutil.DriverTestMixin, unittest.TestCase):
19 TEST_CLASS = ec2.ComputeNodeDriver
21 def test_driver_instantiation(self):
22 kwargs = {'key': 'testkey'}
23 driver = self.new_driver(auth_kwargs=kwargs)
24 self.assertTrue(self.driver_mock.called)
25 self.assertEqual(kwargs, self.driver_mock.call_args[1])
27 def test_list_kwargs_become_filters(self):
28 # We're also testing tag name translation.
29 driver = self.new_driver(list_kwargs={'tag_test': 'true'})
31 list_method = self.driver_mock().list_nodes
32 self.assertTrue(list_method.called)
33 self.assertEqual({'tag:test': 'true'},
34 list_method.call_args[1].get('ex_filters'))
36 def test_create_image_loaded_at_initialization(self):
37 list_method = self.driver_mock().list_images
38 list_method.return_value = [testutil.cloud_object_mock(c)
40 driver = self.new_driver(create_kwargs={'image_id': 'id_b'})
41 self.assertEqual(1, list_method.call_count)
43 def test_create_includes_ping_secret(self):
44 arv_node = testutil.arvados_node_mock(info={'ping_secret': 'ssshh'})
45 driver = self.new_driver()
46 driver.create_node(testutil.MockSize(1), arv_node)
47 create_method = self.driver_mock().create_node
48 self.assertTrue(create_method.called)
49 self.assertIn('ping_secret=ssshh',
50 create_method.call_args[1].get('ex_userdata',
53 def test_create_includes_metadata(self):
54 arv_node = testutil.arvados_node_mock()
55 driver = self.new_driver(list_kwargs={'tag_test': 'testvalue'})
56 driver.create_node(testutil.MockSize(1), arv_node)
57 create_method = self.driver_mock().create_node
58 self.assertTrue(create_method.called)
60 ('test', 'testvalue'),
61 create_method.call_args[1].get('ex_metadata', {'arg': 'missing'}).items()
64 def test_create_includes_arvados_node_size(self):
65 arv_node = testutil.arvados_node_mock()
66 size = testutil.MockSize(1)
67 driver = self.new_driver()
68 driver.create_node(size, arv_node)
69 create_method = self.driver_mock().create_node
70 self.assertTrue(create_method.called)
72 ('arvados_node_size', size.id),
73 create_method.call_args[1].get('ex_metadata', {'arg': 'missing'}).items()
76 def test_create_preemptible_instance(self):
77 arv_node = testutil.arvados_node_mock()
78 driver = self.new_driver()
79 driver.create_node(testutil.MockSize(1, preemptible=True), arv_node)
80 create_method = self.driver_mock().create_node
81 self.assertTrue(create_method.called)
84 create_method.call_args[1].get('ex_spot_market', 'arg missing')
87 def test_hostname_from_arvados_node(self):
88 arv_node = testutil.arvados_node_mock(8)
89 driver = self.new_driver()
90 self.assertEqual('compute8.zzzzz.arvadosapi.com',
91 driver.arvados_create_kwargs(testutil.MockSize(1), arv_node)['name'])
93 def test_default_hostname_from_new_arvados_node(self):
94 arv_node = testutil.arvados_node_mock(hostname=None)
95 driver = self.new_driver()
96 self.assertEqual('dynamic.compute.zzzzz.arvadosapi.com',
97 driver.arvados_create_kwargs(testutil.MockSize(1), arv_node)['name'])
99 def check_node_tagged(self, cloud_node, expected_tags):
100 tag_mock = self.driver_mock().ex_create_tags
101 self.assertTrue(tag_mock.called)
102 self.assertIs(cloud_node, tag_mock.call_args[0][0])
103 self.assertEqual(expected_tags, tag_mock.call_args[0][1])
105 def test_sync_node(self):
106 arv_node = testutil.arvados_node_mock(1)
107 cloud_node = testutil.cloud_node_mock(2)
108 driver = self.new_driver()
109 driver.sync_node(cloud_node, arv_node)
110 self.check_node_tagged(cloud_node,
111 {'Name': 'compute1.zzzzz.arvadosapi.com'})
113 def test_node_create_time(self):
114 refsecs = int(time.time())
115 reftuple = time.gmtime(refsecs)
116 node = testutil.cloud_node_mock()
117 node.extra = {'launch_time': time.strftime('%Y-%m-%dT%H:%M:%S.000Z',
119 self.assertEqual(refsecs, ec2.ComputeNodeDriver.node_start_time(node))
121 def test_node_fqdn(self):
122 name = 'fqdntest.zzzzz.arvadosapi.com'
123 node = testutil.cloud_node_mock()
125 self.assertEqual(name, ec2.ComputeNodeDriver.node_fqdn(node))
127 def test_create_ebs_volume(self):
128 arv_node = testutil.arvados_node_mock()
129 driver = self.new_driver()
130 # libcloud/ec2 "disk" sizes are in GB, Arvados/SLURM "scratch" value is in MB
131 size = testutil.MockSize(1)
134 driver.create_node(size, arv_node)
135 create_method = self.driver_mock().create_node
136 self.assertTrue(create_method.called)
138 "DeviceName": "/dev/xvdt",
140 "DeleteOnTermination": True,
144 create_method.call_args[1].get('ex_blockdevicemappings'))
146 def test_ebs_volume_not_needed(self):
147 arv_node = testutil.arvados_node_mock()
148 driver = self.new_driver()
149 # libcloud/ec2 "disk" sizes are in GB, Arvados/SLURM "scratch" value is in MB
150 size = testutil.MockSize(1)
153 driver.create_node(size, arv_node)
154 create_method = self.driver_mock().create_node
155 self.assertTrue(create_method.called)
156 self.assertIsNone(create_method.call_args[1].get('ex_blockdevicemappings'))
158 def test_ebs_volume_too_big(self):
159 arv_node = testutil.arvados_node_mock()
160 driver = self.new_driver()
161 # libcloud/ec2 "disk" sizes are in GB, Arvados/SLURM "scratch" value is in MB
162 size = testutil.MockSize(1)
164 size.scratch=20000000
165 driver.create_node(size, arv_node)
166 create_method = self.driver_mock().create_node
167 self.assertTrue(create_method.called)
169 "DeviceName": "/dev/xvdt",
171 "DeleteOnTermination": True,
175 create_method.call_args[1].get('ex_blockdevicemappings'))