Code Coverage

Cobertura Coverage Report > osmclient.common >

package_handling.py

Trend

File Coverage summary

NameClassesLinesConditionals
package_handling.py
100%
1/1
29%
8/28
100%
0/0

Coverage Breakdown by Class

NameLinesConditionals
package_handling.py
29%
8/28
N/A

Source

osmclient/common/package_handling.py
1 # Copyright ETSI Contributors and Others.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 1 import osmclient.common.utils as utils
17 1 import os
18
19 1 SOL004_TOSCA = "SOL004_TOSCA"
20 1 SOL004 = "SOL004"
21 1 SOL007_TOSCA = "SOL007_TOSCA"
22 1 SOL007 = "SOL007"
23 1 OSM_OLD = "OSM_OLD"
24
25
26 1 def get_package_type(package_folder):
27     """
28     Detects the package's structure and returns the type:
29     SOL004
30     SOL007
31     OSM_OLD
32     """
33
34 0     package_files = os.listdir(package_folder)
35 0     if "Definitions" in package_files and "TOSCA-Metadata" in package_files:
36 0         descriptors = [
37             definition
38             for definition in os.listdir(package_folder + "/Definitions")
39             if definition.endswith(".yaml") or definition.endswith(".yml")
40         ]
41 0         if len(descriptors) < 1:
42 0             raise Exception(
43                 "No descriptor found on this package, OSM was expecting at least 1"
44             )
45 0         pkg_type = utils.get_key_val_from_pkg(descriptors[0])
46 0         if pkg_type == "nsd":
47 0             return SOL007_TOSCA
48         else:
49 0             return SOL004_TOSCA
50     else:
51 0         manifests = [afile for afile in package_files if afile.endswith(".mf")]
52 0         if len(manifests) < 1:
53             # No manifest found, probably old OSM package structure
54 0             return OSM_OLD
55         else:
56 0             descriptors = [
57                 definition
58                 for definition in package_files
59                 if definition.endswith(".yaml") or definition.endswith(".yml")
60             ]
61 0             if len(descriptors) < 1:
62 0                 raise Exception(
63                     "No descriptor found on this package, OSM was expecting at least 1"
64                 )
65 0             with open(os.path.join(package_folder, descriptors[0])) as descriptor:
66 0                 pkg_type = utils.get_key_val_from_descriptor(descriptor)
67 0                 if pkg_type["type"] == "nsd":
68 0                     return SOL007
69                 else:
70 0                     return SOL004