зеркало из https://github.com/Azure/azfilebackup.git
Add get_storage_client_with_key method
This commit is contained in:
Родитель
1cc7dda229
Коммит
7db86e9bfc
|
@ -151,3 +151,17 @@ class BackupConfiguration(object):
|
|||
_created = self._block_blob_service.create_container(
|
||||
container_name=self.azure_storage_container_name)
|
||||
return self._block_blob_service
|
||||
|
||||
def get_storage_client_with_key(self, key):
|
||||
"""Create or return BlockBlobService client using given key."""
|
||||
if not self._block_blob_service:
|
||||
account_name = self.get_azure_storage_account_name()
|
||||
|
||||
self._block_blob_service = BlockBlobService(
|
||||
account_name=account_name,
|
||||
account_key=key)
|
||||
|
||||
_created = self._block_blob_service.create_container(
|
||||
container_name=self.azure_storage_container_name)
|
||||
|
||||
return self._block_blob_service
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
azure.storage.account_name: sadjfksjlahfkj
|
||||
azure.storage.account_name: testhecbackup
|
||||
azure.storage.container_name: immutab
|
||||
local_temp_directory: /tmp
|
||||
notification_command: /usr/sbin/ticmcmc --stdin
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
"""Unit tests for backupconfiguration."""
|
||||
import os
|
||||
import json
|
||||
import unittest
|
||||
from mock import patch
|
||||
|
@ -48,7 +49,7 @@ class TestBackupConfiguration(unittest.TestCase):
|
|||
|
||||
def test_get_azure_storage_account_name(self):
|
||||
"""test get_azure_storage_account_name"""
|
||||
self.assertEqual(self.cfg.get_azure_storage_account_name(), 'sadjfksjlahfkj')
|
||||
self.assertEqual(self.cfg.get_azure_storage_account_name(), 'testhecbackup')
|
||||
|
||||
def test_get_backup_command(self):
|
||||
"""test get_commandline"""
|
||||
|
@ -68,6 +69,12 @@ class TestBackupConfiguration(unittest.TestCase):
|
|||
self.assertIn('osdisk', filesets)
|
||||
self.assertIn('testecho', filesets)
|
||||
|
||||
def test_get_storage_client_with_key(self):
|
||||
"""test get_storage_client_with_key"""
|
||||
key = os.environ['STORAGE_KEY']
|
||||
client = self.cfg.get_storage_client_with_key(key)
|
||||
self.assertEqual(client.protocol, 'https')
|
||||
|
||||
def tearDown(self):
|
||||
self.patcher1.stop()
|
||||
|
||||
|
|
|
@ -10,14 +10,14 @@ class TestBackupConfigurationFile(unittest.TestCase):
|
|||
values = backupconfigurationfile.BackupConfigurationFile.read_key_value_file(
|
||||
filename="config.txt")
|
||||
self.assertEqual(values['local_temp_directory'], '/tmp')
|
||||
self.assertEqual(values['azure.storage.account_name'], 'sadjfksjlahfkj')
|
||||
self.assertEqual(values['azure.storage.account_name'], 'testhecbackup')
|
||||
self.assertEqual(values['azure.storage.container_name'], 'immutab')
|
||||
|
||||
def test_get_value(self):
|
||||
"""test get_value"""
|
||||
config = backupconfigurationfile.BackupConfigurationFile(filename="config.txt")
|
||||
self.assertEqual(config.get_value('local_temp_directory'), '/tmp')
|
||||
self.assertEqual(config.get_value('azure.storage.account_name'), 'sadjfksjlahfkj')
|
||||
self.assertEqual(config.get_value('azure.storage.account_name'), 'testhecbackup')
|
||||
self.assertEqual(config.get_value('azure.storage.container_name'), 'immutab')
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Загрузка…
Ссылка в новой задаче