3 from __future__ import absolute_import, print_function
9 import libcloud.common.types as cloud_types
12 import arvnodeman.computenode.driver.azure as azure
13 from . import testutil
15 class AzureComputeNodeDriverTestCase(testutil.DriverTestMixin, unittest.TestCase):
16 TEST_CLASS = azure.ComputeNodeDriver
18 def new_driver(self, auth_kwargs={}, list_kwargs={}, create_kwargs={}):
19 list_kwargs.setdefault("ex_resource_group", "TestResourceGroup")
20 return super(AzureComputeNodeDriverTestCase, self).new_driver(auth_kwargs, list_kwargs, create_kwargs)
22 def test_driver_instantiation(self):
23 kwargs = {'key': 'testkey'}
24 driver = self.new_driver(auth_kwargs=kwargs)
25 self.assertTrue(self.driver_mock.called)
26 self.assertEqual(kwargs, self.driver_mock.call_args[1])
28 def test_create_image_loaded_at_initialization(self):
29 get_method = self.driver_mock().get_image
30 get_method.return_value = testutil.cloud_object_mock('id_b')
31 driver = self.new_driver(create_kwargs={'image': 'id_b'})
32 self.assertEqual(1, get_method.call_count)
34 def test_create_includes_ping(self):
35 arv_node = testutil.arvados_node_mock(info={'ping_secret': 'ssshh'})
36 arv_node["hostname"] = None
37 driver = self.new_driver()
38 driver.create_node(testutil.MockSize(1), arv_node)
39 create_method = self.driver_mock().create_node
40 self.assertTrue(create_method.called)
41 self.assertIn('ping_secret=ssshh',
42 create_method.call_args[1].get('ex_tags', {}).get('arv-ping-url', ""))
44 def test_name_from_new_arvados_node(self):
45 arv_node = testutil.arvados_node_mock(hostname=None)
46 driver = self.new_driver()
47 self.assertEqual('compute-000000000000063-zzzzz',
48 driver.arvados_create_kwargs(arv_node)['name'])
50 def check_node_tagged(self, cloud_node, expected_tags):
51 tag_mock = self.driver_mock().ex_create_tags
52 self.assertTrue(tag_mock.called)
53 self.assertIs(cloud_node, tag_mock.call_args[0][0])
54 self.assertEqual(expected_tags, tag_mock.call_args[0][1])
56 def test_node_create_time(self):
57 refsecs = int(time.time())
58 reftuple = time.gmtime(refsecs)
59 node = testutil.cloud_node_mock()
60 node.extra = {'tags': {'booted_at': time.strftime('%Y-%m-%dT%H:%M:%S.000Z',
62 self.assertEqual(refsecs, azure.ComputeNodeDriver.node_start_time(node))
64 def test_node_fqdn(self):
65 name = 'fqdntest.zzzzz.arvadosapi.com'
66 node = testutil.cloud_node_mock()
67 node.extra = {'tags': {"hostname": name}}
68 self.assertEqual(name, azure.ComputeNodeDriver.node_fqdn(node))
70 def test_cloud_exceptions(self):
71 for error in [Exception("test exception"),
72 IOError("test exception"),
73 ssl.SSLError("test exception"),
74 cloud_types.LibcloudError("test exception")]:
75 self.assertTrue(azure.ComputeNodeDriver.is_cloud_exception(error),
76 "{} not flagged as cloud exception".format(error))
78 def test_noncloud_exceptions(self):
80 azure.ComputeNodeDriver.is_cloud_exception(ValueError("test error")),
81 "ValueError flagged as cloud exception")
83 def test_sync_node(self):
84 arv_node = testutil.arvados_node_mock(1)
85 cloud_node = testutil.cloud_node_mock(2)
86 driver = self.new_driver()
87 driver.sync_node(cloud_node, arv_node)
88 self.check_node_tagged(cloud_node,
89 {'hostname': 'compute1.zzzzz.arvadosapi.com'})