Пример #1
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)
Пример #2
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)
Пример #3
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)
Пример #4
0
 def test_add_get_cloud_with_invalid_profile(self):
     # Cloud has profile that doesn't exist so an exception should be raised
     profile = 'none-existent-profile'
     c = Cloud('MyOwnCloud', profile=profile)
     with mock.patch('azure.cli.core.cloud.CLOUD_CONFIG_FILE', tempfile.mkstemp()[1]) as\
             config_file:
         add_cloud(c)
         config = get_config_parser()
         config.read(config_file)
         self.assertTrue(c.name in config.sections())
         self.assertEqual(config.get(c.name, 'profile'), profile)
         with self.assertRaises(CLIError):
             get_custom_clouds()
Пример #5
0
 def test_add_get_cloud_with_invalid_profile(self):
     # Cloud has profile that doesn't exist so an exception should be raised
     profile = 'none-existent-profile'
     c = Cloud('MyOwnCloud', profile=profile)
     with mock.patch('azure.cli.core.cloud.CLOUD_CONFIG_FILE', tempfile.mkstemp()[1]) as\
             config_file:
         add_cloud(c)
         config = get_config_parser()
         config.read(config_file)
         self.assertTrue(c.name in config.sections())
         self.assertEqual(config.get(c.name, 'profile'), profile)
         with self.assertRaises(CLIError):
             get_custom_clouds()
Пример #6
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)
Пример #7
0
 def test_custom_cloud_no_management_endpoint_set(self):
     # Use ARM 'resource manager' endpoint as 'management' (old ASM) endpoint if only ARM endpoint is set
     endpoint_rm = 'http://management.contoso.com'
     endpoints = CloudEndpoints(resource_manager=endpoint_rm)
     profile = '2017-03-09-profile'
     c = Cloud('MyOwnCloud', endpoints=endpoints, profile=profile)
     with mock.patch('azure.cli.core.cloud.CLOUD_CONFIG_FILE', tempfile.mkstemp()[1]):
         add_cloud(c)
         custom_clouds = get_custom_clouds()
         self.assertEqual(len(custom_clouds), 1)
         self.assertEqual(custom_clouds[0].endpoints.resource_manager,
                          c.endpoints.resource_manager)
         # CLI logic should add management endpoint to equal resource_manager as we didn't set it
         self.assertEqual(custom_clouds[0].endpoints.management,
                          c.endpoints.resource_manager)
Пример #8
0
 def test_custom_cloud_management_endpoint_set(self):
     # We have set management endpoint so don't override it
     endpoint_rm = 'http://management.contoso.com'
     endpoint_mgmt = 'http://management.core.contoso.com'
     endpoints = CloudEndpoints(resource_manager=endpoint_rm, management=endpoint_mgmt)
     profile = '2017-03-09-profile'
     c = Cloud('MyOwnCloud', endpoints=endpoints, profile=profile)
     with mock.patch('azure.cli.core.cloud.CLOUD_CONFIG_FILE', tempfile.mkstemp()[1]):
         add_cloud(c)
         custom_clouds = get_custom_clouds()
         self.assertEqual(len(custom_clouds), 1)
         self.assertEqual(custom_clouds[0].endpoints.resource_manager,
                          c.endpoints.resource_manager)
         # CLI logic should keep our set management endpoint
         self.assertEqual(custom_clouds[0].endpoints.management,
                          c.endpoints.management)
Пример #9
0
 def test_custom_cloud_no_management_endpoint_set(self):
     # Use ARM 'resource manager' endpoint as 'management' (old ASM) endpoint if only ARM endpoint is set
     endpoint_rm = 'http://management.contoso.com'
     endpoints = CloudEndpoints(resource_manager=endpoint_rm)
     profile = '2017-03-09-profile-preview'
     c = Cloud('MyOwnCloud', endpoints=endpoints, profile=profile)
     with mock.patch('azure.cli.core.cloud.CLOUD_CONFIG_FILE',
                     tempfile.mkstemp()[1]):
         add_cloud(c)
         custom_clouds = get_custom_clouds()
         self.assertEqual(len(custom_clouds), 1)
         self.assertEqual(custom_clouds[0].endpoints.resource_manager,
                          c.endpoints.resource_manager)
         # CLI logic should add management endpoint to equal resource_manager as we didn't set it
         self.assertEqual(custom_clouds[0].endpoints.management,
                          c.endpoints.resource_manager)
Пример #10
0
 def test_custom_cloud_management_endpoint_set(self):
     ''' We have set management endpoint so don't override it '''
     endpoint_rm = 'http://management.contoso.com'
     endpoint_mgmt = 'http://management.core.contoso.com'
     endpoints = CloudEndpoints(resource_manager=endpoint_rm, management=endpoint_mgmt)
     profile = '2017-03-09-profile-preview'
     c = Cloud('MyOwnCloud', endpoints=endpoints, profile=profile)
     with mock.patch('azure.cli.core.cloud.CLOUD_CONFIG_FILE', tempfile.mkstemp()[1]):
         add_cloud(c)
         custom_clouds = get_custom_clouds()
         self.assertEqual(len(custom_clouds), 1)
         self.assertEqual(custom_clouds[0].endpoints.resource_manager,
                          c.endpoints.resource_manager)
         # CLI logic should keep our set management endpoint
         self.assertEqual(custom_clouds[0].endpoints.management,
                          c.endpoints.management)
Пример #11
0
 def test_add_get_cloud_with_profile(self):
     cli = TestCli()
     endpoint_rm = 'http://management.contoso.com'
     endpoints = CloudEndpoints(resource_manager=endpoint_rm)
     profile = '2017-03-09-profile'
     c = Cloud('MyOwnCloud', endpoints=endpoints, profile=profile)
     with mock.patch('azure.cli.core.cloud.CLOUD_CONFIG_FILE', tempfile.mkstemp()[1]) as\
             config_file:
         add_cloud(cli, c)
         config = cli.config.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, 'profile'), profile)
         custom_clouds = get_custom_clouds(cli)
         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].profile, c.profile)
Пример #12
0
def get_custom_cloud_name_completion_list(prefix, action, parsed_args,
                                          **kwargs):  # pylint: disable=unused-argument
    return [c.name for c in get_custom_clouds()]
Пример #13
0
def get_custom_cloud_name_completion_list(prefix, action, parsed_args, **kwargs):  # pylint: disable=unused-argument
    return [c.name for c in get_custom_clouds()]
Пример #14
0
def get_custom_cloud_name_completion_list(cmd, prefix, namespace, **kwargs):  # pylint: disable=unused-argument
    return [c.name for c in get_custom_clouds(cmd.cli_ctx)]