aboutsummaryrefslogtreecommitdiffstats
path: root/onap-client/onap_client
diff options
context:
space:
mode:
authorstark, steven <steven.stark@att.com>2020-07-21 15:14:27 -0700
committerstark, steven <steven.stark@att.com>2020-07-21 15:15:34 -0700
commit9df81b14e7203d6c3911f5f36881cb5170afdccc (patch)
tree2a9b5e913e83d0f21b374f068c53df266d3dec56 /onap-client/onap_client
parentb3e7a9fbcbf52ac095ca424f3f17610bf1e8df88 (diff)
[VVP] onap-client refactoring
removing create hook from _init_ for resources removing _init_ for non-abstract resources refactor validation logic enhancing error catch for resource failure adding _on_failure hook Issue-ID: VVP-441 Signed-off-by: stark, steven <steven.stark@att.com> Change-Id: Ia627fc7fd35fe6e112d6f89399701c70b5888077
Diffstat (limited to 'onap-client/onap_client')
-rw-r--r--onap-client/onap_client/exceptions.py4
-rw-r--r--onap-client/onap_client/resource.py153
-rw-r--r--onap-client/onap_client/sdc/license_model.py30
-rw-r--r--onap-client/onap_client/sdc/service.py62
-rw-r--r--onap-client/onap_client/sdc/tests/test_license_model.py16
-rw-r--r--onap-client/onap_client/sdc/tests/test_service.py23
-rw-r--r--onap-client/onap_client/sdc/tests/test_vnf.py8
-rw-r--r--onap-client/onap_client/sdc/tests/test_vsp.py17
-rw-r--r--onap-client/onap_client/sdc/vnf.py99
-rw-r--r--onap-client/onap_client/sdc/vsp.py93
-rw-r--r--onap-client/onap_client/sdnc/preload.py26
-rw-r--r--onap-client/onap_client/so/module_instance.py56
-rw-r--r--onap-client/onap_client/so/service_instance.py48
-rw-r--r--onap-client/onap_client/so/tests/test_module_instance.py21
-rw-r--r--onap-client/onap_client/so/tests/test_service_instance.py25
-rw-r--r--onap-client/onap_client/so/tests/test_vnf_instance.py21
-rw-r--r--onap-client/onap_client/so/vnf_instance.py41
-rw-r--r--onap-client/onap_client/tests/test_resource.py20
-rw-r--r--onap-client/onap_client/tests/testdata.py8
19 files changed, 264 insertions, 507 deletions
diff --git a/onap-client/onap_client/exceptions.py b/onap-client/onap_client/exceptions.py
index 76bb77e..8e3b843 100644
--- a/onap-client/onap_client/exceptions.py
+++ b/onap-client/onap_client/exceptions.py
@@ -142,3 +142,7 @@ class DistributionTimeout(Exception):
class TenantNotFound(Exception):
pass
+
+
+class ResourceCreationFailure(Exception):
+ pass
diff --git a/onap-client/onap_client/resource.py b/onap-client/onap_client/resource.py
index 0af0fad..ca5d675 100644
--- a/onap-client/onap_client/resource.py
+++ b/onap-client/onap_client/resource.py
@@ -34,40 +34,62 @@
# limitations under the License.
#
# ============LICENSE_END============================================
-
-import inspect
-
-from abc import ABC, abstractmethod
-from onap_client.exceptions import InvalidSpecException
+from abc import ABC
+from onap_client.exceptions import InvalidSpecException, ResourceAlreadyExistsException, ResourceCreationFailure
+from onap_client.client.clients import Client
class Resource(ABC):
resource_name = "abstract"
spec = {}
- def __init__(self, input):
+ def __init__(self, **kwargs):
self.attributes = {}
-
- attributes = self._create(input)
- self.resolve_attributes(attributes)
-
- self._post_create()
+ self.oc = Client()
+ self.input_spec = self.validate(kwargs, spec=self.spec)
def __getattr__(self, attr):
return self.attributes.get(attr, None)
- @abstractmethod
+ def create(self):
+ attributes = self._create(self.input_spec)
+ self.resolve_attributes(attributes)
+ self._post_create()
+
def _create(self, input):
pass
- @abstractmethod
def _post_create(self):
pass
- @abstractmethod
def _submit(self):
pass
+ def _on_failure(self):
+ pass
+
+ @classmethod
+ def create_from_spec(cls, spec, submit=True):
+ instance = cls(**spec)
+
+ try:
+ instance.create()
+ if submit:
+ instance._submit()
+ except ResourceAlreadyExistsException:
+ raise
+ except Exception as e:
+ instance._on_failure()
+ raise ResourceCreationFailure(
+ "Failed to create resource {}: {}".format(instance.resource_name, str(e))
+ )
+
+ return instance
+
+ def resolve_attributes(self, attributes):
+ for key, val in attributes.items():
+ self.attributes[key] = val
+
@classmethod
def validate(cls, input, spec=None):
"""Validates that an input dictionary spec
@@ -79,82 +101,65 @@ class Resource(ABC):
Returns complete spec with all attributes.
"""
valid_spec = {}
-
- if not isinstance(input, dict):
- raise InvalidSpecException("input spec was not a dictionary")
-
if not spec:
spec = cls.spec
- for k, v in input.items():
- if not spec.get(k):
- raise InvalidSpecException("Unknown property found: {}".format(k))
-
- for k, v in spec.items():
- property_name = k
- property_type = v.get("type")
- property_required = v.get("required")
- property_default = v.get("default", default_empty_value(property_type))
-
- input_property = validate_property(
- input, property_name, property_required, property_default, property_type
- )
-
- if (
- property_type == dict
- and input_property != property_default
- and v.get("nested")
- ):
- property_value = cls.validate(input_property, v.get("nested"))
- elif property_type == list:
- list_property_type = v.get("list_item")
- list_spec = []
- for item in input_property:
- if type(item) != list_property_type:
- raise InvalidSpecException(
- "list item {} not match type {}".format(
- item, list_property_type
- )
- )
- if list_property_type == str:
- list_spec.insert(0, item)
- else:
- list_spec.insert(0, cls.validate(item, v.get("nested", {})))
-
- property_value = list_spec
- else:
- property_value = input_property
+ validate_spec_type(input)
+ validate_spec_properties(input, spec)
+ for property_name, v in spec.items():
+ property_value = cls.validate_spec_item(property_name, v, input, spec)
valid_spec[property_name] = property_value
return valid_spec
@classmethod
- def create_from_spec(cls, spec, submit=True):
- input_args = []
+ def validate_spec_item(cls, property_name, property_item, input, spec):
+ property_type = property_item.get("type")
+ property_required = property_item.get("required")
+ property_default = property_item.get("default", default_empty_value(property_type))
- arguments = inspect.getfullargspec(cls).args
- arguments.pop(0)
+ input_property = validate_property(
+ input, property_name, property_required, property_default, property_type
+ )
- for argument in arguments:
- input_args.append(spec.get(argument))
+ if (
+ property_type == dict
+ and input_property != property_default
+ and property_item.get("nested")
+ ):
+ property_value = cls.validate(input_property, property_item.get("nested"))
+ elif property_type == list:
+ list_property_type = property_item.get("list_item")
+ list_spec = []
+ for item in input_property:
+ if type(item) != list_property_type:
+ raise InvalidSpecException(
+ "list item {} not match type {}".format(
+ item, list_property_type
+ )
+ )
+ if list_property_type == str:
+ list_spec.insert(0, item)
+ else:
+ list_spec.insert(0, cls.validate(item, property_item.get("nested", {})))
- instance = cls(*input_args)
+ property_value = list_spec
+ else:
+ property_value = input_property
- if submit:
- instance._submit()
+ return property_value
- return instance
- def resolve_attributes(self, attributes):
- for key, val in attributes.items():
- self.attributes[key] = val
+def validate_spec_type(input_spec):
+ if not isinstance(input_spec, dict):
+ raise InvalidSpecException("input spec was not a dictionary")
+
- def print(self):
- for k, v in self.attributes.items():
- val = str(v)
- value = val[:50] + "..." if len(val) > 50 else val
- print("{}: {}".format(k, value))
+def validate_spec_properties(input_spec, spec):
+ for k, v in input_spec.items():
+ if not spec.get(k):
+ raise InvalidSpecException("Unknown property found: {}".format(k))
def validate_property(
diff --git a/onap-client/onap_client/sdc/license_model.py b/onap-client/onap_client/sdc/license_model.py
index 591509e..52846c1 100644
--- a/onap-client/onap_client/sdc/license_model.py
+++ b/onap-client/onap_client/sdc/license_model.py
@@ -48,7 +48,7 @@ class LicenseModel(Resource):
"required": False,
"default": generate_dummy_string("test_vendor_"),
},
- "mfr_ref_number": {
+ "manufacturer_reference_number": {
"type": str,
"required": False,
"default": generate_dummy_string("mfref"),
@@ -85,38 +85,10 @@ class LicenseModel(Resource):
},
}
- def __init__(
- self,
- vendor_name,
- mfr_ref_number,
- entitlement_pool_name,
- key_group_name,
- feature_group_name,
- license_agreement_name,
- license_start_date,
- license_end_date,
- ):
- self.oc = Client()
-
- license_input = {}
- license_input["vendor_name"] = vendor_name
- license_input["manufacturer_reference_number"] = mfr_ref_number
- license_input["entitlement_pool_name"] = entitlement_pool_name
- license_input["key_group_name"] = key_group_name
- license_input["feature_group_name"] = feature_group_name
- license_input["license_agreement_name"] = license_agreement_name
- license_input["license_start_date"] = license_start_date
- license_input["license_end_date"] = license_end_date
-
- super().__init__(license_input)
-
def _create(self, license_input):
"""Creates a license model object in SDC"""
return create_license_model(license_input)
- def _post_create(self):
- pass
-
def _submit(self):
"""Submits the license model in SDC"""
diff --git a/onap-client/onap_client/sdc/service.py b/onap-client/onap_client/sdc/service.py
index 8b9c68b..8eec31a 100644
--- a/onap-client/onap_client/sdc/service.py
+++ b/onap-client/onap_client/sdc/service.py
@@ -117,53 +117,6 @@ class Service(Resource):
"wait_for_distribution": {"type": bool, "required": False, "default": False},
}
- def __init__(
- self,
- instantiation_type,
- service_name,
- contact_id,
- category_name,
- tag,
- project_code,
- environment_context,
- ecomp_generated_naming,
- description,
- service_type,
- service_role,
- naming_policy,
- resources=[],
- wait_for_distribution=False,
- allow_update=False,
- ):
- self.oc = Client()
-
- service_input = {}
-
- category_name_lower = category_name.lower()
- category_name_icon = normalize_category_icon(category_name)
- category_id = "serviceNewCategory.{}".format(category_name_lower)
-
- service_input["service_name"] = service_name
- service_input["instantiation_type"] = instantiation_type
- service_input["contact_id"] = contact_id
- service_input["category_name"] = category_name
- service_input["category_id"] = category_id
- service_input["category_name_lower"] = category_name_lower
- service_input["category_name_icon"] = category_name_icon
- service_input["tag"] = tag
- service_input["project_code"] = project_code
- service_input["environment_context"] = environment_context
- service_input["ecomp_generated_naming"] = ecomp_generated_naming
- service_input["description"] = description
- service_input["service_type"] = service_type
- service_input["service_role"] = service_role
- service_input["naming_policy"] = naming_policy
- service_input["resources"] = resources
- service_input["wait_for_distribution"] = wait_for_distribution
- service_input["allow_update"] = allow_update
-
- super().__init__(service_input)
-
def _create(self, service_input):
"""Creates a service object in SDC"""
service = None
@@ -372,14 +325,19 @@ def create_service(service_input):
"""
oc = Client()
- kwargs = service_input
+ category_name_lower = service_input.get("category_name").lower()
+ category_name_icon = normalize_category_icon(service_input.get("category_name"))
+ category_id = "serviceNewCategory.{}".format(category_name_lower)
+ service_input["category_id"] = category_id
+ service_input["category_name_lower"] = category_name_lower
+ service_input["category_name_icon"] = category_name_icon
- service = oc.sdc.service.add_catalog_service(**kwargs)
+ service = oc.sdc.service.add_catalog_service(**service_input)
- kwargs["catalog_service_id"] = service.catalog_service_id
- kwargs["tosca"] = service.response_data
+ service_input["catalog_service_id"] = service.catalog_service_id
+ service_input["tosca"] = service.response_data
- return kwargs
+ return service_input
@utility
diff --git a/onap-client/onap_client/sdc/tests/test_license_model.py b/onap-client/onap_client/sdc/tests/test_license_model.py
index 8da7d07..e9ca735 100644
--- a/onap-client/onap_client/sdc/tests/test_license_model.py
+++ b/onap-client/onap_client/sdc/tests/test_license_model.py
@@ -110,14 +110,14 @@ def test_license_model_create():
)
lm = LicenseModel(
- VENDOR_NAME,
- "abc123",
- "entitlement_pool_name",
- "key_group_name",
- "feature_group_name",
- "license_agreement_name",
- "license_start_date",
- "license_end_date",
+ vendor_name=VENDOR_NAME,
+ entitlement_pool_name="entitlement_pool_name",
+ key_group_name="key_group_name",
+ feature_group_name="feature_group_name",
+ license_agreement_name="license_agreement_name",
+ license_start_date="license_start_date",
+ license_end_date="license_end_date",
)
+ lm.create()
assert lm.tosca == return_data
diff --git a/onap-client/onap_client/sdc/tests/test_service.py b/onap-client/onap_client/sdc/tests/test_service.py
index e4789a5..77eadbd 100644
--- a/onap-client/onap_client/sdc/tests/test_service.py
+++ b/onap-client/onap_client/sdc/tests/test_service.py
@@ -104,18 +104,15 @@ def test_vnf_create():
)
service = Service(
- "A-la-carte",
- SERVICE_NAME,
- "cs0008",
- "Network L1-3",
- "robot",
- "123456",
- "General_Revenue-Bearing",
- "true",
- "This is a test",
- "",
- "",
- "",
+ instantiation_type="A-la-carte",
+ service_name=SERVICE_NAME,
+ contact_id="cs0008",
+ category_name="Network L1-3",
+ tag="robot",
+ project_code="123456",
+ environment_context="General_Revenue-Bearing",
+ ecomp_generated_naming="true",
+ description="This is a test",
resources=[{
"resource_name": VNF_NAME,
"resource_id": VNF_RESOURCE_ID,
@@ -126,7 +123,7 @@ def test_vnf_create():
allow_update=False,
wait_for_distribution=False
)
-
+ service.create()
service._submit()
assert service.service_name == SERVICE_NAME
diff --git a/onap-client/onap_client/sdc/tests/test_vnf.py b/onap-client/onap_client/sdc/tests/test_vnf.py
index dfa5af1..da3dd86 100644
--- a/onap-client/onap_client/sdc/tests/test_vnf.py
+++ b/onap-client/onap_client/sdc/tests/test_vnf.py
@@ -145,12 +145,12 @@ def test_vnf_create():
)
vnf = VNF(
- SOFTWARE_PRODUCT_NAME,
- VNF_NAME,
- RESOURCE_TYPE,
+ software_product_name=SOFTWARE_PRODUCT_NAME,
+ vnf_name=VNF_NAME,
+ resource_type=RESOURCE_TYPE,
vm_types=[{"vm_type": "red", "properties": {"nf_role": "blue"}}],
)
-
+ vnf.create()
vnf._submit()
assert "componentInstancesInputs" in vnf.tosca
diff --git a/onap-client/onap_client/sdc/tests/test_vsp.py b/onap-client/onap_client/sdc/tests/test_vsp.py
index f14e16e..cd35a90 100644
--- a/onap-client/onap_client/sdc/tests/test_vsp.py
+++ b/onap-client/onap_client/sdc/tests/test_vsp.py
@@ -102,15 +102,16 @@ def test_vsp_create():
mockup_client(oc.sdc.vsp)
vsp = sdc.vsp.VSP(
- "vendor_name",
- LICENSE_MODEL_NAME,
- "{}/test.zip".format(THIS_DIR),
- "application/zip",
- VSP_NAME,
- "description",
- "category",
- "sub_category",
+ vendor_name="vendor_name",
+ license_model_name=LICENSE_MODEL_NAME,
+ file_path="{}/test.zip".format(THIS_DIR),
+ file_type="application/zip",
+ software_product_name=VSP_NAME,
+ description="description",
+ category="category",
+ sub_category="sub_category",
contributers=["test123"],
)
+ vsp.create()
assert vsp.tosca == {"name": VSP_NAME}
diff --git a/onap-client/onap_client/sdc/vnf.py b/onap-client/onap_client/sdc/vnf.py
index f1ccb51..03b5c54 100644
--- a/onap-client/onap_client/sdc/vnf.py
+++ b/onap-client/onap_client/sdc/vnf.py
@@ -122,45 +122,6 @@ class VNF(Resource):
"allow_update": {"type": bool, "required": False, "default": False},
}
- def __init__(
- self,
- software_product_name,
- vnf_name,
- resource_type,
- inputs={},
- vm_types=[],
- network_roles=[],
- policies=[],
- allow_update=False,
- description="VNF",
- ):
- self.oc = Client()
-
- vnf_input = {}
-
- software_product_id = vsp.get_vsp_id(software_product_name)
- software_product_version_id = vsp.get_vsp_version_id(software_product_id)
- vsp_model = vsp.get_vsp_model(software_product_id, software_product_version_id)
-
- vsp_vendor = vsp_model.get("vendorName")
- vsp_category = vsp_model.get("category")
- vsp_sub_category = vsp_model.get("subCategory")
-
- vnf_input["software_product_id"] = software_product_id
- vnf_input["vsp_category"] = vsp_category
- vnf_input["vsp_sub_category"] = vsp_sub_category
- vnf_input["vendor_name"] = vsp_vendor
- vnf_input["vnf_name"] = vnf_name
- vnf_input["resource_type"] = resource_type
- vnf_input["inputs"] = inputs
- vnf_input["vm_types"] = vm_types
- vnf_input["network_roles"] = network_roles
- vnf_input["policies"] = policies
- vnf_input["allow_update"] = allow_update
- vnf_input["vnf_description"] = description
-
- super().__init__(vnf_input)
-
def _create(self, vnf_input):
"""Creates a vnf object in SDC"""
vnf = None
@@ -208,6 +169,18 @@ class VNF(Resource):
for k, v in inputs.items():
self.add_input_value(k, v)
+ def _submit(self):
+ """Submits the vnf in SDC"""
+ certification = self.oc.sdc.vnf.certify_catalog_resource(
+ **self.attributes, user_remarks="Ready!"
+ )
+ self.attributes["catalog_resource_id"] = certification.catalog_resource_id
+
+ vnf = self.oc.sdc.vnf.get_catalog_resource(**self.attributes)
+
+ self.attributes["catalog_resource_name"] = vnf.catalog_resource_name
+ self.attributes["tosca"] = vnf.response_data
+
def _add_instance_properties(self, instance_id, properties_dict):
for k, v in properties_dict.items():
# updating vm_type properties
@@ -322,18 +295,6 @@ class VNF(Resource):
return False
- def _submit(self):
- """Submits the vnf in SDC"""
- certification = self.oc.sdc.vnf.certify_catalog_resource(
- **self.attributes, user_remarks="Ready!"
- )
- self.attributes["catalog_resource_id"] = certification.catalog_resource_id
-
- vnf = self.oc.sdc.vnf.get_catalog_resource(**self.attributes)
-
- self.attributes["catalog_resource_name"] = vnf.catalog_resource_name
- self.attributes["tosca"] = vnf.response_data
-
def add_input_value(self, input_name, input_default_value):
"""Updates an input value on a VNF
@@ -548,24 +509,36 @@ def create_vnf(vnf_input):
"""
oc = Client()
- kwargs = vnf_input
+ software_product_id = vsp.get_vsp_id(vnf_input.get("software_product_name"))
+ software_product_version_id = vsp.get_vsp_version_id(software_product_id)
+ vsp_model = vsp.get_vsp_model(software_product_id, software_product_version_id)
- category = get_resource_category(kwargs.get("vsp_category"))
- vsp_sub_category = []
+ vsp_vendor = vsp_model.get("vendorName")
+ vsp_category = vsp_model.get("category")
+ vsp_sub_category = vsp_model.get("subCategory")
+
+ vnf_input["software_product_id"] = software_product_id
+ vnf_input["vsp_category"] = vsp_category
+ vnf_input["vsp_sub_category"] = vsp_sub_category
+ vnf_input["vendor_name"] = vsp_vendor
+ vnf_input["vnf_description"] = vnf_input.get("description")
+
+ category = get_resource_category(vsp_category)
+ vsp_sub_categories = []
for subcategory in category.get("subcategories", []):
- if subcategory.get("uniqueId") == kwargs.get("vsp_sub_category"):
- vsp_sub_category.append(subcategory)
+ if subcategory.get("uniqueId").lower() == vsp_sub_category.lower():
+ vsp_sub_categories.append(subcategory)
break
- category["subcategories"] = vsp_sub_category
- kwargs["contact_id"] = vsp.get_vsp_owner(kwargs.get("software_product_id"))
+ category["subcategories"] = vsp_sub_categories
+ vnf_input["contact_id"] = vsp.get_vsp_owner(software_product_id)
- vnf = oc.sdc.vnf.add_catalog_resource(**kwargs, categories=[category])
+ vnf = oc.sdc.vnf.add_catalog_resource(**vnf_input, categories=[category])
- kwargs["catalog_resource_id"] = vnf.catalog_resource_id
- kwargs["tosca"] = vnf.response_data
+ vnf_input["catalog_resource_id"] = vnf.catalog_resource_id
+ vnf_input["tosca"] = vnf.response_data
- return kwargs
+ return vnf_input
def instance_ids_for_property(vnf_model, property_name, property_value):
@@ -657,7 +630,7 @@ def get_resource_category(category_name):
oc = Client()
resource_categories = oc.sdc.get_resource_categories().response_data
for category in resource_categories:
- if category.get("uniqueId") == category_name:
+ if category.get("uniqueId").lower() == category_name.lower():
return category
return None
diff --git a/onap-client/onap_client/sdc/vsp.py b/onap-client/onap_client/sdc/vsp.py
index cd478e1..de47277 100644
--- a/onap-client/onap_client/sdc/vsp.py
+++ b/onap-client/onap_client/sdc/vsp.py
@@ -72,64 +72,19 @@ class VSP(Resource):
"allow_update": {"type": bool, "required": False, "default": False},
}
- def __init__(
- self,
- vendor_name,
- license_model_name,
- file_path,
- file_type,
- software_product_name,
- description,
- category,
- sub_category,
- contributers=[],
- allow_update=False,
- owner="",
- ):
- self.oc = Client()
- vsp_input = {}
-
- license_model_id = sdc.license_model.get_license_model_id(license_model_name)
- license_model_version_id = sdc.license_model.get_license_model_version_id(
- license_model_id
- )
- feature_group = sdc.license_model.get_license_model_attribute(
- license_model_id, license_model_version_id, "feature-groups"
- )
- license_agreement = sdc.license_model.get_license_model_attribute(
- license_model_id, license_model_version_id, "license-agreements"
- )
-
- vsp_input["software_product_name"] = software_product_name
- vsp_input["feature_group_id"] = feature_group["id"]
- vsp_input["license_agreement_id"] = license_agreement["id"]
- vsp_input["vendor_name"] = vendor_name
- vsp_input["license_model_id"] = license_model_id
- vsp_input["license_model_version_id"] = license_model_version_id
- vsp_input["file_path"] = file_path
- vsp_input["file_type"] = file_type
- vsp_input["description"] = description
- vsp_input["category"] = category.lower()
- vsp_input["sub_category"] = sub_category.lower()
- vsp_input["contributers"] = contributers
- vsp_input["allow_update"] = allow_update
- vsp_input["owner"] = owner
-
- super().__init__(vsp_input)
-
- def _create(self, kwargs):
+ def _create(self, vsp_input):
"""Creates a vsp object in SDC"""
vsp = None
- existing = get_vsp(kwargs.get("software_product_name"))
+ existing = get_vsp(vsp_input.get("software_product_name"))
if not existing:
- vsp = create_vsp(kwargs)
- elif kwargs.get("allow_update"):
- vsp = update_vsp(existing, kwargs)
+ vsp = create_vsp(vsp_input)
+ elif vsp_input.get("allow_update"):
+ vsp = update_vsp(existing, vsp_input)
else:
raise ResourceAlreadyExistsException(
"VSP resource {} already exists".format(
- kwargs.get("software_product_name")
+ vsp_input.get("software_product_name")
)
)
@@ -199,19 +154,37 @@ def create_vsp(vsp_input):
"""
oc = Client()
- kwargs = vsp_input
- vsp = oc.sdc.vsp.add_software_product(**kwargs)
+ license_model_id = sdc.license_model.get_license_model_id(vsp_input.get("license_model_name"))
+
+ license_model_version_id = sdc.license_model.get_license_model_version_id(
+ license_model_id
+ )
+
+ feature_group = sdc.license_model.get_license_model_attribute(
+ license_model_id, license_model_version_id, "feature-groups"
+ )
+
+ license_agreement = sdc.license_model.get_license_model_attribute(
+ license_model_id, license_model_version_id, "license-agreements"
+ )
- kwargs["software_product_id"] = vsp.software_product_id
- kwargs["software_product_version_id"] = vsp.software_product_version_id
+ vsp_input["license_model_id"] = license_model_id
+ vsp_input["license_model_version_id"] = license_model_version_id
+ vsp_input["feature_group_id"] = feature_group["id"]
+ vsp_input["license_agreement_id"] = license_agreement["id"]
- oc.sdc.vsp.upload_heat_package(**kwargs)
- oc.sdc.vsp.validate_software_product(**kwargs)
+ vsp = oc.sdc.vsp.add_software_product(**vsp_input)
- vsp = oc.sdc.vsp.get_software_product(**kwargs)
- kwargs["tosca"] = vsp.response_data
+ vsp_input["software_product_id"] = vsp.software_product_id
+ vsp_input["software_product_version_id"] = vsp.software_product_version_id
- return kwargs
+ oc.sdc.vsp.upload_heat_package(**vsp_input)
+ oc.sdc.vsp.validate_software_product(**vsp_input)
+
+ vsp = oc.sdc.vsp.get_software_product(**vsp_input)
+ vsp_input["tosca"] = vsp.response_data
+
+ return vsp_input
def get_vsp_id(vsp_name):
diff --git a/onap-client/onap_client/sdnc/preload.py b/onap-client/onap_client/sdnc/preload.py
index a8e4a77..8f67feb 100644
--- a/onap-client/onap_client/sdnc/preload.py
+++ b/onap-client/onap_client/sdnc/preload.py
@@ -56,26 +56,6 @@ class Preload(Resource):
"heat_template_name": {"type": str, "required": True},
}
- def __init__(
- self,
- preload_path,
- vnf_instance_name,
- service_instance_name,
- module_instance_name,
- heat_template_name,
- api_type,
- ):
- instance_input = {}
-
- instance_input["preload_path"] = preload_path
- instance_input["vnf_instance_name"] = vnf_instance_name
- instance_input["service_instance_name"] = service_instance_name
- instance_input["module_instance_name"] = module_instance_name
- instance_input["heat_template_name"] = heat_template_name
- instance_input["api_type"] = api_type
-
- super().__init__(instance_input)
-
def _create(self, instance_input):
service_instance = so.vnf_instance.get_service_instance(
instance_input.get("service_instance_name")
@@ -132,12 +112,6 @@ class Preload(Resource):
return instance_input
- def _post_create(self):
- pass
-
- def _submit(self):
- pass
-
def create_preload(preload_path, api_type):
oc = Client()
diff --git a/onap-client/onap_client/so/module_instance.py b/onap-client/onap_client/so/module_instance.py
index 75105ed..51c9bc2 100644
--- a/onap-client/onap_client/so/module_instance.py
+++ b/onap-client/onap_client/so/module_instance.py
@@ -59,37 +59,14 @@ class ModuleInstance(Resource):
"api_type": {"type": str, "required": False, "default": "GR_API"},
}
- def __init__(
- self,
- module_instance_name,
- vnf_instance_name,
- service_instance_name,
- requestor_id,
- heat_template_name,
- preload_path,
- tenant_name,
- cloud_owner,
- cloud_region,
- api_type,
- ):
- instance_input = {}
-
- tenant_id = so.service_instance.get_tenant_id(cloud_region, cloud_owner, tenant_name)
-
- instance_input["module_instance_name"] = module_instance_name
- instance_input["vnf_instance_name"] = vnf_instance_name
- instance_input["service_instance_name"] = service_instance_name
- instance_input["requestor_id"] = requestor_id
- instance_input["heat_template_name"] = heat_template_name
- instance_input["preload_path"] = preload_path
+ def _create(self, instance_input):
+ tenant_id = so.service_instance.get_tenant_id(
+ instance_input.get("cloud_region"),
+ instance_input.get("cloud_owner"),
+ instance_input.get("tenant_name")
+ )
instance_input["tenant_id"] = tenant_id
- instance_input["cloud_owner"] = cloud_owner
- instance_input["cloud_region"] = cloud_region
- instance_input["api_type"] = api_type
-
- super().__init__(instance_input)
- def _create(self, instance_input):
service_instance = so.vnf_instance.get_service_instance(
instance_input.get("service_instance_name")
)
@@ -169,24 +146,19 @@ class ModuleInstance(Resource):
return create_module_instance(instance_input)
- def _post_create(self):
- pass
-
- def _submit(self):
- pass
-
def create_module_instance(instance_input):
oc = Client()
- sdnc.preload.Preload(
- instance_input.get("preload_path"),
- instance_input.get("vnf_instance_name"),
- instance_input.get("service_instance_name"),
- instance_input.get("module_instance_name"),
- instance_input.get("heat_template_name"),
- instance_input.get("api_type")
+ preload = sdnc.preload.Preload(
+ preload_path=instance_input.get("preload_path"),
+ vnf_instance_name=instance_input.get("vnf_instance_name"),
+ service_instance_name=instance_input.get("service_instance_name"),
+ module_instance_name=instance_input.get("module_instance_name"),
+ heat_template_name=instance_input.get("heat_template_name"),
+ api_type=instance_input.get("api_type")
)
+ preload.create()
headers = {"X-TransactionId": str(uuid.uuid4())}
module_instance = oc.so.service_instantiation.create_module_instance(
diff --git a/onap-client/onap_client/so/service_instance.py b/onap-client/onap_client/so/service_instance.py
index 6398ac8..10271fa 100644
--- a/onap-client/onap_client/so/service_instance.py
+++ b/onap-client/onap_client/so/service_instance.py
@@ -74,43 +74,15 @@ class ServiceInstance(Resource):
"owning_entity_name": {"type": str, "required": True},
}
- def __init__(
- self,
- service_instance_name,
- requestor_id,
- model_name,
- model_version,
- tenant_name,
- cloud_owner,
- cloud_region,
- api_type,
- service_type,
- customer_name,
- project_name,
- owning_entity_name,
- ):
- self.oc = Client()
-
- instance_input = {}
-
- tenant_id = get_tenant_id(cloud_region, cloud_owner, tenant_name)
-
- instance_input["service_instance_name"] = service_instance_name
- instance_input["requestor_id"] = requestor_id
- instance_input["model_name"] = model_name
- instance_input["model_version"] = model_version
+ def _create(self, instance_input):
+ tenant_id = get_tenant_id(
+ instance_input.get("cloud_region"),
+ instance_input.get("cloud_owner"),
+ instance_input.get("tenant_name")
+ )
instance_input["tenant_id"] = tenant_id
- instance_input["cloud_owner"] = cloud_owner
- instance_input["cloud_region"] = cloud_region
- instance_input["api_type"] = api_type
- instance_input["service_type"] = service_type
- instance_input["customer_id"] = customer_name
- instance_input["project_name"] = project_name
- instance_input["owning_entity_name"] = owning_entity_name
-
- super().__init__(instance_input)
+ instance_input["customer_id"] = instance_input.get("customer_name")
- def _create(self, instance_input):
service_model = self.oc.sdc.service.get_sdc_service(
catalog_service_id=sdc.service.get_service_id(
instance_input.get("model_name")
@@ -128,12 +100,6 @@ class ServiceInstance(Resource):
return create_service_instance(instance_input)
- def _post_create(self):
- pass
-
- def _submit(self):
- pass
-
@utility
def get_service_instance(instance_name):
diff --git a/onap-client/onap_client/so/tests/test_module_instance.py b/onap-client/onap_client/so/tests/test_module_instance.py
index 297fdea..e102702 100644
--- a/onap-client/onap_client/so/tests/test_module_instance.py
+++ b/onap-client/onap_client/so/tests/test_module_instance.py
@@ -212,16 +212,17 @@ def test_module_instance():
)
mi = ModuleInstance(
- MODULE_INSTANCE_NAME,
- VNF_INSTANCE_NAME,
- SERVICE_INSTANCE_NAME,
- "cs0008",
- HEAT_TEMPLATE_NAME,
- "{}/base_preload.json".format(THIS_DIR),
- TENANT_NAME,
- CLOUD_OWNER,
- CLOUD_REGION,
- "GR_API"
+ module_instance_name=MODULE_INSTANCE_NAME,
+ vnf_instance_name=VNF_INSTANCE_NAME,
+ service_instance_name=SERVICE_INSTANCE_NAME,
+ requestor_id="cs0008",
+ heat_template_name=HEAT_TEMPLATE_NAME,
+ preload_path="{}/base_preload.json".format(THIS_DIR),
+ tenant_name=TENANT_NAME,
+ cloud_owner=CLOUD_OWNER,
+ cloud_region=CLOUD_REGION,
+ api_type="GR_API"
)
+ mi.create()
assert mi.module_instance_name == MODULE_INSTANCE_NAME
diff --git a/onap-client/onap_client/so/tests/test_service_instance.py b/onap-client/onap_client/so/tests/test_service_instance.py
index e0afccc..b215fbf 100644
--- a/onap-client/onap_client/so/tests/test_service_instance.py
+++ b/onap-client/onap_client/so/tests/test_service_instance.py
@@ -119,18 +119,19 @@ def test_service_instance():
)
si = ServiceInstance(
- SERVICE_INSTANCE_NAME,
- "cs0008",
- SERVICE_MODEL_NAME,
- "1.0",
- TENANT_NAME,
- CLOUD_OWNER,
- CLOUD_REGION,
- "GR_API",
- "ONAPSERVICE",
- "ONAPCUSTOMER",
- "ONAPPROJECT",
- OWNING_ENTITY_NAME
+ service_instance_name=SERVICE_INSTANCE_NAME,
+ requestor_id="cs0008",
+ model_name=SERVICE_MODEL_NAME,
+ model_version="1.0",
+ tenant_name=TENANT_NAME,
+ cloud_owner=CLOUD_OWNER,
+ cloud_region=CLOUD_REGION,
+ api_type="GR_API",
+ service_type="ONAPSERVICE",
+ customer_name="ONAPCUSTOMER",
+ project_name="ONAPPROJECT",
+ owning_entity_name=OWNING_ENTITY_NAME
)
+ si.create()
assert si.service_instance_name == SERVICE_INSTANCE_NAME
diff --git a/onap-client/onap_client/so/tests/test_vnf_instance.py b/onap-client/onap_client/so/tests/test_vnf_instance.py
index 3805da8..cecdb39 100644
--- a/onap-client/onap_client/so/tests/test_vnf_instance.py
+++ b/onap-client/onap_client/so/tests/test_vnf_instance.py
@@ -159,16 +159,17 @@ def test_vnf_instance():
)
vnfi = VNFInstance(
- VNF_INSTANCE_NAME,
- SERVICE_INSTANCE_NAME,
- "cs0008",
- VNF_MODEL_NAME,
- TENANT_NAME,
- CLOUD_OWNER,
- CLOUD_REGION,
- "GR_API",
- "platform",
- "lob"
+ vnf_instance_name=VNF_INSTANCE_NAME,
+ service_instance_name=SERVICE_INSTANCE_NAME,
+ requestor_id="cs0008",
+ model_name=VNF_MODEL_NAME,
+ tenant_name=TENANT_NAME,
+ cloud_owner=CLOUD_OWNER,
+ cloud_region=CLOUD_REGION,
+ api_type="GR_API",
+ platform="platform",
+ line_of_business="lob"
)
+ vnfi.create()
assert vnfi.vnf_instance_name == VNF_INSTANCE_NAME
diff --git a/onap-client/onap_client/so/vnf_instance.py b/onap-client/onap_client/so/vnf_instance.py
index 4d289a0..abb26c3 100644
--- a/onap-client/onap_client/so/vnf_instance.py
+++ b/onap-client/onap_client/so/vnf_instance.py
@@ -77,37 +77,14 @@ class VNFInstance(Resource):
"line_of_business": {"type": str, "required": True},
}
- def __init__(
- self,
- vnf_instance_name,
- service_instance_name,
- requestor_id,
- model_name,
- tenant_name,
- cloud_owner,
- cloud_region,
- api_type,
- platform,
- line_of_business,
- ):
- instance_input = {}
-
- tenant_id = so.service_instance.get_tenant_id(cloud_region, cloud_owner, tenant_name)
-
- instance_input["vnf_instance_name"] = vnf_instance_name
- instance_input["service_instance_name"] = service_instance_name
- instance_input["requestor_id"] = requestor_id
- instance_input["model_name"] = model_name
+ def _create(self, instance_input):
+ tenant_id = so.service_instance.get_tenant_id(
+ instance_input.get("cloud_region"),
+ instance_input.get("cloud_owner"),
+ instance_input.get("tenant_name")
+ )
instance_input["tenant_id"] = tenant_id
- instance_input["cloud_owner"] = cloud_owner
- instance_input["cloud_region"] = cloud_region
- instance_input["api_type"] = api_type
- instance_input["platform"] = platform
- instance_input["line_of_business"] = line_of_business
- super().__init__(instance_input)
-
- def _create(self, instance_input):
service_instance = get_service_instance(
instance_input.get("service_instance_name")
)
@@ -156,12 +133,6 @@ class VNFInstance(Resource):
return create_vnf_instance(instance_input)
- def _post_create(self):
- pass
-
- def _submit(self):
- pass
-
def get_vnf_model_component(service_model_name, vnf_model_name):
service_model = sdc_client.service.get_sdc_service(
diff --git a/onap-client/onap_client/tests/test_resource.py b/onap-client/onap_client/tests/test_resource.py
index 5b4124a..6f7a014 100644
--- a/onap-client/onap_client/tests/test_resource.py
+++ b/onap-client/onap_client/tests/test_resource.py
@@ -34,20 +34,16 @@
# limitations under the License.
#
# ============LICENSE_END============================================
-
from onap_client.resource import Resource
-from onap_client.lib import generate_dummy_string, generate_dummy_date
class TestResource(Resource):
- def __init__(self, test_param):
- test_input = {}
-
- test_input["param1"] = test_param
- test_input["param2"] = generate_dummy_string()
- test_input["param3"] = generate_dummy_date()
-
- super().__init__(test_input)
+ spec = {
+ "param1": {
+ "type": str,
+ "required": True,
+ },
+ }
def _create(self, create_input):
return create_input
@@ -62,7 +58,7 @@ class TestResource(Resource):
def test_resource():
test_param = "abc"
- r = TestResource(test_param)
- r.print()
+ r = TestResource(param1=test_param)
+ r.create()
assert hasattr(r, "param1") and r.param1 == test_param
diff --git a/onap-client/onap_client/tests/testdata.py b/onap-client/onap_client/tests/testdata.py
index c5cb235..14f15c7 100644
--- a/onap-client/onap_client/tests/testdata.py
+++ b/onap-client/onap_client/tests/testdata.py
@@ -70,14 +70,6 @@ class TestResource(Resource):
},
}
- def __init__(self, test1, test2):
- instance_input = {}
-
- instance_input["test1"] = test1
- instance_input["test2"] = test2
-
- super().__init__(instance_input)
-
def _create(self, instance_input):
print("creating test instance {}".format(instance_input))