+ mock_extract_items_wth_keep_flag_from_created_items.assert_called_once_with(
+ created_items
+ )
+
+ def test_remove_keep_tag_from_persistent_volumes_keep_flag_exists(self):
+ """Keep flag exists in created items."""
+ created_items = {
+ f"port:{port_id}": True,
+ f"floating_ip:{floating_network_vim_id}": True,
+ f"volume:{volume_id}:keep": True,
+ f"volume:{volume_id2}:keep": True,
+ }
+ expected_result = {
+ f"port:{port_id}": True,
+ f"floating_ip:{floating_network_vim_id}": True,
+ f"volume:{volume_id}": True,
+ f"volume:{volume_id2}": True,
+ }
+ result = self.vimconn.remove_keep_tag_from_persistent_volumes(created_items)
+ self.assertDictEqual(result, expected_result)
+
+ def test_remove_keep_tag_from_persistent_volumes_without_keep_flag(self):
+ """Keep flag does not exist in created items."""
+ created_items = {
+ f"port:{port_id}": True,
+ f"floating_ip:{floating_network_vim_id}": True,
+ f"volume:{volume_id}": True,
+ f"volume:{volume_id2}": True,
+ }
+ result = self.vimconn.remove_keep_tag_from_persistent_volumes(created_items)
+ self.assertDictEqual(result, created_items)
+
+ def test_update_block_device_mapping_empty_volume(self):
+ """"""
+ volume = ""
+ block_device_mapping = {}
+ base_disk_index = 100
+ disk = {}
+ created_items = {}
+ with self.assertRaises(VimConnException) as err:
+ self.vimconn.update_block_device_mapping(
+ volume, block_device_mapping, base_disk_index, disk, created_items
+ )
+ self.assertEqual(str(err), "Volume is empty.")
+ self.assertEqual(block_device_mapping, {})
+ self.assertEqual(created_items, {})
+
+ def test_update_block_device_mapping_invalid_volume(self):
+ """"""
+ volume = "Volume-A"
+ block_device_mapping = {}
+ base_disk_index = 100
+ disk = {}
+ created_items = {}
+ with self.assertRaises(VimConnException) as err:
+ self.vimconn.update_block_device_mapping(
+ volume, block_device_mapping, base_disk_index, disk, created_items
+ )
+ self.assertEqual(
+ str(err), "Created volume is not valid, does not have id attribute."
+ )
+ self.assertEqual(block_device_mapping, {})
+ self.assertEqual(created_items, {})
+
+ def test_update_block_device_mapping(self):
+ """"""
+ volume = MagicMock(autospec=True)
+ volume.id = volume_id
+ block_device_mapping = {}
+ base_disk_index = 100
+ disk = {}
+ created_items = {}
+ self.vimconn.update_block_device_mapping(
+ volume, block_device_mapping, base_disk_index, disk, created_items
+ )
+ self.assertEqual(
+ block_device_mapping, {"vdd": "ac408b73-b9cc-4a6a-a270-82cc4811bd4a"}
+ )
+ self.assertEqual(
+ created_items, {"volume:ac408b73-b9cc-4a6a-a270-82cc4811bd4a": True}
+ )
+
+ def test_update_block_device_mapping_with_keep_flag(self):
+ """"""
+ volume = MagicMock(autospec=True)
+ volume.id = volume_id
+ block_device_mapping = {}
+ base_disk_index = 100
+ disk = {"size": 10, "keep": True}
+ created_items = {}
+ self.vimconn.update_block_device_mapping(
+ volume, block_device_mapping, base_disk_index, disk, created_items
+ )
+ self.assertEqual(
+ block_device_mapping, {"vdd": "ac408b73-b9cc-4a6a-a270-82cc4811bd4a"}
+ )
+ self.assertEqual(
+ created_items, {"volume:ac408b73-b9cc-4a6a-a270-82cc4811bd4a:keep": True}
+ )
+
+ def test_extract_items_with_keep_flag_item_has_keep_flag(self):
+ created_items = deepcopy(created_items_all_true)
+ created_items[f"volume:{volume_id2}:keep"] = True
+ result = self.vimconn._extract_items_wth_keep_flag_from_created_items(
+ created_items
+ )
+ self.assertEqual(result, deepcopy(created_items_all_true))
+
+ def test_extract_items_with_keep_flag_no_item_wth_keep_flag(self):
+ created_items = deepcopy(created_items_all_true)
+ result = self.vimconn._extract_items_wth_keep_flag_from_created_items(
+ created_items
+ )
+ self.assertEqual(result, deepcopy(created_items_all_true))
+
+ def test_extract_items_with_keep_flag_all_items_are_already_deleted(self):
+ created_items = {
+ f"port:{port_id}": None,
+ f"floating_ip:{floating_network_vim_id}": None,
+ f"volume:{volume_id}:keep": None,
+ f"volume:{volume_id2}:keep": None,
+ }
+ expected_result = {
+ f"port:{port_id}": None,
+ f"floating_ip:{floating_network_vim_id}": None,
+ }
+ result = self.vimconn._extract_items_wth_keep_flag_from_created_items(
+ created_items
+ )
+ self.assertEqual(result, expected_result)
+
+ def test_extract_items_with_keep_flag_without_semicolon(self):
+ created_items = {
+ f"port{port_id}": True,
+ f"floating_ip{floating_network_vim_id}": None,
+ f"volume{volume_id}keep": True,
+ f"volume{volume_id2}keep": True,
+ }
+ result = self.vimconn._extract_items_wth_keep_flag_from_created_items(
+ created_items
+ )
+ self.assertEqual(result, {})
+
+ def test_extract_items_with_keep_flag_invalid_type_created_items(self):
+ created_items = [{f"port{port_id}": True}, {f"volume{volume_id2}keep": True}]
+ with self.assertRaises(AttributeError):
+ self.vimconn._extract_items_wth_keep_flag_from_created_items(created_items)