from lcm.pub.database.models import NSDModel, NSInstModel
from lcm.pub.exceptions import NSLCMException
+from lcm.pub.msapi.aai import create_customer_aai
from lcm.pub.utils.timeutil import now_time
logger = logging.getLogger(__name__)
self.check_nsd_valid()
self.check_ns_inst_name_exist()
self.create_ns_inst()
+ self.create_ns_in_aai()
logger.debug("CreateNSService::do_biz::ns_inst_id=%s" % self.ns_inst_id)
return self.ns_inst_id
def create_ns_inst(self):
self.ns_inst_id = str(uuid.uuid4())
logger.debug("CreateNSService::create_ns_inst::ns_inst_id=%s" % self.ns_inst_id)
- NSInstModel(id=self.ns_inst_id, name=self.ns_name, nspackage_id=self.ns_package_id,
- nsd_id=self.nsd_id, description=self.description, status='empty',
+ NSInstModel(id=self.ns_inst_id, name=self.ns_name, nspackage_id=self.ns_package_id,
+ nsd_id=self.nsd_id, description=self.description, status='empty',
lastuptime=now_time()).save()
+ def create_ns_in_aai(self):
+ logger.debug("CreateNSService::create_ns_in_aai::report ns instance[%s] to aai." % self.ns_inst_id)
+ global_customer_id = "global-customer-id-" + self.ns_inst_id
+ data = {
+ "global-customer-id": "global-customer-id-" + self.ns_inst_id,
+ "subscriber-name": "subscriber-name-" + self.ns_inst_id,
+ "subscriber-type": "subscriber-type-" + self.ns_inst_id,
+ "service-subscriptions": {
+ "service-subscription": [
+ {
+ "service-type": "service-type-" + self.ns_inst_id,
+ "service-instances": {
+ "service-instance": [
+ {
+ "service-instance-id": self.ns_inst_id,
+ "service-instance-name": self.ns_name,
+ "service-type": "service-type-" + self.ns_inst_id,
+ "service-role": "service-role-" + self.ns_inst_id
+ }
+ ]
+ }
+ }
+ ]
+ }
+ }
+ resp_data, resp_status = create_customer_aai(global_customer_id, data)
+ if resp_data:
+ logger.debug("Fail to create ns instance[%s] to aai, resp_status: [%s]." % (self.ns_inst_id, resp_status) )
+ else:
+ logger.debug("Success to create ns instance[%s] to aai, resp_status: [%s]." % (self.ns_inst_id, resp_status) )
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+import json
import uuid
+import mock
from django.test import TestCase, Client
from rest_framework import status
from lcm.pub.database.models import NSInstModel, NSDModel
+from lcm.pub.utils import restcall
class TestNsInstantiate(TestCase):
NSDModel.objects.all().delete()
NSInstModel.objects.all().delete()
- def test_create_ns(self):
+ @mock.patch.object(restcall, 'call_req')
+ def test_create_ns(self, mock_call_req):
+ r1_create_ns_to_aai = [0, json.JSONEncoder().encode({}), '201']
+ mock_call_req.side_effect = [r1_create_ns_to_aai]
data = {
'nsdid': self.nsd_id,
'nsname': 'ns',