@asynctest.mock.patch("n2vc.n2vc_juju_conn.get_connection")
@asynctest.mock.patch("n2vc.vca.connection_data.base64_to_cacert")
def setUp(
- self,
- mock_base64_to_cacert=None,
- mock_get_connection=None,
- mock_store=None,
+ self, mock_base64_to_cacert=None, mock_get_connection=None, mock_store=None
):
self.loop = asyncio.get_event_loop()
self.db = Mock()
db=self.db,
fs=fslocal.FsLocal(),
log=None,
- loop=self.loop,
on_update_db=None,
)
N2VCJujuConnector.get_public_key.assert_not_called()
"n2vc.n2vc_juju_conn.generate_random_alfanum_string",
**{"return_value": "random"}
)
- def test_success(
- self,
- mock_generate_random_alfanum_string,
- ):
+ def test_success(self, mock_generate_random_alfanum_string):
self.n2vc.fs.file_exists = MagicMock(create_autospec=True)
self.n2vc.fs.file_exists.return_value = True
ee_id = self.loop.run_until_complete(
self.n2vc.libjuju.get_controller = AsyncMock()
self.n2vc.libjuju.consume = AsyncMock()
- def test_standard_relation(self):
- relation_endpoint_1 = RelationEndpoint("model-1.app1.0", None, "endpoint")
- relation_endpoint_2 = RelationEndpoint("model-1.app2.1", None, "endpoint")
+ def test_standard_relation_same_model_and_controller(self):
+ relation_endpoint_1 = RelationEndpoint("model-1.app1.0", None, "endpoint1")
+ relation_endpoint_2 = RelationEndpoint("model-1.app2.1", None, "endpoint2")
self.loop.run_until_complete(
self.n2vc.add_relation(relation_endpoint_1, relation_endpoint_2)
)
self.n2vc.libjuju.add_relation.assert_called_once_with(
- model_name="model-1", endpoint_1="app1:endpoint", endpoint_2="app2:endpoint"
+ model_name="model-1",
+ endpoint_1="app1:endpoint1",
+ endpoint_2="app2:endpoint2",
)
self.n2vc.libjuju.offer.assert_not_called()
self.n2vc.libjuju.consume.assert_not_called()
"model-2", "app2:endpoint", "saas"
)
+ def test_cmr_relation_different_controller(self):
+ self.n2vc._get_libjuju = AsyncMock(return_value=self.n2vc.libjuju)
+ relation_endpoint_1 = RelationEndpoint(
+ "model-1.app1.0", "vca-id-1", "endpoint1"
+ )
+ relation_endpoint_2 = RelationEndpoint(
+ "model-1.app2.1", "vca-id-2", "endpoint2"
+ )
+ offer = Offer("admin/model-1.app1")
+ self.n2vc.libjuju.offer.return_value = offer
+ self.n2vc.libjuju.consume.return_value = "saas"
+ self.loop.run_until_complete(
+ self.n2vc.add_relation(relation_endpoint_1, relation_endpoint_2)
+ )
+ self.n2vc.libjuju.offer.assert_called_once_with(relation_endpoint_1)
+ self.n2vc.libjuju.consume.assert_called_once()
+ self.n2vc.libjuju.add_relation.assert_called_once_with(
+ "model-1", "app2:endpoint2", "saas"
+ )
+
def test_relation_exception(self):
relation_endpoint_1 = RelationEndpoint("model-1.app1.0", None, "endpoint")
relation_endpoint_2 = RelationEndpoint("model-2.app2.1", None, "endpoint")
class GenerateApplicationNameTest(N2VCJujuConnTestCase):
-
vnf_id = "dbfbd751-3de4-4e68-bd40-ec5ae0a53898"
def setUp(self):
"ee_id": None,
"application": "",
"model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
- },
+ }
]
vnf_count = ""
vdu_count = ""
+ vdu_id = None
expected_result = "simple-ns-charm-abc-000-rrrr-nnnn-4444-h-ns"
application_name = self.n2vc._generate_application_name(
charm_level,
vnfrs,
vca_records,
vnf_count=vnf_count,
+ vdu_id=vdu_id,
vdu_count=vdu_count,
)
self.assertEqual(application_name, expected_result)
vca_records = []
vnf_count = ""
vdu_count = ""
+ vdu_id = None
with self.assertRaises(N2VCException):
self.n2vc._generate_application_name(
charm_level,
vnfrs,
vca_records,
vnf_count=vnf_count,
+ vdu_id=vdu_id,
vdu_count=vdu_count,
)
def test_generate_application_name_vnf_charm(self):
charm_level = "vnf-level"
- vnfrs = {
- "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
- }
+ vnfrs = {"member-vnf-index-ref": "vnf111-xxx-yyy-zzz"}
vca_records = [
{
"target_element": "vnf/vnf1",
"ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
"charm_name": "",
"model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
- },
+ }
]
vnf_count = "1"
vdu_count = ""
+ vdu_id = None
expected_result = "simple-ee-ab-1-vnf111-xxx-y-vnf"
application_name = self.n2vc._generate_application_name(
charm_level,
vnfrs,
vca_records,
vnf_count=vnf_count,
+ vdu_id=vdu_id,
vdu_count=vdu_count,
)
self.assertEqual(application_name, expected_result)
self.assertLess(len(application_name), 50)
- def test_generate_application_name_vdu_charm(self):
+ def test_generate_application_name_vdu_charm_kdu_name_in_vca_record_is_none(self):
charm_level = "vdu-level"
vnfrs = {
"member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
{
"target_element": "vnf/vnf1/mgmtvm",
"member-vnf-index": "vnf111-xxx-yyy-zzz",
- "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
+ "vdu_id": "mgmtVM",
"kdu_name": None,
"vdu_count_index": None,
"vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
"model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
},
{
- "target_element": "vnf/vnf1/datavm",
+ "target_element": "vnf/vnf1/dataVM",
"member-vnf-index": "vnf111-xxx-yyy-zzz",
- "vdu_id": "45512ff7-5bdd-4228-911f-c2bee259c44a",
+ "vdu_id": "dataVM",
"kdu_name": None,
"vdu_count_index": None,
"vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
]
vnf_count = "2"
vdu_count = "0"
+ vdu_id = "mgmtVM"
expected_result = "simple-ee-ab-2-vnf111-xxx-y-mgmtVM-0-vdu"
application_name = self.n2vc._generate_application_name(
charm_level,
vnfrs,
vca_records,
vnf_count=vnf_count,
+ vdu_id=vdu_id,
vdu_count=vdu_count,
)
self.assertEqual(application_name, expected_result)
self.assertLess(len(application_name), 50)
- def test_generate_application_name_vdu_charm_wrong_vnfrs(self):
+ def test_generate_application_name_vdu_charm_vdu_id_kdu_name_in_vca_record_are_both_set(
+ self,
+ ):
charm_level = "vdu-level"
vnfrs = {
"member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
+ "vdur": [
+ {"_id": "38912ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "mgmtVM"},
+ {"_id": "45512ff7-5bdd-4228-911f-c2bee259c44a", "vdu-id-ref": "dataVM"},
+ ],
}
vca_records = [
{
- "target_element": "vnf/vnf1/mgmtvm",
+ "target_element": "vnf/vnf1/mgmtVM",
"member-vnf-index": "vnf111-xxx-yyy-zzz",
- "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
- "kdu_name": None,
+ "vdu_id": "mgmtVM",
+ "kdu_name": "mgmtVM",
"vdu_count_index": None,
"vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
"vdu_name": "mgmtvm",
"charm_name": "",
"model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
},
+ {
+ "target_element": "vnf/vnf1/dataVM",
+ "member-vnf-index": "vnf111-xxx-yyy-zzz",
+ "vdu_id": "dataVM",
+ "kdu_name": None,
+ "vdu_count_index": None,
+ "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
+ "vdu_name": "datavm",
+ "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-8888-hhh-3333-yyyy-888-hhh-ttt-444",
+ "charm_name": "",
+ "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
+ },
]
vnf_count = "2"
vdu_count = "0"
+ vdu_id = "mgmtVM"
+ expected_result = "simple-ee-ab-2-vnf111-xxx-y-mgmtVM-0-vdu"
+ application_name = self.n2vc._generate_application_name(
+ charm_level,
+ vnfrs,
+ vca_records,
+ vnf_count=vnf_count,
+ vdu_id=vdu_id,
+ vdu_count=vdu_count,
+ )
+ self.assertEqual(application_name, expected_result)
+ self.assertLess(len(application_name), 50)
+
+ def test_generate_application_name_vdu_charm_both_vdu_id_kdu_name_in_vca_record_are_none(
+ self,
+ ):
+ charm_level = "vdu-level"
+ vnfrs = {"member-vnf-index-ref": "vnf111-xxx-yyy-zzz"}
+ vca_records = [
+ {
+ "target_element": "vnf/vnf1/mgmtVM",
+ "member-vnf-index": "vnf111-xxx-yyy-zzz",
+ "vdu_id": None,
+ "kdu_name": None,
+ "vdu_count_index": None,
+ "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
+ "vdu_name": "mgmtvm",
+ "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
+ "charm_name": "",
+ "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
+ }
+ ]
+ vnf_count = "2"
+ vdu_count = "0"
+ vdu_id = "mgmtVM"
with self.assertRaises(KeyError):
self.n2vc._generate_application_name(
charm_level,
vnfrs,
vca_records,
vnf_count=vnf_count,
+ vdu_id=vdu_id,
vdu_count=vdu_count,
)
+ def test_generate_application_name_vdu_charm_given_vdu_id_is_none(self):
+ charm_level = "vdu-level"
+ vnfrs = {"member-vnf-index-ref": "vnf111-xxx-yyy-zzz"}
+ vca_records = [
+ {
+ "target_element": "vnf/vnf1/mgmtvVM",
+ "member-vnf-index": "vnf111-xxx-yyy-zzz",
+ "vdu_id": None,
+ "kdu_name": "mgmtVM",
+ "vdu_count_index": None,
+ "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
+ "vdu_name": "mgmtvm",
+ "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
+ "charm_name": "",
+ "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
+ }
+ ]
+ vnf_count = "2"
+ vdu_count = "0"
+ vdu_id = None
+ with self.assertRaises(N2VCException):
+ self.n2vc._generate_application_name(
+ charm_level,
+ vnfrs,
+ vca_records,
+ vnf_count=vnf_count,
+ vdu_id=vdu_id,
+ vdu_count=vdu_count,
+ )
+
+ def test_generate_application_name_vdu_charm_vdu_id_does_not_match_with_the_key_in_vca_record(
+ self,
+ ):
+ charm_level = "vdu-level"
+ vnfrs = {"member-vnf-index-ref": "vnf111-xxx-yyy-zzz"}
+ vca_records = [
+ {
+ "target_element": "vnf/vnf1/mgmtVM",
+ "member-vnf-index": "vnf111-xxx-yyy-zzz",
+ "vdu_id": None,
+ "kdu_name": "mgmtVM",
+ "vdu_count_index": None,
+ "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
+ "vdu_name": "mgmtvm",
+ "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
+ "charm_name": "",
+ "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
+ }
+ ]
+ vnf_count = "2"
+ vdu_count = "0"
+ vdu_id = "mgmtvm"
+ with self.assertRaises(KeyError):
+ self.n2vc._generate_application_name(
+ charm_level,
+ vnfrs,
+ vca_records,
+ vnf_count=vnf_count,
+ vdu_id=vdu_id,
+ vdu_count=vdu_count,
+ )
+
+ def test_generate_application_name_vdu_charm_vdu_id_in_vca_record_is_none(self):
+ charm_level = "vdu-level"
+ vnfrs = {"member-vnf-index-ref": "vnf111-xxx-yyy-zzz"}
+ vca_records = [
+ {
+ "target_element": "vnf/vnf1/mgmtVM",
+ "member-vnf-index": "vnf111-xxx-yyy-zzz",
+ "vdu_id": None,
+ "kdu_name": "mgmtVM",
+ "vdu_count_index": None,
+ "vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
+ "vdu_name": "mgmtvm",
+ "ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
+ "charm_name": "",
+ "model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
+ }
+ ]
+ vnf_count = "2"
+ vdu_count = "0"
+ vdu_id = "mgmtVM"
+ expected_result = "simple-ee-ab-2-vnf111-xxx-y-mgmtVM-0-vdu"
+ application_name = self.n2vc._generate_application_name(
+ charm_level,
+ vnfrs,
+ vca_records,
+ vnf_count=vnf_count,
+ vdu_id=vdu_id,
+ vdu_count=vdu_count,
+ )
+ self.assertEqual(application_name, expected_result)
+ self.assertLess(len(application_name), 50)
+
def test_get_vnf_count_db_vnfr_ns_charm(self):
self.db.get_one.return_value = {"member-vnf-index-ref": "sample-ref"}
charm_level = "ns-level"
"charm_name": "",
"model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
},
- ],
- },
- },
+ ]
+ }
+ }
}
expected_result = [
{
"ee_descriptor_id": "simple-ee-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
"charm_name": "",
"model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
- },
+ }
]
vca_records = self.n2vc._get_vca_records(charm_level, db_nsr, db_vnfr)
self.assertEqual(vca_records, expected_result)
def test_get_vca_records_vnf_charm_member_vnf_index_mismatch(self):
charm_level = "vnf-level"
- db_vnfr = {
- "member-vnf-index-ref": "vnf222-xxx-yyy-zzz",
- }
+ db_vnfr = {"member-vnf-index-ref": "vnf222-xxx-yyy-zzz"}
db_nsr = {
"_admin": {
"deployed": {
"charm_name": "",
"model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
},
- ],
- },
- },
+ ]
+ }
+ }
}
expected_result = []
vca_records = self.n2vc._get_vca_records(charm_level, db_nsr, db_vnfr)
def test_get_vca_records_ns_charm(self):
charm_level = "ns-level"
- db_vnfr = {
- "member-vnf-index-ref": "vnf222-xxx-yyy-zzz",
- }
+ db_vnfr = {"member-vnf-index-ref": "vnf222-xxx-yyy-zzz"}
db_nsr = {
"_admin": {
"deployed": {
"charm_name": "simple-ns-charm-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
"model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
},
- ],
- },
- },
+ ]
+ }
+ }
}
expected_result = [
{
"ee_descriptor_id": "",
"charm_name": "simple-ns-charm-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
"model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
- },
+ }
]
vca_records = self.n2vc._get_vca_records(charm_level, db_nsr, db_vnfr)
self.assertEqual(vca_records, expected_result)
def test_get_vca_records_ns_charm_empty_charm_name(self):
charm_level = "ns-level"
- db_vnfr = {
- "member-vnf-index-ref": "vnf222-xxx-yyy-zzz",
- }
+ db_vnfr = {"member-vnf-index-ref": "vnf222-xxx-yyy-zzz"}
db_nsr = {
"_admin": {
"deployed": {
"charm_name": "",
"model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
},
- ],
- },
- },
+ ]
+ }
+ }
}
expected_result = [
{
"ee_descriptor_id": "",
"charm_name": "",
"model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
- },
+ }
]
vca_records = self.n2vc._get_vca_records(charm_level, db_nsr, db_vnfr)
self.assertEqual(vca_records, expected_result)
"charm_name": "",
"model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
},
- ],
- },
- },
+ ]
+ }
+ }
}
mock_vnf_count_and_record = MagicMock()
- db_vnfr = {
- "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
- }
+ db_vnfr = {"member-vnf-index-ref": "vnf111-xxx-yyy-zzz"}
vnf_count = "0"
mock_vnf_count_and_record.return_value = (vnf_count, db_vnfr)
expected_result = "simple-ee-ab-z0-vnf111-xxx-y-vnf"
"ee_descriptor_id": "",
"model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
},
- ],
- },
- },
+ ]
+ }
+ }
}
mock_vnf_count_and_record = MagicMock()
- db_vnfr = {
- "member-vnf-index-ref": "vnf111-xxx-yyy-zzz",
- }
+ db_vnfr = {"member-vnf-index-ref": "vnf111-xxx-yyy-zzz"}
vnf_count = "0"
mock_vnf_count_and_record.return_value = (vnf_count, db_vnfr)
expected_result = "app-vnf-eb3161eec0-z0-random"
"charm_name": "",
"model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
},
- ],
- },
- },
+ ]
+ }
+ }
}
mock_vnf_count_and_record = MagicMock()
- db_vnfr = {
- "member-vnf-index-ref": "vnf222-xxx-yyy-zzz",
- }
+ db_vnfr = {"member-vnf-index-ref": "vnf222-xxx-yyy-zzz"}
vnf_count = "0"
mock_vnf_count_and_record.return_value = (vnf_count, db_vnfr)
with patch.object(self.n2vc, "db", self.db), patch.object(
{
"target_element": "vnf/vnf1/mgmtvm",
"member-vnf-index": "vnf111-xxx-yyy-zzz",
- "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
+ "vdu_id": "mgmtVM",
"kdu_name": None,
"vdu_count_index": None,
"vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
"application": "openldap-ee-z0-openldap-vdu",
"model": "82b11965-e580-47c0-9ee0-329f318a305b",
"config_sw_installed": True,
- },
+ }
]
}
}
}
mock_vnf_count_and_record = MagicMock()
- db_vnfr = {
- "member-vnf-index-ref": "openldap",
- "vdur": {},
- }
+ db_vnfr = {"member-vnf-index-ref": "openldap", "vdur": {}}
vnf_count = "0"
mock_vnf_count_and_record.return_value = (vnf_count, db_vnfr)
- expected_result = "openldap-ee-z0-openldap-vdu"
+ expected_result = "openldap-ee-z0-openldap-ldap-vdu"
with patch.object(self.n2vc, "db", self.db), patch.object(
self.n2vc, "_get_vnf_count_and_record", mock_vnf_count_and_record
):
"deployed": {
"VCA": [
{
- "target_element": "vnf/vnf1/mgmtvm",
+ "target_element": "vnf/vnf1/mgmtVM",
"member-vnf-index": "vnf111-xxx-yyy-zzz",
- "vdu_id": "38912ff7-5bdd-4228-911f-c2bee259c44a",
+ "vdu_id": "mgmtVM",
"kdu_name": None,
"vdu_count_index": None,
"vnfd_id": "r7fbd751-3de4-4e68-bd40-ec5ae0a53898",
"ee_descriptor_id": "",
"model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
},
- ],
- },
- },
+ ]
+ }
+ }
}
mock_vnf_count_and_record = MagicMock()
db_vnfr = {
"ee_descriptor_id": "",
"charm_name": "simple-ns-charm-abc-000-rrrr-nnnn-4444-hhh-3333-yyyy-333-hhh-ttt-444",
"model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
- },
- ],
- },
- },
+ }
+ ]
+ }
+ }
}
mock_vnf_count_and_record = MagicMock()
db_vnfr = {}
"ee_descriptor_id": "",
"charm_name": "",
"model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
- },
- ],
- },
- },
+ }
+ ]
+ }
+ }
}
mock_vnf_count_and_record = MagicMock()
db_vnfr = {}
"vdu_name": "",
"ee_descriptor_id": "",
"model": "dbfbd751-3de4-4e68-bd40-ec5ae0a53898",
- },
- ],
- },
- },
+ }
+ ]
+ }
+ }
}
mock_vnf_count_and_record = MagicMock()
db_vnfr = {}
self.assertLess(len(application_name), 50)
mock_vnf_count_and_record.assert_called_once_with("ns-level", None)
self.db.get_one.assert_called_once()
+
+
+class DeleteExecutionEnvironmentTest(N2VCJujuConnTestCase):
+ def setUp(self):
+ super(DeleteExecutionEnvironmentTest, self).setUp()
+ self.n2vc.libjuju.get_controller = AsyncMock()
+ self.n2vc.libjuju.destroy_model = AsyncMock()
+ self.n2vc.libjuju.destroy_application = AsyncMock()
+
+ def test_remove_ee__target_application_exists__model_is_deleted(self):
+ get_ee_id_components = MagicMock()
+ get_ee_id_components.return_value = ("my_model", "my_app", None)
+ model = MagicMock(create_autospec=True)
+ model.applications = {}
+ self.n2vc.libjuju.get_model = AsyncMock()
+ self.n2vc.libjuju.get_model.return_value = model
+ with patch.object(self.n2vc, "_get_ee_id_components", get_ee_id_components):
+ self.loop.run_until_complete(
+ self.n2vc.delete_execution_environment(
+ "my_ee", application_to_delete="my_app"
+ )
+ )
+ self.n2vc.libjuju.destroy_application.assert_called_with(
+ model_name="my_model",
+ application_name="my_app",
+ total_timeout=None,
+ )
+ self.n2vc.libjuju.destroy_model.assert_called_with(
+ model_name="my_model",
+ total_timeout=None,
+ )
+
+ def test_remove_ee__multiple_applications_exist__model_is_not_deleted(self):
+ get_ee_id_components = MagicMock()
+ get_ee_id_components.return_value = ("my_model", "my_app", None)
+ model = MagicMock(create_autospec=True)
+ model.applications = {MagicMock(create_autospec=True)}
+ self.n2vc.libjuju.get_model = AsyncMock()
+ self.n2vc.libjuju.get_model.return_value = model
+ with patch.object(self.n2vc, "_get_ee_id_components", get_ee_id_components):
+ self.loop.run_until_complete(
+ self.n2vc.delete_execution_environment(
+ "my_ee", application_to_delete="my_app"
+ )
+ )
+ self.n2vc.libjuju.destroy_application.assert_called_with(
+ model_name="my_model",
+ application_name="my_app",
+ total_timeout=None,
+ )
+ self.n2vc.libjuju.destroy_model.assert_not_called()
+
+ def test_remove_ee__target_application_does_not_exist__model_is_deleted(self):
+ get_ee_id_components = MagicMock()
+ get_ee_id_components.return_value = ("my_model", "my_app", None)
+ with patch.object(self.n2vc, "_get_ee_id_components", get_ee_id_components):
+ self.loop.run_until_complete(
+ self.n2vc.delete_execution_environment("my_ee")
+ )
+ self.n2vc.libjuju.destroy_model.assert_called_with(
+ model_name="my_model",
+ total_timeout=None,
+ )