本文整理汇总了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"])