~oddbloke/cloud-init/lp1506187

« back to all changes in this revision

Viewing changes to tests/unittests/test_datasource/test_azure_helper.py

  • Committer: Daniel Watkins
  • Date: 2015-10-30 16:26:31 UTC
  • Revision ID: daniel.watkins@canonical.com-20151030162631-xmsz2bdgf25zb6d1
Use DMI data to find Azure instance IDs.

This replaces the use of SharedConfig.xml in both the walinuxagent case,
and the case where we communicate with the Azure fabric ourselves.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
          <HostingEnvironmentConfig>
41
41
            http://100.86.192.70:80/...hostingEnvironmentConfig...
42
42
          </HostingEnvironmentConfig>
43
 
          <SharedConfig>{shared_config_url}</SharedConfig>
 
43
          <SharedConfig>http://100.86.192.70:80/..SharedConfig..</SharedConfig>
44
44
          <ExtensionsConfig>
45
45
            http://100.86.192.70:80/...extensionsConfig...
46
46
          </ExtensionsConfig>
55
55
"""
56
56
 
57
57
 
58
 
class TestReadAzureSharedConfig(unittest.TestCase):
59
 
 
60
 
    def test_valid_content(self):
61
 
        xml = """<?xml version="1.0" encoding="utf-8"?>
62
 
            <SharedConfig>
63
 
             <Deployment name="MY_INSTANCE_ID">
64
 
              <Service name="myservice"/>
65
 
              <ServiceInstance name="INSTANCE_ID.0" guid="{abcd-uuid}" />
66
 
             </Deployment>
67
 
            <Incarnation number="1"/>
68
 
            </SharedConfig>"""
69
 
        ret = azure_helper.iid_from_shared_config_content(xml)
70
 
        self.assertEqual("MY_INSTANCE_ID", ret)
71
 
 
72
 
 
73
58
class TestFindEndpoint(TestCase):
74
59
 
75
60
    def setUp(self):
140
125
        'incarnation': 1,
141
126
        'container_id': 'MyContainerId',
142
127
        'instance_id': 'MyInstanceId',
143
 
        'shared_config_url': 'MySharedConfigUrl',
144
128
        'certificates_url': 'MyCertificatesUrl',
145
129
    }
146
130
 
174
158
        goal_state = self._get_goal_state(instance_id=instance_id)
175
159
        self.assertEqual(instance_id, goal_state.instance_id)
176
160
 
177
 
    def test_shared_config_xml_parsed_and_fetched_correctly(self):
178
 
        http_client = mock.MagicMock()
179
 
        shared_config_url = 'TestSharedConfigUrl'
180
 
        goal_state = self._get_goal_state(
181
 
            http_client=http_client, shared_config_url=shared_config_url)
182
 
        shared_config_xml = goal_state.shared_config_xml
183
 
        self.assertEqual(1, http_client.get.call_count)
184
 
        self.assertEqual(shared_config_url, http_client.get.call_args[0][0])
185
 
        self.assertEqual(http_client.get.return_value.contents,
186
 
                         shared_config_xml)
187
 
 
188
161
    def test_certificates_xml_parsed_and_fetched_correctly(self):
189
162
        http_client = mock.MagicMock()
190
 
        certificates_url = 'TestSharedConfigUrl'
 
163
        certificates_url = 'TestCertificatesUrl'
191
164
        goal_state = self._get_goal_state(
192
165
            http_client=http_client, certificates_url=certificates_url)
193
166
        certificates_xml = goal_state.certificates_xml
324
297
                azure_helper.WALinuxAgentShim, 'find_endpoint'))
325
298
        self.GoalState = patches.enter_context(
326
299
            mock.patch.object(azure_helper, 'GoalState'))
327
 
        self.iid_from_shared_config_content = patches.enter_context(
328
 
            mock.patch.object(azure_helper, 'iid_from_shared_config_content'))
329
300
        self.OpenSSLManager = patches.enter_context(
330
301
            mock.patch.object(azure_helper, 'OpenSSLManager'))
331
302
        patches.enter_context(
367
338
        data = shim.register_with_azure_and_fetch_data()
368
339
        self.assertEqual([], data['public-keys'])
369
340
 
370
 
    def test_instance_id_returned_in_data(self):
371
 
        shim = azure_helper.WALinuxAgentShim()
372
 
        data = shim.register_with_azure_and_fetch_data()
373
 
        self.assertEqual(
374
 
            [mock.call(self.GoalState.return_value.shared_config_xml)],
375
 
            self.iid_from_shared_config_content.call_args_list)
376
 
        self.assertEqual(self.iid_from_shared_config_content.return_value,
377
 
                         data['instance-id'])
378
 
 
379
341
    def test_correct_url_used_for_report_ready(self):
380
342
        self.find_endpoint.return_value = 'test_endpoint'
381
343
        shim = azure_helper.WALinuxAgentShim()