Esempio n. 1
0
 def test_add_get_delete_custom_cloud(self):
     endpoint_rm = 'http://management.contoso.com'
     suffix_storage = 'core.contoso.com'
     endpoints = CloudEndpoints(resource_manager=endpoint_rm)
     suffixes = CloudSuffixes(storage_endpoint=suffix_storage)
     c = Cloud('MyOwnCloud', endpoints=endpoints, suffixes=suffixes)
     with mock.patch('azure.cli.core.cloud.CLOUD_CONFIG_FILE', tempfile.mkstemp()[1]) as\
             config_file:
         with mock.patch('azure.cli.core.cloud.get_custom_clouds',
                         lambda: []):
             add_cloud(c)
             config = get_config_parser()
             config.read(config_file)
             self.assertTrue(c.name in config.sections())
             self.assertEqual(
                 config.get(c.name, 'endpoint_resource_manager'),
                 endpoint_rm)
             self.assertEqual(config.get(c.name, 'suffix_storage_endpoint'),
                              suffix_storage)
         custom_clouds = get_custom_clouds()
         self.assertEqual(len(custom_clouds), 1)
         self.assertEqual(custom_clouds[0].name, c.name)
         self.assertEqual(custom_clouds[0].endpoints.resource_manager,
                          c.endpoints.resource_manager)
         self.assertEqual(custom_clouds[0].suffixes.storage_endpoint,
                          c.suffixes.storage_endpoint)
         with mock.patch('azure.cli.core.cloud._get_cloud', lambda _: c):
             remove_cloud(c.name)
         custom_clouds = get_custom_clouds()
         self.assertEqual(len(custom_clouds), 0)
Esempio n. 2
0
 def test_add_get_delete_custom_cloud(self):
     endpoints = CloudEndpoints(management='http://management.contoso.com')
     suffixes = CloudSuffixes(storage_endpoint='core.contoso.com')
     c = Cloud('MyOwnCloud', endpoints=endpoints, suffixes=suffixes)
     expected_config_file_result = '[MyOwnCloud]\nendpoint_management = ' \
                                   'http://management.contoso.com\nsuffix_storage_endpoint = ' \
                                   'core.contoso.com\n\n'
     with mock.patch('azure.cli.core.cloud.CUSTOM_CLOUD_CONFIG_FILE', tempfile.mkstemp()[1]) as\
             config_file:
         with mock.patch('azure.cli.core.cloud.get_custom_clouds',
                         lambda: []):
             add_cloud(c)
             with open(config_file, 'r') as cf:
                 self.assertEqual(cf.read(), expected_config_file_result)
         custom_clouds = get_custom_clouds()
         self.assertEqual(len(custom_clouds), 1)
         self.assertEqual(custom_clouds[0].name, c.name)
         self.assertEqual(custom_clouds[0].endpoints.management,
                          c.endpoints.management)
         self.assertEqual(custom_clouds[0].suffixes.storage_endpoint,
                          c.suffixes.storage_endpoint)
         with mock.patch('azure.cli.core.cloud._get_cloud', lambda _: c):
             remove_cloud(c.name)
         custom_clouds = get_custom_clouds()
         self.assertEqual(len(custom_clouds), 0)