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(
63 {'arg': 'missing'}).items()
66 def test_hostname_from_arvados_node(self):
67 arv_node = testutil.arvados_node_mock(8)
68 driver = self.new_driver()
69 self.assertEqual('compute8.zzzzz.arvadosapi.com',
70 driver.arvados_create_kwargs(testutil.MockSize(1), arv_node)['name'])
72 def test_default_hostname_from_new_arvados_node(self):
73 arv_node = testutil.arvados_node_mock(hostname=None)
74 driver = self.new_driver()
75 self.assertEqual('dynamic.compute.zzzzz.arvadosapi.com',
76 driver.arvados_create_kwargs(testutil.MockSize(1), arv_node)['name'])
78 def check_node_tagged(self, cloud_node, expected_tags):
79 tag_mock = self.driver_mock().ex_create_tags
80 self.assertTrue(tag_mock.called)
81 self.assertIs(cloud_node, tag_mock.call_args[0][0])
82 self.assertEqual(expected_tags, tag_mock.call_args[0][1])
84 def test_sync_node(self):
85 arv_node = testutil.arvados_node_mock(1)
86 cloud_node = testutil.cloud_node_mock(2)
87 driver = self.new_driver()
88 driver.sync_node(cloud_node, arv_node)
89 self.check_node_tagged(cloud_node,
90 {'Name': 'compute1.zzzzz.arvadosapi.com'})
92 def test_node_create_time(self):
93 refsecs = int(time.time())
94 reftuple = time.gmtime(refsecs)
95 node = testutil.cloud_node_mock()
96 node.extra = {'launch_time': time.strftime('%Y-%m-%dT%H:%M:%S.000Z',
98 self.assertEqual(refsecs, ec2.ComputeNodeDriver.node_start_time(node))
100 def test_node_fqdn(self):
101 name = 'fqdntest.zzzzz.arvadosapi.com'
102 node = testutil.cloud_node_mock()
104 self.assertEqual(name, ec2.ComputeNodeDriver.node_fqdn(node))
106 def test_create_ebs_volume(self):
107 arv_node = testutil.arvados_node_mock()
108 driver = self.new_driver()
109 # libcloud/ec2 "disk" sizes are in GB, Arvados/SLURM "scratch" value is in MB
110 size = testutil.MockSize(1)
113 driver.create_node(size, arv_node)
114 create_method = self.driver_mock().create_node
115 self.assertTrue(create_method.called)
117 "DeviceName": "/dev/xvdt",
119 "DeleteOnTermination": True,
123 create_method.call_args[1].get('ex_blockdevicemappings'))
125 def test_ebs_volume_not_needed(self):
126 arv_node = testutil.arvados_node_mock()
127 driver = self.new_driver()
128 # libcloud/ec2 "disk" sizes are in GB, Arvados/SLURM "scratch" value is in MB
129 size = testutil.MockSize(1)
132 driver.create_node(size, arv_node)
133 create_method = self.driver_mock().create_node
134 self.assertTrue(create_method.called)
135 self.assertIsNone(create_method.call_args[1].get('ex_blockdevicemappings'))
137 def test_ebs_volume_too_big(self):
138 arv_node = testutil.arvados_node_mock()
139 driver = self.new_driver()
140 # libcloud/ec2 "disk" sizes are in GB, Arvados/SLURM "scratch" value is in MB
141 size = testutil.MockSize(1)
143 size.scratch=20000000
144 driver.create_node(size, arv_node)
145 create_method = self.driver_mock().create_node
146 self.assertTrue(create_method.called)
148 "DeviceName": "/dev/xvdt",
150 "DeleteOnTermination": True,
154 create_method.call_args[1].get('ex_blockdevicemappings'))