+ result = self.ns._prepare_vdu_cloud_init(target_vdu, vdu2cloud_init, db, fs)
+ self.assertDictEqual(result, expected_result)
+ mock_get_cloud_init.assert_not_called()
+ mock_parse_jinja2.assert_called_once_with(
+ cloud_init_content=cloud_init_content,
+ params=None,
+ context="sample-cloud-init-path",
+ )
+
+ @patch("osm_ng_ro.ns.Ns._get_cloud_init")
+ @patch("osm_ng_ro.ns.Ns._parse_jinja2")
+ def test_prepare_vdu_cloud_init_no_cloud_init(
+ self, mock_parse_jinja2, mock_get_cloud_init
+ ):
+ """Target_vdu do not have cloud-init."""
+ target_vdu = deepcopy(target_vdu_wth_persistent_storage)
+ target_vdu["boot-data-drive"] = "vda"
+ vdu2cloud_init = {}
+ expected_result = {
+ "boot-data-drive": "vda",
+ }
+ result = self.ns._prepare_vdu_cloud_init(target_vdu, vdu2cloud_init, db, fs)
+ self.assertDictEqual(result, expected_result)
+ mock_get_cloud_init.assert_not_called()
+ mock_parse_jinja2.assert_not_called()
+
+ def test_check_vld_information_of_interfaces_ns_vld_vnf_vld_both_exist(self):
+ """ns_vld and vnf_vld both exist."""
+ interface = {
+ "name": "vdu-eth0",
+ "ns-vld-id": "mgmtnet",
+ "vnf-vld-id": "mgmt_cp_int",
+ }
+ expected_result = f"{ns_preffix}:vld.mgmtnet"
+ result = self.ns._check_vld_information_of_interfaces(
+ interface, ns_preffix, vnf_preffix
+ )
+ self.assertEqual(result, expected_result)
+
+ def test_check_vld_information_of_interfaces_empty_interfaces(self):
+ """Interface dict is empty."""
+ interface = {}
+ result = self.ns._check_vld_information_of_interfaces(
+ interface, ns_preffix, vnf_preffix
+ )
+ self.assertEqual(result, "")
+
+ def test_check_vld_information_of_interfaces_has_only_vnf_vld(self):
+ """Interface dict has only vnf_vld."""
+ interface = {
+ "name": "vdu-eth0",
+ "vnf-vld-id": "mgmt_cp_int",
+ }
+ expected_result = f"{vnf_preffix}:vld.mgmt_cp_int"
+ result = self.ns._check_vld_information_of_interfaces(
+ interface, ns_preffix, vnf_preffix
+ )
+ self.assertEqual(result, expected_result)
+
+ def test_check_vld_information_of_interfaces_has_vnf_vld_wthout_vnf_prefix(
+ self,
+ ):
+ """Interface dict has only vnf_vld but vnf_preffix does not exist."""
+ interface = {
+ "name": "vdu-eth0",
+ "vnf-vld-id": "mgmt_cp_int",
+ }
+ vnf_preffix = None
+ with self.assertRaises(Exception) as err:
+ self.ns._check_vld_information_of_interfaces(
+ interface, ns_preffix, vnf_preffix
+ )
+ self.assertEqual(type(err), TypeError)
+
+ def test_prepare_interface_port_security_has_security_details(self):
+ """Interface dict has port security details."""
+ interface = {
+ "name": "vdu-eth0",
+ "ns-vld-id": "mgmtnet",
+ "vnf-vld-id": "mgmt_cp_int",
+ "port-security-enabled": True,
+ "port-security-disable-strategy": "allow-address-pairs",
+ }
+ expected_interface = {
+ "name": "vdu-eth0",
+ "ns-vld-id": "mgmtnet",
+ "vnf-vld-id": "mgmt_cp_int",
+ "port_security": True,
+ "port_security_disable_strategy": "allow-address-pairs",
+ }
+ self.ns._prepare_interface_port_security(interface)
+ self.assertDictEqual(interface, expected_interface)
+
+ def test_prepare_interface_port_security_empty_interfaces(self):
+ """Interface dict is empty."""
+ interface = {}
+ expected_interface = {}
+ self.ns._prepare_interface_port_security(interface)
+ self.assertDictEqual(interface, expected_interface)
+
+ def test_prepare_interface_port_security_wthout_port_security(self):
+ """Interface dict does not have port security details."""
+ interface = {
+ "name": "vdu-eth0",
+ "ns-vld-id": "mgmtnet",
+ "vnf-vld-id": "mgmt_cp_int",
+ }
+ expected_interface = {
+ "name": "vdu-eth0",
+ "ns-vld-id": "mgmtnet",
+ "vnf-vld-id": "mgmt_cp_int",
+ }
+ self.ns._prepare_interface_port_security(interface)
+ self.assertDictEqual(interface, expected_interface)
+
+ def test_create_net_item_of_interface_floating_ip_port_security(self):
+ """Interface dict has floating ip, port-security details."""
+ interface = {
+ "name": "vdu-eth0",
+ "vcpi": "sample_vcpi",
+ "port_security": True,
+ "port_security_disable_strategy": "allow-address-pairs",
+ "floating_ip": "10.1.1.12",
+ "ns-vld-id": "mgmtnet",
+ "vnf-vld-id": "mgmt_cp_int",
+ }
+ net_text = f"{ns_preffix}"
+ expected_net_item = {
+ "name": "vdu-eth0",
+ "port_security": True,
+ "port_security_disable_strategy": "allow-address-pairs",
+ "floating_ip": "10.1.1.12",
+ "net_id": f"TASK-{ns_preffix}",
+ "type": "virtual",
+ }
+ result = self.ns._create_net_item_of_interface(interface, net_text)
+ self.assertDictEqual(result, expected_net_item)
+
+ def test_create_net_item_of_interface_invalid_net_text(self):
+ """net-text is invalid."""
+ interface = {
+ "name": "vdu-eth0",
+ "vcpi": "sample_vcpi",
+ "port_security": True,
+ "port_security_disable_strategy": "allow-address-pairs",
+ "floating_ip": "10.1.1.12",
+ "ns-vld-id": "mgmtnet",
+ "vnf-vld-id": "mgmt_cp_int",
+ }
+ net_text = None
+ with self.assertRaises(TypeError):
+ self.ns._create_net_item_of_interface(interface, net_text)
+
+ def test_create_net_item_of_interface_empty_interface(self):
+ """Interface dict is empty."""
+ interface = {}
+ net_text = ns_preffix
+ expected_net_item = {
+ "net_id": f"TASK-{ns_preffix}",
+ "type": "virtual",
+ }
+ result = self.ns._create_net_item_of_interface(interface, net_text)
+ self.assertDictEqual(result, expected_net_item)
+
+ @patch("osm_ng_ro.ns.deep_get")
+ def test_prepare_type_of_interface_type_sriov(self, mock_deep_get):
+ """Interface type is SR-IOV."""
+ interface = {
+ "name": "vdu-eth0",
+ "vcpi": "sample_vcpi",
+ "port_security": True,
+ "port_security_disable_strategy": "allow-address-pairs",
+ "floating_ip": "10.1.1.12",
+ "ns-vld-id": "mgmtnet",
+ "vnf-vld-id": "mgmt_cp_int",
+ "type": "SR-IOV",
+ }
+ mock_deep_get.return_value = "SR-IOV"
+ net_text = ns_preffix
+ net_item = {}
+ expected_net_item = {
+ "use": "data",
+ "model": "SR-IOV",
+ "type": "SR-IOV",
+ }
+ self.ns._prepare_type_of_interface(
+ interface, tasks_by_target_record_id, net_text, net_item
+ )
+ self.assertDictEqual(net_item, expected_net_item)
+ self.assertEqual(
+ "data",
+ tasks_by_target_record_id[net_text]["extra_dict"]["params"]["net_type"],
+ )
+ mock_deep_get.assert_called_once_with(
+ tasks_by_target_record_id, net_text, "extra_dict", "params", "net_type"
+ )
+
+ @patch("osm_ng_ro.ns.deep_get")
+ def test_prepare_type_of_interface_type_pic_passthrough_deep_get_return_empty_dict(
+ self, mock_deep_get
+ ):
+ """Interface type is PCI-PASSTHROUGH, deep_get method return empty dict."""
+ interface = {
+ "name": "vdu-eth0",
+ "vcpi": "sample_vcpi",
+ "port_security": True,
+ "port_security_disable_strategy": "allow-address-pairs",
+ "floating_ip": "10.1.1.12",
+ "ns-vld-id": "mgmtnet",
+ "vnf-vld-id": "mgmt_cp_int",
+ "type": "PCI-PASSTHROUGH",
+ }
+ mock_deep_get.return_value = {}
+ tasks_by_target_record_id = {}
+ net_text = ns_preffix
+ net_item = {}
+ expected_net_item = {
+ "use": "data",
+ "model": "PCI-PASSTHROUGH",
+ "type": "PCI-PASSTHROUGH",
+ }
+ self.ns._prepare_type_of_interface(
+ interface, tasks_by_target_record_id, net_text, net_item
+ )
+ self.assertDictEqual(net_item, expected_net_item)
+ mock_deep_get.assert_called_once_with(
+ tasks_by_target_record_id, net_text, "extra_dict", "params", "net_type"
+ )
+
+ @patch("osm_ng_ro.ns.deep_get")
+ def test_prepare_type_of_interface_type_mgmt(self, mock_deep_get):
+ """Interface type is mgmt."""
+ interface = {
+ "name": "vdu-eth0",
+ "vcpi": "sample_vcpi",
+ "port_security": True,
+ "port_security_disable_strategy": "allow-address-pairs",
+ "floating_ip": "10.1.1.12",
+ "ns-vld-id": "mgmtnet",
+ "vnf-vld-id": "mgmt_cp_int",
+ "type": "OM-MGMT",
+ }
+ tasks_by_target_record_id = {}
+ net_text = ns_preffix
+ net_item = {}
+ expected_net_item = {
+ "use": "mgmt",
+ }
+ self.ns._prepare_type_of_interface(
+ interface, tasks_by_target_record_id, net_text, net_item
+ )
+ self.assertDictEqual(net_item, expected_net_item)
+ mock_deep_get.assert_not_called()
+
+ @patch("osm_ng_ro.ns.deep_get")
+ def test_prepare_type_of_interface_type_bridge(self, mock_deep_get):
+ """Interface type is bridge."""
+ interface = {
+ "name": "vdu-eth0",
+ "vcpi": "sample_vcpi",
+ "port_security": True,
+ "port_security_disable_strategy": "allow-address-pairs",
+ "floating_ip": "10.1.1.12",
+ "ns-vld-id": "mgmtnet",
+ "vnf-vld-id": "mgmt_cp_int",
+ }
+ tasks_by_target_record_id = {}
+ net_text = ns_preffix
+ net_item = {}
+ expected_net_item = {
+ "use": "bridge",
+ "model": None,
+ }
+ self.ns._prepare_type_of_interface(
+ interface, tasks_by_target_record_id, net_text, net_item
+ )
+ self.assertDictEqual(net_item, expected_net_item)
+ mock_deep_get.assert_not_called()
+
+ @patch("osm_ng_ro.ns.Ns._check_vld_information_of_interfaces")
+ @patch("osm_ng_ro.ns.Ns._prepare_interface_port_security")
+ @patch("osm_ng_ro.ns.Ns._create_net_item_of_interface")
+ @patch("osm_ng_ro.ns.Ns._prepare_type_of_interface")
+ def test_prepare_vdu_interfaces(
+ self,
+ mock_type_of_interface,
+ mock_item_of_interface,
+ mock_port_security,
+ mock_vld_information_of_interface,
+ ):
+ """Prepare vdu interfaces successfully."""
+ target_vdu = deepcopy(target_vdu_wth_persistent_storage)
+ interface_1 = {
+ "name": "vdu-eth1",
+ "ns-vld-id": "net1",
+ "ip-address": "13.2.12.31",
+ "mgmt-interface": True,
+ }
+ interface_2 = {
+ "name": "vdu-eth2",
+ "vnf-vld-id": "net2",
+ "mac-address": "d0:94:66:ed:fc:e2",
+ }
+ interface_3 = {
+ "name": "vdu-eth3",
+ "ns-vld-id": "mgmtnet",
+ }
+ target_vdu["interfaces"] = [interface_1, interface_2, interface_3]
+ extra_dict = {
+ "params": "test_params",
+ "find_params": "test_find_params",
+ "depends_on": [],
+ }
+
+ net_text_1 = f"{ns_preffix}:net1"
+ net_text_2 = f"{vnf_preffix}:net2"
+ net_text_3 = f"{ns_preffix}:mgmtnet"
+ net_item_1 = {
+ "name": "vdu-eth1",
+ "net_id": f"TASK-{ns_preffix}",
+ "type": "virtual",
+ }
+ net_item_2 = {
+ "name": "vdu-eth2",
+ "net_id": f"TASK-{ns_preffix}",
+ "type": "virtual",
+ }
+ net_item_3 = {
+ "name": "vdu-eth3",
+ "net_id": f"TASK-{ns_preffix}",
+ "type": "virtual",
+ }
+ mock_item_of_interface.side_effect = [net_item_1, net_item_2, net_item_3]
+ mock_vld_information_of_interface.side_effect = [
+ net_text_1,
+ net_text_2,
+ net_text_3,
+ ]
+ net_list = []
+ expected_extra_dict = {
+ "params": "test_params",
+ "find_params": "test_find_params",
+ "depends_on": [net_text_1, net_text_2, net_text_3],
+ "mgmt_vdu_interface": 0,
+ }
+ updated_net_item1 = deepcopy(net_item_1)
+ updated_net_item1.update({"ip_address": "13.2.12.31"})
+ updated_net_item2 = deepcopy(net_item_2)
+ updated_net_item2.update({"mac_address": "d0:94:66:ed:fc:e2"})
+ expected_net_list = [updated_net_item1, updated_net_item2, net_item_3]
+ self.ns._prepare_vdu_interfaces(
+ target_vdu,
+ extra_dict,
+ ns_preffix,
+ vnf_preffix,
+ self.logger,
+ tasks_by_target_record_id,
+ net_list,
+ )
+ _call_mock_vld_information_of_interface = (
+ mock_vld_information_of_interface.call_args_list
+ )
+ self.assertEqual(
+ _call_mock_vld_information_of_interface[0][0],
+ (interface_1, ns_preffix, vnf_preffix),
+ )
+ self.assertEqual(
+ _call_mock_vld_information_of_interface[1][0],
+ (interface_2, ns_preffix, vnf_preffix),
+ )
+ self.assertEqual(
+ _call_mock_vld_information_of_interface[2][0],
+ (interface_3, ns_preffix, vnf_preffix),
+ )
+
+ _call_mock_port_security = mock_port_security.call_args_list
+ self.assertEqual(_call_mock_port_security[0].args[0], interface_1)
+ self.assertEqual(_call_mock_port_security[1].args[0], interface_2)
+ self.assertEqual(_call_mock_port_security[2].args[0], interface_3)
+
+ _call_mock_item_of_interface = mock_item_of_interface.call_args_list
+ self.assertEqual(_call_mock_item_of_interface[0][0], (interface_1, net_text_1))
+ self.assertEqual(_call_mock_item_of_interface[1][0], (interface_2, net_text_2))
+ self.assertEqual(_call_mock_item_of_interface[2][0], (interface_3, net_text_3))
+
+ _call_mock_type_of_interface = mock_type_of_interface.call_args_list
+ self.assertEqual(
+ _call_mock_type_of_interface[0][0],
+ (interface_1, tasks_by_target_record_id, net_text_1, net_item_1),
+ )
+ self.assertEqual(
+ _call_mock_type_of_interface[1][0],
+ (interface_2, tasks_by_target_record_id, net_text_2, net_item_2),
+ )
+ self.assertEqual(
+ _call_mock_type_of_interface[2][0],
+ (interface_3, tasks_by_target_record_id, net_text_3, net_item_3),
+ )
+ self.assertEqual(net_list, expected_net_list)
+ self.assertEqual(extra_dict, expected_extra_dict)
+ self.logger.error.assert_not_called()
+
+ @patch("osm_ng_ro.ns.Ns._check_vld_information_of_interfaces")
+ @patch("osm_ng_ro.ns.Ns._prepare_interface_port_security")
+ @patch("osm_ng_ro.ns.Ns._create_net_item_of_interface")
+ @patch("osm_ng_ro.ns.Ns._prepare_type_of_interface")
+ def test_prepare_vdu_interfaces_create_net_item_raise_exception(
+ self,
+ mock_type_of_interface,
+ mock_item_of_interface,
+ mock_port_security,
+ mock_vld_information_of_interface,
+ ):
+ """Prepare vdu interfaces, create_net_item_of_interface method raise exception."""
+ target_vdu = deepcopy(target_vdu_wth_persistent_storage)
+ interface_1 = {
+ "name": "vdu-eth1",
+ "ns-vld-id": "net1",
+ "ip-address": "13.2.12.31",
+ "mgmt-interface": True,
+ }
+ interface_2 = {
+ "name": "vdu-eth2",
+ "vnf-vld-id": "net2",
+ "mac-address": "d0:94:66:ed:fc:e2",
+ }
+ interface_3 = {
+ "name": "vdu-eth3",
+ "ns-vld-id": "mgmtnet",
+ }
+ target_vdu["interfaces"] = [interface_1, interface_2, interface_3]
+ extra_dict = {
+ "params": "test_params",
+ "find_params": "test_find_params",
+ "depends_on": [],
+ }
+ net_text_1 = f"{ns_preffix}:net1"
+ mock_item_of_interface.side_effect = [TypeError, TypeError, TypeError]
+
+ mock_vld_information_of_interface.side_effect = [net_text_1]
+ net_list = []
+ expected_extra_dict = {
+ "params": "test_params",
+ "find_params": "test_find_params",
+ "depends_on": [net_text_1],
+ }
+ with self.assertRaises(TypeError):
+ self.ns._prepare_vdu_interfaces(
+ target_vdu,
+ extra_dict,
+ ns_preffix,
+ vnf_preffix,
+ self.logger,
+ tasks_by_target_record_id,
+ net_list,
+ )
+
+ _call_mock_vld_information_of_interface = (
+ mock_vld_information_of_interface.call_args_list
+ )
+ self.assertEqual(
+ _call_mock_vld_information_of_interface[0][0],
+ (interface_1, ns_preffix, vnf_preffix),
+ )
+
+ _call_mock_port_security = mock_port_security.call_args_list
+ self.assertEqual(_call_mock_port_security[0].args[0], interface_1)
+
+ _call_mock_item_of_interface = mock_item_of_interface.call_args_list
+ self.assertEqual(_call_mock_item_of_interface[0][0], (interface_1, net_text_1))
+
+ mock_type_of_interface.assert_not_called()
+ self.logger.error.assert_not_called()
+ self.assertEqual(net_list, [])
+ self.assertEqual(extra_dict, expected_extra_dict)
+
+ @patch("osm_ng_ro.ns.Ns._check_vld_information_of_interfaces")
+ @patch("osm_ng_ro.ns.Ns._prepare_interface_port_security")
+ @patch("osm_ng_ro.ns.Ns._create_net_item_of_interface")
+ @patch("osm_ng_ro.ns.Ns._prepare_type_of_interface")
+ def test_prepare_vdu_interfaces_vld_information_is_empty(
+ self,
+ mock_type_of_interface,
+ mock_item_of_interface,
+ mock_port_security,
+ mock_vld_information_of_interface,
+ ):
+ """Prepare vdu interfaces, check_vld_information_of_interface method returns empty result."""
+ target_vdu = deepcopy(target_vdu_wth_persistent_storage)
+ interface_1 = {
+ "name": "vdu-eth1",
+ "ns-vld-id": "net1",
+ "ip-address": "13.2.12.31",
+ "mgmt-interface": True,
+ }
+ interface_2 = {
+ "name": "vdu-eth2",
+ "vnf-vld-id": "net2",
+ "mac-address": "d0:94:66:ed:fc:e2",
+ }
+ interface_3 = {
+ "name": "vdu-eth3",
+ "ns-vld-id": "mgmtnet",
+ }
+ target_vdu["interfaces"] = [interface_1, interface_2, interface_3]
+ extra_dict = {
+ "params": "test_params",
+ "find_params": "test_find_params",
+ "depends_on": [],
+ }
+ mock_vld_information_of_interface.side_effect = ["", "", ""]
+ net_list = []
+ self.ns._prepare_vdu_interfaces(
+ target_vdu,
+ extra_dict,
+ ns_preffix,
+ vnf_preffix,
+ self.logger,
+ tasks_by_target_record_id,
+ net_list,
+ )
+
+ _call_mock_vld_information_of_interface = (
+ mock_vld_information_of_interface.call_args_list
+ )
+ self.assertEqual(
+ _call_mock_vld_information_of_interface[0][0],
+ (interface_1, ns_preffix, vnf_preffix),
+ )
+ self.assertEqual(
+ _call_mock_vld_information_of_interface[1][0],
+ (interface_2, ns_preffix, vnf_preffix),
+ )
+ self.assertEqual(
+ _call_mock_vld_information_of_interface[2][0],
+ (interface_3, ns_preffix, vnf_preffix),
+ )
+
+ _call_logger = self.logger.error.call_args_list
+ self.assertEqual(
+ _call_logger[0][0],
+ ("Interface 0 from vdu several_volumes-VM not connected to any vld",),
+ )
+ self.assertEqual(
+ _call_logger[1][0],
+ ("Interface 1 from vdu several_volumes-VM not connected to any vld",),
+ )
+ self.assertEqual(
+ _call_logger[2][0],
+ ("Interface 2 from vdu several_volumes-VM not connected to any vld",),
+ )
+ self.assertEqual(net_list, [])
+ self.assertEqual(
+ extra_dict,
+ {
+ "params": "test_params",
+ "find_params": "test_find_params",
+ "depends_on": [],
+ },
+ )
+
+ mock_item_of_interface.assert_not_called()
+ mock_port_security.assert_not_called()
+ mock_type_of_interface.assert_not_called()
+
+ @patch("osm_ng_ro.ns.Ns._check_vld_information_of_interfaces")
+ @patch("osm_ng_ro.ns.Ns._prepare_interface_port_security")
+ @patch("osm_ng_ro.ns.Ns._create_net_item_of_interface")
+ @patch("osm_ng_ro.ns.Ns._prepare_type_of_interface")
+ def test_prepare_vdu_interfaces_empty_interface_list(
+ self,
+ mock_type_of_interface,
+ mock_item_of_interface,
+ mock_port_security,
+ mock_vld_information_of_interface,
+ ):
+ """Prepare vdu interfaces, interface list is empty."""
+ target_vdu = deepcopy(target_vdu_wth_persistent_storage)
+ target_vdu["interfaces"] = []
+ extra_dict = {}
+ net_list = []
+ self.ns._prepare_vdu_interfaces(
+ target_vdu,
+ extra_dict,
+ ns_preffix,
+ vnf_preffix,
+ self.logger,
+ tasks_by_target_record_id,
+ net_list,
+ )
+ mock_type_of_interface.assert_not_called()
+ mock_vld_information_of_interface.assert_not_called()
+ mock_item_of_interface.assert_not_called()
+ mock_port_security.assert_not_called()
+
+ def test_prepare_vdu_ssh_keys(self):
+ """Target_vdu has ssh-keys and ro_nsr_public_key exists."""
+ target_vdu = deepcopy(target_vdu_wth_persistent_storage)
+ target_vdu["ssh-keys"] = ["sample-ssh-key"]
+ ro_nsr_public_key = {"public_key": "path_of_public_key"}
+ target_vdu["ssh-access-required"] = True
+ cloud_config = {}
+ expected_cloud_config = {
+ "key-pairs": ["sample-ssh-key", {"public_key": "path_of_public_key"}]
+ }
+ self.ns._prepare_vdu_ssh_keys(target_vdu, ro_nsr_public_key, cloud_config)
+ self.assertDictEqual(cloud_config, expected_cloud_config)
+
+ def test_prepare_vdu_ssh_keys_target_vdu_wthout_ssh_keys(self):
+ """Target_vdu does not have ssh-keys."""
+ target_vdu = deepcopy(target_vdu_wth_persistent_storage)
+ ro_nsr_public_key = {"public_key": "path_of_public_key"}
+ target_vdu["ssh-access-required"] = True
+ cloud_config = {}
+ expected_cloud_config = {"key-pairs": [{"public_key": "path_of_public_key"}]}
+ self.ns._prepare_vdu_ssh_keys(target_vdu, ro_nsr_public_key, cloud_config)
+ self.assertDictEqual(cloud_config, expected_cloud_config)
+
+ def test_prepare_vdu_ssh_keys_ssh_access_is_not_required(self):
+ """Target_vdu has ssh-keys, ssh-access is not required."""
+ target_vdu = deepcopy(target_vdu_wth_persistent_storage)
+ target_vdu["ssh-keys"] = ["sample-ssh-key"]
+ ro_nsr_public_key = {"public_key": "path_of_public_key"}
+ target_vdu["ssh-access-required"] = False
+ cloud_config = {}
+ expected_cloud_config = {"key-pairs": ["sample-ssh-key"]}
+ self.ns._prepare_vdu_ssh_keys(target_vdu, ro_nsr_public_key, cloud_config)
+ self.assertDictEqual(cloud_config, expected_cloud_config)
+
+ @patch("osm_ng_ro.ns.Ns._select_persistent_root_disk")
+ @patch("osm_ng_ro.ns.Ns.is_volume_keeping_required")
+ def test_add_persistent_root_disk_to_disk_list_keep_false(
+ self, mock_volume_keeping_required, mock_select_persistent_root_disk
+ ):
+ """Add persistent root disk to disk_list, keep volume set to False."""
+ root_disk = {
+ "id": "persistent-root-volume",
+ "type-of-storage": "persistent-storage:persistent-storage",
+ "size-of-storage": "10",
+ }
+ mock_select_persistent_root_disk.return_value = root_disk
+ vnfd = deepcopy(vnfd_wth_persistent_storage)
+ vnfd["virtual-storage-desc"][1] = root_disk
+ target_vdu = deepcopy(target_vdu_wth_persistent_storage)
+ persistent_root_disk = {}
+ disk_list = []
+ mock_volume_keeping_required.return_value = False
+ expected_disk_list = [
+ {
+ "image_id": "ubuntu20.04",
+ "size": "10",
+ "keep": False,
+ }
+ ]
+ self.ns._add_persistent_root_disk_to_disk_list(
+ vnfd, target_vdu, persistent_root_disk, disk_list
+ )
+ self.assertEqual(disk_list, expected_disk_list)
+ mock_select_persistent_root_disk.assert_called_once()
+ mock_volume_keeping_required.assert_called_once()
+
+ @patch("osm_ng_ro.ns.Ns._select_persistent_root_disk")
+ @patch("osm_ng_ro.ns.Ns.is_volume_keeping_required")
+ def test_add_persistent_root_disk_to_disk_list_select_persistent_root_disk_raises(
+ self, mock_volume_keeping_required, mock_select_persistent_root_disk
+ ):
+ """Add persistent root disk to disk_list"""
+ root_disk = {
+ "id": "persistent-root-volume",
+ "type-of-storage": "persistent-storage:persistent-storage",
+ "size-of-storage": "10",
+ }
+ mock_select_persistent_root_disk.side_effect = AttributeError
+ vnfd = deepcopy(vnfd_wth_persistent_storage)
+ vnfd["virtual-storage-desc"][1] = root_disk
+ target_vdu = deepcopy(target_vdu_wth_persistent_storage)
+ persistent_root_disk = {}
+ disk_list = []
+ with self.assertRaises(AttributeError):
+ self.ns._add_persistent_root_disk_to_disk_list(
+ vnfd, target_vdu, persistent_root_disk, disk_list
+ )
+ self.assertEqual(disk_list, [])
+ mock_select_persistent_root_disk.assert_called_once()
+ mock_volume_keeping_required.assert_not_called()
+
+ @patch("osm_ng_ro.ns.Ns._select_persistent_root_disk")
+ @patch("osm_ng_ro.ns.Ns.is_volume_keeping_required")
+ def test_add_persistent_root_disk_to_disk_list_keep_true(
+ self, mock_volume_keeping_required, mock_select_persistent_root_disk
+ ):
+ """Add persistent root disk, keeo volume set to True."""
+ vnfd = deepcopy(vnfd_wth_persistent_storage)
+ target_vdu = deepcopy(target_vdu_wth_persistent_storage)
+ mock_volume_keeping_required.return_value = True
+ root_disk = {
+ "id": "persistent-root-volume",
+ "type-of-storage": "persistent-storage:persistent-storage",
+ "size-of-storage": "10",
+ "vdu-storage-requirements": [
+ {"key": "keep-volume", "value": "true"},