Пример #1
0
 def test_batchai_patch_mount_volumes_no_azure_file_url(self):
     # noinspection PyTypeChecker
     mount_volumes = MountVolumes(
         azure_file_shares=[
             AzureFileShareReference(
                 relative_mount_path='azfiles',
                 account_name=None,
                 azure_file_url=None,
                 credentials=None
             )
         ]
     )
     with self.assertRaisesRegexp(CLIError, 'Azure File URL cannot absent or be empty'):
         _patch_mount_volumes(TestCli(), mount_volumes)
Пример #2
0
 def test_batchai_patch_mount_volumes_ill_formed_azure_file_url(self):
     # noinspection PyTypeChecker
     mount_volumes = MountVolumes(
         azure_file_shares=[
             AzureFileShareReference(
                 relative_mount_path='azfiles',
                 account_name=None,
                 azure_file_url='http://http://something/is/wrong',
                 credentials=None
             )
         ]
     )
     with self.assertRaisesRegexp(CLIError, 'Ill-formed Azure File URL'):
         _patch_mount_volumes(TestCli(), mount_volumes)
Пример #3
0
 def test_batchai_patch_mount_volumes_with_credentials_no_account_found(self, get_storage_client):
     get_storage_client.return_value = _get_mock_storage_accounts_and_keys({})
     # noinspection PyTypeChecker
     mount_volumes = MountVolumes(
         azure_file_shares=[
             AzureFileShareReference(
                 relative_mount_path='azfiles',
                 account_name=None,
                 azure_file_url='https://account1.file.core.windows.net/share',
                 credentials=None
             )
         ]
     )
     with self.assertRaisesRegexp(CLIError, 'Cannot find "account1" storage account'):
         _patch_mount_volumes(TestCli(), mount_volumes)
Пример #4
0
 def test_batchai_patch_mount_volumes_with_credentials_no_account_given(
         self, get_storage_client):
     get_storage_client.return_value = _get_mock_storage_accounts_and_keys(
         {})
     # noinspection PyTypeChecker
     mount_volumes = MountVolumes(
         azure_file_shares=[
             AzureFileShareReference(
                 relative_mount_path='azfiles',
                 account_name=None,
                 azure_file_url='https://<AZURE_BATCHAI_STORAGE_ACCOUNT>.file.core.windows.net/share',
                 credentials=None
             )
         ]
     )
     with self.assertRaisesRegexp(CLIError, 'Please configure Azure Storage account name'):
         _patch_mount_volumes(TestCli(), mount_volumes)
Пример #5
0
 def test_batchai_patch_mount_volumes_when_no_patching_required(
         self, get_storage_client):
     get_storage_client.return_value = _get_mock_storage_accounts_and_keys(
         {})
     # noinspection PyTypeChecker
     mount_volumes = MountVolumes(
         azure_file_shares=[
             AzureFileShareReference(
                 relative_mount_path='azfiles',
                 account_name='account1',
                 azure_file_url='https://account1.file.core.windows.net/share',
                 credentials=AzureStorageCredentialsInfo(account_key='key')
             )
         ]
     )
     actual = _patch_mount_volumes(TestCli(), mount_volumes)
     self.assertEquals(mount_volumes, actual)
Пример #6
0
 def test_batchai_patch_mount_volumes_with_credentials(self, get_storage_client):
     # noinspection PyTypeChecker
     mount_volumes = MountVolumes(
         azure_file_shares=[
             AzureFileShareReference(
                 relative_mount_path='azfiles',
                 account_name=None,
                 azure_file_url='https://account1.file.core.windows.net/share',
                 credentials=None
             )
         ],
         azure_blob_file_systems=[
             AzureBlobFileSystemReference(
                 relative_mount_path='blobfs',
                 container_name='container',
                 account_name='account2',
                 credentials=None
             ),
         ]
     )
     get_storage_client.return_value = \
         _get_mock_storage_accounts_and_keys({'account1': 'key1', 'account2': 'key2'})
     actual = _patch_mount_volumes(TestCli(), mount_volumes)
     expected = MountVolumes(
         azure_file_shares=[
             AzureFileShareReference(
                 relative_mount_path='azfiles',
                 account_name='account1',
                 azure_file_url='https://account1.file.core.windows.net/share',
                 credentials=AzureStorageCredentialsInfo(account_key='key1')
             )
         ],
         azure_blob_file_systems=[
             AzureBlobFileSystemReference(
                 relative_mount_path='blobfs',
                 container_name='container',
                 account_name='account2',
                 credentials=AzureStorageCredentialsInfo(account_key='key2')
             )
         ]
     )
     self.assertEquals(expected, actual)
Пример #7
0
 def test_batchai_patch_mount_volumes_with_templates_via_env_variables(self):
     # noinspection PyTypeChecker
     mount_volumes = MountVolumes(
         azure_file_shares=[
             AzureFileShareReference(
                 relative_mount_path='azfiles',
                 account_name='<AZURE_BATCHAI_STORAGE_ACCOUNT>',
                 azure_file_url='https://<AZURE_BATCHAI_STORAGE_ACCOUNT>.file.core.windows.net/share',
                 credentials=AzureStorageCredentialsInfo(account_key='<AZURE_BATCHAI_STORAGE_KEY>')
             ),
             AzureFileShareReference(
                 relative_mount_path='azfiles2',
                 account_name=None,
                 azure_file_url='https://<AZURE_BATCHAI_STORAGE_ACCOUNT>.file.core.windows.net/share2',
                 credentials=None
             )
         ],
         azure_blob_file_systems=[
             AzureBlobFileSystemReference(
                 relative_mount_path='blobfs',
                 container_name='container',
                 account_name='<AZURE_BATCHAI_STORAGE_ACCOUNT>',
                 credentials=AzureStorageCredentialsInfo(account_key='<AZURE_BATCHAI_STORAGE_KEY>')
             ),
             AzureBlobFileSystemReference(
                 relative_mount_path='blobfs2',
                 container_name='container2',
                 account_name='<AZURE_BATCHAI_STORAGE_ACCOUNT>',
                 credentials=None
             ),
         ]
     )
     with _given_env_variable('AZURE_BATCHAI_STORAGE_ACCOUNT', 'account'):
         with _given_env_variable('AZURE_BATCHAI_STORAGE_KEY', 'key'):
             actual = _patch_mount_volumes(TestCli(), mount_volumes)
     expected = MountVolumes(
         azure_file_shares=[
             AzureFileShareReference(
                 relative_mount_path='azfiles',
                 account_name='account',
                 azure_file_url='https://account.file.core.windows.net/share',
                 credentials=AzureStorageCredentialsInfo(account_key='key')
             ),
             AzureFileShareReference(
                 relative_mount_path='azfiles2',
                 account_name='account',
                 azure_file_url='https://account.file.core.windows.net/share2',
                 credentials=AzureStorageCredentialsInfo(account_key='key')
             ),
         ],
         azure_blob_file_systems=[
             AzureBlobFileSystemReference(
                 relative_mount_path='blobfs',
                 container_name='container',
                 account_name='account',
                 credentials=AzureStorageCredentialsInfo(account_key='key')
             ),
             AzureBlobFileSystemReference(
                 relative_mount_path='blobfs2',
                 container_name='container2',
                 account_name='account',
                 credentials=AzureStorageCredentialsInfo(account_key='key')
             )
         ]
     )
     self.assertEquals(expected, actual)
Пример #8
0
 def test_batchai_patch_mount_volumes_empty_volumes(self):
     self.assertEqual(MountVolumes(), _patch_mount_volumes(TestCli(), MountVolumes()))
Пример #9
0
 def test_batchai_patch_mount_volumes_no_volumes(self):
     self.assertIsNone(_patch_mount_volumes(TestCli(), None))