aboutsummaryrefslogtreecommitdiffstats
path: root/onap-client
diff options
context:
space:
mode:
authorstark, steven <steven.stark@att.com>2020-08-17 13:00:47 -0700
committerstark, steven <steven.stark@att.com>2020-08-19 13:52:20 -0700
commit7c90d325e8fd8ce21fa747ab292f9c233e3bf367 (patch)
tree6857c930b3c558a6bb52b33ade86efc20581589f /onap-client
parent6b5ef9b8b18f46358e699686a6e706ed3002bd9a (diff)
[VVP] Updating logging
Updating logging to inherit logging instacne from calling application. CLI creates own logging instance. Issue-ID: VVP-456 Signed-off-by: stark, steven <steven.stark@att.com> Change-Id: I1277eb55413063e90b1681b36881a6a5a2b9c272 Signed-off-by: stark, steven <steven.stark@att.com>
Diffstat (limited to 'onap-client')
-rw-r--r--onap-client/onap_client/cli.py17
-rw-r--r--onap-client/onap_client/client/clients.py11
-rw-r--r--onap-client/onap_client/client/request.py7
-rw-r--r--onap-client/onap_client/client/response.py4
-rw-r--r--onap-client/onap_client/config.py10
-rw-r--r--onap-client/onap_client/engine.py4
-rw-r--r--onap-client/onap_client/sdc/vnf.py94
-rw-r--r--onap-client/onap_client/tests/conftest.py45
-rw-r--r--onap-client/setup.py2
9 files changed, 125 insertions, 69 deletions
diff --git a/onap-client/onap_client/cli.py b/onap-client/onap_client/cli.py
index 24f8b9b..9a58fab 100644
--- a/onap-client/onap_client/cli.py
+++ b/onap-client/onap_client/cli.py
@@ -36,9 +36,10 @@
# ============LICENSE_END============================================
import json
+import logging
from prettytable import PrettyTable
-from onap_client.client.clients import Client
+from onap_client.client.clients import get_client as Client
from onap_client.client.catalog import Catalog
from onap_client.engine import spec_cli
from onap_client.util import utility_cli
@@ -51,6 +52,7 @@ def main(*args):
keys = None
oc = Client()
+ configure_logging()
if len(args) > 0 and args[0] == "spec-engine":
# use engine cli instead
@@ -213,3 +215,16 @@ def get_catalog_item_data(catalog_item):
item["description"] = catalog_item.description
return item
+
+
+def configure_logging():
+ oc = Client()
+ LOG_LEVEL = oc.config.LOG_LEVEL if oc.config.LOG_LEVEL else "INFO"
+
+ LOG = logging.getLogger()
+ log_level = getattr(logging, LOG_LEVEL.upper())
+ ch = logging.StreamHandler()
+ LOG.setLevel(log_level)
+ formatter = logging.Formatter('%(levelname)s %(asctime)s %(name)s %(message)s')
+ ch.setFormatter(formatter)
+ LOG.addHandler(ch)
diff --git a/onap-client/onap_client/client/clients.py b/onap-client/onap_client/client/clients.py
index f0a0c1d..8a8160f 100644
--- a/onap-client/onap_client/client/clients.py
+++ b/onap-client/onap_client/client/clients.py
@@ -36,11 +36,11 @@
# ============LICENSE_END============================================
import importlib
+import logging
import onap_client
import pkgutil
import inspect
import sys
-import logging
from onap_client.client.catalog import Catalog
from onap_client import config
@@ -66,7 +66,7 @@ class Client(Catalog):
super().__init__()
if config_file:
- config.LOG.info("Overriding ONAP Client configuration: {}".format(config_file))
+ logging.info("Overriding ONAP Client configuration: {}".format(config_file))
self.set_config(config_file)
@property
@@ -90,18 +90,13 @@ class Client(Catalog):
def set_config(self, config_file):
self.config = config.load_config(config_file, "onap_client")
- self._set_logging(self.config.LOG_LEVEL)
for attr_name, attr in self.__dict__.items():
if isinstance(attr, Client):
- config.LOG.info("Reloading {} {}".format(attr_name, attr))
+ logging.info("Reloading {} {}".format(attr_name, attr))
attr.set_config(config_file)
for k, v in attr.catalog_resources.items():
attr.load(k, v)
- def _set_logging(self, level):
- LOG = logging.getLogger("ONAP_CLIENT")
- LOG.setLevel(getattr(logging, level.upper()))
-
def import_submodules(package, recursive=True):
"""Import all the modules in onap-client, except for those starting
diff --git a/onap-client/onap_client/client/request.py b/onap-client/onap_client/client/request.py
index 194dad5..268ee98 100644
--- a/onap-client/onap_client/client/request.py
+++ b/onap-client/onap_client/client/request.py
@@ -40,14 +40,12 @@ import requests
import json
import os
import copy
-import logging
+import logging as logger
from onap_client.client.response import ResponseHandler
from onap_client.exceptions import FilesRequestFailure
from jinja2 import exceptions as jinja_exceptions
-logger = logging.getLogger("ONAP_CLIENT")
-
class RequestHandler:
"""Handles a APICatalogRequestObject to make a request
@@ -62,7 +60,7 @@ class RequestHandler:
def make_request(self):
r = Request(self.request_object)
- logger.warning("Submitting request: {}".format(self.request_object.description))
+ logger.info("Submitting request: {}".format(self.request_object.description))
# TODO
# Add verify to config file
return ResponseHandler(r.request(verify=False), self.request_object)
@@ -110,7 +108,6 @@ class Request:
try:
logger.info(json.dumps(debug_request, indent=4))
- # logger.info(debug_request)
except TypeError:
logger.info(debug_request)
diff --git a/onap-client/onap_client/client/response.py b/onap-client/onap_client/client/response.py
index 307ed1b..d9c6a84 100644
--- a/onap-client/onap_client/client/response.py
+++ b/onap-client/onap_client/client/response.py
@@ -36,9 +36,7 @@
# ============LICENSE_END============================================
import simplejson
-import logging
-
-logger = logging.getLogger("ONAP_CLIENT")
+import logging as logger
class ResponseHandler:
diff --git a/onap-client/onap_client/config.py b/onap-client/onap_client/config.py
index 2436619..6fe43e9 100644
--- a/onap-client/onap_client/config.py
+++ b/onap-client/onap_client/config.py
@@ -70,7 +70,7 @@ class Config:
with open(self.config_file, "r") as f:
config_data = yaml.safe_load(f)
except FileNotFoundError:
- logging.warn(
+ logging.debug(
"Config file {} not found, using default.".format(self.config_file)
)
@@ -96,11 +96,3 @@ APPLICATION_ID = "robot-ete"
CONFIG_ENV = os.environ.get("OC_CONFIG")
CONFIG_FILE = CONFIG_ENV or "/etc/onap_client/config.yaml"
APP_CONFIG = load_config(CONFIG_FILE, "onap_client")
-LOG = logging.getLogger("ONAP_CLIENT")
-LOG.propagate = False
-log_level = getattr(logging, APP_CONFIG.LOG_LEVEL.upper())
-ch = logging.StreamHandler()
-LOG.setLevel(log_level)
-formatter = logging.Formatter('%(levelname)s %(asctime)s %(name)s %(message)s')
-ch.setFormatter(formatter)
-LOG.addHandler(ch)
diff --git a/onap-client/onap_client/engine.py b/onap-client/onap_client/engine.py
index 37d5b0b..d0bf6b8 100644
--- a/onap-client/onap_client/engine.py
+++ b/onap-client/onap_client/engine.py
@@ -37,15 +37,13 @@
import argparse
import json
-import logging
+import logging as logger
from onap_client.resource import Resource
from onap_client.client.clients import import_submodules
from onap_client.exceptions import InvalidSpecException, ResourceTypeNotFoundException
from onap_client.client.clients import get_client
-logger = logging.getLogger("ONAP_CLIENT")
-
def dumper(obj):
try:
diff --git a/onap-client/onap_client/sdc/vnf.py b/onap-client/onap_client/sdc/vnf.py
index 33e2558..39c66b8 100644
--- a/onap-client/onap_client/sdc/vnf.py
+++ b/onap-client/onap_client/sdc/vnf.py
@@ -316,14 +316,18 @@ class VNF(Resource):
unique_id = item["uniqueId"]
parent_unique_id = item["parentUniqueId"]
owner_id = item["ownerId"]
- return self.oc.sdc.vnf.add_catalog_resource_input(
- **self.attributes,
- input_default_value=input_default_value,
- input_name=input_name,
- input_parent_unique_id=parent_unique_id,
- input_unique_id=unique_id,
- input_owner_id=owner_id,
- )
+ default_value = item.get("defaultValue", "")
+ if default_value != input_default_value:
+ return self.oc.sdc.vnf.add_catalog_resource_input(
+ **self.attributes,
+ input_default_value=input_default_value,
+ input_name=input_name,
+ input_parent_unique_id=parent_unique_id,
+ input_unique_id=unique_id,
+ input_owner_id=owner_id,
+ )
+ else:
+ return None
raise exceptions.InputNotFoundException(
"Input {} was not found in VF".format(input_name)
@@ -352,17 +356,21 @@ class VNF(Resource):
owner_id = prop.get("ownerId")
schemaType = prop.get("schemaType", "")
property_type = prop.get("type")
- return self.oc.sdc.vnf.add_catalog_resource_property(
- **self.attributes,
- unique_id=unique_id,
- parent_unique_id=parent_unique_id,
- owner_id=owner_id,
- catalog_resource_instance_id=instance_id,
- property_name=property_name,
- property_default_value=property_value,
- schema_type=schemaType,
- property_type=property_type,
- )
+ value = prop.get("value", "")
+ if value != property_value:
+ return self.oc.sdc.vnf.add_catalog_resource_property(
+ **self.attributes,
+ unique_id=unique_id,
+ parent_unique_id=parent_unique_id,
+ owner_id=owner_id,
+ catalog_resource_instance_id=instance_id,
+ property_name=property_name,
+ property_default_value=property_value,
+ schema_type=schemaType,
+ property_type=property_type,
+ )
+ else:
+ return None
raise exceptions.PropertyNotFoundException(
"Property {} was not found in Instance {}".format(
@@ -389,17 +397,21 @@ class VNF(Resource):
owner_id = prop.get("ownerId")
schemaType = prop.get("schemaType", "")
property_type = prop.get("type")
- return self.oc.sdc.vnf.add_catalog_resource_property_non_vf(
- **self.attributes,
- unique_id=unique_id,
- parent_unique_id=parent_unique_id,
- owner_id=owner_id,
- catalog_resource_instance_id=instance_id,
- property_name=property_name,
- property_default_value=property_value,
- schema_type=schemaType,
- property_type=property_type,
- )
+ value = prop.get("value", "")
+ if value != property_value:
+ return self.oc.sdc.vnf.add_catalog_resource_property_non_vf(
+ **self.attributes,
+ unique_id=unique_id,
+ parent_unique_id=parent_unique_id,
+ owner_id=owner_id,
+ catalog_resource_instance_id=instance_id,
+ property_name=property_name,
+ property_default_value=property_value,
+ schema_type=schemaType,
+ property_type=property_type,
+ )
+ else:
+ return None
raise exceptions.PropertyNotFoundException(
"Property {} was not found in Instance {}".format(
@@ -424,15 +436,19 @@ class VNF(Resource):
unique_id = prop.get("uniqueId")
property_type = prop.get("type")
description = prop.get("description")
- return self.oc.sdc.vnf.add_catalog_policy_property(
- catalog_resource_id=self.catalog_resource_id,
- unique_id=unique_id,
- catalog_policy_id=policy_id,
- property_name=property_name,
- property_default_value=property_value,
- description=description,
- property_type=property_type,
- )
+ value = prop.get("value", "")
+ if value != property_value:
+ return self.oc.sdc.vnf.add_catalog_policy_property(
+ catalog_resource_id=self.catalog_resource_id,
+ unique_id=unique_id,
+ catalog_policy_id=policy_id,
+ property_name=property_name,
+ property_default_value=property_value,
+ description=description,
+ property_type=property_type,
+ )
+ else:
+ return None
raise exceptions.PropertyNotFoundException(
"Property {} was not found in policy {}".format(property_name, policy_id)
diff --git a/onap-client/onap_client/tests/conftest.py b/onap-client/onap_client/tests/conftest.py
new file mode 100644
index 0000000..705e557
--- /dev/null
+++ b/onap-client/onap_client/tests/conftest.py
@@ -0,0 +1,45 @@
+# -*- coding: utf8 -*-
+# ============LICENSE_START=======================================================
+# org.onap.vvp/validation-scripts
+# ===================================================================
+# Copyright © 2020 AT&T Intellectual Property. All rights reserved.
+# ===================================================================
+#
+# Unless otherwise specified, all software contained herein is licensed
+# under the Apache License, Version 2.0 (the "License");
+# you may not use this software except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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.
+#
+#
+#
+# Unless otherwise specified, all documentation contained herein is licensed
+# under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+# you may not use this documentation except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://creativecommons.org/licenses/by/4.0/
+#
+# Unless required by applicable law or agreed to in writing, documentation
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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.
+#
+# ============LICENSE_END============================================
+import logging
+
+LOG = logging.getLogger()
+log_level = getattr(logging, "DEBUG")
+ch = logging.StreamHandler()
+LOG.setLevel(log_level)
+formatter = logging.Formatter('%(levelname)s %(asctime)s %(name)s %(message)s')
+ch.setFormatter(formatter)
+LOG.addHandler(ch)
diff --git a/onap-client/setup.py b/onap-client/setup.py
index e63b08c..d02864b 100644
--- a/onap-client/setup.py
+++ b/onap-client/setup.py
@@ -47,7 +47,7 @@ for file in os.listdir("etc/payloads"):
setuptools.setup(
name="onap-client",
- version="0.9.3",
+ version="0.9.4",
author="Steven Stark",
author_email="steven.stark@att.com",
description="Python API wrapper for ONAP applications",