summaryrefslogtreecommitdiffstats
path: root/nfvparser/toscaparser/tests
diff options
context:
space:
mode:
authorshangxdy <shang.xiaodong@zte.com.cn>2017-09-26 20:40:39 +0800
committershangxdy <shang.xiaodong@zte.com.cn>2017-09-26 20:47:53 +0800
commit000ea52b78b072435f01d67dd799023117e67a2e (patch)
tree1f14cdb4485e2184904b553b82afd9e7139a18e5 /nfvparser/toscaparser/tests
parent53065490134870ead778bff590cfd9e43ddd9f77 (diff)
Sync code from nfv-toscaprser
Currently nfv-toscaparser has published the regular version of 0.5.1 the patch will synchronize the code. JIRA: MODELING-23 Change-Id: If95579fc366b69b2b14b2e441ff9a3e6807e3820 Signed-off-by: shangxdy <shang.xiaodong@zte.com.cn>
Diffstat (limited to 'nfvparser/toscaparser/tests')
-rw-r--r--nfvparser/toscaparser/tests/data/custom_types/container_cap_child.yaml33
-rw-r--r--nfvparser/toscaparser/tests/data/custom_types/custom_cap.yaml22
-rw-r--r--nfvparser/toscaparser/tests/data/custom_types/nested_test_kibana.yaml3
-rw-r--r--nfvparser/toscaparser/tests/data/custom_types/node_with_cap.yaml7
-rw-r--r--nfvparser/toscaparser/tests/data/custom_types/wordpress.yml19
-rw-r--r--nfvparser/toscaparser/tests/data/functions/test_container_cap_child.yaml28
-rw-r--r--nfvparser/toscaparser/tests/data/functions/test_get_prop_cap_bool.yaml37
-rw-r--r--nfvparser/toscaparser/tests/data/functions/test_get_prop_cap_host.yaml25
-rw-r--r--nfvparser/toscaparser/tests/data/policies/tosca_policy_template.yaml26
-rw-r--r--nfvparser/toscaparser/tests/data/test_custom_capabilty.yaml23
-rw-r--r--nfvparser/toscaparser/tests/data/test_instance_nested_imports.yaml4
-rw-r--r--nfvparser/toscaparser/tests/data/topology_template/definitions.yaml2
-rw-r--r--nfvparser/toscaparser/tests/data/tosca_helloworld_with_version_1_1.yaml23
-rw-r--r--nfvparser/toscaparser/tests/test_functions.py24
-rw-r--r--nfvparser/toscaparser/tests/test_topology_template.py2
-rw-r--r--nfvparser/toscaparser/tests/test_toscatpl.py18
-rw-r--r--nfvparser/toscaparser/tests/test_toscatplvalidation.py66
17 files changed, 356 insertions, 6 deletions
diff --git a/nfvparser/toscaparser/tests/data/custom_types/container_cap_child.yaml b/nfvparser/toscaparser/tests/data/custom_types/container_cap_child.yaml
new file mode 100644
index 0000000..1df09dd
--- /dev/null
+++ b/nfvparser/toscaparser/tests/data/custom_types/container_cap_child.yaml
@@ -0,0 +1,33 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: >
+ Define a capability class that inherits from tosca.capabilities.Container
+
+capability_types:
+
+ tosca.capabilities.ContainerChild:
+ derived_from: tosca.capabilities.Container
+
+node_types:
+
+ tosca.nodes.SomeNode:
+ derived_from: tosca.nodes.Root
+ properties:
+ some_prop:
+ type: string
+ requirements:
+ - host_child:
+ capability: tosca.capabilities.ContainerChild
+ node: tosca.nodes.SomeNode2
+ relationship: tosca.relationships.HostedOn
+
+ tosca.nodes.SomeNode2:
+ derived_from: tosca.nodes.Root
+ capabilities:
+ host_child:
+ type: tosca.capabilities.ContainerChild
+ requirements:
+ - host:
+ capability: tosca.capabilities.Container
+ node: tosca.nodes.Compute
+ relationship: tosca.relationships.HostedOn
diff --git a/nfvparser/toscaparser/tests/data/custom_types/custom_cap.yaml b/nfvparser/toscaparser/tests/data/custom_types/custom_cap.yaml
new file mode 100644
index 0000000..018bcf6
--- /dev/null
+++ b/nfvparser/toscaparser/tests/data/custom_types/custom_cap.yaml
@@ -0,0 +1,22 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+capability_types:
+
+ tosca.capabilities.SomeCap:
+ derived_from: tosca.capabilities.Container
+
+node_types:
+
+ tosca.nodes.NodeWithReq:
+ derived_from: tosca.nodes.SoftwareComponent
+ requirements:
+ - host:
+ capability: tosca.capabilities.SomeCap
+ relationship: tosca.relationships.HostedOn
+ occurrences: [1, 1]
+
+ tosca.nodes.NodeWithCap:
+ derived_from: tosca.nodes.SoftwareComponent
+ capabilities:
+ host:
+ type: tosca.capabilities.SomeCap
diff --git a/nfvparser/toscaparser/tests/data/custom_types/nested_test_kibana.yaml b/nfvparser/toscaparser/tests/data/custom_types/nested_test_kibana.yaml
new file mode 100644
index 0000000..c8675c6
--- /dev/null
+++ b/nfvparser/toscaparser/tests/data/custom_types/nested_test_kibana.yaml
@@ -0,0 +1,3 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+imports:
+ - custom_types/kibana.yaml
diff --git a/nfvparser/toscaparser/tests/data/custom_types/node_with_cap.yaml b/nfvparser/toscaparser/tests/data/custom_types/node_with_cap.yaml
index b17513f..332f830 100644
--- a/nfvparser/toscaparser/tests/data/custom_types/node_with_cap.yaml
+++ b/nfvparser/toscaparser/tests/data/custom_types/node_with_cap.yaml
@@ -6,7 +6,7 @@ description: >
capability_types:
tosca.capabilities.SomeCap:
- derived_from: tosca.capabilities.Root
+ derived_from: tosca.capabilities.Container
properties:
type:
type: string
@@ -19,6 +19,11 @@ node_types:
tosca.nodes.SomeNode:
derived_from: tosca.nodes.Root
+ properties:
+ some_prop:
+ type: string
+ required: false
+ default: some
requirements:
- some_req:
capability: tosca.capabilities.SomeCap
diff --git a/nfvparser/toscaparser/tests/data/custom_types/wordpress.yml b/nfvparser/toscaparser/tests/data/custom_types/wordpress.yml
new file mode 100644
index 0000000..5899ed9
--- /dev/null
+++ b/nfvparser/toscaparser/tests/data/custom_types/wordpress.yml
@@ -0,0 +1,19 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+node_types:
+ tosca.nodes.WebApplication.WordPress:
+ derived_from: tosca.nodes.WebApplication
+ requirements:
+ - database_endpoint:
+ capability: tosca.capabilities.Endpoint.Database
+ node: tosca.nodes.Database
+ relationship: tosca.relationships.ConnectsTo
+ interfaces:
+ Standard:
+ inputs:
+ wp_db_name:
+ type: string
+ wp_db_user:
+ type: string
+ wp_db_password:
+ type: string
diff --git a/nfvparser/toscaparser/tests/data/functions/test_container_cap_child.yaml b/nfvparser/toscaparser/tests/data/functions/test_container_cap_child.yaml
new file mode 100644
index 0000000..84118c8
--- /dev/null
+++ b/nfvparser/toscaparser/tests/data/functions/test_container_cap_child.yaml
@@ -0,0 +1,28 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: >
+ TOSCA simple profile to test the get attribute function with HOST parameter
+ using a node that has as capability a child class of Container
+
+imports:
+ - ../custom_types/container_cap_child.yaml
+
+topology_template:
+
+ node_templates:
+
+ test_node:
+ type: tosca.nodes.SomeNode
+ properties:
+ some_prop: { get_attribute: [ HOST, public_address ] }
+ requirements:
+ - host_child: test_node2
+
+ test_node2:
+ type: tosca.nodes.SomeNode2
+ requirements:
+ - host: server
+
+ server:
+ type: tosca.nodes.Compute
+
diff --git a/nfvparser/toscaparser/tests/data/functions/test_get_prop_cap_bool.yaml b/nfvparser/toscaparser/tests/data/functions/test_get_prop_cap_bool.yaml
new file mode 100644
index 0000000..d9c4c1c
--- /dev/null
+++ b/nfvparser/toscaparser/tests/data/functions/test_get_prop_cap_bool.yaml
@@ -0,0 +1,37 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: TOSCA test for boolean properties
+
+node_types:
+
+ tosca.nodes.SoftwareComponentTest:
+ derived_from: tosca.nodes.SoftwareComponent
+ properties:
+ some_prop:
+ type: boolean
+
+ tosca.nodes.ComputeTest:
+ derived_from: tosca.nodes.Compute
+ capabilities:
+ endpoint:
+ type: tosca.capabilities.Endpoint
+
+topology_template:
+
+ node_templates:
+
+ software:
+ type: tosca.nodes.SoftwareComponentTest
+ properties:
+ some_prop: { get_property: [ HOST, endpoint, secure ] }
+ requirements:
+ - host: server
+
+ server:
+ type: tosca.nodes.ComputeTest
+ capabilities:
+ endpoint:
+ properties:
+ network_name: PUBLIC
+ secure: false
+
diff --git a/nfvparser/toscaparser/tests/data/functions/test_get_prop_cap_host.yaml b/nfvparser/toscaparser/tests/data/functions/test_get_prop_cap_host.yaml
new file mode 100644
index 0000000..7fcb4a7
--- /dev/null
+++ b/nfvparser/toscaparser/tests/data/functions/test_get_prop_cap_host.yaml
@@ -0,0 +1,25 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: TOSCA test for the IM
+
+imports:
+ - test: ../custom_types/node_with_cap.yaml
+
+topology_template:
+
+ node_templates:
+
+ some_node:
+ type: tosca.nodes.SomeNode
+ properties:
+ some_prop: { get_property: [ HOST, some_req, type ] }
+ requirements:
+ - some_req: server
+
+ server:
+ type: tosca.nodes.NodeWithCap
+ capabilities:
+ some_req:
+ properties:
+ type: someval
+
diff --git a/nfvparser/toscaparser/tests/data/policies/tosca_policy_template.yaml b/nfvparser/toscaparser/tests/data/policies/tosca_policy_template.yaml
index 47f7870..4c18d9d 100644
--- a/nfvparser/toscaparser/tests/data/policies/tosca_policy_template.yaml
+++ b/nfvparser/toscaparser/tests/data/policies/tosca_policy_template.yaml
@@ -75,6 +75,32 @@ topology_template:
inputs:
strategy: LEAST_USED
implementation: Senlin.webhook()
+ high_cpu_usage:
+ description: trigger
+ meter_name: cpu_util
+ condition:
+ constraint: utilization greater_than 60%
+ threshold: 60
+ period: 600
+ evaluations: 1
+ method: average
+ comparison_operator: gt
+ metadata: SG1
+ action: [SP1]
+
+ low_cpu_usage:
+ description: trigger
+ meter_name: cpu_util
+ condition:
+ constraint: utilization less_than 20%
+ threshold: 20
+ period: 600
+ evaluations: 1
+ method: average
+ comparison_operator: gt
+ metadata: SG1
+ action: [SP1]
+
- my_groups_placement:
type: mycompany.mytypes.myScalingPolicy
targets: [ webserver_group ]
diff --git a/nfvparser/toscaparser/tests/data/test_custom_capabilty.yaml b/nfvparser/toscaparser/tests/data/test_custom_capabilty.yaml
new file mode 100644
index 0000000..03a8a07
--- /dev/null
+++ b/nfvparser/toscaparser/tests/data/test_custom_capabilty.yaml
@@ -0,0 +1,23 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: TOSCA simple profile to test a custom defined capability
+
+imports:
+ - custom_types/custom_cap.yaml
+
+topology_template:
+
+ node_templates:
+
+ node_req:
+ type: tosca.nodes.NodeWithReq
+ requirements:
+ - host: node_cap
+
+ node_cap:
+ type: tosca.nodes.NodeWithCap
+ requirements:
+ - host: server
+
+ server:
+ type: tosca.nodes.Compute
diff --git a/nfvparser/toscaparser/tests/data/test_instance_nested_imports.yaml b/nfvparser/toscaparser/tests/data/test_instance_nested_imports.yaml
index 6aa9307..a130e49 100644
--- a/nfvparser/toscaparser/tests/data/test_instance_nested_imports.yaml
+++ b/nfvparser/toscaparser/tests/data/test_instance_nested_imports.yaml
@@ -5,6 +5,7 @@ description: >
imports:
- wordpress: custom_types/nested_test_wordpress.yaml
+ - custom_types/nested_test_kibana.yaml
topology_template:
@@ -20,3 +21,6 @@ topology_template:
logstash:
type: tosca.nodes.SoftwareComponent.Logstash
+
+ kibana:
+ type: tosca.nodes.SoftwareComponent.Kibana
diff --git a/nfvparser/toscaparser/tests/data/topology_template/definitions.yaml b/nfvparser/toscaparser/tests/data/topology_template/definitions.yaml
index ba5eac1..300bb8a 100644
--- a/nfvparser/toscaparser/tests/data/topology_template/definitions.yaml
+++ b/nfvparser/toscaparser/tests/data/topology_template/definitions.yaml
@@ -49,7 +49,7 @@ node_types:
derived_from: tosca.nodes.Database
example.SomeApp:
- derived_from: tosca.nodes.SoftwareComponent
+ derived_from: tosca.nodes.WebApplication
properties:
admin_user:
type: string
diff --git a/nfvparser/toscaparser/tests/data/tosca_helloworld_with_version_1_1.yaml b/nfvparser/toscaparser/tests/data/tosca_helloworld_with_version_1_1.yaml
new file mode 100644
index 0000000..eeb5f7b
--- /dev/null
+++ b/nfvparser/toscaparser/tests/data/tosca_helloworld_with_version_1_1.yaml
@@ -0,0 +1,23 @@
+tosca_definitions_version: tosca_simple_yaml_1_1
+
+description: Template for deploying a single server with predefined properties.
+
+topology_template:
+ node_templates:
+ my_server:
+ type: tosca.nodes.Compute
+ capabilities:
+ # Host container properties
+ host:
+ properties:
+ num_cpus: 2
+ disk_size: 10 GB
+ mem_size: 512 MB
+ # Guest Operating System properties
+ os:
+ properties:
+ # host Operating System image properties
+ architecture: x86_64
+ type: Linux
+ distribution: RHEL
+ version: 6.5
diff --git a/nfvparser/toscaparser/tests/test_functions.py b/nfvparser/toscaparser/tests/test_functions.py
index fa60140..2e1d71e 100644
--- a/nfvparser/toscaparser/tests/test_functions.py
+++ b/nfvparser/toscaparser/tests/test_functions.py
@@ -188,6 +188,26 @@ class IntrinsicFunctionsTest(TestCase):
self.assertIsInstance(source_port, functions.GetProperty)
self.assertEqual(3306, source_port.result())
+ def test_get_prop_cap_host(self):
+ tosca_tpl = os.path.join(
+ os.path.dirname(os.path.abspath(__file__)),
+ "data/functions/test_get_prop_cap_host.yaml")
+ some_node = self._get_node('some_node',
+ ToscaTemplate(tosca_tpl))
+ some_prop = some_node.get_properties()['some_prop']
+ self.assertIsInstance(some_prop.value, functions.GetProperty)
+ self.assertEqual('someval', some_prop.value.result())
+
+ def test_get_prop_cap_bool(self):
+ tosca_tpl = os.path.join(
+ os.path.dirname(os.path.abspath(__file__)),
+ "data/functions/test_get_prop_cap_bool.yaml")
+ some_node = self._get_node('software',
+ ToscaTemplate(tosca_tpl))
+ some_prop = some_node.get_properties()['some_prop']
+ self.assertIsInstance(some_prop.value, functions.GetProperty)
+ self.assertEqual(False, some_prop.value.result())
+
class GetAttributeTest(TestCase):
@@ -318,6 +338,10 @@ class GetAttributeTest(TestCase):
self.assertIsNotNone(self._load_template(
'functions/test_get_implicit_attribute.yaml'))
+ def test_get_attribute_capability_inheritance(self):
+ self.assertIsNotNone(self._load_template(
+ 'functions/test_container_cap_child.yaml'))
+
class ConcatTest(TestCase):
diff --git a/nfvparser/toscaparser/tests/test_topology_template.py b/nfvparser/toscaparser/tests/test_topology_template.py
index 3aabc9b..a0d6dc3 100644
--- a/nfvparser/toscaparser/tests/test_topology_template.py
+++ b/nfvparser/toscaparser/tests/test_topology_template.py
@@ -91,7 +91,7 @@ class TopologyTemplateTest(TestCase):
tpl_name = "app"
expected_type = "example.SomeApp"
expected_properties = ['admin_user', 'pool_size']
- expected_capabilities = ['feature', 'message_receiver']
+ expected_capabilities = ['app_endpoint', 'feature', 'message_receiver']
expected_requirements = [{'host': {'node': 'websrv'}}]
expected_relationshp = ['tosca.relationships.HostedOn']
expected_host = ['websrv']
diff --git a/nfvparser/toscaparser/tests/test_toscatpl.py b/nfvparser/toscaparser/tests/test_toscatpl.py
index fac8687..fd8ee90 100644
--- a/nfvparser/toscaparser/tests/test_toscatpl.py
+++ b/nfvparser/toscaparser/tests/test_toscatpl.py
@@ -216,6 +216,10 @@ class ToscaTemplateTest(TestCase):
tosca_tpl = self._load_template('test_no_outputs_in_template.yaml')
self.assertEqual(0, len(tosca_tpl.outputs))
+ def test_template_file_with_suffix_yml(self):
+ tosca_tpl = self._load_template('custom_types/wordpress.yml')
+ self.assertIsNotNone(tosca_tpl)
+
def test_relationship_interface(self):
template = ToscaTemplate(self.tosca_elk_tpl)
for node_tpl in template.nodetemplates:
@@ -510,7 +514,8 @@ class ToscaTemplateTest(TestCase):
os.path.dirname(os.path.abspath(__file__)),
"data/test_instance_nested_imports.yaml")
tosca = ToscaTemplate(tosca_tpl)
- expected_custom_types = ['tosca.nodes.WebApplication.WordPress',
+ expected_custom_types = ['tosca.nodes.SoftwareComponent.Kibana',
+ 'tosca.nodes.WebApplication.WordPress',
'test_namespace_prefix.Rsyslog',
'Test2ndRsyslogType',
'test_2nd_namespace_prefix.Rsyslog',
@@ -661,6 +666,17 @@ class ToscaTemplateTest(TestCase):
self.assertEqual(tosca.version, "tosca_simple_yaml_1_0")
+ def test_yaml_dict_tpl_with_version_1_1(self):
+ test_tpl = os.path.join(
+ os.path.dirname(os.path.abspath(__file__)),
+ "data/tosca_helloworld_with_version_1_1.yaml")
+
+ yaml_dict_tpl = toscaparser.utils.yamlparser.load_yaml(test_tpl)
+
+ tosca = ToscaTemplate(yaml_dict_tpl=yaml_dict_tpl)
+
+ self.assertEqual(tosca.version, "tosca_simple_yaml_1_1")
+
def test_yaml_dict_tpl_with_params_and_url_import(self):
test_tpl = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
diff --git a/nfvparser/toscaparser/tests/test_toscatplvalidation.py b/nfvparser/toscaparser/tests/test_toscatplvalidation.py
index 911867f..a8b1590 100644
--- a/nfvparser/toscaparser/tests/test_toscatplvalidation.py
+++ b/nfvparser/toscaparser/tests/test_toscatplvalidation.py
@@ -101,6 +101,7 @@ class ToscaTemplateValidationTest(TestCase):
_('The template version "tosca_simple_yaml_1_10 in '
'custom_types/imported_sample.yaml" is invalid. '
'Valid versions are "tosca_simple_yaml_1_0, '
+ 'tosca_simple_yaml_1_1, '
'tosca_simple_profile_for_nfv_1_0_0".'))
exception.ExceptionCollector.assertExceptionMessage(
exception.UnknownFieldError,
@@ -446,6 +447,18 @@ heat-translator/master/translator/tests/data/custom_types/wordpress.yaml
self.assertTrue(custom_defs.get("mycompany.tosca.nodes."
"WebApplication.WordPress"))
+ def test_imports_file_with_suffix_yml(self):
+ tpl_snippet = '''
+ imports:
+ - custom_types/wordpress.yml
+ '''
+ path = 'toscaparser/tests/data/tosca_elk.yaml'
+ custom_defs = self._imports_content_test(tpl_snippet,
+ path,
+ "node_types")
+ self.assertTrue(custom_defs.get("tosca.nodes."
+ "WebApplication.WordPress"))
+
def test_import_error_file_uri(self):
tpl_snippet = '''
imports:
@@ -1581,7 +1594,7 @@ heat-translator/master/translator/tests/data/custom_types/wordpress.yaml
lambda: Policy(name, policies[name], None, None))
self.assertEqual(expectedmessage, err.__str__())
- def test_policy_trigger_valid_keyname(self):
+ def test_policy_trigger_valid_keyname_senlin_resources(self):
tpl_snippet = '''
triggers:
- resize_compute:
@@ -1610,7 +1623,28 @@ heat-translator/master/translator/tests/data/custom_types/wordpress.yaml
name = list(triggers.keys())[0]
Triggers(name, triggers[name])
- def test_policy_trigger_invalid_keyname(self):
+ def test_policy_trigger_valid_keyname_heat_resources(self):
+ tpl_snippet = '''
+ triggers:
+ - high_cpu_usage:
+ description: trigger
+ meter_name: cpu_util
+ condition:
+ constraint: utilization greater_than 60%
+ threshold: 60
+ period: 600
+ evaluations: 1
+ method: average
+ comparison_operator: gt
+ metadata: SG1
+ action: [SP1]
+ '''
+ triggers = (toscaparser.utils.yamlparser.
+ simple_parse(tpl_snippet))['triggers'][0]
+ name = list(triggers.keys())[0]
+ Triggers(name, triggers[name])
+
+ def test_policy_trigger_invalid_keyname_senlin_resources(self):
tpl_snippet = '''
triggers:
- resize_compute:
@@ -1646,6 +1680,34 @@ heat-translator/master/translator/tests/data/custom_types/wordpress.yaml
lambda: Triggers(name, triggers[name]))
self.assertEqual(expectedmessage, err.__str__())
+ def test_policy_trigger_invalid_keyname_heat_resources(self):
+ tpl_snippet = '''
+ triggers:
+ - high_cpu_usage:
+ description: trigger
+ meter_name: cpu_util
+ condition:
+ constraint: utilization greater_than 60%
+ threshold: 60
+ period: 600
+ evaluations: 1
+ method: average
+ comparison_operator: gt
+ metadata1: SG1
+ action: [SP1]
+ '''
+ triggers = (toscaparser.utils.yamlparser.
+ simple_parse(tpl_snippet))['triggers'][0]
+ name = list(triggers.keys())[0]
+ expectedmessage = _(
+ 'Triggers "high_cpu_usage" contains unknown field '
+ '"metadata1". Refer to the definition '
+ 'to verify valid values.')
+ err = self.assertRaises(
+ exception.UnknownFieldError,
+ lambda: Triggers(name, triggers[name]))
+ self.assertEqual(expectedmessage, err.__str__())
+
def test_policy_missing_required_keyname(self):
tpl_snippet = '''
policies: