__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
-""" Perform unittests using asynctest
+""" Perform unittests using asynctest of osm_lcm.ns module
It allows, if some testing ENV are supplied, testing without mocking some external libraries for debugging:
OSMLCMTEST_NS_PUBKEY: public ssh-key returned by N2VC to inject to VMs
+ OSMLCMTEST_NS_NAME: change name of NS
OSMLCMTEST_PACKAGES_PATH: path where the vnf-packages are stored (de-compressed), each one on a 'vnfd_id' folder
OSMLCMTEST_NS_IPADDRESS: IP address where emulated VMs are reached. Comma separate list
+ OSMLCMTEST_RO_VIMID: VIM id of RO target vim IP. Obtain it with openmano datcenter-list on RO container
OSMLCMTEST_VCA_NOMOCK: Do no mock the VCA, N2VC library, for debugging it
OSMLCMTEST_RO_NOMOCK: Do no mock the ROClient library, for debugging it
OSMLCMTEST_DB_NOMOCK: Do no mock the database library, for debugging it
- OSMLCMTEST_FS_NOMOCK: Do no mock the File Sorage library, for debugging it
+ OSMLCMTEST_FS_NOMOCK: Do no mock the File Storage library, for debugging it
OSMLCMTEST_LOGGING_NOMOCK: Do no mock the logging
OSMLCM_VCA_XXX: configuration of N2VC
OSMLCM_RO_XXX: configuration of RO
vca_config = { # TODO replace with os.get_env to get other configurations
"host": getenv("OSMLCM_VCA_HOST", "vca"),
- "port": 17070,
- "user": "admin",
- "secret": "secret",
+ "port": getenv("OSMLCM_VCA_PORT", 17070),
+ "user": getenv("OSMLCM_VCA_USER", "admin"),
+ "secret": getenv("OSMLCM_VCA_SECRET", "vca"),
+ "pubkey": getenv("OSMLCM_VCA_PUBKEY", None),
+ 'cacert': getenv("OSMLCM_VCA_CACERT", None)
}
ro_config = {
vcpu-count: 1
version: '1.0'
vnf-configuration:
+ config-access:
+ ssh-access:
+ required: True
+ default-user: ubuntu
config-primitive:
- name: touch
parameter:
yield "app_name-{}".format(num_calls)
num_calls += 1
- def _n2vc_CreateExecutionEnvironment(self, namespace):
+ def _n2vc_CreateExecutionEnvironment(self, namespace, reuse_ee_id, db_dict):
k_list = namespace.split(".")
ee_id = k_list[1] + "."
if len(k_list) >= 2:
ee_id += k[:8]
else:
ee_id += "_NS_"
- return ee_id
+ return ee_id, {}
def _ro_show(self, *args, **kwargs):
ro_ns_desc = yaml.load(ro_ns_text)
# allow several versions of n2vc
self.my_ns.n2vc.FormatApplicationName = asynctest.Mock(side_effect=self._n2vc_FormatApplicationName())
self.my_ns.n2vc.DeployCharms = asynctest.CoroutineMock(side_effect=self._n2vc_DeployCharms)
- self.my_ns.n2vc.CreateExecutionEnvironment = asynctest.CoroutineMock(
+ self.my_ns.n2vc.create_execution_environment = asynctest.CoroutineMock(
side_effect=self._n2vc_CreateExecutionEnvironment)
- self.my_ns.n2vc.InstallConfigurationSW = asynctest.CoroutineMock(return_value=pub_key)
- self.my_ns.n2vc.ExecutePrimitive = asynctest.CoroutineMock(side_effect=self._return_uuid)
+ self.my_ns.n2vc.install_configuration_sw = asynctest.CoroutineMock(return_value=pub_key)
+ self.my_ns.n2vc.get_ee_ssh_public__key = asynctest.CoroutineMock(return_value=pub_key)
+ self.my_ns.n2vc.exec_primitive = asynctest.CoroutineMock(side_effect=self._return_uuid)
self.my_ns.n2vc.GetPrimitiveStatus = asynctest.CoroutineMock(return_value="completed")
self.my_ns.n2vc.GetPrimitiveOutput = asynctest.CoroutineMock(return_value={"result": "ok",
"pubkey": pub_key})
+ self.my_ns.n2vc.get_public_key = asynctest.CoroutineMock(
+ return_value=getenv("OSMLCM_VCA_PUBKEY", "public_key"))
# Mock RO
if not getenv("OSMLCMTEST_RO_NOMOCK"):
self.my_ns.RO.get_list = asynctest.CoroutineMock(self.my_ns.RO.get_list, return_value=[])
self.my_ns.RO.create = asynctest.CoroutineMock(self.my_ns.RO.create, side_effect=self._ro_create())
self.my_ns.RO.show = asynctest.CoroutineMock(self.my_ns.RO.show, side_effect=self._ro_show())
+ self.my_ns.RO.create_action = asynctest.CoroutineMock(self.my_ns.RO.create_action,
+ return_value={"vm-id": {"vim_result": 200,
+ "description": "done"}})
@asynctest.fail_on(active_handles=True) # all async tasks must be completed
async def test_instantiate(self):
for db_vdur in db_vnfr["vdur"]:
db_vdur.pop("ip_address", None)
db_vdur.pop("mac_address", None)
+ if getenv("OSMLCMTEST_RO_VIMID"):
+ self.db_content["vim_accounts"][0]["_admin"]["deployed"]["RO"] = getenv("OSMLCMTEST_RO_VIMID")
+ if getenv("OSMLCMTEST_RO_VIMID"):
+ self.db_content["nsrs"][0]["_admin"]["deployed"]["RO"] = getenv("OSMLCMTEST_RO_VIMID")
await self.my_ns.instantiate(nsr_id, nslcmop_id)
# TODO add more checks of called methods
# TODO add a terminate
+ def test_ns_params_2_RO(self):
+ vim = self._db_get_list("vim_accounts")[0]
+ vim_id = vim["_id"]
+ ro_vim_id = vim["_admin"]["deployed"]["RO"]
+ ns_params = {"vimAccountId": vim_id}
+ mgmt_interface = {"cp": "cp"}
+ vdu = [{"id": "vdu_id", "interface": [{"external-connection-point-ref": "cp"}]}]
+ vnfd_dict = {
+ "1": {"vdu": vdu, "mgmt-interface": mgmt_interface},
+ "2": {"vdu": vdu, "mgmt-interface": mgmt_interface, "vnf-configuration": None},
+ "3": {"vdu": vdu, "mgmt-interface": mgmt_interface, "vnf-configuration": {"config-access": None}},
+ "4": {"vdu": vdu, "mgmt-interface": mgmt_interface,
+ "vnf-configuration": {"config-access": {"ssh-access": None}}},
+ "5": {"vdu": vdu, "mgmt-interface": mgmt_interface,
+ "vnf-configuration": {"config-access": {"ssh-access": {"required": True, "default_user": "U"}}}},
+ }
+ nsd = {"constituent-vnfd": []}
+ for k in vnfd_dict.keys():
+ nsd["constituent-vnfd"].append({"vnfd-id-ref": k, "member-vnf-index": k})
+
+ n2vc_key_list = ["key"]
+ ro_ns_params = self.my_ns.ns_params_2_RO(ns_params, nsd, vnfd_dict, n2vc_key_list)
+ ro_params_expected = {'wim_account': None, "datacenter": ro_vim_id,
+ "vnfs": {"5": {"vdus": {"vdu_id": {"mgmt_keys": n2vc_key_list}}}}}
+ self.assertEqual(ro_ns_params, ro_params_expected)
+
@asynctest.fail_on(active_handles=True) # all async tasks must be completed
async def test_scale(self):
pass