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