本文整理匯總了Python中gns3.cloud.rackspace_ctrl.RackspaceCtrl.find_storage_image_names方法的典型用法代碼示例。如果您正苦於以下問題:Python RackspaceCtrl.find_storage_image_names方法的具體用法?Python RackspaceCtrl.find_storage_image_names怎麽用?Python RackspaceCtrl.find_storage_image_names使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gns3.cloud.rackspace_ctrl.RackspaceCtrl
的用法示例。
在下文中一共展示了RackspaceCtrl.find_storage_image_names方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestRackspaceCtrl
# 需要導入模塊: from gns3.cloud.rackspace_ctrl import RackspaceCtrl [as 別名]
# 或者: from gns3.cloud.rackspace_ctrl.RackspaceCtrl import find_storage_image_names [as 別名]
#.........這裏部分代碼省略.........
f.write(test_data)
self.ctrl.storage_driver = mock.MagicMock()
mock_container = mock.MagicMock()
mock_container.list_objects = mock.MagicMock(
return_value=[MockStorageObject("test_folder/test.txt"), MockStorageObject("test_folder/test.txt.md5")]
)
self.ctrl.storage_driver.create_container = mock.MagicMock(return_value=mock_container)
mock_container.get_object = mock.MagicMock(return_value=MockStorageObject("", bytes(test_data_hash, "utf8")))
return_value = self.ctrl.upload_file(test_file.name, "test_folder/test.txt")
self.assertFalse(self.ctrl.storage_driver.upload_object_via_stream.called)
self.assertEqual(return_value, False)
def test_download_file__exists__same_hash(self):
test_data = b"abcdefghi"
test_data_hash = hashlib.md5(test_data).hexdigest()
test_file = tempfile.NamedTemporaryFile()
with test_file.file as f:
f.write(test_data)
self.ctrl.storage_driver = mock.MagicMock()
mock_container = mock.MagicMock()
self.ctrl.storage_driver.get_container = mock.MagicMock(return_value=mock_container)
file_object = MockStorageObject("test_file.txt")
file_object.download = mock.MagicMock()
file_hash_object = MockStorageObject("test_file.txt", bytes(test_data_hash, "utf8"))
mock_container.get_object = lambda name: {"test_file.txt": file_object, "test_file.txt.md5": file_hash_object}[
name
]
self.ctrl.download_file("test_file.txt", test_file.name)
self.assertFalse(file_object.download.called)
def test_download_file__exists__different_hash(self):
test_data = b"abcdefghij"
test_data_hash = "some_garbage_hash"
test_file = tempfile.NamedTemporaryFile()
with test_file.file as f:
f.write(test_data)
self.ctrl.storage_driver = mock.MagicMock()
mock_container = mock.MagicMock()
self.ctrl.storage_driver.get_container = mock.MagicMock(return_value=mock_container)
file_object = MockStorageObject("test_file.txt")
file_object.download = mock.MagicMock()
file_hash_object = MockStorageObject("test_file.txt", bytes(test_data_hash, "utf8"))
mock_container.get_object = lambda name: {"test_file.txt": file_object, "test_file.txt.md5": file_hash_object}[
name
]
self.ctrl.download_file("test_file.txt", test_file.name)
file_object.download.assert_called_once_with(test_file.name)
def test_find_storage_image_names(self):
self.ctrl.storage_driver = mock.MagicMock()
mock_container = mock.MagicMock()
self.ctrl.storage_driver.get_container = mock.MagicMock(return_value=mock_container)
mock_container.list_objects = mock.MagicMock(
return_value=[
MockStorageObject("images/IOS/test_image_1.image"),
MockStorageObject("images/IOS/test_image_1.image.md5"),
MockStorageObject("images/IOS/test_image_2.img"),
MockStorageObject("images/IOS/test_image_2.img.md5"),
MockStorageObject("images/IOS/test_image_3.img"),
MockStorageObject("projects/project1.zip"),
MockStorageObject("test_image_1.image"),
]
)
image_names = self.ctrl.find_storage_image_names(["test_image_1.image", "test_image_2.img"])
self.assertDictEqual(
image_names,
{"test_image_1.image": "images/IOS/test_image_1.image", "test_image_2.img": "images/IOS/test_image_2.img"},
)
def test_find_storage_image_names__missing(self):
self.ctrl.storage_driver = mock.MagicMock()
mock_container = mock.MagicMock()
self.ctrl.storage_driver.get_container = mock.MagicMock(return_value=mock_container)
mock_container.list_objects = mock.MagicMock(
return_value=[
MockStorageObject("images/IOS/test_image_1.image"),
MockStorageObject("images/IOS/test_image_1.image.md5"),
MockStorageObject("images/IOS/test_image_2.img.md5"),
MockStorageObject("projects/project1.zip"),
MockStorageObject("test_image_1.image"),
]
)
self.assertRaises(Exception, self.ctrl.find_storage_image_names, ["test_image_1.image", "test_image_2.img"])