from django.test import TestCase, Client
from rest_framework import status
-from lcm.pub.database.models import NfInstModel, JobModel, NSInstModel, VmInstModel, OOFDataModel
+from lcm.pub.database.models import NfInstModel, JobModel, NSInstModel, VmInstModel, OOFDataModel, SubscriptionModel
from lcm.pub.exceptions import NSLCMException
from lcm.pub.utils import restcall
from lcm.pub.utils.jobutil import JOB_MODEL_STATUS
from lcm.pub.utils.timeutil import now_time
from lcm.pub.utils.values import ignore_case_get
from lcm.ns_vnfs.biz.create_vnfs import CreateVnfs
+from lcm.ns_vnfs.biz.grant_vnf import GrantVnf
from lcm.ns_vnfs.biz.heal_vnfs import NFHealService
from lcm.ns_vnfs.biz.scale_vnfs import NFManualScaleService
+from lcm.ns_vnfs.biz.subscribe import SubscriptionDeletion
from lcm.ns_vnfs.biz.terminate_nfs import TerminateVnfs
from lcm.ns_vnfs.const import VNF_STATUS, INST_TYPE
from lcm.ns_vnfs.biz import create_vnfs
from lcm.ns_vnfs.biz.place_vnfs import PlaceVnfs
+from lcm.pub.msapi import resmgr
class TestGetVnfViews(TestCase):
self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
@mock.patch.object(restcall, 'call_req')
- def test_terminate_vnf(self, mock_call_req):
+ @mock.patch.object(SubscriptionDeletion, 'send_subscription_deletion_request')
+ def test_terminate_vnf(self, mock_send_subscription_deletion_request, mock_call_req):
job_id = JobUtil.create_job("VNF", JOB_TYPE.TERMINATE_VNF, self.nf_inst_id)
nfinst = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
else:
self.failUnlessEqual(1, 0)
+ notification_types = ["VnfLcmOperationOccurrenceNotification"],
+ operation_types = [
+ "INSTANTIATE",
+ "SCALE",
+ "SCALE_TO_LEVEL",
+ "CHANGE_FLAVOUR",
+ "TERMINATE",
+ "HEAL",
+ "OPERATE",
+ "CHANGE_EXT_CONN",
+ "MODIFY_INFO"
+ ],
+ operation_states = [
+ "STARTING",
+ "PROCESSING",
+ "COMPLETED",
+ "FAILED_TEMP",
+ "FAILED",
+ "ROLLING_BACK",
+ "ROLLED_BACK"
+ ],
+ vnf_instance_subscription_filter = {
+ "vnfdIds": [],
+ "vnfInstanceIds": '1',
+ "vnfInstanceNames": [],
+ "vnfProductsFromProviders": {}
+ }
+ SubscriptionModel.objects.create(
+ subscription_id='1',
+ notification_types=json.dumps(notification_types),
+ operation_types=json.dumps(operation_types),
+ operation_states=json.dumps(operation_states),
+ vnf_instance_filter=json.dumps(vnf_instance_subscription_filter),
+ # callback_uri,
+ # links=json.dumps(...)
+ )
+
vnf_info = {
"vnf-id": "vnf-id-test111",
"vnf-name": "vnf-name-test111",
def side_effect(*args):
return mock_vals[args[4]]
+
mock_call_req.side_effect = side_effect
req_data = {
class TestPlaceVnfViews(TestCase):
def setUp(self):
self.vnf_inst_id = "1234"
- self.vnf_inst_name = "vG"
+ self.vnf_id = "vG"
self.client = Client()
OOFDataModel.objects.all().delete()
OOFDataModel.objects.create(
request_id="1234",
transaction_id="1234",
request_status="init",
- request_module_name=self.vnf_inst_name,
+ request_module_name=self.vnf_id,
service_resource_id=self.vnf_inst_id,
vim_id="",
cloud_owner="",
vdu_info_json = [{
"vduName": "vG_0",
"flavorName": "HPA.flavor.1",
+ "flavorId": "12345",
"directive": []
}]
PlaceVnfs(vnf_place_request).extract()
"placementSolutions": [
[
{
- "resourceModuleName": self.vnf_inst_name,
+ "resourceModuleName": self.vnf_id,
"serviceResourceId": self.vnf_inst_id,
"solution": {
"identifierType": "serviceInstanceId",
"placementSolutions": [
[
{
- "resourceModuleName": self.vnf_inst_name,
+ "resourceModuleName": self.vnf_id,
"serviceResourceId": self.vnf_inst_id,
"solution": {
"identifierType": "serviceInstanceId",
"placementSolutions": [
[
{
- "resourceModuleName": self.vnf_inst_name,
+ "resourceModuleName": self.vnf_id,
"serviceResourceId": self.vnf_inst_id,
"solution": {
"identifierType": "serviceInstanceId",
PlaceVnfs(resp).extract()
db_info = OOFDataModel.objects.filter(request_id=resp.get("requestId"), transaction_id=resp.get("transactionId"))
self.assertEqual(db_info[0].request_status, "completed")
- self.assertEqual(db_info[0].vim_id, "no-solution")
- self.assertEqual(db_info[0].cloud_owner, "no-solution")
- self.assertEqual(db_info[0].cloud_region_id, "no-solution")
- self.assertEqual(db_info[0].vdu_info, "no-solution")
+ self.assertEqual(db_info[0].vim_id, "none")
+ self.assertEqual(db_info[0].cloud_owner, "none")
+ self.assertEqual(db_info[0].cloud_region_id, "none")
+ self.assertEqual(db_info[0].vdu_info, "none")
+
+
+class TestGrantVnfViews(TestCase):
+ def setUp(self):
+ self.vnf_inst_id = str(uuid.uuid4())
+ self.data = {
+ "vnfInstanceId": self.vnf_inst_id,
+ "vnfLcmOpOccId": "1234",
+ "operation": "INSTANTIATE"
+ }
+ vdu_info_dict = [{"vduName": "vg", "flavorName": "flavor_1", "flavorId": "12345", "directive": []}]
+ OOFDataModel(request_id='1234', transaction_id='1234', request_status='done', request_module_name='vg',
+ service_resource_id=self.vnf_inst_id, vim_id='cloudOwner_casa', cloud_owner='cloudOwner',
+ cloud_region_id='casa', vdu_info=json.dumps(vdu_info_dict)).save()
+
+ def tearDown(self):
+ OOFDataModel.objects.all().delete()
+
+ @mock.patch.object(resmgr, "grant_vnf")
+ def test_exec_grant(self, mock_grant):
+ resmgr_grant_resp = {
+ "vim": {
+ "vimId": "cloudOwner_casa",
+ "accessInfo": {
+ "tenant": "tenantA"
+ }
+ }
+ }
+ mock_grant.return_value = resmgr_grant_resp
+ resp = GrantVnf(self.data).exec_grant()
+ self.assertEquals(resp['vimAssets']['computeResourceFlavours'][0]['vimConnectionId'], 'cloudOwner_casa')
+ self.assertEquals(resp['vimAssets']['computeResourceFlavours'][0]['resourceProviderId'], 'vg')
+ self.assertEquals(resp['vimAssets']['computeResourceFlavours'][0]['vimFlavourId'], '12345')
vnfd_model_dict = {
{"key": "physicalLocationId",
"value": "DLLSTX1223"
},
- {"key": "oofDirectives",
+ {"key": "oof_directives",
"value": {
"directives": [
{
"id": "vG_0",
- "type": "tocsa.nodes.nfv.Vdu.Compute",
+ "type": "tosca.nodes.nfv.Vdu.Compute",
"directives": [
{
- "type": "flavor_directive",
+ "type": "flavor_directives",
"attributes": [
{
- "attribute_name": "flavor_name",
+ "attribute_name": "flavorName",
"attribute_value": "HPA.flavor.1"
- }
+ },
+ {
+ "attribute_name": "flavorId",
+ "attribute_value": "12345"
+ },
]
}
]