1 # ============LICENSE_START=======================================================
2 # Copyright (C) 2021 Samsung
3 # ================================================================================
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # ============LICENSE_END=========================================================
21 from onapsdk.aai.business import Customer
22 from onapsdk.cds.blueprint import Workflow, Blueprint
24 from config import Config
26 #FIXME remove from global scope
27 logger = logging.getLogger("")
28 logger.setLevel(logging.INFO)
29 fh = logging.StreamHandler()
30 fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s')
31 fh.setFormatter(fh_formatter)
34 def resolve_hc_inputs():
35 logger.info("******** Check Customer *******")
37 for found_customer in list(Customer.get_all()):
38 logger.debug("Customer %s found", found_customer.subscriber_name)
39 if found_customer.subscriber_name == Config.GLOBAL_CUSTOMER_ID:
40 logger.info("Customer %s found", found_customer.subscriber_name)
41 customer = found_customer
44 raise Exception("Customer %s wasn't found in ONAP" % Config.GLOBAL_CUSTOMER_ID)
45 logger.info("******** Check Service Subscription *******")
46 service_subscription = None
47 for service_sub in customer.service_subscriptions:
48 logger.debug("Service subscription %s is found", service_sub.service_type)
49 if service_sub.service_type == Config.SERVICENAME:
50 logger.info("Service %s subscribed", Config.SERVICENAME)
51 service_subscription = service_sub
53 logger.info("******** Retrieve Service Metadata *******")
54 service_instance = None
55 for single_service in service_subscription.service_instances:
56 if single_service.instance_name == Config.SERVICE_INSTANCE_NAME:
57 service_instance = single_service
59 service_id = service_instance.instance_id
60 vnfs = list(service_instance.vnf_instances)
62 raise NotImplementedError("Service %s is composed of more than one vnf!" % service_id)
64 raise Exception("Service %s doesn't contain any vnfs" % service_id)
65 vnf_id = vnfs[0].vnf_id
66 return service_id, vnf_id
70 with zipfile.ZipFile(Config.VSPFILE, 'r') as package:
71 with package.open("CBA.zip", 'r') as cba:
72 blueprint = Blueprint(cba.read())
74 healthcheck = Workflow('health-check', None, blueprint)
75 serv_id, vnf_id = resolve_hc_inputs()
76 cds_input = {"health-check-properties":
78 "service-instance-id": serv_id,
82 logger.info("Requesting Healthcheck for CBA %s:%s with inputs:\n%s",
83 blueprint.metadata.template_name,
84 blueprint.metadata.template_version,
86 result = healthcheck.execute(cds_input)
87 logger.info("Healthcheck process completed with result: %s", result)
88 logger.info("Please check cds-blueprints-processor logs to see exact status")
90 if __name__ == "__main__":