From 6a3e9d53686eda1d45fb54b97869a594741f089c Mon Sep 17 00:00:00 2001 From: Zhaoxing Date: Fri, 22 Sep 2017 15:40:57 +0800 Subject: Move python files to root dir Change-Id: I16a66e1f6bcb65cbb68f2b622618252885ab47fc Issue-Id: MODELING-20 Signed-off-by: Zhaoxing --- nfvparser/.coveragerc | 7 + nfvparser/.gitignore | 56 + nfvparser/.gitreview | 4 + nfvparser/.mailmap | 3 + nfvparser/.testr.conf | 7 + nfvparser/LICENSE | 175 ++ nfvparser/MANIFEST.in | 14 + nfvparser/README.md | 55 + nfvparser/babel.cfg | 1 + nfvparser/openstack-common.conf | 6 + nfvparser/requirements.txt | 10 + nfvparser/setup.cfg | 43 + nfvparser/setup.py | 29 + nfvparser/src/main/python/.coveragerc | 7 - nfvparser/src/main/python/.gitignore | 56 - nfvparser/src/main/python/.gitreview | 4 - nfvparser/src/main/python/.mailmap | 3 - nfvparser/src/main/python/.testr.conf | 7 - nfvparser/src/main/python/LICENSE | 175 -- nfvparser/src/main/python/MANIFEST.in | 14 - nfvparser/src/main/python/README.md | 55 - nfvparser/src/main/python/babel.cfg | 1 - nfvparser/src/main/python/openstack-common.conf | 6 - nfvparser/src/main/python/requirements.txt | 10 - nfvparser/src/main/python/setup.cfg | 43 - nfvparser/src/main/python/setup.py | 29 - nfvparser/src/main/python/test-requirements.txt | 13 - nfvparser/src/main/python/tools/tox_install.sh | 30 - nfvparser/src/main/python/tosca_parser.py | 32 - nfvparser/src/main/python/toscaparser/__init__.py | 17 - .../src/main/python/toscaparser/capabilities.py | 45 - .../src/main/python/toscaparser/common/__init__.py | 0 .../main/python/toscaparser/common/exception.py | 246 --- .../src/main/python/toscaparser/dataentity.py | 182 -- .../toscaparser/elements/TOSCA_definition_1_0.yaml | 952 ----------- .../main/python/toscaparser/elements/__init__.py | 0 .../python/toscaparser/elements/artifacttype.py | 50 - .../toscaparser/elements/attribute_definition.py | 20 - .../python/toscaparser/elements/capabilitytype.py | 96 -- .../python/toscaparser/elements/constraints.py | 615 ------- .../main/python/toscaparser/elements/datatype.py | 57 - .../python/toscaparser/elements/entity_type.py | 170 -- .../main/python/toscaparser/elements/grouptype.py | 95 -- .../main/python/toscaparser/elements/interfaces.py | 87 - .../main/python/toscaparser/elements/nodetype.py | 213 --- .../main/python/toscaparser/elements/policytype.py | 121 -- .../python/toscaparser/elements/portspectype.py | 86 - .../toscaparser/elements/property_definition.py | 100 -- .../toscaparser/elements/relationshiptype.py | 49 - .../main/python/toscaparser/elements/scalarunit.py | 129 -- .../toscaparser/elements/statefulentitytype.py | 91 - .../toscaparser/elements/tosca_type_validation.py | 59 - .../src/main/python/toscaparser/entity_template.py | 329 ---- .../main/python/toscaparser/extensions/__init__.py | 0 .../main/python/toscaparser/extensions/exttools.py | 88 - .../extensions/nfv/TOSCA_nfv_definition_1_0_0.yaml | 240 --- .../python/toscaparser/extensions/nfv/__init__.py | 0 .../toscaparser/extensions/nfv/tests/__init__.py | 0 .../nfv/tests/data/tosca_helloworld_nfv.yaml | 31 - .../data/vRNC/Definitions/rnc_definition.yaml | 173 -- .../nfv/tests/data/vRNC/Definitions/vRNC.yaml | 552 ------ .../extensions/nfv/tests/data/vRNC/README.txt | 22 - .../nfv/tests/data/vRNC/TOSCA-Metadata/TOSCA.meta | 4 - .../extensions/nfv/tests/test_tosca_nfv_tpl.py | 29 - .../extensions/nfv/tests/test_tosca_vRNC.py | 62 - .../nfv/tosca_simple_profile_for_nfv_1_0_0.py | 19 - nfvparser/src/main/python/toscaparser/functions.py | 826 --------- nfvparser/src/main/python/toscaparser/groups.py | 55 - nfvparser/src/main/python/toscaparser/imports.py | 290 ---- .../src/main/python/toscaparser/nodetemplate.py | 298 ---- .../src/main/python/toscaparser/parameters.py | 128 -- nfvparser/src/main/python/toscaparser/policy.py | 81 - .../src/main/python/toscaparser/prereq/__init__.py | 0 .../src/main/python/toscaparser/prereq/csar.py | 286 ---- .../src/main/python/toscaparser/properties.py | 77 - .../python/toscaparser/relationship_template.py | 78 - .../src/main/python/toscaparser/repositories.py | 52 - nfvparser/src/main/python/toscaparser/shell.py | 120 -- .../python/toscaparser/substitution_mappings.py | 228 --- .../src/main/python/toscaparser/tests/__init__.py | 0 .../toscaparser/tests/artifacts/collectd/config.py | 25 - .../toscaparser/tests/artifacts/collectd/create.sh | 5 - .../toscaparser/tests/artifacts/collectd/start.sh | 4 - .../tests/artifacts/elasticsearch/create.sh | 14 - .../tests/artifacts/elasticsearch/start.sh | 4 - .../toscaparser/tests/artifacts/kibana/config.sh | 7 - .../toscaparser/tests/artifacts/kibana/create.sh | 12 - .../toscaparser/tests/artifacts/kibana/start.sh | 4 - .../tests/artifacts/logstash/configure_collectd.py | 28 - .../artifacts/logstash/configure_elasticsearch.py | 26 - .../tests/artifacts/logstash/configure_rsyslog.py | 25 - .../toscaparser/tests/artifacts/logstash/create.sh | 20 - .../toscaparser/tests/artifacts/logstash/start.sh | 4 - .../toscaparser/tests/artifacts/mongodb/config.sh | 7 - .../toscaparser/tests/artifacts/mongodb/create.sh | 14 - .../tests/artifacts/mongodb/create_database.sh | 5 - .../toscaparser/tests/artifacts/mongodb/start.sh | 5 - .../artifacts/mysql/mysql_database_configure.sh | 8 - .../tests/artifacts/mysql/mysql_dbms_configure.sh | 5 - .../tests/artifacts/mysql/mysql_dbms_install.sh | 9 - .../tests/artifacts/mysql/mysql_dbms_start.sh | 2 - .../toscaparser/tests/artifacts/nodejs/config.sh | 28 - .../toscaparser/tests/artifacts/nodejs/create.sh | 7 - .../toscaparser/tests/artifacts/nodejs/start.sh | 3 - .../toscaparser/tests/artifacts/rsyslog/config.sh | 30 - .../toscaparser/tests/artifacts/rsyslog/create.sh | 5 - .../toscaparser/tests/artifacts/rsyslog/start.sh | 4 - .../tests/artifacts/webserver/webserver_install.sh | 5 - .../tests/artifacts/webserver/webserver_start.sh | 2 - .../artifacts/wordpress/wordpress_configure.sh | 4 - .../tests/artifacts/wordpress/wordpress_install.sh | 5 - .../src/main/python/toscaparser/tests/base.py | 65 - .../toscaparser/tests/data/CSAR/csar_elk.csar | Bin 17490 -> 0 bytes .../toscaparser/tests/data/CSAR/csar_elk.zip | Bin 17490 -> 0 bytes .../tests/data/CSAR/csar_hello_world.zip | Bin 936 -> 0 bytes .../tests/data/CSAR/csar_invalid_entry_def.zip | Bin 940 -> 0 bytes .../tests/data/CSAR/csar_metadata_not_yaml.zip | Bin 936 -> 0 bytes .../tests/data/CSAR/csar_missing_metadata.zip | Bin 933 -> 0 bytes .../tests/data/CSAR/csar_no_metadata_file.zip | Bin 496 -> 0 bytes .../toscaparser/tests/data/CSAR/csar_not_zip.zip | 1 - .../toscaparser/tests/data/CSAR/csar_wordpress.zip | Bin 5967 -> 0 bytes .../CSAR/csar_wordpress_invalid_import_path.zip | Bin 5978 -> 0 bytes .../CSAR/csar_wordpress_invalid_import_url.zip | Bin 6043 -> 0 bytes .../CSAR/csar_wordpress_invalid_script_path.zip | Bin 5969 -> 0 bytes .../CSAR/csar_wordpress_invalid_script_url.zip | Bin 6043 -> 0 bytes .../csar_wordpress_with_url_import_and_script.zip | Bin 6046 -> 0 bytes .../tests/data/CSAR/csar_wrong_metadata_file.zip | Bin 873 -> 0 bytes .../data/CSAR/tosca_elk/Definitions/collectd.yaml | 13 - .../CSAR/tosca_elk/Definitions/elasticsearch.yaml | 11 - .../data/CSAR/tosca_elk/Definitions/kibana.yaml | 16 - .../data/CSAR/tosca_elk/Definitions/logstash.yaml | 25 - .../Definitions/paypalpizzastore_nodejs_app.yaml | 29 - .../data/CSAR/tosca_elk/Definitions/rsyslog.yaml | 13 - .../data/CSAR/tosca_elk/Definitions/tosca_elk.yaml | 217 --- .../data/CSAR/tosca_elk/Python/collectd/config.py | 25 - .../Python/logstash/configure_collectd.py | 28 - .../Python/logstash/configure_elasticsearch.py | 26 - .../tosca_elk/Python/logstash/configure_rsyslog.py | 25 - .../tests/data/CSAR/tosca_elk/README.txt | 5 - .../data/CSAR/tosca_elk/Scripts/collectd/create.sh | 5 - .../data/CSAR/tosca_elk/Scripts/collectd/start.sh | 4 - .../CSAR/tosca_elk/Scripts/elasticsearch/create.sh | 14 - .../CSAR/tosca_elk/Scripts/elasticsearch/start.sh | 4 - .../data/CSAR/tosca_elk/Scripts/kibana/config.sh | 7 - .../data/CSAR/tosca_elk/Scripts/kibana/create.sh | 12 - .../data/CSAR/tosca_elk/Scripts/kibana/start.sh | 4 - .../data/CSAR/tosca_elk/Scripts/logstash/create.sh | 20 - .../data/CSAR/tosca_elk/Scripts/logstash/start.sh | 4 - .../data/CSAR/tosca_elk/Scripts/mongodb/config.sh | 7 - .../data/CSAR/tosca_elk/Scripts/mongodb/create.sh | 14 - .../tosca_elk/Scripts/mongodb/create_database.sh | 5 - .../data/CSAR/tosca_elk/Scripts/mongodb/start.sh | 5 - .../data/CSAR/tosca_elk/Scripts/nodejs/config.sh | 28 - .../data/CSAR/tosca_elk/Scripts/nodejs/create.sh | 7 - .../data/CSAR/tosca_elk/Scripts/nodejs/start.sh | 3 - .../data/CSAR/tosca_elk/Scripts/rsyslog/config.sh | 30 - .../data/CSAR/tosca_elk/Scripts/rsyslog/create.sh | 5 - .../data/CSAR/tosca_elk/Scripts/rsyslog/start.sh | 4 - .../data/CSAR/tosca_elk/TOSCA-Metadata/TOSCA.meta | 4 - .../tosca_single_instance_wordpress.yaml | 109 -- .../Definitions/wordpress.yaml | 19 - .../tosca_single_instance_wordpress/README.txt | 22 - .../Scripts/MYSQLDBMS/configure.sh | 5 - .../Scripts/MYSQLDBMS/install.sh | 9 - .../Scripts/MYSQLDBMS/start.sh | 2 - .../Scripts/MYSQLDatabase/configure.sh | 8 - .../Scripts/WebServer/install.sh | 5 - .../Scripts/WebServer/start.sh | 2 - .../Scripts/WordPress/configure.sh | 4 - .../Scripts/WordPress/install.sh | 5 - .../TOSCA-Metadata/TOSCA.meta | 5 - .../containers/test_container_docker_mysql.yaml | 44 - .../tests/data/custom_types/collectd.yaml | 13 - .../custom_types/compute_with_attribute_list.yaml | 13 - .../compute_with_nested_atributes.yaml | 22 - .../tests/data/custom_types/compute_with_prop.yaml | 13 - .../tests/data/custom_types/custom_caps_def.yaml | 22 - .../tests/data/custom_types/custom_interface.yaml | 20 - .../custom_relationship_type_defs.yaml | 23 - .../data/custom_types/db_with_list_param.yaml | 10 - .../tests/data/custom_types/elasticsearch.yaml | 12 - .../tests/data/custom_types/imported_sample.yaml | 38 - .../tests/data/custom_types/kibana.yaml | 14 - .../tests/data/custom_types/logstash.yaml | 25 - .../tests/data/custom_types/nested_rsyslog.yaml | 17 - .../data/custom_types/nested_test_wordpress.yaml | 32 - .../tests/data/custom_types/node_with_cap.yaml | 33 - .../custom_types/paypalpizzastore_nodejs_app.yaml | 29 - .../tests/data/custom_types/rsyslog.yaml | 13 - .../tests/data/custom_types/wordpress.yaml | 19 - .../tests/data/datatypes/custom_datatype_def.yaml | 53 - .../test_custom_datatypes_in_current_template.yaml | 70 - ...est_custom_datatypes_nested_datatype_error.yaml | 25 - .../datatypes/test_custom_datatypes_positive.yaml | 24 - .../test_custom_datatypes_value_error.yaml | 18 - .../datatypes/test_datatype_portspec_add_req.yaml | 41 - .../data/dsl_definitions/test_nested_dsl_def.yaml | 23 - .../functions/test_capabilties_inheritance.yaml | 25 - .../tests/data/functions/test_concat.yaml | 30 - .../tests/data/functions/test_concat_invalid.yaml | 9 - .../functions/test_get_attribute_host_keyword.yaml | 33 - .../test_get_attribute_host_not_found.yaml | 20 - ...test_get_attribute_illegal_host_in_outputs.yaml | 17 - .../test_get_attribute_source_target_keywords.yaml | 30 - .../test_get_attribute_unknown_attribute_name.yaml | 28 - ...t_get_attribute_unknown_node_template_name.yaml | 30 - .../functions/test_get_attribute_with_index.yaml | 19 - .../test_get_attribute_with_index_error.yaml | 19 - .../test_get_attribute_with_nested_params.yaml | 23 - .../functions/test_get_implicit_attribute.yaml | 25 - .../test_get_property_source_target_keywords.yaml | 35 - .../functions/test_get_property_with_host.yaml | 65 - .../functions/test_invalid_function_signature.yaml | 34 - .../tests/data/functions/test_token.yaml | 15 - .../tests/data/functions/test_token_invalid.yaml | 17 - .../test_unknown_capability_property.yaml | 36 - .../functions/test_unknown_input_in_interface.yaml | 20 - .../functions/test_unknown_input_in_property.yaml | 13 - .../tosca_nested_property_names_indexes.yaml | 47 - .../toscaparser/tests/data/groups/definitions.yaml | 10 - .../tests/data/groups/tosca_group_template.yaml | 54 - .../test_custom_interface_in_template.yaml | 23 - .../test_custom_interface_invalid_operation.yaml | 19 - .../data/load_balancer/tosca_load_balancer.yaml | 75 - .../tests/data/node_filter/test_node_filter.yaml | 18 - .../tests/data/policies/custom_definitions.yaml | 10 - .../tests/data/policies/tacker_defs.yaml | 183 -- .../tests/data/policies/tacker_nfv_defs.yaml | 261 --- .../policies/test_tosca_nfv_multiple_policies.yaml | 95 -- .../tests/data/policies/tosca_policy_template.yaml | 85 - .../relationship/test_custom_relationship.yaml | 48 - .../repositories/test_repositories_definition.yaml | 23 - .../tosca_repositories_test_definition.yaml | 26 - .../tests/data/requirements/test_requirements.yaml | 67 - .../tests/data/test_attributes_inheritance.yaml | 28 - .../tests/data/test_available_rel_tpls.yaml | 23 - .../toscaparser/tests/data/test_containers.yaml | 44 - .../tests/data/test_credential_datatype.yaml | 77 - .../tests/data/test_custom_caps_def.yaml | 13 - .../tests/data/test_custom_relationships.yaml | 48 - .../tests/data/test_endpoint_on_compute.yaml | 21 - .../tests/data/test_instance_nested_imports.yaml | 22 - .../tests/data/test_invalid_input_defaults.yaml | 12 - .../tests/data/test_invalid_section_names.yaml | 25 - .../tests/data/test_invalid_template_version.yaml | 14 - .../data/test_multiple_validation_errors.yaml | 128 -- .../tests/data/test_no_inputs_in_template.yaml | 17 - .../tests/data/test_no_outputs_in_template.yaml | 15 - .../toscaparser/tests/data/test_node_filter.yaml | 18 - .../test_normative_type_properties_override.yaml | 37 - .../tests/data/test_repositories_definition.yaml | 23 - .../toscaparser/tests/data/test_requirements.yaml | 67 - .../data/test_tosca_custom_rel_with_script.yaml | 23 - .../test_tosca_normative_type_by_shortname.yaml | 34 - .../tests/data/test_tosca_top_level_error1.yaml | 2 - .../tests/data/test_tosca_top_level_error2.yaml | 11 - .../data/topology_template/databasesubsystem.yaml | 81 - .../tests/data/topology_template/definitions.yaml | 74 - .../data/topology_template/queuingsubsystem.yaml | 75 - .../tests/data/topology_template/system.yaml | 62 - .../topology_template/transactionsubsystem.yaml | 88 - .../validate/queuingsubsystem_invalid_input.yaml | 76 - .../validate/system_invalid_input.yaml | 24 - .../validate/system_invalid_missing_output.yaml | 24 - .../validate/system_invalid_unknown_output.yaml | 24 - .../test_example_app_substitution_mappings.yaml | 70 - .../test_substitution_mappings_invalid_output.yaml | 31 - .../test_substitution_mappings_valid_output.yaml | 31 - ...ransactionsubsystem_invalid_missing_output.yaml | 92 - ...ransactionsubsystem_invalid_unknown_output.yaml | 94 -- .../python/toscaparser/tests/data/tosca_elk.yaml | 217 --- .../toscaparser/tests/data/tosca_helloworld.yaml | 23 - .../tests/data/tosca_imports_validation.yaml | 45 - .../tests/data/tosca_load_balancer.yaml | 75 - .../data/tosca_repositories_test_definition.yaml | 26 - .../data/tosca_single_instance_wordpress.yaml | 121 -- ...stance_wordpress_with_local_abspath_import.yaml | 122 -- ..._single_instance_wordpress_with_url_import.yaml | 120 -- .../data/tosca_test_get_operation_output.yaml | 19 - .../v1.0/network/tosca_one_server_one_network.yaml | 43 - .../network/tosca_one_server_three_networks.yaml | 64 - .../network/tosca_server_on_existing_network.yaml | 39 - .../network/tosca_two_servers_one_network.yaml | 79 - .../tosca_blockstorage_with_attachment.yaml | 61 - ...sca_blockstorage_with_attachment_notation1.yaml | 87 - ...sca_blockstorage_with_attachment_notation2.yaml | 99 -- ...blockstorage_with_custom_relationship_type.yaml | 64 - ...ca_blockstorage_with_relationship_template.yaml | 59 - ...osca_multiple_blockstorage_with_attachment.yaml | 93 - .../v1.0/storage/tosca_single_object_store.yaml | 17 - .../v1.0/tosca_nodejs_mongodb_two_instances.yaml | 96 -- .../spec_samples/v1.0/tosca_single_server.yaml | 32 - .../python/toscaparser/tests/test_constraints.py | 373 ---- .../toscaparser/tests/test_custom_relationships.py | 35 - .../python/toscaparser/tests/test_datatypes.py | 517 ------ .../python/toscaparser/tests/test_exception.py | 42 - .../python/toscaparser/tests/test_functions.py | 373 ---- .../main/python/toscaparser/tests/test_prereq.py | 230 --- .../python/toscaparser/tests/test_properties.py | 368 ---- .../python/toscaparser/tests/test_scalarunit.py | 355 ---- .../main/python/toscaparser/tests/test_shell.py | 51 - .../toscaparser/tests/test_topology_template.py | 313 ---- .../main/python/toscaparser/tests/test_toscadef.py | 346 ---- .../main/python/toscaparser/tests/test_toscatpl.py | 854 ---------- .../toscaparser/tests/test_toscatplvalidation.py | 1784 -------------------- .../main/python/toscaparser/tests/test_utils.py | 48 - .../tests/test_validate_tosca_version.py | 132 -- .../main/python/toscaparser/topology_template.py | 310 ---- .../src/main/python/toscaparser/tosca_template.py | 344 ---- .../python/toscaparser/tpl_relationship_graph.py | 46 - nfvparser/src/main/python/toscaparser/triggers.py | 68 - .../src/main/python/toscaparser/unsupportedtype.py | 50 - .../src/main/python/toscaparser/utils/__init__.py | 0 .../main/python/toscaparser/utils/gettextutils.py | 23 - .../src/main/python/toscaparser/utils/urlutils.py | 65 - .../main/python/toscaparser/utils/validateutils.py | 236 --- .../main/python/toscaparser/utils/yamlparser.py | 86 - nfvparser/src/main/python/tox.ini | 37 - nfvparser/test-requirements.txt | 13 + nfvparser/tools/tox_install.sh | 30 + nfvparser/tosca_parser.py | 32 + nfvparser/toscaparser/__init__.py | 17 + nfvparser/toscaparser/capabilities.py | 45 + nfvparser/toscaparser/common/__init__.py | 0 nfvparser/toscaparser/common/exception.py | 246 +++ nfvparser/toscaparser/dataentity.py | 182 ++ .../toscaparser/elements/TOSCA_definition_1_0.yaml | 952 +++++++++++ nfvparser/toscaparser/elements/__init__.py | 0 nfvparser/toscaparser/elements/artifacttype.py | 50 + .../toscaparser/elements/attribute_definition.py | 20 + nfvparser/toscaparser/elements/capabilitytype.py | 96 ++ nfvparser/toscaparser/elements/constraints.py | 615 +++++++ nfvparser/toscaparser/elements/datatype.py | 57 + nfvparser/toscaparser/elements/entity_type.py | 170 ++ nfvparser/toscaparser/elements/grouptype.py | 95 ++ nfvparser/toscaparser/elements/interfaces.py | 87 + nfvparser/toscaparser/elements/nodetype.py | 213 +++ nfvparser/toscaparser/elements/policytype.py | 121 ++ nfvparser/toscaparser/elements/portspectype.py | 86 + .../toscaparser/elements/property_definition.py | 100 ++ nfvparser/toscaparser/elements/relationshiptype.py | 49 + nfvparser/toscaparser/elements/scalarunit.py | 129 ++ .../toscaparser/elements/statefulentitytype.py | 91 + .../toscaparser/elements/tosca_type_validation.py | 59 + nfvparser/toscaparser/entity_template.py | 329 ++++ nfvparser/toscaparser/extensions/__init__.py | 0 nfvparser/toscaparser/extensions/exttools.py | 88 + .../extensions/nfv/TOSCA_nfv_definition_1_0_0.yaml | 240 +++ nfvparser/toscaparser/extensions/nfv/__init__.py | 0 .../toscaparser/extensions/nfv/tests/__init__.py | 0 .../nfv/tests/data/tosca_helloworld_nfv.yaml | 31 + .../data/vRNC/Definitions/rnc_definition.yaml | 173 ++ .../nfv/tests/data/vRNC/Definitions/vRNC.yaml | 552 ++++++ .../extensions/nfv/tests/data/vRNC/README.txt | 22 + .../nfv/tests/data/vRNC/TOSCA-Metadata/TOSCA.meta | 4 + .../extensions/nfv/tests/test_tosca_nfv_tpl.py | 29 + .../extensions/nfv/tests/test_tosca_vRNC.py | 62 + .../nfv/tosca_simple_profile_for_nfv_1_0_0.py | 19 + nfvparser/toscaparser/functions.py | 826 +++++++++ nfvparser/toscaparser/groups.py | 55 + nfvparser/toscaparser/imports.py | 290 ++++ nfvparser/toscaparser/nodetemplate.py | 298 ++++ nfvparser/toscaparser/parameters.py | 128 ++ nfvparser/toscaparser/policy.py | 81 + nfvparser/toscaparser/prereq/__init__.py | 0 nfvparser/toscaparser/prereq/csar.py | 286 ++++ nfvparser/toscaparser/properties.py | 77 + nfvparser/toscaparser/relationship_template.py | 78 + nfvparser/toscaparser/repositories.py | 52 + nfvparser/toscaparser/shell.py | 120 ++ nfvparser/toscaparser/substitution_mappings.py | 228 +++ nfvparser/toscaparser/tests/__init__.py | 0 .../toscaparser/tests/artifacts/collectd/config.py | 25 + .../toscaparser/tests/artifacts/collectd/create.sh | 5 + .../toscaparser/tests/artifacts/collectd/start.sh | 4 + .../tests/artifacts/elasticsearch/create.sh | 14 + .../tests/artifacts/elasticsearch/start.sh | 4 + .../toscaparser/tests/artifacts/kibana/config.sh | 7 + .../toscaparser/tests/artifacts/kibana/create.sh | 12 + .../toscaparser/tests/artifacts/kibana/start.sh | 4 + .../tests/artifacts/logstash/configure_collectd.py | 28 + .../artifacts/logstash/configure_elasticsearch.py | 26 + .../tests/artifacts/logstash/configure_rsyslog.py | 25 + .../toscaparser/tests/artifacts/logstash/create.sh | 20 + .../toscaparser/tests/artifacts/logstash/start.sh | 4 + .../toscaparser/tests/artifacts/mongodb/config.sh | 7 + .../toscaparser/tests/artifacts/mongodb/create.sh | 14 + .../tests/artifacts/mongodb/create_database.sh | 5 + .../toscaparser/tests/artifacts/mongodb/start.sh | 5 + .../artifacts/mysql/mysql_database_configure.sh | 8 + .../tests/artifacts/mysql/mysql_dbms_configure.sh | 5 + .../tests/artifacts/mysql/mysql_dbms_install.sh | 9 + .../tests/artifacts/mysql/mysql_dbms_start.sh | 2 + .../toscaparser/tests/artifacts/nodejs/config.sh | 28 + .../toscaparser/tests/artifacts/nodejs/create.sh | 7 + .../toscaparser/tests/artifacts/nodejs/start.sh | 3 + .../toscaparser/tests/artifacts/rsyslog/config.sh | 30 + .../toscaparser/tests/artifacts/rsyslog/create.sh | 5 + .../toscaparser/tests/artifacts/rsyslog/start.sh | 4 + .../tests/artifacts/webserver/webserver_install.sh | 5 + .../tests/artifacts/webserver/webserver_start.sh | 2 + .../artifacts/wordpress/wordpress_configure.sh | 4 + .../tests/artifacts/wordpress/wordpress_install.sh | 5 + nfvparser/toscaparser/tests/base.py | 65 + .../toscaparser/tests/data/CSAR/csar_elk.csar | Bin 0 -> 17490 bytes nfvparser/toscaparser/tests/data/CSAR/csar_elk.zip | Bin 0 -> 17490 bytes .../tests/data/CSAR/csar_hello_world.zip | Bin 0 -> 936 bytes .../tests/data/CSAR/csar_invalid_entry_def.zip | Bin 0 -> 940 bytes .../tests/data/CSAR/csar_metadata_not_yaml.zip | Bin 0 -> 936 bytes .../tests/data/CSAR/csar_missing_metadata.zip | Bin 0 -> 933 bytes .../tests/data/CSAR/csar_no_metadata_file.zip | Bin 0 -> 496 bytes .../toscaparser/tests/data/CSAR/csar_not_zip.zip | 1 + .../toscaparser/tests/data/CSAR/csar_wordpress.zip | Bin 0 -> 5967 bytes .../CSAR/csar_wordpress_invalid_import_path.zip | Bin 0 -> 5978 bytes .../CSAR/csar_wordpress_invalid_import_url.zip | Bin 0 -> 6043 bytes .../CSAR/csar_wordpress_invalid_script_path.zip | Bin 0 -> 5969 bytes .../CSAR/csar_wordpress_invalid_script_url.zip | Bin 0 -> 6043 bytes .../csar_wordpress_with_url_import_and_script.zip | Bin 0 -> 6046 bytes .../tests/data/CSAR/csar_wrong_metadata_file.zip | Bin 0 -> 873 bytes .../data/CSAR/tosca_elk/Definitions/collectd.yaml | 13 + .../CSAR/tosca_elk/Definitions/elasticsearch.yaml | 11 + .../data/CSAR/tosca_elk/Definitions/kibana.yaml | 16 + .../data/CSAR/tosca_elk/Definitions/logstash.yaml | 25 + .../Definitions/paypalpizzastore_nodejs_app.yaml | 29 + .../data/CSAR/tosca_elk/Definitions/rsyslog.yaml | 13 + .../data/CSAR/tosca_elk/Definitions/tosca_elk.yaml | 217 +++ .../data/CSAR/tosca_elk/Python/collectd/config.py | 25 + .../Python/logstash/configure_collectd.py | 28 + .../Python/logstash/configure_elasticsearch.py | 26 + .../tosca_elk/Python/logstash/configure_rsyslog.py | 25 + .../tests/data/CSAR/tosca_elk/README.txt | 5 + .../data/CSAR/tosca_elk/Scripts/collectd/create.sh | 5 + .../data/CSAR/tosca_elk/Scripts/collectd/start.sh | 4 + .../CSAR/tosca_elk/Scripts/elasticsearch/create.sh | 14 + .../CSAR/tosca_elk/Scripts/elasticsearch/start.sh | 4 + .../data/CSAR/tosca_elk/Scripts/kibana/config.sh | 7 + .../data/CSAR/tosca_elk/Scripts/kibana/create.sh | 12 + .../data/CSAR/tosca_elk/Scripts/kibana/start.sh | 4 + .../data/CSAR/tosca_elk/Scripts/logstash/create.sh | 20 + .../data/CSAR/tosca_elk/Scripts/logstash/start.sh | 4 + .../data/CSAR/tosca_elk/Scripts/mongodb/config.sh | 7 + .../data/CSAR/tosca_elk/Scripts/mongodb/create.sh | 14 + .../tosca_elk/Scripts/mongodb/create_database.sh | 5 + .../data/CSAR/tosca_elk/Scripts/mongodb/start.sh | 5 + .../data/CSAR/tosca_elk/Scripts/nodejs/config.sh | 28 + .../data/CSAR/tosca_elk/Scripts/nodejs/create.sh | 7 + .../data/CSAR/tosca_elk/Scripts/nodejs/start.sh | 3 + .../data/CSAR/tosca_elk/Scripts/rsyslog/config.sh | 30 + .../data/CSAR/tosca_elk/Scripts/rsyslog/create.sh | 5 + .../data/CSAR/tosca_elk/Scripts/rsyslog/start.sh | 4 + .../data/CSAR/tosca_elk/TOSCA-Metadata/TOSCA.meta | 4 + .../tosca_single_instance_wordpress.yaml | 109 ++ .../Definitions/wordpress.yaml | 19 + .../tosca_single_instance_wordpress/README.txt | 22 + .../Scripts/MYSQLDBMS/configure.sh | 5 + .../Scripts/MYSQLDBMS/install.sh | 9 + .../Scripts/MYSQLDBMS/start.sh | 2 + .../Scripts/MYSQLDatabase/configure.sh | 8 + .../Scripts/WebServer/install.sh | 5 + .../Scripts/WebServer/start.sh | 2 + .../Scripts/WordPress/configure.sh | 4 + .../Scripts/WordPress/install.sh | 5 + .../TOSCA-Metadata/TOSCA.meta | 5 + .../containers/test_container_docker_mysql.yaml | 44 + .../tests/data/custom_types/collectd.yaml | 13 + .../custom_types/compute_with_attribute_list.yaml | 13 + .../compute_with_nested_atributes.yaml | 22 + .../tests/data/custom_types/compute_with_prop.yaml | 13 + .../tests/data/custom_types/custom_caps_def.yaml | 22 + .../tests/data/custom_types/custom_interface.yaml | 20 + .../custom_relationship_type_defs.yaml | 23 + .../data/custom_types/db_with_list_param.yaml | 10 + .../tests/data/custom_types/elasticsearch.yaml | 12 + .../tests/data/custom_types/imported_sample.yaml | 38 + .../tests/data/custom_types/kibana.yaml | 14 + .../tests/data/custom_types/logstash.yaml | 25 + .../tests/data/custom_types/nested_rsyslog.yaml | 17 + .../data/custom_types/nested_test_wordpress.yaml | 32 + .../tests/data/custom_types/node_with_cap.yaml | 33 + .../custom_types/paypalpizzastore_nodejs_app.yaml | 29 + .../tests/data/custom_types/rsyslog.yaml | 13 + .../tests/data/custom_types/wordpress.yaml | 19 + .../tests/data/datatypes/custom_datatype_def.yaml | 53 + .../test_custom_datatypes_in_current_template.yaml | 70 + ...est_custom_datatypes_nested_datatype_error.yaml | 25 + .../datatypes/test_custom_datatypes_positive.yaml | 24 + .../test_custom_datatypes_value_error.yaml | 18 + .../datatypes/test_datatype_portspec_add_req.yaml | 41 + .../data/dsl_definitions/test_nested_dsl_def.yaml | 23 + .../functions/test_capabilties_inheritance.yaml | 25 + .../tests/data/functions/test_concat.yaml | 30 + .../tests/data/functions/test_concat_invalid.yaml | 9 + .../functions/test_get_attribute_host_keyword.yaml | 33 + .../test_get_attribute_host_not_found.yaml | 20 + ...test_get_attribute_illegal_host_in_outputs.yaml | 17 + .../test_get_attribute_source_target_keywords.yaml | 30 + .../test_get_attribute_unknown_attribute_name.yaml | 28 + ...t_get_attribute_unknown_node_template_name.yaml | 30 + .../functions/test_get_attribute_with_index.yaml | 19 + .../test_get_attribute_with_index_error.yaml | 19 + .../test_get_attribute_with_nested_params.yaml | 23 + .../functions/test_get_implicit_attribute.yaml | 25 + .../test_get_property_source_target_keywords.yaml | 35 + .../functions/test_get_property_with_host.yaml | 65 + .../functions/test_invalid_function_signature.yaml | 34 + .../tests/data/functions/test_token.yaml | 15 + .../tests/data/functions/test_token_invalid.yaml | 17 + .../test_unknown_capability_property.yaml | 36 + .../functions/test_unknown_input_in_interface.yaml | 20 + .../functions/test_unknown_input_in_property.yaml | 13 + .../tosca_nested_property_names_indexes.yaml | 47 + .../toscaparser/tests/data/groups/definitions.yaml | 10 + .../tests/data/groups/tosca_group_template.yaml | 54 + .../test_custom_interface_in_template.yaml | 23 + .../test_custom_interface_invalid_operation.yaml | 19 + .../data/load_balancer/tosca_load_balancer.yaml | 75 + .../tests/data/node_filter/test_node_filter.yaml | 18 + .../tests/data/policies/custom_definitions.yaml | 10 + .../tests/data/policies/tacker_defs.yaml | 183 ++ .../tests/data/policies/tacker_nfv_defs.yaml | 261 +++ .../policies/test_tosca_nfv_multiple_policies.yaml | 95 ++ .../tests/data/policies/tosca_policy_template.yaml | 85 + .../relationship/test_custom_relationship.yaml | 48 + .../repositories/test_repositories_definition.yaml | 23 + .../tosca_repositories_test_definition.yaml | 26 + .../tests/data/requirements/test_requirements.yaml | 67 + .../tests/data/test_attributes_inheritance.yaml | 28 + .../tests/data/test_available_rel_tpls.yaml | 23 + .../toscaparser/tests/data/test_containers.yaml | 44 + .../tests/data/test_credential_datatype.yaml | 77 + .../tests/data/test_custom_caps_def.yaml | 13 + .../tests/data/test_custom_relationships.yaml | 48 + .../tests/data/test_endpoint_on_compute.yaml | 21 + .../tests/data/test_instance_nested_imports.yaml | 22 + .../tests/data/test_invalid_input_defaults.yaml | 12 + .../tests/data/test_invalid_section_names.yaml | 25 + .../tests/data/test_invalid_template_version.yaml | 14 + .../data/test_multiple_validation_errors.yaml | 128 ++ .../tests/data/test_no_inputs_in_template.yaml | 17 + .../tests/data/test_no_outputs_in_template.yaml | 15 + .../toscaparser/tests/data/test_node_filter.yaml | 18 + .../test_normative_type_properties_override.yaml | 37 + .../tests/data/test_repositories_definition.yaml | 23 + .../toscaparser/tests/data/test_requirements.yaml | 67 + .../data/test_tosca_custom_rel_with_script.yaml | 23 + .../test_tosca_normative_type_by_shortname.yaml | 34 + .../tests/data/test_tosca_top_level_error1.yaml | 2 + .../tests/data/test_tosca_top_level_error2.yaml | 11 + .../data/topology_template/databasesubsystem.yaml | 81 + .../tests/data/topology_template/definitions.yaml | 74 + .../data/topology_template/queuingsubsystem.yaml | 75 + .../tests/data/topology_template/system.yaml | 62 + .../topology_template/transactionsubsystem.yaml | 88 + .../validate/queuingsubsystem_invalid_input.yaml | 76 + .../validate/system_invalid_input.yaml | 24 + .../validate/system_invalid_missing_output.yaml | 24 + .../validate/system_invalid_unknown_output.yaml | 24 + .../test_example_app_substitution_mappings.yaml | 70 + .../test_substitution_mappings_invalid_output.yaml | 31 + .../test_substitution_mappings_valid_output.yaml | 31 + ...ransactionsubsystem_invalid_missing_output.yaml | 92 + ...ransactionsubsystem_invalid_unknown_output.yaml | 94 ++ nfvparser/toscaparser/tests/data/tosca_elk.yaml | 217 +++ .../toscaparser/tests/data/tosca_helloworld.yaml | 23 + .../tests/data/tosca_imports_validation.yaml | 45 + .../tests/data/tosca_load_balancer.yaml | 75 + .../data/tosca_repositories_test_definition.yaml | 26 + .../data/tosca_single_instance_wordpress.yaml | 121 ++ ...stance_wordpress_with_local_abspath_import.yaml | 122 ++ ..._single_instance_wordpress_with_url_import.yaml | 120 ++ .../data/tosca_test_get_operation_output.yaml | 19 + .../v1.0/network/tosca_one_server_one_network.yaml | 43 + .../network/tosca_one_server_three_networks.yaml | 64 + .../network/tosca_server_on_existing_network.yaml | 39 + .../network/tosca_two_servers_one_network.yaml | 79 + .../tosca_blockstorage_with_attachment.yaml | 61 + ...sca_blockstorage_with_attachment_notation1.yaml | 87 + ...sca_blockstorage_with_attachment_notation2.yaml | 99 ++ ...blockstorage_with_custom_relationship_type.yaml | 64 + ...ca_blockstorage_with_relationship_template.yaml | 59 + ...osca_multiple_blockstorage_with_attachment.yaml | 93 + .../v1.0/storage/tosca_single_object_store.yaml | 17 + .../v1.0/tosca_nodejs_mongodb_two_instances.yaml | 96 ++ .../spec_samples/v1.0/tosca_single_server.yaml | 32 + nfvparser/toscaparser/tests/test_constraints.py | 373 ++++ .../toscaparser/tests/test_custom_relationships.py | 35 + nfvparser/toscaparser/tests/test_datatypes.py | 517 ++++++ nfvparser/toscaparser/tests/test_exception.py | 42 + nfvparser/toscaparser/tests/test_functions.py | 373 ++++ nfvparser/toscaparser/tests/test_prereq.py | 230 +++ nfvparser/toscaparser/tests/test_properties.py | 368 ++++ nfvparser/toscaparser/tests/test_scalarunit.py | 355 ++++ nfvparser/toscaparser/tests/test_shell.py | 51 + .../toscaparser/tests/test_topology_template.py | 313 ++++ nfvparser/toscaparser/tests/test_toscadef.py | 346 ++++ nfvparser/toscaparser/tests/test_toscatpl.py | 854 ++++++++++ .../toscaparser/tests/test_toscatplvalidation.py | 1784 ++++++++++++++++++++ nfvparser/toscaparser/tests/test_utils.py | 48 + .../tests/test_validate_tosca_version.py | 132 ++ nfvparser/toscaparser/topology_template.py | 310 ++++ nfvparser/toscaparser/tosca_template.py | 344 ++++ nfvparser/toscaparser/tpl_relationship_graph.py | 46 + nfvparser/toscaparser/triggers.py | 68 + nfvparser/toscaparser/unsupportedtype.py | 50 + nfvparser/toscaparser/utils/__init__.py | 0 nfvparser/toscaparser/utils/gettextutils.py | 23 + nfvparser/toscaparser/utils/urlutils.py | 65 + nfvparser/toscaparser/utils/validateutils.py | 236 +++ nfvparser/toscaparser/utils/yamlparser.py | 86 + nfvparser/tox.ini | 37 + 610 files changed, 21727 insertions(+), 21727 deletions(-) create mode 100644 nfvparser/.coveragerc create mode 100644 nfvparser/.gitignore create mode 100644 nfvparser/.gitreview create mode 100644 nfvparser/.mailmap create mode 100644 nfvparser/.testr.conf create mode 100644 nfvparser/LICENSE create mode 100644 nfvparser/MANIFEST.in create mode 100644 nfvparser/README.md create mode 100644 nfvparser/babel.cfg create mode 100644 nfvparser/openstack-common.conf create mode 100644 nfvparser/requirements.txt create mode 100644 nfvparser/setup.cfg create mode 100644 nfvparser/setup.py delete mode 100644 nfvparser/src/main/python/.coveragerc delete mode 100644 nfvparser/src/main/python/.gitignore delete mode 100644 nfvparser/src/main/python/.gitreview delete mode 100644 nfvparser/src/main/python/.mailmap delete mode 100644 nfvparser/src/main/python/.testr.conf delete mode 100644 nfvparser/src/main/python/LICENSE delete mode 100644 nfvparser/src/main/python/MANIFEST.in delete mode 100644 nfvparser/src/main/python/README.md delete mode 100644 nfvparser/src/main/python/babel.cfg delete mode 100644 nfvparser/src/main/python/openstack-common.conf delete mode 100644 nfvparser/src/main/python/requirements.txt delete mode 100644 nfvparser/src/main/python/setup.cfg delete mode 100644 nfvparser/src/main/python/setup.py delete mode 100644 nfvparser/src/main/python/test-requirements.txt delete mode 100644 nfvparser/src/main/python/tools/tox_install.sh delete mode 100644 nfvparser/src/main/python/tosca_parser.py delete mode 100644 nfvparser/src/main/python/toscaparser/__init__.py delete mode 100644 nfvparser/src/main/python/toscaparser/capabilities.py delete mode 100644 nfvparser/src/main/python/toscaparser/common/__init__.py delete mode 100644 nfvparser/src/main/python/toscaparser/common/exception.py delete mode 100644 nfvparser/src/main/python/toscaparser/dataentity.py delete mode 100644 nfvparser/src/main/python/toscaparser/elements/TOSCA_definition_1_0.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/elements/__init__.py delete mode 100644 nfvparser/src/main/python/toscaparser/elements/artifacttype.py delete mode 100644 nfvparser/src/main/python/toscaparser/elements/attribute_definition.py delete mode 100644 nfvparser/src/main/python/toscaparser/elements/capabilitytype.py delete mode 100644 nfvparser/src/main/python/toscaparser/elements/constraints.py delete mode 100644 nfvparser/src/main/python/toscaparser/elements/datatype.py delete mode 100644 nfvparser/src/main/python/toscaparser/elements/entity_type.py delete mode 100644 nfvparser/src/main/python/toscaparser/elements/grouptype.py delete mode 100644 nfvparser/src/main/python/toscaparser/elements/interfaces.py delete mode 100644 nfvparser/src/main/python/toscaparser/elements/nodetype.py delete mode 100644 nfvparser/src/main/python/toscaparser/elements/policytype.py delete mode 100644 nfvparser/src/main/python/toscaparser/elements/portspectype.py delete mode 100644 nfvparser/src/main/python/toscaparser/elements/property_definition.py delete mode 100644 nfvparser/src/main/python/toscaparser/elements/relationshiptype.py delete mode 100644 nfvparser/src/main/python/toscaparser/elements/scalarunit.py delete mode 100644 nfvparser/src/main/python/toscaparser/elements/statefulentitytype.py delete mode 100644 nfvparser/src/main/python/toscaparser/elements/tosca_type_validation.py delete mode 100644 nfvparser/src/main/python/toscaparser/entity_template.py delete mode 100644 nfvparser/src/main/python/toscaparser/extensions/__init__.py delete mode 100644 nfvparser/src/main/python/toscaparser/extensions/exttools.py delete mode 100644 nfvparser/src/main/python/toscaparser/extensions/nfv/TOSCA_nfv_definition_1_0_0.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/extensions/nfv/__init__.py delete mode 100644 nfvparser/src/main/python/toscaparser/extensions/nfv/tests/__init__.py delete mode 100644 nfvparser/src/main/python/toscaparser/extensions/nfv/tests/data/tosca_helloworld_nfv.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/rnc_definition.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/vRNC.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/extensions/nfv/tests/data/vRNC/README.txt delete mode 100644 nfvparser/src/main/python/toscaparser/extensions/nfv/tests/data/vRNC/TOSCA-Metadata/TOSCA.meta delete mode 100644 nfvparser/src/main/python/toscaparser/extensions/nfv/tests/test_tosca_nfv_tpl.py delete mode 100644 nfvparser/src/main/python/toscaparser/extensions/nfv/tests/test_tosca_vRNC.py delete mode 100644 nfvparser/src/main/python/toscaparser/extensions/nfv/tosca_simple_profile_for_nfv_1_0_0.py delete mode 100644 nfvparser/src/main/python/toscaparser/functions.py delete mode 100644 nfvparser/src/main/python/toscaparser/groups.py delete mode 100644 nfvparser/src/main/python/toscaparser/imports.py delete mode 100644 nfvparser/src/main/python/toscaparser/nodetemplate.py delete mode 100644 nfvparser/src/main/python/toscaparser/parameters.py delete mode 100644 nfvparser/src/main/python/toscaparser/policy.py delete mode 100644 nfvparser/src/main/python/toscaparser/prereq/__init__.py delete mode 100644 nfvparser/src/main/python/toscaparser/prereq/csar.py delete mode 100644 nfvparser/src/main/python/toscaparser/properties.py delete mode 100644 nfvparser/src/main/python/toscaparser/relationship_template.py delete mode 100644 nfvparser/src/main/python/toscaparser/repositories.py delete mode 100644 nfvparser/src/main/python/toscaparser/shell.py delete mode 100644 nfvparser/src/main/python/toscaparser/substitution_mappings.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/__init__.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/collectd/config.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/collectd/create.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/collectd/start.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/elasticsearch/create.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/elasticsearch/start.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/kibana/config.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/kibana/create.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/kibana/start.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/logstash/configure_collectd.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/logstash/configure_elasticsearch.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/logstash/configure_rsyslog.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/logstash/create.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/logstash/start.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/mongodb/config.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/mongodb/create.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/mongodb/create_database.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/mongodb/start.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/mysql/mysql_database_configure.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/mysql/mysql_dbms_configure.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/mysql/mysql_dbms_install.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/mysql/mysql_dbms_start.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/nodejs/config.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/nodejs/create.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/nodejs/start.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/rsyslog/config.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/rsyslog/create.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/rsyslog/start.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/webserver/webserver_install.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/webserver/webserver_start.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/wordpress/wordpress_configure.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/artifacts/wordpress/wordpress_install.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/base.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_elk.csar delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_elk.zip delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_hello_world.zip delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_invalid_entry_def.zip delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_metadata_not_yaml.zip delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_missing_metadata.zip delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_no_metadata_file.zip delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_not_zip.zip delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress.zip delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress_invalid_import_path.zip delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress_invalid_import_url.zip delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress_invalid_script_path.zip delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress_invalid_script_url.zip delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress_with_url_import_and_script.zip delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wrong_metadata_file.zip delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/collectd.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/elasticsearch.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/kibana.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/logstash.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/paypalpizzastore_nodejs_app.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/rsyslog.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/tosca_elk.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Python/collectd/config.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_collectd.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_elasticsearch.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_rsyslog.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/README.txt delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/collectd/create.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/collectd/start.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/elasticsearch/create.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/elasticsearch/start.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/config.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/create.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/start.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/logstash/create.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/logstash/start.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/config.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/create.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/create_database.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/start.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/config.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/create.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/start.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/config.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/create.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/start.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/TOSCA-Metadata/TOSCA.meta delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Definitions/tosca_single_instance_wordpress.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Definitions/wordpress.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/README.txt delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/configure.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/install.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/start.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDatabase/configure.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WebServer/install.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WebServer/start.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WordPress/configure.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WordPress/install.sh delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/TOSCA-Metadata/TOSCA.meta delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/containers/test_container_docker_mysql.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/custom_types/collectd.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/custom_types/compute_with_attribute_list.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/custom_types/compute_with_nested_atributes.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/custom_types/compute_with_prop.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/custom_types/custom_caps_def.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/custom_types/custom_interface.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/custom_types/custom_relationship_type_defs.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/custom_types/db_with_list_param.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/custom_types/elasticsearch.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/custom_types/imported_sample.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/custom_types/kibana.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/custom_types/logstash.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/custom_types/nested_rsyslog.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/custom_types/nested_test_wordpress.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/custom_types/node_with_cap.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/custom_types/paypalpizzastore_nodejs_app.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/custom_types/rsyslog.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/custom_types/wordpress.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/datatypes/custom_datatype_def.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/datatypes/test_custom_datatypes_in_current_template.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/datatypes/test_custom_datatypes_nested_datatype_error.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/datatypes/test_custom_datatypes_positive.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/datatypes/test_custom_datatypes_value_error.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/datatypes/test_datatype_portspec_add_req.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/dsl_definitions/test_nested_dsl_def.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_capabilties_inheritance.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_concat.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_concat_invalid.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_host_keyword.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_host_not_found.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_illegal_host_in_outputs.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_source_target_keywords.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_unknown_attribute_name.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_unknown_node_template_name.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_with_index.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_with_index_error.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_with_nested_params.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_implicit_attribute.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_property_source_target_keywords.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_property_with_host.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_invalid_function_signature.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_token.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_token_invalid.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_unknown_capability_property.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_unknown_input_in_interface.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/test_unknown_input_in_property.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/functions/tosca_nested_property_names_indexes.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/groups/definitions.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/groups/tosca_group_template.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/interfaces/test_custom_interface_in_template.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/interfaces/test_custom_interface_invalid_operation.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/load_balancer/tosca_load_balancer.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/node_filter/test_node_filter.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/policies/custom_definitions.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/policies/tacker_defs.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/policies/tacker_nfv_defs.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/policies/test_tosca_nfv_multiple_policies.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/policies/tosca_policy_template.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/relationship/test_custom_relationship.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/repositories/test_repositories_definition.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/repositories/tosca_repositories_test_definition.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/requirements/test_requirements.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_attributes_inheritance.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_available_rel_tpls.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_containers.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_credential_datatype.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_custom_caps_def.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_custom_relationships.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_endpoint_on_compute.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_instance_nested_imports.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_invalid_input_defaults.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_invalid_section_names.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_invalid_template_version.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_multiple_validation_errors.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_no_inputs_in_template.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_no_outputs_in_template.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_node_filter.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_normative_type_properties_override.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_repositories_definition.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_requirements.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_tosca_custom_rel_with_script.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_tosca_normative_type_by_shortname.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_tosca_top_level_error1.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/test_tosca_top_level_error2.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/topology_template/databasesubsystem.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/topology_template/definitions.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/topology_template/queuingsubsystem.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/topology_template/system.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/topology_template/transactionsubsystem.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/queuingsubsystem_invalid_input.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/system_invalid_input.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/system_invalid_missing_output.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/system_invalid_unknown_output.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/test_example_app_substitution_mappings.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/test_substitution_mappings_invalid_output.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/test_substitution_mappings_valid_output.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/transactionsubsystem_invalid_missing_output.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/transactionsubsystem_invalid_unknown_output.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/tosca_elk.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/tosca_helloworld.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/tosca_imports_validation.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/tosca_load_balancer.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/tosca_repositories_test_definition.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/tosca_single_instance_wordpress.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/tosca_single_instance_wordpress_with_local_abspath_import.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/tosca_single_instance_wordpress_with_url_import.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/data/tosca_test_get_operation_output.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/network/tosca_one_server_one_network.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/network/tosca_one_server_three_networks.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/network/tosca_server_on_existing_network.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/network/tosca_two_servers_one_network.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment_notation1.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment_notation2.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_custom_relationship_type.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_relationship_template.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_multiple_blockstorage_with_attachment.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_single_object_store.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/tosca_nodejs_mongodb_two_instances.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/tosca_single_server.yaml delete mode 100644 nfvparser/src/main/python/toscaparser/tests/test_constraints.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/test_custom_relationships.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/test_datatypes.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/test_exception.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/test_functions.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/test_prereq.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/test_properties.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/test_scalarunit.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/test_shell.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/test_topology_template.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/test_toscadef.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/test_toscatpl.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/test_toscatplvalidation.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/test_utils.py delete mode 100644 nfvparser/src/main/python/toscaparser/tests/test_validate_tosca_version.py delete mode 100644 nfvparser/src/main/python/toscaparser/topology_template.py delete mode 100644 nfvparser/src/main/python/toscaparser/tosca_template.py delete mode 100644 nfvparser/src/main/python/toscaparser/tpl_relationship_graph.py delete mode 100644 nfvparser/src/main/python/toscaparser/triggers.py delete mode 100644 nfvparser/src/main/python/toscaparser/unsupportedtype.py delete mode 100644 nfvparser/src/main/python/toscaparser/utils/__init__.py delete mode 100644 nfvparser/src/main/python/toscaparser/utils/gettextutils.py delete mode 100644 nfvparser/src/main/python/toscaparser/utils/urlutils.py delete mode 100644 nfvparser/src/main/python/toscaparser/utils/validateutils.py delete mode 100644 nfvparser/src/main/python/toscaparser/utils/yamlparser.py delete mode 100644 nfvparser/src/main/python/tox.ini create mode 100644 nfvparser/test-requirements.txt create mode 100644 nfvparser/tools/tox_install.sh create mode 100644 nfvparser/tosca_parser.py create mode 100644 nfvparser/toscaparser/__init__.py create mode 100644 nfvparser/toscaparser/capabilities.py create mode 100644 nfvparser/toscaparser/common/__init__.py create mode 100644 nfvparser/toscaparser/common/exception.py create mode 100644 nfvparser/toscaparser/dataentity.py create mode 100644 nfvparser/toscaparser/elements/TOSCA_definition_1_0.yaml create mode 100644 nfvparser/toscaparser/elements/__init__.py create mode 100644 nfvparser/toscaparser/elements/artifacttype.py create mode 100644 nfvparser/toscaparser/elements/attribute_definition.py create mode 100644 nfvparser/toscaparser/elements/capabilitytype.py create mode 100644 nfvparser/toscaparser/elements/constraints.py create mode 100644 nfvparser/toscaparser/elements/datatype.py create mode 100644 nfvparser/toscaparser/elements/entity_type.py create mode 100644 nfvparser/toscaparser/elements/grouptype.py create mode 100644 nfvparser/toscaparser/elements/interfaces.py create mode 100644 nfvparser/toscaparser/elements/nodetype.py create mode 100644 nfvparser/toscaparser/elements/policytype.py create mode 100644 nfvparser/toscaparser/elements/portspectype.py create mode 100644 nfvparser/toscaparser/elements/property_definition.py create mode 100644 nfvparser/toscaparser/elements/relationshiptype.py create mode 100644 nfvparser/toscaparser/elements/scalarunit.py create mode 100644 nfvparser/toscaparser/elements/statefulentitytype.py create mode 100644 nfvparser/toscaparser/elements/tosca_type_validation.py create mode 100644 nfvparser/toscaparser/entity_template.py create mode 100644 nfvparser/toscaparser/extensions/__init__.py create mode 100644 nfvparser/toscaparser/extensions/exttools.py create mode 100644 nfvparser/toscaparser/extensions/nfv/TOSCA_nfv_definition_1_0_0.yaml create mode 100644 nfvparser/toscaparser/extensions/nfv/__init__.py create mode 100644 nfvparser/toscaparser/extensions/nfv/tests/__init__.py create mode 100644 nfvparser/toscaparser/extensions/nfv/tests/data/tosca_helloworld_nfv.yaml create mode 100644 nfvparser/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/rnc_definition.yaml create mode 100644 nfvparser/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/vRNC.yaml create mode 100644 nfvparser/toscaparser/extensions/nfv/tests/data/vRNC/README.txt create mode 100644 nfvparser/toscaparser/extensions/nfv/tests/data/vRNC/TOSCA-Metadata/TOSCA.meta create mode 100644 nfvparser/toscaparser/extensions/nfv/tests/test_tosca_nfv_tpl.py create mode 100644 nfvparser/toscaparser/extensions/nfv/tests/test_tosca_vRNC.py create mode 100644 nfvparser/toscaparser/extensions/nfv/tosca_simple_profile_for_nfv_1_0_0.py create mode 100644 nfvparser/toscaparser/functions.py create mode 100644 nfvparser/toscaparser/groups.py create mode 100644 nfvparser/toscaparser/imports.py create mode 100644 nfvparser/toscaparser/nodetemplate.py create mode 100644 nfvparser/toscaparser/parameters.py create mode 100644 nfvparser/toscaparser/policy.py create mode 100644 nfvparser/toscaparser/prereq/__init__.py create mode 100644 nfvparser/toscaparser/prereq/csar.py create mode 100644 nfvparser/toscaparser/properties.py create mode 100644 nfvparser/toscaparser/relationship_template.py create mode 100644 nfvparser/toscaparser/repositories.py create mode 100644 nfvparser/toscaparser/shell.py create mode 100644 nfvparser/toscaparser/substitution_mappings.py create mode 100644 nfvparser/toscaparser/tests/__init__.py create mode 100644 nfvparser/toscaparser/tests/artifacts/collectd/config.py create mode 100644 nfvparser/toscaparser/tests/artifacts/collectd/create.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/collectd/start.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/elasticsearch/create.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/elasticsearch/start.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/kibana/config.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/kibana/create.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/kibana/start.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/logstash/configure_collectd.py create mode 100644 nfvparser/toscaparser/tests/artifacts/logstash/configure_elasticsearch.py create mode 100644 nfvparser/toscaparser/tests/artifacts/logstash/configure_rsyslog.py create mode 100644 nfvparser/toscaparser/tests/artifacts/logstash/create.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/logstash/start.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/mongodb/config.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/mongodb/create.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/mongodb/create_database.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/mongodb/start.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/mysql/mysql_database_configure.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/mysql/mysql_dbms_configure.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/mysql/mysql_dbms_install.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/mysql/mysql_dbms_start.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/nodejs/config.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/nodejs/create.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/nodejs/start.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/rsyslog/config.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/rsyslog/create.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/rsyslog/start.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/webserver/webserver_install.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/webserver/webserver_start.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/wordpress/wordpress_configure.sh create mode 100644 nfvparser/toscaparser/tests/artifacts/wordpress/wordpress_install.sh create mode 100644 nfvparser/toscaparser/tests/base.py create mode 100644 nfvparser/toscaparser/tests/data/CSAR/csar_elk.csar create mode 100644 nfvparser/toscaparser/tests/data/CSAR/csar_elk.zip create mode 100644 nfvparser/toscaparser/tests/data/CSAR/csar_hello_world.zip create mode 100644 nfvparser/toscaparser/tests/data/CSAR/csar_invalid_entry_def.zip create mode 100644 nfvparser/toscaparser/tests/data/CSAR/csar_metadata_not_yaml.zip create mode 100644 nfvparser/toscaparser/tests/data/CSAR/csar_missing_metadata.zip create mode 100644 nfvparser/toscaparser/tests/data/CSAR/csar_no_metadata_file.zip create mode 100644 nfvparser/toscaparser/tests/data/CSAR/csar_not_zip.zip create mode 100644 nfvparser/toscaparser/tests/data/CSAR/csar_wordpress.zip create mode 100644 nfvparser/toscaparser/tests/data/CSAR/csar_wordpress_invalid_import_path.zip create mode 100644 nfvparser/toscaparser/tests/data/CSAR/csar_wordpress_invalid_import_url.zip create mode 100644 nfvparser/toscaparser/tests/data/CSAR/csar_wordpress_invalid_script_path.zip create mode 100644 nfvparser/toscaparser/tests/data/CSAR/csar_wordpress_invalid_script_url.zip create mode 100644 nfvparser/toscaparser/tests/data/CSAR/csar_wordpress_with_url_import_and_script.zip create mode 100644 nfvparser/toscaparser/tests/data/CSAR/csar_wrong_metadata_file.zip create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/collectd.yaml create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/elasticsearch.yaml create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/kibana.yaml create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/logstash.yaml create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/paypalpizzastore_nodejs_app.yaml create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/rsyslog.yaml create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/tosca_elk.yaml create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Python/collectd/config.py create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_collectd.py create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_elasticsearch.py create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_rsyslog.py create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/README.txt create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/collectd/create.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/collectd/start.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/elasticsearch/create.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/elasticsearch/start.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/config.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/create.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/start.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/logstash/create.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/logstash/start.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/config.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/create.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/create_database.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/start.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/config.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/create.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/start.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/config.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/create.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/start.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_elk/TOSCA-Metadata/TOSCA.meta create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Definitions/tosca_single_instance_wordpress.yaml create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Definitions/wordpress.yaml create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/README.txt create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/configure.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/install.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/start.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDatabase/configure.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WebServer/install.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WebServer/start.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WordPress/configure.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WordPress/install.sh create mode 100644 nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/TOSCA-Metadata/TOSCA.meta create mode 100644 nfvparser/toscaparser/tests/data/containers/test_container_docker_mysql.yaml create mode 100644 nfvparser/toscaparser/tests/data/custom_types/collectd.yaml create mode 100644 nfvparser/toscaparser/tests/data/custom_types/compute_with_attribute_list.yaml create mode 100644 nfvparser/toscaparser/tests/data/custom_types/compute_with_nested_atributes.yaml create mode 100644 nfvparser/toscaparser/tests/data/custom_types/compute_with_prop.yaml create mode 100644 nfvparser/toscaparser/tests/data/custom_types/custom_caps_def.yaml create mode 100644 nfvparser/toscaparser/tests/data/custom_types/custom_interface.yaml create mode 100644 nfvparser/toscaparser/tests/data/custom_types/custom_relationship_type_defs.yaml create mode 100644 nfvparser/toscaparser/tests/data/custom_types/db_with_list_param.yaml create mode 100644 nfvparser/toscaparser/tests/data/custom_types/elasticsearch.yaml create mode 100644 nfvparser/toscaparser/tests/data/custom_types/imported_sample.yaml create mode 100644 nfvparser/toscaparser/tests/data/custom_types/kibana.yaml create mode 100644 nfvparser/toscaparser/tests/data/custom_types/logstash.yaml create mode 100644 nfvparser/toscaparser/tests/data/custom_types/nested_rsyslog.yaml create mode 100644 nfvparser/toscaparser/tests/data/custom_types/nested_test_wordpress.yaml create mode 100644 nfvparser/toscaparser/tests/data/custom_types/node_with_cap.yaml create mode 100644 nfvparser/toscaparser/tests/data/custom_types/paypalpizzastore_nodejs_app.yaml create mode 100644 nfvparser/toscaparser/tests/data/custom_types/rsyslog.yaml create mode 100644 nfvparser/toscaparser/tests/data/custom_types/wordpress.yaml create mode 100644 nfvparser/toscaparser/tests/data/datatypes/custom_datatype_def.yaml create mode 100644 nfvparser/toscaparser/tests/data/datatypes/test_custom_datatypes_in_current_template.yaml create mode 100644 nfvparser/toscaparser/tests/data/datatypes/test_custom_datatypes_nested_datatype_error.yaml create mode 100644 nfvparser/toscaparser/tests/data/datatypes/test_custom_datatypes_positive.yaml create mode 100644 nfvparser/toscaparser/tests/data/datatypes/test_custom_datatypes_value_error.yaml create mode 100644 nfvparser/toscaparser/tests/data/datatypes/test_datatype_portspec_add_req.yaml create mode 100644 nfvparser/toscaparser/tests/data/dsl_definitions/test_nested_dsl_def.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_capabilties_inheritance.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_concat.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_concat_invalid.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_get_attribute_host_keyword.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_get_attribute_host_not_found.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_get_attribute_illegal_host_in_outputs.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_get_attribute_source_target_keywords.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_get_attribute_unknown_attribute_name.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_get_attribute_unknown_node_template_name.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_get_attribute_with_index.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_get_attribute_with_index_error.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_get_attribute_with_nested_params.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_get_implicit_attribute.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_get_property_source_target_keywords.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_get_property_with_host.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_invalid_function_signature.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_token.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_token_invalid.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_unknown_capability_property.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_unknown_input_in_interface.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/test_unknown_input_in_property.yaml create mode 100644 nfvparser/toscaparser/tests/data/functions/tosca_nested_property_names_indexes.yaml create mode 100644 nfvparser/toscaparser/tests/data/groups/definitions.yaml create mode 100644 nfvparser/toscaparser/tests/data/groups/tosca_group_template.yaml create mode 100644 nfvparser/toscaparser/tests/data/interfaces/test_custom_interface_in_template.yaml create mode 100644 nfvparser/toscaparser/tests/data/interfaces/test_custom_interface_invalid_operation.yaml create mode 100644 nfvparser/toscaparser/tests/data/load_balancer/tosca_load_balancer.yaml create mode 100644 nfvparser/toscaparser/tests/data/node_filter/test_node_filter.yaml create mode 100644 nfvparser/toscaparser/tests/data/policies/custom_definitions.yaml create mode 100644 nfvparser/toscaparser/tests/data/policies/tacker_defs.yaml create mode 100644 nfvparser/toscaparser/tests/data/policies/tacker_nfv_defs.yaml create mode 100644 nfvparser/toscaparser/tests/data/policies/test_tosca_nfv_multiple_policies.yaml create mode 100644 nfvparser/toscaparser/tests/data/policies/tosca_policy_template.yaml create mode 100644 nfvparser/toscaparser/tests/data/relationship/test_custom_relationship.yaml create mode 100644 nfvparser/toscaparser/tests/data/repositories/test_repositories_definition.yaml create mode 100644 nfvparser/toscaparser/tests/data/repositories/tosca_repositories_test_definition.yaml create mode 100644 nfvparser/toscaparser/tests/data/requirements/test_requirements.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_attributes_inheritance.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_available_rel_tpls.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_containers.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_credential_datatype.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_custom_caps_def.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_custom_relationships.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_endpoint_on_compute.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_instance_nested_imports.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_invalid_input_defaults.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_invalid_section_names.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_invalid_template_version.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_multiple_validation_errors.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_no_inputs_in_template.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_no_outputs_in_template.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_node_filter.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_normative_type_properties_override.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_repositories_definition.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_requirements.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_tosca_custom_rel_with_script.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_tosca_normative_type_by_shortname.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_tosca_top_level_error1.yaml create mode 100644 nfvparser/toscaparser/tests/data/test_tosca_top_level_error2.yaml create mode 100644 nfvparser/toscaparser/tests/data/topology_template/databasesubsystem.yaml create mode 100644 nfvparser/toscaparser/tests/data/topology_template/definitions.yaml create mode 100644 nfvparser/toscaparser/tests/data/topology_template/queuingsubsystem.yaml create mode 100644 nfvparser/toscaparser/tests/data/topology_template/system.yaml create mode 100644 nfvparser/toscaparser/tests/data/topology_template/transactionsubsystem.yaml create mode 100644 nfvparser/toscaparser/tests/data/topology_template/validate/queuingsubsystem_invalid_input.yaml create mode 100644 nfvparser/toscaparser/tests/data/topology_template/validate/system_invalid_input.yaml create mode 100644 nfvparser/toscaparser/tests/data/topology_template/validate/system_invalid_missing_output.yaml create mode 100644 nfvparser/toscaparser/tests/data/topology_template/validate/system_invalid_unknown_output.yaml create mode 100644 nfvparser/toscaparser/tests/data/topology_template/validate/test_example_app_substitution_mappings.yaml create mode 100644 nfvparser/toscaparser/tests/data/topology_template/validate/test_substitution_mappings_invalid_output.yaml create mode 100644 nfvparser/toscaparser/tests/data/topology_template/validate/test_substitution_mappings_valid_output.yaml create mode 100644 nfvparser/toscaparser/tests/data/topology_template/validate/transactionsubsystem_invalid_missing_output.yaml create mode 100644 nfvparser/toscaparser/tests/data/topology_template/validate/transactionsubsystem_invalid_unknown_output.yaml create mode 100644 nfvparser/toscaparser/tests/data/tosca_elk.yaml create mode 100644 nfvparser/toscaparser/tests/data/tosca_helloworld.yaml create mode 100644 nfvparser/toscaparser/tests/data/tosca_imports_validation.yaml create mode 100644 nfvparser/toscaparser/tests/data/tosca_load_balancer.yaml create mode 100644 nfvparser/toscaparser/tests/data/tosca_repositories_test_definition.yaml create mode 100644 nfvparser/toscaparser/tests/data/tosca_single_instance_wordpress.yaml create mode 100644 nfvparser/toscaparser/tests/data/tosca_single_instance_wordpress_with_local_abspath_import.yaml create mode 100644 nfvparser/toscaparser/tests/data/tosca_single_instance_wordpress_with_url_import.yaml create mode 100644 nfvparser/toscaparser/tests/data/tosca_test_get_operation_output.yaml create mode 100644 nfvparser/toscaparser/tests/spec_samples/v1.0/network/tosca_one_server_one_network.yaml create mode 100644 nfvparser/toscaparser/tests/spec_samples/v1.0/network/tosca_one_server_three_networks.yaml create mode 100644 nfvparser/toscaparser/tests/spec_samples/v1.0/network/tosca_server_on_existing_network.yaml create mode 100644 nfvparser/toscaparser/tests/spec_samples/v1.0/network/tosca_two_servers_one_network.yaml create mode 100644 nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment.yaml create mode 100644 nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment_notation1.yaml create mode 100644 nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment_notation2.yaml create mode 100644 nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_custom_relationship_type.yaml create mode 100644 nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_relationship_template.yaml create mode 100644 nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_multiple_blockstorage_with_attachment.yaml create mode 100644 nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_single_object_store.yaml create mode 100644 nfvparser/toscaparser/tests/spec_samples/v1.0/tosca_nodejs_mongodb_two_instances.yaml create mode 100644 nfvparser/toscaparser/tests/spec_samples/v1.0/tosca_single_server.yaml create mode 100644 nfvparser/toscaparser/tests/test_constraints.py create mode 100644 nfvparser/toscaparser/tests/test_custom_relationships.py create mode 100644 nfvparser/toscaparser/tests/test_datatypes.py create mode 100644 nfvparser/toscaparser/tests/test_exception.py create mode 100644 nfvparser/toscaparser/tests/test_functions.py create mode 100644 nfvparser/toscaparser/tests/test_prereq.py create mode 100644 nfvparser/toscaparser/tests/test_properties.py create mode 100644 nfvparser/toscaparser/tests/test_scalarunit.py create mode 100644 nfvparser/toscaparser/tests/test_shell.py create mode 100644 nfvparser/toscaparser/tests/test_topology_template.py create mode 100644 nfvparser/toscaparser/tests/test_toscadef.py create mode 100644 nfvparser/toscaparser/tests/test_toscatpl.py create mode 100644 nfvparser/toscaparser/tests/test_toscatplvalidation.py create mode 100644 nfvparser/toscaparser/tests/test_utils.py create mode 100644 nfvparser/toscaparser/tests/test_validate_tosca_version.py create mode 100644 nfvparser/toscaparser/topology_template.py create mode 100644 nfvparser/toscaparser/tosca_template.py create mode 100644 nfvparser/toscaparser/tpl_relationship_graph.py create mode 100644 nfvparser/toscaparser/triggers.py create mode 100644 nfvparser/toscaparser/unsupportedtype.py create mode 100644 nfvparser/toscaparser/utils/__init__.py create mode 100644 nfvparser/toscaparser/utils/gettextutils.py create mode 100644 nfvparser/toscaparser/utils/urlutils.py create mode 100644 nfvparser/toscaparser/utils/validateutils.py create mode 100644 nfvparser/toscaparser/utils/yamlparser.py create mode 100644 nfvparser/tox.ini diff --git a/nfvparser/.coveragerc b/nfvparser/.coveragerc new file mode 100644 index 0000000..3309d46 --- /dev/null +++ b/nfvparser/.coveragerc @@ -0,0 +1,7 @@ +[run] +branch = True +source = toscaparser +omit = toscaparser/openstack/* + +[report] +ignore_errors = True diff --git a/nfvparser/.gitignore b/nfvparser/.gitignore new file mode 100644 index 0000000..c172104 --- /dev/null +++ b/nfvparser/.gitignore @@ -0,0 +1,56 @@ +*.py[cod] + +# C extensions +*.so + +# Packages +*.egg +*.egg-info +dist +build +eggs +parts +bin +var +sdist +develop-eggs +.installed.cfg +lib +lib64 + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox +nosetests.xml +.testrepository + +# Translations +*.mo + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + +# Complexity +output/*.html +output/*/index.html + +# Sphinx +doc/build + +# pbr generates these +AUTHORS +ChangeLog + +# Editors +*~ +.*.swp +.idea +*.iml + +# OSX +.DS_Store \ No newline at end of file diff --git a/nfvparser/.gitreview b/nfvparser/.gitreview new file mode 100644 index 0000000..9105f23 --- /dev/null +++ b/nfvparser/.gitreview @@ -0,0 +1,4 @@ +[gerrit] +host=review.openstack.org +port=29418 +project=openstack/tosca-parser.git diff --git a/nfvparser/.mailmap b/nfvparser/.mailmap new file mode 100644 index 0000000..cc92f17 --- /dev/null +++ b/nfvparser/.mailmap @@ -0,0 +1,3 @@ +# Format is: +# +# \ No newline at end of file diff --git a/nfvparser/.testr.conf b/nfvparser/.testr.conf new file mode 100644 index 0000000..fb62267 --- /dev/null +++ b/nfvparser/.testr.conf @@ -0,0 +1,7 @@ +[DEFAULT] +test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ + OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \ + OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \ + ${PYTHON:-python} -m subunit.run discover -t ./ . $LISTOPT $IDOPTION +test_id_option=--load-list $IDFILE +test_list_option=--list \ No newline at end of file diff --git a/nfvparser/LICENSE b/nfvparser/LICENSE new file mode 100644 index 0000000..67db858 --- /dev/null +++ b/nfvparser/LICENSE @@ -0,0 +1,175 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. diff --git a/nfvparser/MANIFEST.in b/nfvparser/MANIFEST.in new file mode 100644 index 0000000..1fc29b3 --- /dev/null +++ b/nfvparser/MANIFEST.in @@ -0,0 +1,14 @@ +include AUTHORS +include ChangeLog +global-include *.py +global-include *.yaml +global-include *.sh +global-include *.txt +global-include *.csar +global-include *.zip +global-include *.meta +global-include *.conf +exclude .gitignore +exclude .gitreview + +global-exclude *.pyc diff --git a/nfvparser/README.md b/nfvparser/README.md new file mode 100644 index 0000000..4883bd1 --- /dev/null +++ b/nfvparser/README.md @@ -0,0 +1,55 @@ +======================== +Team and repository tags +======================== + +.. image:: http://governance.openstack.org/badges/tosca-parser.svg + :target: http://governance.openstack.org/reference/tags/index.html + +.. Change things from this point on + +=============== +TOSCA Parser +=============== + +Overview +-------- + +The TOSCA Parser is OPNFV project based on the OpenStack project and licensed under Apache 2. It is +developed to parse nfv TOSCA simple Profile and TOSCA Simple Profile in YAML. It reads the TOSCA +templates and creates an in-memory object or json file(for future) about graph of TOSCA nodes and +their relationship. + +Architecture +------------ + +The TOSCA Parser takes TOSCA YAML template or TOSCA Cloud Service Archive (CSAR) +file as an input, with optional input of dictionary of needed parameters with their +values, and produces in-memory objects of different TOSCA elements with their +relationship to each other. It also creates a graph of TOSCA node templates and their +relationship. + +The ToscaTemplate class located in the toscaparser/tosca_template.py is an entry +class of the parser and various functionality of parser can be used by initiating +this class. In order to see an example usage of TOSCA Parser from a separate tool, +refer to the OpenStack heat-translator class TranslateTemplate located in the +translator/osc/v1/translate.py module. The toscaparser/shell.py module of tosca-parser +also provides a good reference on how to invoke TOSCA Parser from Command Line Interface. + +The toscaparser/elements sub-directory contains various modules to handle +various TOSCA type elements like node type, relationship type etc. The +entity_type.py module is a parent of all type elements. The toscaparser +directory contains various python module to handle service template including +topology template, node templates, relationship templates etc. The +entity_template.py is a parent of all template elements. + + +How To Use +---------- +Please refer to `doc/source/usage.rst ` + +Project Info +------------ + +* License: Apache License, Version 2.0 +* Source: http://git.openstack.org/cgit/openstack/tosca-parser/ + diff --git a/nfvparser/babel.cfg b/nfvparser/babel.cfg new file mode 100644 index 0000000..efceab8 --- /dev/null +++ b/nfvparser/babel.cfg @@ -0,0 +1 @@ +[python: **.py] diff --git a/nfvparser/openstack-common.conf b/nfvparser/openstack-common.conf new file mode 100644 index 0000000..178c8c4 --- /dev/null +++ b/nfvparser/openstack-common.conf @@ -0,0 +1,6 @@ +[DEFAULT] + +# The list of modules to copy from oslo-incubator.git + +# The base module to hold the copy of openstack.common +base=toscaparser \ No newline at end of file diff --git a/nfvparser/requirements.txt b/nfvparser/requirements.txt new file mode 100644 index 0000000..45a19f0 --- /dev/null +++ b/nfvparser/requirements.txt @@ -0,0 +1,10 @@ +# The order of packages is significant, because pip processes them in the order +# of appearance. Changing the order has an impact on the overall integration +# process, which may cause wedges in the gate later. +pbr>=1.8 # Apache-2.0 +Babel>=2.3.4 # BSD +cliff>=2.3.0 # Apache-2.0 +PyYAML>=3.10.0 # MIT +python-dateutil>=2.4.2 # BSD +six>=1.9.0 # MIT +requests!=2.12.2,!=2.13.0,>=2.10.0 # Apache-2.0 diff --git a/nfvparser/setup.cfg b/nfvparser/setup.cfg new file mode 100644 index 0000000..2396c1f --- /dev/null +++ b/nfvparser/setup.cfg @@ -0,0 +1,43 @@ +[metadata] +name = tosca-parser +url = https://launchpad.net/tosca-parser +summary = Parser for nfv TOSCA Simple Profile and TOSCA Simple Profile in YAML. +description-file = + README.md +author = OpenStack +author-email = openstack-dev@lists.openstack.org +home-page = http://docs.openstack.org/developer/tosca-parser/ +classifier = + Environment :: OpenStack + Intended Audience :: Information Technology + Intended Audience :: System Administrators + License :: OSI Approved :: Apache Software License + Operating System :: POSIX :: Linux + Programming Language :: Python + Programming Language :: Python :: 2 + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.4 + Programming Language :: Python :: 3.5 + +[files] +packages = + toscaparser + +[entry_points] +console_scripts = + tosca-parser = toscaparser.shell:main + +[compile_catalog] +directory = toscaparser/locale +domain = toscaparser + +[update_catalog] +domain = toscaparser +output_dir = toscaparser/locale +input_file = toscaparser/locale/toscaparser.pot + +[extract_messages] +keywords = _ gettext ngettext l_ lazy_gettext +mapping_file = babel.cfg +output_file = toscaparser/locale/toscaparser.pot diff --git a/nfvparser/setup.py b/nfvparser/setup.py new file mode 100644 index 0000000..782bb21 --- /dev/null +++ b/nfvparser/setup.py @@ -0,0 +1,29 @@ +# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file 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. + +# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT +import setuptools + +# In python < 2.7.4, a lazy loading of package `pbr` will break +# setuptools if some other modules registered functions in `atexit`. +# solution from: http://bugs.python.org/issue15881#msg170215 +try: + import multiprocessing # noqa +except ImportError: + pass + +setuptools.setup( + setup_requires=['pbr>=1.8'], + pbr=True) diff --git a/nfvparser/src/main/python/.coveragerc b/nfvparser/src/main/python/.coveragerc deleted file mode 100644 index 3309d46..0000000 --- a/nfvparser/src/main/python/.coveragerc +++ /dev/null @@ -1,7 +0,0 @@ -[run] -branch = True -source = toscaparser -omit = toscaparser/openstack/* - -[report] -ignore_errors = True diff --git a/nfvparser/src/main/python/.gitignore b/nfvparser/src/main/python/.gitignore deleted file mode 100644 index c172104..0000000 --- a/nfvparser/src/main/python/.gitignore +++ /dev/null @@ -1,56 +0,0 @@ -*.py[cod] - -# C extensions -*.so - -# Packages -*.egg -*.egg-info -dist -build -eggs -parts -bin -var -sdist -develop-eggs -.installed.cfg -lib -lib64 - -# Installer logs -pip-log.txt - -# Unit test / coverage reports -.coverage -.tox -nosetests.xml -.testrepository - -# Translations -*.mo - -# Mr Developer -.mr.developer.cfg -.project -.pydevproject - -# Complexity -output/*.html -output/*/index.html - -# Sphinx -doc/build - -# pbr generates these -AUTHORS -ChangeLog - -# Editors -*~ -.*.swp -.idea -*.iml - -# OSX -.DS_Store \ No newline at end of file diff --git a/nfvparser/src/main/python/.gitreview b/nfvparser/src/main/python/.gitreview deleted file mode 100644 index 9105f23..0000000 --- a/nfvparser/src/main/python/.gitreview +++ /dev/null @@ -1,4 +0,0 @@ -[gerrit] -host=review.openstack.org -port=29418 -project=openstack/tosca-parser.git diff --git a/nfvparser/src/main/python/.mailmap b/nfvparser/src/main/python/.mailmap deleted file mode 100644 index cc92f17..0000000 --- a/nfvparser/src/main/python/.mailmap +++ /dev/null @@ -1,3 +0,0 @@ -# Format is: -# -# \ No newline at end of file diff --git a/nfvparser/src/main/python/.testr.conf b/nfvparser/src/main/python/.testr.conf deleted file mode 100644 index fb62267..0000000 --- a/nfvparser/src/main/python/.testr.conf +++ /dev/null @@ -1,7 +0,0 @@ -[DEFAULT] -test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ - OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \ - OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \ - ${PYTHON:-python} -m subunit.run discover -t ./ . $LISTOPT $IDOPTION -test_id_option=--load-list $IDFILE -test_list_option=--list \ No newline at end of file diff --git a/nfvparser/src/main/python/LICENSE b/nfvparser/src/main/python/LICENSE deleted file mode 100644 index 67db858..0000000 --- a/nfvparser/src/main/python/LICENSE +++ /dev/null @@ -1,175 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. diff --git a/nfvparser/src/main/python/MANIFEST.in b/nfvparser/src/main/python/MANIFEST.in deleted file mode 100644 index 1fc29b3..0000000 --- a/nfvparser/src/main/python/MANIFEST.in +++ /dev/null @@ -1,14 +0,0 @@ -include AUTHORS -include ChangeLog -global-include *.py -global-include *.yaml -global-include *.sh -global-include *.txt -global-include *.csar -global-include *.zip -global-include *.meta -global-include *.conf -exclude .gitignore -exclude .gitreview - -global-exclude *.pyc diff --git a/nfvparser/src/main/python/README.md b/nfvparser/src/main/python/README.md deleted file mode 100644 index 4883bd1..0000000 --- a/nfvparser/src/main/python/README.md +++ /dev/null @@ -1,55 +0,0 @@ -======================== -Team and repository tags -======================== - -.. image:: http://governance.openstack.org/badges/tosca-parser.svg - :target: http://governance.openstack.org/reference/tags/index.html - -.. Change things from this point on - -=============== -TOSCA Parser -=============== - -Overview --------- - -The TOSCA Parser is OPNFV project based on the OpenStack project and licensed under Apache 2. It is -developed to parse nfv TOSCA simple Profile and TOSCA Simple Profile in YAML. It reads the TOSCA -templates and creates an in-memory object or json file(for future) about graph of TOSCA nodes and -their relationship. - -Architecture ------------- - -The TOSCA Parser takes TOSCA YAML template or TOSCA Cloud Service Archive (CSAR) -file as an input, with optional input of dictionary of needed parameters with their -values, and produces in-memory objects of different TOSCA elements with their -relationship to each other. It also creates a graph of TOSCA node templates and their -relationship. - -The ToscaTemplate class located in the toscaparser/tosca_template.py is an entry -class of the parser and various functionality of parser can be used by initiating -this class. In order to see an example usage of TOSCA Parser from a separate tool, -refer to the OpenStack heat-translator class TranslateTemplate located in the -translator/osc/v1/translate.py module. The toscaparser/shell.py module of tosca-parser -also provides a good reference on how to invoke TOSCA Parser from Command Line Interface. - -The toscaparser/elements sub-directory contains various modules to handle -various TOSCA type elements like node type, relationship type etc. The -entity_type.py module is a parent of all type elements. The toscaparser -directory contains various python module to handle service template including -topology template, node templates, relationship templates etc. The -entity_template.py is a parent of all template elements. - - -How To Use ----------- -Please refer to `doc/source/usage.rst ` - -Project Info ------------- - -* License: Apache License, Version 2.0 -* Source: http://git.openstack.org/cgit/openstack/tosca-parser/ - diff --git a/nfvparser/src/main/python/babel.cfg b/nfvparser/src/main/python/babel.cfg deleted file mode 100644 index efceab8..0000000 --- a/nfvparser/src/main/python/babel.cfg +++ /dev/null @@ -1 +0,0 @@ -[python: **.py] diff --git a/nfvparser/src/main/python/openstack-common.conf b/nfvparser/src/main/python/openstack-common.conf deleted file mode 100644 index 178c8c4..0000000 --- a/nfvparser/src/main/python/openstack-common.conf +++ /dev/null @@ -1,6 +0,0 @@ -[DEFAULT] - -# The list of modules to copy from oslo-incubator.git - -# The base module to hold the copy of openstack.common -base=toscaparser \ No newline at end of file diff --git a/nfvparser/src/main/python/requirements.txt b/nfvparser/src/main/python/requirements.txt deleted file mode 100644 index 45a19f0..0000000 --- a/nfvparser/src/main/python/requirements.txt +++ /dev/null @@ -1,10 +0,0 @@ -# The order of packages is significant, because pip processes them in the order -# of appearance. Changing the order has an impact on the overall integration -# process, which may cause wedges in the gate later. -pbr>=1.8 # Apache-2.0 -Babel>=2.3.4 # BSD -cliff>=2.3.0 # Apache-2.0 -PyYAML>=3.10.0 # MIT -python-dateutil>=2.4.2 # BSD -six>=1.9.0 # MIT -requests!=2.12.2,!=2.13.0,>=2.10.0 # Apache-2.0 diff --git a/nfvparser/src/main/python/setup.cfg b/nfvparser/src/main/python/setup.cfg deleted file mode 100644 index 2396c1f..0000000 --- a/nfvparser/src/main/python/setup.cfg +++ /dev/null @@ -1,43 +0,0 @@ -[metadata] -name = tosca-parser -url = https://launchpad.net/tosca-parser -summary = Parser for nfv TOSCA Simple Profile and TOSCA Simple Profile in YAML. -description-file = - README.md -author = OpenStack -author-email = openstack-dev@lists.openstack.org -home-page = http://docs.openstack.org/developer/tosca-parser/ -classifier = - Environment :: OpenStack - Intended Audience :: Information Technology - Intended Audience :: System Administrators - License :: OSI Approved :: Apache Software License - Operating System :: POSIX :: Linux - Programming Language :: Python - Programming Language :: Python :: 2 - Programming Language :: Python :: 2.7 - Programming Language :: Python :: 3 - Programming Language :: Python :: 3.4 - Programming Language :: Python :: 3.5 - -[files] -packages = - toscaparser - -[entry_points] -console_scripts = - tosca-parser = toscaparser.shell:main - -[compile_catalog] -directory = toscaparser/locale -domain = toscaparser - -[update_catalog] -domain = toscaparser -output_dir = toscaparser/locale -input_file = toscaparser/locale/toscaparser.pot - -[extract_messages] -keywords = _ gettext ngettext l_ lazy_gettext -mapping_file = babel.cfg -output_file = toscaparser/locale/toscaparser.pot diff --git a/nfvparser/src/main/python/setup.py b/nfvparser/src/main/python/setup.py deleted file mode 100644 index 782bb21..0000000 --- a/nfvparser/src/main/python/setup.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file 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. - -# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT -import setuptools - -# In python < 2.7.4, a lazy loading of package `pbr` will break -# setuptools if some other modules registered functions in `atexit`. -# solution from: http://bugs.python.org/issue15881#msg170215 -try: - import multiprocessing # noqa -except ImportError: - pass - -setuptools.setup( - setup_requires=['pbr>=1.8'], - pbr=True) diff --git a/nfvparser/src/main/python/test-requirements.txt b/nfvparser/src/main/python/test-requirements.txt deleted file mode 100644 index d4b59c3..0000000 --- a/nfvparser/src/main/python/test-requirements.txt +++ /dev/null @@ -1,13 +0,0 @@ -# The order of packages is significant, because pip processes them in the order -# of appearance. Changing the order has an impact on the overall integration -# process, which may cause wedges in the gate later. -hacking<0.11,>=0.10.0 -coverage>=4.0 # Apache-2.0 -fixtures>=3.0.0 # Apache-2.0/BSD -oslotest>=1.10.0 # Apache-2.0 -oslosphinx>=4.7.0 # Apache-2.0 -python-subunit>=0.0.18 # Apache-2.0/BSD -sphinx>=1.5.1 # BSD -testrepository>=0.0.18 # Apache-2.0/BSD -testscenarios>=0.4 # Apache-2.0/BSD -testtools>=1.4.0 # MIT diff --git a/nfvparser/src/main/python/tools/tox_install.sh b/nfvparser/src/main/python/tools/tox_install.sh deleted file mode 100644 index e61b63a..0000000 --- a/nfvparser/src/main/python/tools/tox_install.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash - -# Client constraint file contains this client version pin that is in conflict -# with installing the client from source. We should remove the version pin in -# the constraints file before applying it for from-source installation. - -CONSTRAINTS_FILE="$1" -shift 1 - -set -e - -# NOTE(tonyb): Place this in the tox enviroment's log dir so it will get -# published to logs.openstack.org for easy debugging. -localfile="$VIRTUAL_ENV/log/upper-constraints.txt" - -if [[ "$CONSTRAINTS_FILE" != http* ]]; then - CONSTRAINTS_FILE="file://$CONSTRAINTS_FILE" -fi -# NOTE(tonyb): need to add curl to bindep.txt if the project supports bindep -curl "$CONSTRAINTS_FILE" --insecure --progress-bar --output "$localfile" - -pip install -c"$localfile" openstack-requirements - -# This is the main purpose of the script: Allow local installation of -# the current repo. It is listed in constraints file and thus any -# install will be constrained and we need to unconstrain it. -edit-constraints "$localfile" -- "$CLIENT_NAME" - -pip install -c"$localfile" -U "$@" -exit $? diff --git a/nfvparser/src/main/python/tosca_parser.py b/nfvparser/src/main/python/tosca_parser.py deleted file mode 100644 index 0d2de75..0000000 --- a/nfvparser/src/main/python/tosca_parser.py +++ /dev/null @@ -1,32 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - - -from toscaparser import shell as parser_shell - -""" -Test utility to show how TOSCA Parser can be used programmatically - -It can be used as, -#python tosca_parser.py --template-file= -#python tosca_parser.py --template-file= -#python tosca_parser.py --template-file= - -e.g. -#python tosca_parser.py ---template-file=toscaparser/tests/data/tosca_helloworld.yaml -#python tosca_parser.py ---template-file=toscaparser/tests/data/CSAR/csar_hello_world.zip -""" - -if __name__ == '__main__': - parser_shell.main() diff --git a/nfvparser/src/main/python/toscaparser/__init__.py b/nfvparser/src/main/python/toscaparser/__init__.py deleted file mode 100644 index d9745ed..0000000 --- a/nfvparser/src/main/python/toscaparser/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import pbr.version - - -__version__ = pbr.version.VersionInfo( - 'tosca-parser').version_string() diff --git a/nfvparser/src/main/python/toscaparser/capabilities.py b/nfvparser/src/main/python/toscaparser/capabilities.py deleted file mode 100644 index c23ef72..0000000 --- a/nfvparser/src/main/python/toscaparser/capabilities.py +++ /dev/null @@ -1,45 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from toscaparser.properties import Property - - -class Capability(object): - '''TOSCA built-in capabilities type.''' - - def __init__(self, name, properties, definition): - self.name = name - self._properties = properties - self.definition = definition - - def get_properties_objects(self): - '''Return a list of property objects.''' - properties = [] - props = self._properties - if props: - for name, value in props.items(): - props_def = self.definition.get_properties_def() - if props_def and name in props_def: - properties.append(Property(name, value, - props_def[name].schema)) - return properties - - def get_properties(self): - '''Return a dictionary of property name-object pairs.''' - return {prop.name: prop - for prop in self.get_properties_objects()} - - def get_property_value(self, name): - '''Return the value of a given property name.''' - props = self.get_properties() - if props and name in props: - return props[name].value diff --git a/nfvparser/src/main/python/toscaparser/common/__init__.py b/nfvparser/src/main/python/toscaparser/common/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/nfvparser/src/main/python/toscaparser/common/exception.py b/nfvparser/src/main/python/toscaparser/common/exception.py deleted file mode 100644 index 13ccabd..0000000 --- a/nfvparser/src/main/python/toscaparser/common/exception.py +++ /dev/null @@ -1,246 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -''' -TOSCA exception classes -''' -import logging -import sys -import traceback - -from toscaparser.utils.gettextutils import _ - - -log = logging.getLogger(__name__) - - -class TOSCAException(Exception): - '''Base exception class for TOSCA - - To correctly use this class, inherit from it and define - a 'msg_fmt' property. - - ''' - - _FATAL_EXCEPTION_FORMAT_ERRORS = False - - message = _('An unknown exception occurred.') - - def __init__(self, **kwargs): - try: - self.message = self.msg_fmt % kwargs - except KeyError: - exc_info = sys.exc_info() - log.exception(_('Exception in string format operation: %s') - % exc_info[1]) - - if TOSCAException._FATAL_EXCEPTION_FORMAT_ERRORS: - raise exc_info[0] - - def __str__(self): - return self.message - - @staticmethod - def generate_inv_schema_property_error(self, attr, value, valid_values): - msg = (_('Schema definition of "%(propname)s" has ' - '"%(attr)s" attribute with invalid value ' - '"%(value1)s". The value must be one of ' - '"%(value2)s".') % {"propname": self.name, - "attr": attr, - "value1": value, - "value2": valid_values}) - ExceptionCollector.appendException( - InvalidSchemaError(message=msg)) - - @staticmethod - def set_fatal_format_exception(flag): - if isinstance(flag, bool): - TOSCAException._FATAL_EXCEPTION_FORMAT_ERRORS = flag - - -class UnsupportedTypeError(TOSCAException): - msg_fmt = _('Type "%(what)s" is valid TOSCA type' - ' but not supported at this time.') - - -class MissingRequiredFieldError(TOSCAException): - msg_fmt = _('%(what)s is missing required field "%(required)s".') - - -class UnknownFieldError(TOSCAException): - msg_fmt = _('%(what)s contains unknown field "%(field)s". Refer to the ' - 'definition to verify valid values.') - - -class TypeMismatchError(TOSCAException): - msg_fmt = _('%(what)s must be of type "%(type)s".') - - -class InvalidNodeTypeError(TOSCAException): - msg_fmt = _('Node type "%(what)s" is not a valid type.') - - -class InvalidTypeError(TOSCAException): - msg_fmt = _('Type "%(what)s" is not a valid type.') - - -class InvalidTypeAdditionalRequirementsError(TOSCAException): - msg_fmt = _('Additional requirements for type "%(type)s" not met.') - - -class RangeValueError(TOSCAException): - msg_fmt = _('The value "%(pvalue)s" of property "%(pname)s" is out of ' - 'range "(min:%(vmin)s, max:%(vmax)s)".') - - -class InvalidSchemaError(TOSCAException): - msg_fmt = _('%(message)s') - - -class ValidationError(TOSCAException): - msg_fmt = _('%(message)s') - - -class UnknownInputError(TOSCAException): - msg_fmt = _('Unknown input "%(input_name)s".') - - -class UnknownOutputError(TOSCAException): - msg_fmt = _('Unknown output "%(output_name)s" in %(where)s.') - - -class MissingRequiredInputError(TOSCAException): - msg_fmt = _('%(what)s is missing required input definition ' - 'of input "%(input_name)s".') - - -class MissingRequiredParameterError(TOSCAException): - msg_fmt = _('%(what)s is missing required parameter for input ' - '"%(input_name)s".') - - -class MissingDefaultValueError(TOSCAException): - msg_fmt = _('%(what)s is missing required default value ' - 'of input "%(input_name)s".') - - -class MissingRequiredOutputError(TOSCAException): - msg_fmt = _('%(what)s is missing required output definition ' - 'of output "%(output_name)s".') - - -class InvalidPropertyValueError(TOSCAException): - msg_fmt = _('Value of property "%(what)s" is invalid.') - - -class InvalidTemplateVersion(TOSCAException): - msg_fmt = _('The template version "%(what)s" is invalid. ' - 'Valid versions are "%(valid_versions)s".') - - -class InvalidTOSCAVersionPropertyException(TOSCAException): - msg_fmt = _('Value of TOSCA version property "%(what)s" is invalid.') - - -class URLException(TOSCAException): - msg_fmt = _('%(what)s') - - -class ToscaExtImportError(TOSCAException): - msg_fmt = _('Unable to import extension "%(ext_name)s". ' - 'Check to see that it exists and has no ' - 'language definition errors.') - - -class ToscaExtAttributeError(TOSCAException): - msg_fmt = _('Missing attribute in extension "%(ext_name)s". ' - 'Check to see that it has required attributes ' - '"%(attrs)s" defined.') - - -class InvalidGroupTargetException(TOSCAException): - msg_fmt = _('"%(message)s"') - - -class ExceptionCollector(object): - - exceptions = [] - collecting = False - - @staticmethod - def clear(): - del ExceptionCollector.exceptions[:] - - @staticmethod - def start(): - ExceptionCollector.clear() - ExceptionCollector.collecting = True - - @staticmethod - def stop(): - ExceptionCollector.collecting = False - - @staticmethod - def contains(exception): - for ex in ExceptionCollector.exceptions: - if str(ex) == str(exception): - return True - return False - - @staticmethod - def appendException(exception): - if ExceptionCollector.collecting: - if not ExceptionCollector.contains(exception): - exception.trace = traceback.extract_stack()[:-1] - ExceptionCollector.exceptions.append(exception) - else: - raise exception - - @staticmethod - def exceptionsCaught(): - return len(ExceptionCollector.exceptions) > 0 - - @staticmethod - def getTraceString(traceList): - traceString = '' - for entry in traceList: - f, l, m, c = entry[0], entry[1], entry[2], entry[3] - traceString += (_('\t\tFile %(file)s, line %(line)s, in ' - '%(method)s\n\t\t\t%(call)s\n') - % {'file': f, 'line': l, 'method': m, 'call': c}) - return traceString - - @staticmethod - def getExceptionReportEntry(exception, full=True): - entry = exception.__class__.__name__ + ': ' + str(exception) - if full: - entry += '\n' + ExceptionCollector.getTraceString(exception.trace) - return entry - - @staticmethod - def getExceptions(): - return ExceptionCollector.exceptions - - @staticmethod - def getExceptionsReport(full=True): - report = [] - for exception in ExceptionCollector.exceptions: - report.append( - ExceptionCollector.getExceptionReportEntry(exception, full)) - return report - - @staticmethod - def assertExceptionMessage(exception, message): - err_msg = exception.__name__ + ': ' + message - report = ExceptionCollector.getExceptionsReport(False) - assert err_msg in report, (_('Could not find "%(msg)s" in "%(rep)s".') - % {'rep': report.__str__(), 'msg': err_msg}) diff --git a/nfvparser/src/main/python/toscaparser/dataentity.py b/nfvparser/src/main/python/toscaparser/dataentity.py deleted file mode 100644 index 507c899..0000000 --- a/nfvparser/src/main/python/toscaparser/dataentity.py +++ /dev/null @@ -1,182 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import MissingRequiredFieldError -from toscaparser.common.exception import TypeMismatchError -from toscaparser.common.exception import UnknownFieldError -from toscaparser.elements.constraints import Schema -from toscaparser.elements.datatype import DataType -from toscaparser.elements.portspectype import PortSpec -from toscaparser.elements.scalarunit import ScalarUnit_Frequency -from toscaparser.elements.scalarunit import ScalarUnit_Size -from toscaparser.elements.scalarunit import ScalarUnit_Time -from toscaparser.utils.gettextutils import _ -from toscaparser.utils import validateutils - - -class DataEntity(object): - '''A complex data value entity.''' - - def __init__(self, datatypename, value_dict, custom_def=None, - prop_name=None): - self.custom_def = custom_def - self.datatype = DataType(datatypename, custom_def) - self.schema = self.datatype.get_all_properties() - self.value = value_dict - self.property_name = prop_name - - def validate(self): - '''Validate the value by the definition of the datatype.''' - - # A datatype can not have both 'type' and 'properties' definitions. - # If the datatype has 'type' definition - if self.datatype.value_type: - self.value = DataEntity.validate_datatype(self.datatype.value_type, - self.value, - None, - self.custom_def) - schema = Schema(self.property_name, self.datatype.defs) - for constraint in schema.constraints: - constraint.validate(self.value) - # If the datatype has 'properties' definition - else: - if not isinstance(self.value, dict): - ExceptionCollector.appendException( - TypeMismatchError(what=self.value, - type=self.datatype.type)) - allowed_props = [] - required_props = [] - default_props = {} - if self.schema: - allowed_props = self.schema.keys() - for name, prop_def in self.schema.items(): - if prop_def.required: - required_props.append(name) - if prop_def.default: - default_props[name] = prop_def.default - - # check allowed field - for value_key in list(self.value.keys()): - if value_key not in allowed_props: - ExceptionCollector.appendException( - UnknownFieldError(what=(_('Data value of type "%s"') - % self.datatype.type), - field=value_key)) - - # check default field - for def_key, def_value in list(default_props.items()): - if def_key not in list(self.value.keys()): - self.value[def_key] = def_value - - # check missing field - missingprop = [] - for req_key in required_props: - if req_key not in list(self.value.keys()): - missingprop.append(req_key) - if missingprop: - ExceptionCollector.appendException( - MissingRequiredFieldError( - what=(_('Data value of type "%s"') - % self.datatype.type), required=missingprop)) - - # check every field - for name, value in list(self.value.items()): - schema_name = self._find_schema(name) - if not schema_name: - continue - prop_schema = Schema(name, schema_name) - # check if field value meets type defined - DataEntity.validate_datatype(prop_schema.type, value, - prop_schema.entry_schema, - self.custom_def) - # check if field value meets constraints defined - if prop_schema.constraints: - for constraint in prop_schema.constraints: - if isinstance(value, list): - for val in value: - constraint.validate(val) - else: - constraint.validate(value) - - return self.value - - def _find_schema(self, name): - if self.schema and name in self.schema.keys(): - return self.schema[name].schema - - @staticmethod - def validate_datatype(type, value, entry_schema=None, custom_def=None, - prop_name=None): - '''Validate value with given type. - - If type is list or map, validate its entry by entry_schema(if defined) - If type is a user-defined complex datatype, custom_def is required. - ''' - from toscaparser.functions import is_function - if is_function(value): - return value - if type == Schema.STRING: - return validateutils.validate_string(value) - elif type == Schema.INTEGER: - return validateutils.validate_integer(value) - elif type == Schema.FLOAT: - return validateutils.validate_float(value) - elif type == Schema.NUMBER: - return validateutils.validate_numeric(value) - elif type == Schema.BOOLEAN: - return validateutils.validate_boolean(value) - elif type == Schema.RANGE: - return validateutils.validate_range(value) - elif type == Schema.TIMESTAMP: - validateutils.validate_timestamp(value) - return value - elif type == Schema.LIST: - validateutils.validate_list(value) - if entry_schema: - DataEntity.validate_entry(value, entry_schema, custom_def) - return value - elif type == Schema.SCALAR_UNIT_SIZE: - return ScalarUnit_Size(value).validate_scalar_unit() - elif type == Schema.SCALAR_UNIT_FREQUENCY: - return ScalarUnit_Frequency(value).validate_scalar_unit() - elif type == Schema.SCALAR_UNIT_TIME: - return ScalarUnit_Time(value).validate_scalar_unit() - elif type == Schema.VERSION: - return validateutils.TOSCAVersionProperty(value).get_version() - elif type == Schema.MAP: - validateutils.validate_map(value) - if entry_schema: - DataEntity.validate_entry(value, entry_schema, custom_def) - return value - elif type == Schema.PORTSPEC: - # TODO(TBD) bug 1567063, validate source & target as PortDef type - # as complex types not just as integers - PortSpec.validate_additional_req(value, prop_name, custom_def) - else: - data = DataEntity(type, value, custom_def) - return data.validate() - - @staticmethod - def validate_entry(value, entry_schema, custom_def=None): - '''Validate entries for map and list.''' - schema = Schema(None, entry_schema) - valuelist = value - if isinstance(value, dict): - valuelist = list(value.values()) - for v in valuelist: - DataEntity.validate_datatype(schema.type, v, schema.entry_schema, - custom_def) - if schema.constraints: - for constraint in schema.constraints: - constraint.validate(v) - return value diff --git a/nfvparser/src/main/python/toscaparser/elements/TOSCA_definition_1_0.yaml b/nfvparser/src/main/python/toscaparser/elements/TOSCA_definition_1_0.yaml deleted file mode 100644 index 9f3369e..0000000 --- a/nfvparser/src/main/python/toscaparser/elements/TOSCA_definition_1_0.yaml +++ /dev/null @@ -1,952 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -########################################################################## -# The content of this file reflects TOSCA Simple Profile in YAML version -# 1.0.0. It describes the definition for TOSCA types including Node Type, -# Relationship Type, Capability Type and Interfaces. -########################################################################## -tosca_definitions_version: tosca_simple_yaml_1_0 - -########################################################################## -# Node Type. -# A Node Type is a reusable entity that defines the type of one or more -# Node Templates. -########################################################################## -node_types: - tosca.nodes.Root: - description: > - The TOSCA root node all other TOSCA base node types derive from. - attributes: - tosca_id: - type: string - tosca_name: - type: string - state: - type: string - capabilities: - feature: - type: tosca.capabilities.Node - requirements: - - dependency: - capability: tosca.capabilities.Node - node: tosca.nodes.Root - relationship: tosca.relationships.DependsOn - occurrences: [ 0, UNBOUNDED ] - interfaces: - Standard: - type: tosca.interfaces.node.lifecycle.Standard - - tosca.nodes.Compute: - derived_from: tosca.nodes.Root - attributes: - private_address: - type: string - public_address: - type: string - networks: - type: map - entry_schema: - type: tosca.datatypes.network.NetworkInfo - ports: - type: map - entry_schema: - type: tosca.datatypes.network.PortInfo - capabilities: - host: - type: tosca.capabilities.Container - binding: - type: tosca.capabilities.network.Bindable - os: - type: tosca.capabilities.OperatingSystem - scalable: - type: tosca.capabilities.Scalable - endpoint: - type: tosca.capabilities.Endpoint.Admin - requirements: - - local_storage: - capability: tosca.capabilities.Attachment - node: tosca.nodes.BlockStorage - relationship: tosca.relationships.AttachesTo - occurrences: [0, UNBOUNDED] - - tosca.nodes.SoftwareComponent: - derived_from: tosca.nodes.Root - properties: - # domain-specific software component version - component_version: - type: version - required: false - description: > - Software component version. - admin_credential: - type: tosca.datatypes.Credential - required: false - requirements: - - host: - capability: tosca.capabilities.Container - node: tosca.nodes.Compute - relationship: tosca.relationships.HostedOn - - tosca.nodes.DBMS: - derived_from: tosca.nodes.SoftwareComponent - properties: - port: - required: false - type: integer - description: > - The port the DBMS service will listen to for data and requests. - root_password: - required: false - type: string - description: > - The root password for the DBMS service. - capabilities: - host: - type: tosca.capabilities.Container - valid_source_types: [tosca.nodes.Database] - - tosca.nodes.Database: - derived_from: tosca.nodes.Root - properties: - user: - required: false - type: string - description: > - User account name for DB administration - port: - required: false - type: integer - description: > - The port the database service will use to listen for incoming data and - requests. - name: - required: false - type: string - description: > - The name of the database. - password: - required: false - type: string - description: > - The password for the DB user account - requirements: - - host: - capability: tosca.capabilities.Container - node: tosca.nodes.DBMS - relationship: tosca.relationships.HostedOn - capabilities: - database_endpoint: - type: tosca.capabilities.Endpoint.Database - - tosca.nodes.WebServer: - derived_from: tosca.nodes.SoftwareComponent - capabilities: - data_endpoint: - type: tosca.capabilities.Endpoint - admin_endpoint: - type: tosca.capabilities.Endpoint.Admin - host: - type: tosca.capabilities.Container - valid_source_types: [tosca.nodes.WebApplication] - - tosca.nodes.WebApplication: - derived_from: tosca.nodes.Root - properties: - context_root: - type: string - required: false - requirements: - - host: - capability: tosca.capabilities.Container - node: tosca.nodes.WebServer - relationship: tosca.relationships.HostedOn - capabilities: - app_endpoint: - type: tosca.capabilities.Endpoint - - tosca.nodes.BlockStorage: - derived_from: tosca.nodes.Root - properties: - size: - type: scalar-unit.size - constraints: - - greater_or_equal: 1 MB - volume_id: - type: string - required: false - snapshot_id: - type: string - required: false - attributes: - volume_id: - type: string - capabilities: - attachment: - type: tosca.capabilities.Attachment - - tosca.nodes.network.Network: - derived_from: tosca.nodes.Root - description: > - The TOSCA Network node represents a simple, logical network service. - properties: - ip_version: - type: integer - required: false - default: 4 - constraints: - - valid_values: [ 4, 6 ] - description: > - The IP version of the requested network. Valid values are 4 for ipv4 - or 6 for ipv6. - cidr: - type: string - required: false - description: > - The cidr block of the requested network. - start_ip: - type: string - required: false - description: > - The IP address to be used as the start of a pool of addresses within - the full IP range derived from the cidr block. - end_ip: - type: string - required: false - description: > - The IP address to be used as the end of a pool of addresses within - the full IP range derived from the cidr block. - gateway_ip: - type: string - required: false - description: > - The gateway IP address. - network_name: - type: string - required: false - description: > - An identifier that represents an existing Network instance in the - underlying cloud infrastructure or can be used as the name of the - newly created network. If network_name is provided and no other - properties are provided (with exception of network_id), then an - existing network instance will be used. If network_name is provided - alongside with more properties then a new network with this name will - be created. - network_id: - type: string - required: false - description: > - An identifier that represents an existing Network instance in the - underlying cloud infrastructure. This property is mutually exclusive - with all other properties except network_name. This can be used alone - or together with network_name to identify an existing network. - segmentation_id: - type: string - required: false - description: > - A segmentation identifier in the underlying cloud infrastructure. - E.g. VLAN ID, GRE tunnel ID, etc.. - network_type: - type: string - required: false - description: > - It specifies the nature of the physical network in the underlying - cloud infrastructure. Examples are flat, vlan, gre or vxlan. - For flat and vlan types, physical_network should be provided too. - physical_network: - type: string - required: false - description: > - It identifies the physical network on top of which the network is - implemented, e.g. physnet1. This property is required if network_type - is flat or vlan. - dhcp_enabled: - type: boolean - required: false - default: true - description: > - Indicates should DHCP service be enabled on the network or not. - capabilities: - link: - type: tosca.capabilities.network.Linkable - - tosca.nodes.network.Port: - derived_from: tosca.nodes.Root - description: > - The TOSCA Port node represents a logical entity that associates between - Compute and Network normative types. The Port node type effectively - represents a single virtual NIC on the Compute node instance. - properties: - ip_address: - type: string - required: false - description: > - Allow the user to set a static IP. - order: - type: integer - required: false - default: 0 - constraints: - - greater_or_equal: 0 - description: > - The order of the NIC on the compute instance (e.g. eth2). - is_default: - type: boolean - required: false - default: false - description: > - If is_default=true this port will be used for the default gateway - route. Only one port that is associated to single compute node can - set as is_default=true. - ip_range_start: - type: string - required: false - description: > - Defines the starting IP of a range to be allocated for the compute - instances that are associated with this Port. - ip_range_end: - type: string - required: false - description: > - Defines the ending IP of a range to be allocated for the compute - instances that are associated with this Port. - attributes: - ip_address: - type: string - requirements: - - binding: - description: > - Binding requirement expresses the relationship between Port and - Compute nodes. Effectively it indicates that the Port will be - attached to specific Compute node instance - capability: tosca.capabilities.network.Bindable - relationship: tosca.relationships.network.BindsTo - node: tosca.nodes.Compute - - link: - description: > - Link requirement expresses the relationship between Port and Network - nodes. It indicates which network this port will connect to. - capability: tosca.capabilities.network.Linkable - relationship: tosca.relationships.network.LinksTo - node: tosca.nodes.network.Network - - tosca.nodes.ObjectStorage: - derived_from: tosca.nodes.Root - description: > - The TOSCA ObjectStorage node represents storage that provides the ability - to store data as objects (or BLOBs of data) without consideration for the - underlying filesystem or devices - properties: - name: - type: string - required: true - description: > - The logical name of the object store (or container). - size: - type: scalar-unit.size - required: false - constraints: - - greater_or_equal: 0 GB - description: > - The requested initial storage size. - maxsize: - type: scalar-unit.size - required: false - constraints: - - greater_or_equal: 0 GB - description: > - The requested maximum storage size. - capabilities: - storage_endpoint: - type: tosca.capabilities.Endpoint - - tosca.nodes.LoadBalancer: - derived_from: tosca.nodes.Root - properties: - algorithm: - type: string - required: false - status: experimental - capabilities: - client: - type: tosca.capabilities.Endpoint.Public - occurrences: [0, UNBOUNDED] - description: the Floating (IP) client’s on the public network can connect to - requirements: - - application: - capability: tosca.capabilities.Endpoint - relationship: tosca.relationships.RoutesTo - occurrences: [0, UNBOUNDED] - description: Connection to one or more load balanced applications - - tosca.nodes.Container.Application: - derived_from: tosca.nodes.Root - requirements: - - host: - capability: tosca.capabilities.Container - node: tosca.nodes.Container.Runtime - relationship: tosca.relationships.HostedOn - - tosca.nodes.Container.Runtime: - derived_from: tosca.nodes.SoftwareComponent - capabilities: - host: - type: tosca.capabilities.Container - scalable: - type: tosca.capabilities.Scalable - - tosca.nodes.Container.Application.Docker: - derived_from: tosca.nodes.Container.Application - requirements: - - host: - capability: tosca.capabilities.Container.Docker - -########################################################################## -# Relationship Type. -# A Relationship Type is a reusable entity that defines the type of one -# or more relationships between Node Types or Node Templates. -########################################################################## -relationship_types: - tosca.relationships.Root: - description: > - The TOSCA root Relationship Type all other TOSCA base Relationship Types - derive from. - attributes: - tosca_id: - type: string - tosca_name: - type: string - interfaces: - Configure: - type: tosca.interfaces.relationship.Configure - - tosca.relationships.DependsOn: - derived_from: tosca.relationships.Root - - tosca.relationships.HostedOn: - derived_from: tosca.relationships.Root - valid_target_types: [ tosca.capabilities.Container ] - - tosca.relationships.ConnectsTo: - derived_from: tosca.relationships.Root - valid_target_types: [ tosca.capabilities.Endpoint ] - credential: - type: tosca.datatypes.Credential - required: false - - tosca.relationships.AttachesTo: - derived_from: tosca.relationships.Root - valid_target_types: [ tosca.capabilities.Attachment ] - properties: - location: - required: true - type: string - constraints: - - min_length: 1 - device: - required: false - type: string - - tosca.relationships.RoutesTo: - derived_from: tosca.relationships.ConnectsTo - valid_target_types: [ tosca.capabilities.Endpoint ] - - tosca.relationships.network.LinksTo: - derived_from: tosca.relationships.DependsOn - valid_target_types: [ tosca.capabilities.network.Linkable ] - - tosca.relationships.network.BindsTo: - derived_from: tosca.relationships.DependsOn - valid_target_types: [ tosca.capabilities.network.Bindable ] - -########################################################################## -# Capability Type. -# A Capability Type is a reusable entity that describes a kind of -# capability that a Node Type can declare to expose. -########################################################################## -capability_types: - tosca.capabilities.Root: - description: > - The TOSCA root Capability Type all other TOSCA base Capability Types - derive from. - - tosca.capabilities.Node: - derived_from: tosca.capabilities.Root - - tosca.capabilities.Container: - derived_from: tosca.capabilities.Root - properties: - num_cpus: - required: false - type: integer - constraints: - - greater_or_equal: 1 - cpu_frequency: - required: false - type: scalar-unit.frequency - constraints: - - greater_or_equal: 0.1 GHz - disk_size: - required: false - type: scalar-unit.size - constraints: - - greater_or_equal: 0 MB - mem_size: - required: false - type: scalar-unit.size - constraints: - - greater_or_equal: 0 MB - - tosca.capabilities.Endpoint: - derived_from: tosca.capabilities.Root - properties: - protocol: - type: string - required: true - default: tcp - port: - type: tosca.datatypes.network.PortDef - required: false - secure: - type: boolean - required: false - default: false - url_path: - type: string - required: false - port_name: - type: string - required: false - network_name: - type: string - required: false - default: PRIVATE - initiator: - type: string - required: false - default: source - constraints: - - valid_values: [source, target, peer] - ports: - type: map - required: false - constraints: - - min_length: 1 - entry_schema: - type: tosca.datatypes.network.PortSpec - attributes: - ip_address: - type: string - - tosca.capabilities.Endpoint.Admin: - derived_from: tosca.capabilities.Endpoint - properties: - secure: - type: boolean - default: true - constraints: - - equal: true - - tosca.capabilities.Endpoint.Public: - derived_from: tosca.capabilities.Endpoint - properties: - # Change the default network_name to use the first public network found - network_name: - type: string - default: PUBLIC - constraints: - - equal: PUBLIC - floating: - description: > - Indicates that the public address should be allocated from a pool of - floating IPs that are associated with the network. - type: boolean - default: false - status: experimental - dns_name: - description: The optional name to register with DNS - type: string - required: false - status: experimental - - tosca.capabilities.Scalable: - derived_from: tosca.capabilities.Root - properties: - min_instances: - type: integer - required: true - default: 1 - description: > - This property is used to indicate the minimum number of instances - that should be created for the associated TOSCA Node Template by - a TOSCA orchestrator. - max_instances: - type: integer - required: true - default: 1 - description: > - This property is used to indicate the maximum number of instances - that should be created for the associated TOSCA Node Template by - a TOSCA orchestrator. - default_instances: - type: integer - required: false - description: > - An optional property that indicates the requested default number - of instances that should be the starting number of instances a - TOSCA orchestrator should attempt to allocate. - The value for this property MUST be in the range between the values - set for min_instances and max_instances properties. - - tosca.capabilities.Endpoint.Database: - derived_from: tosca.capabilities.Endpoint - - tosca.capabilities.Attachment: - derived_from: tosca.capabilities.Root - - tosca.capabilities.network.Linkable: - derived_from: tosca.capabilities.Root - description: > - A node type that includes the Linkable capability indicates that it can - be pointed by tosca.relationships.network.LinksTo relationship type, which - represents an association relationship between Port and Network node types. - - tosca.capabilities.network.Bindable: - derived_from: tosca.capabilities.Root - description: > - A node type that includes the Bindable capability indicates that it can - be pointed by tosca.relationships.network.BindsTo relationship type, which - represents a network association relationship between Port and Compute node - types. - - tosca.capabilities.OperatingSystem: - derived_from: tosca.capabilities.Root - properties: - architecture: - required: false - type: string - description: > - The host Operating System (OS) architecture. - type: - required: false - type: string - description: > - The host Operating System (OS) type. - distribution: - required: false - type: string - description: > - The host Operating System (OS) distribution. Examples of valid values - for an “type” of “Linux” would include: - debian, fedora, rhel and ubuntu. - version: - required: false - type: version - description: > - The host Operating System version. - - tosca.capabilities.Container.Docker: - derived_from: tosca.capabilities.Container - properties: - version: - type: list - required: false - entry_schema: - type: version - description: > - The Docker version capability. - publish_all: - type: boolean - default: false - required: false - description: > - Indicates that all ports (ranges) listed in the dockerfile - using the EXPOSE keyword be published. - publish_ports: - type: list - entry_schema: - type: tosca.datatypes.network.PortSpec - required: false - description: > - List of ports mappings from source (Docker container) - to target (host) ports to publish. - expose_ports: - type: list - entry_schema: - type: tosca.datatypes.network.PortSpec - required: false - description: > - List of ports mappings from source (Docker container) to expose - to other Docker containers (not accessible outside host). - volumes: - type: list - entry_schema: - type: string - required: false - description: > - The dockerfile VOLUME command which is used to enable access - from the Docker container to a directory on the host machine. - host_id: - type: string - required: false - description: > - The optional identifier of an existing host resource - that should be used to run this container on. - volume_id: - type: string - required: false - description: > - The optional identifier of an existing storage volume (resource) - that should be used to create the container's mount point(s) on. - -########################################################################## - # Interfaces Type. - # The Interfaces element describes a list of one or more interface - # definitions for a modelable entity (e.g., a Node or Relationship Type) - # as defined within the TOSCA Simple Profile specification. -########################################################################## -interface_types: - tosca.interfaces.node.lifecycle.Standard: - create: - description: Standard lifecycle create operation. - configure: - description: Standard lifecycle configure operation. - start: - description: Standard lifecycle start operation. - stop: - description: Standard lifecycle stop operation. - delete: - description: Standard lifecycle delete operation. - - tosca.interfaces.relationship.Configure: - pre_configure_source: - description: Operation to pre-configure the source endpoint. - pre_configure_target: - description: Operation to pre-configure the target endpoint. - post_configure_source: - description: Operation to post-configure the source endpoint. - post_configure_target: - description: Operation to post-configure the target endpoint. - add_target: - description: Operation to add a target node. - remove_target: - description: Operation to remove a target node. - add_source: > - description: Operation to notify the target node of a source node which - is now available via a relationship. - description: - target_changed: > - description: Operation to notify source some property or attribute of the - target changed - -########################################################################## - # Data Type. - # A Datatype is a complex data type declaration which contains other - # complex or simple data types. -########################################################################## -data_types: - tosca.datatypes.Root: - description: > - The TOSCA root Data Type all other TOSCA base Data Types derive from - - tosca.datatypes.network.NetworkInfo: - derived_from: tosca.datatypes.Root - properties: - network_name: - type: string - network_id: - type: string - addresses: - type: list - entry_schema: - type: string - - tosca.datatypes.network.PortInfo: - derived_from: tosca.datatypes.Root - properties: - port_name: - type: string - port_id: - type: string - network_id: - type: string - mac_address: - type: string - addresses: - type: list - entry_schema: - type: string - - tosca.datatypes.network.PortDef: - derived_from: tosca.datatypes.Root - type: integer - constraints: - - in_range: [ 1, 65535 ] - - tosca.datatypes.network.PortSpec: - derived_from: tosca.datatypes.Root - properties: - protocol: - type: string - required: true - default: tcp - constraints: - - valid_values: [ udp, tcp, igmp ] - target: - type: tosca.datatypes.network.PortDef - required: false - target_range: - type: range - required: false - constraints: - - in_range: [ 1, 65535 ] - source: - type: tosca.datatypes.network.PortDef - required: false - source_range: - type: range - required: false - constraints: - - in_range: [ 1, 65535 ] - - tosca.datatypes.Credential: - derived_from: tosca.datatypes.Root - properties: - protocol: - type: string - required: false - token_type: - type: string - default: password - required: true - token: - type: string - required: true - keys: - type: map - entry_schema: - type: string - required: false - user: - type: string - required: false - -########################################################################## - # Artifact Type. - # An Artifact Type is a reusable entity that defines the type of one or more - # files which Node Types or Node Templates can have dependent relationships - # and used during operations such as during installation or deployment. -########################################################################## -artifact_types: - tosca.artifacts.Root: - description: > - The TOSCA Artifact Type all other TOSCA Artifact Types derive from - properties: - version: version - - tosca.artifacts.File: - derived_from: tosca.artifacts.Root - - tosca.artifacts.Deployment: - derived_from: tosca.artifacts.Root - description: TOSCA base type for deployment artifacts - - tosca.artifacts.Deployment.Image: - derived_from: tosca.artifacts.Deployment - - tosca.artifacts.Deployment.Image.VM: - derived_from: tosca.artifacts.Deployment.Image - - tosca.artifacts.Implementation: - derived_from: tosca.artifacts.Root - description: TOSCA base type for implementation artifacts - - tosca.artifacts.Implementation.Bash: - derived_from: tosca.artifacts.Implementation - description: Script artifact for the Unix Bash shell - mime_type: application/x-sh - file_ext: [ sh ] - - tosca.artifacts.Implementation.Python: - derived_from: tosca.artifacts.Implementation - description: Artifact for the interpreted Python language - mime_type: application/x-python - file_ext: [ py ] - - tosca.artifacts.Deployment.Image.Container.Docker: - derived_from: tosca.artifacts.Deployment.Image - description: Docker container image - - tosca.artifacts.Deployment.Image.VM.ISO: - derived_from: tosca.artifacts.Deployment.Image - description: Virtual Machine (VM) image in ISO disk format - mime_type: application/octet-stream - file_ext: [ iso ] - - tosca.artifacts.Deployment.Image.VM.QCOW2: - derived_from: tosca.artifacts.Deployment.Image - description: Virtual Machine (VM) image in QCOW v2 standard disk format - mime_type: application/octet-stream - file_ext: [ qcow2 ] - -########################################################################## - # Policy Type. - # TOSCA Policy Types represent logical grouping of TOSCA nodes that have - # an implied relationship and need to be orchestrated or managed together - # to achieve some result. -########################################################################## -policy_types: - tosca.policies.Root: - description: The TOSCA Policy Type all other TOSCA Policy Types derive from. - - tosca.policies.Placement: - derived_from: tosca.policies.Root - description: The TOSCA Policy Type definition that is used to govern - placement of TOSCA nodes or groups of nodes. - - tosca.policies.Placement.Colocate: - derived_from: tosca.policies.Placement - description: The TOSCA Policy Type definition that is used to govern - colocate placement of TOSCA nodes or groups of nodes. - - tosca.policies.Placement.Antilocate: - derived_from: tosca.policies.Placement - description: The TOSCA Policy Type definition that is used to govern - anti-locate placement of TOSCA nodes or groups of nodes. - - tosca.policies.Scaling: - derived_from: tosca.policies.Root - description: The TOSCA Policy Type definition that is used to govern - scaling of TOSCA nodes or groups of nodes. - - tosca.policies.Update: - derived_from: tosca.policies.Root - description: The TOSCA Policy Type definition that is used to govern - update of TOSCA nodes or groups of nodes. - - tosca.policies.Performance: - derived_from: tosca.policies.Root - description: The TOSCA Policy Type definition that is used to declare - performance requirements for TOSCA nodes or groups of nodes. - -########################################################################## - # Group Type. - # Group Type represents logical grouping of TOSCA nodes that have an - # implied membership relationship and may need to be orchestrated or - # managed together to achieve some result. -########################################################################## -group_types: - tosca.groups.Root: - description: The TOSCA Group Type all other TOSCA Group Types derive from - interfaces: - Standard: - type: tosca.interfaces.node.lifecycle.Standard diff --git a/nfvparser/src/main/python/toscaparser/elements/__init__.py b/nfvparser/src/main/python/toscaparser/elements/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/nfvparser/src/main/python/toscaparser/elements/artifacttype.py b/nfvparser/src/main/python/toscaparser/elements/artifacttype.py deleted file mode 100644 index bf379fc..0000000 --- a/nfvparser/src/main/python/toscaparser/elements/artifacttype.py +++ /dev/null @@ -1,50 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from toscaparser.elements.statefulentitytype import StatefulEntityType - - -class ArtifactTypeDef(StatefulEntityType): - '''TOSCA built-in artifacts type.''' - - def __init__(self, atype, custom_def=None): - super(ArtifactTypeDef, self).__init__(atype, self.ARTIFACT_PREFIX, - custom_def) - self.type = atype - self.custom_def = custom_def - self.properties = None - if self.PROPERTIES in self.defs: - self.properties = self.defs[self.PROPERTIES] - self.parent_artifacts = self._get_parent_artifacts() - - def _get_parent_artifacts(self): - artifacts = {} - parent_artif = self.parent_type.type if self.parent_type else None - if parent_artif: - while parent_artif != 'tosca.artifacts.Root': - artifacts[parent_artif] = self.TOSCA_DEF[parent_artif] - parent_artif = artifacts[parent_artif]['derived_from'] - return artifacts - - @property - def parent_type(self): - '''Return a artifact entity from which this entity is derived.''' - if not hasattr(self, 'defs'): - return None - partifact_entity = self.derived_from(self.defs) - if partifact_entity: - return ArtifactTypeDef(partifact_entity, self.custom_def) - - def get_artifact(self, name): - '''Return the definition of an artifact field by name.''' - if name in self.defs: - return self.defs[name] diff --git a/nfvparser/src/main/python/toscaparser/elements/attribute_definition.py b/nfvparser/src/main/python/toscaparser/elements/attribute_definition.py deleted file mode 100644 index 35ba27f..0000000 --- a/nfvparser/src/main/python/toscaparser/elements/attribute_definition.py +++ /dev/null @@ -1,20 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - - -class AttributeDef(object): - '''TOSCA built-in Attribute type.''' - - def __init__(self, name, value=None, schema=None): - self.name = name - self.value = value - self.schema = schema diff --git a/nfvparser/src/main/python/toscaparser/elements/capabilitytype.py b/nfvparser/src/main/python/toscaparser/elements/capabilitytype.py deleted file mode 100644 index 5fa9661..0000000 --- a/nfvparser/src/main/python/toscaparser/elements/capabilitytype.py +++ /dev/null @@ -1,96 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from toscaparser.elements.property_definition import PropertyDef -from toscaparser.elements.statefulentitytype import StatefulEntityType - - -class CapabilityTypeDef(StatefulEntityType): - '''TOSCA built-in capabilities type.''' - TOSCA_TYPEURI_CAPABILITY_ROOT = 'tosca.capabilities.Root' - - def __init__(self, name, ctype, ntype, custom_def=None): - self.name = name - super(CapabilityTypeDef, self).__init__(ctype, self.CAPABILITY_PREFIX, - custom_def) - self.nodetype = ntype - self.properties = None - self.custom_def = custom_def - if self.PROPERTIES in self.defs: - self.properties = self.defs[self.PROPERTIES] - self.parent_capabilities = self._get_parent_capabilities(custom_def) - - def get_properties_def_objects(self): - '''Return a list of property definition objects.''' - properties = [] - parent_properties = {} - if self.parent_capabilities: - for type, value in self.parent_capabilities.items(): - parent_properties[type] = value.get('properties') - if self.properties: - for prop, schema in self.properties.items(): - properties.append(PropertyDef(prop, None, schema)) - if parent_properties: - for parent, props in parent_properties.items(): - for prop, schema in props.items(): - # add parent property if not overridden by children type - if not self.properties or \ - prop not in self.properties.keys(): - properties.append(PropertyDef(prop, None, schema)) - return properties - - def get_properties_def(self): - '''Return a dictionary of property definition name-object pairs.''' - return {prop.name: prop - for prop in self.get_properties_def_objects()} - - def get_property_def_value(self, name): - '''Return the definition of a given property name.''' - props_def = self.get_properties_def() - if props_def and name in props_def: - return props_def[name].value - - def _get_parent_capabilities(self, custom_def=None): - capabilities = {} - parent_cap = self.parent_type - if parent_cap: - parent_cap = parent_cap.type - while parent_cap != self.TOSCA_TYPEURI_CAPABILITY_ROOT: - if parent_cap in self.TOSCA_DEF.keys(): - capabilities[parent_cap] = self.TOSCA_DEF[parent_cap] - elif custom_def and parent_cap in custom_def.keys(): - capabilities[parent_cap] = custom_def[parent_cap] - parent_cap = capabilities[parent_cap]['derived_from'] - return capabilities - - @property - def parent_type(self): - '''Return a capability this capability is derived from.''' - if not hasattr(self, 'defs'): - return None - pnode = self.derived_from(self.defs) - if pnode: - return CapabilityTypeDef(self.name, pnode, - self.nodetype, self.custom_def) - - def inherits_from(self, type_names): - '''Check this capability is in type_names - - Check if this capability or some of its parent types - are in the list of types: type_names - ''' - if self.type in type_names: - return True - elif self.parent_type: - return self.parent_type.inherits_from(type_names) - else: - return False diff --git a/nfvparser/src/main/python/toscaparser/elements/constraints.py b/nfvparser/src/main/python/toscaparser/elements/constraints.py deleted file mode 100644 index 70863bc..0000000 --- a/nfvparser/src/main/python/toscaparser/elements/constraints.py +++ /dev/null @@ -1,615 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import collections -import datetime -import re - -import toscaparser -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import InvalidSchemaError -from toscaparser.common.exception import ValidationError -from toscaparser.elements.portspectype import PortSpec -from toscaparser.elements import scalarunit -from toscaparser.utils.gettextutils import _ - - -class Schema(collections.Mapping): - - KEYS = ( - TYPE, REQUIRED, DESCRIPTION, - DEFAULT, CONSTRAINTS, ENTRYSCHEMA, STATUS - ) = ( - 'type', 'required', 'description', - 'default', 'constraints', 'entry_schema', 'status' - ) - - PROPERTY_TYPES = ( - INTEGER, STRING, BOOLEAN, FLOAT, RANGE, - NUMBER, TIMESTAMP, LIST, MAP, - SCALAR_UNIT_SIZE, SCALAR_UNIT_FREQUENCY, SCALAR_UNIT_TIME, - VERSION, PORTDEF, PORTSPEC - ) = ( - 'integer', 'string', 'boolean', 'float', 'range', - 'number', 'timestamp', 'list', 'map', - 'scalar-unit.size', 'scalar-unit.frequency', 'scalar-unit.time', - 'version', 'PortDef', PortSpec.SHORTNAME - ) - - SCALAR_UNIT_SIZE_DEFAULT = 'B' - SCALAR_UNIT_SIZE_DICT = {'B': 1, 'KB': 1000, 'KIB': 1024, 'MB': 1000000, - 'MIB': 1048576, 'GB': 1000000000, - 'GIB': 1073741824, 'TB': 1000000000000, - 'TIB': 1099511627776} - - def __init__(self, name, schema_dict): - self.name = name - if not isinstance(schema_dict, collections.Mapping): - msg = (_('Schema definition of "%(pname)s" must be a dict.') - % dict(pname=name)) - ExceptionCollector.appendException(InvalidSchemaError(message=msg)) - - try: - schema_dict['type'] - except KeyError: - msg = (_('Schema definition of "%(pname)s" must have a "type" ' - 'attribute.') % dict(pname=name)) - ExceptionCollector.appendException(InvalidSchemaError(message=msg)) - - self.schema = schema_dict - self._len = None - self.constraints_list = [] - - @property - def type(self): - return self.schema[self.TYPE] - - @property - def required(self): - return self.schema.get(self.REQUIRED, True) - - @property - def description(self): - return self.schema.get(self.DESCRIPTION, '') - - @property - def default(self): - return self.schema.get(self.DEFAULT) - - @property - def status(self): - return self.schema.get(self.STATUS, '') - - @property - def constraints(self): - if not self.constraints_list: - constraint_schemata = self.schema.get(self.CONSTRAINTS) - if constraint_schemata: - self.constraints_list = [Constraint(self.name, - self.type, - cschema) - for cschema in constraint_schemata] - return self.constraints_list - - @property - def entry_schema(self): - return self.schema.get(self.ENTRYSCHEMA) - - def __getitem__(self, key): - return self.schema[key] - - def __iter__(self): - for k in self.KEYS: - try: - self.schema[k] - except KeyError: - pass - else: - yield k - - def __len__(self): - if self._len is None: - self._len = len(list(iter(self))) - return self._len - - -class Constraint(object): - '''Parent class for constraints for a Property or Input.''' - - CONSTRAINTS = (EQUAL, GREATER_THAN, - GREATER_OR_EQUAL, LESS_THAN, LESS_OR_EQUAL, IN_RANGE, - VALID_VALUES, LENGTH, MIN_LENGTH, MAX_LENGTH, PATTERN) = \ - ('equal', 'greater_than', 'greater_or_equal', 'less_than', - 'less_or_equal', 'in_range', 'valid_values', 'length', - 'min_length', 'max_length', 'pattern') - - def __new__(cls, property_name, property_type, constraint): - if cls is not Constraint: - return super(Constraint, cls).__new__(cls) - - if(not isinstance(constraint, collections.Mapping) or - len(constraint) != 1): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('Invalid constraint schema.'))) - - for type in constraint.keys(): - ConstraintClass = get_constraint_class(type) - if not ConstraintClass: - msg = _('Invalid property "%s".') % type - ExceptionCollector.appendException( - InvalidSchemaError(message=msg)) - - return ConstraintClass(property_name, property_type, constraint) - - def __init__(self, property_name, property_type, constraint): - self.property_name = property_name - self.property_type = property_type - self.constraint_value = constraint[self.constraint_key] - self.constraint_value_msg = self.constraint_value - if self.property_type in scalarunit.ScalarUnit.SCALAR_UNIT_TYPES: - self.constraint_value = self._get_scalarunit_constraint_value() - # check if constraint is valid for property type - if property_type not in self.valid_prop_types: - msg = _('Property "%(ctype)s" is not valid for data type ' - '"%(dtype)s".') % dict( - ctype=self.constraint_key, - dtype=property_type) - ExceptionCollector.appendException(InvalidSchemaError(message=msg)) - - def _get_scalarunit_constraint_value(self): - if self.property_type in scalarunit.ScalarUnit.SCALAR_UNIT_TYPES: - ScalarUnit_Class = (scalarunit. - get_scalarunit_class(self.property_type)) - if isinstance(self.constraint_value, list): - return [ScalarUnit_Class(v).get_num_from_scalar_unit() - for v in self.constraint_value] - else: - return (ScalarUnit_Class(self.constraint_value). - get_num_from_scalar_unit()) - - def _err_msg(self, value): - return _('Property "%s" could not be validated.') % self.property_name - - def validate(self, value): - self.value_msg = value - if self.property_type in scalarunit.ScalarUnit.SCALAR_UNIT_TYPES: - value = scalarunit.get_scalarunit_value(self.property_type, value) - if not self._is_valid(value): - err_msg = self._err_msg(value) - ExceptionCollector.appendException( - ValidationError(message=err_msg)) - - -class Equal(Constraint): - """Constraint class for "equal" - - Constrains a property or parameter to a value equal to ('=') - the value declared. - """ - - constraint_key = Constraint.EQUAL - - valid_prop_types = Schema.PROPERTY_TYPES - - def _is_valid(self, value): - if value == self.constraint_value: - return True - - return False - - def _err_msg(self, value): - return (_('The value "%(pvalue)s" of property "%(pname)s" is not ' - 'equal to "%(cvalue)s".') % - dict(pname=self.property_name, - pvalue=self.value_msg, - cvalue=self.constraint_value_msg)) - - -class GreaterThan(Constraint): - """Constraint class for "greater_than" - - Constrains a property or parameter to a value greater than ('>') - the value declared. - """ - - constraint_key = Constraint.GREATER_THAN - - valid_types = (int, float, datetime.date, - datetime.time, datetime.datetime) - - valid_prop_types = (Schema.INTEGER, Schema.FLOAT, Schema.TIMESTAMP, - Schema.SCALAR_UNIT_SIZE, Schema.SCALAR_UNIT_FREQUENCY, - Schema.SCALAR_UNIT_TIME) - - def __init__(self, property_name, property_type, constraint): - super(GreaterThan, self).__init__(property_name, property_type, - constraint) - if not isinstance(constraint[self.GREATER_THAN], self.valid_types): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('The property "greater_than" ' - 'expects comparable values.'))) - - def _is_valid(self, value): - if value > self.constraint_value: - return True - - return False - - def _err_msg(self, value): - return (_('The value "%(pvalue)s" of property "%(pname)s" must be ' - 'greater than "%(cvalue)s".') % - dict(pname=self.property_name, - pvalue=self.value_msg, - cvalue=self.constraint_value_msg)) - - -class GreaterOrEqual(Constraint): - """Constraint class for "greater_or_equal" - - Constrains a property or parameter to a value greater than or equal - to ('>=') the value declared. - """ - - constraint_key = Constraint.GREATER_OR_EQUAL - - valid_types = (int, float, datetime.date, - datetime.time, datetime.datetime) - - valid_prop_types = (Schema.INTEGER, Schema.FLOAT, Schema.TIMESTAMP, - Schema.SCALAR_UNIT_SIZE, Schema.SCALAR_UNIT_FREQUENCY, - Schema.SCALAR_UNIT_TIME) - - def __init__(self, property_name, property_type, constraint): - super(GreaterOrEqual, self).__init__(property_name, property_type, - constraint) - if not isinstance(self.constraint_value, self.valid_types): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('The property ' - '"greater_or_equal" expects ' - 'comparable values.'))) - - def _is_valid(self, value): - if toscaparser.functions.is_function(value) or \ - value >= self.constraint_value: - return True - return False - - def _err_msg(self, value): - return (_('The value "%(pvalue)s" of property "%(pname)s" must be ' - 'greater than or equal to "%(cvalue)s".') % - dict(pname=self.property_name, - pvalue=self.value_msg, - cvalue=self.constraint_value_msg)) - - -class LessThan(Constraint): - """Constraint class for "less_than" - - Constrains a property or parameter to a value less than ('<') - the value declared. - """ - - constraint_key = Constraint.LESS_THAN - - valid_types = (int, float, datetime.date, - datetime.time, datetime.datetime) - - valid_prop_types = (Schema.INTEGER, Schema.FLOAT, Schema.TIMESTAMP, - Schema.SCALAR_UNIT_SIZE, Schema.SCALAR_UNIT_FREQUENCY, - Schema.SCALAR_UNIT_TIME) - - def __init__(self, property_name, property_type, constraint): - super(LessThan, self).__init__(property_name, property_type, - constraint) - if not isinstance(self.constraint_value, self.valid_types): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('The property "less_than" ' - 'expects comparable values.'))) - - def _is_valid(self, value): - if value < self.constraint_value: - return True - - return False - - def _err_msg(self, value): - return (_('The value "%(pvalue)s" of property "%(pname)s" must be ' - 'less than "%(cvalue)s".') % - dict(pname=self.property_name, - pvalue=self.value_msg, - cvalue=self.constraint_value_msg)) - - -class LessOrEqual(Constraint): - """Constraint class for "less_or_equal" - - Constrains a property or parameter to a value less than or equal - to ('<=') the value declared. - """ - - constraint_key = Constraint.LESS_OR_EQUAL - - valid_types = (int, float, datetime.date, - datetime.time, datetime.datetime) - - valid_prop_types = (Schema.INTEGER, Schema.FLOAT, Schema.TIMESTAMP, - Schema.SCALAR_UNIT_SIZE, Schema.SCALAR_UNIT_FREQUENCY, - Schema.SCALAR_UNIT_TIME) - - def __init__(self, property_name, property_type, constraint): - super(LessOrEqual, self).__init__(property_name, property_type, - constraint) - if not isinstance(self.constraint_value, self.valid_types): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('The property "less_or_equal" ' - 'expects comparable values.'))) - - def _is_valid(self, value): - if value <= self.constraint_value: - return True - - return False - - def _err_msg(self, value): - return (_('The value "%(pvalue)s" of property "%(pname)s" must be ' - 'less than or equal to "%(cvalue)s".') % - dict(pname=self.property_name, - pvalue=self.value_msg, - cvalue=self.constraint_value_msg)) - - -class InRange(Constraint): - """Constraint class for "in_range" - - Constrains a property or parameter to a value in range of (inclusive) - the two values declared. - """ - UNBOUNDED = 'UNBOUNDED' - - constraint_key = Constraint.IN_RANGE - - valid_types = (int, float, datetime.date, - datetime.time, datetime.datetime, str) - - valid_prop_types = (Schema.INTEGER, Schema.FLOAT, Schema.TIMESTAMP, - Schema.SCALAR_UNIT_SIZE, Schema.SCALAR_UNIT_FREQUENCY, - Schema.SCALAR_UNIT_TIME, Schema.RANGE) - - def __init__(self, property_name, property_type, constraint): - super(InRange, self).__init__(property_name, property_type, constraint) - if(not isinstance(self.constraint_value, collections.Sequence) or - (len(constraint[self.IN_RANGE]) != 2)): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('The property "in_range" ' - 'expects a list.'))) - - msg = _('The property "in_range" expects comparable values.') - for value in self.constraint_value: - if not isinstance(value, self.valid_types): - ExceptionCollector.appendException( - InvalidSchemaError(message=msg)) - # The only string we allow for range is the special value - # 'UNBOUNDED' - if(isinstance(value, str) and value != self.UNBOUNDED): - ExceptionCollector.appendException( - InvalidSchemaError(message=msg)) - - self.min = self.constraint_value[0] - self.max = self.constraint_value[1] - - def _is_valid(self, value): - if not isinstance(self.min, str): - if value < self.min: - return False - elif self.min != self.UNBOUNDED: - return False - if not isinstance(self.max, str): - if value > self.max: - return False - elif self.max != self.UNBOUNDED: - return False - return True - - def _err_msg(self, value): - return (_('The value "%(pvalue)s" of property "%(pname)s" is out of ' - 'range "(min:%(vmin)s, max:%(vmax)s)".') % - dict(pname=self.property_name, - pvalue=self.value_msg, - vmin=self.constraint_value_msg[0], - vmax=self.constraint_value_msg[1])) - - -class ValidValues(Constraint): - """Constraint class for "valid_values" - - Constrains a property or parameter to a value that is in the list of - declared values. - """ - constraint_key = Constraint.VALID_VALUES - - valid_prop_types = Schema.PROPERTY_TYPES - - def __init__(self, property_name, property_type, constraint): - super(ValidValues, self).__init__(property_name, property_type, - constraint) - if not isinstance(self.constraint_value, collections.Sequence): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('The property "valid_values" ' - 'expects a list.'))) - - def _is_valid(self, value): - if isinstance(value, list): - return all(v in self.constraint_value for v in value) - return value in self.constraint_value - - def _err_msg(self, value): - allowed = '[%s]' % ', '.join(str(a) for a in self.constraint_value) - return (_('The value "%(pvalue)s" of property "%(pname)s" is not ' - 'valid. Expected a value from "%(cvalue)s".') % - dict(pname=self.property_name, - pvalue=value, - cvalue=allowed)) - - -class Length(Constraint): - """Constraint class for "length" - - Constrains the property or parameter to a value of a given length. - """ - - constraint_key = Constraint.LENGTH - - valid_types = (int, ) - - valid_prop_types = (Schema.STRING, ) - - def __init__(self, property_name, property_type, constraint): - super(Length, self).__init__(property_name, property_type, constraint) - if not isinstance(self.constraint_value, self.valid_types): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('The property "length" expects ' - 'an integer.'))) - - def _is_valid(self, value): - if isinstance(value, str) and len(value) == self.constraint_value: - return True - - return False - - def _err_msg(self, value): - return (_('Length of value "%(pvalue)s" of property "%(pname)s" ' - 'must be equal to "%(cvalue)s".') % - dict(pname=self.property_name, - pvalue=value, - cvalue=self.constraint_value)) - - -class MinLength(Constraint): - """Constraint class for "min_length" - - Constrains the property or parameter to a value to a minimum length. - """ - - constraint_key = Constraint.MIN_LENGTH - - valid_types = (int, ) - - valid_prop_types = (Schema.STRING, Schema.MAP) - - def __init__(self, property_name, property_type, constraint): - super(MinLength, self).__init__(property_name, property_type, - constraint) - if not isinstance(self.constraint_value, self.valid_types): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('The property "min_length" ' - 'expects an integer.'))) - - def _is_valid(self, value): - if ((isinstance(value, str) or isinstance(value, dict)) and - len(value) >= self.constraint_value): - return True - - return False - - def _err_msg(self, value): - return (_('Length of value "%(pvalue)s" of property "%(pname)s" ' - 'must be at least "%(cvalue)s".') % - dict(pname=self.property_name, - pvalue=value, - cvalue=self.constraint_value)) - - -class MaxLength(Constraint): - """Constraint class for "max_length" - - Constrains the property or parameter to a value to a maximum length. - """ - - constraint_key = Constraint.MAX_LENGTH - - valid_types = (int, ) - - valid_prop_types = (Schema.STRING, Schema.MAP) - - def __init__(self, property_name, property_type, constraint): - super(MaxLength, self).__init__(property_name, property_type, - constraint) - if not isinstance(self.constraint_value, self.valid_types): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('The property "max_length" ' - 'expects an integer.'))) - - def _is_valid(self, value): - if ((isinstance(value, str) or isinstance(value, dict)) and - len(value) <= self.constraint_value): - return True - - return False - - def _err_msg(self, value): - return (_('Length of value "%(pvalue)s" of property "%(pname)s" ' - 'must be no greater than "%(cvalue)s".') % - dict(pname=self.property_name, - pvalue=value, - cvalue=self.constraint_value)) - - -class Pattern(Constraint): - """Constraint class for "pattern" - - Constrains the property or parameter to a value that is allowed by - the provided regular expression. - """ - - constraint_key = Constraint.PATTERN - - valid_types = (str, ) - - valid_prop_types = (Schema.STRING, ) - - def __init__(self, property_name, property_type, constraint): - super(Pattern, self).__init__(property_name, property_type, constraint) - if not isinstance(self.constraint_value, self.valid_types): - ExceptionCollector.appendException( - InvalidSchemaError(message=_('The property "pattern" ' - 'expects a string.'))) - self.match = re.compile(self.constraint_value).match - - def _is_valid(self, value): - match = self.match(value) - return match is not None and match.end() == len(value) - - def _err_msg(self, value): - return (_('The value "%(pvalue)s" of property "%(pname)s" does not ' - 'match pattern "%(cvalue)s".') % - dict(pname=self.property_name, - pvalue=value, - cvalue=self.constraint_value)) - - -constraint_mapping = { - Constraint.EQUAL: Equal, - Constraint.GREATER_THAN: GreaterThan, - Constraint.GREATER_OR_EQUAL: GreaterOrEqual, - Constraint.LESS_THAN: LessThan, - Constraint.LESS_OR_EQUAL: LessOrEqual, - Constraint.IN_RANGE: InRange, - Constraint.VALID_VALUES: ValidValues, - Constraint.LENGTH: Length, - Constraint.MIN_LENGTH: MinLength, - Constraint.MAX_LENGTH: MaxLength, - Constraint.PATTERN: Pattern - } - - -def get_constraint_class(type): - return constraint_mapping.get(type) diff --git a/nfvparser/src/main/python/toscaparser/elements/datatype.py b/nfvparser/src/main/python/toscaparser/elements/datatype.py deleted file mode 100644 index 93d1b3a..0000000 --- a/nfvparser/src/main/python/toscaparser/elements/datatype.py +++ /dev/null @@ -1,57 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - - -from toscaparser.elements.statefulentitytype import StatefulEntityType - - -class DataType(StatefulEntityType): - '''TOSCA built-in and user defined complex data type.''' - - def __init__(self, datatypename, custom_def=None): - super(DataType, self).__init__(datatypename, - self.DATATYPE_NETWORK_PREFIX, - custom_def) - self.custom_def = custom_def - - @property - def parent_type(self): - '''Return a datatype this datatype is derived from.''' - ptype = self.derived_from(self.defs) - if ptype: - return DataType(ptype, self.custom_def) - return None - - @property - def value_type(self): - '''Return 'type' section in the datatype schema.''' - return self.entity_value(self.defs, 'type') - - def get_all_properties_objects(self): - '''Return all properties objects defined in type and parent type.''' - props_def = self.get_properties_def_objects() - ptype = self.parent_type - while ptype: - props_def.extend(ptype.get_properties_def_objects()) - ptype = ptype.parent_type - return props_def - - def get_all_properties(self): - '''Return a dictionary of all property definition name-object pairs.''' - return {prop.name: prop - for prop in self.get_all_properties_objects()} - - def get_all_property_value(self, name): - '''Return the value of a given property name.''' - props_def = self.get_all_properties() - if props_def and name in props_def.key(): - return props_def[name].value diff --git a/nfvparser/src/main/python/toscaparser/elements/entity_type.py b/nfvparser/src/main/python/toscaparser/elements/entity_type.py deleted file mode 100644 index 9fd6c4d..0000000 --- a/nfvparser/src/main/python/toscaparser/elements/entity_type.py +++ /dev/null @@ -1,170 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import copy -import logging -import os -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import ValidationError -from toscaparser.extensions.exttools import ExtTools -import toscaparser.utils.yamlparser - -log = logging.getLogger('tosca') - - -class EntityType(object): - '''Base class for TOSCA elements.''' - - SECTIONS = (DERIVED_FROM, PROPERTIES, ATTRIBUTES, REQUIREMENTS, - INTERFACES, CAPABILITIES, TYPE, ARTIFACTS) = \ - ('derived_from', 'properties', 'attributes', 'requirements', - 'interfaces', 'capabilities', 'type', 'artifacts') - - TOSCA_DEF_SECTIONS = ['node_types', 'data_types', 'artifact_types', - 'group_types', 'relationship_types', - 'capability_types', 'interface_types', - 'policy_types'] - - '''TOSCA definition file.''' - TOSCA_DEF_FILE = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "TOSCA_definition_1_0.yaml") - - loader = toscaparser.utils.yamlparser.load_yaml - - TOSCA_DEF_LOAD_AS_IS = loader(TOSCA_DEF_FILE) - - # Map of definition with pre-loaded values of TOSCA_DEF_FILE_SECTIONS - TOSCA_DEF = {} - for section in TOSCA_DEF_SECTIONS: - if section in TOSCA_DEF_LOAD_AS_IS.keys(): - value = TOSCA_DEF_LOAD_AS_IS[section] - for key in value.keys(): - TOSCA_DEF[key] = value[key] - - RELATIONSHIP_TYPE = (DEPENDSON, HOSTEDON, CONNECTSTO, ATTACHESTO, - LINKSTO, BINDSTO) = \ - ('tosca.relationships.DependsOn', - 'tosca.relationships.HostedOn', - 'tosca.relationships.ConnectsTo', - 'tosca.relationships.AttachesTo', - 'tosca.relationships.network.LinksTo', - 'tosca.relationships.network.BindsTo') - - NODE_PREFIX = 'tosca.nodes.' - RELATIONSHIP_PREFIX = 'tosca.relationships.' - CAPABILITY_PREFIX = 'tosca.capabilities.' - INTERFACE_PREFIX = 'tosca.interfaces.' - ARTIFACT_PREFIX = 'tosca.artifacts.' - POLICY_PREFIX = 'tosca.policies.' - GROUP_PREFIX = 'tosca.groups.' - # currently the data types are defined only for network - # but may have changes in the future. - DATATYPE_PREFIX = 'tosca.datatypes.' - DATATYPE_NETWORK_PREFIX = DATATYPE_PREFIX + 'network.' - TOSCA = 'tosca' - - def derived_from(self, defs): - '''Return a type this type is derived from.''' - return self.entity_value(defs, 'derived_from') - - def is_derived_from(self, type_str): - '''Check if object inherits from the given type. - - Returns true if this object is derived from 'type_str'. - False otherwise. - ''' - if not self.type: - return False - elif self.type == type_str: - return True - elif self.parent_type: - return self.parent_type.is_derived_from(type_str) - else: - return False - - def entity_value(self, defs, key): - if defs and key in defs: - return defs[key] - - def get_value(self, ndtype, defs=None, parent=None): - value = None - if defs is None: - if not hasattr(self, 'defs'): - return None - defs = self.defs - if defs and ndtype in defs: - # copy the value to avoid that next operations add items in the - # item definitions - value = copy.copy(defs[ndtype]) - if parent: - p = self - if p: - while p: - if p.defs and ndtype in p.defs: - # get the parent value - parent_value = p.defs[ndtype] - if value: - if isinstance(value, dict): - for k, v in parent_value.items(): - if k not in value.keys(): - value[k] = v - if isinstance(value, list): - for p_value in parent_value: - if isinstance(p_value, dict): - if list(p_value.keys())[0] not in [ - list(item.keys())[0] for item in - value]: - value.append(p_value) - else: - if p_value not in value: - value.append(p_value) - else: - value = copy.copy(parent_value) - p = p.parent_type - return value - - def get_definition(self, ndtype): - value = None - if not hasattr(self, 'defs'): - defs = None - ExceptionCollector.appendException( - ValidationError(message="defs is " + str(defs))) - else: - defs = self.defs - if defs is not None and ndtype in defs: - value = defs[ndtype] - p = self.parent_type - if p: - inherited = p.get_definition(ndtype) - if inherited: - inherited = dict(inherited) - if not value: - value = inherited - else: - inherited.update(value) - value.update(inherited) - return value - - -def update_definitions(version): - exttools = ExtTools() - extension_defs_file = exttools.get_defs_file(version) - loader = toscaparser.utils.yamlparser.load_yaml - nfv_def_file = loader(extension_defs_file) - nfv_def = {} - for section in EntityType.TOSCA_DEF_SECTIONS: - if section in nfv_def_file.keys(): - value = nfv_def_file[section] - for key in value.keys(): - nfv_def[key] = value[key] - EntityType.TOSCA_DEF.update(nfv_def) diff --git a/nfvparser/src/main/python/toscaparser/elements/grouptype.py b/nfvparser/src/main/python/toscaparser/elements/grouptype.py deleted file mode 100644 index 4e58d64..0000000 --- a/nfvparser/src/main/python/toscaparser/elements/grouptype.py +++ /dev/null @@ -1,95 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import InvalidTypeError -from toscaparser.common.exception import UnknownFieldError -from toscaparser.elements.statefulentitytype import StatefulEntityType - - -class GroupType(StatefulEntityType): - '''TOSCA built-in group type.''' - - SECTIONS = (DERIVED_FROM, VERSION, METADATA, DESCRIPTION, PROPERTIES, - MEMBERS, INTERFACES) = \ - ("derived_from", "version", "metadata", "description", - "properties", "members", "interfaces") - - def __init__(self, grouptype, custom_def=None): - super(GroupType, self).__init__(grouptype, self.GROUP_PREFIX, - custom_def) - self.custom_def = custom_def - self.grouptype = grouptype - self._validate_fields() - self.group_description = None - if self.DESCRIPTION in self.defs: - self.group_description = self.defs[self.DESCRIPTION] - - self.group_version = None - if self.VERSION in self.defs: - self.group_version = self.defs[self.VERSION] - - self.group_properties = None - if self.PROPERTIES in self.defs: - self.group_properties = self.defs[self.PROPERTIES] - - self.group_members = None - if self.MEMBERS in self.defs: - self.group_members = self.defs[self.MEMBERS] - - if self.METADATA in self.defs: - self.meta_data = self.defs[self.METADATA] - self._validate_metadata(self.meta_data) - - @property - def parent_type(self): - '''Return a group statefulentity of this entity is derived from.''' - if not hasattr(self, 'defs'): - return None - pgroup_entity = self.derived_from(self.defs) - if pgroup_entity: - return GroupType(pgroup_entity, self.custom_def) - - @property - def description(self): - return self.group_description - - @property - def version(self): - return self.group_version - - @property - def interfaces(self): - return self.get_value(self.INTERFACES) - - def _validate_fields(self): - if self.defs: - for name in self.defs.keys(): - if name not in self.SECTIONS: - ExceptionCollector.appendException( - UnknownFieldError(what='Group Type %s' - % self.grouptype, field=name)) - - def _validate_metadata(self, meta_data): - if not meta_data.get('type') in ['map', 'tosca:map']: - ExceptionCollector.appendException( - InvalidTypeError(what='"%s" defined in group for ' - 'metadata' % (meta_data.get('type')))) - for entry_schema, entry_schema_type in meta_data.items(): - if isinstance(entry_schema_type, dict) and not \ - entry_schema_type.get('type') == 'string': - ExceptionCollector.appendException( - InvalidTypeError(what='"%s" defined in group for ' - 'metadata "%s"' - % (entry_schema_type.get('type'), - entry_schema))) diff --git a/nfvparser/src/main/python/toscaparser/elements/interfaces.py b/nfvparser/src/main/python/toscaparser/elements/interfaces.py deleted file mode 100644 index 47ec90a..0000000 --- a/nfvparser/src/main/python/toscaparser/elements/interfaces.py +++ /dev/null @@ -1,87 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import UnknownFieldError -from toscaparser.elements.statefulentitytype import StatefulEntityType - -SECTIONS = (LIFECYCLE, CONFIGURE, LIFECYCLE_SHORTNAME, - CONFIGURE_SHORTNAME) = \ - ('tosca.interfaces.node.lifecycle.Standard', - 'tosca.interfaces.relationship.Configure', - 'Standard', 'Configure') - -INTERFACEVALUE = (IMPLEMENTATION, INPUTS) = ('implementation', 'inputs') - -INTERFACE_DEF_RESERVED_WORDS = ['type', 'inputs', 'derived_from', 'version', - 'description'] - - -class InterfacesDef(StatefulEntityType): - '''TOSCA built-in interfaces type.''' - - def __init__(self, node_type, interfacetype, - node_template=None, name=None, value=None): - self.ntype = node_type - self.node_template = node_template - self.type = interfacetype - self.name = name - self.value = value - self.implementation = None - self.inputs = None - self.defs = {} - if interfacetype == LIFECYCLE_SHORTNAME: - interfacetype = LIFECYCLE - if interfacetype == CONFIGURE_SHORTNAME: - interfacetype = CONFIGURE - if hasattr(self.ntype, 'interfaces') \ - and self.ntype.interfaces \ - and interfacetype in self.ntype.interfaces: - interfacetype = self.ntype.interfaces[interfacetype]['type'] - if node_type: - if self.node_template and self.node_template.custom_def \ - and interfacetype in self.node_template.custom_def: - self.defs = self.node_template.custom_def[interfacetype] - else: - self.defs = self.TOSCA_DEF[interfacetype] - if value: - if isinstance(self.value, dict): - for i, j in self.value.items(): - if i == IMPLEMENTATION: - self.implementation = j - elif i == INPUTS: - self.inputs = j - else: - what = ('"interfaces" of template "%s"' % - self.node_template.name) - ExceptionCollector.appendException( - UnknownFieldError(what=what, field=i)) - else: - self.implementation = value - - @property - def lifecycle_ops(self): - if self.defs: - if self.type == LIFECYCLE: - return self._ops() - - @property - def configure_ops(self): - if self.defs: - if self.type == CONFIGURE: - return self._ops() - - def _ops(self): - ops = [] - for name in list(self.defs.keys()): - ops.append(name) - return ops diff --git a/nfvparser/src/main/python/toscaparser/elements/nodetype.py b/nfvparser/src/main/python/toscaparser/elements/nodetype.py deleted file mode 100644 index 7f3da2d..0000000 --- a/nfvparser/src/main/python/toscaparser/elements/nodetype.py +++ /dev/null @@ -1,213 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import UnknownFieldError -from toscaparser.elements.capabilitytype import CapabilityTypeDef -import toscaparser.elements.interfaces as ifaces -from toscaparser.elements.interfaces import InterfacesDef -from toscaparser.elements.relationshiptype import RelationshipType -from toscaparser.elements.statefulentitytype import StatefulEntityType - - -class NodeType(StatefulEntityType): - '''TOSCA built-in node type.''' - SECTIONS = (DERIVED_FROM, METADATA, PROPERTIES, VERSION, DESCRIPTION, ATTRIBUTES, REQUIREMENTS, CAPABILITIES, INTERFACES, ARTIFACTS) = \ - ('derived_from', 'metadata', 'properties', 'version', - 'description', 'attributes', 'requirements', 'capabilities', - 'interfaces', 'artifacts') - - def __init__(self, ntype, custom_def=None): - super(NodeType, self).__init__(ntype, self.NODE_PREFIX, custom_def) - self.ntype = ntype - self.custom_def = custom_def - self._validate_keys() - - @property - def parent_type(self): - '''Return a node this node is derived from.''' - if not hasattr(self, 'defs'): - return None - pnode = self.derived_from(self.defs) - if pnode: - return NodeType(pnode, self.custom_def) - - @property - def relationship(self): - '''Return a dictionary of relationships to other node types. - - This method returns a dictionary of named relationships that nodes - of the current node type (self) can have to other nodes (of specific - types) in a TOSCA template. - - ''' - relationship = {} - requires = self.get_all_requirements() - if requires: - # NOTE(sdmonov): Check if requires is a dict. - # If it is a dict convert it to a list of dicts. - # This is needed because currently the code below supports only - # lists as requirements definition. The following check will - # make sure if a map (dict) was provided it will be converted to - # a list before proceeding to the parsing. - if isinstance(requires, dict): - requires = [{key: value} for key, value in requires.items()] - - keyword = None - node_type = None - for require in requires: - for key, req in require.items(): - if 'relationship' in req: - relation = req.get('relationship') - if 'type' in relation: - relation = relation.get('type') - node_type = req.get('node') - value = req - if node_type: - keyword = 'node' - else: - # If value is a dict and has a type key - # we need to lookup the node type using - # the capability type - value = req - if isinstance(value, dict): - captype = value['capability'] - value = (self. - _get_node_type_by_cap(captype)) - # _get_node_type_by_cap(key, captype)) - # relation = self._get_relation(key, value) - keyword = key - node_type = value - rtype = RelationshipType(relation, keyword, self.custom_def) - relatednode = NodeType(node_type, self.custom_def) - relationship[rtype] = relatednode - return relationship - - def _get_node_type_by_cap(self, cap): - '''Find the node type that has the provided capability - - This method will lookup all node types if they have the - provided capability. - ''' - - # Filter the node types - node_types = [node_type for node_type in self.TOSCA_DEF.keys() - if node_type.startswith(self.NODE_PREFIX) and - node_type != 'tosca.nodes.Root'] - custom_node_types = [node_type for node_type in self.custom_def.keys() - if node_type.startswith(self.NODE_PREFIX) and - node_type != 'tosca.nodes.Root'] - - for node_type in node_types + custom_node_types: - if node_type in self.TOSCA_DEF: - node_def = self.TOSCA_DEF[node_type] - else: - node_def = self.custom_def[node_type] - if isinstance(node_def, dict) and 'capabilities' in node_def: - node_caps = node_def['capabilities'] - for value in node_caps.values(): - if isinstance(value, dict) and \ - 'type' in value and value['type'] == cap: - return node_type - - def _get_relation(self, key, ndtype): - relation = None - ntype = NodeType(ndtype, self.custom_def) - caps = ntype.get_capabilities() - if caps and key in caps.keys(): - c = caps[key] - for r in self.RELATIONSHIP_TYPE: - rtypedef = ntype.TOSCA_DEF[r] - for properties in rtypedef.values(): - if c.type in properties: - relation = r - break - if relation: - break - else: - for properties in rtypedef.values(): - if c.parent_type in properties: - relation = r - break - return relation - - def get_capabilities_objects(self): - '''Return a list of capability objects.''' - typecapabilities = [] - caps = self.get_value(self.CAPABILITIES, None, True) - if caps: - # 'name' is symbolic name of the capability - # 'value' is a dict { 'type': } - for name, value in caps.items(): - ctype = value.get('type') - cap = CapabilityTypeDef(name, ctype, self.type, - self.custom_def) - typecapabilities.append(cap) - return typecapabilities - - def get_capabilities(self): - '''Return a dictionary of capability name-objects pairs.''' - return {cap.name: cap - for cap in self.get_capabilities_objects()} - - @property - def requirements(self): - return self.get_value(self.REQUIREMENTS, None, True) - - def get_all_requirements(self): - return self.requirements - - @property - def interfaces(self): - return self.get_value(self.INTERFACES) - - @property - def lifecycle_inputs(self): - '''Return inputs to life cycle operations if found.''' - inputs = [] - interfaces = self.interfaces - if interfaces: - for name, value in interfaces.items(): - if name == ifaces.LIFECYCLE: - for x, y in value.items(): - if x == 'inputs': - for i in y.iterkeys(): - inputs.append(i) - return inputs - - @property - def lifecycle_operations(self): - '''Return available life cycle operations if found.''' - ops = None - interfaces = self.interfaces - if interfaces: - i = InterfacesDef(self.type, ifaces.LIFECYCLE) - ops = i.lifecycle_ops - return ops - - def get_capability(self, name): - caps = self.get_capabilities() - if caps and name in caps.keys(): - return caps[name].value - - def get_capability_type(self, name): - captype = self.get_capability(name) - if captype and name in captype.keys(): - return captype[name].value - - def _validate_keys(self): - if self.defs: - for key in self.defs.keys(): - if key not in self.SECTIONS: - ExceptionCollector.appendException( - UnknownFieldError(what='Nodetype"%s"' % self.ntype, - field=key)) diff --git a/nfvparser/src/main/python/toscaparser/elements/policytype.py b/nfvparser/src/main/python/toscaparser/elements/policytype.py deleted file mode 100644 index a922d26..0000000 --- a/nfvparser/src/main/python/toscaparser/elements/policytype.py +++ /dev/null @@ -1,121 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import InvalidTypeError -from toscaparser.common.exception import UnknownFieldError -from toscaparser.elements.statefulentitytype import StatefulEntityType -from toscaparser.utils.validateutils import TOSCAVersionProperty - - -class PolicyType(StatefulEntityType): - - '''TOSCA built-in policies type.''' - SECTIONS = (DERIVED_FROM, METADATA, PROPERTIES, VERSION, DESCRIPTION, - TARGETS, TRIGGERS, TYPE) = \ - ('derived_from', 'metadata', 'properties', 'version', - 'description', 'targets', 'triggers', 'type') - - def __init__(self, ptype, custom_def=None): - super(PolicyType, self).__init__(ptype, self.POLICY_PREFIX, - custom_def) - self.type = ptype - self.custom_def = custom_def - self._validate_keys() - - self.meta_data = None - if self.METADATA in self.defs: - self.meta_data = self.defs[self.METADATA] - self._validate_metadata(self.meta_data) - - self.properties = None - if self.PROPERTIES in self.defs: - self.properties = self.defs[self.PROPERTIES] - self.parent_policies = self._get_parent_policies() - - self.policy_version = None - if self.VERSION in self.defs: - self.policy_version = TOSCAVersionProperty( - self.defs[self.VERSION]).get_version() - - self.policy_description = self.defs[self.DESCRIPTION] \ - if self.DESCRIPTION in self.defs else None - - self.targets_list = None - if self.TARGETS in self.defs: - self.targets_list = self.defs[self.TARGETS] - self._validate_targets(self.targets_list, custom_def) - - def _get_parent_policies(self): - policies = {} - parent_policy = self.parent_type.type if self.parent_type else None - if parent_policy: - while parent_policy != 'tosca.policies.Root': - policies[parent_policy] = self.TOSCA_DEF[parent_policy] - parent_policy = policies[parent_policy]['derived_from'] - return policies - - @property - def parent_type(self): - '''Return a policy statefulentity of this node is derived from.''' - if not hasattr(self, 'defs'): - return None - ppolicy_entity = self.derived_from(self.defs) - if ppolicy_entity: - return PolicyType(ppolicy_entity, self.custom_def) - - def get_policy(self, name): - '''Return the definition of a policy field by name.''' - if name in self.defs: - return self.defs[name] - - @property - def targets(self): - '''Return targets.''' - return self.targets_list - - @property - def description(self): - return self.policy_description - - @property - def version(self): - return self.policy_version - - def _validate_keys(self): - for key in self.defs.keys(): - if key not in self.SECTIONS: - ExceptionCollector.appendException( - UnknownFieldError(what='Policy "%s"' % self.type, - field=key)) - - def _validate_targets(self, targets_list, custom_def): - for nodetype in targets_list: - if nodetype not in custom_def: - ExceptionCollector.appendException( - InvalidTypeError(what='"%s" defined in targets for ' - 'policy "%s"' % (nodetype, self.type))) - - def _validate_metadata(self, meta_data): - if not meta_data.get('type') in ['map', 'tosca:map']: - ExceptionCollector.appendException( - InvalidTypeError(what='"%s" defined in policy for ' - 'metadata' % (meta_data.get('type')))) - - for entry_schema, entry_schema_type in meta_data.items(): - if isinstance(entry_schema_type, dict) and not \ - entry_schema_type.get('type') == 'string': - ExceptionCollector.appendException( - InvalidTypeError(what='"%s" defined in policy for ' - 'metadata "%s"' - % (entry_schema_type.get('type'), - entry_schema))) diff --git a/nfvparser/src/main/python/toscaparser/elements/portspectype.py b/nfvparser/src/main/python/toscaparser/elements/portspectype.py deleted file mode 100644 index 0218305..0000000 --- a/nfvparser/src/main/python/toscaparser/elements/portspectype.py +++ /dev/null @@ -1,86 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import logging - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import InvalidTypeAdditionalRequirementsError -from toscaparser.utils.gettextutils import _ -import toscaparser.utils.validateutils as validateutils - -log = logging.getLogger('tosca') - - -class PortSpec(object): - '''Parent class for tosca.datatypes.network.PortSpec type.''' - - SHORTNAME = 'PortSpec' - TYPE_URI = 'tosca.datatypes.network.' + SHORTNAME - - PROPERTY_NAMES = ( - PROTOCOL, SOURCE, SOURCE_RANGE, - TARGET, TARGET_RANGE - ) = ( - 'protocol', 'source', 'source_range', - 'target', 'target_range' - ) - - # TODO(TBD) May want to make this a subclass of DataType - # and change init method to set PortSpec's properties - def __init__(self): - pass - - # The following additional requirements MUST be tested: - # 1) A valid PortSpec MUST have at least one of the following properties: - # target, target_range, source or source_range. - # 2) A valid PortSpec MUST have a value for the source property that - # is within the numeric range specified by the property source_range - # when source_range is specified. - # 3) A valid PortSpec MUST have a value for the target property that is - # within the numeric range specified by the property target_range - # when target_range is specified. - @staticmethod - def validate_additional_req(properties, prop_name, custom_def=None, ): - try: - source = properties.get(PortSpec.SOURCE) - source_range = properties.get(PortSpec.SOURCE_RANGE) - target = properties.get(PortSpec.TARGET) - target_range = properties.get(PortSpec.TARGET_RANGE) - - # verify one of the specified values is set - if source is None and source_range is None and \ - target is None and target_range is None: - ExceptionCollector.appendException( - InvalidTypeAdditionalRequirementsError( - type=PortSpec.TYPE_URI)) - # Validate source value is in specified range - if source and source_range: - validateutils.validate_value_in_range(source, source_range, - PortSpec.SOURCE) - else: - from toscaparser.dataentity import DataEntity - portdef = DataEntity('PortDef', source, None, PortSpec.SOURCE) - portdef.validate() - # Validate target value is in specified range - if target and target_range: - validateutils.validate_value_in_range(target, target_range, - PortSpec.TARGET) - else: - from toscaparser.dataentity import DataEntity - portdef = DataEntity('PortDef', source, None, PortSpec.TARGET) - portdef.validate() - except Exception: - msg = _('"%(value)s" do not meet requirements ' - 'for type "%(type)s".') \ - % {'value': properties, 'type': PortSpec.SHORTNAME} - ExceptionCollector.appendException( - ValueError(msg)) diff --git a/nfvparser/src/main/python/toscaparser/elements/property_definition.py b/nfvparser/src/main/python/toscaparser/elements/property_definition.py deleted file mode 100644 index a242ddf..0000000 --- a/nfvparser/src/main/python/toscaparser/elements/property_definition.py +++ /dev/null @@ -1,100 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import InvalidSchemaError -from toscaparser.common.exception import TOSCAException -from toscaparser.utils.gettextutils import _ - - -class PropertyDef(object): - '''TOSCA built-in Property type.''' - - VALID_PROPERTY_KEYNAMES = (PROPERTY_KEYNAME_DEFAULT, - PROPERTY_KEYNAME_REQUIRED, - PROPERTY_KEYNAME_STATUS) = \ - ('default', 'required', 'status') - - PROPERTY_REQUIRED_DEFAULT = True - - VALID_REQUIRED_VALUES = ['true', 'false'] - VALID_STATUS_VALUES = (PROPERTY_STATUS_SUPPORTED, - PROPERTY_STATUS_EXPERIMENTAL) = \ - ('supported', 'experimental') - - PROPERTY_STATUS_DEFAULT = PROPERTY_STATUS_SUPPORTED - - def __init__(self, name, value=None, schema=None): - self.name = name - self.value = value - self.schema = schema - self._status = self.PROPERTY_STATUS_DEFAULT - self._required = self.PROPERTY_REQUIRED_DEFAULT - - # Validate required 'type' property exists - try: - self.schema['type'] - except KeyError: - msg = (_('Schema definition of "%(pname)s" must have a "type" ' - 'attribute.') % dict(pname=self.name)) - ExceptionCollector.appendException( - InvalidSchemaError(message=msg)) - - if self.schema: - self._load_required_attr_from_schema() - self._load_status_attr_from_schema() - - @property - def default(self): - if self.schema: - for prop_key, prop_value in self.schema.items(): - if prop_key == self.PROPERTY_KEYNAME_DEFAULT: - return prop_value - return None - - @property - def required(self): - return self._required - - def _load_required_attr_from_schema(self): - # IF 'required' keyname exists verify it's a boolean, - # if so override default - if self.PROPERTY_KEYNAME_REQUIRED in self.schema: - value = self.schema[self.PROPERTY_KEYNAME_REQUIRED] - if isinstance(value, bool): - self._required = value - else: - valid_values = ', '.join(self.VALID_REQUIRED_VALUES) - attr = self.PROPERTY_KEYNAME_REQUIRED - TOSCAException.generate_inv_schema_property_error(self, - attr, - value, - valid_values) - - @property - def status(self): - return self._status - - def _load_status_attr_from_schema(self): - # IF 'status' keyname exists verify it's a valid value, - # if so override default - if self.PROPERTY_KEYNAME_STATUS in self.schema: - value = self.schema[self.PROPERTY_KEYNAME_STATUS] - if value in self.VALID_STATUS_VALUES: - self._status = value - else: - valid_values = ', '.join(self.VALID_STATUS_VALUES) - attr = self.PROPERTY_KEYNAME_STATUS - TOSCAException.generate_inv_schema_property_error(self, - attr, - value, - valid_values) diff --git a/nfvparser/src/main/python/toscaparser/elements/relationshiptype.py b/nfvparser/src/main/python/toscaparser/elements/relationshiptype.py deleted file mode 100644 index 8eefbea..0000000 --- a/nfvparser/src/main/python/toscaparser/elements/relationshiptype.py +++ /dev/null @@ -1,49 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import UnknownFieldError -from toscaparser.elements.statefulentitytype import StatefulEntityType - - -class RelationshipType(StatefulEntityType): - '''TOSCA built-in relationship type.''' - SECTIONS = (DERIVED_FROM, VALID_TARGET_TYPES, INTERFACES, - ATTRIBUTES, PROPERTIES, DESCRIPTION, VERSION, - CREDENTIAL) = ('derived_from', 'valid_target_types', - 'interfaces', 'attributes', 'properties', - 'description', 'version', 'credential') - - def __init__(self, type, capability_name=None, custom_def=None): - super(RelationshipType, self).__init__(type, self.RELATIONSHIP_PREFIX, - custom_def) - self.capability_name = capability_name - self.custom_def = custom_def - self._validate_keys() - - @property - def parent_type(self): - '''Return a relationship this reletionship is derived from.''' - prel = self.derived_from(self.defs) - if prel: - return RelationshipType(prel, self.custom_def) - - @property - def valid_target_types(self): - return self.entity_value(self.defs, 'valid_target_types') - - def _validate_keys(self): - for key in self.defs.keys(): - if key not in self.SECTIONS: - ExceptionCollector.appendException( - UnknownFieldError(what='Relationshiptype "%s"' % self.type, - field=key)) diff --git a/nfvparser/src/main/python/toscaparser/elements/scalarunit.py b/nfvparser/src/main/python/toscaparser/elements/scalarunit.py deleted file mode 100644 index d7f72e6..0000000 --- a/nfvparser/src/main/python/toscaparser/elements/scalarunit.py +++ /dev/null @@ -1,129 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import logging -import re - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.utils.gettextutils import _ -from toscaparser.utils import validateutils - -log = logging.getLogger('tosca') - - -class ScalarUnit(object): - '''Parent class for scalar-unit type.''' - - SCALAR_UNIT_TYPES = ( - SCALAR_UNIT_SIZE, SCALAR_UNIT_FREQUENCY, SCALAR_UNIT_TIME - ) = ( - 'scalar-unit.size', 'scalar-unit.frequency', 'scalar-unit.time' - ) - - def __init__(self, value): - self.value = value - - def _check_unit_in_scalar_standard_units(self, input_unit): - """Check whether the input unit is following specified standard - - If unit is not following specified standard, convert it to standard - unit after displaying a warning message. - """ - if input_unit in self.SCALAR_UNIT_DICT.keys(): - return input_unit - else: - for key in self.SCALAR_UNIT_DICT.keys(): - if key.upper() == input_unit.upper(): - log.warning(_('The unit "%(unit)s" does not follow ' - 'scalar unit standards; using "%(key)s" ' - 'instead.') % {'unit': input_unit, - 'key': key}) - return key - msg = (_('The unit "%(unit)s" is not valid. Valid units are ' - '"%(valid_units)s".') % - {'unit': input_unit, - 'valid_units': sorted(self.SCALAR_UNIT_DICT.keys())}) - ExceptionCollector.appendException(ValueError(msg)) - - def validate_scalar_unit(self): - regex = re.compile('([0-9.]+)\s*(\w+)') - try: - result = regex.match(str(self.value)).groups() - validateutils.str_to_num(result[0]) - scalar_unit = self._check_unit_in_scalar_standard_units(result[1]) - self.value = ' '.join([result[0], scalar_unit]) - return self.value - - except Exception: - ExceptionCollector.appendException( - ValueError(_('"%s" is not a valid scalar-unit.') - % self.value)) - - def get_num_from_scalar_unit(self, unit=None): - if unit: - unit = self._check_unit_in_scalar_standard_units(unit) - else: - unit = self.SCALAR_UNIT_DEFAULT - self.validate_scalar_unit() - - regex = re.compile('([0-9.]+)\s*(\w+)') - result = regex.match(str(self.value)).groups() - converted = (float(validateutils.str_to_num(result[0])) - * self.SCALAR_UNIT_DICT[result[1]] - / self.SCALAR_UNIT_DICT[unit]) - if converted - int(converted) < 0.0000000000001: - converted = int(converted) - return converted - - -class ScalarUnit_Size(ScalarUnit): - - SCALAR_UNIT_DEFAULT = 'B' - SCALAR_UNIT_DICT = {'B': 1, 'kB': 1000, 'KiB': 1024, 'MB': 1000000, - 'MiB': 1048576, 'GB': 1000000000, - 'GiB': 1073741824, 'TB': 1000000000000, - 'TiB': 1099511627776} - - -class ScalarUnit_Time(ScalarUnit): - - SCALAR_UNIT_DEFAULT = 'ms' - SCALAR_UNIT_DICT = {'d': 86400, 'h': 3600, 'm': 60, 's': 1, - 'ms': 0.001, 'us': 0.000001, 'ns': 0.000000001} - - -class ScalarUnit_Frequency(ScalarUnit): - - SCALAR_UNIT_DEFAULT = 'GHz' - SCALAR_UNIT_DICT = {'Hz': 1, 'kHz': 1000, - 'MHz': 1000000, 'GHz': 1000000000} - - -scalarunit_mapping = { - ScalarUnit.SCALAR_UNIT_FREQUENCY: ScalarUnit_Frequency, - ScalarUnit.SCALAR_UNIT_SIZE: ScalarUnit_Size, - ScalarUnit.SCALAR_UNIT_TIME: ScalarUnit_Time, - } - - -def get_scalarunit_class(type): - return scalarunit_mapping.get(type) - - -def get_scalarunit_value(type, value, unit=None): - if type in ScalarUnit.SCALAR_UNIT_TYPES: - ScalarUnit_Class = get_scalarunit_class(type) - return (ScalarUnit_Class(value). - get_num_from_scalar_unit(unit)) - else: - ExceptionCollector.appendException( - TypeError(_('"%s" is not a valid scalar-unit type.') % type)) diff --git a/nfvparser/src/main/python/toscaparser/elements/statefulentitytype.py b/nfvparser/src/main/python/toscaparser/elements/statefulentitytype.py deleted file mode 100644 index 2f221b3..0000000 --- a/nfvparser/src/main/python/toscaparser/elements/statefulentitytype.py +++ /dev/null @@ -1,91 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import InvalidTypeError -from toscaparser.elements.attribute_definition import AttributeDef -from toscaparser.elements.entity_type import EntityType -from toscaparser.elements.property_definition import PropertyDef -from toscaparser.unsupportedtype import UnsupportedType - - -class StatefulEntityType(EntityType): - '''Class representing TOSCA states.''' - - interfaces_node_lifecycle_operations = ['create', - 'configure', 'start', - 'stop', 'delete'] - - interfaces_relationship_configure_operations = ['post_configure_source', - 'post_configure_target', - 'add_target', - 'remove_target'] - - def __init__(self, entitytype, prefix, custom_def=None): - entire_entitytype = entitytype - if UnsupportedType.validate_type(entire_entitytype): - self.defs = None - else: - if entitytype.startswith(self.TOSCA + ":"): - entitytype = entitytype[(len(self.TOSCA) + 1):] - entire_entitytype = prefix + entitytype - if not entitytype.startswith(self.TOSCA): - entire_entitytype = prefix + entitytype - if entire_entitytype in list(self.TOSCA_DEF.keys()): - self.defs = self.TOSCA_DEF[entire_entitytype] - entitytype = entire_entitytype - elif custom_def and entitytype in list(custom_def.keys()): - self.defs = custom_def[entitytype] - else: - self.defs = None - ExceptionCollector.appendException( - InvalidTypeError(what=entitytype)) - self.type = entitytype - - def get_properties_def_objects(self): - '''Return a list of property definition objects.''' - properties = [] - props = self.get_definition(self.PROPERTIES) - if props: - for prop, schema in props.items(): - properties.append(PropertyDef(prop, None, schema)) - return properties - - def get_properties_def(self): - '''Return a dictionary of property definition name-object pairs.''' - return {prop.name: prop - for prop in self.get_properties_def_objects()} - - def get_property_def_value(self, name): - '''Return the property definition associated with a given name.''' - props_def = self.get_properties_def() - if props_def and name in props_def.keys(): - return props_def[name].value - - def get_attributes_def_objects(self): - '''Return a list of attribute definition objects.''' - attrs = self.get_value(self.ATTRIBUTES, parent=True) - if attrs: - return [AttributeDef(attr, None, schema) - for attr, schema in attrs.items()] - return [] - - def get_attributes_def(self): - '''Return a dictionary of attribute definition name-object pairs.''' - return {attr.name: attr - for attr in self.get_attributes_def_objects()} - - def get_attribute_def_value(self, name): - '''Return the attribute definition associated with a given name.''' - attrs_def = self.get_attributes_def() - if attrs_def and name in attrs_def.keys(): - return attrs_def[name].value diff --git a/nfvparser/src/main/python/toscaparser/elements/tosca_type_validation.py b/nfvparser/src/main/python/toscaparser/elements/tosca_type_validation.py deleted file mode 100644 index 82b0b46..0000000 --- a/nfvparser/src/main/python/toscaparser/elements/tosca_type_validation.py +++ /dev/null @@ -1,59 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import InvalidTemplateVersion -from toscaparser.common.exception import UnknownFieldError -from toscaparser.extensions.exttools import ExtTools - - -class TypeValidation(object): - - ALLOWED_TYPE_SECTIONS = (DEFINITION_VERSION, DESCRIPTION, IMPORTS, - DSL_DEFINITIONS, NODE_TYPES, REPOSITORIES, - DATA_TYPES, ARTIFACT_TYPES, GROUP_TYPES, - RELATIONSHIP_TYPES, CAPABILITY_TYPES, - INTERFACE_TYPES, POLICY_TYPES, - TOPOLOGY_TEMPLATE) = \ - ('tosca_definitions_version', 'description', 'imports', - 'dsl_definitions', 'node_types', 'repositories', - 'data_types', 'artifact_types', 'group_types', - 'relationship_types', 'capability_types', - 'interface_types', 'policy_types', 'topology_template') - VALID_TEMPLATE_VERSIONS = ['tosca_simple_yaml_1_0'] - exttools = ExtTools() - VALID_TEMPLATE_VERSIONS.extend(exttools.get_versions()) - - def __init__(self, custom_types, import_def): - self.import_def = import_def - self._validate_type_keys(custom_types) - - def _validate_type_keys(self, custom_type): - version = custom_type[self.DEFINITION_VERSION] \ - if self.DEFINITION_VERSION in custom_type \ - else None - if version: - self._validate_type_version(version) - self.version = version - - for name in custom_type: - if name not in self.ALLOWED_TYPE_SECTIONS: - ExceptionCollector.appendException( - UnknownFieldError(what='Template ' + (self.import_def), - field=name)) - - def _validate_type_version(self, version): - if version not in self.VALID_TEMPLATE_VERSIONS: - ExceptionCollector.appendException( - InvalidTemplateVersion( - what=version + ' in ' + self.import_def, - valid_versions=', '. join(self.VALID_TEMPLATE_VERSIONS))) diff --git a/nfvparser/src/main/python/toscaparser/entity_template.py b/nfvparser/src/main/python/toscaparser/entity_template.py deleted file mode 100644 index cc3d620..0000000 --- a/nfvparser/src/main/python/toscaparser/entity_template.py +++ /dev/null @@ -1,329 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from toscaparser.capabilities import Capability -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import MissingRequiredFieldError -from toscaparser.common.exception import UnknownFieldError -from toscaparser.common.exception import ValidationError -from toscaparser.elements.grouptype import GroupType -from toscaparser.elements.interfaces import InterfacesDef -from toscaparser.elements.nodetype import NodeType -from toscaparser.elements.policytype import PolicyType -from toscaparser.elements.relationshiptype import RelationshipType -from toscaparser.properties import Property -from toscaparser.unsupportedtype import UnsupportedType -from toscaparser.utils.gettextutils import _ - - -class EntityTemplate(object): - '''Base class for TOSCA templates.''' - - SECTIONS = (DERIVED_FROM, PROPERTIES, REQUIREMENTS, - INTERFACES, CAPABILITIES, TYPE, DESCRIPTION, DIRECTIVES, - ATTRIBUTES, ARTIFACTS, NODE_FILTER, COPY) = \ - ('derived_from', 'properties', 'requirements', 'interfaces', - 'capabilities', 'type', 'description', 'directives', - 'attributes', 'artifacts', 'node_filter', 'copy') - REQUIREMENTS_SECTION = (NODE, CAPABILITY, RELATIONSHIP, OCCURRENCES, NODE_FILTER) = \ - ('node', 'capability', 'relationship', - 'occurrences', 'node_filter') - # Special key names - SPECIAL_SECTIONS = (METADATA) = ('metadata') - - def __init__(self, name, template, entity_name, custom_def=None): - self.name = name - self.entity_tpl = template - self.custom_def = custom_def - self._validate_field(self.entity_tpl) - type = self.entity_tpl.get('type') - UnsupportedType.validate_type(type) - if entity_name == 'node_type': - self.type_definition = NodeType(type, custom_def) \ - if type is not None else None - if entity_name == 'relationship_type': - relationship = template.get('relationship') - type = None - if relationship and isinstance(relationship, dict): - type = relationship.get('type') - elif isinstance(relationship, str): - type = self.entity_tpl['relationship'] - else: - type = self.entity_tpl['type'] - UnsupportedType.validate_type(type) - self.type_definition = RelationshipType(type, - None, custom_def) - if entity_name == 'policy_type': - if not type: - msg = (_('Policy definition of "%(pname)s" must have' - ' a "type" ''attribute.') % dict(pname=name)) - ExceptionCollector.appendException( - ValidationError(msg)) - self.type_definition = PolicyType(type, custom_def) - if entity_name == 'group_type': - self.type_definition = GroupType(type, custom_def) \ - if type is not None else None - self._properties = None - self._interfaces = None - self._requirements = None - self._capabilities = None - - @property - def type(self): - if self.type_definition: - return self.type_definition.type - - @property - def parent_type(self): - if self.type_definition: - return self.type_definition.parent_type - - @property - def requirements(self): - if self._requirements is None: - self._requirements = self.type_definition.get_value( - self.REQUIREMENTS, - self.entity_tpl) or [] - return self._requirements - - def get_properties_objects(self): - '''Return properties objects for this template.''' - if self._properties is None: - self._properties = self._create_properties() - return self._properties - - def get_properties(self): - '''Return a dictionary of property name-object pairs.''' - return {prop.name: prop - for prop in self.get_properties_objects()} - - def get_property_value(self, name): - '''Return the value of a given property name.''' - props = self.get_properties() - if props and name in props.keys(): - return props[name].value - - @property - def interfaces(self): - if self._interfaces is None: - self._interfaces = self._create_interfaces() - return self._interfaces - - def get_capabilities_objects(self): - '''Return capabilities objects for this template.''' - if not self._capabilities: - self._capabilities = self._create_capabilities() - return self._capabilities - - def get_capabilities(self): - '''Return a dictionary of capability name-object pairs.''' - return {cap.name: cap - for cap in self.get_capabilities_objects()} - - def is_derived_from(self, type_str): - '''Check if object inherits from the given type. - - Returns true if this object is derived from 'type_str'. - False otherwise. - ''' - if not self.type: - return False - elif self.type == type_str: - return True - elif self.parent_type: - return self.parent_type.is_derived_from(type_str) - else: - return False - - def _create_capabilities(self): - capability = [] - caps = self.type_definition.get_value(self.CAPABILITIES, - self.entity_tpl, True) - if caps: - for name, props in caps.items(): - capabilities = self.type_definition.get_capabilities() - if name in capabilities.keys(): - c = capabilities[name] - properties = {} - # first use the definition default value - if c.properties: - for property_name in c.properties.keys(): - prop_def = c.properties[property_name] - if 'default' in prop_def: - properties[property_name] = prop_def['default'] - # then update (if available) with the node properties - if 'properties' in props and props['properties']: - properties.update(props['properties']) - - cap = Capability(name, properties, c) - capability.append(cap) - return capability - - def _validate_properties(self, template, entitytype): - properties = entitytype.get_value(self.PROPERTIES, template) - self._common_validate_properties(entitytype, properties) - - def _validate_capabilities(self): - type_capabilities = self.type_definition.get_capabilities() - allowed_caps = \ - type_capabilities.keys() if type_capabilities else [] - capabilities = self.type_definition.get_value(self.CAPABILITIES, - self.entity_tpl) - if capabilities: - self._common_validate_field(capabilities, allowed_caps, - 'capabilities') - self._validate_capabilities_properties(capabilities) - - def _validate_capabilities_properties(self, capabilities): - for cap, props in capabilities.items(): - capability = self.get_capability(cap) - if not capability: - continue - capabilitydef = capability.definition - self._common_validate_properties(capabilitydef, - props[self.PROPERTIES]) - - # validating capability properties values - for prop in self.get_capability(cap).get_properties_objects(): - prop.validate() - - # TODO(srinivas_tadepalli): temporary work around to validate - # default_instances until standardized in specification - if cap == "scalable" and prop.name == "default_instances": - prop_dict = props[self.PROPERTIES] - min_instances = prop_dict.get("min_instances") - max_instances = prop_dict.get("max_instances") - default_instances = prop_dict.get("default_instances") - if not (min_instances <= default_instances - <= max_instances): - err_msg = ('"properties" of template "%s": ' - '"default_instances" value is not between ' - '"min_instances" and "max_instances".' % - self.name) - ExceptionCollector.appendException( - ValidationError(message=err_msg)) - - def _common_validate_properties(self, entitytype, properties): - allowed_props = [] - required_props = [] - for p in entitytype.get_properties_def_objects(): - allowed_props.append(p.name) - # If property is 'required' and has no 'default' value then record - if p.required and p.default is None: - required_props.append(p.name) - # validate all required properties have values - if properties: - req_props_no_value_or_default = [] - self._common_validate_field(properties, allowed_props, - 'properties') - # make sure it's not missing any property required by a tosca type - for r in required_props: - if r not in properties.keys(): - req_props_no_value_or_default.append(r) - # Required properties found without value or a default value - if req_props_no_value_or_default: - ExceptionCollector.appendException( - MissingRequiredFieldError( - what='"properties" of template "%s"' % self.name, - required=req_props_no_value_or_default)) - else: - # Required properties in schema, but not in template - if required_props: - ExceptionCollector.appendException( - MissingRequiredFieldError( - what='"properties" of template "%s"' % self.name, - required=required_props)) - - def _validate_field(self, template): - if not isinstance(template, dict): - ExceptionCollector.appendException( - MissingRequiredFieldError( - what='Template "%s"' % self.name, required=self.TYPE)) - try: - relationship = template.get('relationship') - if relationship and not isinstance(relationship, str): - relationship[self.TYPE] - elif isinstance(relationship, str): - template['relationship'] - else: - template[self.TYPE] - except KeyError: - ExceptionCollector.appendException( - MissingRequiredFieldError( - what='Template "%s"' % self.name, required=self.TYPE)) - - def _common_validate_field(self, schema, allowedlist, section): - for name in schema: - if name not in allowedlist: - ExceptionCollector.appendException( - UnknownFieldError( - what=('"%(section)s" of template "%(nodename)s"' - % {'section': section, 'nodename': self.name}), - field=name)) - - def _create_properties(self): - props = [] - properties = self.type_definition.get_value(self.PROPERTIES, - self.entity_tpl) or {} - for name, value in properties.items(): - props_def = self.type_definition.get_properties_def() - if props_def and name in props_def: - prop = Property(name, value, - props_def[name].schema, self.custom_def) - props.append(prop) - for p in self.type_definition.get_properties_def_objects(): - if p.default is not None and p.name not in properties.keys(): - prop = Property(p.name, p.default, p.schema, self.custom_def) - props.append(prop) - return props - - def _create_interfaces(self): - interfaces = [] - type_interfaces = None - if isinstance(self.type_definition, RelationshipType): - if isinstance(self.entity_tpl, dict): - if self.INTERFACES in self.entity_tpl: - type_interfaces = self.entity_tpl[self.INTERFACES] - else: - for rel_def, value in self.entity_tpl.items(): - if rel_def != 'type': - rel_def = self.entity_tpl.get(rel_def) - rel = None - if isinstance(rel_def, dict): - rel = rel_def.get('relationship') - if rel: - if self.INTERFACES in rel: - type_interfaces = rel[self.INTERFACES] - break - else: - type_interfaces = self.type_definition.get_value(self.INTERFACES, - self.entity_tpl) - if type_interfaces: - for interface_type, value in type_interfaces.items(): - for op, op_def in value.items(): - iface = InterfacesDef(self.type_definition, - interfacetype=interface_type, - node_template=self, - name=op, - value=op_def) - interfaces.append(iface) - return interfaces - - def get_capability(self, name): - """Provide named capability - - :param name: name of capability - :return: capability object if found, None otherwise - """ - caps = self.get_capabilities() - if caps and name in caps.keys(): - return caps[name] diff --git a/nfvparser/src/main/python/toscaparser/extensions/__init__.py b/nfvparser/src/main/python/toscaparser/extensions/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/nfvparser/src/main/python/toscaparser/extensions/exttools.py b/nfvparser/src/main/python/toscaparser/extensions/exttools.py deleted file mode 100644 index 5310422..0000000 --- a/nfvparser/src/main/python/toscaparser/extensions/exttools.py +++ /dev/null @@ -1,88 +0,0 @@ -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import importlib -import logging -import os - -from toscaparser.common.exception import ToscaExtAttributeError -from toscaparser.common.exception import ToscaExtImportError - -log = logging.getLogger("tosca.model") - -REQUIRED_ATTRIBUTES = ['VERSION', 'DEFS_FILE'] - - -class ExtTools(object): - def __init__(self): - self.EXTENSION_INFO = self._load_extensions() - - def _load_extensions(self): - '''Dynamically load all the extensions .''' - extensions = {} - - # Use the absolute path of the class path - abs_path = os.path.dirname(os.path.abspath(__file__)) - - extdirs = [e for e in os.listdir(abs_path) if - not e.startswith('tests') and - os.path.isdir(os.path.join(abs_path, e))] - - for e in extdirs: - log.info(e) - extpath = abs_path + '/' + e - # Grab all the extension files in the given path - ext_files = [f for f in os.listdir(extpath) if f.endswith('.py') - and not f.startswith('__init__')] - - # For each module, pick out the target translation class - for f in ext_files: - log.info(f) - ext_name = 'toscaparser/extensions/' + e + '/' + f.strip('.py') - ext_name = ext_name.replace('/', '.') - try: - extinfo = importlib.import_module(ext_name) - version = getattr(extinfo, 'VERSION') - defs_file = extpath + '/' + getattr(extinfo, 'DEFS_FILE') - - # Sections is an optional attribute - sections = getattr(extinfo, 'SECTIONS', ()) - - extensions[version] = {'sections': sections, - 'defs_file': defs_file} - except ImportError: - raise ToscaExtImportError(ext_name=ext_name) - except AttributeError: - attrs = ', '.join(REQUIRED_ATTRIBUTES) - raise ToscaExtAttributeError(ext_name=ext_name, - attrs=attrs) - - return extensions - - def get_versions(self): - return self.EXTENSION_INFO.keys() - - def get_sections(self): - sections = {} - for version in self.EXTENSION_INFO.keys(): - sections[version] = self.EXTENSION_INFO[version]['sections'] - - return sections - - def get_defs_file(self, version): - versiondata = self.EXTENSION_INFO.get(version) - - if versiondata: - return versiondata.get('defs_file') - else: - return None diff --git a/nfvparser/src/main/python/toscaparser/extensions/nfv/TOSCA_nfv_definition_1_0_0.yaml b/nfvparser/src/main/python/toscaparser/extensions/nfv/TOSCA_nfv_definition_1_0_0.yaml deleted file mode 100644 index 365d70e..0000000 --- a/nfvparser/src/main/python/toscaparser/extensions/nfv/TOSCA_nfv_definition_1_0_0.yaml +++ /dev/null @@ -1,240 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -########################################################################## -# The content of this file reflects TOSCA NFV Profile in YAML version -# 1.0.0. It describes the definition for TOSCA NFV types including Node Type, -# Relationship Type, Capability Type and Interfaces. -########################################################################## -tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 - -########################################################################## -# Node Type. -# A Node Type is a reusable entity that defines the type of one or more -# Node Templates. -########################################################################## -node_types: - tosca.nodes.nfv.VNF: - derived_from: tosca.nodes.Root # Or should this be its own top - level type? - properties: - id: - type: string - description: ID of this VNF - vendor: - type: string - description: name of the vendor who generate this VNF - version: - type: version - description: version of the software for this VNF - requirements: - - virtualLink: - capability: tosca.capabilities.nfv.VirtualLinkable - relationship: tosca.relationships.nfv.VirtualLinksTo - node: tosca.nodes.nfv.VL - - tosca.nodes.nfv.VDU: - derived_from: tosca.nodes.Compute - capabilities: - high_availability: - type: tosca.capabilities.nfv.HA - virtualbinding: - type: tosca.capabilities.nfv.VirtualBindable - monitoring_parameter: - type: tosca.capabilities.nfv.Metric - requirements: - - high_availability: - capability: tosca.capabilities.nfv.HA - relationship: tosca.relationships.nfv.HA - node: tosca.nodes.nfv.VDU - occurrences: [ 0, 1 ] - - tosca.nodes.nfv.CP: - derived_from: tosca.nodes.network.Port - properties: - type: - type: string - required: false - requirements: - - virtualLink: - capability: tosca.capabilities.nfv.VirtualLinkable - relationship: tosca.relationships.nfv.VirtualLinksTo - node: tosca.nodes.nfv.VL - - virtualBinding: - capability: tosca.capabilities.nfv.VirtualBindable - relationship: tosca.relationships.nfv.VirtualBindsTo - node: tosca.nodes.nfv.VDU - attributes: - address: - type: string - - tosca.nodes.nfv.VL: - derived_from: tosca.nodes.network.Network - properties: - vendor: - type: string - required: true - description: name of the vendor who generate this VL - capabilities: - virtual_linkable: - type: tosca.capabilities.nfv.VirtualLinkable - - tosca.nodes.nfv.VL.ELine: - derived_from: tosca.nodes.nfv.VL - capabilities: - virtual_linkable: - occurrences: 2 - - tosca.nodes.nfv.VL.ELAN: - derived_from: tosca.nodes.nfv.VL - - tosca.nodes.nfv.VL.ETree: - derived_from: tosca.nodes.nfv.VL - - tosca.nodes.nfv.FP: - derived_from: tosca.nodes.Root - properties: - policy: - type: string - required: false - description: name of the vendor who generate this VL - requirements: - - forwarder: - capability: tosca.capabilities.nfv.Forwarder - relationship: tosca.relationships.nfv.ForwardsTo - -########################################################################## -# Relationship Type. -# A Relationship Type is a reusable entity that defines the type of one -# or more relationships between Node Types or Node Templates. -########################################################################## - -relationship_types: - tosca.relationships.nfv.VirtualLinksTo: - derived_from: tosca.relationships.network.LinksTo - valid_target_types: [ tosca.capabilities.nfv.VirtualLinkable ] - - tosca.relationships.nfv.VirtualBindsTo: - derived_from: tosca.relationships.network.BindsTo - valid_target_types: [ tosca.capabilities.nfv.VirtualBindable ] - - tosca.relationships.nfv.HA: - derived_from: tosca.relationships.Root - valid_target_types: [ tosca.capabilities.nfv.HA ] - - tosca.relationships.nfv.Monitor: - derived_from: tosca.relationships.ConnectsTo - valid_target_types: [ tosca.capabilities.nfv.Metric ] - - tosca.relationships.nfv.ForwardsTo: - derived_from: tosca.relationships.root - valid_target_types: [ tosca.capabilities.nfv.Forwarder] - -########################################################################## -# Capability Type. -# A Capability Type is a reusable entity that describes a kind of -# capability that a Node Type can declare to expose. -########################################################################## - -capability_types: - tosca.capabilities.nfv.VirtualLinkable: - derived_from: tosca.capabilities.network.Linkable - - tosca.capabilities.nfv.VirtualBindable: - derived_from: tosca.capabilities.network.Bindable - - tosca.capabilities.nfv.HA: - derived_from: tosca.capabilities.Root - valid_source_types: [ tosca.nodes.nfv.VDU ] - - tosca.capabilities.nfv.HA.ActiveActive: - derived_from: tosca.capabilities.nfv.HA - - tosca.capabilities.nfv.HA.ActivePassive: - derived_from: tosca.capabilities.nfv.HA - - tosca.capabilities.nfv.Metric: - derived_from: tosca.capabilities.Root - - tosca.capabilities.nfv.Forwarder: - derived_from: tosca.capabilities.Root - -########################################################################## - # Interfaces Type. - # The Interfaces element describes a list of one or more interface - # definitions for a modelable entity (e.g., a Node or Relationship Type) - # as defined within the TOSCA Simple Profile specification. -########################################################################## - -########################################################################## - # Data Type. - # A Datatype is a complex data type declaration which contains other - # complex or simple data types. -########################################################################## - -########################################################################## - # Artifact Type. - # An Artifact Type is a reusable entity that defines the type of one or more - # files which Node Types or Node Templates can have dependent relationships - # and used during operations such as during installation or deployment. -########################################################################## - -########################################################################## - # Policy Type. - # TOSCA Policy Types represent logical grouping of TOSCA nodes that have - # an implied relationship and need to be orchestrated or managed together - # to achieve some result. -########################################################################## - -########################################################################## - # Group Type - # -########################################################################## -group_types: - tosca.groups.nfv.VNFFG: - derived_from: tosca.groups.Root - - properties: - vendor: - type: string - required: true - description: name of the vendor who generate this VNFFG - - version: - type: string - required: true - description: version of this VNFFG - - number_of_endpoints: - type: integer - required: true - description: count of the external endpoints included in this VNFFG - - dependent_virtual_link: - type: list - entry_schema: - type: string - required: true - description: Reference to a VLD used in this Forwarding Graph - - connection_point: - type: list - entry_schema: - type: string - required: true - description: Reference to Connection Points forming the VNFFG - - constituent_vnfs: - type: list - entry_schema: - type: string - required: true - description: Reference to a list of VNFD used in this VNF Forwarding Graph diff --git a/nfvparser/src/main/python/toscaparser/extensions/nfv/__init__.py b/nfvparser/src/main/python/toscaparser/extensions/nfv/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/__init__.py b/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/data/tosca_helloworld_nfv.yaml b/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/data/tosca_helloworld_nfv.yaml deleted file mode 100644 index 6afa9f0..0000000 --- a/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/data/tosca_helloworld_nfv.yaml +++ /dev/null @@ -1,31 +0,0 @@ -tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 - -description: Template for deploying a single server with predefined properties. - -metadata: - template_name: TOSCA NFV Sample Template - -topology_template: - node_templates: - VNF1: - type: tosca.nodes.nfv.VNF - properties: - id: vnf1 - vendor: acmetelco - version: 1.0 - - VDU1: - type: tosca.nodes.nfv.VDU - - CP1: - type: tosca.nodes.nfv.CP - properties: - type: vPort - requirements: - - virtualLink: PrivateNetwork - - virtualBinding: VDU1 - - PrivateNetwork: - type: tosca.nodes.nfv.VL - properties: - vendor: ACME Networks diff --git a/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/rnc_definition.yaml b/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/rnc_definition.yaml deleted file mode 100644 index 52fbd4c..0000000 --- a/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/rnc_definition.yaml +++ /dev/null @@ -1,173 +0,0 @@ -## Licensed under the Apache License, Version 2.0 (the "License"); you may -## not use this file 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. - -tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 - -#metadata: -# template_name: tosca_simple_profile_for_nfv_vRNC -# template_author: opnfv_parser_project -# template_version: tosca_simple_profile_for_nfv_1_0 - -# Optional description of the definitions inside the file. -description: > - NFV TOSCA simple profile for RNC types - 1. Compute Node MM, CM, DM, LB... - 1.1 MM: MaintainModule; - 1.2 CM: Control Module; - 1.3 DM: Data Module; - 1.4 LB: LineCard Module. - 2. Network Node VL and CP - -# The import section shall be ignored if the value of tosca_definitions_version -# is tosca_simple_profile_for_nfv_1_0_0, otherwise will be needed. - -# list of node type definitions -node_types: - rnc.nodes.VNF: - derived_from: tosca.nodes.nfv.VNF - properties: - vnftype: - type: string - description: type of the RNC - default: UMTS - required: false - constraints: - - valid_values: [ TDS-CDMA, UMTS, CDMA ] - attributes: - private_ip_of_MM: - type: string - description: IP of master MM - private_ip_of_CM: - type: string - description: IP of master CM - private_ip_of_DM: - type: string - description: IP of master DM - private_ip_of_LB: - type: string - description: IP of master LB - requirements: - - virtualLink_VNFM: - capability: tosca.capabilities.nfv.VirtualLinkable - relationship: tosca.relationships.nfv.VirtualLinksTo - node: rnc.nodes.VL - - virtualLink_EMS: - capability: tosca.capabilities.nfv.VirtualLinkable - relationship: tosca.relationships.nfv.VirtualLinksTo - node: rnc.nodes.VL - - virtualLink_TRAFFIC: - capability: tosca.capabilities.nfv.VirtualLinkable - relationship: tosca.relationships.nfv.VirtualLinksTo - node: rnc.nodes.VL - - rnc.nodes.compute.MM: - derived_from: tosca.nodes.nfv.VDU - properties: - activestatus: - type: integer - required: false - description: 1 for active or 0 for passive - constraints: - - valid_values: [ 0, 1 ] - id: - type: string - defaule: MM - required: false - description: > - A identifier of this VDU within the scope of the VNFD, - including version functional description and other - identification information. - - rnc.nodes.compute.CM: - derived_from: tosca.nodes.nfv.VDU - properties: - activestatus: - type: integer - required: false - description: 1 for active or 0 for passive - constraints: - - valid_values: [ 0, 1 ] - - rnc.nodes.compute.DM: - derived_from: tosca.nodes.nfv.VDU - - rnc.nodes.compute.LB: - derived_from: tosca.nodes.nfv.VDU - - rnc.nodes.BlockStorage: - derived_from: tosca.nodes.BlockStorage - - rnc.nodes.VL: - derived_from: tosca.nodes.nfv.VL - - rnc.nodes.CP: - derived_from: tosca.nodes.nfv.CP - - rnc.nodes.CP.MM: - derived_from: tosca.nodes.nfv.CP - # It's ok here because of the weakly validation. - - rnc.nodes.CP.CM: - derived_from: tosca.nodes.nfv.CP - requirements: - - virtualLink: - capability: tosca.capabilities.nfv.VirtualLinkable - relationship: tosca.relationships.nfv.VirtualLinksTo - node: rnc.nodes.VL - - virtualBinding: - capability: tosca.capabilities.nfv.VirtualBindable - relationship: tosca.relationships.nfv.VirtualBindsTo - node: rnc.nodes.compute.CM - - rnc.nodes.CP.DM: - derived_from: tosca.nodes.nfv.CP - requirements: - - virtualLink: - capability: tosca.capabilities.nfv.VirtualLinkable - relationship: tosca.relationships.nfv.VirtualLinksTo - node: rnc.nodes.VL - - virtualBinding: - capability: tosca.capabilities.nfv.VirtualBindable - relationship: tosca.relationships.nfv.VirtualBindsTo - node: rnc.nodes.compute.DM - - rnc.nodes.CP.LB: - derived_from: tosca.nodes.nfv.CP - requirements: - - virtualLink: - capability: tosca.capabilities.nfv.VirtualLinkable - relationship: tosca.relationships.nfv.VirtualLinksTo - node: rnc.nodes.VL - - virtualBinding: - capability: tosca.capabilities.nfv.VirtualBindable - relationship: tosca.relationships.nfv.VirtualBindsTo - node: rnc.nodes.compute.LB - -# list of capability type definitions -capability_types: - rnc.capabilities.Container: - derived_from: tosca.capabilities.Container - properties: - swap: - type: scalar-unit.size - description: swap info - required: false - default: 0 - constraints: - - greater_or_equal: 0 MB - iops: - type: integer - description: IOPS for disk - required: false - default: 0 - constraints: - - greater_than: 0 diff --git a/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/vRNC.yaml b/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/vRNC.yaml deleted file mode 100644 index 4441372..0000000 --- a/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/vRNC.yaml +++ /dev/null @@ -1,552 +0,0 @@ -## Licensed under the Apache License, Version 2.0 (the "License"); you may -## not use this file 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. - -tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 - -metadata: - template_name: tosca_simple_profile_for_nfv_vRNC - template_author: opnfv_parser_project - template_version: tosca_simple_profile_for_nfv_1_0 - -# Optional description of the definitions inside the file. -description: > - TOSCA simple profile for RNC - 1. Compute Node MM, CM, DM, LB... - 1.1 MM: MaintainModule; - 1.2 CM: Control Module; - 1.3 DM: Data Module; - 1.4 LB: LineCard Module - 2. Network Node VL and CP - -imports: - - rnc_definition.yaml - -# list of YAML alias anchors (or macros) -dsl_definitions: - compute_props_os_DEF: &compute_props_os_DEF - architecture: x86_64 - type: Linux - distribution: Cirros - version: 0.3.2 - - compute_props_host_MM: &compute_props_host_MM - disk_size: 1 GB - num_cpus: 1 - mem_size: 512 MB - - compute_props_host_CM: &compute_props_host_CM - disk_size: 0 GB - num_cpus: 1 - mem_size: 512 MB - - compute_props_host_DM: &compute_props_host_DM - disk_size: 0 GB - num_cpus: 1 - mem_size: 512 MB - - compute_props_host_LB: &compute_props_host_LB - disk_size: 0 GB - num_cpus: 1 - mem_size: 512 MB - -# topology template definition of the cloud application or service -topology_template: - # a description of the topology template - description: > - simple RNC template - - inputs: - mm_storage_size: - type: integer - default: 1 - description: mm additional block storage size - constraints: - - in_range: [ 1, 200 ] - id: - type: string - description: ID of this VNF - default: UMTS - vendor: - type: string - description: name of the vendor who generate this VNF - default: opnfv_parser_project - version: - type: version - description: version of the software for this VNF - default: 1.0 - - substitution_mappings: - node_type: rnc.nodes.VNF - requirements: - virtualLink_VNFM: [ MM_Port_CTRL, virtualLink ] - virtualLink_EMS: [ MM_Port_EMS, virtualLink ] - virtualLink_TRAFFIC: [ LB_Port_EXTERMEDIA, virtualLink ] - - # definition of the node templates of the topology - node_templates: - MM_Active: - type: tosca.nodes.SoftwareComponent - properties: - component_version: 1.0 - requirements: - - host: MM_Active_Host - interfaces: - Standard: - create: - implementation: ./Scripts/MM/mm_install.sh - configure: - implementation: ./Scripts/MM/mm_active_configure.sh - - MM_Active_Host: - type: rnc.nodes.compute.MM - capabilities: - os: - properties: *compute_props_os_DEF - host: - properties: *compute_props_host_MM - requirements: - - local_storage: - node: MM_BlockStorage - relationship: Storage_attachesto - artifacts: - #the VM image of MM - vm_image: mm.image - - MM_Passive: - type: tosca.nodes.SoftwareComponent - properties: - component_version: 1.0 - requirements: - - host: MM_Passive_Host - interfaces: - Standard: - create: - implementation: ./Scripts/MM/mm_install.sh - configure: - implementation: ./Scripts/MM/mm_passvie_configure.sh - - MM_Passive_Host: - type: rnc.nodes.compute.MM - capabilities: - os: - properties: *compute_props_os_DEF - host: - properties: *compute_props_host_MM - requirements: - - local_storage: - node: MM_BlockStorage - relationship: Storage_attachesto - - high_availability: MM_Active_Host - artifacts: - #the VM image of MM - vm_image: mm.image - - MM_BlockStorage: - type: rnc.nodes.BlockStorage - properties: - size: { get_input: mm_storage_size } - interfaces: - Configure: - post_configure_target: - implementation: ./Scripts/MM/storage_script.sh - - CM_Active: - type: tosca.nodes.SoftwareComponent - properties: - component_version: 1.0 - requirements: - - host: CM_Active_Host - interfaces: - Standard: - create: - implementation: ./Scripts/CM/cm_install.sh - configure: - implementation: ./Scripts/CM/cm_active_configure.sh - - CM_Active_Host: - type: rnc.nodes.compute.CM - capabilities: - os: - properties: *compute_props_os_DEF - host: - properties: *compute_props_host_CM - scalable: - properties: - min_instances: 1 - max_instances: 12 - default_instances: 1 - artifacts: - #the VM image of CM - vm_image: cm.image - - CM_Passive: - type: tosca.nodes.SoftwareComponent - properties: - component_version: 1.0 - requirements: - - host: CM_Passive_Host - interfaces: - Standard: - create: - implementation: ./Scripts/CM/cm_install.sh - configure: - implementation: ./Scripts/CM/cm_passvie_configure.sh - - CM_Passive_Host: - type: rnc.nodes.compute.CM - capabilities: - os: - properties: *compute_props_os_DEF - host: - properties: *compute_props_host_CM - scalable: - properties: - min_instances: 1 - max_instances: 12 - default_instances: 1 - requirements: - - high_availability: CM_Active_Host - artifacts: - #the VM image of CM - vm_image: mm.image - - DM: - type: tosca.nodes.SoftwareComponent - properties: - component_version: 1.0 - requirements: - - host: DM_Host - interfaces: - Standard: - create: - implementation: ./Scripts/DM/dm_install.sh - configure: - implementation: ./Scripts/DM/dm_configure.sh - - DM_Host: - type: rnc.nodes.compute.DM - capabilities: - os: - properties: *compute_props_os_DEF - host: - properties: *compute_props_host_DM - scalable: - properties: - min_instances: 1 - max_instances: 12 - default_instances: 1 - artifacts: - vm_image: dm.image - - LB: - type: tosca.nodes.SoftwareComponent - properties: - component_version: 1.0 - requirements: - - host: LB_Host - interfaces: - Standard: - create: - implementation: ./Scripts/LB/lb_install.sh - configure: - implementation: ./Scripts/LB/lb_configure.sh - - LB_Host: - type: rnc.nodes.compute.LB - capabilities: - os: - properties: *compute_props_os_DEF - host: - properties: *compute_props_host_LB - scalable: - properties: - min_instances: 1 - max_instances: 2 - default_instances: 1 - artifacts: - #the VM image of LB - vm_image: lb.image - - CTRL_Net: - type: rnc.nodes.VL - properties: - vendor: ZTE - cidr: "128.0.0.0/8" - network_name: Ctrl_Net - network_type: vlan - segmentation_id: 110 - dhcp_enabled: false - - INTERMEDIA_Net: - type: rnc.nodes.VL - properties: - vendor: ZTE - cidr: 10.0.0.0/8 - start_ip: 10.1.0.1 - end_ip: 10.1.2.254 - network_name: InterMedia_Net - network_type: vlan - segmentation_id: 111 - dhcp_enabled: false - - EXTERMEDIA_Net: - type: rnc.nodes.VL - properties: - vendor: ZTE - cidr: 172.1.0.0/16 - start_ip: 172.1.0.2 - end_ip: 172.1.2.254 - gateway_ip: 172.1.0.1 - network_name: ExterMdedia_Net - network_type: vlan - segmentation_id: 100 - dhcp_enabled: false - - EMS_Net: - type: rnc.nodes.VL - properties: - vendor: ZTE - cidr: 129.0.0.0/24 - start_ip: 129.0.0.2 - end_ip: 129.0.0.64 - gateway_ip: 129.0.0.1 - network_name: Ems_Net - network_type: vlan - segmentation_id: 101 - dhcp_enabled: false - - MM_Active_Port_EMS: - type: rnc.nodes.CP.MM - properties: - order: 0 - is_default: true - requirements: - - virtualBinding: MM_Active_Host - - virtualLink: EMS_Net - - MM_Active_Port_EXTERMEDIA: - type: rnc.nodes.CP.MM - properties: - order: 1 - is_default: true - requirements: - - virtualBinding: MM_Active_Host - - virtualLink: EMS_Net - - MM_Active_Port_CTRL: - type: rnc.nodes.CP.MM - properties: - order: 2 - is_default: false - requirements: - - virtualBinding: MM_Active_Host - - virtualLink: CTRL_Net - - MM_Active_Port_INTERMEDIA: - type: rnc.nodes.CP.MM - properties: - order: 3 - is_default: false - requirements: - - virtualBinding: MM_Active_Host - - virtualLink: EXTERMEDIA_Net - - MM_Passive_Port_EMS: - type: rnc.nodes.CP.MM - properties: - order: 0 - is_default: true - requirements: - - virtualBinding: MM_Passive_Host - - virtualLink: EMS_Net - - MM_Passive_Port_EXTERMEDIA: - type: rnc.nodes.CP.MM - properties: - order: 1 - is_default: true - requirements: - - virtualBinding: MM_Passive_Host - - virtualLink: EXTERMEDIA_Net - - MM_Passive_Port_CTRL: - type: rnc.nodes.CP.MM - properties: - order: 2 - is_default: false - requirements: - - virtualBinding: MM_Passive_Host - - virtualLink: CTRL_Net - - MM_Passive_Port_INTERMEDIA: - type: rnc.nodes.CP.MM - properties: - order: 3 - is_default: false - requirements: - - virtualBinding: MM_Passive_Host - - virtualLink: INTERMEDIA_Net - - CM_Active_Port_CTRL: - type: rnc.nodes.CP.CM - properties: - order: 0 - is_default: true - requirements: - - virtualBinding: CM_Active_Host - - virtualLink: CTRL_Net - - CM_Active_Port_INTERMEDIA: - type: rnc.nodes.CP.CM - properties: - order: 1 - is_default: false - requirements: - - virtualBinding: CM_Active_Host - - virtualLink: INTERMEDIA_Net - - CM_Passive_Port_CTRL: - type: rnc.nodes.CP.CM - properties: - order: 0 - is_default: true - requirements: - - virtualBinding: CM_Passive_Host - - virtualLink: CTRL_Net - - CM_Passive_Port_INTERMEDIA: - type: rnc.nodes.CP.CM - properties: - order: 1 - is_default: false - requirements: - - virtualBinding: CM_Passive_Host - - virtualLink: INTERMEDIA_Net - - DM_Port_CTRL: - type: rnc.nodes.CP.DM - properties: - order: 0 - is_default: true - requirements: - - virtualBinding: DM_Host - - virtualLink: CTRL_Net - - DM_Port_INTERMEDIA: - type: rnc.nodes.CP.DM - properties: - order: 1 - is_default: false - requirements: - - virtualBinding: DM_Host - - virtualLink: INTERMEDIA_Net - - LB_Port_CTRL: - type: rnc.nodes.CP.LB - properties: - order: 0 - is_default: true - requirements: - - virtualBinding: LB_Host - - virtualLink: CTRL_Net - - LB_Port_INTERMEDIA: - type: rnc.nodes.CP.LB - properties: - order: 1 - is_default: false - requirements: - - virtualBinding: LB_Host - - virtualLink: INTERMEDIA_Net - - LB_Port_EXTERMEDIA: - type: rnc.nodes.CP.LB - properties: - order: 2 - is_default: false - requirements: - - virtualBinding: LB_Host - - virtualLink: EXTERMEDIA_Net - - # definition of the relationship templates of the topology - relationship_templates: - Storage_attachesto: - type: tosca.relationships.AttachesTo - properties: - location: /data_location - - # definition of output parameters for the topology template - outputs: - private_ip_of_MM: - description: The Inner(CtrPlane) IP address of the MM. - value: { get_attribute: [ MM_Active_Host, private_address ] } - - private_ip_of_CM: - description: The Inner(CtrPlane) IP address of the CM. - value: { get_attribute: [ CM_Active_Host, private_address ] } - - private_ip_of_DM: - description: The Inner(CtrPlane) IP address of the DM. - value: { get_attribute: [ DM_Host, private_address ] } - - private_ip_of_LB: - description: The Inner(CtrPlane) IP address of the LB. - value: { get_attribute: [ LB_Host, private_address ] } - - # definition of logical groups of node templates within the topology - # To be continue about this section - groups: - AntiAffinityServerGroup: - type: tosca.groups.Root - description: > - Logical component grouping for anti affinity placement, - MM_Acitve, MM_Passive, CM_Acitve, CM_Passive, LB must host - on different host to reduce the impact to each other. - members: [ MM_Active, MM_Passive, CM_Active, CM_Passive, LB ] - - AffinityServerGroup: - type: tosca.groups.Root - description: > - Logical component grouping for affinity placement, - CM and DM will be host on the same host to get high performence - members: [ CM_Active, DM ] - - policies: - - AntiAffinityPolicy: - # type: tosca.policies.Placement - type: tosca.policies.Placement.Antilocate - # Current only placement in openstack community - description: Apply anti-locate placement policy to group - targets: [ AntiAffinityServerGroup ] - - - AffinityPolicy: - #type: tosca.policies.Placement - type: tosca.policies.Placement.Colocate - # Current only placement in openstack community - description: Apply anti-locate placement policy to group - targets: [ AffinityServerGroup ] - - # ServerGroupScaling_DM: # added future - # members: [ DM, ]# only one, will be error - # policies: - # - name: MyScaleUpPolicy - # - type: tosca.policy.scale.up | tosca.policy.scale.down - # - rule: fn.utilizaton [ DM ], greater_than: 80 - # - trigger: script_dm - - # ServerGroupScaling_LB: # added future - # members: [ LB, ] # only one, will be error - # policies: - # - name: MyScaleUpPolicy - # - type: tosca.policy.scale.up | tosca.policy.scale.down - # - rule: fn.utilizaton [ LB ], greater_than: 80 - # - trigger: script_lb diff --git a/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/data/vRNC/README.txt b/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/data/vRNC/README.txt deleted file mode 100644 index 9ea77a4..0000000 --- a/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/data/vRNC/README.txt +++ /dev/null @@ -1,22 +0,0 @@ -README: - -This CSAR contains all definitions that are required for deploying a simple -vRNC(virtual Radio Network Controller) on a cloud. - -Entry information for processing through an orchestrator is contained in file -TOSCA-Metadata/TOSCA.meta. This file provides high-level information such as -CSAR version or creator of the CSAR. Furthermore, it provides pointers to the -various TOSCA definitions files that contain the real details. -The entry 'Entry-Definitions' points to the definitions file which holds the -service template for the workload. -'Entry-Definitions' is optional. An orchestrator can also process the contents -like this: -1) Read in and process each definitions file. -2) For each definitions file: - 2.1) Read in all * type definitions (node types, capability types, etc.) and - store them in an internal map -3) Verify and build dependencies (e.g. inheritance) between all type definitions - previously read in. Orchestrator built-in types (e.g. TOSCA base types) are - also considered in this step. -4) Process the actual service template (the file with a node_templates section). - Validate using previously obtained type information. \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/data/vRNC/TOSCA-Metadata/TOSCA.meta b/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/data/vRNC/TOSCA-Metadata/TOSCA.meta deleted file mode 100644 index 45f9ab2..0000000 --- a/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/data/vRNC/TOSCA-Metadata/TOSCA.meta +++ /dev/null @@ -1,4 +0,0 @@ -TOSCA-Meta-File-Version: 1.0 -CSAR-Version: 1.1 -Created-By: shang.xiaodog@zte.com.cn -Entry-Definitions: Definitions/vRNC.yaml \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/test_tosca_nfv_tpl.py b/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/test_tosca_nfv_tpl.py deleted file mode 100644 index b166d83..0000000 --- a/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/test_tosca_nfv_tpl.py +++ /dev/null @@ -1,29 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import os - -from toscaparser.tests.base import TestCase -from toscaparser.tosca_template import ToscaTemplate - - -class ToscaNFVTemplateTest(TestCase): - - '''TOSCA NFV template.''' - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/tosca_helloworld_nfv.yaml") - tosca = ToscaTemplate(tosca_tpl) - - def test_version(self): - self.assertEqual(self.tosca.version, - "tosca_simple_profile_for_nfv_1_0_0") diff --git a/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/test_tosca_vRNC.py b/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/test_tosca_vRNC.py deleted file mode 100644 index a0ffc21..0000000 --- a/nfvparser/src/main/python/toscaparser/extensions/nfv/tests/test_tosca_vRNC.py +++ /dev/null @@ -1,62 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import os - -from toscaparser.tests.base import TestCase -from toscaparser.tosca_template import ToscaTemplate - - -class ToscaVRNCTemplateTest(TestCase): - - '''NFV TOSCA vRNC template.''' - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/vRNC/Definitions/vRNC.yaml") - tosca = ToscaTemplate(tosca_tpl) - - def test_version(self): - self.assertEqual(self.tosca.version, - "tosca_simple_profile_for_nfv_1_0_0") - - def test_input(self): - input_names = sorted(["mm_storage_size", "id", - "vendor", "version"]) - self.assertEqual(sorted([i.name for i in self.tosca.inputs]), - input_names) - - def test_nodetemplates(self): - expected_node_list = sorted( - ["MM_Active", "MM_Passive", "MM_BlockStorage", - "MM_Active_Host", "MM_Passive_Host", - "CM_Active", "CM_Passive", "DM", "LB", - "CM_Active_Host", "CM_Passive_Host", "DM_Host", "LB_Host", - "EXTERMEDIA_Net", "INTERMEDIA_Net", "EMS_Net", "CTRL_Net", - "MM_Active_Port_EMS", "MM_Active_Port_CTRL", - "MM_Active_Port_EXTERMEDIA", "MM_Active_Port_INTERMEDIA", - "MM_Passive_Port_EMS", "MM_Passive_Port_CTRL", - "MM_Passive_Port_EXTERMEDIA", "MM_Passive_Port_INTERMEDIA", - "CM_Active_Port_CTRL", "CM_Active_Port_INTERMEDIA", - "CM_Passive_Port_CTRL", "CM_Passive_Port_INTERMEDIA", - "DM_Port_CTRL", "DM_Port_INTERMEDIA", - "LB_Port_INTERMEDIA", "LB_Port_EXTERMEDIA", "LB_Port_CTRL"]) - - node_list = sorted([node.name for node in self.tosca.nodetemplates]) - self.assertEqual(node_list, expected_node_list) - - def test_output(self): - expected_output_name = sorted( - ["private_ip_of_CM", "private_ip_of_DM", - "private_ip_of_LB", "private_ip_of_MM"]) - - output_list = sorted([output.name for output in self.tosca.outputs]) - self.assertEqual(output_list, expected_output_name) diff --git a/nfvparser/src/main/python/toscaparser/extensions/nfv/tosca_simple_profile_for_nfv_1_0_0.py b/nfvparser/src/main/python/toscaparser/extensions/nfv/tosca_simple_profile_for_nfv_1_0_0.py deleted file mode 100644 index 24eabab..0000000 --- a/nfvparser/src/main/python/toscaparser/extensions/nfv/tosca_simple_profile_for_nfv_1_0_0.py +++ /dev/null @@ -1,19 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -# VERSION and DEFS_FILE are required for all extensions - -VERSION = 'tosca_simple_profile_for_nfv_1_0_0' - -DEFS_FILE = "TOSCA_nfv_definition_1_0_0.yaml" - -SECTIONS = ('metadata') diff --git a/nfvparser/src/main/python/toscaparser/functions.py b/nfvparser/src/main/python/toscaparser/functions.py deleted file mode 100644 index d498229..0000000 --- a/nfvparser/src/main/python/toscaparser/functions.py +++ /dev/null @@ -1,826 +0,0 @@ -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - - -import abc -import six -import toscaparser.elements.interfaces - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import UnknownInputError -from toscaparser.dataentity import DataEntity -from toscaparser.elements.constraints import Schema -from toscaparser.elements.datatype import DataType -from toscaparser.elements.entity_type import EntityType -from toscaparser.elements.relationshiptype import RelationshipType -from toscaparser.elements.statefulentitytype import StatefulEntityType -from toscaparser.utils.gettextutils import _ - - -GET_PROPERTY = 'get_property' -GET_ATTRIBUTE = 'get_attribute' -GET_INPUT = 'get_input' -GET_OPERATION_OUTPUT = 'get_operation_output' -CONCAT = 'concat' -TOKEN = 'token' - -SELF = 'SELF' -HOST = 'HOST' -TARGET = 'TARGET' -SOURCE = 'SOURCE' - -HOSTED_ON = 'tosca.relationships.HostedOn' - - -@six.add_metaclass(abc.ABCMeta) -class Function(object): - """An abstract type for representing a Tosca template function.""" - - def __init__(self, tosca_tpl, context, name, args): - self.tosca_tpl = tosca_tpl - self.context = context - self.name = name - self.args = args - self.validate() - - @abc.abstractmethod - def result(self): - """Invokes the function and returns its result - - Some methods invocation may only be relevant on runtime (for example, - getting runtime properties) and therefore its the responsibility of - the orchestrator/translator to take care of such functions invocation. - - :return: Function invocation result. - """ - return {self.name: self.args} - - @abc.abstractmethod - def validate(self): - """Validates function arguments.""" - pass - - -class GetInput(Function): - """Get a property value declared within the input of the service template. - - Arguments: - - * Input name. - - Example: - - * get_input: port - """ - - def validate(self): - if len(self.args) != 1: - ExceptionCollector.appendException( - ValueError(_( - 'Expected one argument for function "get_input" but ' - 'received "%s".') % self.args)) - inputs = [input.name for input in self.tosca_tpl.inputs] - if self.args[0] not in inputs: - ExceptionCollector.appendException( - UnknownInputError(input_name=self.args[0])) - - def result(self): - if self.tosca_tpl.parsed_params and \ - self.input_name in self.tosca_tpl.parsed_params: - return DataEntity.validate_datatype( - self.tosca_tpl.tpl['inputs'][self.input_name]['type'], - self.tosca_tpl.parsed_params[self.input_name]) - - input = [input_def for input_def in self.tosca_tpl.inputs - if self.input_name == input_def.name][0] - return input.default - - @property - def input_name(self): - return self.args[0] - - -class GetAttribute(Function): - """Get an attribute value of an entity defined in the service template - - Node template attributes values are set in runtime and therefore its the - responsibility of the Tosca engine to implement the evaluation of - get_attribute functions. - - Arguments: - - * Node template name | HOST. - * Attribute name. - - If the HOST keyword is passed as the node template name argument the - function will search each node template along the HostedOn relationship - chain until a node which contains the attribute is found. - - Examples: - - * { get_attribute: [ server, private_address ] } - * { get_attribute: [ HOST, private_address ] } - * { get_attribute: [ HOST, private_address, 0 ] } - * { get_attribute: [ HOST, private_address, 0, some_prop] } - """ - - def validate(self): - if len(self.args) < 2: - ExceptionCollector.appendException( - ValueError(_('Illegal arguments for function "{0}". Expected ' - 'arguments: "node-template-name", "req-or-cap"' - '(optional), "property name"' - ).format(GET_ATTRIBUTE))) - return - elif len(self.args) == 2: - self._find_node_template_containing_attribute() - else: - node_tpl = self._find_node_template(self.args[0]) - if node_tpl is None: - return - index = 2 - attrs = node_tpl.type_definition.get_attributes_def() - found = [attrs[self.args[1]]] if self.args[1] in attrs else [] - if found: - attr = found[0] - else: - index = 3 - # then check the req or caps - attr = self._find_req_or_cap_attribute(self.args[1], - self.args[2]) - - value_type = attr.schema['type'] - if len(self.args) > index: - for elem in self.args[index:]: - if value_type == "list": - if not isinstance(elem, int): - ExceptionCollector.appendException( - ValueError(_('Illegal arguments for function' - ' "{0}". "{1}" Expected positive' - ' integer argument' - ).format(GET_ATTRIBUTE, elem))) - value_type = attr.schema['entry_schema']['type'] - elif value_type == "map": - value_type = attr.schema['entry_schema']['type'] - elif value_type in Schema.PROPERTY_TYPES: - ExceptionCollector.appendException( - ValueError(_('Illegal arguments for function' - ' "{0}". Unexpected attribute/' - 'index value "{1}"' - ).format(GET_ATTRIBUTE, elem))) - return - else: # It is a complex type - data_type = DataType(value_type) - props = data_type.get_all_properties() - found = [props[elem]] if elem in props else [] - if found: - prop = found[0] - value_type = prop.schema['type'] - else: - ExceptionCollector.appendException( - KeyError(_('Illegal arguments for function' - ' "{0}". Attribute name "{1}" not' - ' found in "{2}"' - ).format(GET_ATTRIBUTE, - elem, - value_type))) - - def result(self): - return self - - def get_referenced_node_template(self): - """Gets the NodeTemplate instance the get_attribute function refers to. - - If HOST keyword was used as the node template argument, the node - template which contains the attribute along the HostedOn relationship - chain will be returned. - """ - return self._find_node_template_containing_attribute() - - # Attributes can be explicitly created as part of the type definition - # or a property name can be implicitly used as an attribute name - def _find_node_template_containing_attribute(self): - node_tpl = self._find_node_template(self.args[0]) - if node_tpl and \ - not self._attribute_exists_in_type(node_tpl.type_definition) \ - and self.attribute_name not in node_tpl.get_properties(): - ExceptionCollector.appendException( - KeyError(_('Attribute "%(att)s" was not found in node ' - 'template "%(ntpl)s".') % - {'att': self.attribute_name, - 'ntpl': node_tpl.name})) - return node_tpl - - def _attribute_exists_in_type(self, type_definition): - attrs_def = type_definition.get_attributes_def() - found = [attrs_def[self.attribute_name]] \ - if self.attribute_name in attrs_def else [] - return len(found) == 1 - - def _find_host_containing_attribute(self, node_template_name=SELF): - node_template = self._find_node_template(node_template_name) - if node_template: - hosted_on_rel = EntityType.TOSCA_DEF[HOSTED_ON] - for r in node_template.requirements: - for requirement, target_name in r.items(): - target_node = self._find_node_template(target_name) - target_type = target_node.type_definition - for capability in target_type.get_capabilities_objects(): - if capability.type in \ - hosted_on_rel['valid_target_types']: - if self._attribute_exists_in_type(target_type): - return target_node - return self._find_host_containing_attribute( - target_name) - - def _find_node_template(self, node_template_name): - if node_template_name == HOST: - # Currently this is the only way to tell whether the function - # is used within the outputs section of the TOSCA template. - if isinstance(self.context, list): - ExceptionCollector.appendException( - ValueError(_( - '"get_attribute: [ HOST, ... ]" is not allowed in ' - '"outputs" section of the TOSCA template.'))) - return - node_tpl = self._find_host_containing_attribute() - if not node_tpl: - ExceptionCollector.appendException( - ValueError(_( - '"get_attribute: [ HOST, ... ]" was used in node ' - 'template "{0}" but "{1}" was not found in ' - 'the relationship chain.').format(self.context.name, - HOSTED_ON))) - return - return node_tpl - if node_template_name == TARGET: - if not isinstance(self.context.type_definition, RelationshipType): - ExceptionCollector.appendException( - KeyError(_('"TARGET" keyword can only be used in context' - ' to "Relationships" target node'))) - return - return self.context.target - if node_template_name == SOURCE: - if not isinstance(self.context.type_definition, RelationshipType): - ExceptionCollector.appendException( - KeyError(_('"SOURCE" keyword can only be used in context' - ' to "Relationships" source node'))) - return - return self.context.source - name = self.context.name \ - if node_template_name == SELF and \ - not isinstance(self.context, list) \ - else node_template_name - for node_template in self.tosca_tpl.nodetemplates: - if node_template.name == name: - return node_template - ExceptionCollector.appendException( - KeyError(_( - 'Node template "{0}" was not found.' - ).format(node_template_name))) - - def _find_req_or_cap_attribute(self, req_or_cap, attr_name): - node_tpl = self._find_node_template(self.args[0]) - # Find attribute in node template's requirements - for r in node_tpl.requirements: - for req, node_name in r.items(): - if req == req_or_cap: - node_template = self._find_node_template(node_name) - return self._get_capability_attribute( - node_template, - req, - attr_name) - # If requirement was not found, look in node template's capabilities - return self._get_capability_attribute(node_tpl, - req_or_cap, - attr_name) - - def _get_capability_attribute(self, - node_template, - capability_name, - attr_name): - """Gets a node template capability attribute.""" - caps = node_template.get_capabilities() - if caps and capability_name in caps.keys(): - cap = caps[capability_name] - attribute = None - attrs = cap.definition.get_attributes_def() - if attrs and attr_name in attrs.keys(): - attribute = attrs[attr_name] - if not attribute: - ExceptionCollector.appendException( - KeyError(_('Attribute "%(attr)s" was not found in ' - 'capability "%(cap)s" of node template ' - '"%(ntpl1)s" referenced from node template ' - '"%(ntpl2)s".') % {'attr': attr_name, - 'cap': capability_name, - 'ntpl1': node_template.name, - 'ntpl2': self.context.name})) - return attribute - msg = _('Requirement/Capability "{0}" referenced from node template ' - '"{1}" was not found in node template "{2}".').format( - capability_name, - self.context.name, - node_template.name) - ExceptionCollector.appendException(KeyError(msg)) - - @property - def node_template_name(self): - return self.args[0] - - @property - def attribute_name(self): - return self.args[1] - - -class GetProperty(Function): - """Get a property value of an entity defined in the same service template. - - Arguments: - - * Node template name | SELF | HOST | SOURCE | TARGET. - * Requirement or capability name (optional). - * Property name. - - If requirement or capability name is specified, the behavior is as follows: - The req or cap name is first looked up in the specified node template's - requirements. - If found, it would search for a matching capability - of an other node template and get its property as specified in function - arguments. - Otherwise, the req or cap name would be looked up in the specified - node template's capabilities and if found, it would return the property of - the capability as specified in function arguments. - - Examples: - - * { get_property: [ mysql_server, port ] } - * { get_property: [ SELF, db_port ] } - * { get_property: [ SELF, database_endpoint, port ] } - * { get_property: [ SELF, database_endpoint, port, 1 ] } - """ - - def validate(self): - if len(self.args) < 2: - ExceptionCollector.appendException( - ValueError(_( - 'Expected arguments: "node-template-name", "req-or-cap" ' - '(optional), "property name".'))) - return - if len(self.args) == 2: - found_prop = self._find_property(self.args[1]) - if not found_prop: - return - prop = found_prop.value - if not isinstance(prop, Function): - get_function(self.tosca_tpl, self.context, prop) - elif len(self.args) >= 3: - # do not use _find_property to avoid raise KeyError - # if the prop is not found - # First check if there is property with this name - node_tpl = self._find_node_template(self.args[0]) - props = node_tpl.get_properties() if node_tpl else [] - index = 2 - found = [props[self.args[1]]] if self.args[1] in props else [] - if found: - property_value = found[0].value - else: - index = 3 - # then check the req or caps - property_value = self._find_req_or_cap_property(self.args[1], - self.args[2]) - if len(self.args) > index: - for elem in self.args[index:]: - if isinstance(property_value, list): - int_elem = int(elem) - property_value = self._get_index_value(property_value, - int_elem) - else: - property_value = self._get_attribute_value( - property_value, - elem) - - def _find_req_or_cap_property(self, req_or_cap, property_name): - node_tpl = self._find_node_template(self.args[0]) - # Find property in node template's requirements - for r in node_tpl.requirements: - for req, node_name in r.items(): - if req == req_or_cap: - node_template = self._find_node_template(node_name) - return self._get_capability_property( - node_template, - req, - property_name) - # If requirement was not found, look in node template's capabilities - return self._get_capability_property(node_tpl, - req_or_cap, - property_name) - - def _get_capability_property(self, - node_template, - capability_name, - property_name): - """Gets a node template capability property.""" - caps = node_template.get_capabilities() - if caps and capability_name in caps.keys(): - cap = caps[capability_name] - property = None - props = cap.get_properties() - if props and property_name in props.keys(): - property = props[property_name].value - if not property: - ExceptionCollector.appendException( - KeyError(_('Property "%(prop)s" was not found in ' - 'capability "%(cap)s" of node template ' - '"%(ntpl1)s" referenced from node template ' - '"%(ntpl2)s".') % {'prop': property_name, - 'cap': capability_name, - 'ntpl1': node_template.name, - 'ntpl2': self.context.name})) - return property - msg = _('Requirement/Capability "{0}" referenced from node template ' - '"{1}" was not found in node template "{2}".').format( - capability_name, - self.context.name, - node_template.name) - ExceptionCollector.appendException(KeyError(msg)) - - def _find_property(self, property_name): - node_tpl = self._find_node_template(self.args[0]) - if not node_tpl: - return - props = node_tpl.get_properties() - found = [props[property_name]] if property_name in props else [] - if len(found) == 0: - ExceptionCollector.appendException( - KeyError(_('Property "%(prop)s" was not found in node ' - 'template "%(ntpl)s".') % - {'prop': property_name, - 'ntpl': node_tpl.name})) - return None - return found[0] - - def _find_node_template(self, node_template_name): - if node_template_name == SELF: - return self.context - # enable the HOST value in the function - if node_template_name == HOST: - return self._find_host_containing_property() - if node_template_name == TARGET: - if not isinstance(self.context.type_definition, RelationshipType): - ExceptionCollector.appendException( - KeyError(_('"TARGET" keyword can only be used in context' - ' to "Relationships" target node'))) - return - return self.context.target - if node_template_name == SOURCE: - if not isinstance(self.context.type_definition, RelationshipType): - ExceptionCollector.appendException( - KeyError(_('"SOURCE" keyword can only be used in context' - ' to "Relationships" source node'))) - return - return self.context.source - if not hasattr(self.tosca_tpl, 'nodetemplates'): - return - for node_template in self.tosca_tpl.nodetemplates: - if node_template.name == node_template_name: - return node_template - ExceptionCollector.appendException( - KeyError(_( - 'Node template "{0}" was not found.' - ).format(node_template_name))) - - def _get_index_value(self, value, index): - if isinstance(value, list): - if index < len(value): - return value[index] - else: - ExceptionCollector.appendException( - KeyError(_( - "Property '{0}' found in capability '{1}'" - " referenced from node template {2}" - " must have an element with index {3}."). - format(self.args[2], - self.args[1], - self.context.name, - index))) - else: - ExceptionCollector.appendException( - KeyError(_( - "Property '{0}' found in capability '{1}'" - " referenced from node template {2}" - " must be a list.").format(self.args[2], - self.args[1], - self.context.name))) - - def _get_attribute_value(self, value, attibute): - if isinstance(value, dict): - if attibute in value: - return value[attibute] - else: - ExceptionCollector.appendException( - KeyError(_( - "Property '{0}' found in capability '{1}'" - " referenced from node template {2}" - " must have an attribute named {3}."). - format(self.args[2], - self.args[1], - self.context.name, - attibute))) - else: - ExceptionCollector.appendException( - KeyError(_( - "Property '{0}' found in capability '{1}'" - " referenced from node template {2}" - " must be a dict.").format(self.args[2], - self.args[1], - self.context.name))) - - # Add this functions similar to get_attribute case - def _find_host_containing_property(self, node_template_name=SELF): - node_template = self._find_node_template(node_template_name) - hosted_on_rel = EntityType.TOSCA_DEF[HOSTED_ON] - for r in node_template.requirements: - for requirement, target_name in r.items(): - target_node = self._find_node_template(target_name) - target_type = target_node.type_definition - for capability in target_type.get_capabilities_objects(): - if capability.type in hosted_on_rel['valid_target_types']: - if self._property_exists_in_type(target_type): - return target_node - return self._find_host_containing_property( - target_name) - return None - - def _property_exists_in_type(self, type_definition): - props_def = type_definition.get_properties_def() - found = [props_def[self.args[1]]] \ - if self.args[1] in props_def else [] - return len(found) == 1 - - def result(self): - if len(self.args) >= 3: - # First check if there is property with this name - node_tpl = self._find_node_template(self.args[0]) - props = node_tpl.get_properties() if node_tpl else [] - index = 2 - found = [props[self.args[1]]] if self.args[1] in props else [] - if found: - property_value = found[0].value - else: - index = 3 - # then check the req or caps - property_value = self._find_req_or_cap_property(self.args[1], - self.args[2]) - if len(self.args) > index: - for elem in self.args[index:]: - if isinstance(property_value, list): - int_elem = int(elem) - property_value = self._get_index_value(property_value, - int_elem) - else: - property_value = self._get_attribute_value( - property_value, - elem) - else: - property_value = self._find_property(self.args[1]).value - if isinstance(property_value, Function): - return property_value.result() - return get_function(self.tosca_tpl, - self.context, - property_value) - - @property - def node_template_name(self): - return self.args[0] - - @property - def property_name(self): - if len(self.args) > 2: - return self.args[2] - return self.args[1] - - @property - def req_or_cap(self): - if len(self.args) > 2: - return self.args[1] - return None - - -class GetOperationOutput(Function): - def validate(self): - if len(self.args) == 4: - self._find_node_template(self.args[0]) - interface_name = self._find_interface_name(self.args[1]) - self._find_operation_name(interface_name, self.args[2]) - else: - ExceptionCollector.appendException( - ValueError(_('Illegal arguments for function "{0}". Expected ' - 'arguments: "template_name","interface_name",' - '"operation_name","output_variable_name"' - ).format(GET_OPERATION_OUTPUT))) - return - - def _find_interface_name(self, interface_name): - if interface_name in toscaparser.elements.interfaces.SECTIONS: - return interface_name - else: - ExceptionCollector.appendException( - ValueError(_('Enter a valid interface name' - ).format(GET_OPERATION_OUTPUT))) - return - - def _find_operation_name(self, interface_name, operation_name): - if(interface_name == 'Configure' or - interface_name == 'tosca.interfaces.node.relationship.Configure'): - if(operation_name in - StatefulEntityType. - interfaces_relationship_configure_operations): - return operation_name - else: - ExceptionCollector.appendException( - ValueError(_('Enter an operation of Configure interface' - ).format(GET_OPERATION_OUTPUT))) - return - elif(interface_name == 'Standard' or - interface_name == 'tosca.interfaces.node.lifecycle.Standard'): - if(operation_name in - StatefulEntityType.interfaces_node_lifecycle_operations): - return operation_name - else: - ExceptionCollector.appendException( - ValueError(_('Enter an operation of Standard interface' - ).format(GET_OPERATION_OUTPUT))) - return - else: - ExceptionCollector.appendException( - ValueError(_('Enter a valid operation name' - ).format(GET_OPERATION_OUTPUT))) - return - - def _find_node_template(self, node_template_name): - if node_template_name == TARGET: - if not isinstance(self.context.type_definition, RelationshipType): - ExceptionCollector.appendException( - KeyError(_('"TARGET" keyword can only be used in context' - ' to "Relationships" target node'))) - return - return self.context.target - if node_template_name == SOURCE: - if not isinstance(self.context.type_definition, RelationshipType): - ExceptionCollector.appendException( - KeyError(_('"SOURCE" keyword can only be used in context' - ' to "Relationships" source node'))) - return - return self.context.source - name = self.context.name \ - if node_template_name == SELF and \ - not isinstance(self.context, list) \ - else node_template_name - for node_template in self.tosca_tpl.nodetemplates: - if node_template.name == name: - return node_template - ExceptionCollector.appendException( - KeyError(_( - 'Node template "{0}" was not found.' - ).format(node_template_name))) - - def result(self): - return self - - -class Concat(Function): - """Validate the function and provide an instance of the function - - Concatenation of values are supposed to be produced at runtime and - therefore its the responsibility of the TOSCA engine to implement the - evaluation of Concat functions. - - Arguments: - - * List of strings that needs to be concatenated - - Example: - - [ 'http://', - get_attribute: [ server, public_address ], - ':' , - get_attribute: [ server, port ] ] - """ - - def validate(self): - if len(self.args) < 1: - ExceptionCollector.appendException( - ValueError(_('Invalid arguments for function "{0}". Expected ' - 'at least one arguments.').format(CONCAT))) - - def result(self): - return self - - -class Token(Function): - """Validate the function and provide an instance of the function - - The token function is used within a TOSCA service template on a string to - parse out (tokenize) substrings separated by one or more token characters - within a larger string. - - - Arguments: - - * The composite string that contains one or more substrings separated by - token characters. - * The string that contains one or more token characters that separate - substrings within the composite string. - * The integer indicates the index of the substring to return from the - composite string. Note that the first substring is denoted by using - the '0' (zero) integer value. - - Example: - - [ get_attribute: [ my_server, data_endpoint, ip_address ], ':', 1 ] - - """ - - def validate(self): - if len(self.args) < 3: - ExceptionCollector.appendException( - ValueError(_('Invalid arguments for function "{0}". Expected ' - 'at least three arguments.').format(TOKEN))) - else: - if not isinstance(self.args[1], str) or len(self.args[1]) != 1: - ExceptionCollector.appendException( - ValueError(_('Invalid arguments for function "{0}". ' - 'Expected single char value as second ' - 'argument.').format(TOKEN))) - - if not isinstance(self.args[2], int): - ExceptionCollector.appendException( - ValueError(_('Invalid arguments for function "{0}". ' - 'Expected integer value as third ' - 'argument.').format(TOKEN))) - - def result(self): - return self - -function_mappings = { - GET_PROPERTY: GetProperty, - GET_INPUT: GetInput, - GET_ATTRIBUTE: GetAttribute, - GET_OPERATION_OUTPUT: GetOperationOutput, - CONCAT: Concat, - TOKEN: Token -} - - -def is_function(function): - """Returns True if the provided function is a Tosca intrinsic function. - - Examples: - - * "{ get_property: { SELF, port } }" - * "{ get_input: db_name }" - * Function instance - - :param function: Function as string or a Function instance. - :return: True if function is a Tosca intrinsic function, otherwise False. - """ - if isinstance(function, dict) and len(function) == 1: - func_name = list(function.keys())[0] - return func_name in function_mappings - return isinstance(function, Function) - - -def get_function(tosca_tpl, node_template, raw_function): - """Gets a Function instance representing the provided template function. - - If the format provided raw_function format is not relevant for template - functions or if the function name doesn't exist in function mapping the - method returns the provided raw_function. - - :param tosca_tpl: The tosca template. - :param node_template: The node template the function is specified for. - :param raw_function: The raw function as dict. - :return: Template function as Function instance or the raw_function if - parsing was unsuccessful. - """ - if is_function(raw_function): - if isinstance(raw_function, dict): - func_name = list(raw_function.keys())[0] - if func_name in function_mappings: - func = function_mappings[func_name] - func_args = list(raw_function.values())[0] - if not isinstance(func_args, list): - func_args = [func_args] - return func(tosca_tpl, node_template, func_name, func_args) - return raw_function diff --git a/nfvparser/src/main/python/toscaparser/groups.py b/nfvparser/src/main/python/toscaparser/groups.py deleted file mode 100644 index 6a3e5c7..0000000 --- a/nfvparser/src/main/python/toscaparser/groups.py +++ /dev/null @@ -1,55 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import UnknownFieldError -from toscaparser.entity_template import EntityTemplate -from toscaparser.utils import validateutils - -SECTIONS = (TYPE, METADATA, DESCRIPTION, PROPERTIES, MEMBERS, INTERFACES) = \ - ('type', 'metadata', 'description', - 'properties', 'members', 'interfaces') - - -class Group(EntityTemplate): - - def __init__(self, name, group_templates, member_nodes, custom_defs=None): - super(Group, self).__init__(name, - group_templates, - 'group_type', - custom_defs) - self.name = name - self.tpl = group_templates - self.meta_data = None - if self.METADATA in self.tpl: - self.meta_data = self.tpl.get(self.METADATA) - validateutils.validate_map(self.meta_data) - self.member_nodes = member_nodes - self._validate_keys() - - @property - def members(self): - return self.entity_tpl.get('members') - - @property - def description(self): - return self.entity_tpl.get('description') - - def get_member_nodes(self): - return self.member_nodes - - def _validate_keys(self): - for key in self.entity_tpl.keys(): - if key not in SECTIONS: - ExceptionCollector.appendException( - UnknownFieldError(what='Groups "%s"' % self.name, - field=key)) diff --git a/nfvparser/src/main/python/toscaparser/imports.py b/nfvparser/src/main/python/toscaparser/imports.py deleted file mode 100644 index 429a396..0000000 --- a/nfvparser/src/main/python/toscaparser/imports.py +++ /dev/null @@ -1,290 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import logging -import os - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import InvalidPropertyValueError -from toscaparser.common.exception import MissingRequiredFieldError -from toscaparser.common.exception import UnknownFieldError -from toscaparser.common.exception import ValidationError -from toscaparser.elements.tosca_type_validation import TypeValidation -from toscaparser.utils.gettextutils import _ -import toscaparser.utils.urlutils -import toscaparser.utils.yamlparser - -YAML_LOADER = toscaparser.utils.yamlparser.load_yaml -log = logging.getLogger("tosca") - - -class ImportsLoader(object): - - IMPORTS_SECTION = (FILE, REPOSITORY, NAMESPACE_URI, NAMESPACE_PREFIX) = \ - ('file', 'repository', 'namespace_uri', - 'namespace_prefix') - - def __init__(self, importslist, path, type_definition_list=None, - tpl=None): - self.importslist = importslist - self.custom_defs = {} - self.nested_tosca_tpls = [] - if not path and not tpl: - msg = _('Input tosca template is not provided.') - log.warning(msg) - ExceptionCollector.appendException(ValidationError(message=msg)) - self.path = path - self.repositories = {} - if tpl and tpl.get('repositories'): - self.repositories = tpl.get('repositories') - self.type_definition_list = [] - if type_definition_list: - if isinstance(type_definition_list, list): - self.type_definition_list = type_definition_list - else: - self.type_definition_list.append(type_definition_list) - self._validate_and_load_imports() - - def get_custom_defs(self): - return self.custom_defs - - def get_nested_tosca_tpls(self): - return self.nested_tosca_tpls - - def _validate_and_load_imports(self): - imports_names = set() - - if not self.importslist: - msg = _('"imports" keyname is defined without including ' - 'templates.') - log.error(msg) - ExceptionCollector.appendException(ValidationError(message=msg)) - return - - for import_def in self.importslist: - if isinstance(import_def, dict): - for import_name, import_uri in import_def.items(): - if import_name in imports_names: - msg = (_('Duplicate import name "%s" was found.') % - import_name) - log.error(msg) - ExceptionCollector.appendException( - ValidationError(message=msg)) - imports_names.add(import_name) - - full_file_name, custom_type = self._load_import_template( - import_name, import_uri) - namespace_prefix = None - if isinstance(import_uri, dict): - namespace_prefix = import_uri.get( - self.NAMESPACE_PREFIX) - if custom_type: - TypeValidation(custom_type, import_def) - self._update_custom_def(custom_type, namespace_prefix) - else: # old style of imports - full_file_name, custom_type = self._load_import_template( - None, import_def) - if custom_type: - TypeValidation( - custom_type, import_def) - self._update_custom_def(custom_type, None) - - self._update_nested_tosca_tpls(full_file_name, custom_type) - - def _update_custom_def(self, custom_type, namespace_prefix): - outer_custom_types = {} - for type_def in self.type_definition_list: - outer_custom_types = custom_type.get(type_def) - if outer_custom_types: - if type_def == "imports": - for i in self.custom_defs.get('imports', []): - if i not in outer_custom_types: - outer_custom_types.append(i) - self.custom_defs.update({'imports': outer_custom_types}) - else: - if namespace_prefix: - prefix_custom_types = {} - for type_def_key in outer_custom_types.keys(): - namespace_prefix_to_key = (namespace_prefix + - "." + type_def_key) - prefix_custom_types[namespace_prefix_to_key] = \ - outer_custom_types[type_def_key] - self.custom_defs.update(prefix_custom_types) - else: - self.custom_defs.update(outer_custom_types) - - def _update_nested_tosca_tpls(self, full_file_name, custom_tpl): - if full_file_name and custom_tpl: - topo_tpl = {full_file_name: custom_tpl} - self.nested_tosca_tpls.append(topo_tpl) - - def _validate_import_keys(self, import_name, import_uri_def): - if self.FILE not in import_uri_def.keys(): - log.warning(_('Missing keyname "file" in import "%(name)s".') - % {'name': import_name}) - ExceptionCollector.appendException( - MissingRequiredFieldError( - what='Import of template "%s"' % import_name, - required=self.FILE)) - for key in import_uri_def.keys(): - if key not in self.IMPORTS_SECTION: - log.warning(_('Unknown keyname "%(key)s" error in ' - 'imported definition "%(def)s".') - % {'key': key, 'def': import_name}) - ExceptionCollector.appendException( - UnknownFieldError( - what='Import of template "%s"' % import_name, - field=key)) - - def _load_import_template(self, import_name, import_uri_def): - """Handle custom types defined in imported template files - - This method loads the custom type definitions referenced in "imports" - section of the TOSCA YAML template by determining whether each import - is specified via a file reference (by relative or absolute path) or a - URL reference. - - Possibilities: - +----------+--------+------------------------------+ - | template | import | comment | - +----------+--------+------------------------------+ - | file | file | OK | - | file | URL | OK | - | preparsed| file | file must be a full path | - | preparsed| URL | OK | - | URL | file | file must be a relative path | - | URL | URL | OK | - +----------+--------+------------------------------+ - """ - short_import_notation = False - if isinstance(import_uri_def, dict): - self._validate_import_keys(import_name, import_uri_def) - file_name = import_uri_def.get(self.FILE) - repository = import_uri_def.get(self.REPOSITORY) - repos = self.repositories.keys() - if repository is not None: - if repository not in repos: - ExceptionCollector.appendException( - InvalidPropertyValueError( - what=_('Repository is not found in "%s"') % repos)) - else: - file_name = import_uri_def - repository = None - short_import_notation = True - - if not file_name: - msg = (_('A template file name is not provided with import ' - 'definition "%(import_name)s".') - % {'import_name': import_name}) - log.error(msg) - ExceptionCollector.appendException(ValidationError(message=msg)) - return None, None - - if toscaparser.utils.urlutils.UrlUtils.validate_url(file_name): - return file_name, YAML_LOADER(file_name, False) - elif not repository: - import_template = None - if self.path: - if toscaparser.utils.urlutils.UrlUtils.validate_url(self.path): - if os.path.isabs(file_name): - msg = (_('Absolute file name "%(name)s" cannot be ' - 'used in a URL-based input template ' - '"%(template)s".') - % {'name': file_name, 'template': self.path}) - log.error(msg) - ExceptionCollector.appendException(ImportError(msg)) - return None, None - import_template = toscaparser.utils.urlutils.UrlUtils.\ - join_url(self.path, file_name) - a_file = False - else: - a_file = True - main_a_file = os.path.isfile(self.path) - - if main_a_file: - if os.path.isfile(file_name): - import_template = file_name - else: - full_path = os.path.join( - os.path.dirname(os.path.abspath(self.path)), - file_name) - if os.path.isfile(full_path): - import_template = full_path - else: - file_path = file_name.rpartition("/") - dir_path = os.path.dirname(os.path.abspath( - self.path)) - if file_path[0] != '' and dir_path.endswith( - file_path[0]): - import_template = dir_path + "/" +\ - file_path[2] - if not os.path.isfile(import_template): - msg = (_('"%(import_template)s" is' - 'not a valid file') - % {'import_template': - import_template}) - log.error(msg) - ExceptionCollector.appendException - (ValueError(msg)) - else: # template is pre-parsed - if os.path.isabs(file_name) and os.path.isfile(file_name): - a_file = True - import_template = file_name - else: - msg = (_('Relative file name "%(name)s" cannot be used ' - 'in a pre-parsed input template.') - % {'name': file_name}) - log.error(msg) - ExceptionCollector.appendException(ImportError(msg)) - return None, None - - if not import_template: - log.error(_('Import "%(name)s" is not valid.') % - {'name': import_uri_def}) - ExceptionCollector.appendException( - ImportError(_('Import "%s" is not valid.') % - import_uri_def)) - return None, None - return import_template, YAML_LOADER(import_template, a_file) - - if short_import_notation: - log.error(_('Import "%(name)s" is not valid.') % import_uri_def) - ExceptionCollector.appendException( - ImportError(_('Import "%s" is not valid.') % import_uri_def)) - return None, None - - full_url = "" - if repository: - if self.repositories: - for repo_name, repo_def in self.repositories.items(): - if repo_name == repository: - # Remove leading, ending spaces and strip - # the last character if "/" - repo_url = ((repo_def['url']).strip()).rstrip("//") - full_url = repo_url + "/" + file_name - - if not full_url: - msg = (_('referenced repository "%(n_uri)s" in import ' - 'definition "%(tpl)s" not found.') - % {'n_uri': repository, 'tpl': import_name}) - log.error(msg) - ExceptionCollector.appendException(ImportError(msg)) - return None, None - - if toscaparser.utils.urlutils.UrlUtils.validate_url(full_url): - return full_url, YAML_LOADER(full_url, False) - else: - msg = (_('repository url "%(n_uri)s" is not valid in import ' - 'definition "%(tpl)s".') - % {'n_uri': repo_url, 'tpl': import_name}) - log.error(msg) - ExceptionCollector.appendException(ImportError(msg)) diff --git a/nfvparser/src/main/python/toscaparser/nodetemplate.py b/nfvparser/src/main/python/toscaparser/nodetemplate.py deleted file mode 100644 index 0d65ac5..0000000 --- a/nfvparser/src/main/python/toscaparser/nodetemplate.py +++ /dev/null @@ -1,298 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - - -import logging - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import InvalidPropertyValueError -from toscaparser.common.exception import MissingRequiredFieldError -from toscaparser.common.exception import TypeMismatchError -from toscaparser.common.exception import UnknownFieldError -from toscaparser.common.exception import ValidationError -from toscaparser.dataentity import DataEntity -from toscaparser.elements.interfaces import CONFIGURE -from toscaparser.elements.interfaces import CONFIGURE_SHORTNAME -from toscaparser.elements.interfaces import INTERFACE_DEF_RESERVED_WORDS -from toscaparser.elements.interfaces import InterfacesDef -from toscaparser.elements.interfaces import LIFECYCLE -from toscaparser.elements.interfaces import LIFECYCLE_SHORTNAME -from toscaparser.elements.relationshiptype import RelationshipType -from toscaparser.entity_template import EntityTemplate -from toscaparser.relationship_template import RelationshipTemplate -from toscaparser.utils.gettextutils import _ - -log = logging.getLogger('tosca') - - -class NodeTemplate(EntityTemplate): - '''Node template from a Tosca profile.''' - def __init__(self, name, node_templates, custom_def=None, - available_rel_tpls=None, available_rel_types=None): - super(NodeTemplate, self).__init__(name, node_templates[name], - 'node_type', - custom_def) - self.templates = node_templates - self._validate_fields(node_templates[name]) - self.custom_def = custom_def - self.related = {} - self.relationship_tpl = [] - self.available_rel_tpls = available_rel_tpls - self.available_rel_types = available_rel_types - self._relationships = {} - self.substitution_mapped = None - - @property - def relationships(self): - if not self._relationships: - requires = self.requirements - if requires and isinstance(requires, list): - for r in requires: - for r1, value in r.items(): - explicit = self._get_explicit_relationship(r, value) - if explicit: - for key, value in explicit.items(): - self._relationships[key] = value - return self._relationships - - def _get_explicit_relationship(self, req, value): - """Handle explicit relationship - - For example, - - req: - node: DBMS - relationship: tosca.relationships.HostedOn - """ - explicit_relation = {} - node = value.get('node') if isinstance(value, dict) else value - - if node: - # TODO(spzala) implement look up once Glance meta data is available - # to find a matching TOSCA node using the TOSCA types - msg = _('Lookup by TOSCA types is not supported. ' - 'Requirement node "%(node)s" for "%(name)s"' - ' can not be full-filled.') \ - % {'node': node, 'name': self.name} - if (node in list(self.type_definition.TOSCA_DEF.keys()) - or node in self.custom_def): - ExceptionCollector.appendException(NotImplementedError(msg)) - return - - if node not in self.templates: - ExceptionCollector.appendException( - KeyError(_('Node template "%(node)s" was not found' - ' in "%(name)s".') - % {'node': node, 'name': self.name})) - return - - related_tpl = NodeTemplate(node, self.templates, self.custom_def) - relationship = value.get('relationship') \ - if isinstance(value, dict) else None - # check if it's type has relationship defined - if not relationship: - parent_reqs = self.type_definition.get_all_requirements() - if parent_reqs is None: - ExceptionCollector.appendException( - ValidationError(message='parent_req is ' + - str(parent_reqs))) - else: - for key in req.keys(): - for req_dict in parent_reqs: - if key in req_dict.keys(): - relationship = (req_dict.get(key). - get('relationship')) - break - if relationship: - found_relationship_tpl = False - - # apply available relationship templates if found - if self.available_rel_tpls: - for tpl in self.available_rel_tpls: - if tpl.name == relationship: - rtype = RelationshipType(tpl.type, None, - self.custom_def) - explicit_relation[rtype] = related_tpl - tpl.target = related_tpl - tpl.source = self - self.relationship_tpl.append(tpl) - found_relationship_tpl = True - # create relationship template object. - rel_prfx = self.type_definition.RELATIONSHIP_PREFIX - if not found_relationship_tpl: - if isinstance(relationship, dict): - relationship = relationship.get('type') - if relationship: - if self.available_rel_types and \ - relationship in self.available_rel_types.keys(): - pass - elif not relationship.startswith(rel_prfx): - relationship = rel_prfx + relationship - else: - ExceptionCollector.appendException( - MissingRequiredFieldError( - what=_('"relationship" used in template ' - '"%s"') % related_tpl.name, - required=self.TYPE)) - for rtype in self.type_definition.relationship.keys(): - if rtype.type == relationship: - explicit_relation[rtype] = related_tpl - related_tpl._add_relationship_template(req, - rtype.type, - self) - elif self.available_rel_types: - if relationship in self.available_rel_types.keys(): - rel_type_def = self.available_rel_types.\ - get(relationship) - if 'derived_from' in rel_type_def: - super_type = \ - rel_type_def.get('derived_from') - if not super_type.startswith(rel_prfx): - super_type = rel_prfx + super_type - if rtype.type == super_type: - explicit_relation[rtype] = related_tpl - related_tpl.\ - _add_relationship_template( - req, rtype.type, self) - return explicit_relation - - def _add_relationship_template(self, requirement, rtype, source): - req = requirement.copy() - req['type'] = rtype - tpl = RelationshipTemplate(req, rtype, self.custom_def, self, source) - self.relationship_tpl.append(tpl) - - def get_relationship_template(self): - return self.relationship_tpl - - def _add_next(self, nodetpl, relationship): - self.related[nodetpl] = relationship - - @property - def related_nodes(self): - if not self.related: - for relation, node in self.type_definition.relationship.items(): - for tpl in self.templates: - if tpl == node.type: - self.related[NodeTemplate(tpl)] = relation - return self.related.keys() - - def validate(self, tosca_tpl=None): - self._validate_capabilities() - self._validate_requirements() - self._validate_properties(self.entity_tpl, self.type_definition) - self._validate_interfaces() - for prop in self.get_properties_objects(): - prop.validate() - - def _validate_requirements(self): - type_requires = self.type_definition.get_all_requirements() - allowed_reqs = ["template"] - if type_requires: - for treq in type_requires: - for key, value in treq.items(): - allowed_reqs.append(key) - if isinstance(value, dict): - for key in value: - allowed_reqs.append(key) - - requires = self.type_definition.get_value(self.REQUIREMENTS, - self.entity_tpl) - if requires: - if not isinstance(requires, list): - ExceptionCollector.appendException( - TypeMismatchError( - what='"requirements" of template "%s"' % self.name, - type='list')) - else: - for req in requires: - for r1, value in req.items(): - if isinstance(value, dict): - self._validate_requirements_keys(value) - self._validate_requirements_properties(value) - allowed_reqs.append(r1) - self._common_validate_field(req, allowed_reqs, - 'requirements') - - def _validate_requirements_properties(self, requirements): - # TODO(anyone): Only occurrences property of the requirements is - # validated here. Validation of other requirement properties are being - # validated in different files. Better to keep all the requirements - # properties validation here. - for key, value in requirements.items(): - if key == 'occurrences': - self._validate_occurrences(value) - break - - def _validate_occurrences(self, occurrences): - DataEntity.validate_datatype('list', occurrences) - for value in occurrences: - DataEntity.validate_datatype('integer', value) - if len(occurrences) != 2 or not (0 <= occurrences[0] <= occurrences[1]) \ - or occurrences[1] == 0: - ExceptionCollector.appendException( - InvalidPropertyValueError(what=(occurrences))) - - def _validate_requirements_keys(self, requirement): - for key in requirement.keys(): - if key not in self.REQUIREMENTS_SECTION: - ExceptionCollector.appendException( - UnknownFieldError( - what='"requirements" of template "%s"' % self.name, - field=key)) - - def _validate_interfaces(self): - ifaces = self.type_definition.get_value(self.INTERFACES, - self.entity_tpl) - if ifaces: - for name, value in ifaces.items(): - if name in (LIFECYCLE, LIFECYCLE_SHORTNAME): - self._common_validate_field( - value, InterfacesDef. - interfaces_node_lifecycle_operations, - 'interfaces') - elif name in (CONFIGURE, CONFIGURE_SHORTNAME): - self._common_validate_field( - value, InterfacesDef. - interfaces_relationship_configure_operations, - 'interfaces') - elif name in self.type_definition.interfaces.keys(): - self._common_validate_field( - value, - self._collect_custom_iface_operations(name), - 'interfaces') - else: - ExceptionCollector.appendException( - UnknownFieldError( - what='"interfaces" of template "%s"' % - self.name, field=name)) - - def _collect_custom_iface_operations(self, name): - allowed_operations = [] - nodetype_iface_def = self.type_definition.interfaces[name] - allowed_operations.extend(nodetype_iface_def.keys()) - if 'type' in nodetype_iface_def: - iface_type = nodetype_iface_def['type'] - if iface_type in self.type_definition.custom_def: - iface_type_def = self.type_definition.custom_def[iface_type] - else: - iface_type_def = self.type_definition.TOSCA_DEF[iface_type] - allowed_operations.extend(iface_type_def.keys()) - allowed_operations = [op for op in allowed_operations if - op not in INTERFACE_DEF_RESERVED_WORDS] - return allowed_operations - - def _validate_fields(self, nodetemplate): - for name in nodetemplate.keys(): - if name not in self.SECTIONS and name not in self.SPECIAL_SECTIONS: - ExceptionCollector.appendException( - UnknownFieldError(what='Node template "%s"' % self.name, - field=name)) diff --git a/nfvparser/src/main/python/toscaparser/parameters.py b/nfvparser/src/main/python/toscaparser/parameters.py deleted file mode 100644 index 787db00..0000000 --- a/nfvparser/src/main/python/toscaparser/parameters.py +++ /dev/null @@ -1,128 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - - -import logging - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import MissingRequiredFieldError -from toscaparser.common.exception import UnknownFieldError -from toscaparser.dataentity import DataEntity -from toscaparser.elements.constraints import Schema -from toscaparser.elements.entity_type import EntityType -from toscaparser.utils.gettextutils import _ - - -log = logging.getLogger('tosca') - - -class Input(object): - - INPUTFIELD = (TYPE, DESCRIPTION, DEFAULT, CONSTRAINTS, REQUIRED, STATUS, - ENTRY_SCHEMA) = ('type', 'description', 'default', - 'constraints', 'required', 'status', - 'entry_schema') - - def __init__(self, name, schema_dict): - self.name = name - self.schema = Schema(name, schema_dict) - - self._validate_field() - self.validate_type(self.type) - - @property - def type(self): - return self.schema.type - - @property - def required(self): - return self.schema.required - - @property - def description(self): - return self.schema.description - - @property - def default(self): - return self.schema.default - - @property - def constraints(self): - return self.schema.constraints - - @property - def status(self): - return self.schema.status - - def validate(self, value=None): - if value is not None: - self._validate_value(value) - - def _validate_field(self): - for name in self.schema.schema: - if name not in self.INPUTFIELD: - ExceptionCollector.appendException( - UnknownFieldError(what='Input "%s"' % self.name, - field=name)) - - def validate_type(self, input_type): - if input_type not in Schema.PROPERTY_TYPES: - ExceptionCollector.appendException( - ValueError(_('Invalid type "%s".') % type)) - - # TODO(anyone) Need to test for any built-in datatype not just network - # that is, tosca.datatypes.* and not assume tosca.datatypes.network.* - # TODO(anyone) Add support for tosca.datatypes.Credential - def _validate_value(self, value): - tosca = EntityType.TOSCA_DEF - datatype = None - if self.type in tosca: - datatype = tosca[self.type] - elif EntityType.DATATYPE_NETWORK_PREFIX + self.type in tosca: - datatype = tosca[EntityType.DATATYPE_NETWORK_PREFIX + self.type] - - DataEntity.validate_datatype(self.type, value, None, datatype) - - -class Output(object): - - OUTPUTFIELD = (DESCRIPTION, VALUE) = ('description', 'value') - - def __init__(self, name, attrs): - self.name = name - self.attrs = attrs - - @property - def description(self): - return self.attrs.get(self.DESCRIPTION) - - @property - def value(self): - return self.attrs.get(self.VALUE) - - def validate(self): - self._validate_field() - - def _validate_field(self): - if not isinstance(self.attrs, dict): - ExceptionCollector.appendException( - MissingRequiredFieldError(what='Output "%s"' % self.name, - required=self.VALUE)) - if self.value is None: - ExceptionCollector.appendException( - MissingRequiredFieldError(what='Output "%s"' % self.name, - required=self.VALUE)) - for name in self.attrs: - if name not in self.OUTPUTFIELD: - ExceptionCollector.appendException( - UnknownFieldError(what='Output "%s"' % self.name, - field=name)) diff --git a/nfvparser/src/main/python/toscaparser/policy.py b/nfvparser/src/main/python/toscaparser/policy.py deleted file mode 100644 index fedbeb4..0000000 --- a/nfvparser/src/main/python/toscaparser/policy.py +++ /dev/null @@ -1,81 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - - -import logging - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import UnknownFieldError -from toscaparser.entity_template import EntityTemplate -from toscaparser.triggers import Triggers -from toscaparser.utils import validateutils - - -SECTIONS = (TYPE, METADATA, DESCRIPTION, PROPERTIES, TARGETS, TRIGGERS) = \ - ('type', 'metadata', 'description', - 'properties', 'targets', 'triggers') - -log = logging.getLogger('tosca') - - -class Policy(EntityTemplate): - '''Policies defined in Topology template.''' - def __init__(self, name, policy, targets=None, targets_type=None, - custom_def=None): - super(Policy, self).__init__(name, - policy, - 'policy_type', - custom_def) - self.meta_data = None - if self.METADATA in policy: - self.meta_data = policy.get(self.METADATA) - validateutils.validate_map(self.meta_data) - self.targets_list = targets - self.targets_type = targets_type - self.triggers = self._triggers(policy.get(TRIGGERS)) - self.properties = None - if 'properties' in policy: - self.properties = policy['properties'] - self._validate_keys() - - @property - def targets(self): - return self.entity_tpl.get('targets') - - @property - def description(self): - return self.entity_tpl.get('description') - - @property - def metadata(self): - return self.entity_tpl.get('metadata') - - def get_targets_type(self): - return self.targets_type - - def get_targets_list(self): - return self.targets_list - - def _triggers(self, triggers): - triggerObjs = [] - if triggers: - for name, trigger_tpl in triggers.items(): - triggersObj = Triggers(name, trigger_tpl) - triggerObjs.append(triggersObj) - return triggerObjs - - def _validate_keys(self): - for key in self.entity_tpl.keys(): - if key not in SECTIONS: - ExceptionCollector.appendException( - UnknownFieldError(what='Policy "%s"' % self.name, - field=key)) diff --git a/nfvparser/src/main/python/toscaparser/prereq/__init__.py b/nfvparser/src/main/python/toscaparser/prereq/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/nfvparser/src/main/python/toscaparser/prereq/csar.py b/nfvparser/src/main/python/toscaparser/prereq/csar.py deleted file mode 100644 index 1cba5c4..0000000 --- a/nfvparser/src/main/python/toscaparser/prereq/csar.py +++ /dev/null @@ -1,286 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import os.path -import requests -import shutil -import six -import tempfile -import yaml -import zipfile - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import URLException -from toscaparser.common.exception import ValidationError -from toscaparser.imports import ImportsLoader -from toscaparser.utils.gettextutils import _ -from toscaparser.utils.urlutils import UrlUtils - -try: # Python 2.x - from BytesIO import BytesIO -except ImportError: # Python 3.x - from io import BytesIO - - -class CSAR(object): - - def __init__(self, csar_file, a_file=True): - self.path = csar_file - self.a_file = a_file - self.is_validated = False - self.error_caught = False - self.csar = None - self.temp_dir = None - - def validate(self): - """Validate the provided CSAR file.""" - - self.is_validated = True - - # validate that the file or URL exists - missing_err_msg = (_('"%s" does not exist.') % self.path) - if self.a_file: - if not os.path.isfile(self.path): - ExceptionCollector.appendException( - ValidationError(message=missing_err_msg)) - return False - else: - self.csar = self.path - else: # a URL - if not UrlUtils.validate_url(self.path): - ExceptionCollector.appendException( - ValidationError(message=missing_err_msg)) - return False - else: - response = requests.get(self.path) - self.csar = BytesIO(response.content) - - # validate that it is a valid zip file - if not zipfile.is_zipfile(self.csar): - err_msg = (_('"%s" is not a valid zip file.') % self.path) - ExceptionCollector.appendException( - ValidationError(message=err_msg)) - return False - - # validate that it contains the metadata file in the correct location - self.zfile = zipfile.ZipFile(self.csar, 'r') - filelist = self.zfile.namelist() - if 'TOSCA-Metadata/TOSCA.meta' not in filelist: - err_msg = (_('"%s" is not a valid CSAR as it does not contain the ' - 'required file "TOSCA.meta" in the folder ' - '"TOSCA-Metadata".') % self.path) - ExceptionCollector.appendException( - ValidationError(message=err_msg)) - return False - - # validate that 'Entry-Definitions' property exists in TOSCA.meta - data = self.zfile.read('TOSCA-Metadata/TOSCA.meta') - invalid_yaml_err_msg = (_('The file "TOSCA-Metadata/TOSCA.meta" in ' - 'the CSAR "%s" does not contain valid YAML ' - 'content.') % self.path) - try: - meta = yaml.load(data) - if type(meta) is dict: - self.metadata = meta - else: - ExceptionCollector.appendException( - ValidationError(message=invalid_yaml_err_msg)) - return False - except yaml.YAMLError: - ExceptionCollector.appendException( - ValidationError(message=invalid_yaml_err_msg)) - return False - - if 'Entry-Definitions' not in self.metadata: - err_msg = (_('The CSAR "%s" is missing the required metadata ' - '"Entry-Definitions" in ' - '"TOSCA-Metadata/TOSCA.meta".') - % self.path) - ExceptionCollector.appendException( - ValidationError(message=err_msg)) - return False - - # validate that 'Entry-Definitions' metadata value points to an - # existing file in the CSAR - entry = self.metadata.get('Entry-Definitions') - if entry and entry not in filelist: - err_msg = (_('The "Entry-Definitions" file defined in the ' - 'CSAR "%s" does not exist.') % self.path) - ExceptionCollector.appendException( - ValidationError(message=err_msg)) - return False - - # validate that external references in the main template actually - # exist and are accessible - self._validate_external_references() - return not self.error_caught - - def get_metadata(self): - """Return the metadata dictionary.""" - - # validate the csar if not already validated - if not self.is_validated: - self.validate() - - # return a copy to avoid changes overwrite the original - return dict(self.metadata) if self.metadata else None - - def _get_metadata(self, key): - if not self.is_validated: - self.validate() - return self.metadata.get(key) - - def get_author(self): - return self._get_metadata('Created-By') - - def get_version(self): - return self._get_metadata('CSAR-Version') - - def get_main_template(self): - entry_def = self._get_metadata('Entry-Definitions') - if entry_def in self.zfile.namelist(): - return entry_def - - def get_main_template_yaml(self): - main_template = self.get_main_template() - if main_template: - data = self.zfile.read(main_template) - invalid_tosca_yaml_err_msg = ( - _('The file "%(template)s" in the CSAR "%(csar)s" does not ' - 'contain valid TOSCA YAML content.') % - {'template': main_template, 'csar': self.path}) - try: - tosca_yaml = yaml.load(data) - if type(tosca_yaml) is not dict: - ExceptionCollector.appendException( - ValidationError(message=invalid_tosca_yaml_err_msg)) - return tosca_yaml - except Exception: - ExceptionCollector.appendException( - ValidationError(message=invalid_tosca_yaml_err_msg)) - - def get_description(self): - desc = self._get_metadata('Description') - if desc is not None: - return desc - - self.metadata['Description'] = \ - self.get_main_template_yaml().get('description') - return self.metadata['Description'] - - def decompress(self): - if not self.is_validated: - self.validate() - self.temp_dir = tempfile.NamedTemporaryFile().name - with zipfile.ZipFile(self.csar, "r") as zf: - zf.extractall(self.temp_dir) - - def _validate_external_references(self): - """Extracts files referenced in the main template - - These references are currently supported: - * imports - * interface implementations - * artifacts - """ - try: - self.decompress() - main_tpl_file = self.get_main_template() - if not main_tpl_file: - return - main_tpl = self.get_main_template_yaml() - - if 'imports' in main_tpl: - ImportsLoader(main_tpl['imports'], - os.path.join(self.temp_dir, main_tpl_file)) - - if 'topology_template' in main_tpl: - topology_template = main_tpl['topology_template'] - - if 'node_templates' in topology_template: - node_templates = topology_template['node_templates'] - - for node_template_key in node_templates: - node_template = node_templates[node_template_key] - if 'artifacts' in node_template: - artifacts = node_template['artifacts'] - for artifact_key in artifacts: - artifact = artifacts[artifact_key] - if isinstance(artifact, six.string_types): - self._validate_external_reference( - main_tpl_file, - artifact) - elif isinstance(artifact, dict): - if 'file' in artifact: - self._validate_external_reference( - main_tpl_file, - artifact['file']) - else: - ExceptionCollector.appendException( - ValueError(_('Unexpected artifact ' - 'definition for "%s".') - % artifact_key)) - self.error_caught = True - if 'interfaces' in node_template: - interfaces = node_template['interfaces'] - for interface_key in interfaces: - interface = interfaces[interface_key] - for opertation_key in interface: - operation = interface[opertation_key] - if isinstance(operation, six.string_types): - self._validate_external_reference( - main_tpl_file, - operation, - False) - elif isinstance(operation, dict): - if 'implementation' in operation: - self._validate_external_reference( - main_tpl_file, - operation['implementation']) - finally: - if self.temp_dir: - shutil.rmtree(self.temp_dir) - - def _validate_external_reference(self, tpl_file, resource_file, - raise_exc=True): - """Verify that the external resource exists - - If resource_file is a URL verify that the URL is valid. - If resource_file is a relative path verify that the path is valid - considering base folder (self.temp_dir) and tpl_file. - Note that in a CSAR resource_file cannot be an absolute path. - """ - if UrlUtils.validate_url(resource_file): - msg = (_('The resource at "%s" cannot be accessed.') % - resource_file) - try: - if UrlUtils.url_accessible(resource_file): - return - else: - ExceptionCollector.appendException( - URLException(what=msg)) - self.error_caught = True - except Exception: - ExceptionCollector.appendException( - URLException(what=msg)) - self.error_caught = True - - if os.path.isfile(os.path.join(self.temp_dir, - os.path.dirname(tpl_file), - resource_file)): - return - - if raise_exc: - ExceptionCollector.appendException( - ValueError(_('The resource "%s" does not exist.') - % resource_file)) - self.error_caught = True diff --git a/nfvparser/src/main/python/toscaparser/properties.py b/nfvparser/src/main/python/toscaparser/properties.py deleted file mode 100644 index c69b151..0000000 --- a/nfvparser/src/main/python/toscaparser/properties.py +++ /dev/null @@ -1,77 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from toscaparser.dataentity import DataEntity -from toscaparser.elements.constraints import Schema -from toscaparser.functions import is_function - - -class Property(object): - '''TOSCA built-in Property type.''' - - PROPERTY_KEYS = ( - TYPE, REQUIRED, DESCRIPTION, DEFAULT, CONSTRAINTS - ) = ( - 'type', 'required', 'description', 'default', 'constraints' - ) - - ENTRY_SCHEMA_KEYS = ( - ENTRYTYPE, ENTRYPROPERTIES - ) = ( - 'type', 'properties' - ) - - def __init__(self, property_name, value, schema_dict, custom_def=None): - self.name = property_name - self.value = value - self.custom_def = custom_def - self.schema = Schema(property_name, schema_dict) - - @property - def type(self): - return self.schema.type - - @property - def required(self): - return self.schema.required - - @property - def description(self): - return self.schema.description - - @property - def default(self): - return self.schema.default - - @property - def constraints(self): - return self.schema.constraints - - @property - def entry_schema(self): - return self.schema.entry_schema - - def validate(self): - '''Validate if not a reference property.''' - if not is_function(self.value): - if self.type == Schema.STRING: - self.value = str(self.value) - self.value = DataEntity.validate_datatype(self.type, self.value, - self.entry_schema, - self.custom_def, - self.name) - self._validate_constraints() - - def _validate_constraints(self): - if self.constraints: - for constraint in self.constraints: - constraint.validate(self.value) diff --git a/nfvparser/src/main/python/toscaparser/relationship_template.py b/nfvparser/src/main/python/toscaparser/relationship_template.py deleted file mode 100644 index db334c4..0000000 --- a/nfvparser/src/main/python/toscaparser/relationship_template.py +++ /dev/null @@ -1,78 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - - -import logging - -from toscaparser.entity_template import EntityTemplate -from toscaparser.properties import Property - -SECTIONS = (DERIVED_FROM, PROPERTIES, REQUIREMENTS, - INTERFACES, CAPABILITIES, TYPE) = \ - ('derived_from', 'properties', 'requirements', 'interfaces', - 'capabilities', 'type') - -log = logging.getLogger('tosca') - - -class RelationshipTemplate(EntityTemplate): - '''Relationship template.''' - def __init__(self, relationship_template, name, custom_def=None, - target=None, source=None): - super(RelationshipTemplate, self).__init__(name, - relationship_template, - 'relationship_type', - custom_def) - self.name = name.lower() - self.target = target - self.source = source - - def get_properties_objects(self): - '''Return properties objects for this template.''' - if self._properties is None: - self._properties = self._create_relationship_properties() - return self._properties - - def _create_relationship_properties(self): - props = [] - properties = {} - relationship = self.entity_tpl.get('relationship') - - if not relationship: - for value in self.entity_tpl.values(): - if isinstance(value, dict): - relationship = value.get('relationship') - break - - if relationship: - properties = self.type_definition.get_value(self.PROPERTIES, - relationship) or {} - if not properties: - properties = self.entity_tpl.get(self.PROPERTIES) or {} - - if properties: - for name, value in properties.items(): - props_def = self.type_definition.get_properties_def() - if props_def and name in props_def: - if name in properties.keys(): - value = properties.get(name) - prop = Property(name, value, - props_def[name].schema, self.custom_def) - props.append(prop) - for p in self.type_definition.get_properties_def_objects(): - if p.default is not None and p.name not in properties.keys(): - prop = Property(p.name, p.default, p.schema, self.custom_def) - props.append(prop) - return props - - def validate(self): - self._validate_properties(self.entity_tpl, self.type_definition) diff --git a/nfvparser/src/main/python/toscaparser/repositories.py b/nfvparser/src/main/python/toscaparser/repositories.py deleted file mode 100644 index 184eba4..0000000 --- a/nfvparser/src/main/python/toscaparser/repositories.py +++ /dev/null @@ -1,52 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import MissingRequiredFieldError -from toscaparser.common.exception import UnknownFieldError -from toscaparser.common.exception import URLException -from toscaparser.utils.gettextutils import _ -import toscaparser.utils.urlutils - -SECTIONS = (DESCRIPTION, URL, CREDENTIAL) = \ - ('description', 'url', 'credential') - - -class Repository(object): - def __init__(self, repositories, values): - self.name = repositories - self.reposit = values - if isinstance(self.reposit, dict): - if 'url' not in self.reposit.keys(): - ExceptionCollector.appendException( - MissingRequiredFieldError(what=_('Repository "%s"') - % self.name, required='url')) - self.url = self.reposit['url'] - self.load_and_validate(self.name, self.reposit) - - def load_and_validate(self, val, reposit_def): - self.keyname = val - if isinstance(reposit_def, dict): - for key in reposit_def.keys(): - if key not in SECTIONS: - ExceptionCollector.appendException( - UnknownFieldError(what=_('repositories "%s"') - % self.keyname, field=key)) - - if URL in reposit_def.keys(): - reposit_url = reposit_def.get(URL) - url_val = toscaparser.utils.urlutils.UrlUtils.\ - validate_url(reposit_url) - if url_val is not True: - ExceptionCollector.appendException( - URLException(what=_('repsositories "%s" Invalid Url') - % self.keyname)) diff --git a/nfvparser/src/main/python/toscaparser/shell.py b/nfvparser/src/main/python/toscaparser/shell.py deleted file mode 100644 index 1d98f1a..0000000 --- a/nfvparser/src/main/python/toscaparser/shell.py +++ /dev/null @@ -1,120 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - - -import argparse -import os -import sys - -from toscaparser.tosca_template import ToscaTemplate -from toscaparser.utils.gettextutils import _ -import toscaparser.utils.urlutils - -""" -CLI entry point to show how TOSCA Parser can be used programmatically - -This is a basic command line utility showing the entry point in the -TOSCA Parser and how to iterate over parsed template. It can be extended -or modified to fit an individual need. - -It can be used as, -#tosca-parser --template-file= -#tosca-parser --template-file= -#tosca-parser --template-file= - -e.g. -#tosca-parser - --template-file=toscaparser/tests/data/tosca_helloworld.yaml -#tosca-parser - --template-file=toscaparser/tests/data/CSAR/csar_hello_world.zip -""" - - -class ParserShell(object): - - def get_parser(self, argv): - parser = argparse.ArgumentParser(prog="tosca-parser") - - parser.add_argument('--template-file', - metavar='', - required=True, - help=_('YAML template or CSAR file to parse.')) - - return parser - - def main(self, argv): - parser = self.get_parser(argv) - (args, extra_args) = parser.parse_known_args(argv) - path = args.template_file - if os.path.isfile(path): - self.parse(path) - elif toscaparser.utils.urlutils.UrlUtils.validate_url(path): - self.parse(path, False) - else: - raise ValueError(_('"%(path)s" is not a valid file.') - % {'path': path}) - - def parse(self, path, a_file=True): - output = None - tosca = ToscaTemplate(path, None, a_file) - - version = tosca.version - if tosca.version: - print("\nversion: " + version) - - if hasattr(tosca, 'description'): - description = tosca.description - if description: - print("\ndescription: " + description) - - if hasattr(tosca, 'inputs'): - inputs = tosca.inputs - if inputs: - print("\ninputs:") - for input in inputs: - print("\t" + input.name) - - if hasattr(tosca, 'nodetemplates'): - nodetemplates = tosca.nodetemplates - if nodetemplates: - print("\nnodetemplates:") - for node in nodetemplates: - print("\t" + node.name) - - # example of retrieving policy object - '''if hasattr(tosca, 'policies'): - policies = tosca.policies - if policies: - print("policies:") - for policy in policies: - print("\t" + policy.name) - if policy.triggers: - print("\ttriggers:") - for trigger in policy.triggers: - print("\ttrigger name:" + trigger.name)''' - - if hasattr(tosca, 'outputs'): - outputs = tosca.outputs - if outputs: - print("\noutputs:") - for output in outputs: - print("\t" + output.name) - - -def main(args=None): - if args is None: - args = sys.argv[1:] - ParserShell().main(args) - - -if __name__ == '__main__': - main() diff --git a/nfvparser/src/main/python/toscaparser/substitution_mappings.py b/nfvparser/src/main/python/toscaparser/substitution_mappings.py deleted file mode 100644 index dea5de7..0000000 --- a/nfvparser/src/main/python/toscaparser/substitution_mappings.py +++ /dev/null @@ -1,228 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import logging - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import InvalidNodeTypeError -from toscaparser.common.exception import MissingDefaultValueError -from toscaparser.common.exception import MissingRequiredFieldError -from toscaparser.common.exception import MissingRequiredInputError -from toscaparser.common.exception import MissingRequiredOutputError -from toscaparser.common.exception import UnknownFieldError -from toscaparser.common.exception import UnknownOutputError -from toscaparser.elements.nodetype import NodeType -from toscaparser.utils.gettextutils import _ - -log = logging.getLogger('tosca') - - -class SubstitutionMappings(object): - '''SubstitutionMappings class declaration - - SubstitutionMappings exports the topology template as an - implementation of a Node type. - ''' - - SECTIONS = (NODE_TYPE, REQUIREMENTS, CAPABILITIES) = \ - ('node_type', 'requirements', 'capabilities') - - OPTIONAL_OUTPUTS = ['tosca_id', 'tosca_name', 'state'] - - def __init__(self, sub_mapping_def, nodetemplates, inputs, outputs, - sub_mapped_node_template, custom_defs): - self.nodetemplates = nodetemplates - self.sub_mapping_def = sub_mapping_def - self.inputs = inputs or [] - self.outputs = outputs or [] - self.sub_mapped_node_template = sub_mapped_node_template - self.custom_defs = custom_defs or {} - self._validate() - - self._capabilities = None - self._requirements = None - - @property - def type(self): - if self.sub_mapping_def: - return self.sub_mapping_def.get(self.NODE_TYPE) - - @classmethod - def get_node_type(cls, sub_mapping_def): - if isinstance(sub_mapping_def, dict): - return sub_mapping_def.get(cls.NODE_TYPE) - - @property - def node_type(self): - return self.sub_mapping_def.get(self.NODE_TYPE) - - @property - def capabilities(self): - return self.sub_mapping_def.get(self.CAPABILITIES) - - @property - def requirements(self): - return self.sub_mapping_def.get(self.REQUIREMENTS) - - @property - def node_definition(self): - return NodeType(self.node_type, self.custom_defs) - - def _validate(self): - # Basic validation - self._validate_keys() - self._validate_type() - - # SubstitutionMapping class syntax validation - self._validate_inputs() - self._validate_capabilities() - self._validate_requirements() - self._validate_outputs() - - def _validate_keys(self): - """validate the keys of substitution mappings.""" - for key in self.sub_mapping_def.keys(): - if key not in self.SECTIONS: - ExceptionCollector.appendException( - UnknownFieldError(what=_('SubstitutionMappings'), - field=key)) - - def _validate_type(self): - """validate the node_type of substitution mappings.""" - node_type = self.sub_mapping_def.get(self.NODE_TYPE) - if not node_type: - ExceptionCollector.appendException( - MissingRequiredFieldError( - what=_('SubstitutionMappings used in topology_template'), - required=self.NODE_TYPE)) - - node_type_def = self.custom_defs.get(node_type) - if not node_type_def: - ExceptionCollector.appendException( - InvalidNodeTypeError(what=node_type)) - - def _validate_inputs(self): - """validate the inputs of substitution mappings. - - The inputs defined by the topology template have to match the - properties of the node type or the substituted node template. If - there are more inputs than the substituted node has properties, - default values must be defined for those inputs. - """ - - all_inputs = set([input.name for input in self.inputs]) - required_properties = set([p.name for p in - self.node_definition. - get_properties_def_objects() - if p.required and p.default is None]) - # Must provide inputs for required properties of node type. - for property in required_properties: - # Check property which is 'required' and has no 'default' value - if property not in all_inputs: - ExceptionCollector.appendException( - MissingRequiredInputError( - what=_('SubstitutionMappings with node_type ') - + self.node_type, - input_name=property)) - - # If the optional properties of node type need to be customized by - # substituted node, it also is necessary to define inputs for them, - # otherwise they are not mandatory to be defined. - customized_parameters = set(self.sub_mapped_node_template - .get_properties().keys() - if self.sub_mapped_node_template else []) - all_properties = set(self.node_definition.get_properties_def()) - for parameter in customized_parameters - all_inputs: - if parameter in all_properties: - ExceptionCollector.appendException( - MissingRequiredInputError( - what=_('SubstitutionMappings with node_type ') - + self.node_type, - input_name=parameter)) - - # Additional inputs are not in the properties of node type must - # provide default values. Currently the scenario may not happen - # because of parameters validation in nodetemplate, here is a - # guarantee. - for input in self.inputs: - if input.name in all_inputs - all_properties \ - and input.default is None: - ExceptionCollector.appendException( - MissingDefaultValueError( - what=_('SubstitutionMappings with node_type ') - + self.node_type, - input_name=input.name)) - - def _validate_capabilities(self): - """validate the capabilities of substitution mappings.""" - - # The capabilites must be in node template wchich be mapped. - tpls_capabilities = self.sub_mapping_def.get(self.CAPABILITIES) - node_capabiliteys = self.sub_mapped_node_template.get_capabilities() \ - if self.sub_mapped_node_template else None - for cap in node_capabiliteys.keys() if node_capabiliteys else []: - if (tpls_capabilities and - cap not in list(tpls_capabilities.keys())): - pass - # ExceptionCollector.appendException( - # UnknownFieldError(what='SubstitutionMappings', - # field=cap)) - - def _validate_requirements(self): - """validate the requirements of substitution mappings.""" - - # The requirements must be in node template wchich be mapped. - tpls_requirements = self.sub_mapping_def.get(self.REQUIREMENTS) - node_requirements = self.sub_mapped_node_template.requirements \ - if self.sub_mapped_node_template else None - for req in node_requirements if node_requirements else []: - if (tpls_requirements and - req not in list(tpls_requirements.keys())): - pass - # ExceptionCollector.appendException( - # UnknownFieldError(what='SubstitutionMappings', - # field=req)) - - def _validate_outputs(self): - """validate the outputs of substitution mappings. - - The outputs defined by the topology template have to match the - attributes of the node type or the substituted node template, - and the observable attributes of the substituted node template - have to be defined as attributes of the node type or outputs in - the topology template. - """ - - # The outputs defined by the topology template have to match the - # attributes of the node type according to the specification, but - # it's reasonable that there are more inputs than the node type - # has properties, the specification will be amended? - for output in self.outputs: - if output.name not in self.node_definition.get_attributes_def(): - ExceptionCollector.appendException( - UnknownOutputError( - where=_('SubstitutionMappings with node_type ') - + self.node_type, - output_name=output.name)) - - # The observable attributes of the substituted node template - # have to be defined as attributes of the node type or outputs in - # the topology template, the attributes in tosca.node.root are - # optional. - for attribute in self.node_definition.get_attributes_def(): - if attribute not in [output.name for output in self.outputs] \ - and attribute not in self.OPTIONAL_OUTPUTS: - ExceptionCollector.appendException( - MissingRequiredOutputError( - what=_('SubstitutionMappings with node_type ') - + self.node_type, - output_name=attribute)) diff --git a/nfvparser/src/main/python/toscaparser/tests/__init__.py b/nfvparser/src/main/python/toscaparser/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/collectd/config.py b/nfvparser/src/main/python/toscaparser/tests/artifacts/collectd/config.py deleted file mode 100644 index 686bbd1..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/collectd/config.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/python - -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -# This script configures collectd to send metric data to the -# logstash server port 25826 -# The environment variable logstash_ip is expected to be set up -import os -with open("/etc/collectd/collectd.conf.d/tosca_elk.conf", "w") as fh: - fh.write(""" - LoadPlugin network - - Server "%s" "25826" - - """ % (os.environ['logstash_ip'])) diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/collectd/create.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/collectd/create.sh deleted file mode 100644 index a483b88..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/collectd/create.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -# This script install collectd for monitoring data - -apt-get update -apt-get install -y collectd diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/collectd/start.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/collectd/start.sh deleted file mode 100644 index 7e8e033..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/collectd/start.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -# This script starts collectd as a service in init.d -service collectd stop -service collectd start diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/elasticsearch/create.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/elasticsearch/create.sh deleted file mode 100644 index c34126c..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/elasticsearch/create.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -# This script installs java and elasticsearch - -apt-get update -apt-get install -y openjdk-7-jre-headless - -wget -qO - https://packages.elasticsearch.org/GPG-KEY-elasticsearch | apt-key add - -echo "deb http://packages.elasticsearch.org/elasticsearch/1.5/debian stable main" | tee -a /etc/apt/sources.list - -apt-get update -apt-get install -y elasticsearch - -# set up to run as service -update-rc.d elasticsearch defaults 95 10 diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/elasticsearch/start.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/elasticsearch/start.sh deleted file mode 100644 index bbc0347..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/elasticsearch/start.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -# This script starts elasticsearch as a service in init.d -service elasticsearch stop -service elasticsearch start diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/kibana/config.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/kibana/config.sh deleted file mode 100644 index f28215a..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/kibana/config.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -# This script configures kibana to connect to the elasticsearch server -# to access data and to export the app url on port 5601: -# The environment variable elasticsearch_ip and kibana_ip are expected -# to be set up. -sed -i 's/localhost/'$elasticsearch_ip'/' /opt/kibana/config/kibana.yml -sed -i 's/0.0.0.0/'$kibana_ip'/' /opt/kibana/config/kibana.yml diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/kibana/create.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/kibana/create.sh deleted file mode 100644 index 41914b1..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/kibana/create.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# This script installs kibana and sets it up to run as a service in init.d -cd /opt -wget https://download.elastic.co/kibana/kibana/kibana-4.1.0-linux-x64.tar.gz -tar xzvf kibana-4.1.0-linux-x64.tar.gz -mv kibana-4.1.0-linux-x64 kibana - -# set up to run as service -cd /etc/init.d -wget https://gist.githubusercontent.com/thisismitch/8b15ac909aed214ad04a/raw/bce61d85643c2dcdfbc2728c55a41dab444dca20/kibana4 -chmod +x kibana4 -update-rc.d kibana4 defaults 96 9 diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/kibana/start.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/kibana/start.sh deleted file mode 100644 index 5149bb3..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/kibana/start.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -# This script starts kibana as a service in init.d -service kibana4 stop -service kibana4 start diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/logstash/configure_collectd.py b/nfvparser/src/main/python/toscaparser/tests/artifacts/logstash/configure_collectd.py deleted file mode 100644 index 18fdacf..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/logstash/configure_collectd.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/python - -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -# This script configures the logstash input using the udp protocol on -# port 25826. This is intended to receive data from collectd from -# any source -with open("/etc/logstash/conf.d/collectd.conf", "w") as fh: - fh.write(""" - input { - udp { - port => 25826 # 25826 is the default for collectd - buffer_size => 1452 # 1452 is the default for collectd - codec => collectd { } - tags => ["metrics"] - type => "collectd" - } - }""") diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/logstash/configure_elasticsearch.py b/nfvparser/src/main/python/toscaparser/tests/artifacts/logstash/configure_elasticsearch.py deleted file mode 100644 index 2e5389c..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/logstash/configure_elasticsearch.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/python - -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -# This script configures the logstash output to forward to elasticsearch -# The environment variable elasticsearch_ip is expected to be set up -import os -with open("/etc/logstash/conf.d/elasticsearch.conf", 'w') as fh: - fh.write(""" - output { - elasticsearch { - action => index - host => "%s" - protocol => "http" - } - }""" % (os.environ['elasticsearch_ip'])) diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/logstash/configure_rsyslog.py b/nfvparser/src/main/python/toscaparser/tests/artifacts/logstash/configure_rsyslog.py deleted file mode 100644 index fc610c2..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/logstash/configure_rsyslog.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/python - -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -# This script configures the logstash input using the RELP protocol on -# port 2514 This is intended to receive logs from rsyslog from -# any source -with open("/etc/logstash/conf.d/rsyslog.conf", "w") as fh: - fh.write(""" - input { - relp { - port => 2514 - tags => ["logs"] - } - }""") diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/logstash/create.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/logstash/create.sh deleted file mode 100644 index 77cc8fd..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/logstash/create.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -# This script installs java, logstash and the contrib package for logstash -# install java as prereq - -apt-get update -apt-get install -y openjdk-7-jre-headless -mkdir /etc/logstash - -# install by apt-get from repo -wget -O - http://packages.elasticsearch.org/GPG-KEY-elasticsearch | apt-key add - -echo "deb http://packages.elasticsearch.org/logstash/1.4/debian stable main" | tee -a /etc/apt/sources.list - -apt-get update -apt-get install -y logstash - -# install contrib to get the relp plugin -/opt/logstash/bin/plugin install contrib - -# set up to run as service -update-rc.d logstash defaults 95 10 diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/logstash/start.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/logstash/start.sh deleted file mode 100644 index a73cf61..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/logstash/start.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -# Run logstash as service in init.d -service logstash stop -service logstash start diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/mongodb/config.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/mongodb/config.sh deleted file mode 100644 index 78f484e..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/mongodb/config.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -# Edit the file /etc/mongod.conf, update with real IP of Mongo server -# This script configures the mongodb server to export its service on -# the server IP -# bind_ip = 127.0.0.1 -> bind_ip = -# The environment variable mongodb_ip is expected to be set up -sed -i "s/= 127.0.0.1/= $mongodb_ip,127.0.0.1/" /etc/mongod.conf diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/mongodb/create.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/mongodb/create.sh deleted file mode 100644 index d84c275..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/mongodb/create.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -# This script installs mongodb - -apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 -echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.0.list - -apt-get update -apt-get install -y mongodb-org - -#Wait for mongodb initialization -while [[ ! -d "/var/lib/mongodb/_tmp" ]]; do - echo "Waiting for mongodb initialization ..." - sleep 5 -done diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/mongodb/create_database.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/mongodb/create_database.sh deleted file mode 100644 index 16f1358..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/mongodb/create_database.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -echo "conn = new Mongo();" > setup.js -echo "db = conn.getDB('paypal_pizza');" >> setup.js -echo "db.about.insert({'name': 'PayPal Pizza Store'});" >> setup.js -mongo setup.js diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/mongodb/start.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/mongodb/start.sh deleted file mode 100644 index ac200a5..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/mongodb/start.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -# This script starts mongodb -service mongod stop -rm /var/lib/mongodb/mongod.lock -service mongod start diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/mysql/mysql_database_configure.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/mysql/mysql_database_configure.sh deleted file mode 100644 index 092136a..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/mysql/mysql_database_configure.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -cat << EOF | mysql -u root --password=$db_root_password -CREATE DATABASE $db_name; -GRANT ALL PRIVILEGES ON $db_name.* TO "$db_user"@"localhost" -IDENTIFIED BY "$db_password"; -FLUSH PRIVILEGES; -EXIT -EOF \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/mysql/mysql_dbms_configure.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/mysql/mysql_dbms_configure.sh deleted file mode 100644 index d4ef6b4..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/mysql/mysql_dbms_configure.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -sed --regexp-extended "s/(port\s*=\s*)[0-9]*/\1$db_port/g" /tmp/my.cnf -mv -f /tmp/my.cnf /etc/mysql/my.cnf -/etc/init.d/mysql stop -/etc/init.d/mysql start \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/mysql/mysql_dbms_install.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/mysql/mysql_dbms_install.sh deleted file mode 100644 index 38628b9..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/mysql/mysql_dbms_install.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -#This script installs mysql server - -apt-get update - -debconf-set-selections <<< "mysql-server mysql-server/root_password password $db_root_password" -debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $db_root_password" - -apt-get -y install --fix-missing mysql-server \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/mysql/mysql_dbms_start.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/mysql/mysql_dbms_start.sh deleted file mode 100644 index 3378670..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/mysql/mysql_dbms_start.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -/etc/init.d/mysql start \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/nodejs/config.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/nodejs/config.sh deleted file mode 100644 index 1e149a2..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/nodejs/config.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -# This script installs an app for nodejs: the app intended is the paypal app -# and it is configured to connect to the mongodb server -# The environment variables github_url and mongodb_ip are expected to be set up -export app_dir=/opt/app -git clone $github_url /opt/app -if [ -f /opt/app/package.json ]; then - cd /opt/app/ && npm install - sed -i "s/localhost/$mongodb_ip/" config.json -fi - -cat > /etc/init/nodeapp.conf <> /var/log/nodeapp.log 2>&1 & -end script -EOS diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/nodejs/create.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/nodejs/create.sh deleted file mode 100644 index 04fd6c6..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/nodejs/create.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -# This script installs nodejs and the prereq - -add-apt-repository ppa:chris-lea/node.js - -apt-get update -apt-get install -y nodejs build-essential diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/nodejs/start.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/nodejs/start.sh deleted file mode 100644 index 6939cb7..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/nodejs/start.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -# This script starts the nodejs application -start nodeapp diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/rsyslog/config.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/rsyslog/config.sh deleted file mode 100644 index 630767d..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/rsyslog/config.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -# This script configures the output for rsyslogd to send logs to the -# logstash server port 2514 using the RELP protocol -# The environment variable logstash_ip is expected to be set up -echo "module(load=\"omrelp\") -action(type=\"omrelp\" target=\"$logstash_ip\" port=\"2514\")" > /etc/rsyslog.d/tosca_elk.conf - -# Remove the /dev/xconsole configuration as xconsole -# is not available by default -l=`awk '/=warn.*\|.*\/dev\/xconsole/{print NR - 1}' /etc/rsyslog.d/50-default.conf` -if [ ! -z $l ]; then - l=`expr $l + 1` - line=`cat /etc/rsyslog.d/50-default.conf | head -n $l | tail -1` - if [[ ! $line == \#* ]]; then - l0=`expr $l - 3` - sed -i -r -e "${l0},${l}s/^.{0}/&#/" /etc/rsyslog.d/50-default.conf - fi -fi - -# Enable nodejs logs for rsyslog -if ! grep -q nodeapp "/etc/rsyslog.conf"; then - sed -i 's/\$PrivDropToGroup\ syslog/\$PrivDropToGroup adm/' /etc/rsyslog.conf - echo "\$ModLoad imfile.so -\$InputFileName /var/log/nodeapp.log -\$InputFileTag paypal_pizza: -\$InputFileStateFile stat-nodeapp -\$InputRunFileMonitor -\$InputFilePollInterval 1" >> /etc/rsyslog.conf -fi diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/rsyslog/create.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/rsyslog/create.sh deleted file mode 100644 index affdd6e..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/rsyslog/create.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -# This script installs rsyslog and the library for RELP - -apt-get update -apt-get install -y rsyslog rsyslog-relp diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/rsyslog/start.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/rsyslog/start.sh deleted file mode 100644 index 3de82d1..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/rsyslog/start.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -# This script starts rsyslogd as a service in init.d -service rsyslog stop -service rsyslog start diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/webserver/webserver_install.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/webserver/webserver_install.sh deleted file mode 100644 index 4ca9b4e..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/webserver/webserver_install.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -#This script installs apache web server - -apt-get update -apt-get install -y apache2 \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/webserver/webserver_start.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/webserver/webserver_start.sh deleted file mode 100644 index e962ca5..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/webserver/webserver_start.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -service apache2 start \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/wordpress/wordpress_configure.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/wordpress/wordpress_configure.sh deleted file mode 100644 index 5598b4f..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/wordpress/wordpress_configure.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -ln -s /usr/share/wordpress /var/www/html/wordpress -gzip -d /usr/share/doc/wordpress/examples/setup-mysql.gz -echo $wp_db_password | bash /usr/share/doc/wordpress/examples/setup-mysql -e $wp_db_name -u $wp_db_user localhost \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/artifacts/wordpress/wordpress_install.sh b/nfvparser/src/main/python/toscaparser/tests/artifacts/wordpress/wordpress_install.sh deleted file mode 100644 index 1320443..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/artifacts/wordpress/wordpress_install.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -#This script installs wordpress - -apt-get update -apt-get install -y wordpress \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/base.py b/nfvparser/src/main/python/toscaparser/tests/base.py deleted file mode 100644 index 2619889..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/base.py +++ /dev/null @@ -1,65 +0,0 @@ -# Copyright 2010-2011 OpenStack Foundation -# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import os - -import fixtures -import testscenarios -import testtools - -from toscaparser.tosca_template import ToscaTemplate - -_TRUE_VALUES = ('True', 'true', '1', 'yes') - - -class TestCase(testscenarios.TestWithScenarios, testtools.TestCase): - - """Test case base class for all unit tests.""" - - def setUp(self): - """Run before each test method to initialize test environment.""" - - super(TestCase, self).setUp() - test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) - try: - test_timeout = int(test_timeout) - except ValueError: - # If timeout value is invalid do not set a timeout. - test_timeout = 0 - if test_timeout > 0: - self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) - - self.useFixture(fixtures.NestedTempfile()) - self.useFixture(fixtures.TempHomeDir()) - - if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES: - stdout = self.useFixture(fixtures.StringStream('stdout')).stream - self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) - if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES: - stderr = self.useFixture(fixtures.StringStream('stderr')).stream - self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) - - self.log_fixture = self.useFixture(fixtures.FakeLogger()) - - def _load_template(self, filename): - """Load a Tosca template from tests data folder. - - :param filename: Tosca template file name to load. - :return: ToscaTemplate - """ - return ToscaTemplate(os.path.join( - os.path.dirname(os.path.abspath(__file__)), - 'data', - filename)) diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_elk.csar b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_elk.csar deleted file mode 100644 index a514dc6..0000000 Binary files a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_elk.csar and /dev/null differ diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_elk.zip b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_elk.zip deleted file mode 100644 index 0d860d4..0000000 Binary files a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_elk.zip and /dev/null differ diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_hello_world.zip b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_hello_world.zip deleted file mode 100644 index 43ffbbc..0000000 Binary files a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_hello_world.zip and /dev/null differ diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_invalid_entry_def.zip b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_invalid_entry_def.zip deleted file mode 100644 index 382f790..0000000 Binary files a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_invalid_entry_def.zip and /dev/null differ diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_metadata_not_yaml.zip b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_metadata_not_yaml.zip deleted file mode 100644 index 3e6120b..0000000 Binary files a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_metadata_not_yaml.zip and /dev/null differ diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_missing_metadata.zip b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_missing_metadata.zip deleted file mode 100644 index 5ec7a99..0000000 Binary files a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_missing_metadata.zip and /dev/null differ diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_no_metadata_file.zip b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_no_metadata_file.zip deleted file mode 100644 index b0df9b9..0000000 Binary files a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_no_metadata_file.zip and /dev/null differ diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_not_zip.zip b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_not_zip.zip deleted file mode 100644 index 43b7f5f..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_not_zip.zip +++ /dev/null @@ -1 +0,0 @@ -This is an invalid CSAR file. \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress.zip b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress.zip deleted file mode 100644 index 5df7b48..0000000 Binary files a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress.zip and /dev/null differ diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress_invalid_import_path.zip b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress_invalid_import_path.zip deleted file mode 100644 index 9dc6c9a..0000000 Binary files a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress_invalid_import_path.zip and /dev/null differ diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress_invalid_import_url.zip b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress_invalid_import_url.zip deleted file mode 100644 index c7a260f..0000000 Binary files a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress_invalid_import_url.zip and /dev/null differ diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress_invalid_script_path.zip b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress_invalid_script_path.zip deleted file mode 100644 index 5e4f9e0..0000000 Binary files a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress_invalid_script_path.zip and /dev/null differ diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress_invalid_script_url.zip b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress_invalid_script_url.zip deleted file mode 100644 index b4133b6..0000000 Binary files a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress_invalid_script_url.zip and /dev/null differ diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress_with_url_import_and_script.zip b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress_with_url_import_and_script.zip deleted file mode 100644 index 5dedfcd..0000000 Binary files a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wordpress_with_url_import_and_script.zip and /dev/null differ diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wrong_metadata_file.zip b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wrong_metadata_file.zip deleted file mode 100644 index 85d660a..0000000 Binary files a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/csar_wrong_metadata_file.zip and /dev/null differ diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/collectd.yaml b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/collectd.yaml deleted file mode 100644 index 1ac0935..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/collectd.yaml +++ /dev/null @@ -1,13 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - collectd is a daemon which gathers statistics about the system it is running on. - -node_types: - tosca.nodes.SoftwareComponent.Collectd: - derived_from: tosca.nodes.SoftwareComponent - requirements: - - log_endpoint: - capability: tosca.capabilities.Endpoint - node: tosca.nodes.SoftwareComponent.Logstash - relationship: tosca.relationships.ConnectsTo \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/elasticsearch.yaml b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/elasticsearch.yaml deleted file mode 100644 index 4a1770f..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/elasticsearch.yaml +++ /dev/null @@ -1,11 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Elasticsearch is an open-source search engine built on top of Apache Lucene, a full-text search-engine library. - -node_types: - tosca.nodes.SoftwareComponent.Elasticsearch: - derived_from: tosca.nodes.SoftwareComponent - capabilities: - search_endpoint: - type: tosca.capabilities.Endpoint diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/kibana.yaml b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/kibana.yaml deleted file mode 100644 index 3a4351c..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/kibana.yaml +++ /dev/null @@ -1,16 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Kibana is an open source analytics and visualization platform designed to work with Elasticsearch. - You use Kibana to search, view, and interact with data stored in Elasticsearch. - -node_types: - tosca.nodes.SoftwareComponent.Kibana: - derived_from: tosca.nodes.SoftwareComponent - requirements: - - search_endpoint: - capability: tosca.capabilities.Endpoint - node: tosca.nodes.SoftwareComponent.Elasticsearch - relationship: tosca.relationships.ConnectsTo - - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/logstash.yaml b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/logstash.yaml deleted file mode 100644 index 8495954..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/logstash.yaml +++ /dev/null @@ -1,25 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Logstash is a tool for receiving, processing and outputting logs. All kinds of logs. System logs, webserver logs, - error logs, application logs, and just about anything you can throw at it. - -node_types: - tosca.nodes.SoftwareComponent.Logstash: - derived_from: tosca.nodes.SoftwareComponent - requirements: - - search_endpoint: - capability: tosca.capabilities.Endpoint - node: tosca.nodes.SoftwareComponent.Elasticsearch - relationship: - type: tosca.relationships.ConnectsTo - interfaces: - Configure: - pre_configure_source: - inputs: - elasticsearch_ip: - type: string - capabilities: - log_endpoint: - type: tosca.capabilities.Endpoint - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/paypalpizzastore_nodejs_app.yaml b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/paypalpizzastore_nodejs_app.yaml deleted file mode 100644 index cdabeae..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/paypalpizzastore_nodejs_app.yaml +++ /dev/null @@ -1,29 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Pizza store app that allows you to explore the features provided by PayPal's REST APIs. - More detail can be found at https://github.com/paypal/rest-api-sample-app-nodejs/ - -node_types: - tosca.nodes.WebApplication.PayPalPizzaStore: - derived_from: tosca.nodes.WebApplication - properties: - github_url: - required: false - type: string - description: location of the application on the github. - default: https://github.com/sample.git - requirements: - #WebApplication inherits Computer, so host implied. - - database_connection: - capability: tosca.capabilities.Endpoint.Database - node: tosca.nodes.Database - relationship: tosca.relationships.ConnectsTo - interfaces: - Standard: - configure: - inputs: - github_url: - type: string - mongodb_ip: - type: string diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/rsyslog.yaml b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/rsyslog.yaml deleted file mode 100644 index 4614ee7..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/rsyslog.yaml +++ /dev/null @@ -1,13 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - RSYSLOG is the Rocket-fast SYStem for LOG processing. - -node_types: - tosca.nodes.SoftwareComponent.Rsyslog: - derived_from: tosca.nodes.SoftwareComponent - requirements: - - log_endpoint: - capability: tosca.capabilities.Endpoint - node: tosca.nodes.SoftwareComponent.Logstash - relationship: tosca.relationships.ConnectsTo diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/tosca_elk.yaml b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/tosca_elk.yaml deleted file mode 100644 index 932f131..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Definitions/tosca_elk.yaml +++ /dev/null @@ -1,217 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - This TOSCA simple profile deploys nodejs, mongodb, elasticsearch, logstash and kibana each on a separate server - with monitoring enabled for nodejs server where a sample nodejs application is running. The rsyslog and collectd are - installed on a nodejs server. - -imports: - - paypalpizzastore_nodejs_app.yaml - - elasticsearch.yaml - - logstash.yaml - - kibana.yaml - - collectd.yaml - - rsyslog.yaml - -dsl_definitions: - host_capabilities: &host_capabilities - # container properties (flavor) - disk_size: 10 GB - num_cpus: { get_input: my_cpus } - mem_size: 4096 MB - os_capabilities: &os_capabilities - architecture: x86_64 - type: Linux - distribution: Ubuntu - version: 14.04 - -topology_template: - inputs: - my_cpus: - type: integer - description: Number of CPUs for the server. - constraints: - - valid_values: [ 1, 2, 4, 8 ] - github_url: - type: string - description: The URL to download nodejs. - default: http://github.com/paypal/rest-api-sample-app-nodejs.git - - node_templates: - paypal_pizzastore: - type: tosca.nodes.WebApplication.PayPalPizzaStore - properties: - github_url: { get_input: github_url } - requirements: - - host: nodejs - - database_connection: mongo_db - interfaces: - Standard: - configure: - implementation: ../Scripts/nodejs/config.sh - inputs: - github_url: { get_property: [ SELF, github_url ] } - mongodb_ip: { get_attribute: [mongo_server, private_address] } - start: ../Scripts/nodejs/start.sh - nodejs: - type: tosca.nodes.WebServer - requirements: - - host: - node: app_server - interfaces: - Standard: - create: ../Scripts/nodejs/create.sh - mongo_db: - type: tosca.nodes.Database - requirements: - - host: mongo_dbms - interfaces: - Standard: - create: ../Scripts/mongodb/create_database.sh - mongo_dbms: - type: tosca.nodes.DBMS - requirements: - - host: mongo_server - interfaces: - Standard: - create: ../Scripts/mongodb/create.sh - configure: - implementation: ../Scripts/mongodb/config.sh - inputs: - mongodb_ip: { get_attribute: [mongo_server, private_address] } - start: ../Scripts/mongodb/start.sh - elasticsearch: - type: tosca.nodes.SoftwareComponent.Elasticsearch - requirements: - - host: elasticsearch_server - interfaces: - Standard: - create: ../Scripts/elasticsearch/create.sh - start: ../Scripts/elasticsearch/start.sh - logstash: - type: tosca.nodes.SoftwareComponent.Logstash - requirements: - - host: logstash_server - - search_endpoint: - node: elasticsearch - capability: search_endpoint - relationship: - type: tosca.relationships.ConnectsTo - interfaces: - Configure: - pre_configure_source: - implementation: ../Python/logstash/configure_elasticsearch.py - inputs: - elasticsearch_ip: { get_attribute: [elasticsearch_server, private_address] } - interfaces: - Standard: - create: ../Scripts/logstash/create.sh - start: ../Scripts/logstash/start.sh - kibana: - type: tosca.nodes.SoftwareComponent.Kibana - requirements: - - host: kibana_server - - search_endpoint: elasticsearch - interfaces: - Standard: - create: ../Scripts/kibana/create.sh - configure: - implementation: ../Scripts/kibana/config.sh - inputs: - elasticsearch_ip: { get_attribute: [elasticsearch_server, private_address] } - kibana_ip: { get_attribute: [kibana_server, private_address] } - start: ../Scripts/kibana/start.sh - app_collectd: - type: tosca.nodes.SoftwareComponent.Collectd - requirements: - - host: app_server - - log_endpoint: - node: logstash - capability: log_endpoint - relationship: - type: tosca.relationships.ConnectsTo - interfaces: - Configure: - pre_configure_target: - implementation: ../Python/logstash/configure_collectd.py - interfaces: - Standard: - create: ../Scripts/collectd/create.sh - configure: - implementation: ../Python/collectd/config.py - inputs: - logstash_ip: { get_attribute: [logstash_server, private_address] } - start: ../Scripts/collectd/start.sh - app_rsyslog: - type: tosca.nodes.SoftwareComponent.Rsyslog - requirements: - - host: app_server - - log_endpoint: - node: logstash - capability: log_endpoint - relationship: - type: tosca.relationships.ConnectsTo - interfaces: - Configure: - pre_configure_target: - implementation: ../Python/logstash/configure_rsyslog.py - interfaces: - Standard: - create: ../Scripts/rsyslog/create.sh - configure: - implementation: ../Scripts/rsyslog/config.sh - inputs: - logstash_ip: { get_attribute: [logstash_server, private_address] } - start: ../Scripts/rsyslog/start.sh - app_server: - type: tosca.nodes.Compute - capabilities: - host: - properties: *host_capabilities - os: - properties: *os_capabilities - mongo_server: - type: tosca.nodes.Compute - capabilities: - host: - properties: *host_capabilities - os: - properties: *os_capabilities - elasticsearch_server: - type: tosca.nodes.Compute - capabilities: - host: - properties: *host_capabilities - os: - properties: *os_capabilities - logstash_server: - type: tosca.nodes.Compute - capabilities: - host: - properties: *host_capabilities - os: - properties: *os_capabilities - kibana_server: - type: tosca.nodes.Compute - capabilities: - host: - properties: *host_capabilities - os: - properties: *os_capabilities - - outputs: - nodejs_url: - description: URL for the nodejs server, http://:3000 - value: { get_attribute: [ app_server, private_address ] } - mongodb_url: - description: URL for the mongodb server. - value: { get_attribute: [ mongo_server, private_address ] } - elasticsearch_url: - description: URL for the elasticsearch server. - value: { get_attribute: [ elasticsearch_server, private_address ] } - logstash_url: - description: URL for the logstash server. - value: { get_attribute: [ logstash_server, private_address ] } - kibana_url: - description: URL for the kibana server. - value: { get_attribute: [ kibana_server, private_address ] } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Python/collectd/config.py b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Python/collectd/config.py deleted file mode 100644 index 686bbd1..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Python/collectd/config.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/python - -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -# This script configures collectd to send metric data to the -# logstash server port 25826 -# The environment variable logstash_ip is expected to be set up -import os -with open("/etc/collectd/collectd.conf.d/tosca_elk.conf", "w") as fh: - fh.write(""" - LoadPlugin network - - Server "%s" "25826" - - """ % (os.environ['logstash_ip'])) diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_collectd.py b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_collectd.py deleted file mode 100644 index 18fdacf..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_collectd.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/python - -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -# This script configures the logstash input using the udp protocol on -# port 25826. This is intended to receive data from collectd from -# any source -with open("/etc/logstash/conf.d/collectd.conf", "w") as fh: - fh.write(""" - input { - udp { - port => 25826 # 25826 is the default for collectd - buffer_size => 1452 # 1452 is the default for collectd - codec => collectd { } - tags => ["metrics"] - type => "collectd" - } - }""") diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_elasticsearch.py b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_elasticsearch.py deleted file mode 100644 index 2e5389c..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_elasticsearch.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/python - -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -# This script configures the logstash output to forward to elasticsearch -# The environment variable elasticsearch_ip is expected to be set up -import os -with open("/etc/logstash/conf.d/elasticsearch.conf", 'w') as fh: - fh.write(""" - output { - elasticsearch { - action => index - host => "%s" - protocol => "http" - } - }""" % (os.environ['elasticsearch_ip'])) diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_rsyslog.py b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_rsyslog.py deleted file mode 100644 index fc610c2..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_rsyslog.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/python - -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -# This script configures the logstash input using the RELP protocol on -# port 2514 This is intended to receive logs from rsyslog from -# any source -with open("/etc/logstash/conf.d/rsyslog.conf", "w") as fh: - fh.write(""" - input { - relp { - port => 2514 - tags => ["logs"] - } - }""") diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/README.txt b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/README.txt deleted file mode 100644 index 382c9b0..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/README.txt +++ /dev/null @@ -1,5 +0,0 @@ -README: - -This TOSCA simple profile deploys nodejs, mongodb, elasticsearch, logstash and kibana each on a separate server with monitoring enabled for nodejs server where a sample nodejs application is running. The syslog and collectd are installed on a nodejs server. - -Entry information for processing through an orchestrator is contained in file TOSCA-Metadata/TOSCA.meta. This file provides high-level information such as CSAR version or creator of the CSAR. Furthermore, it provides pointers to the entry template under 'Entry-Definitions' key. The entry template itself may contain pointers to one or more files that are used to define TOSCA base type, unless provided by orchestrator as built-in TOSCA basetypes, and other non-normative types. These are typically provided under 'imports' section in the entry template file. Those type definitions will be read and processed by orchestrator or TOSCA parser to create an internal graph showing dependencies and relationships between various TOSCA types. The entry template may have references to various artifacts required for deployment and will be processed accordingly. diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/collectd/create.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/collectd/create.sh deleted file mode 100644 index a483b88..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/collectd/create.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -# This script install collectd for monitoring data - -apt-get update -apt-get install -y collectd diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/collectd/start.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/collectd/start.sh deleted file mode 100644 index 7e8e033..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/collectd/start.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -# This script starts collectd as a service in init.d -service collectd stop -service collectd start diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/elasticsearch/create.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/elasticsearch/create.sh deleted file mode 100644 index c34126c..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/elasticsearch/create.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -# This script installs java and elasticsearch - -apt-get update -apt-get install -y openjdk-7-jre-headless - -wget -qO - https://packages.elasticsearch.org/GPG-KEY-elasticsearch | apt-key add - -echo "deb http://packages.elasticsearch.org/elasticsearch/1.5/debian stable main" | tee -a /etc/apt/sources.list - -apt-get update -apt-get install -y elasticsearch - -# set up to run as service -update-rc.d elasticsearch defaults 95 10 diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/elasticsearch/start.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/elasticsearch/start.sh deleted file mode 100644 index bbc0347..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/elasticsearch/start.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -# This script starts elasticsearch as a service in init.d -service elasticsearch stop -service elasticsearch start diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/config.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/config.sh deleted file mode 100644 index f28215a..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/config.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -# This script configures kibana to connect to the elasticsearch server -# to access data and to export the app url on port 5601: -# The environment variable elasticsearch_ip and kibana_ip are expected -# to be set up. -sed -i 's/localhost/'$elasticsearch_ip'/' /opt/kibana/config/kibana.yml -sed -i 's/0.0.0.0/'$kibana_ip'/' /opt/kibana/config/kibana.yml diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/create.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/create.sh deleted file mode 100644 index 41914b1..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/create.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# This script installs kibana and sets it up to run as a service in init.d -cd /opt -wget https://download.elastic.co/kibana/kibana/kibana-4.1.0-linux-x64.tar.gz -tar xzvf kibana-4.1.0-linux-x64.tar.gz -mv kibana-4.1.0-linux-x64 kibana - -# set up to run as service -cd /etc/init.d -wget https://gist.githubusercontent.com/thisismitch/8b15ac909aed214ad04a/raw/bce61d85643c2dcdfbc2728c55a41dab444dca20/kibana4 -chmod +x kibana4 -update-rc.d kibana4 defaults 96 9 diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/start.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/start.sh deleted file mode 100644 index 5149bb3..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/start.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -# This script starts kibana as a service in init.d -service kibana4 stop -service kibana4 start diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/logstash/create.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/logstash/create.sh deleted file mode 100644 index 77cc8fd..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/logstash/create.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -# This script installs java, logstash and the contrib package for logstash -# install java as prereq - -apt-get update -apt-get install -y openjdk-7-jre-headless -mkdir /etc/logstash - -# install by apt-get from repo -wget -O - http://packages.elasticsearch.org/GPG-KEY-elasticsearch | apt-key add - -echo "deb http://packages.elasticsearch.org/logstash/1.4/debian stable main" | tee -a /etc/apt/sources.list - -apt-get update -apt-get install -y logstash - -# install contrib to get the relp plugin -/opt/logstash/bin/plugin install contrib - -# set up to run as service -update-rc.d logstash defaults 95 10 diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/logstash/start.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/logstash/start.sh deleted file mode 100644 index a73cf61..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/logstash/start.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -# Run logstash as service in init.d -service logstash stop -service logstash start diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/config.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/config.sh deleted file mode 100644 index 78f484e..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/config.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -# Edit the file /etc/mongod.conf, update with real IP of Mongo server -# This script configures the mongodb server to export its service on -# the server IP -# bind_ip = 127.0.0.1 -> bind_ip = -# The environment variable mongodb_ip is expected to be set up -sed -i "s/= 127.0.0.1/= $mongodb_ip,127.0.0.1/" /etc/mongod.conf diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/create.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/create.sh deleted file mode 100644 index d84c275..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/create.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -# This script installs mongodb - -apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 -echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.0.list - -apt-get update -apt-get install -y mongodb-org - -#Wait for mongodb initialization -while [[ ! -d "/var/lib/mongodb/_tmp" ]]; do - echo "Waiting for mongodb initialization ..." - sleep 5 -done diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/create_database.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/create_database.sh deleted file mode 100644 index 16f1358..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/create_database.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -echo "conn = new Mongo();" > setup.js -echo "db = conn.getDB('paypal_pizza');" >> setup.js -echo "db.about.insert({'name': 'PayPal Pizza Store'});" >> setup.js -mongo setup.js diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/start.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/start.sh deleted file mode 100644 index ac200a5..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/start.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -# This script starts mongodb -service mongod stop -rm /var/lib/mongodb/mongod.lock -service mongod start diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/config.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/config.sh deleted file mode 100644 index 1e149a2..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/config.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -# This script installs an app for nodejs: the app intended is the paypal app -# and it is configured to connect to the mongodb server -# The environment variables github_url and mongodb_ip are expected to be set up -export app_dir=/opt/app -git clone $github_url /opt/app -if [ -f /opt/app/package.json ]; then - cd /opt/app/ && npm install - sed -i "s/localhost/$mongodb_ip/" config.json -fi - -cat > /etc/init/nodeapp.conf <> /var/log/nodeapp.log 2>&1 & -end script -EOS diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/create.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/create.sh deleted file mode 100644 index 04fd6c6..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/create.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -# This script installs nodejs and the prereq - -add-apt-repository ppa:chris-lea/node.js - -apt-get update -apt-get install -y nodejs build-essential diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/start.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/start.sh deleted file mode 100644 index 6939cb7..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/start.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -# This script starts the nodejs application -start nodeapp diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/config.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/config.sh deleted file mode 100644 index 630767d..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/config.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -# This script configures the output for rsyslogd to send logs to the -# logstash server port 2514 using the RELP protocol -# The environment variable logstash_ip is expected to be set up -echo "module(load=\"omrelp\") -action(type=\"omrelp\" target=\"$logstash_ip\" port=\"2514\")" > /etc/rsyslog.d/tosca_elk.conf - -# Remove the /dev/xconsole configuration as xconsole -# is not available by default -l=`awk '/=warn.*\|.*\/dev\/xconsole/{print NR - 1}' /etc/rsyslog.d/50-default.conf` -if [ ! -z $l ]; then - l=`expr $l + 1` - line=`cat /etc/rsyslog.d/50-default.conf | head -n $l | tail -1` - if [[ ! $line == \#* ]]; then - l0=`expr $l - 3` - sed -i -r -e "${l0},${l}s/^.{0}/&#/" /etc/rsyslog.d/50-default.conf - fi -fi - -# Enable nodejs logs for rsyslog -if ! grep -q nodeapp "/etc/rsyslog.conf"; then - sed -i 's/\$PrivDropToGroup\ syslog/\$PrivDropToGroup adm/' /etc/rsyslog.conf - echo "\$ModLoad imfile.so -\$InputFileName /var/log/nodeapp.log -\$InputFileTag paypal_pizza: -\$InputFileStateFile stat-nodeapp -\$InputRunFileMonitor -\$InputFilePollInterval 1" >> /etc/rsyslog.conf -fi diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/create.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/create.sh deleted file mode 100644 index affdd6e..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/create.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -# This script installs rsyslog and the library for RELP - -apt-get update -apt-get install -y rsyslog rsyslog-relp diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/start.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/start.sh deleted file mode 100644 index 3de82d1..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/start.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -# This script starts rsyslogd as a service in init.d -service rsyslog stop -service rsyslog start diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/TOSCA-Metadata/TOSCA.meta b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/TOSCA-Metadata/TOSCA.meta deleted file mode 100644 index feb3d4f..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_elk/TOSCA-Metadata/TOSCA.meta +++ /dev/null @@ -1,4 +0,0 @@ -TOSCA-Meta-File-Version: 1.0 -CSAR-Version: 1.1 -Created-By: OASIS TOSCA TC -Entry-Definitions: Definitions/tosca_elk.yaml \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Definitions/tosca_single_instance_wordpress.yaml b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Definitions/tosca_single_instance_wordpress.yaml deleted file mode 100644 index 1dd195a..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Definitions/tosca_single_instance_wordpress.yaml +++ /dev/null @@ -1,109 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with wordpress, web server and mysql on the same server. - -imports: - - wordpress.yaml - -topology_template: - inputs: - cpus: - type: integer - description: Number of CPUs for the server. - constraints: - - valid_values: [ 1, 2, 4, 8 ] - db_name: - type: string - description: The name of the database. - db_user: - type: string - description: The user name of the DB user. - db_pwd: - type: string - description: The WordPress database admin account password. - db_root_pwd: - type: string - description: Root password for MySQL. - db_port: - type: PortDef - description: Port for the MySQL database. - - node_templates: - wordpress: - type: tosca.nodes.WebApplication.WordPress - requirements: - - host: webserver - - database_endpoint: mysql_database - interfaces: - Standard: - create: ../Scripts/WordPress/install.sh - configure: - implementation: ../Scripts/WordPress/configure.sh - inputs: - wp_db_name: { get_property: [ mysql_database, name ] } - wp_db_user: { get_property: [ mysql_database, user ] } - wp_db_password: { get_property: [ mysql_database, password ] } - - mysql_database: - type: tosca.nodes.Database - properties: - name: { get_input: db_name } - user: { get_input: db_user } - password: { get_input: db_pwd } - requirements: - - host: mysql_dbms - interfaces: - Standard: - configure: - implementation: ../Scripts/MYSQLDatabase/configure.sh - inputs: - db_name: { get_property: [ SELF, name ] } - db_user: { get_property: [ SELF, user ] } - db_password: { get_property: [ SELF, password ] } - db_root_password: { get_property: [ mysql_dbms, root_password ] } - - mysql_dbms: - type: tosca.nodes.DBMS - properties: - root_password: { get_input: db_root_pwd } - port: { get_input: db_port } - requirements: - - host: server - interfaces: - Standard: - create: ../Scripts/MYSQLDBMS/install.sh - start: ../Scripts/MYSQLDBMS/start.sh - configure: - implementation: ../Scripts/MYSQLDBMS/configure.sh - inputs: - root_password: { get_property: [ mysql_dbms, root_password ] } - - webserver: - type: tosca.nodes.WebServer - requirements: - - host: server - interfaces: - Standard: - create: ../Scripts/WebServer/install.sh - start: ../Scripts/WebServer/start.sh - - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: cpus } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Fedora - version: 18.0 - - outputs: - website_url: - description: IP address for Wordpress wiki. - value: { get_attribute: [server, private_address] } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Definitions/wordpress.yaml b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Definitions/wordpress.yaml deleted file mode 100644 index 5899ed9..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Definitions/wordpress.yaml +++ /dev/null @@ -1,19 +0,0 @@ -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/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/README.txt b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/README.txt deleted file mode 100644 index e882ff6..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/README.txt +++ /dev/null @@ -1,22 +0,0 @@ -README: - -This CSAR contains all definitions that are required for deploying WordPress -and MySQL on a single compute instance. - -Entry information for processing through an orchestrator is contained in file -TOSCA-Metadata/TOSCA.meta. This file provides high-level information such as -CSAR version or creator of the CSAR. Furthermore, it provides pointers to the -various TOSCA definitions files that contain the real details. -The entry 'Entry-Definitions' points to the definitions file which holds the -service template for the workload. -'Entry-Definitions' is optional. An orchestrator can also process the contents -like this: -1) Read in and process each definitions file. -2) For each definitions file: - 2.1) Read in all * type definitions (node types, capability types, etc.) and - store them in an internal map -3) Verify and build dependencies (e.g. inheritance) between all type definitions - previously read in. Orchestrator built-in types (e.g. TOSCA base types) are - also considered in this step. -4) Process the actual service template (the file with a node_templates section). - Validate using previously obtained type information. diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/configure.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/configure.sh deleted file mode 100644 index d4ef6b4..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/configure.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -sed --regexp-extended "s/(port\s*=\s*)[0-9]*/\1$db_port/g" /tmp/my.cnf -mv -f /tmp/my.cnf /etc/mysql/my.cnf -/etc/init.d/mysql stop -/etc/init.d/mysql start \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/install.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/install.sh deleted file mode 100644 index 38628b9..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/install.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -#This script installs mysql server - -apt-get update - -debconf-set-selections <<< "mysql-server mysql-server/root_password password $db_root_password" -debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $db_root_password" - -apt-get -y install --fix-missing mysql-server \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/start.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/start.sh deleted file mode 100644 index 3378670..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/start.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -/etc/init.d/mysql start \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDatabase/configure.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDatabase/configure.sh deleted file mode 100644 index 092136a..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDatabase/configure.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -cat << EOF | mysql -u root --password=$db_root_password -CREATE DATABASE $db_name; -GRANT ALL PRIVILEGES ON $db_name.* TO "$db_user"@"localhost" -IDENTIFIED BY "$db_password"; -FLUSH PRIVILEGES; -EXIT -EOF \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WebServer/install.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WebServer/install.sh deleted file mode 100644 index 4ca9b4e..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WebServer/install.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -#This script installs apache web server - -apt-get update -apt-get install -y apache2 \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WebServer/start.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WebServer/start.sh deleted file mode 100644 index e962ca5..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WebServer/start.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -service apache2 start \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WordPress/configure.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WordPress/configure.sh deleted file mode 100644 index 5598b4f..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WordPress/configure.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -ln -s /usr/share/wordpress /var/www/html/wordpress -gzip -d /usr/share/doc/wordpress/examples/setup-mysql.gz -echo $wp_db_password | bash /usr/share/doc/wordpress/examples/setup-mysql -e $wp_db_name -u $wp_db_user localhost \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WordPress/install.sh b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WordPress/install.sh deleted file mode 100644 index 1320443..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WordPress/install.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -#This script installs wordpress - -apt-get update -apt-get install -y wordpress \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/TOSCA-Metadata/TOSCA.meta b/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/TOSCA-Metadata/TOSCA.meta deleted file mode 100644 index 5208113..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/TOSCA-Metadata/TOSCA.meta +++ /dev/null @@ -1,5 +0,0 @@ -TOSCA-Meta-File-Version: 1.0 -CSAR-Version: 1.1 -Created-By: OASIS TOSCA TC -Entry-Definitions: Definitions/tosca_single_instance_wordpress.yaml -Content-Type: application/vnd.oasis.tosca.definitions.yaml diff --git a/nfvparser/src/main/python/toscaparser/tests/data/containers/test_container_docker_mysql.yaml b/nfvparser/src/main/python/toscaparser/tests/data/containers/test_container_docker_mysql.yaml deleted file mode 100644 index 3fd4466..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/containers/test_container_docker_mysql.yaml +++ /dev/null @@ -1,44 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with mysql docker container. - -# Repositories to retrieve code artifacts from -repositories: - docker_hub: https://registry.hub.docker.com/ - -topology_template: - - inputs: - mysql_root_pwd: - type: string - description: Root password for MySQL. - - node_templates: - # The MYSQL container based on official MySQL image in Docker hub - mysql_container: - type: tosca.nodes.Container.Application.Docker - requirements: - - host: mysql_runtime - artifacts: - my_image: - file: mysql - type: tosca.artifacts.Deployment.Image.Container.Docker - repository: docker_hub - interfaces: - Standard: - create: - implementation: my_image - inputs: - MYSQL_ROOT_PASSWORD: { get_input: mysql_root_pwd } - - # The properties of the runtime to host the container - mysql_runtime: - type: tosca.nodes.Container.Runtime - capabilities: - host: - properties: - num_cpus: 1 - disk_size: 10 GB - mem_size: 2 MB - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/collectd.yaml b/nfvparser/src/main/python/toscaparser/tests/data/custom_types/collectd.yaml deleted file mode 100644 index 1ac0935..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/collectd.yaml +++ /dev/null @@ -1,13 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - collectd is a daemon which gathers statistics about the system it is running on. - -node_types: - tosca.nodes.SoftwareComponent.Collectd: - derived_from: tosca.nodes.SoftwareComponent - requirements: - - log_endpoint: - capability: tosca.capabilities.Endpoint - node: tosca.nodes.SoftwareComponent.Logstash - relationship: tosca.relationships.ConnectsTo \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/compute_with_attribute_list.yaml b/nfvparser/src/main/python/toscaparser/tests/data/custom_types/compute_with_attribute_list.yaml deleted file mode 100644 index 3487433..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/compute_with_attribute_list.yaml +++ /dev/null @@ -1,13 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: Compute node type with a list attribute - -node_types: - tosca.nodes.ComputeWithAttrList: - derived_from: tosca.nodes.Compute - attributes: - attr_list: - type: map - entry_schema: - type: string - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/compute_with_nested_atributes.yaml b/nfvparser/src/main/python/toscaparser/tests/data/custom_types/compute_with_nested_atributes.yaml deleted file mode 100644 index 909a297..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/compute_with_nested_atributes.yaml +++ /dev/null @@ -1,22 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: Compute node type with capability with an attribute of type list - -capability_types: - - tosca.capabilities.indigo.Endpoint: - derived_from: tosca.capabilities.Endpoint - attributes: - credential: - type: list - entry_schema: - type: tosca.datatypes.Credential - -node_types: - - tosca.nodes.ComputeWithCapWithAttr: - derived_from: tosca.nodes.Compute - capabilities: - endpoint: - type: tosca.capabilities.indigo.Endpoint - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/compute_with_prop.yaml b/nfvparser/src/main/python/toscaparser/tests/data/custom_types/compute_with_prop.yaml deleted file mode 100644 index 93a82af..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/compute_with_prop.yaml +++ /dev/null @@ -1,13 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Compute node type with a parameter for the get property with host test - -node_types: - tosca.nodes.ComputeWithProp: - derived_from: tosca.nodes.Compute - properties: - test: - required: false - type: integer - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/custom_caps_def.yaml b/nfvparser/src/main/python/toscaparser/tests/data/custom_types/custom_caps_def.yaml deleted file mode 100644 index 337c38f..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/custom_caps_def.yaml +++ /dev/null @@ -1,22 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Definition of a node with a capiblity and a parent capability - defined in an imported file - -capability_types: - - tosca.capabilities.SomeCap: - derived_from: tosca.capabilities.Root - - tosca.capabilities.SomeChildCap: - derived_from: tosca.capabilities.SomeCap - -node_types: - - tosca.nodes.SomeNode: - derived_from: tosca.nodes.Root - capabilities: - lrms: - type: tosca.capabilities.SomeChildCap - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/custom_interface.yaml b/nfvparser/src/main/python/toscaparser/tests/data/custom_types/custom_interface.yaml deleted file mode 100644 index 2d9bec4..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/custom_interface.yaml +++ /dev/null @@ -1,20 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - This template contains custom defined interface type - and a node type which uses this custom interface - -interface_types: - tosca.interfaces.CustomInterface: - derived_from: tosca.interfaces.Root - CustomOp: - CustomOp2: - -node_types: - tosca.nodes.CustomInterfaceTest: - derived_from: tosca.nodes.WebApplication - interfaces: - CustomInterface: - type: tosca.interfaces.CustomInterface - CustomOp3: - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/custom_relationship_type_defs.yaml b/nfvparser/src/main/python/toscaparser/tests/data/custom_types/custom_relationship_type_defs.yaml deleted file mode 100644 index cf5c2b4..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/custom_relationship_type_defs.yaml +++ /dev/null @@ -1,23 +0,0 @@ -node_types: - tosca.nodes.HACompute: - derived_from: tosca.nodes.Compute - capabilities: - high_availability: - type: tosca.capabilities.HA - requirements: - - high_availability: - capability: tosca.capabilities.HA - relationship: tosca.relationships.HA - node: tosca.nodes.HACompute - occurences: [ 0, 1 ] - -relationship_types: - tosca.relationships.HA: - derived_from: tosca.relationships.Root - valid_target_types: [ tosca.capabilities.HA ] - -capability_types: - tosca.capabilities.HA: - derived_from: tosca.capabilities.Root - valid_source_types: [ tosca.nodes.HACompute ] - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/db_with_list_param.yaml b/nfvparser/src/main/python/toscaparser/tests/data/custom_types/db_with_list_param.yaml deleted file mode 100644 index 57ce279..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/db_with_list_param.yaml +++ /dev/null @@ -1,10 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -node_types: - tosca.nodes.DatabaseWithListParam: - derived_from: tosca.nodes.Database - properties: - list_prop: - type: list - entry_schema: - type: integer diff --git a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/elasticsearch.yaml b/nfvparser/src/main/python/toscaparser/tests/data/custom_types/elasticsearch.yaml deleted file mode 100644 index b140a32..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/elasticsearch.yaml +++ /dev/null @@ -1,12 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Elasticsearch is an open-source search engine built on top of Apache Lucene, - a full-text search-engine library. - -node_types: - tosca.nodes.SoftwareComponent.Elasticsearch: - derived_from: tosca.nodes.SoftwareComponent - capabilities: - search_endpoint: - type: tosca.capabilities.Endpoint diff --git a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/imported_sample.yaml b/nfvparser/src/main/python/toscaparser/tests/data/custom_types/imported_sample.yaml deleted file mode 100644 index c8e4532..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/imported_sample.yaml +++ /dev/null @@ -1,38 +0,0 @@ -tosca1_definitions_version: tosca_simple_yaml_1_0 -tosca_definitions_version: tosca_simple_yaml_1_10 - -descriptions: > - Pizza store app that allows you to explore the features provided by PayPal's REST APIs. - More detail can be found at https://github.com/paypal/rest-api-sample-app-nodejs/ - -node_typess: -node_types: - tosca.nodes.SoftwareComponent.Logstash: - derived_from: tosca.nodes.SoftwareComponent - requirements: - - search_endpoint: - capability: tosca.capabilities.Endpoint - node: tosca.nodes.SoftwareComponent.Elasticsearch - relationship: - type: tosca.relationships.ConnectsTo - interfaces: - Configure: - pre_configure_source: - inputs: - elasticsearch_ip: - type: string - capabilities1: - log_endpoint: - type: tosca.capabilities.Endpoint -policy_types1: -policy_types: - mycompany.mytypes.myScalingPolicy: - derived1_from: tosca.policies.Scaling - metadata: - type: map - entry_schema: - type: string -relationship_types1: -relationship_types: - test.relation.connects: - derived_from4: tosca.relationships.ConnectsTo diff --git a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/kibana.yaml b/nfvparser/src/main/python/toscaparser/tests/data/custom_types/kibana.yaml deleted file mode 100644 index 5701e69..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/kibana.yaml +++ /dev/null @@ -1,14 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Kibana is an open source analytics and visualization platform designed to work with Elasticsearch. - You use Kibana to search, view, and interact with data stored in Elasticsearch. - -node_types: - tosca.nodes.SoftwareComponent.Kibana: - derived_from: tosca.nodes.SoftwareComponent - requirements: - - search_endpoint: - capability: tosca.capabilities.Endpoint - node: tosca.nodes.SoftwareComponent.Elasticsearch - relationship: tosca.relationships.ConnectsTo diff --git a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/logstash.yaml b/nfvparser/src/main/python/toscaparser/tests/data/custom_types/logstash.yaml deleted file mode 100644 index cf60521..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/logstash.yaml +++ /dev/null @@ -1,25 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Logstash is a tool for receiving, processing and outputting logs. All kinds - of logs. System logs, webserver logs, error logs, application logs, and just - about anything you can throw at it. - -node_types: - tosca.nodes.SoftwareComponent.Logstash: - derived_from: tosca.nodes.SoftwareComponent - requirements: - - search_endpoint: - capability: tosca.capabilities.Endpoint - node: tosca.nodes.SoftwareComponent.Elasticsearch - relationship: - type: tosca.relationships.ConnectsTo - interfaces: - Configure: - pre_configure_source: - inputs: - elasticsearch_ip: - type: string - capabilities: - log_endpoint: - type: tosca.capabilities.Endpoint diff --git a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/nested_rsyslog.yaml b/nfvparser/src/main/python/toscaparser/tests/data/custom_types/nested_rsyslog.yaml deleted file mode 100644 index 8c04171..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/nested_rsyslog.yaml +++ /dev/null @@ -1,17 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - RSYSLOG is the Rocket-fast SYStem for LOG processing. - -imports: - - test_import: - file: custom_types/logstash.yaml - -node_types: - Rsyslog: - derived_from: tosca.nodes.SoftwareComponent - requirements: - - log_endpoint: - capability: tosca.capabilities.Endpoint - node: tosca.nodes.SoftwareComponent.Logstash - relationship: tosca.relationships.ConnectsTo diff --git a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/nested_test_wordpress.yaml b/nfvparser/src/main/python/toscaparser/tests/data/custom_types/nested_test_wordpress.yaml deleted file mode 100644 index 4df277d..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/nested_test_wordpress.yaml +++ /dev/null @@ -1,32 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 -imports: - - test_prefix_defs: - file: custom_types/nested_rsyslog.yaml - namespace_prefix: test_namespace_prefix - - test_second_time_with_another_prefix: - file: custom_types/nested_rsyslog.yaml - namespace_prefix: test_2nd_namespace_prefix - -node_types: - tosca.nodes.SoftwareComponent.Rsyslog.TestRsyslogType: - derived_from: test_namespace_prefix.Rsyslog - - Test2ndRsyslogType: - derived_from: test_2nd_namespace_prefix.Rsyslog - - 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/src/main/python/toscaparser/tests/data/custom_types/node_with_cap.yaml b/nfvparser/src/main/python/toscaparser/tests/data/custom_types/node_with_cap.yaml deleted file mode 100644 index b17513f..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/node_with_cap.yaml +++ /dev/null @@ -1,33 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Node type that has a requirement of a capability with a defined value - -capability_types: - - tosca.capabilities.SomeCap: - derived_from: tosca.capabilities.Root - properties: - type: - type: string - required: true - default: someval - constraints: - - equal: someval - -node_types: - - tosca.nodes.SomeNode: - derived_from: tosca.nodes.Root - requirements: - - some_req: - capability: tosca.capabilities.SomeCap - node: tosca.nodes.NodeWithCap - relationship: tosca.relationships.HostedOn - - tosca.nodes.NodeWithCap: - derived_from: tosca.nodes.Root - capabilities: - some_req: - type: tosca.capabilities.SomeCap - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/paypalpizzastore_nodejs_app.yaml b/nfvparser/src/main/python/toscaparser/tests/data/custom_types/paypalpizzastore_nodejs_app.yaml deleted file mode 100644 index cdabeae..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/paypalpizzastore_nodejs_app.yaml +++ /dev/null @@ -1,29 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Pizza store app that allows you to explore the features provided by PayPal's REST APIs. - More detail can be found at https://github.com/paypal/rest-api-sample-app-nodejs/ - -node_types: - tosca.nodes.WebApplication.PayPalPizzaStore: - derived_from: tosca.nodes.WebApplication - properties: - github_url: - required: false - type: string - description: location of the application on the github. - default: https://github.com/sample.git - requirements: - #WebApplication inherits Computer, so host implied. - - database_connection: - capability: tosca.capabilities.Endpoint.Database - node: tosca.nodes.Database - relationship: tosca.relationships.ConnectsTo - interfaces: - Standard: - configure: - inputs: - github_url: - type: string - mongodb_ip: - type: string diff --git a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/rsyslog.yaml b/nfvparser/src/main/python/toscaparser/tests/data/custom_types/rsyslog.yaml deleted file mode 100644 index 4614ee7..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/rsyslog.yaml +++ /dev/null @@ -1,13 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - RSYSLOG is the Rocket-fast SYStem for LOG processing. - -node_types: - tosca.nodes.SoftwareComponent.Rsyslog: - derived_from: tosca.nodes.SoftwareComponent - requirements: - - log_endpoint: - capability: tosca.capabilities.Endpoint - node: tosca.nodes.SoftwareComponent.Logstash - relationship: tosca.relationships.ConnectsTo diff --git a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/wordpress.yaml b/nfvparser/src/main/python/toscaparser/tests/data/custom_types/wordpress.yaml deleted file mode 100644 index 5899ed9..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/custom_types/wordpress.yaml +++ /dev/null @@ -1,19 +0,0 @@ -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/src/main/python/toscaparser/tests/data/datatypes/custom_datatype_def.yaml b/nfvparser/src/main/python/toscaparser/tests/data/datatypes/custom_datatype_def.yaml deleted file mode 100644 index b1fb402..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/datatypes/custom_datatype_def.yaml +++ /dev/null @@ -1,53 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Custom type and node definition used to test custom datatypes. - -node_types: - tosca.nodes.my.SomeNode: - derived_from: tosca.nodes.Root - properties: - people: - type: tosca.my.datatypes.People - -data_types: - tosca.my.datatypes.PeopleBase: - properties: - name: - type: string - required: true - constraints: - - min_length: 2 - gender: - type: string - required: false - default: unknown - - tosca.my.datatypes.People: - derived_from: tosca.my.datatypes.PeopleBase - properties: - addresses: - type: map - required: false - entry_schema: - type: string - contacts: - type: list - required: false - entry_schema: - type: tosca.my.datatypes.ContactInfo - - tosca.my.datatypes.ContactInfo: - description: simple contact information - properties: - contact_name: - type: string - required: true - constraints: - - min_length: 2 - contact_email: - type: string - required: false - contact_phone: - type: string - required: false diff --git a/nfvparser/src/main/python/toscaparser/tests/data/datatypes/test_custom_datatypes_in_current_template.yaml b/nfvparser/src/main/python/toscaparser/tests/data/datatypes/test_custom_datatypes_in_current_template.yaml deleted file mode 100644 index befa198..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/datatypes/test_custom_datatypes_in_current_template.yaml +++ /dev/null @@ -1,70 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA templates used to test custom datatypes. - -node_types: - tosca.nodes.my.SomeNode: - derived_from: tosca.nodes.Root - properties: - people: - type: tosca.my.datatypes.People - -data_types: - tosca.my.datatypes.PeopleBase: - properties: - name: - type: string - required: true - constraints: - - min_length: 2 - gender: - type: string - required: false - default: unknown - - tosca.my.datatypes.People: - derived_from: tosca.my.datatypes.PeopleBase - properties: - addresses: - type: map - required: false - entry_schema: - type: string - contacts: - type: list - required: false - entry_schema: - type: tosca.my.datatypes.ContactInfo - - tosca.my.datatypes.ContactInfo: - description: simple contact information - properties: - contact_name: - type: string - required: true - constraints: - - min_length: 2 - contact_email: - type: string - required: false - contact_phone: - type: string - required: false - -topology_template: - node_templates: - positive: - type: tosca.nodes.my.SomeNode - properties: - people: - name: Mike - gender: male - addresses: {Home: 1 foo street, Office: 9 bar avenue} - contacts: - - {contact_name: Tom, - contact_email: tom@email.com, - contact_phone: '123456789'} - - {contact_name: Jerry, - contact_email: jerry@email.com, - contact_phone: '321654987'} diff --git a/nfvparser/src/main/python/toscaparser/tests/data/datatypes/test_custom_datatypes_nested_datatype_error.yaml b/nfvparser/src/main/python/toscaparser/tests/data/datatypes/test_custom_datatypes_nested_datatype_error.yaml deleted file mode 100644 index b28f499..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/datatypes/test_custom_datatypes_nested_datatype_error.yaml +++ /dev/null @@ -1,25 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA templates used to test custom datatypes. - -imports: - - custom_datatype_def.yaml - -topology_template: - node_templates: - # 123456789 is not a string - error in nested datatype: - type: tosca.nodes.my.SomeNode - properties: - people: - name: Mike - gender: male - addresses: {Home: 1 foo street, Office: 9 bar avenue} - contacts: - - {contact_name: Tom, - contact_email: tom@email.com, - contact_phone: 123456789} - - {contact_name: Jerry, - contact_email: jerry@email.com, - contact_phone: '321654987'} diff --git a/nfvparser/src/main/python/toscaparser/tests/data/datatypes/test_custom_datatypes_positive.yaml b/nfvparser/src/main/python/toscaparser/tests/data/datatypes/test_custom_datatypes_positive.yaml deleted file mode 100644 index f1762f4..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/datatypes/test_custom_datatypes_positive.yaml +++ /dev/null @@ -1,24 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA templates used to test custom datatypes. - -imports: - - custom_datatype_def.yaml - -topology_template: - node_templates: - positive: - type: tosca.nodes.my.SomeNode - properties: - people: - name: Mike - gender: male - addresses: {Home: 1 foo street, Office: 9 bar avenue} - contacts: - - {contact_name: Tom, - contact_email: tom@email.com, - contact_phone: '123456789'} - - {contact_name: Jerry, - contact_email: jerry@email.com, - contact_phone: '321654987'} diff --git a/nfvparser/src/main/python/toscaparser/tests/data/datatypes/test_custom_datatypes_value_error.yaml b/nfvparser/src/main/python/toscaparser/tests/data/datatypes/test_custom_datatypes_value_error.yaml deleted file mode 100644 index 31cf681..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/datatypes/test_custom_datatypes_value_error.yaml +++ /dev/null @@ -1,18 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA templates used to test custom datatypes. - -imports: - - custom_datatype_def.yaml - -topology_template: - node_templates: - # addresses is not a map - error in field value: - type: tosca.nodes.my.SomeNode - properties: - people: - name: Mike - gender: male - addresses: [1 foo street, 9 bar avenue] diff --git a/nfvparser/src/main/python/toscaparser/tests/data/datatypes/test_datatype_portspec_add_req.yaml b/nfvparser/src/main/python/toscaparser/tests/data/datatypes/test_datatype_portspec_add_req.yaml deleted file mode 100644 index f944927..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/datatypes/test_datatype_portspec_add_req.yaml +++ /dev/null @@ -1,41 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: TOSCA test PortSpec Additional Requirement clauses - -node_types: - - MyNodeType: - derived_from: Root - properties: - test_port: - type: PortSpec - -topology_template: - - node_templates: - - # Test invalid source value below (default) specified range constraint - test_node2: - type: MyNodeType - properties: - test_port: - protocol: tcp - source: 0 - - # Test invalid source value over specified range - test_node3: - type: MyNodeType - properties: - test_port: - protocol: tcp - source: 65535 - source_range: [ 2, 65534 ] - - # Test invalid source value under specified range - test_node4: - type: MyNodeType - properties: - test_port: - protocol: tcp - source: 1 - source_range: [ 2, 65534 ] diff --git a/nfvparser/src/main/python/toscaparser/tests/data/dsl_definitions/test_nested_dsl_def.yaml b/nfvparser/src/main/python/toscaparser/tests/data/dsl_definitions/test_nested_dsl_def.yaml deleted file mode 100644 index 6155595..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/dsl_definitions/test_nested_dsl_def.yaml +++ /dev/null @@ -1,23 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: Test template demonstrating usage of nested dsl_definitions value. - -dsl_definitions: - caps: &caps - host: - properties: - disk_size: 10 GB - num_cpus: 2 - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Ubuntu - version: 14.04 - -topology_template: - node_templates: - my_server: - type: tosca.nodes.Compute - capabilities: *caps \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_capabilties_inheritance.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_capabilties_inheritance.yaml deleted file mode 100644 index f0bec84..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_capabilties_inheritance.yaml +++ /dev/null @@ -1,25 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: TOSCA simple profile to test the attribute inheritance - -imports: - - ../custom_types/node_with_cap.yaml - -topology_template: - - node_templates: - - some_node: - type: tosca.nodes.SomeNode - requirements: - - some_req: node_cap - interfaces: - Standard: - configure: - implementation: some_script.sh - inputs: - some_input: { get_property: [ SELF, some_req, type ] } - - node_cap: - type: tosca.nodes.NodeWithCap - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_concat.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_concat.yaml deleted file mode 100644 index 22fcfb4..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_concat.yaml +++ /dev/null @@ -1,30 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: Template for deploying a single server with concat function. - -topology_template: - node_templates: - 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 - outputs: - url: - description: Concatenate the URL for a server from template values. - value: { concat: [ 'http://', - get_attribute: [ server, public_address ], - ':' , - get_attribute: [ server, port ] ] } \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_concat_invalid.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_concat_invalid.yaml deleted file mode 100644 index 7c7b0aa..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_concat_invalid.yaml +++ /dev/null @@ -1,9 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: Template for deploying a single server with invalid concat function. - -topology_template: - outputs: - invalid_concat_syntax: - description: test concat with invalid syntax. - value: { concat: []} \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_host_keyword.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_host_keyword.yaml deleted file mode 100644 index 90ffbe2..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_host_keyword.yaml +++ /dev/null @@ -1,33 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA template for testing get_attribute with HOST keyword. - -topology_template: - node_templates: - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - num_cpus: 2 - dbms: - type: tosca.nodes.DBMS - requirements: - - host: server - interfaces: - Standard: - configure: - implementation: configure.sh - inputs: - ip_address: { get_attribute: [ HOST, private_address ] } - database: - type: tosca.nodes.Database - requirements: - - host: dbms - interfaces: - Standard: - configure: - implementation: configure.sh - inputs: - ip_address: { get_attribute: [ HOST, private_address ] } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_host_not_found.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_host_not_found.yaml deleted file mode 100644 index 69679ff..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_host_not_found.yaml +++ /dev/null @@ -1,20 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA template for testing get_attribute with HOST keyword. - -topology_template: - node_templates: - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - num_cpus: 2 - interfaces: - Standard: - configure: - implementation: configure.sh - inputs: - ip_address: { get_attribute: [ HOST, private_address ] } - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_illegal_host_in_outputs.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_illegal_host_in_outputs.yaml deleted file mode 100644 index 6c7d9bb..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_illegal_host_in_outputs.yaml +++ /dev/null @@ -1,17 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA template for testing get_attribute with HOST keyword. - -topology_template: - node_templates: - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - num_cpus: 2 - - outputs: - ip_address: - value: { get_attribute: [ HOST, private_address ] } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_source_target_keywords.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_source_target_keywords.yaml deleted file mode 100644 index 047387f..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_source_target_keywords.yaml +++ /dev/null @@ -1,30 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA template for testing get_attribute with TARGET ans SOURCE keywords. - -topology_template: - - node_templates: - - mysql: - type: tosca.nodes.DBMS - properties: - root_password: rootpw - port: 3306 - requirements: - - host: - node: db_server - relationship: - type: tosca.relationships.HostedOn - interfaces: - Configure: - pre_configure_source: - implementation: some_script.sh - inputs: - target_test: { get_attribute: [ TARGET, public_address ] } - source_port: { get_attribute: [ SOURCE, tosca_name ] } - - db_server: - type: tosca.nodes.Compute - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_unknown_attribute_name.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_unknown_attribute_name.yaml deleted file mode 100644 index 0570c7c..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_unknown_attribute_name.yaml +++ /dev/null @@ -1,28 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Tosca template for testing unknown attribute name in get_attribute - function. - -topology_template: - inputs: - image_id: - type: string - - node_templates: - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - num_cpus: 2 - interfaces: - Standard: - configure: - implementation: start_server.sh - inputs: - image_id: { get_input: image_id } - - outputs: - ip_address: - value: { get_attribute: [ server, unknown_attribute ] } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_unknown_node_template_name.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_unknown_node_template_name.yaml deleted file mode 100644 index 34c1c33..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_unknown_node_template_name.yaml +++ /dev/null @@ -1,30 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Tosca template for testing unknown node template name in get_attribute - function. - -topology_template: - inputs: - image_id: - type: string - - node_templates: - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - num_cpus: 2 - interfaces: - Standard: - configure: - implementation: start_server.sh - inputs: - image_id: { get_input: image_id } - - outputs: - ip_address: - value: { get_attribute: [ unknown_node_template, private_address ] } - network: - value: { get_attribute: [ unknown_node_template, networks, public ] } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_with_index.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_with_index.yaml deleted file mode 100644 index 5766490..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_with_index.yaml +++ /dev/null @@ -1,19 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA template for testing get_attribute with a list attribute and an index - -imports: - - ../custom_types/compute_with_attribute_list.yaml - -topology_template: - node_templates: - server: - type: tosca.nodes.ComputeWithAttrList - interfaces: - Standard: - configure: - implementation: configure.sh - inputs: - ip_address: { get_attribute: [ SELF, attr_list, 0 ] } - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_with_index_error.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_with_index_error.yaml deleted file mode 100644 index 7511999..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_with_index_error.yaml +++ /dev/null @@ -1,19 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA template for testing get_attribute with an incorrect index - -imports: - - ../custom_types/compute_with_attribute_list.yaml - -topology_template: - node_templates: - server: - type: tosca.nodes.ComputeWithAttrList - interfaces: - Standard: - configure: - implementation: configure.sh - inputs: - ip_address: { get_attribute: [ SELF, private_address, 0 ] } - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_with_nested_params.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_with_nested_params.yaml deleted file mode 100644 index 79e632c..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_attribute_with_nested_params.yaml +++ /dev/null @@ -1,23 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA template for testing get_attribute with nested attributes - -imports: - - ../custom_types/compute_with_nested_atributes.yaml - -topology_template: - node_templates: - server: - type: tosca.nodes.ComputeWithCapWithAttr - capabilities: - endpoint: - properties: - port: 80 - interfaces: - Standard: - configure: - implementation: configure.sh - inputs: - ip_address: { get_attribute: [ SELF, endpoint, credential, 0, token ] } - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_implicit_attribute.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_implicit_attribute.yaml deleted file mode 100644 index a269005..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_implicit_attribute.yaml +++ /dev/null @@ -1,25 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Attribute can be defined explicitly as part of type definition - or implicitly via property. This TOSCA template tests validation - of attribute name implicitly created as a property and referenced - via get_attribute function. - -node_types: - ServerNode: - derived_from: SoftwareComponent - properties: - notification_port: - type: integer - -topology_template: - node_templates: - my_server: - type: ServerNode - properties: - notification_port: 8000 - - outputs: - ip_address: - value: { get_attribute: [ my_server, notification_port ] } \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_property_source_target_keywords.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_property_source_target_keywords.yaml deleted file mode 100644 index c460257..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_property_source_target_keywords.yaml +++ /dev/null @@ -1,35 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA template for testing get_property with TARGET ans SOURCE keywords. - -imports: - - ../custom_types/compute_with_prop.yaml - -topology_template: - - node_templates: - - mysql: - type: tosca.nodes.DBMS - properties: - root_password: rootpw - port: 3306 - requirements: - - host: - node: db_server - relationship: - type: tosca.relationships.HostedOn - interfaces: - Configure: - pre_configure_source: - implementation: some_script.sh - inputs: - target_test: { get_property: [ TARGET, test ] } - source_port: { get_property: [ SOURCE, port ] } - - db_server: - type: tosca.nodes.ComputeWithProp - properties: - test: 1 - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_property_with_host.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_property_with_host.yaml deleted file mode 100644 index 1ca69ca..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_get_property_with_host.yaml +++ /dev/null @@ -1,65 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile to test the get property function with HOST parameter - -imports: - - ../custom_types/compute_with_prop.yaml - -topology_template: - inputs: - db_name: - type: string - description: The name of the database. - default: wordpress - db_user: - type: string - description: The user name of the DB user. - default: wp_user - db_pwd: - type: string - description: The WordPress database admin account password. - default: wp_pass - db_root_pwd: - type: string - description: Root password for MySQL. - db_port: - type: PortDef - description: Port for the MySQL database. - default: 3306 - - node_templates: - - mysql_database: - type: tosca.nodes.Database - properties: - name: { get_input: db_name } - user: { get_input: db_user } - password: { get_input: db_pwd } - capabilities: - database_endpoint: - properties: - port: { get_input: db_port } - requirements: - - host: mysql_dbms - interfaces: - Standard: - configure: - implementation: mysql/mysql_database_configure.sh - inputs: - db_port: { get_property: [ HOST, port ] } - test: { get_property: [ HOST, test ] } - - mysql_dbms: - type: tosca.nodes.DBMS - properties: - root_password: { get_input: db_root_pwd } - port: { get_input: db_port } - requirements: - - host: server - - server: - type: tosca.nodes.ComputeWithProp - properties: - test: 1 - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_invalid_function_signature.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_invalid_function_signature.yaml deleted file mode 100644 index dde8427..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_invalid_function_signature.yaml +++ /dev/null @@ -1,34 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile template to test invalid get_input function. - -topology_template: - inputs: - cpus: - type: integer - description: Number of CPUs for the server. - constraints: - - valid_values: [ 1, 2, 4, 8 ] - - node_templates: - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - # compute properties (flavor) - disk_size: 10 GB - num_cpus: { get_input: [cpus, cpus] } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Fedora - version: 18.0 - - outputs: - server_address: - description: IP address of server instance. - value: { get_attribute: [server, private_address] } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_token.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_token.yaml deleted file mode 100644 index 495a930..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_token.yaml +++ /dev/null @@ -1,15 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: Template for deploying a single server with token function. - -topology_template: - node_templates: - server: - type: tosca.nodes.Compute - - outputs: - url: - description: Get the first part of the ip - value: { token: [ get_attribute: [ server, public_address ], - '.' , - 0 ] } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_token_invalid.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_token_invalid.yaml deleted file mode 100644 index 35ae2ff..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_token_invalid.yaml +++ /dev/null @@ -1,17 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: Template for deploying a single server with invalid token function. - -topology_template: - outputs: - invalid_token_syntax_1: - description: test token with only two paremeters. - value: { token: ["some_string", "_"]} - - invalid_token_syntax_2: - description: test token with invalid string as third argument. - value: { token: ["some_string", "_", "1"]} - - invalid_token_syntax_3: - description: test token with invalid string as second argument. - value: { token: ["some_string", "aa", "1"]} diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_unknown_capability_property.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_unknown_capability_property.yaml deleted file mode 100644 index 4a92530..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_unknown_capability_property.yaml +++ /dev/null @@ -1,36 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Tosca template for testing an unknown capability property. - -topology_template: - node_templates: - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - num_cpus: 2 - dbms: - type: tosca.nodes.DBMS - properties: - root_password: 1234 - port: 3672 - database: - type: tosca.nodes.Database - properties: - name: my_db - user: abcd - password: 1234 - capabilities: - database_endpoint: - properties: - port: { get_property: [ dbms, port ] } - requirements: - - host: dbms - interfaces: - Standard: - configure: - implementation: database_configure.sh - inputs: - db_port: { get_property: [ SELF, database_endpoint, unknown ] } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_unknown_input_in_interface.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_unknown_input_in_interface.yaml deleted file mode 100644 index cbfb391..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_unknown_input_in_interface.yaml +++ /dev/null @@ -1,20 +0,0 @@ - -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Tosca template for testing an unknown input. - -topology_template: - node_templates: - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - num_cpus: 2 - interfaces: - Standard: - configure: - implementation: start_server.sh - inputs: - image_id: { get_input: image_id } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_unknown_input_in_property.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/test_unknown_input_in_property.yaml deleted file mode 100644 index 9ba7ee5..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/test_unknown_input_in_property.yaml +++ /dev/null @@ -1,13 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Tosca template for testing an unknown input. - -topology_template: - node_templates: - obj_store_server: - type: tosca.nodes.ObjectStorage - properties: - name: { get_input: objectstore_name } - size: 1024 MB - maxsize: 1 GB diff --git a/nfvparser/src/main/python/toscaparser/tests/data/functions/tosca_nested_property_names_indexes.yaml b/nfvparser/src/main/python/toscaparser/tests/data/functions/tosca_nested_property_names_indexes.yaml deleted file mode 100644 index 8fb7b96..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/functions/tosca_nested_property_names_indexes.yaml +++ /dev/null @@ -1,47 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: TOSCA simple profile with nested property names or indexes. - -imports: - - ../custom_types/wordpress.yaml - - ../custom_types/db_with_list_param.yaml - -topology_template: - - node_templates: - - wordpress: - type: tosca.nodes.WebApplication.WordPress - requirements: - - host: server - - database_endpoint: mysql_database - interfaces: - Standard: - configure: - implementation: wordpress/wordpress_configure.sh - inputs: - wp_endpoint_protocol: { get_property: [ SELF, database_endpoint, ports, user_port, protocol ] } - wp_list_prop: { get_property: [ mysql_database, list_prop, 2 ] } - - mysql_database: - type: tosca.nodes.DatabaseWithListParam - properties: - list_prop: [1,2,3] - capabilities: - database_endpoint: - properties: - ports: - user_port: - protocol: tcp - target: 50000 - source: 9000 - requirements: - - host: mysql_dbms - - mysql_dbms: - type: tosca.nodes.DBMS - requirements: - - host: server - - server: - type: tosca.nodes.Compute diff --git a/nfvparser/src/main/python/toscaparser/tests/data/groups/definitions.yaml b/nfvparser/src/main/python/toscaparser/tests/data/groups/definitions.yaml deleted file mode 100644 index 40c1d8b..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/groups/definitions.yaml +++ /dev/null @@ -1,10 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -group_types: - mycompany.mytypes.groups.placement: - description: My company's group type for placing nodes of type Compute - members: [ tosca.nodes.Compute ] - metadata: - type: map - entry_schema: - type: string diff --git a/nfvparser/src/main/python/toscaparser/tests/data/groups/tosca_group_template.yaml b/nfvparser/src/main/python/toscaparser/tests/data/groups/tosca_group_template.yaml deleted file mode 100644 index 0e94240..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/groups/tosca_group_template.yaml +++ /dev/null @@ -1,54 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Service template with topology_template, act as a nested system inside another system. - -imports: - - definitions.yaml - -topology_template: - description: Template of a database including its hosting stack. - - inputs: - mq_server_ip: - type: string - description: IP address of the message queuing server to receive messages from. - receiver_port: - type: string - description: Port to be used for receiving messages. - my_cpus: - type: integer - description: Number of CPUs for the server. - constraints: - - valid_values: [ 1, 2, 4, 8 ] - - node_templates: - websrv: - type: tosca.nodes.WebServer - capabilities: - data_endpoint: - properties: - port_name: { get_input: receiver_port } - requirements: - - host: - node: server - - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: my_cpus } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Ubuntu - version: 14.04 - - groups: - webserver_group: - type: mycompany.mytypes.groups.placement - members: [ websrv, server ] diff --git a/nfvparser/src/main/python/toscaparser/tests/data/interfaces/test_custom_interface_in_template.yaml b/nfvparser/src/main/python/toscaparser/tests/data/interfaces/test_custom_interface_in_template.yaml deleted file mode 100644 index c23917c..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/interfaces/test_custom_interface_in_template.yaml +++ /dev/null @@ -1,23 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with valid custom interface and operations. - -imports: - - ../custom_types/custom_interface.yaml - -topology_template: - - node_templates: - customInterfaceTest: - type: tosca.nodes.CustomInterfaceTest - interfaces: - CustomInterface: - CustomOp: # operation from interface_type with additional inputs - inputs: - param: - type: string - CustomOp3: # operation from node_type with additional inputs - inputs: - param3: - type: string diff --git a/nfvparser/src/main/python/toscaparser/tests/data/interfaces/test_custom_interface_invalid_operation.yaml b/nfvparser/src/main/python/toscaparser/tests/data/interfaces/test_custom_interface_invalid_operation.yaml deleted file mode 100644 index d56ad9c..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/interfaces/test_custom_interface_invalid_operation.yaml +++ /dev/null @@ -1,19 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with invalid custom operation. - -imports: - - ../custom_types/custom_interface.yaml - -topology_template: - - node_templates: - customInterfaceTest: - type: tosca.nodes.CustomInterfaceTest - interfaces: - CustomInterface: - CustomOp4: # invalid operation - inputs: - param3: - type: string diff --git a/nfvparser/src/main/python/toscaparser/tests/data/load_balancer/tosca_load_balancer.yaml b/nfvparser/src/main/python/toscaparser/tests/data/load_balancer/tosca_load_balancer.yaml deleted file mode 100644 index 2fcdb48..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/load_balancer/tosca_load_balancer.yaml +++ /dev/null @@ -1,75 +0,0 @@ -# Note: this could eventually be translated to a Neutron Load Balancer -# However, in Heat/HOT the preferred way of doing this is creating an Autoscale Group -# -#heat_template_version: 2015-04-30 ... -#resources: -#load_bal_resource: -# type: OS::Neutron::Pool -# properties: -# admin_state_up: Boolean -# description: String -# lb_method: String -# monitors: [Value, Value, ...] -# name: String -# protocol: String -# provider: String -# subnet: String -# vip: { -# "description": String, -# "name": String, -# "connection_limit": Integer, -# "protocol_port": Integer, -# "subnet": String, -# "address": String, -# "admin_state_up": Boolean, -# "session_persistence": -# { -# "cookie_name": String, -# "type": String} -# } -# -# example from: https://gist.github.com/therve/9231701 -# -#resources: -# web_server_group: -# type: AWS::AutoScaling::AutoScalingGroup -# properties: -# AvailabilityZones: [nova] -# LaunchConfigurationName: {get_resource: launch_config} -# MinSize: 1 -# MaxSize: 3 -# LoadBalancerNames: -# - {get_resource: mylb} -# mypool: -# type: OS::Neutron::Pool -# properties: -# protocol: HTTP -# monitors: [{get_resource: mymonitor}] -# subnet_id: {get_param: subnet_id} -# lb_method: ROUND_ROBIN -# vip: -# protocol_port: 80 -# mylb: -# type: OS::Neutron::LoadBalancer -# properties: -# protocol_port: 80 -# pool_id: {get_resource: mypool} - -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: Template for deploying a load balancer with predefined endpoint properties. - -topology_template: - node_templates: - simple_load_balancer: - type: tosca.nodes.LoadBalancer - capabilities: - # properties: - # algorithm: DEFAULT (define new keyword, ROUND_ROBIN?) - # Client, public facing endpoint - client: - properties: - network_name: PUBLIC - floating: true - dns_name: http://mycompany.com/ - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/node_filter/test_node_filter.yaml b/nfvparser/src/main/python/toscaparser/tests/data/node_filter/test_node_filter.yaml deleted file mode 100644 index 3dd8e26..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/node_filter/test_node_filter.yaml +++ /dev/null @@ -1,18 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: Template with requirements against hosting infrastructure. - -topology_template: - - node_templates: - test: - type: tosca.nodes.DBMS - requirements: - - host: - node_filter: - capabilities: - - host: - properties: - - num_cpus: { in_range: [ 1, 4 ] } - - mem_size: { greater_or_equal: 2 GB } - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/policies/custom_definitions.yaml b/nfvparser/src/main/python/toscaparser/tests/data/policies/custom_definitions.yaml deleted file mode 100644 index 7f15ade..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/policies/custom_definitions.yaml +++ /dev/null @@ -1,10 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -policy_types: - mycompany.mytypes.myScalingPolicy: - derived_from: tosca.policies.Scaling - metadata: - type: map - entry_schema: - type: string - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/policies/tacker_defs.yaml b/nfvparser/src/main/python/toscaparser/tests/data/policies/tacker_defs.yaml deleted file mode 100644 index 96b0d45..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/policies/tacker_defs.yaml +++ /dev/null @@ -1,183 +0,0 @@ -tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 - -data_types: - tosca.datatypes.tacker.ActionMap: - properties: - trigger: - type: string - required: true - action: - type: string - required: true - params: - type: map - entry_schema: - type: string - required: false - - tosca.datatypes.tacker.MonitoringParams: - properties: - monitoring_delay: - type: int - required: false - count: - type: int - required: false - interval: - type: int - required: false - timeout: - type: int - required: false - retry: - type: int - required: false - port: - type: int - required: false - - tosca.datatypes.tacker.MonitoringType: - properties: - name: - type: string - required: true - actions: - type: map - required: true - parameters: - type: tosca.datatypes.tacker.MonitoringParams - required: false - - tosca.datatypes.compute_properties: - properties: - num_cpus: - type: integer - required: false - mem_size: - type: string - required: false - disk_size: - type: string - required: false - mem_page_size: - type: string - required: false - numa_node_count: - type: integer - constraints: - - greater_or_equal: 2 - required: false - numa_nodes: - type: map - required: false - cpu_allocation: - type: map - required: false - -policy_types: - tosca.policies.tacker.Placement: - derived_from: tosca.policies.Root - - tosca.policies.tacker.Failure: - derived_from: tosca.policies.Root - action: - type: string - - tosca.policies.tacker.Failure.Respawn: - derived_from: tosca.policies.tacker.Failure - action: respawn - - tosca.policies.tacker.Failure.Terminate: - derived_from: tosca.policies.tacker.Failure - action: log_and_kill - - tosca.policies.tacker.Failure.Log: - derived_from: tosca.policies.tacker.Failure - action: log - - tosca.policies.tacker.Monitoring: - derived_from: tosca.policies.Root - properties: - name: - type: string - required: true - parameters: - type: map - entry_schema: - type: string - required: false - actions: - type: map - entry_schema: - type: string - required: true - - tosca.policies.tacker.Monitoring.NoOp: - derived_from: tosca.policies.tacker.Monitoring - properties: - name: noop - - tosca.policies.tacker.Monitoring.Ping: - derived_from: tosca.policies.tacker.Monitoring - properties: - name: ping - - tosca.policies.tacker.Monitoring.HttpPing: - derived_from: tosca.policies.tacker.Monitoring.Ping - properties: - name: http-ping - - tosca.policies.tacker.Alarming: - derived_from: tosca.policies.Monitoring - triggers: - resize_compute: - event_type: - type: map - entry_schema: - type: string - required: true - metrics: - type: string - required: true - condition: - type: map - entry_schema: - type: string - required: false - action: - type: map - entry_schema: - type: string - required: true - - tosca.policies.tacker.Scaling: - derived_from: tosca.policies.Scaling - description: Defines policy for scaling the given targets. - properties: - increment: - type: integer - required: true - description: Number of nodes to add or remove during the scale out/in. - targets: - type: list - entry_schema: - type: string - required: true - description: List of Scaling nodes. - min_instances: - type: integer - required: true - description: Minimum number of instances to scale in. - max_instances: - type: integer - required: true - description: Maximum number of instances to scale out. - default_instances: - type: integer - required: true - description: Initial number of instances. - cooldown: - type: integer - required: false - default: 120 - description: Wait time (in seconds) between consecutive scaling operations. During the cooldown period... diff --git a/nfvparser/src/main/python/toscaparser/tests/data/policies/tacker_nfv_defs.yaml b/nfvparser/src/main/python/toscaparser/tests/data/policies/tacker_nfv_defs.yaml deleted file mode 100644 index 1387509..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/policies/tacker_nfv_defs.yaml +++ /dev/null @@ -1,261 +0,0 @@ -tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 - -data_types: - tosca.nfv.datatypes.pathType: - properties: - forwarder: - type: string - required: true - capability: - type: string - required: true - - tosca.nfv.datatypes.aclType: - properties: - eth_type: - type: string - required: false - eth_src: - type: string - required: false - eth_dst: - type: string - required: false - vlan_id: - type: integer - constraints: - - in_range: [ 1, 4094 ] - required: false - vlan_pcp: - type: integer - constraints: - - in_range: [ 0, 7 ] - required: false - mpls_label: - type: integer - constraints: - - in_range: [ 16, 1048575] - required: false - mpls_tc: - type: integer - constraints: - - in_range: [ 0, 7 ] - required: false - ip_dscp: - type: integer - constraints: - - in_range: [ 0, 63 ] - required: false - ip_ecn: - type: integer - constraints: - - in_range: [ 0, 3 ] - required: false - ip_src_prefix: - type: string - required: false - ip_dst_prefix: - type: string - required: false - ip_proto: - type: integer - constraints: - - in_range: [ 1, 254 ] - required: false - destination_port_range: - type: string - required: false - source_port_range: - type: string - required: false - network_src_port_id: - type: string - required: false - network_dst_port_id: - type: string - required: false - network_id: - type: string - required: false - network_name: - type: string - required: false - tenant_id: - type: string - required: false - icmpv4_type: - type: integer - constraints: - - in_range: [ 0, 254 ] - required: false - icmpv4_code: - type: integer - constraints: - - in_range: [ 0, 15 ] - required: false - arp_op: - type: integer - constraints: - - in_range: [ 1, 25 ] - required: false - arp_spa: - type: string - required: false - arp_tpa: - type: string - required: false - arp_sha: - type: string - required: false - arp_tha: - type: string - required: false - ipv6_src: - type: string - required: false - ipv6_dst: - type: string - required: false - ipv6_flabel: - type: integer - constraints: - - in_range: [ 0, 1048575] - required: false - icmpv6_type: - type: integer - constraints: - - in_range: [ 0, 255] - required: false - icmpv6_code: - type: integer - constraints: - - in_range: [ 0, 7] - required: false - ipv6_nd_target: - type: string - required: false - ipv6_nd_sll: - type: string - required: false - ipv6_nd_tll: - type: string - required: false - - tosca.nfv.datatypes.policyType: - properties: - type: - type: string - required: false - constraints: - - valid_values: [ ACL ] - criteria: - type: list - required: true - entry_schema: - type: tosca.nfv.datatypes.aclType - -node_types: - tosca.nodes.nfv.VDU.Tacker: - derived_from: tosca.nodes.nfv.VDU - capabilities: - nfv_compute: - type: tosca.datatypes.compute_properties - properties: - name: - type: string - required: false - image: -# type: tosca.artifacts.Deployment.Image.VM - type: string - required: false - flavor: - type: string - required: false - availability_zone: - type: string - required: false - metadata: - type: map - entry_schema: - type: string - required: false - config_drive: - type: boolean - default: false - required: false - - placement_policy: -# type: tosca.policies.tacker.Placement - type: string - required: false - - monitoring_policy: -# type: tosca.policies.tacker.Monitoring -# type: tosca.datatypes.tacker.MonitoringType - type: map - required: false - - config: - type: string - required: false - - mgmt_driver: - type: string - default: noop - required: false - - service_type: - type: string - required: false - - user_data: - type: string - required: false - - user_data_format: - type: string - required: false - - key_name: - type: string - required: false - - tosca.nodes.nfv.CP.Tacker: - derived_from: tosca.nodes.nfv.CP - properties: - mac_address: - type: string - required: false - name: - type: string - required: false - management: - type: boolean - required: false - anti_spoofing_protection: - type: boolean - required: false - security_groups: - type: list - required: false - type: - type: string - required: false - constraints: - - valid_values: [ sriov, vnic ] - - tosca.nodes.nfv.FP.Tacker: - derived_from: tosca.nodes.Root - properties: - id: - type: integer - required: false - policy: - type: tosca.nfv.datatypes.policyType - required: true - description: policy to use to match traffic for this FP - path: - type: list - required: true - entry_schema: - type: tosca.nfv.datatypes.pathType diff --git a/nfvparser/src/main/python/toscaparser/tests/data/policies/test_tosca_nfv_multiple_policies.yaml b/nfvparser/src/main/python/toscaparser/tests/data/policies/test_tosca_nfv_multiple_policies.yaml deleted file mode 100644 index 452dbb5..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/policies/test_tosca_nfv_multiple_policies.yaml +++ /dev/null @@ -1,95 +0,0 @@ -tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 - -description: sample-tosca-vnfd-scaling - -imports: - - tacker_defs.yaml - - tacker_nfv_defs.yaml - -metadata: - template_name: sample-tosca-vnfd-scaling - -topology_template: - node_templates: - VDU1: - type: tosca.nodes.nfv.VDU.Tacker - properties: - image: cirros-0.3.4-x86_64-uec - mgmt_driver: noop - availability_zone: nova - flavor: m1.tiny - - CP1: - type: tosca.nodes.nfv.CP.Tacker - properties: - management: true - order: 0 - anti_spoofing_protection: false - requirements: - - virtualLink: - node: VL1 - - virtualBinding: - node: VDU1 - - VDU2: - type: tosca.nodes.nfv.VDU.Tacker - properties: - image: cirros-0.3.4-x86_64-uec - mgmt_driver: noop - availability_zone: nova - flavor: m1.tiny - - CP2: - type: tosca.nodes.nfv.CP.Tacker - properties: - management: true - order: 0 - anti_spoofing_protection: false - requirements: - - virtualLink: - node: VL1 - - virtualBinding: - node: VDU2 - - VL1: - type: tosca.nodes.nfv.VL - properties: - network_name: net_mgmt - vendor: Tacker - - policies: - - SP1: - type: tosca.policies.tacker.Scaling - targets: [VDU1] - properties: - increment: 1 - cooldown: 120 - min_instances: 1 - max_instances: 2 - default_instances: 1 - - - SP2: - type: tosca.policies.tacker.Scaling - targets: [VDU2] - properties: - increment: 1 - cooldown: 120 - min_instances: 1 - max_instances: 2 - default_instances: 1 - - - ALRM1: - type: tosca.policies.tacker.Monitoring - triggers: - resize_compute: - event_type: - type: tosca.events.resource.utilization - implementation: ceilometer - condition: - constraint: 50 - period: 600 - evaluations: 1 - method: avg - action: - resize_compute: - action_name: SP1 diff --git a/nfvparser/src/main/python/toscaparser/tests/data/policies/tosca_policy_template.yaml b/nfvparser/src/main/python/toscaparser/tests/data/policies/tosca_policy_template.yaml deleted file mode 100644 index 47f7870..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/policies/tosca_policy_template.yaml +++ /dev/null @@ -1,85 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Template for deploying servers based on policies. - -imports: - - custom_definitions.yaml - -topology_template: - node_templates: - my_server_1: - 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 - - my_server_2: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: 2 - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Ubuntu - version: 14.04 - - groups: - webserver_group: - members: [ my_server_1, my_server_2 ] - type: tosca.groups.Root - metadata: { user1: 1008, user2: 1002 } - - - policies: - - my_compute_placement_policy: - type: tosca.policies.Placement - description: Apply placement policy to servers - metadata: { user1: 1001, user2: 1002 } - targets: [ my_server_1, my_server_2 ] - triggers: - resize_compute: - description: trigger - event_type: tosca.events.resource.utilization - schedule: - start_time: "2015-05-07T07:00:00Z" - end_time: "2015-06-07T07:00:00Z" - target_filter: - node: master-container - requirement: host - capability: Container - condition: - constraint: { greater_than: 50 } - period: 60 - evaluations: 1 - method: average - action: - resize: # Operation name - inputs: - strategy: LEAST_USED - implementation: Senlin.webhook() - - my_groups_placement: - type: mycompany.mytypes.myScalingPolicy - targets: [ webserver_group ] - description: my company scaling policy - metadata: - user1: 1001 - user2: 1003 - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/relationship/test_custom_relationship.yaml b/nfvparser/src/main/python/toscaparser/tests/data/relationship/test_custom_relationship.yaml deleted file mode 100644 index 81b92b4..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/relationship/test_custom_relationship.yaml +++ /dev/null @@ -1,48 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: Test template for deploying a single server with predefined properties and custom relationship types - -imports: - - ../custom_types/custom_relationship_type_defs.yaml - -topology_template: - node_templates: - server1: - type: tosca.nodes.HACompute - 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 - requirements: - - high_availability: server2 - - server2: - type: tosca.nodes.HACompute - 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 - requirements: - - high_availability: server1 diff --git a/nfvparser/src/main/python/toscaparser/tests/data/repositories/test_repositories_definition.yaml b/nfvparser/src/main/python/toscaparser/tests/data/repositories/test_repositories_definition.yaml deleted file mode 100644 index c2856c8..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/repositories/test_repositories_definition.yaml +++ /dev/null @@ -1,23 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -repositories: - some_repository: - description: Some repo - url: https://raw.githubusercontent.com/openstack/tosca-parser/master/toscaparser/tests/data/custom_types/ - credential: #type: Credential - token_type: basic_auth - token: myusername:mypassword -imports: - - some_import: - file: compute_with_prop.yaml - repository: some_repository - -description: > - TOSCA test for testing repositories definition - - node_templates: - - server: - type: tosca.nodes.ComputeWithProp - properties: - test: yes diff --git a/nfvparser/src/main/python/toscaparser/tests/data/repositories/tosca_repositories_test_definition.yaml b/nfvparser/src/main/python/toscaparser/tests/data/repositories/tosca_repositories_test_definition.yaml deleted file mode 100644 index 0001d06..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/repositories/tosca_repositories_test_definition.yaml +++ /dev/null @@ -1,26 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: TOSCA simple profile with repositories validation and imports. - -repositories: - repo_code0: https://raw.githubusercontent.com/nandinivemula/intern - repo_code1: - description: My project's code Repository in github usercontent. - url: https://raw.githubusercontent.com/nandinivemula/intern/master - credential: #type: Credential - token_type: basic_auth - token: myusername:mypassword - - repo_code2: - description: My Project's code Repository in github. - url: https://github.com/nandinivemula/intern/master - credential: #type: Credential - token_type: basic_auth - token: myusername:mypassword - -imports: - - sample_import: - file: tosca_repository_import.yaml - repository: repo_code1 - namespace_uri: https://github.com/nandinivemula/intern - namespace_prefix: intern diff --git a/nfvparser/src/main/python/toscaparser/tests/data/requirements/test_requirements.yaml b/nfvparser/src/main/python/toscaparser/tests/data/requirements/test_requirements.yaml deleted file mode 100644 index bb67577..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/requirements/test_requirements.yaml +++ /dev/null @@ -1,67 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Test Requirements. - -imports: - - ../custom_types/wordpress.yaml - -topology_template: - node_templates: - my_app: - description: > - Specify multiple requirement via node and relationship keyword, - as an explicit relationship. Also demonstrates relationship with - type keyword and without it as an in-line reference. - type: tosca.nodes.WebApplication.WordPress - requirements: - - req1: - node: my_webserver - relationship: tosca.relationships.HostedOn - - req2: - node: mysql_database - relationship: - type: tosca.relationships.ConnectsTo - mysql_database: - description: Specify requirement via a capability as an implicit relationship. - type: tosca.nodes.Database - requirements: - - host: - node: my_dbms - relationship: tosca.relationships.HostedOn - my_dbms: - type: tosca.nodes.DBMS - my_webserver: - type: tosca.nodes.WebServer - my_server: - description: > - Specify requirement via a relationship template, as an explicit relationship. - type: tosca.nodes.Compute - capabilities: - host: - properties: - num_cpus: 2 - disk_size: 10 GB - mem_size: 4 MB - os: - properties: - # host Operating System image properties - architecture: x86_64 - type: linux - distribution: rhel - version: 6.5 - requirements: - - req1: - node: my_storage - relationship: storage_attachment - my_storage: - type: tosca.nodes.BlockStorage - properties: - size: 1 GiB - snapshot_id: id - - relationship_templates: - storage_attachment: - type: tosca.relationships.AttachesTo - properties: - location: /temp diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_attributes_inheritance.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_attributes_inheritance.yaml deleted file mode 100644 index 0649c11..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_attributes_inheritance.yaml +++ /dev/null @@ -1,28 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: TOSCA simple profile to test the attribute inheritance - -imports: - - custom_types/compute_with_prop.yaml - -topology_template: - - node_templates: - - server: - type: tosca.nodes.ComputeWithProp - properties: - test: yes - capabilities: - host: - properties: - num_cpus: 1 - mem_size: 1 GB - os: - properties: - type: linux - - outputs: - server_ip: - value: { get_attribute: [ server, public_address ] } - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_available_rel_tpls.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_available_rel_tpls.yaml deleted file mode 100644 index e8d9045..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_available_rel_tpls.yaml +++ /dev/null @@ -1,23 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: TOSCA test for bug 1527214 - -topology_template: - - node_templates: - - test_db: - type: tosca.nodes.Database - requirements: - - host: - node: mysql - - mysql: - type: tosca.nodes.DBMS - requirements: - - host: - node: db_server - - db_server: - type: tosca.nodes.Compute - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_containers.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_containers.yaml deleted file mode 100644 index ba1cc16..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_containers.yaml +++ /dev/null @@ -1,44 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with mysql docker container. - -# Repositories to retrieve code artifacts from -repositories: - docker_hub: https://registry.hub.docker.com/ - -topology_template: - - inputs: - mysql_root_pwd: - type: string - description: Root password for MySQL. - - node_templates: - # The MYSQL container based on official MySQL image in Docker hub - mysql_container: - type: tosca.nodes.Container.Application - requirements: - - host: mysql_runtime - artifacts: - my_image: - file: mysql - type: tosca.artifacts.Deployment.Image.Container.Docker - repository: docker_hub - interfaces: - Standard: - create: - implementation: my_image - inputs: - MYSQL_ROOT_PASSWORD: { get_input: mysql_root_pwd } - - # The properties of the runtime to host the container - mysql_runtime: - type: tosca.nodes.Container.Runtime - capabilities: - host: - properties: - num_cpus: 1 - disk_size: 10 GB - mem_size: 2 MB - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_credential_datatype.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_credential_datatype.yaml deleted file mode 100644 index 583ec82..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_credential_datatype.yaml +++ /dev/null @@ -1,77 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with to demonstrate the usage of the - TOSCA Credential Data Type. - -imports: - - custom_types/wordpress.yaml - -relationship_types: - my.types.WordpressDbConnection: - derived_from: tosca.relationships.ConnectsTo - properties: - credential: - user: db_user - token: db_pwd - -topology_template: - node_templates: - wordpress: - type: tosca.nodes.WebApplication.WordPress - requirements: - - host: webserver - - database_endpoint: - node: mysql_database - relationship: my.types.WordpressDbConnection - - mysql_database: - type: tosca.nodes.Database - properties: - name: db_name - user: db_user - password: db_pwd - capabilities: - database_endpoint: - properties: - port: 3306 - requirements: - - host: - node: mysql_dbms - - mysql_dbms: - type: tosca.nodes.DBMS - properties: - root_password: db_root_pwd - port: 3306 - requirements: - - host: server - - webserver: - type: tosca.nodes.WebServer - properties: - admin_credential: - user: username - token: some_pass - requirements: - - host: server - - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: 1 - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Ubuntu - version: 14.04 - - outputs: - website_url: - description: URL for Wordpress wiki. - value: { get_attribute: [server, private_address] } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_custom_caps_def.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_custom_caps_def.yaml deleted file mode 100644 index 0b0984a..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_custom_caps_def.yaml +++ /dev/null @@ -1,13 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: TOSCA simple profile to test a custom defined capability - -imports: - - custom_types/custom_caps_def.yaml - -topology_template: - - node_templates: - - server: - type: tosca.nodes.SomeNode diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_custom_relationships.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_custom_relationships.yaml deleted file mode 100644 index 9c8171d..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_custom_relationships.yaml +++ /dev/null @@ -1,48 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: Test template for deploying a single server with predefined properties and custom relationship types - -imports: - - custom_types/custom_relationship_type_defs.yaml - -topology_template: - node_templates: - server1: - type: tosca.nodes.HACompute - 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 - requirements: - - high_availability: server2 - - server2: - type: tosca.nodes.HACompute - 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 - requirements: - - high_availability: server1 diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_endpoint_on_compute.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_endpoint_on_compute.yaml deleted file mode 100644 index cf2ec94..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_endpoint_on_compute.yaml +++ /dev/null @@ -1,21 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -topology_template: - node_templates: - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: 1 - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Ubuntu - version: 14.04 - endpoint: - properties: - network_name: PUBLIC diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_instance_nested_imports.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_instance_nested_imports.yaml deleted file mode 100644 index 6aa9307..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_instance_nested_imports.yaml +++ /dev/null @@ -1,22 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with wordpress, web server and mysql on the same server. - -imports: - - wordpress: custom_types/nested_test_wordpress.yaml - -topology_template: - - node_templates: - wordpress: - type: tosca.nodes.WebApplication.WordPress - - testrsyslogtype: - type: tosca.nodes.SoftwareComponent.Rsyslog.TestRsyslogType - - rsyslog: - type: Test2ndRsyslogType - - logstash: - type: tosca.nodes.SoftwareComponent.Logstash diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_invalid_input_defaults.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_invalid_input_defaults.yaml deleted file mode 100644 index f8f4ae7..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_invalid_input_defaults.yaml +++ /dev/null @@ -1,12 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: Test template with default not matching required type. - -topology_template: - inputs: - invalid_default: - type: integer - default: two - valid_default: - type: integer - default: 2 diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_invalid_section_names.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_invalid_section_names.yaml deleted file mode 100644 index 6241585..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_invalid_section_names.yaml +++ /dev/null @@ -1,25 +0,0 @@ -tosca_definitions_versions: tosca_simple_yaml_1_0 - -descriptions: > - TOSCA profile with invalid top-level section names. - -import: - - imported.yaml - -topology_templates: - - node_templates: - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: 1 - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Ubuntu - version: 14.04 diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_invalid_template_version.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_invalid_template_version.yaml deleted file mode 100644 index 86dce79..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_invalid_template_version.yaml +++ /dev/null @@ -1,14 +0,0 @@ -tosca_definitions_version: tosca_xyz - -description: > - Test template with an invalid template version. - -topology_template: - node_templates: - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - num_cpus: 2 - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_multiple_validation_errors.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_multiple_validation_errors.yaml deleted file mode 100644 index 479a1ec..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_multiple_validation_errors.yaml +++ /dev/null @@ -1,128 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1 - -description: > - TOSCA simple profile with wordpress, web server and mysql on the same server. - -imports: - - custom_types/not_there.yaml - -topology_template: - inputs: - cpus: - type: integer - description: Number of CPUs for the server. - constraints: - - valid_values: [ 1, 2, 4, 8 ] - default: 1 - db_name: - type: string - description: The name of the database. - default: wordpress - db_user: - type: string - description: The user name of the DB user. - default: wp_user - db_pwd: - type: string - description: The WordPress database admin account password. - default: wp_pass - db_root_pwd: - type: string - description: Root password for MySQL. - db_port: - type: PortDef - description: Port for the MySQL database. - default: 3306 - - node_templates: - xyz: - type: tosca.nodes.XYZ - - wordpress: - type: tosca.nodes.WebApplication.WordPress - requirement: - - host: webserver - - database_endpoint: mysql_database - interfaces: - Standard: - create: wordpress/wordpress_install.sh - configure: - implementation: wordpress/wordpress_configure.sh - inputs: - wp_db_name: { get_property: [ mysql_database, name ] } - wp_db_user: { get_property: [ mysql_database, user ] } - wp_db_password: { get_property: [ mysql_database, password ] } - - mysql_database: - type: tosca.nodes.Database - properties: - name: { get_input: db_name } - user: { get_input: db_user } - password: { get_input: db_pwd } - capabilities: - database_endpoint: - properties: - port: { get_input: db_port } - requirements: - - host: mysql_dbms - interfaces: - Standard: - configure: - implementation: mysql/mysql_database_configure.sh - inputs: - db_name: { get_property: [ SELF, name ] } - db_user: { get_property: [ SELF, user ] } - db_password: { get_property: [ SELF, passwords ] } - db_root_password: { get_property: [ mysql_dbms, root_password ] } - - mysql_dbms: - type1: tosca.nodes.DBMS - properties: - root_password: { get_input: db_root_pwd } - port: { get_input: db_port } - requirements: - - host: server - interfaces: - Standard: - create: - implementation: mysql/mysql_dbms_install.sh - inputs: - db_root_password: { get_property: [ mysql_dbms, root_password ] } - start: mysql/mysql_dbms_start.sh - configure: - implementation: mysql/mysql_dbms_configure.sh - inputs: - db_port: { get_property: [ mysql_dbms, port ] } - - webserver: - type: tosca.nodes.WebServer - requirements: - - host: server1 - - database_endpoint: - node: webserver - relationship: - type1: tosca.relationships.ConnectsTo - interfaces: - Standard: - create: webserver/webserver_install.sh - start: webserver/webserver_start.sh - - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: cpus } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Ubuntu - version: 14.04 - - outputs: - website_url: - description: URL for Wordpress wiki. - value: { get_attribute: [server, private_address] } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_no_inputs_in_template.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_no_inputs_in_template.yaml deleted file mode 100644 index 0b9da4c..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_no_inputs_in_template.yaml +++ /dev/null @@ -1,17 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Tosca template for testing a template with no inputs. - -metadata: test - -topology_template: - node_templates: - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - num_cpus: 2 - - outputs: diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_no_outputs_in_template.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_no_outputs_in_template.yaml deleted file mode 100644 index 51d42ff..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_no_outputs_in_template.yaml +++ /dev/null @@ -1,15 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Tosca template for testing a template with no outputs. - -topology_template: - inputs: - - node_templates: - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - num_cpus: 2 diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_node_filter.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_node_filter.yaml deleted file mode 100644 index 3dd8e26..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_node_filter.yaml +++ /dev/null @@ -1,18 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: Template with requirements against hosting infrastructure. - -topology_template: - - node_templates: - test: - type: tosca.nodes.DBMS - requirements: - - host: - node_filter: - capabilities: - - host: - properties: - - num_cpus: { in_range: [ 1, 4 ] } - - mem_size: { greater_or_equal: 2 GB } - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_normative_type_properties_override.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_normative_type_properties_override.yaml deleted file mode 100644 index 3c3e272..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_normative_type_properties_override.yaml +++ /dev/null @@ -1,37 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Test template for deploying a server with custom properties for image, - flavor and key_name. This template provides an example of how to - override TOSCA normative type's (e.g. Compute) properties. Here new - properties are injected in the tosca.nodes.myserver which derives from - tosca.nodes.Compute. Note that tosca.nodes.myserver can not be a name of - another normative type (e.g. tosca.nodes.WebServer or tosca.nodes.nfv.VDU) - because that will create conflict while resolving type definition by the - TOSCA Parser. - -node_types: - tosca.nodes.myserver: - derived_from: tosca.nodes.Compute - properties: - key_name: - type: string - image: - type: string - flavor: - type: string - -topology_template: - inputs: - key_name: - type: string - default: inputkey - - node_templates: - my_server: - type: tosca.nodes.myserver - properties: - flavor: m1.medium - image: rhel-6.5-test-image - key_name: - get_input: key_name diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_repositories_definition.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_repositories_definition.yaml deleted file mode 100644 index c2856c8..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_repositories_definition.yaml +++ /dev/null @@ -1,23 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -repositories: - some_repository: - description: Some repo - url: https://raw.githubusercontent.com/openstack/tosca-parser/master/toscaparser/tests/data/custom_types/ - credential: #type: Credential - token_type: basic_auth - token: myusername:mypassword -imports: - - some_import: - file: compute_with_prop.yaml - repository: some_repository - -description: > - TOSCA test for testing repositories definition - - node_templates: - - server: - type: tosca.nodes.ComputeWithProp - properties: - test: yes diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_requirements.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_requirements.yaml deleted file mode 100644 index 269c46d..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_requirements.yaml +++ /dev/null @@ -1,67 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Test Requirements. - -imports: - - custom_types/wordpress.yaml - -topology_template: - node_templates: - my_app: - description: > - Specify multiple requirement via node and relationship keyword, - as an explicit relationship. Also demonstrates relationship with - type keyword and without it as an in-line reference. - type: tosca.nodes.WebApplication.WordPress - requirements: - - req1: - node: my_webserver - relationship: tosca.relationships.HostedOn - - req2: - node: mysql_database - relationship: - type: tosca.relationships.ConnectsTo - mysql_database: - description: Specify requirement via a capability as an implicit relationship. - type: tosca.nodes.Database - requirements: - - host: - node: my_dbms - relationship: tosca.relationships.HostedOn - my_dbms: - type: tosca.nodes.DBMS - my_webserver: - type: tosca.nodes.WebServer - my_server: - description: > - Specify requirement via a relationship template, as an explicit relationship. - type: tosca.nodes.Compute - capabilities: - host: - properties: - num_cpus: 2 - disk_size: 10 GB - mem_size: 4 MB - os: - properties: - # host Operating System image properties - architecture: x86_64 - type: linux - distribution: rhel - version: 6.5 - requirements: - - req1: - node: my_storage - relationship: storage_attachment - my_storage: - type: tosca.nodes.BlockStorage - properties: - size: 1 GiB - snapshot_id: id - - relationship_templates: - storage_attachment: - type: tosca.relationships.AttachesTo - properties: - location: /temp diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_tosca_custom_rel_with_script.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_tosca_custom_rel_with_script.yaml deleted file mode 100644 index 18a94a3..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_tosca_custom_rel_with_script.yaml +++ /dev/null @@ -1,23 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: Test template of a custom relationship with a configure script - -topology_template: - - node_templates: - apache: - type: tosca.nodes.WebServer - requirements: - - host: - node: web_server - relationship: my_custom_rel - - web_server: - type: tosca.nodes.Compute - - relationship_templates: - my_custom_rel: - type: HostedOn - interfaces: - Configure: - pre_configure_source: scripts/wp_db_configure.sh diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_tosca_normative_type_by_shortname.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_tosca_normative_type_by_shortname.yaml deleted file mode 100644 index c0653e7..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_tosca_normative_type_by_shortname.yaml +++ /dev/null @@ -1,34 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with short type name for Compute. - -topology_template: - inputs: - cpus: - type: integer - description: Number of CPUs for the server. - constraints: - - valid_values: [ 1, 2, 4, 8 ] - default: 2 - - node_templates: - server: - type: Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: cpus } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Fedora - version: 18.0 - - outputs: - server_address: - description: IP address of server instance. - value: { get_attribute: [server, private_address] } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_tosca_top_level_error1.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_tosca_top_level_error1.yaml deleted file mode 100644 index d35c022..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_tosca_top_level_error1.yaml +++ /dev/null @@ -1,2 +0,0 @@ -description: > - TOSCA simple profile missing version section. \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/data/test_tosca_top_level_error2.yaml b/nfvparser/src/main/python/toscaparser/tests/data/test_tosca_top_level_error2.yaml deleted file mode 100644 index b3e80f9..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/test_tosca_top_level_error2.yaml +++ /dev/null @@ -1,11 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with invalid top-level key: 'node_template'. - -topology_template: - - node_template: - server: - type: tosca.nodes.Compute - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/databasesubsystem.yaml b/nfvparser/src/main/python/toscaparser/tests/data/topology_template/databasesubsystem.yaml deleted file mode 100644 index b6e9c42..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/databasesubsystem.yaml +++ /dev/null @@ -1,81 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Database subsystem, which is service template with topology_template, - act as a nested system inside another system and also act as stand - alone service template. - -imports: - - definitions.yaml - -topology_template: - description: Template of a database including its hosting stack. - - inputs: - user: - type: string - description: the user name of database. - default: test - port: - type: integer - description: the port of database. - default: 3306 - name: - type: string - description: the name of database. - default: test - my_cpus: - type: integer - description: Number of CPUs for the server. - default: 2 - constraints: - - valid_values: [ 1, 2, 4, 8 ] - - substitution_mappings: - node_type: example.DatabaseSubsystem - capabilities: - database_endpoint: [ db_app, database_endpoint ] - - node_templates: - db_app: - type: tosca.nodes.Database - properties: - user: { get_input: user } - port: { get_input: port } - name: { get_input: name } - capabilities: - database_endpoint: - properties: - port: 1234 - requirements: - - host: - node: dbms - - dbms: - type: tosca.nodes.DBMS - properties: - port: 3306 - root_password: 123456789 - requirements: - - host: - node: server - - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: my_cpus } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Ubuntu - version: 14.04 - - groups: - dbserver_group: - members: [ dbms, server ] - type: tosca.groups.Root diff --git a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/definitions.yaml b/nfvparser/src/main/python/toscaparser/tests/data/topology_template/definitions.yaml deleted file mode 100644 index ba5eac1..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/definitions.yaml +++ /dev/null @@ -1,74 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -node_types: - example.QueuingSubsystem: - derived_from: tosca.nodes.SoftwareComponent - properties: - server_ip: - type: string - server_port: - type: integer - attributes: - server_ip: - type: string - server_port: - type: integer - requirements: - - receiver1: - node: example.TransactionSubsystem - capability: example.capabilities.Receiver - relationship: tosca.relationships.ConnectsTo - - receiver2: - node: example.TransactionSubsystem - capability: example.capabilities.Receiver - relationship: tosca.relationships.ConnectsTo - - example.TransactionSubsystem: - properties: - mq_server_ip: - type: string - required: False - receiver_port: - type: integer - required: False - attributes: - receiver_ip: - type: string - receiver_port: - type: integer - capabilities: - message_receiver: - type: example.capabilities.Receiver - requirements: - - database_endpoint: - node: tosca.nodes.Database - capability: tosca.capabilities.Endpoint.Database - relationship: tosca.relationships.ConnectsTo - - example.DatabaseSubsystem: - derived_from: tosca.nodes.Database - - example.SomeApp: - derived_from: tosca.nodes.SoftwareComponent - properties: - admin_user: - type: string - required: False - pool_size: - type: integer - required: False - capabilities: - message_receiver: - type: example.capabilities.Receiver - requirements: - - database: - node: tosca.nodes.Database - capability: tosca.capabilities.Endpoint.Database - relationship: tosca.relationships.ConnectsTo - -capability_types: - example.capabilities.Receiver: - derived_from: tosca.capabilities.Endpoint - properties: - server_ip: - type: string diff --git a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/queuingsubsystem.yaml b/nfvparser/src/main/python/toscaparser/tests/data/topology_template/queuingsubsystem.yaml deleted file mode 100644 index 578aa4a..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/queuingsubsystem.yaml +++ /dev/null @@ -1,75 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Queue subsystem, which is service template with topology_template, - act as a nested system inside another system and also act as stand - alone service template. - -imports: - - definitions.yaml - -topology_template: - description: Template of a database including its hosting stack. - - inputs: - server_ip: - type: string - description: IP address of the message queuing server to receive messages from. - default: 127.0.0.1 - server_port: - type: integer - description: Port to be used for receiving messages. - default: 8080 - my_cpus: - type: integer - description: Number of CPUs for the server. - default: 2 - constraints: - - valid_values: [ 1, 2, 4, 8 ] - - substitution_mappings: - node_type: example.QueuingSubsystem - # capabilities: - # message_receiver: [ app, message_receiver ] - requirements: - receiver1: [ tran_app, receiver1 ] - receiver2: [ tran_app, receiver2 ] - - node_templates: - tran_app: - type: example.QueuingSubsystem - properties: - server_ip: { get_input: server_ip } - server_port: { get_input: server_port } - requirements: - - host: - node: server - - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: my_cpus } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Ubuntu - version: 14.04 - - outputs: - server_ip: - description: server_ip of the message receiver application - value: { get_input: server_ip } - - server_port: - description: server_port of the message receiver application - value: { get_input: server_port } - - groups: - tran_server_group: - members: [ tran_app, server ] - type: tosca.groups.Root diff --git a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/system.yaml b/nfvparser/src/main/python/toscaparser/tests/data/topology_template/system.yaml deleted file mode 100644 index f4e10ae..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/system.yaml +++ /dev/null @@ -1,62 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -imports: - - queuingsubsystem.yaml - - transactionsubsystem.yaml - - databasesubsystem.yaml - -topology_template: - description: Template of online transaction processing service. - - inputs: - mq_server_ip: - type: string - default: 127.0.0.1 - description: IP address of the message queuing server to receive messages from. - mq_server_port: - type: integer - default: 8080 - description: Port to be used for receiving messages. - - node_templates: - mq: - type: example.QueuingSubsystem - properties: - server_ip: { get_input: mq_server_ip } - server_port: { get_input: mq_server_port } - # capabilities: - # message_queue_endpoint: - # to be updated when substitution_mapping is validated later - requirements: - - receiver1: trans1 - - receiver2: trans2 - - trans1: - type: example.TransactionSubsystem - properties: - mq_server_ip: { get_attribute: [ mq, server_ip ] } - receiver_port: { get_attribute: [ mq, server_port ] } - # capabilities: - # message_receiver: - # to be updated when substitution_mapping is validated later - requirements: - - database_endpoint: dbsys - - trans2: - type: example.TransactionSubsystem - properties: - mq_server_ip: { get_attribute: [ mq, server_ip ] } - receiver_port: { get_attribute: [ mq, server_port ] } - # capabilities: - # message_receiver: - # to be updated when substitution_mapping is validated later - requirements: - - database_endpoint: dbsys - - dbsys: - type: example.DatabaseSubsystem - # properties: - # to be updated when substitution_mapping is validated later - # capabilities: - # database_endpoint: - # to be updated when substitution_mapping is validated later diff --git a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/transactionsubsystem.yaml b/nfvparser/src/main/python/toscaparser/tests/data/topology_template/transactionsubsystem.yaml deleted file mode 100644 index 42e100a..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/transactionsubsystem.yaml +++ /dev/null @@ -1,88 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Transaction subsystem, which is service template with topology_template, - act as a nested system inside another system and also act as stand - alone service template. - -imports: - - definitions.yaml - -topology_template: - description: Template of a database including its hosting stack. - - inputs: - mq_server_ip: - type: string - description: IP address of the message queuing server to receive messages from. - default: 127.0.0.1 - receiver_port: - type: integer - description: Port to be used for receiving messages. - default: 8080 - my_cpus: - type: integer - description: Number of CPUs for the server. - default: 2 - constraints: - - valid_values: [ 1, 2, 4, 8 ] - - substitution_mappings: - node_type: example.TransactionSubsystem - capabilities: - message_receiver: [ app, message_receiver ] - requirements: - database_endpoint: [ app, database ] - - node_templates: - app: - type: example.SomeApp - properties: - admin_user: foo - pool_size: 10 - capabilities: - message_receiver: - properties: - server_ip: { get_input: mq_server_ip } - requirements: - - host: - node: websrv - - websrv: - type: tosca.nodes.WebServer - capabilities: - data_endpoint: - properties: - port_name: { get_input: receiver_port } - requirements: - - host: - node: server - - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: my_cpus } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Ubuntu - version: 14.04 - - outputs: - receiver_ip: - description: private IP address of the message receiver application - value: { get_attribute: [ server, private_address ] } - - receiver_port: - description: receiver_port of the message receiver application - value: { get_input: receiver_port } - - groups: - webserver_group: - members: [ websrv, server ] - type: tosca.groups.Root diff --git a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/queuingsubsystem_invalid_input.yaml b/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/queuingsubsystem_invalid_input.yaml deleted file mode 100644 index 67ef341..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/queuingsubsystem_invalid_input.yaml +++ /dev/null @@ -1,76 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - This template is a test template which contains invalid input needed for substitution mappings. - The required properties without default value in substituted node template which be mapped must be - as inputs of nested service template which defines substutition mappings, and the inputs of nested - service template which are not in the properties of the substituted node template must provide - default values. - This template provides an additional input of server_port1/my_cpus/my_input which are not defined - in example.QueuingSubsystem, and the default value are 8080/2/123, all of these are right. But the - required property of server_port defined in example.QueuingSubsystem is not appeared in inputs - definiton, so will raise excepton of "MissingRequiredInputError". - -imports: - - ../definitions.yaml - -topology_template: - description: Template of a database including its hosting stack. - - inputs: - server_ip: - type: string - description: IP address of the message queuing server to receive messages from. - default: 127.0.0.1 - server_port1: - type: integer - description: Port to be used for receiving messages. - default: 8080 - my_cpus: - type: integer - description: Number of CPUs for the server. - default: 2 - constraints: - - valid_values: [ 1, 2, 4, 8 ] - my_input: - type: integer - description: test for input validation. - default: 123 - - substitution_mappings: - node_type: example.QueuingSubsystem - - node_templates: - tran_app: - type: example.QueuingSubsystem - properties: - server_ip: { get_input: server_ip } - server_port: { get_input: server_port1 } - requirements: - - host: - node: server - - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: my_cpus } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Ubuntu - version: 14.04 - - outputs: - receiver_ip: - description: private IP address of the message receiver application - value: { get_attribute: [ server, private_address ] } - - groups: - tran_server_group: - members: [ tran_app, server ] - type: tosca.groups.Root diff --git a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/system_invalid_input.yaml b/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/system_invalid_input.yaml deleted file mode 100644 index e3cdd71..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/system_invalid_input.yaml +++ /dev/null @@ -1,24 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -imports: - - queuingsubsystem_invalid_input.yaml - -topology_template: - description: Test template with invalid input. - - inputs: - mq_server_ip: - type: string - default: 127.0.0.1 - description: IP address of the message queuing server to receive messages from. - mq_server_port: - type: integer - default: 8080 - description: Port to be used for receiving messages. - - node_templates: - mq: - type: example.QueuingSubsystem - properties: - server_ip: { get_input: mq_server_ip } - server_port: { get_input: mq_server_port } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/system_invalid_missing_output.yaml b/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/system_invalid_missing_output.yaml deleted file mode 100644 index 2028c38..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/system_invalid_missing_output.yaml +++ /dev/null @@ -1,24 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -imports: - - transactionsubsystem_invalid_missing_output.yaml - -topology_template: - description: Test template with invalid missing output. - - inputs: - mq_server_ip: - type: string - default: 127.0.0.1 - description: IP address of the message queuing server to receive messages from. - mq_server_port: - type: integer - default: 8080 - description: Port to be used for receiving messages. - - node_templates: - trans: - type: example.TransactionSubsystem - properties: - mq_server_ip: { get_input: mq_server_ip } - receiver_port: { get_input: mq_server_port } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/system_invalid_unknown_output.yaml b/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/system_invalid_unknown_output.yaml deleted file mode 100644 index de16ca2..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/system_invalid_unknown_output.yaml +++ /dev/null @@ -1,24 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -imports: - - transactionsubsystem_invalid_unknown_output.yaml - -topology_template: - description: Test template with invalid unknown output. - - inputs: - mq_server_ip: - type: string - default: 127.0.0.1 - description: IP address of the message queuing server to receive messages from. - mq_server_port: - type: integer - default: 8080 - description: Port to be used for receiving messages. - - node_templates: - trans: - type: example.TransactionSubsystem - properties: - mq_server_ip: { get_input: mq_server_ip } - receiver_port: { get_input: mq_server_port } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/test_example_app_substitution_mappings.yaml b/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/test_example_app_substitution_mappings.yaml deleted file mode 100644 index 718022a..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/test_example_app_substitution_mappings.yaml +++ /dev/null @@ -1,70 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Template showing an example TOSCA type to demonstrate usage - of output in the substitution mappings. - -node_types: - example.app: - derived_from: tosca.nodes.WebApplication - properties: - mq_server_ip: - type: string - required: False - receiver_port: - type: integer - required: False - attributes: - receiver_ip: - type: string - receiver_port: - type: integer - -topology_template: - inputs: - mq_server_ip: - type: string - description: IP address of the message queuing server to receive messages from. - default: 127.0.0.1 - receiver_port: - type: integer - description: Port to be used for receiving messages. - default: 8080 - my_cpus: - type: integer - description: Number of CPUs for the server. - default: 2 - constraints: - - valid_values: [ 1, 2, 4, 8 ] - - substitution_mappings: - node_type: example.app - - node_templates: - app: - type: example.app - properties: - mq_server_ip: { get_input: mq_server_ip } - receiver_port: { get_input: receiver_port } - requirements: - - host: - node: websrv - websrv: - type: tosca.nodes.WebServer - requirements: - - host: - node: server - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: my_cpus } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Ubuntu - version: 14.04 diff --git a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/test_substitution_mappings_invalid_output.yaml b/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/test_substitution_mappings_invalid_output.yaml deleted file mode 100644 index ef21811..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/test_substitution_mappings_invalid_output.yaml +++ /dev/null @@ -1,31 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -imports: - - test_example_app_substitution_mappings.yaml - -topology_template: - description: > - Test template showing valid output section containing attribute defined - in the substitution mappings in the imported yaml file. - - inputs: - mq_server_ip: - type: string - default: 127.0.0.1 - description: IP address of the message queuing server to receive messages from. - mq_server_port: - type: integer - default: 8080 - description: Port to be used for receiving messages. - - node_templates: - substitute_app: - type: example.app - properties: - mq_server_ip: { get_input: mq_server_ip } - receiver_port: { get_input: mq_server_port } - - outputs: - receiver_ip: - description: private IP address of the message receiver application - value: { get_attribute: [ substitute_app, my_cpu_output ] } \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/test_substitution_mappings_valid_output.yaml b/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/test_substitution_mappings_valid_output.yaml deleted file mode 100644 index 766ca87..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/test_substitution_mappings_valid_output.yaml +++ /dev/null @@ -1,31 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -imports: - - test_example_app_substitution_mappings.yaml - -topology_template: - description: > - Test template showing valid output section containing attribute defined - in the substitution mappings in the imported yaml file. - - inputs: - mq_server_ip: - type: string - default: 127.0.0.1 - description: IP address of the message queuing server to receive messages from. - mq_server_port: - type: integer - default: 8080 - description: Port to be used for receiving messages. - - node_templates: - sustitute_app: - type: example.app - properties: - mq_server_ip: { get_input: mq_server_ip } - receiver_port: { get_input: mq_server_port } - - outputs: - receiver_ip: - description: private IP address of the message receiver application - value: { get_attribute: [ sustitute_app, receiver_ip ] } \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/transactionsubsystem_invalid_missing_output.yaml b/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/transactionsubsystem_invalid_missing_output.yaml deleted file mode 100644 index c92e5f8..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/transactionsubsystem_invalid_missing_output.yaml +++ /dev/null @@ -1,92 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - This template is a test template which contains invalid output - needed for substitution mappings. - The outputs defined by the topology template have to match the - attributes of the node type or the substituted node template, - and the observable attributes of the substituted node template - have to be defined as attributes of the node type or outputs in - the topology template. - But this template misses output of receiver_port which is not - defined in node type of example.TransactionSubsystem, so it will - be validated error for substitution mappings. - -imports: - - ../definitions.yaml - -topology_template: - description: Template of a database including its hosting stack. - - inputs: - mq_server_ip: - type: string - description: IP address of the message queuing server to receive messages from. - default: 127.0.0.1 - receiver_port: - type: integer - description: Port to be used for receiving messages. - default: 8080 - my_cpus: - type: integer - description: Number of CPUs for the server. - default: 2 - constraints: - - valid_values: [ 1, 2, 4, 8 ] - - substitution_mappings: - node_type: example.TransactionSubsystem - capabilities: - message_receiver: [ app, message_receiver ] - requirements: - database_endpoint: [ app, database ] - - node_templates: - app: - type: example.SomeApp - properties: - admin_user: foo - pool_size: 10 - capabilities: - message_receiver: - properties: - server_ip: { get_input: mq_server_ip } - requirements: - - host: - node: websrv - - websrv: - type: tosca.nodes.WebServer - capabilities: - data_endpoint: - properties: - port_name: { get_input: receiver_port } - requirements: - - host: - node: server - - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: my_cpus } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Ubuntu - version: 14.04 - - outputs: - receiver_ip: - description: private IP address of the message receiver application - value: { get_attribute: [ server, private_address ] } - - # This output is invalid if comment receiver_out out only for - # substituion mappings -# receiver_port: -# description: receiver_port of the message receiver application -# value: { get_input: receiver_port } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/transactionsubsystem_invalid_unknown_output.yaml b/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/transactionsubsystem_invalid_unknown_output.yaml deleted file mode 100644 index ffca24b..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/topology_template/validate/transactionsubsystem_invalid_unknown_output.yaml +++ /dev/null @@ -1,94 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - This template is a test template which contains invalid output - needed for substitution mappings. - The outputs defined by the topology template have to match the - attributes of the node type or the substituted node template, - and the observable attributes of the substituted node template - have to be defined as attributes of the node type or outputs in - the topology template. - But this template contains output of my_cpu_output which is not - defined in node type of example.TransactionSubsystem, so it will - be validated error for substitution mappings. - -imports: - - ../definitions.yaml - -topology_template: - description: Template of a database including its hosting stack. - - inputs: - mq_server_ip: - type: string - description: IP address of the message queuing server to receive messages from. - default: 127.0.0.1 - receiver_port: - type: integer - description: Port to be used for receiving messages. - default: 8080 - my_cpus: - type: integer - description: Number of CPUs for the server. - default: 2 - constraints: - - valid_values: [ 1, 2, 4, 8 ] - - substitution_mappings: - node_type: example.TransactionSubsystem - capabilities: - message_receiver: [ app, message_receiver ] - requirements: - database_endpoint: [ app, database ] - - node_templates: - app: - type: example.SomeApp - properties: - admin_user: foo - pool_size: 10 - capabilities: - message_receiver: - properties: - server_ip: { get_input: mq_server_ip } - requirements: - - host: - node: websrv - - websrv: - type: tosca.nodes.WebServer - capabilities: - data_endpoint: - properties: - port_name: { get_input: receiver_port } - requirements: - - host: - node: server - - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: my_cpus } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Ubuntu - version: 14.04 - - outputs: - receiver_ip: - description: private IP address of the message receiver application - value: { get_attribute: [ server, private_address ] } - - receiver_port: - description: receiver_port of the message receiver application - value: { get_input: receiver_port } - - my_cpu_output: - description: this output is only invalid for substitution mappings - value: { get_input: my_cpus } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/tosca_elk.yaml b/nfvparser/src/main/python/toscaparser/tests/data/tosca_elk.yaml deleted file mode 100644 index 6fc1756..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/tosca_elk.yaml +++ /dev/null @@ -1,217 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - This TOSCA simple profile deploys nodejs, mongodb, elasticsearch, logstash - and kibana each on a separate server with monitoring enabled for nodejs - server where a sample nodejs application is running. The rsyslog and collectd - are installed on a nodejs server. - -imports: - - custom_types/paypalpizzastore_nodejs_app.yaml - - custom_types/elasticsearch.yaml - - custom_types/logstash.yaml - - custom_types/kibana.yaml - - custom_types/collectd.yaml - - custom_types/rsyslog.yaml - -dsl_definitions: - host_capabilities: &host_capabilities - disk_size: 10 GB - num_cpus: { get_input: my_cpus } - mem_size: 4096 MB - os_capabilities: &os_capabilities - architecture: x86_64 - type: Linux - distribution: Ubuntu - version: 14.04 - -topology_template: - inputs: - my_cpus: - type: integer - description: Number of CPUs for the server. - constraints: - - valid_values: [ 1, 2, 4, 8 ] - default: 1 - github_url: - type: string - description: The URL to download nodejs. - default: http://github.com/paypal/rest-api-sample-app-nodejs.git - - node_templates: - paypal_pizzastore: - type: tosca.nodes.WebApplication.PayPalPizzaStore - properties: - github_url: { get_input: github_url } - requirements: - - host: nodejs - - database_connection: mongo_db - interfaces: - Standard: - configure: - implementation: nodejs/config.sh - inputs: - github_url: { get_property: [ SELF, github_url ] } - mongodb_ip: { get_attribute: [mongo_server, private_address] } - start: nodejs/start.sh - nodejs: - type: tosca.nodes.WebServer - requirements: - - host: app_server - interfaces: - Standard: - create: nodejs/create.sh - mongo_db: - type: tosca.nodes.Database - requirements: - - host: mongo_dbms - interfaces: - Standard: - create: mongodb/create_database.sh - mongo_dbms: - type: tosca.nodes.DBMS - requirements: - - host: mongo_server - interfaces: - Standard: - create: mongodb/create.sh - configure: - implementation: mongodb/config.sh - inputs: - mongodb_ip: { get_attribute: [mongo_server, private_address] } - start: mongodb/start.sh - elasticsearch: - type: tosca.nodes.SoftwareComponent.Elasticsearch - requirements: - - host: elasticsearch_server - interfaces: - Standard: - create: elasticsearch/create.sh - start: elasticsearch/start.sh - logstash: - type: tosca.nodes.SoftwareComponent.Logstash - requirements: - - host: logstash_server - - search_endpoint: - node: elasticsearch - capability: search_endpoint - relationship: - type: tosca.relationships.ConnectsTo - interfaces: - Configure: - pre_configure_source: - implementation: logstash/configure_elasticsearch.py - inputs: - elasticsearch_ip: { get_attribute: [elasticsearch_server, private_address] } - interfaces: - Standard: - create: logstash/create.sh - start: logstash/start.sh - kibana: - type: tosca.nodes.SoftwareComponent.Kibana - requirements: - - host: kibana_server - - search_endpoint: elasticsearch - interfaces: - Standard: - create: kibana/create.sh - configure: - implementation: kibana/config.sh - inputs: - elasticsearch_ip: { get_attribute: [elasticsearch_server, private_address] } - kibana_ip: { get_attribute: [kibana_server, private_address] } - start: kibana/start.sh - app_collectd: - type: tosca.nodes.SoftwareComponent.Collectd - requirements: - - host: app_server - - log_endpoint: - node: logstash - capability: log_endpoint - relationship: - type: tosca.relationships.ConnectsTo - interfaces: - Configure: - pre_configure_target: - implementation: logstash/configure_collectd.py - interfaces: - Standard: - create: collectd/create.sh - configure: - implementation: collectd/config.py - inputs: - logstash_ip: { get_attribute: [logstash_server, private_address] } - start: collectd/start.sh - app_rsyslog: - type: tosca.nodes.SoftwareComponent.Rsyslog - requirements: - - host: app_server - - log_endpoint: - node: logstash - capability: log_endpoint - relationship: - type: tosca.relationships.ConnectsTo - interfaces: - Configure: - pre_configure_target: - implementation: logstash/configure_rsyslog.py - interfaces: - Standard: - create: rsyslog/create.sh - configure: - implementation: rsyslog/config.sh - inputs: - logstash_ip: { get_attribute: [logstash_server, private_address] } - start: rsyslog/start.sh - app_server: - type: tosca.nodes.Compute - capabilities: - host: - properties: *host_capabilities - os: - properties: *os_capabilities - mongo_server: - type: tosca.nodes.Compute - capabilities: - host: - properties: *host_capabilities - os: - properties: *os_capabilities - elasticsearch_server: - type: tosca.nodes.Compute - capabilities: - host: - properties: *host_capabilities - os: - properties: *os_capabilities - logstash_server: - type: tosca.nodes.Compute - capabilities: - host: - properties: *host_capabilities - os: - properties: *os_capabilities - kibana_server: - type: tosca.nodes.Compute - capabilities: - host: - properties: *host_capabilities - os: - properties: *os_capabilities - - outputs: - nodejs_url: - description: URL for the nodejs server, http://:3000 - value: { get_attribute: [ app_server, private_address ] } - mongodb_url: - description: URL for the mongodb server. - value: { get_attribute: [ mongo_server, private_address ] } - elasticsearch_url: - description: URL for the elasticsearch server. - value: { get_attribute: [ elasticsearch_server, private_address ] } - logstash_url: - description: URL for the logstash server. - value: { get_attribute: [ logstash_server, private_address ] } - kibana_url: - description: URL for the kibana server. - value: { get_attribute: [ kibana_server, private_address ] } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/tosca_helloworld.yaml b/nfvparser/src/main/python/toscaparser/tests/data/tosca_helloworld.yaml deleted file mode 100644 index 5b913ff..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/tosca_helloworld.yaml +++ /dev/null @@ -1,23 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -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/src/main/python/toscaparser/tests/data/tosca_imports_validation.yaml b/nfvparser/src/main/python/toscaparser/tests/data/tosca_imports_validation.yaml deleted file mode 100644 index 257beb8..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/tosca_imports_validation.yaml +++ /dev/null @@ -1,45 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: Template to test invalid imports. - -imports: - - custom_types/imported_sample.yaml - -topology_template: - node_templates: - logstash: - type: tosca.nodes.SoftwareComponent.Logstash - requirements: - - search_endpoint: - capability: search_endpoint - relationship: - type: tosca.relationships.ConnectsTo - interfaces: - Configure: - pre_configure_source: - implementation: logstash/configure_elasticsearch.py - inputs: - elasticsearch_ip: { get_attribute: [elasticsearch_server, private_address] } - interfaces: - Standard: - create: logstash/create.sh - start: logstash/start.sh - policies: - - my_compute_placement_policy: - type: tosca.policies.Placement - description: Apply placement policy to servers - metadata: { user1: 1001, user2: 1002 } - targets: [ my_server_1, my_server_2 ] - - my_groups_placement: - type: mycompany.mytypes.myScalingPolicy - targets: [ webserver_group ] - description: my company scaling policy - metadata: - user1: 1001 - user2: 1003 - relationship_templates: - my_custom_rel: - type: test.relation.connects - interfaces: - Configure: - pre_configure_source: scripts/wp_db_configure.sh diff --git a/nfvparser/src/main/python/toscaparser/tests/data/tosca_load_balancer.yaml b/nfvparser/src/main/python/toscaparser/tests/data/tosca_load_balancer.yaml deleted file mode 100644 index 2fcdb48..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/tosca_load_balancer.yaml +++ /dev/null @@ -1,75 +0,0 @@ -# Note: this could eventually be translated to a Neutron Load Balancer -# However, in Heat/HOT the preferred way of doing this is creating an Autoscale Group -# -#heat_template_version: 2015-04-30 ... -#resources: -#load_bal_resource: -# type: OS::Neutron::Pool -# properties: -# admin_state_up: Boolean -# description: String -# lb_method: String -# monitors: [Value, Value, ...] -# name: String -# protocol: String -# provider: String -# subnet: String -# vip: { -# "description": String, -# "name": String, -# "connection_limit": Integer, -# "protocol_port": Integer, -# "subnet": String, -# "address": String, -# "admin_state_up": Boolean, -# "session_persistence": -# { -# "cookie_name": String, -# "type": String} -# } -# -# example from: https://gist.github.com/therve/9231701 -# -#resources: -# web_server_group: -# type: AWS::AutoScaling::AutoScalingGroup -# properties: -# AvailabilityZones: [nova] -# LaunchConfigurationName: {get_resource: launch_config} -# MinSize: 1 -# MaxSize: 3 -# LoadBalancerNames: -# - {get_resource: mylb} -# mypool: -# type: OS::Neutron::Pool -# properties: -# protocol: HTTP -# monitors: [{get_resource: mymonitor}] -# subnet_id: {get_param: subnet_id} -# lb_method: ROUND_ROBIN -# vip: -# protocol_port: 80 -# mylb: -# type: OS::Neutron::LoadBalancer -# properties: -# protocol_port: 80 -# pool_id: {get_resource: mypool} - -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: Template for deploying a load balancer with predefined endpoint properties. - -topology_template: - node_templates: - simple_load_balancer: - type: tosca.nodes.LoadBalancer - capabilities: - # properties: - # algorithm: DEFAULT (define new keyword, ROUND_ROBIN?) - # Client, public facing endpoint - client: - properties: - network_name: PUBLIC - floating: true - dns_name: http://mycompany.com/ - diff --git a/nfvparser/src/main/python/toscaparser/tests/data/tosca_repositories_test_definition.yaml b/nfvparser/src/main/python/toscaparser/tests/data/tosca_repositories_test_definition.yaml deleted file mode 100644 index 0001d06..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/tosca_repositories_test_definition.yaml +++ /dev/null @@ -1,26 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: TOSCA simple profile with repositories validation and imports. - -repositories: - repo_code0: https://raw.githubusercontent.com/nandinivemula/intern - repo_code1: - description: My project's code Repository in github usercontent. - url: https://raw.githubusercontent.com/nandinivemula/intern/master - credential: #type: Credential - token_type: basic_auth - token: myusername:mypassword - - repo_code2: - description: My Project's code Repository in github. - url: https://github.com/nandinivemula/intern/master - credential: #type: Credential - token_type: basic_auth - token: myusername:mypassword - -imports: - - sample_import: - file: tosca_repository_import.yaml - repository: repo_code1 - namespace_uri: https://github.com/nandinivemula/intern - namespace_prefix: intern diff --git a/nfvparser/src/main/python/toscaparser/tests/data/tosca_single_instance_wordpress.yaml b/nfvparser/src/main/python/toscaparser/tests/data/tosca_single_instance_wordpress.yaml deleted file mode 100644 index 9e686ab..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/tosca_single_instance_wordpress.yaml +++ /dev/null @@ -1,121 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with wordpress, web server and mysql on the same server. - -imports: - - custom_types/wordpress.yaml - -topology_template: - inputs: - cpus: - type: integer - description: Number of CPUs for the server. - constraints: - - valid_values: [ 1, 2, 4, 8 ] - default: 1 - db_name: - type: string - description: The name of the database. - default: wordpress - db_user: - type: string - description: The user name of the DB user. - default: wp_user - db_pwd: - type: string - description: The WordPress database admin account password. - default: wp_pass - db_root_pwd: - type: string - description: Root password for MySQL. - db_port: - type: PortDef - description: Port for the MySQL database. - default: 3306 - - node_templates: - wordpress: - type: tosca.nodes.WebApplication.WordPress - requirements: - - host: webserver - - database_endpoint: mysql_database - interfaces: - Standard: - create: wordpress/wordpress_install.sh - configure: - implementation: wordpress/wordpress_configure.sh - inputs: - wp_db_name: { get_property: [ mysql_database, name ] } - wp_db_user: { get_property: [ mysql_database, user ] } - wp_db_password: { get_property: [ mysql_database, password ] } - - mysql_database: - type: tosca.nodes.Database - properties: - name: { get_input: db_name } - user: { get_input: db_user } - password: { get_input: db_pwd } - capabilities: - database_endpoint: - properties: - port: { get_input: db_port } - requirements: - - host: mysql_dbms - interfaces: - Standard: - configure: - implementation: mysql/mysql_database_configure.sh - inputs: - db_name: { get_property: [ SELF, name ] } - db_user: { get_property: [ SELF, user ] } - db_password: { get_property: [ SELF, password ] } - db_root_password: { get_property: [ mysql_dbms, root_password ] } - - mysql_dbms: - type: tosca.nodes.DBMS - properties: - root_password: { get_input: db_root_pwd } - port: { get_input: db_port } - requirements: - - host: server - interfaces: - Standard: - create: - implementation: mysql/mysql_dbms_install.sh - inputs: - db_root_password: { get_property: [ mysql_dbms, root_password ] } - start: mysql/mysql_dbms_start.sh - configure: - implementation: mysql/mysql_dbms_configure.sh - inputs: - db_port: { get_property: [ mysql_dbms, port ] } - - webserver: - type: tosca.nodes.WebServer - requirements: - - host: server - interfaces: - Standard: - create: webserver/webserver_install.sh - start: webserver/webserver_start.sh - - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: cpus } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Ubuntu - version: 14.04 - - outputs: - website_url: - description: URL for Wordpress wiki. - value: { get_attribute: [server, private_address] } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/tosca_single_instance_wordpress_with_local_abspath_import.yaml b/nfvparser/src/main/python/toscaparser/tests/data/tosca_single_instance_wordpress_with_local_abspath_import.yaml deleted file mode 100644 index 6caac11..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/tosca_single_instance_wordpress_with_local_abspath_import.yaml +++ /dev/null @@ -1,122 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with wordpress, web server and mysql on the same server. - Parsing of this test template will fail with errors if provided imports does - not refer to a valid absolute path. - -imports: - - /tmp/tosca-parser/toscaparser/tests/data/custom_types/wordpress.yaml - -topology_template: - inputs: - cpus: - type: integer - description: Number of CPUs for the server. - constraints: - - valid_values: [ 1, 2, 4, 8 ] - default: 1 - db_name: - type: string - description: The name of the database. - default: wordpress - db_user: - type: string - description: The user name of the DB user. - default: wp_user - db_pwd: - type: string - description: The WordPress database admin account password. - default: wp_pass - db_root_pwd: - type: string - description: Root password for MySQL. - db_port: - type: PortDef - description: Port for the MySQL database. - default: 3306 - - node_templates: - wordpress: - type: tosca.nodes.WebApplication.WordPress - requirements: - - host: webserver - - database_endpoint: mysql_database - interfaces: - Standard: - create: wordpress/wordpress_install.sh - configure: - implementation: wordpress/wordpress_configure.sh - inputs: - wp_db_name: wordpress - wp_db_user: wp_user - wp_db_password: wp_pass - - mysql_database: - type: tosca.nodes.Database - properties: - name: { get_input: db_name } - user: { get_input: db_user } - password: { get_input: db_pwd } - capabilities: - database_endpoint: - properties: - port: { get_input: db_port } - requirements: - - host: - node: mysql_dbms - interfaces: - Standard: - configure: - implementation: mysql/mysql_database_configure.sh - inputs: - db_name: wordpress - db_user: wp_user - db_password: wp_pass - db_root_password: passw0rd - mysql_dbms: - type: tosca.nodes.DBMS - properties: - root_password: { get_input: db_root_pwd } - port: { get_input: db_port } - requirements: - - host: server - interfaces: - Standard: - create: - implementation: mysql/mysql_dbms_install.sh - inputs: - db_root_password: passw0rd - start: mysql/mysql_dbms_start.sh - configure: - implementation: mysql/mysql_dbms_configure.sh - inputs: - db_port: 3366 - - webserver: - type: tosca.nodes.WebServer - requirements: - - host: server - interfaces: - Standard: - create: webserver/webserver_install.sh - start: webserver/webserver_start.sh - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: cpus } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Ubuntu - version: 14.04 - - outputs: - website_url: - description: URL for Wordpress wiki. - value: { get_attribute: [server, private_address] } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/tosca_single_instance_wordpress_with_url_import.yaml b/nfvparser/src/main/python/toscaparser/tests/data/tosca_single_instance_wordpress_with_url_import.yaml deleted file mode 100644 index e5f1580..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/tosca_single_instance_wordpress_with_url_import.yaml +++ /dev/null @@ -1,120 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with wordpress, web server and mysql on the same server. - -imports: - - https://raw.githubusercontent.com/openstack/heat-translator/master/translator/tests/data/custom_types/wordpress.yaml - -topology_template: - inputs: - cpus: - type: integer - description: Number of CPUs for the server. - constraints: - - valid_values: [ 1, 2, 4, 8 ] - default: 1 - db_name: - type: string - description: The name of the database. - default: wordpress - db_user: - type: string - description: The user name of the DB user. - default: wp_user - db_pwd: - type: string - description: The WordPress database admin account password. - default: wp_pass - db_root_pwd: - type: string - description: Root password for MySQL. - db_port: - type: PortDef - description: Port for the MySQL database. - default: 3306 - - node_templates: - wordpress: - type: tosca.nodes.WebApplication.WordPress - requirements: - - host: webserver - - database_endpoint: mysql_database - interfaces: - Standard: - create: wordpress/wordpress_install.sh - configure: - implementation: wordpress/wordpress_configure.sh - inputs: - wp_db_name: wordpress - wp_db_user: wp_user - wp_db_password: wp_pass - - mysql_database: - type: tosca.nodes.Database - properties: - name: { get_input: db_name } - user: { get_input: db_user } - password: { get_input: db_pwd } - capabilities: - database_endpoint: - properties: - port: { get_input: db_port } - requirements: - - host: - node: mysql_dbms - interfaces: - Standard: - configure: - implementation: mysql/mysql_database_configure.sh - inputs: - db_name: wordpress - db_user: wp_user - db_password: wp_pass - db_root_password: passw0rd - mysql_dbms: - type: tosca.nodes.DBMS - properties: - root_password: { get_input: db_root_pwd } - port: { get_input: db_port } - requirements: - - host: server - interfaces: - Standard: - create: - implementation: mysql/mysql_dbms_install.sh - inputs: - db_root_password: passw0rd - start: mysql/mysql_dbms_start.sh - configure: - implementation: mysql/mysql_dbms_configure.sh - inputs: - db_port: 3366 - - webserver: - type: tosca.nodes.WebServer - requirements: - - host: server - interfaces: - Standard: - create: webserver/webserver_install.sh - start: webserver/webserver_start.sh - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: cpus } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Ubuntu - version: 14.04 - - outputs: - website_url: - description: URL for Wordpress wiki. - value: { get_attribute: [server, private_address] } diff --git a/nfvparser/src/main/python/toscaparser/tests/data/tosca_test_get_operation_output.yaml b/nfvparser/src/main/python/toscaparser/tests/data/tosca_test_get_operation_output.yaml deleted file mode 100644 index f47f33c..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/data/tosca_test_get_operation_output.yaml +++ /dev/null @@ -1,19 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: TOSCA simple profile to test the GET OPERATION OUTPUT functionality - -imports: - - custom_types/compute_with_prop.yaml - -topology_template: - - node_templates: - - front_end: - type: tosca.nodes.ComputeWithProp - interfaces: - Standard: - create: - implementation: nodejs/create.sh - inputs: - data_dir: {get_operation_output: [front_end,Standard,create,data_dir]} diff --git a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/network/tosca_one_server_one_network.yaml b/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/network/tosca_one_server_one_network.yaml deleted file mode 100644 index 8e58fa9..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/network/tosca_one_server_one_network.yaml +++ /dev/null @@ -1,43 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with 1 server bound to a new network - -topology_template: - - inputs: - network_name: - type: string - description: Network name - - node_templates: - my_server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: 1 - mem_size: 512 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: CirrOS - version: 0.3.2 - - my_network: - type: tosca.nodes.network.Network - properties: - network_name: { get_input: network_name } - ip_version: 4 - cidr: '192.168.0.0/24' - start_ip: '192.168.0.50' - end_ip: '192.168.0.200' - gateway_ip: '192.168.0.1' - - my_port: - type: tosca.nodes.network.Port - requirements: - - binding: my_server - - link: my_network diff --git a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/network/tosca_one_server_three_networks.yaml b/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/network/tosca_one_server_three_networks.yaml deleted file mode 100644 index d791b17..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/network/tosca_one_server_three_networks.yaml +++ /dev/null @@ -1,64 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with 1 server bound to 3 networks - -topology_template: - - node_templates: - my_server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: 1 - mem_size: 512 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: CirrOS - version: 0.3.2 - - my_network1: - type: tosca.nodes.network.Network - properties: - cidr: '192.168.1.0/24' - network_name: net1 - - my_network2: - type: tosca.nodes.network.Network - properties: - cidr: '192.168.2.0/24' - network_name: net2 - - my_network3: - type: tosca.nodes.network.Network - properties: - cidr: '192.168.3.0/24' - network_name: net3 - - my_port1: - type: tosca.nodes.network.Port - properties: - order: 0 - requirements: - - binding: my_server - - link: my_network1 - - my_port2: - type: tosca.nodes.network.Port - properties: - order: 1 - requirements: - - binding: my_server - - link: my_network2 - - my_port3: - type: tosca.nodes.network.Port - properties: - order: 2 - requirements: - - binding: my_server - - link: my_network3 diff --git a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/network/tosca_server_on_existing_network.yaml b/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/network/tosca_server_on_existing_network.yaml deleted file mode 100644 index 7fedc13..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/network/tosca_server_on_existing_network.yaml +++ /dev/null @@ -1,39 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with 1 server bound to an existing network - -topology_template: - inputs: - network_name: - type: string - description: Network name - - node_templates: - my_server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: 1 - mem_size: 512 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: CirrOS - version: 0.3.2 - - my_network: - type: tosca.nodes.network.Network - properties: - network_name: { get_input: network_name } - - my_port: - type: tosca.nodes.network.Port - requirements: - - binding: - node: my_server - - link: - node: my_network diff --git a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/network/tosca_two_servers_one_network.yaml b/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/network/tosca_two_servers_one_network.yaml deleted file mode 100644 index 1473a8d..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/network/tosca_two_servers_one_network.yaml +++ /dev/null @@ -1,79 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with 2 servers bound to the 1 network - -topology_template: - - inputs: - network_name: - type: string - description: Network name - network_cidr: - type: string - default: 10.0.0.0/24 - description: CIDR for the network - network_start_ip: - type: string - default: 10.0.0.100 - description: Start IP for the allocation pool - network_end_ip: - type: string - default: 10.0.0.150 - description: End IP for the allocation pool - - node_templates: - my_server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: 1 - mem_size: 512 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: CirrOS - version: 0.3.2 - - my_server2: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: 1 - mem_size: 512 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: CirrOS - version: 0.3.2 - - my_network: - type: tosca.nodes.network.Network - properties: - ip_version: 4 - cidr: { get_input: network_cidr } - network_name: { get_input: network_name } - start_ip: { get_input: network_start_ip } - end_ip: { get_input: network_end_ip } - - my_port: - type: tosca.nodes.network.Port - requirements: - - binding: - node: my_server - - link: - node: my_network - - my_port2: - type: tosca.nodes.network.Port - requirements: - - binding: - node: my_server2 - - link: - node: my_network diff --git a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment.yaml b/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment.yaml deleted file mode 100644 index 460fa4c..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment.yaml +++ /dev/null @@ -1,61 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with server and attached block storage using the normative AttachesTo Relationship Type. - -topology_template: - - inputs: - cpus: - type: integer - description: Number of CPUs for the server. - constraints: - - valid_values: [ 1, 2, 4, 8 ] - storage_size: - type: scalar-unit.size - description: Size of the storage to be created. - default: 1 GB - storage_snapshot_id: - type: string - description: > - Optional identifier for an existing snapshot to use when creating storage. - storage_location: - type: string - description: Block storage mount point (filesystem path). - - node_templates: - my_server: - type: Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: cpus } - mem_size: 4096 kB - os: - properties: - architecture: x86_64 - type: linux - distribution: fedora - version: 18.0 - requirements: - - local_storage: - node: my_storage - relationship: - type: AttachesTo - properties: - location: { get_input: storage_location } - - my_storage: - type: BlockStorage - properties: - size: { get_input: storage_size } - snapshot_id: { get_input: storage_snapshot_id } - - outputs: - private_ip: - description: The private IP address of the newly created compute instance. - value: { get_attribute: [my_server, private_address] } - volume_id: - description: The volume id of the block storage instance. - value: { get_attribute: [my_storage, volume_id] } diff --git a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment_notation1.yaml b/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment_notation1.yaml deleted file mode 100644 index df22d72..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment_notation1.yaml +++ /dev/null @@ -1,87 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with a Single Block Storage node shared by 2-Tier Application with custom AttachesTo Type and implied relationships. - -relationship_types: - MyAttachesTo: - derived_from: tosca.relationships.AttachesTo - properties: - location: - type: string - default: /default_location - -topology_template: - inputs: - cpus: - type: integer - description: Number of CPUs for the server. - constraints: - - valid_values: [ 1, 2, 4, 8 ] - storage_size: - type: scalar-unit.size - default: 1 GB - description: Size of the storage to be created. - storage_snapshot_id: - type: string - description: > - Optional identifier for an existing snapshot to use when creating storage. - - node_templates: - my_web_app_tier_1: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: cpus } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Fedora - version: 18.0 - requirements: - - local_storage: - node: my_storage - relationship: MyAttachesTo - - my_web_app_tier_2: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: cpus } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Fedora - version: 18.0 - requirements: - - local_storage: - node: my_storage - relationship: - type: MyAttachesTo - properties: - location: /some_other_data_location - - my_storage: - type: tosca.nodes.BlockStorage - properties: - size: { get_input: storage_size } - snapshot_id: { get_input: storage_snapshot_id } - - outputs: - private_ip_1: - description: The private IP address of the application's first tier. - value: { get_attribute: [my_web_app_tier_1, private_address] } - private_ip_2: - description: The private IP address of the application's second tier. - value: { get_attribute: [my_web_app_tier_2, private_address] } - volume_id: - description: The volume id of the block storage instance. - value: { get_attribute: [my_storage, volume_id] } diff --git a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment_notation2.yaml b/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment_notation2.yaml deleted file mode 100644 index cb1c17a..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment_notation2.yaml +++ /dev/null @@ -1,99 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with a single Block Storage node shared by 2-Tier Application with custom AttachesTo Type and explicit Relationship Templates. - -relationship_types: - MyAttachesTo: - derived_from: tosca.relationships.AttachesTo - properties: - location: - type: string - default: /default_location - -topology_template: - inputs: - cpus: - type: integer - description: Number of CPUs for the server. - constraints: - - valid_values: [ 1, 2, 4, 8 ] - storage_size: - type: scalar-unit.size - default: 1 GB - description: Size of the storage to be created. - storage_snapshot_id: - type: string - description: > - Optional identifier for an existing snapshot to use when creating storage. - storage_location: - type: string - description: > - Block storage mount point (filesystem path). - - node_templates: - - my_web_app_tier_1: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: cpus } - mem_size: 4096 kB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Fedora - version: 18.0 - requirements: - - local_storage: - node: my_storage - relationship: storage_attachesto_1 - - my_web_app_tier_2: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: cpus } - mem_size: 4096 kB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Fedora - version: 18.0 - requirements: - - local_storage: - node: my_storage - relationship: storage_attachesto_2 - - my_storage: - type: tosca.nodes.BlockStorage - properties: - size: { get_input: storage_size } - snapshot_id: { get_input: storage_snapshot_id } - - relationship_templates: - storage_attachesto_1: - type: MyAttachesTo - properties: - location: /my_data_location - - storage_attachesto_2: - type: MyAttachesTo - properties: - location: /some_other_data_location - outputs: - private_ip_1: - description: The private IP address of the application's first tier. - value: { get_attribute: [my_web_app_tier_1, private_address] } - private_ip_2: - description: The private IP address of the application's second tier. - value: { get_attribute: [my_web_app_tier_2, private_address] } - volume_id: - description: The volume id of the block storage instance. - value: { get_attribute: [my_storage, volume_id] } diff --git a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_custom_relationship_type.yaml b/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_custom_relationship_type.yaml deleted file mode 100644 index 932f89e..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_custom_relationship_type.yaml +++ /dev/null @@ -1,64 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with server and attached block storage using a custom AttachesTo Relationship Type. - -relationship_types: - MyCustomAttachesTo: - derived_from: AttachesTo - -topology_template: - inputs: - cpus: - type: integer - description: Number of CPUs for the server. - constraints: - - valid_values: [ 1, 2, 4, 8 ] - storage_size: - type: scalar-unit.size - description: Size of the storage to be created. - default: 1 GB - storage_snapshot_id: - type: string - description: > - Optional identifier for an existing snapshot to use when creating storage. - storage_location: - type: string - description: Block storage mount point (filesystem path). - - node_templates: - my_server: - type: Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: cpus } - mem_size: 4 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Fedora - version: 18.0 - requirements: - - local_storage: - node: my_storage - # Declare custom AttachesTo type using the 'relationship' keyword - relationship: - type: MyCustomAttachesTo - properties: - location: { get_input: storage_location } - my_storage: - type: BlockStorage - properties: - size: { get_input: storage_size } - snapshot_id: { get_input: storage_snapshot_id } - - outputs: - private_ip: - description: The private IP address of the newly created compute instance. - value: { get_attribute: [my_server, private_address] } - volume_id: - description: The volume id of the block storage instance. - value: { get_attribute: [my_storage, volume_id] } diff --git a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_relationship_template.yaml b/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_relationship_template.yaml deleted file mode 100644 index c31a4da..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_relationship_template.yaml +++ /dev/null @@ -1,59 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with server and attached block storage using a named Relationship Template for the storage attachment. - -topology_template: - inputs: - cpus: - type: integer - description: Number of CPUs for the server. - constraints: - - valid_values: [ 1, 2, 4, 8 ] - storage_size: - type: scalar-unit.size - description: Size of the storage to be created. - default: 1 GB - storage_location: - type: string - description: Block storage mount point (filesystem path). - - node_templates: - my_server: - type: Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: cpus } - mem_size: 4 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Fedora - version: 18.0 - requirements: - - local_storage: - node: my_storage - # Declare template to use with 'relationship' keyword - relationship: storage_attachment - - my_storage: - type: BlockStorage - properties: - size: { get_input: storage_size } - - relationship_templates: - storage_attachment: - type: AttachesTo - properties: - location: { get_input: storage_location } - - outputs: - private_ip: - description: The private IP address of the newly created compute instance. - value: { get_attribute: [my_server, private_address] } - volume_id: - description: The volume id of the block storage instance. - value: { get_attribute: [my_storage, volume_id] } diff --git a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_multiple_blockstorage_with_attachment.yaml b/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_multiple_blockstorage_with_attachment.yaml deleted file mode 100644 index aa4647e..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_multiple_blockstorage_with_attachment.yaml +++ /dev/null @@ -1,93 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with 2 servers each with different attached block storage. - -topology_template: - inputs: - cpus: - type: integer - description: Number of CPUs for the server. - constraints: - - valid_values: [ 1, 2, 4, 8 ] - storage_size: - type: scalar-unit.size - default: 1 GB - description: Size of the storage to be created. - storage_snapshot_id: - type: string - description: > - Optional identifier for an existing snapshot to use when creating storage. - storage_location: - type: string - description: > - Block storage mount point (filesystem path). - - node_templates: - my_server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: cpus } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Fedora - version: 18.0 - requirements: - - local_storage: - node: my_storage - relationship: - type: AttachesTo - properties: - location: { get_input: storage_location } - my_storage: - type: tosca.nodes.BlockStorage - properties: - size: { get_input: storage_size } - snapshot_id: { get_input: storage_snapshot_id } - - my_server2: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: cpus } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Fedora - version: 18.0 - requirements: - - local_storage: - node: my_storage2 - relationship: - type: AttachesTo - properties: - location: { get_input: storage_location } - my_storage2: - type: tosca.nodes.BlockStorage - properties: - size: { get_input: storage_size } - snapshot_id: { get_input: storage_snapshot_id } - - outputs: - server_ip_1: - description: The private IP address of the application's first server. - value: { get_attribute: [my_server, private_address] } - server_ip_2: - description: The private IP address of the application's second server. - value: { get_attribute: [my_server2, private_address] } - volume_id_1: - description: The volume id of the first block storage instance. - value: { get_attribute: [my_storage, volume_id] } - volume_id_2: - description: The volume id of the second block storage instance. - value: { get_attribute: [my_storage2, volume_id] } diff --git a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_single_object_store.yaml b/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_single_object_store.yaml deleted file mode 100644 index 869af48..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/storage/tosca_single_object_store.yaml +++ /dev/null @@ -1,17 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - Tosca template for creating an object storage service. - -topology_template: - inputs: - objectstore_name: - type: string - - node_templates: - obj_store_server: - type: tosca.nodes.ObjectStorage - properties: - name: { get_input: objectstore_name } - size: 1024 kB - maxsize: 1 GB diff --git a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/tosca_nodejs_mongodb_two_instances.yaml b/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/tosca_nodejs_mongodb_two_instances.yaml deleted file mode 100644 index f611071..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/tosca_nodejs_mongodb_two_instances.yaml +++ /dev/null @@ -1,96 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile with nodejs and mongodb. - -imports: - - custom_types/paypalpizzastore_nodejs_app.yaml - -dsl_definitions: - host_capabilities: &host_capabilities - disk_size: 10 GB - num_cpus: 1 - mem_size: 4096 MB - os_capabilities: &os_capabilities - architecture: x86_64 - type: Linux - distribution: Ubuntu - version: 14.04 - -topology_template: - inputs: - my_cpus: - type: integer - description: Number of CPUs for the server. - constraints: - - valid_values: [ 1, 2, 4, 8 ] - default: 1 - github_url: - type: string - description: The URL to download nodejs. - default: http://github.com/paypal/rest-api-sample-app-nodejs.git - - node_templates: - paypal_pizzastore: - type: tosca.nodes.WebApplication.PayPalPizzaStore - properties: - github_url: { get_input: github_url } - requirements: - - host: nodejs - - database_connection: mongo_db - interfaces: - Standard: - configure: - implementation: nodejs/config.sh - inputs: - github_url: http://github.com/paypal/rest-api-sample-app-nodejs.git - mongodb_ip: { get_attribute: [mongo_server, private_address] } - start: nodejs/start.sh - nodejs: - type: tosca.nodes.WebServer - requirements: - - host: app_server - interfaces: - Standard: - create: nodejs/create.sh - mongo_db: - type: tosca.nodes.Database - requirements: - - host: mongo_dbms - interfaces: - Standard: - create: mongodb/create_database.sh - mongo_dbms: - type: tosca.nodes.DBMS - requirements: - - host: mongo_server - interfaces: - Standard: - create: mongodb/create.sh - configure: - implementation: mongodb/config.sh - inputs: - mongodb_ip: { get_attribute: [mongo_server, private_address] } - start: mongodb/start.sh - mongo_server: - type: tosca.nodes.Compute - capabilities: - host: - properties: *host_capabilities - os: - properties: *os_capabilities - app_server: - type: tosca.nodes.Compute - capabilities: - host: - properties: *host_capabilities - os: - properties: *os_capabilities - - outputs: - nodejs_url: - description: URL for the nodejs server, http://:3000 - value: { get_attribute: [app_server, private_address] } - mongodb_url: - description: URL for the mongodb server. - value: { get_attribute: [mongo_server, private_address] } diff --git a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/tosca_single_server.yaml b/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/tosca_single_server.yaml deleted file mode 100644 index c4cce9d..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/spec_samples/v1.0/tosca_single_server.yaml +++ /dev/null @@ -1,32 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: > - TOSCA simple profile that just defines a single compute instance and selects a (guest) host Operating System from the Compute node's properties. Note, this example does not include default values on inputs properties. - -topology_template: - inputs: - cpus: - type: integer - description: Number of CPUs for the server. - constraints: - - valid_values: [ 1, 2, 4, 8 ] - - node_templates: - my_server: - type: Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: cpus } - mem_size: 4 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: ubuntu - version: 12.04 - outputs: - private_ip: - description: The private IP address of the deployed server instance. - value: { get_attribute: [my_server, private_address] } \ No newline at end of file diff --git a/nfvparser/src/main/python/toscaparser/tests/test_constraints.py b/nfvparser/src/main/python/toscaparser/tests/test_constraints.py deleted file mode 100644 index 07cb910..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/test_constraints.py +++ /dev/null @@ -1,373 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import datetime -import yaml - -from toscaparser.common import exception -from toscaparser.elements.constraints import Constraint -from toscaparser.elements.constraints import Schema -from toscaparser.tests.base import TestCase -from toscaparser.utils.gettextutils import _ -from toscaparser.utils import yamlparser - - -class ConstraintTest(TestCase): - - def test_schema_dict(self): - tpl_snippet = ''' - cpus: - type: integer - description: Number of CPUs for the server. - ''' - schema = yamlparser.simple_parse(tpl_snippet) - cpus_schema = Schema('cpus', schema['cpus']) - self.assertEqual(len(cpus_schema), 2) - self.assertEqual('integer', cpus_schema.type) - self.assertEqual('Number of CPUs for the server.', - cpus_schema.description) - self.assertEqual(True, cpus_schema.required) - self.assertIsNone(cpus_schema.default) - - def test_schema_not_dict(self): - tpl_snippet = ''' - cpus: - - type: integer - - description: Number of CPUs for the server. - ''' - schema = yamlparser.simple_parse(tpl_snippet) - error = self.assertRaises(exception.InvalidSchemaError, Schema, - 'cpus', schema['cpus']) - self.assertEqual(_('Schema definition of "cpus" must be a dict.'), - str(error)) - - def test_schema_miss_type(self): - tpl_snippet = ''' - cpus: - description: Number of CPUs for the server. - ''' - schema = yamlparser.simple_parse(tpl_snippet) - error = self.assertRaises(exception.InvalidSchemaError, Schema, - 'cpus', schema['cpus']) - self.assertEqual(_('Schema definition of "cpus" must have a "type" ' - 'attribute.'), str(error)) - - def test_schema_none_description(self): - tpl_snippet = ''' - cpus: - type: integer - ''' - schema = yamlparser.simple_parse(tpl_snippet) - cpus_schema = Schema('cpus', schema['cpus']) - self.assertEqual('', cpus_schema.description) - - def test_invalid_constraint_type(self): - schema = {'invalid_type': 2} - error = self.assertRaises(exception.InvalidSchemaError, Constraint, - 'prop', Schema.INTEGER, - schema) - self.assertEqual(_('Invalid property "invalid_type".'), - str(error)) - - def test_invalid_prop_type(self): - schema = {'length': 5} - error = self.assertRaises(exception.InvalidSchemaError, Constraint, - 'prop', Schema.INTEGER, - schema) - self.assertEqual(_('Property "length" is not valid for data type ' - '"integer".'), str(error)) - - def test_invalid_validvalues(self): - schema = {'valid_values': 2} - error = self.assertRaises(exception.InvalidSchemaError, Constraint, - 'prop', Schema.INTEGER, - schema) - self.assertEqual(_('The property "valid_values" expects a list.'), - str(error)) - - def test_validvalues_validate(self): - schema = {'valid_values': [2, 4, 6, 8]} - constraint = Constraint('prop', Schema.INTEGER, schema) - self.assertIsNone(constraint.validate(4)) - - def test_validvalues_validate_fail(self): - schema = {'valid_values': [2, 4, 6, 8]} - constraint = Constraint('prop', Schema.INTEGER, schema) - error = self.assertRaises(exception.ValidationError, - constraint.validate, 5) - self.assertEqual(_('The value "5" of property "prop" is not valid. ' - 'Expected a value from "[2, 4, 6, 8]".'), - str(error)) - - def test_invalid_in_range(self): - snippet = 'in_range: {2, 6}' - schema = yaml.load(snippet) - error = self.assertRaises(exception.InvalidSchemaError, Constraint, - 'prop', Schema.INTEGER, - schema) - self.assertEqual(_('The property "in_range" expects a list.'), - str(error)) - - def test_in_range_min_max(self): - schema = {'in_range': [2, 6]} - constraint = Constraint('prop', Schema.INTEGER, schema) - self.assertEqual(2, constraint.min) - self.assertEqual(6, constraint.max) - - def test_in_range_validate(self): - schema = {'in_range': [2, 6]} - constraint = Constraint('prop', Schema.INTEGER, schema) - self.assertIsNone(constraint.validate(2)) - self.assertIsNone(constraint.validate(4)) - self.assertIsNone(constraint.validate(6)) - - def test_in_range_validate_fail(self): - schema = {'in_range': [2, 6]} - constraint = Constraint('prop', Schema.INTEGER, schema) - error = self.assertRaises(exception.ValidationError, - constraint.validate, 8) - self.assertEqual(_('The value "8" of property "prop" is out of range ' - '"(min:2, max:6)".'), str(error)) - - def test_equal_validate(self): - schema = {'equal': 4} - constraint = Constraint('prop', Schema.INTEGER, schema) - self.assertIsNone(constraint.validate(4)) - - def test_equal_validate_fail(self): - schema = {'equal': 4} - constraint = Constraint('prop', Schema.INTEGER, schema) - error = self.assertRaises(exception.ValidationError, - constraint.validate, 8) - self.assertEqual('The value "8" of property "prop" is not equal to ' - '"4".', str(error)) - - def test_greater_than_validate(self): - schema = {'greater_than': 4} - constraint = Constraint('prop', Schema.INTEGER, schema) - self.assertIsNone(constraint.validate(6)) - - def test_greater_than_validate_fail(self): - schema = {'greater_than': 4} - constraint = Constraint('prop', Schema.INTEGER, schema) - error = self.assertRaises(exception.ValidationError, - constraint.validate, 3) - self.assertEqual(_('The value "3" of property "prop" must be greater ' - 'than "4".'), str(error)) - - error = self.assertRaises(exception.ValidationError, - constraint.validate, 4) - self.assertEqual(_('The value "4" of property "prop" must be greater ' - 'than "4".'), str(error)) - - def test_greater_than_invalid(self): - snippet = 'greater_than: {4}' - schema = yaml.load(snippet) - error = self.assertRaises(exception.InvalidSchemaError, Constraint, - 'prop', Schema.INTEGER, - schema) - self.assertEqual(_('The property "greater_than" expects comparable ' - 'values.'), str(error)) - - def test_greater_or_equal_validate(self): - schema = {'greater_or_equal': 3.9} - constraint = Constraint('prop', Schema.FLOAT, schema) - self.assertIsNone(constraint.validate(3.9)) - self.assertIsNone(constraint.validate(4.0)) - - def test_greater_or_equal_validate_fail(self): - schema = {'greater_or_equal': 3.9} - constraint = Constraint('prop', Schema.FLOAT, schema) - error = self.assertRaises(exception.ValidationError, - constraint.validate, 3.0) - self.assertEqual(_('The value "3.0" of property "prop" must be ' - 'greater than or equal to "3.9".'), - str(error)) - - error = self.assertRaises(exception.ValidationError, - constraint.validate, 3.8) - self.assertEqual(_('The value "3.8" of property "prop" must be ' - 'greater than or equal to "3.9".'), - str(error)) - - def test_greater_or_equal_invalid(self): - snippet = 'greater_or_equal: {3.9}' - schema = yaml.load(snippet) - error = self.assertRaises(exception.InvalidSchemaError, Constraint, - 'prop', Schema.INTEGER, - schema) - self.assertEqual(_('The property "greater_or_equal" expects ' - 'comparable values.'), str(error)) - - def test_less_than_validate(self): - schema = {'less_than': datetime.date(2014, 0o7, 25)} - constraint = Constraint('prop', Schema.TIMESTAMP, schema) - self.assertIsNone(constraint.validate(datetime.date(2014, 0o7, 20))) - self.assertIsNone(constraint.validate(datetime.date(2014, 0o7, 24))) - - def test_less_than_validate_fail(self): - schema = {'less_than': datetime.date(2014, 0o7, 25)} - constraint = Constraint('prop', Schema.TIMESTAMP, schema) - error = self.assertRaises(exception.ValidationError, - constraint.validate, - datetime.date(2014, 0o7, 25)) - self.assertEqual(_('The value "2014-07-25" of property "prop" must be ' - 'less than "2014-07-25".'), - str(error)) - - error = self.assertRaises(exception.ValidationError, - constraint.validate, - datetime.date(2014, 0o7, 27)) - self.assertEqual(_('The value "2014-07-27" of property "prop" must be ' - 'less than "2014-07-25".'), - str(error)) - - def test_less_than_invalid(self): - snippet = 'less_than: {3.9}' - schema = yaml.load(snippet) - error = self.assertRaises(exception.InvalidSchemaError, Constraint, - 'prop', Schema.INTEGER, - schema) - self.assertEqual(_('The property "less_than" expects comparable ' - 'values.'), str(error)) - - def test_less_or_equal_validate(self): - schema = {'less_or_equal': 4} - constraint = Constraint('prop', Schema.INTEGER, schema) - self.assertIsNone(constraint.validate(4)) - self.assertIsNone(constraint.validate(3)) - - def test_less_or_equal_validate_fail(self): - schema = {'less_or_equal': 4} - constraint = Constraint('prop', Schema.INTEGER, schema) - error = self.assertRaises(exception.ValidationError, - constraint.validate, 5) - self.assertEqual(_('The value "5" of property "prop" must be less ' - 'than or equal to "4".'), str(error)) - - def test_less_or_equal_invalid(self): - snippet = 'less_or_equal: {3.9}' - schema = yaml.load(snippet) - error = self.assertRaises(exception.InvalidSchemaError, Constraint, - 'prop', Schema.INTEGER, - schema) - self.assertEqual(_('The property "less_or_equal" expects comparable ' - 'values.'), str(error)) - - def test_invalid_length(self): - schema = {'length': 'four'} - error = self.assertRaises(exception.InvalidSchemaError, Constraint, - 'prop', Schema.STRING, - schema) - self.assertEqual(_('The property "length" expects an integer.'), - str(error)) - - schema = {'length': 4.5} - error = self.assertRaises(exception.InvalidSchemaError, Constraint, - 'prop', Schema.STRING, - schema) - self.assertEqual(_('The property "length" expects an integer.'), - str(error)) - - def test_length_validate(self): - schema = {'length': 4} - constraint = Constraint('prop', Schema.STRING, schema) - self.assertIsNone(constraint.validate('abcd')) - - def test_length_validate_fail(self): - schema = {'length': 4} - constraint = Constraint('prop', Schema.STRING, schema) - error = self.assertRaises(exception.ValidationError, - constraint.validate, 'abc') - self.assertEqual(_('Length of value "abc" of property "prop" must ' - 'be equal to "4".'), str(error)) - - error = self.assertRaises(exception.ValidationError, - constraint.validate, - 'abcde') - self.assertEqual(_('Length of value "abcde" of property "prop" must ' - 'be equal to "4".'), str(error)) - - def test_invalid_min_length(self): - schema = {'min_length': 'four'} - error = self.assertRaises(exception.InvalidSchemaError, Constraint, - 'prop', Schema.STRING, - schema) - self.assertEqual(_('The property "min_length" expects an integer.'), - str(error)) - - def test_min_length_validate(self): - schema = {'min_length': 4} - constraint = Constraint('prop', Schema.STRING, schema) - self.assertIsNone(constraint.validate('abcd')) - self.assertIsNone(constraint.validate('abcde')) - - def test_min_length_validate_fail(self): - schema = {'min_length': 4} - constraint = Constraint('prop', Schema.STRING, schema) - error = self.assertRaises(exception.ValidationError, - constraint.validate, 'abc') - self.assertEqual(_('Length of value "abc" of property "prop" must ' - 'be at least "4".'), str(error)) - - def test_invalid_max_length(self): - schema = {'max_length': 'four'} - error = self.assertRaises(exception.InvalidSchemaError, Constraint, - 'prop', Schema.STRING, - schema) - self.assertEqual(_('The property "max_length" expects an integer.'), - str(error)) - - def test_max_length_validate(self): - schema = {'max_length': 4} - constraint = Constraint('prop', Schema.STRING, schema) - self.assertIsNone(constraint.validate('abcd')) - self.assertIsNone(constraint.validate('abc')) - - def test_max_length_validate_fail(self): - schema = {'max_length': 4} - constraint = Constraint('prop', Schema.STRING, schema) - error = self.assertRaises(exception.ValidationError, - constraint.validate, - 'abcde') - self.assertEqual(_('Length of value "abcde" of property "prop" ' - 'must be no greater than "4".'), - str(error)) - - def test_pattern_validate(self): - schema = {'pattern': '[0-9]*'} - constraint = Constraint('prop', Schema.STRING, schema) - self.assertIsNone(constraint.validate('123')) - - def test_pattern_validate_fail(self): - schema = {'pattern': '[0-9]*'} - constraint = Constraint('prop', Schema.STRING, schema) - error = self.assertRaises(exception.ValidationError, - constraint.validate, 'abc') - self.assertEqual(_('The value "abc" of property "prop" does not ' - 'match pattern "[0-9]*".'), str(error)) - - def test_min_length_with_map(self): - schema = {'min_length': 1} - constraint = Constraint('prop', Schema.MAP, schema) - try: - constraint.validate({"k": "v"}) - except Exception as ex: - self.fail(ex) - - def test_max_length_with_map(self): - schema = {'max_length': 1} - constraint = Constraint('prop', Schema.MAP, schema) - try: - constraint.validate({"k": "v"}) - except Exception as ex: - self.fail(ex) diff --git a/nfvparser/src/main/python/toscaparser/tests/test_custom_relationships.py b/nfvparser/src/main/python/toscaparser/tests/test_custom_relationships.py deleted file mode 100644 index 9ae85d5..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/test_custom_relationships.py +++ /dev/null @@ -1,35 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import os - -from toscaparser.tests.base import TestCase -from toscaparser.tosca_template import ToscaTemplate - - -class CustomRelationshipTypesTest(TestCase): - - '''TOSCA template.''' - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/relationship/test_custom_relationship.yaml") - tosca = ToscaTemplate(tosca_tpl) - - def test_version(self): - self.assertEqual(self.tosca.version, "tosca_simple_yaml_1_0") - - def test_custom_types(self): - expected_custom_types = ['tosca.capabilities.HA', - 'tosca.nodes.HACompute', - 'tosca.relationships.HA'] - self.assertItemsEqual(self.tosca.topology_template.custom_defs.keys(), - expected_custom_types) diff --git a/nfvparser/src/main/python/toscaparser/tests/test_datatypes.py b/nfvparser/src/main/python/toscaparser/tests/test_datatypes.py deleted file mode 100644 index 0a6cfe0..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/test_datatypes.py +++ /dev/null @@ -1,517 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import os - -from testtools.testcase import skip -from toscaparser.common import exception -from toscaparser.dataentity import DataEntity -from toscaparser.elements.datatype import DataType -from toscaparser.parameters import Input -from toscaparser.tests.base import TestCase -from toscaparser.tosca_template import ToscaTemplate -from toscaparser.utils.gettextutils import _ -from toscaparser.utils import yamlparser - - -class DataTypeTest(TestCase): - - custom_type_schema = ''' - tosca.my.datatypes.PeopleBase: - properties: - name: - type: string - required: true - constraints: - - min_length: 2 - gender: - type: string - default: unknown - - tosca.my.datatypes.People: - derived_from: tosca.my.datatypes.PeopleBase - properties: - addresses: - type: map - required: false - entry_schema: - type: string - contacts: - type: list - required: false - entry_schema: - type: tosca.my.datatypes.ContactInfo - - tosca.my.datatypes.ContactInfo: - description: simple contact information - properties: - contact_name: - type: string - required: true - constraints: - - min_length: 2 - contact_email: - type: string - contact_phone: - type: string - - tosca.my.datatypes.TestLab: - properties: - humidity: - type: range - required: false - constraints: - - in_range: [-256, INFINITY] - temperature1: - type: range - required: false - constraints: - - in_range: [-256, UNBOUNDED] - temperature2: - type: range - required: false - constraints: - - in_range: [UNBOUNDED, 256] - ''' - custom_type_def = yamlparser.simple_parse(custom_type_schema) - - def test_empty_template(self): - value_snippet = '' - value = yamlparser.simple_parse(value_snippet) - self.assertEqual(value, {}) - - def test_built_in_datatype(self): - value_snippet = ''' - private_network: - network_name: private - network_id: 3e54214f-5c09-1bc9-9999-44100326da1b - addresses: [ 10.111.128.10 ] - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.datatypes.network.NetworkInfo', - value.get('private_network')) - self.assertIsNotNone(data.validate()) - - value_snippet = ''' - portspec_valid: - protocol: tcp - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.datatypes.network.PortSpec', - value.get('portspec_valid')) - self.assertIsNotNone(data.validate()) - - value_snippet = ''' - portspec_invalid: - protocol: xyz - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.datatypes.network.PortSpec', - value.get('portspec_invalid')) - err = self.assertRaises(exception.ValidationError, data.validate) - self.assertEqual(_('The value "xyz" of property "protocol" is not ' - 'valid. Expected a value from "[udp, tcp, igmp]".' - ), - err.__str__()) - - def test_built_in_datatype_with_short_name(self): - value_snippet = ''' - ethernet_port: - port_name: port1 - port_id: 2c0c7a37-691a-23a6-7709-2d10ad041467 - network_id: 3e54214f-5c09-1bc9-9999-44100326da1b - mac_address: f1:18:3b:41:92:1e - addresses: [ 172.24.9.102 ] - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('PortInfo', value.get('ethernet_port')) - self.assertIsNotNone(data.validate()) - - # Test normative PortSpec datatype's additional requirements - # TODO(Matt) - opened as bug 1555300 - # Need a test for PortSpec normative data type - # that tests the spec. requirement: "A valid PortSpec - # must have at least one of the following properties: - # target, target_range, source or source_range." - # TODO(Matt) - opened as bug 1555310 - # test PortSpec value for source and target - # against the source_range and target_range - # when specified. - def test_port_spec_addl_reqs(self): - value_snippet = ''' - test_port: - protocol: tcp - target: 65535 - target_range: [ 1, 65535 ] - source: 1 - source_range: [ 1, 65535 ] - - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.datatypes.network.PortSpec', - value.get('test_port')) - self.assertIsNotNone(data.validate()) - - def test_built_in_datatype_without_properties(self): - value_snippet = ''' - 2 - ''' - value = yamlparser.simple_parse(value_snippet) - datatype = DataType('PortDef') - self.assertEqual('integer', datatype.value_type) - data = DataEntity('PortDef', value) - self.assertIsNotNone(data.validate()) - - @skip('The example in TOSCA spec may have some problem.') - def test_built_in_nested_datatype(self): - value_snippet = ''' - user_port: - protocol: tcp - target: [50000] - source: [9000] - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('PortSpec', value.get('user_port')) - self.assertIsNotNone(data.validate()) - - def test_built_in_nested_datatype_portdef(self): - tpl_snippet = ''' - inputs: - db_port: - type: PortDef - description: Port for the MySQL database - ''' - inputs = yamlparser.simple_parse(tpl_snippet)['inputs'] - name, attrs = list(inputs.items())[0] - input = Input(name, attrs) - self.assertIsNone(input.validate(3360)) - err = self.assertRaises(exception.ValidationError, input.validate, - 336000) - self.assertEqual(_('The value "336000" of property "None" is out of ' - 'range "(min:1, max:65535)".'), - err.__str__()) - - def test_custom_datatype(self): - value_snippet = ''' - name: Mike - gender: male - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.my.datatypes.PeopleBase', value, - DataTypeTest.custom_type_def) - self.assertIsNotNone(data.validate()) - - def test_custom_datatype_with_parent(self): - value_snippet = ''' - name: Mike - gender: male - contacts: - - {contact_name: Tom, - contact_email: tom@email.com, - contact_phone: '123456789'} - - {contact_name: Jerry, - contact_email: jerry@email.com, - contact_phone: '321654987'} - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.my.datatypes.People', value, - DataTypeTest.custom_type_def) - self.assertIsNotNone(data.validate()) - - # [Tom, Jerry] is not a dict, it can't be a value of datatype PeopleBase - def test_non_dict_value_for_datatype(self): - value_snippet = ''' - [Tom, Jerry] - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.my.datatypes.PeopleBase', value, - DataTypeTest.custom_type_def) - error = self.assertRaises(exception.TypeMismatchError, data.validate) - self.assertEqual(_('[\'Tom\', \'Jerry\'] must be of type ' - '"tosca.my.datatypes.PeopleBase".'), - error.__str__()) - - # 'nema' is an invalid field name - def test_field_error_in_dataentity(self): - value_snippet = ''' - nema: Mike - gender: male - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.my.datatypes.PeopleBase', value, - DataTypeTest.custom_type_def) - error = self.assertRaises(exception.UnknownFieldError, data.validate) - self.assertEqual(_('Data value of type ' - '"tosca.my.datatypes.PeopleBase" contains unknown ' - 'field "nema". Refer to the definition to verify ' - 'valid values.'), - error.__str__()) - - def test_default_field_in_dataentity(self): - value_snippet = ''' - name: Mike - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.my.datatypes.PeopleBase', value, - DataTypeTest.custom_type_def) - data = data.validate() - self.assertEqual('unknown', data.get('gender')) - - # required field 'name' is missing - def test_missing_field_in_dataentity(self): - value_snippet = ''' - gender: male - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.my.datatypes.PeopleBase', value, - DataTypeTest.custom_type_def) - error = self.assertRaises(exception.MissingRequiredFieldError, - data.validate) - self.assertEqual(_('Data value of type ' - '"tosca.my.datatypes.PeopleBase" is missing ' - 'required field "[\'name\']".'), - error.__str__()) - - # the value of name field is not a string - def test_type_error_in_dataentity(self): - value_snippet = ''' - name: 123 - gender: male - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.my.datatypes.PeopleBase', value, - DataTypeTest.custom_type_def) - error = self.assertRaises(ValueError, data.validate) - self.assertEqual(_('"123" is not a string.'), error.__str__()) - - # the value of name doesn't meet the defined constraint - def test_value_error_in_dataentity(self): - value_snippet = ''' - name: M - gender: male - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.my.datatypes.PeopleBase', value, - DataTypeTest.custom_type_def) - error = self.assertRaises(exception.ValidationError, data.validate) - self.assertEqual(_('Length of value "M" of property "name" must be ' - 'at least "2".'), error.__str__()) - - # value of addresses doesn't fit the entry_schema - def test_validation_in_collection_entry(self): - value_snippet = ''' - name: Mike - gender: male - addresses: {Home: 1, Office: 9 bar avenue} - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.my.datatypes.People', value, - DataTypeTest.custom_type_def) - error = self.assertRaises(ValueError, data.validate) - self.assertEqual(_('"1" is not a string.'), error.__str__()) - - # 'contact_pone' is an invalid attribute name in nested datatype below - def test_validation_in_nested_datatype(self): - value_snippet = ''' - name: Mike - gender: male - contacts: - - {contact_name: Tom, - contact_email: tom@email.com, - contact_pone: '123456789'} - - {contact_name: Jerry, - contact_email: jerry@email.com, - contact_phone: '321654987'} - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.my.datatypes.People', value, - DataTypeTest.custom_type_def) - error = self.assertRaises(exception.UnknownFieldError, data.validate) - self.assertEqual(_('Data value of type ' - '"tosca.my.datatypes.ContactInfo" contains unknown ' - 'field "contact_pone". Refer to the definition to ' - 'verify valid values.'), - error.__str__()) - - def test_datatype_in_current_template(self): - tpl_path = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/datatypes/test_custom_datatypes_in_current_template.yaml") - self.assertIsNotNone(ToscaTemplate(tpl_path)) - - def test_datatype_in_template_positive(self): - tpl_path = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/datatypes/test_custom_datatypes_positive.yaml") - self.assertIsNotNone(ToscaTemplate(tpl_path)) - - def test_datatype_in_template_invalid_value(self): - tpl_path = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/datatypes/test_custom_datatypes_value_error.yaml") - self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path) - exception.ExceptionCollector.assertExceptionMessage( - ValueError, - _('"[\'1 foo street\', \'9 bar avenue\']" is not a map.')) - - def test_datatype_in_template_nested_datatype_error(self): - tpl_path = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/datatypes/test_custom_datatypes_nested_datatype_error.yaml") - self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path) - exception.ExceptionCollector.assertExceptionMessage( - ValueError, _('"123456789" is not a string.')) - - def test_valid_range_type(self): - value_snippet = ''' - user_port: - protocol: tcp - target_range: [20000, 60000] - source_range: [1000, 3000] - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('PortSpec', value.get('user_port')) - self.assertIsNotNone(data.validate()) - - def test_invalid_range_datatype(self): - value_snippet = ''' - user_port: - protocol: tcp - target: 1 - target_range: [20000] - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('PortSpec', value.get('user_port')) - err = self.assertRaises(ValueError, data.validate) - self.assertEqual(_('"[20000]" is not a valid range.' - ), - err.__str__()) - - value_snippet = ''' - user_port: - protocol: tcp - target: 1 - target_range: [20000, 3000] - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('PortSpec', value.get('user_port')) - err = self.assertRaises(ValueError, data.validate) - self.assertEqual(_('"[20000, 3000]" is not a valid range.' - ), - err.__str__()) - - value_snippet = ''' - humidity: [-100, 100] - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.my.datatypes.TestLab', - value, DataTypeTest.custom_type_def) - err = self.assertRaises(exception.InvalidSchemaError, - lambda: data.validate()) - self.assertEqual(_('The property "in_range" expects comparable values.' - ), - err.__str__()) - - def test_range_unbounded(self): - value_snippet = ''' - humidity: [-100, 100] - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.my.datatypes.TestLab', - value, DataTypeTest.custom_type_def) - err = self.assertRaises(exception.InvalidSchemaError, - lambda: data.validate()) - self.assertEqual(_('The property "in_range" expects comparable values.' - ), - err.__str__()) - - def test_invalid_ranges_against_constraints(self): - # The TestLab range type has min=-256, max=UNBOUNDED - value_snippet = ''' - temperature1: [-257, 999999] - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.my.datatypes.TestLab', value, - DataTypeTest.custom_type_def) - err = self.assertRaises(exception.ValidationError, data.validate) - self.assertEqual(_('The value "-257" of property "temperature1" is ' - 'out of range "(min:-256, max:UNBOUNDED)".'), - err.__str__()) - - value_snippet = ''' - temperature2: [-999999, 257] - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.my.datatypes.TestLab', value, - DataTypeTest.custom_type_def) - err = self.assertRaises(exception.ValidationError, data.validate) - self.assertEqual(_('The value "257" of property "temperature2" is ' - 'out of range "(min:UNBOUNDED, max:256)".'), - err.__str__()) - - def test_valid_ranges_against_constraints(self): - - # The TestLab range type has max=UNBOUNDED - value_snippet = ''' - temperature1: [-255, 999999] - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.my.datatypes.TestLab', value, - DataTypeTest.custom_type_def) - self.assertIsNotNone(data.validate()) - - # The TestLab range type has min=UNBOUNDED - value_snippet = ''' - temperature2: [-999999, 255] - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.my.datatypes.TestLab', value, - DataTypeTest.custom_type_def) - self.assertIsNotNone(data.validate()) - - def test_incorrect_field_in_datatype(self): - tpl_snippet = ''' - tosca_definitions_version: tosca_simple_yaml_1_0 - topology_template: - node_templates: - server: - type: tosca.nodes.Compute - - webserver: - type: tosca.nodes.WebServer - properties: - admin_credential: - user: username - token: some_pass - some_field: value - requirements: - - host: server - ''' - tpl = yamlparser.simple_parse(tpl_snippet) - err = self.assertRaises(exception.ValidationError, ToscaTemplate, - None, None, None, tpl) - self.assertIn(_('The pre-parsed input failed validation with the ' - 'following error(s): \n\n\tUnknownFieldError: Data ' - 'value of type "tosca.datatypes.Credential" contains' - ' unknown field "some_field". Refer to the definition' - ' to verify valid values'), err.__str__()) - - def test_functions_datatype(self): - value_snippet = ''' - admin_credential: - user: username - token: { get_input: password } - ''' - value = yamlparser.simple_parse(value_snippet) - data = DataEntity('tosca.datatypes.Credential', - value.get('admin_credential')) - self.assertIsNotNone(data.validate()) diff --git a/nfvparser/src/main/python/toscaparser/tests/test_exception.py b/nfvparser/src/main/python/toscaparser/tests/test_exception.py deleted file mode 100644 index a404f4f..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/test_exception.py +++ /dev/null @@ -1,42 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from toscaparser.common import exception -from toscaparser.tests.base import TestCase -from toscaparser.utils.gettextutils import _ - - -class ExceptionTest(TestCase): - - def setUp(self): - super(TestCase, self).setUp() - exception.TOSCAException.set_fatal_format_exception(False) - - def test_message(self): - ex = exception.MissingRequiredFieldError(what='Template', - required='type') - self.assertEqual(_('Template is missing required field "type".'), - ex.__str__()) - - def test_set_flag(self): - exception.TOSCAException.set_fatal_format_exception('True') - self.assertFalse( - exception.TOSCAException._FATAL_EXCEPTION_FORMAT_ERRORS) - - def test_format_error(self): - ex = exception.UnknownFieldError(what='Template') - self.assertEqual(_('An unknown exception occurred.'), ex.__str__(),) - self.assertRaises(KeyError, self._formate_exception) - - def _formate_exception(self): - exception.UnknownFieldError.set_fatal_format_exception(True) - raise exception.UnknownFieldError(what='Template') diff --git a/nfvparser/src/main/python/toscaparser/tests/test_functions.py b/nfvparser/src/main/python/toscaparser/tests/test_functions.py deleted file mode 100644 index fa60140..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/test_functions.py +++ /dev/null @@ -1,373 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import os -import six -from toscaparser.common import exception -from toscaparser import functions -from toscaparser.tests.base import TestCase -from toscaparser.tosca_template import ToscaTemplate -from toscaparser.utils.gettextutils import _ - - -class IntrinsicFunctionsTest(TestCase): - - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/tosca_single_instance_wordpress.yaml") - params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user', - 'db_root_pwd': '12345678'} - tosca = ToscaTemplate(tosca_tpl, parsed_params=params) - - def _get_node(self, node_name, tosca=None): - if tosca is None: - tosca = self.tosca - return [ - node for node in tosca.nodetemplates - if node.name == node_name][0] - - def _get_operation(self, interfaces, operation): - return [ - interface for interface in interfaces - if interface.name == operation][0] - - def _get_property(self, node_template, property_name): - return [prop.value for prop in node_template.get_properties_objects() - if prop.name == property_name][0] - - def _get_inputs_dict(self): - inputs = {} - for input in self.tosca.inputs: - inputs[input.name] = input.default - return inputs - - def _get_input(self, name): - self._get_inputs_dict()[name] - - def test_get_property(self): - wordpress = self._get_node('wordpress') - operation = self._get_operation(wordpress.interfaces, 'configure') - wp_db_password = operation.inputs['wp_db_password'] - self.assertIsInstance(wp_db_password, functions.GetProperty) - result = wp_db_password.result() - self.assertEqual('wp_pass', result) - - def test_get_property_with_input_param(self): - wordpress = self._get_node('wordpress') - operation = self._get_operation(wordpress.interfaces, 'configure') - wp_db_user = operation.inputs['wp_db_user'] - self.assertIsInstance(wp_db_user, functions.GetProperty) - result = wp_db_user.result() - self.assertEqual('my_db_user', result) - - def test_unknown_capability_property(self): - self.assertRaises(exception.ValidationError, self._load_template, - 'functions/test_unknown_capability_property.yaml') - exception.ExceptionCollector.assertExceptionMessage( - KeyError, - _('\'Property "unknown" was not found in capability ' - '"database_endpoint" of node template "database" referenced ' - 'from node template "database".\'')) - - def test_get_input_in_properties(self): - mysql_dbms = self._get_node('mysql_dbms') - expected_inputs = ['db_root_pwd', 'db_port'] - props = mysql_dbms.get_properties() - for key in props.keys(): - prop = props[key] - self.assertIsInstance(prop.value, functions.GetInput) - expected_inputs.remove(prop.value.input_name) - self.assertListEqual(expected_inputs, []) - - def test_get_input_validation(self): - self.assertRaises( - exception.ValidationError, self._load_template, - 'functions/test_unknown_input_in_property.yaml') - exception.ExceptionCollector.assertExceptionMessage( - exception.UnknownInputError, - _('Unknown input "objectstore_name".')) - - self.assertRaises( - exception.ValidationError, self._load_template, - 'functions/test_unknown_input_in_interface.yaml') - exception.ExceptionCollector.assertExceptionMessage( - exception.UnknownInputError, - _('Unknown input "image_id".')) - - self.assertRaises( - exception.ValidationError, self._load_template, - 'functions/test_invalid_function_signature.yaml') - exception.ExceptionCollector.assertExceptionMessage( - ValueError, - _('Expected one argument for function "get_input" but received ' - '"[\'cpus\', \'cpus\']".')) - - def test_get_input_default_value_result(self): - mysql_dbms = self._get_node('mysql_dbms') - dbms_port = self._get_property(mysql_dbms, 'port') - self.assertEqual(3306, dbms_port.result()) - dbms_root_password = self._get_property(mysql_dbms, - 'root_password') - self.assertEqual(dbms_root_password.result(), '12345678') - - def test_get_property_with_host(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/functions/test_get_property_with_host.yaml") - mysql_database = self._get_node('mysql_database', - ToscaTemplate(tosca_tpl, - parsed_params={ - 'db_root_pwd': '123' - })) - operation = self._get_operation(mysql_database.interfaces, 'configure') - db_port = operation.inputs['db_port'] - self.assertIsInstance(db_port, functions.GetProperty) - result = db_port.result() - self.assertEqual(3306, result) - test = operation.inputs['test'] - self.assertIsInstance(test, functions.GetProperty) - result = test.result() - self.assertEqual(1, result) - - def test_get_property_with_nested_params(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/functions/tosca_nested_property_names_indexes.yaml") - webserver = self._get_node('wordpress', - ToscaTemplate(tosca_tpl, - parsed_params={ - 'db_root_pwd': '1234'})) - operation = self._get_operation(webserver.interfaces, 'configure') - wp_endpoint_prot = operation.inputs['wp_endpoint_protocol'] - self.assertIsInstance(wp_endpoint_prot, functions.GetProperty) - self.assertEqual('tcp', wp_endpoint_prot.result()) - wp_list_prop = operation.inputs['wp_list_prop'] - self.assertIsInstance(wp_list_prop, functions.GetProperty) - self.assertEqual(3, wp_list_prop.result()) - - def test_get_property_with_capabilties_inheritance(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/functions/test_capabilties_inheritance.yaml") - some_node = self._get_node('some_node', - ToscaTemplate(tosca_tpl, - parsed_params={ - 'db_root_pwd': '1234'})) - operation = self._get_operation(some_node.interfaces, 'configure') - some_input = operation.inputs['some_input'] - self.assertIsInstance(some_input, functions.GetProperty) - self.assertEqual('someval', some_input.result()) - - def test_get_property_source_target_keywords(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/functions/test_get_property_source_target_keywords.yaml") - tosca = ToscaTemplate(tosca_tpl, - parsed_params={'db_root_pwd': '1234'}) - - for node in tosca.nodetemplates: - for relationship, trgt in node.relationships.items(): - rel_template = trgt.get_relationship_template()[0] - break - - operation = self._get_operation(rel_template.interfaces, - 'pre_configure_source') - target_test = operation.inputs['target_test'] - self.assertIsInstance(target_test, functions.GetProperty) - self.assertEqual(1, target_test.result()) - source_port = operation.inputs['source_port'] - self.assertIsInstance(source_port, functions.GetProperty) - self.assertEqual(3306, source_port.result()) - - -class GetAttributeTest(TestCase): - - def _load_template(self, filename): - return ToscaTemplate(os.path.join( - os.path.dirname(os.path.abspath(__file__)), - 'data', - filename), - parsed_params={'db_root_pwd': '1234'}) - - def _get_operation(self, interfaces, operation): - return [ - interface for interface in interfaces - if interface.name == operation][0] - - def test_get_attribute_in_outputs(self): - tpl = self._load_template('tosca_single_instance_wordpress.yaml') - website_url_output = [ - x for x in tpl.outputs if x.name == 'website_url'][0] - self.assertIsInstance(website_url_output.value, functions.GetAttribute) - self.assertEqual('server', website_url_output.value.node_template_name) - self.assertEqual('private_address', - website_url_output.value.attribute_name) - - def test_get_attribute_invalid_args(self): - expected_msg = _('Illegal arguments for function "get_attribute".' - ' Expected arguments: "node-template-name", ' - '"req-or-cap"(optional), "property name"') - err = self.assertRaises(ValueError, - functions.get_function, None, None, - {'get_attribute': []}) - self.assertIn(expected_msg, six.text_type(err)) - err = self.assertRaises(ValueError, - functions.get_function, None, None, - {'get_attribute': ['x']}) - self.assertIn(expected_msg, six.text_type(err)) - - def test_get_attribute_unknown_node_template_name(self): - self.assertRaises( - exception.ValidationError, self._load_template, - 'functions/test_get_attribute_unknown_node_template_name.yaml') - exception.ExceptionCollector.assertExceptionMessage( - KeyError, - _('\'Node template "unknown_node_template" was not found.\'')) - - def test_get_attribute_unknown_attribute(self): - self.assertRaises( - exception.ValidationError, self._load_template, - 'functions/test_get_attribute_unknown_attribute_name.yaml') - exception.ExceptionCollector.assertExceptionMessage( - KeyError, - _('\'Attribute "unknown_attribute" was not found in node template ' - '"server".\'')) - - def test_get_attribute_host_keyword(self): - tpl = self._load_template( - 'functions/test_get_attribute_host_keyword.yaml') - - def assert_get_attribute_host_functionality(node_template_name): - node = [x for x in tpl.nodetemplates - if x.name == node_template_name][0] - configure_op = [ - x for x in node.interfaces if x.name == 'configure'][0] - ip_addr_input = configure_op.inputs['ip_address'] - self.assertIsInstance(ip_addr_input, functions.GetAttribute) - self.assertEqual('server', - ip_addr_input.get_referenced_node_template().name) - - assert_get_attribute_host_functionality('dbms') - assert_get_attribute_host_functionality('database') - - def test_get_attribute_host_not_found(self): - self.assertRaises( - exception.ValidationError, self._load_template, - 'functions/test_get_attribute_host_not_found.yaml') - exception.ExceptionCollector.assertExceptionMessage( - ValueError, - _('"get_attribute: [ HOST, ... ]" was used in node template ' - '"server" but "tosca.relationships.HostedOn" was not found in ' - 'the relationship chain.')) - - def test_get_attribute_illegal_host_in_outputs(self): - self.assertRaises( - exception.ValidationError, self._load_template, - 'functions/test_get_attribute_illegal_host_in_outputs.yaml') - exception.ExceptionCollector.assertExceptionMessage( - ValueError, - _('"get_attribute: [ HOST, ... ]" is not allowed in "outputs" ' - 'section of the TOSCA template.')) - - def test_get_attribute_with_index(self): - self._load_template( - 'functions/test_get_attribute_with_index.yaml') - - def test_get_attribute_with_index_error(self): - self.assertRaises( - exception.ValidationError, self._load_template, - 'functions/test_get_attribute_with_index_error.yaml') - exception.ExceptionCollector.assertExceptionMessage( - ValueError, - _('Illegal arguments for function "get_attribute". ' - 'Unexpected attribute/index value "0"')) - - def test_get_attribute_source_target_keywords(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/functions/test_get_attribute_source_target_keywords.yaml") - tosca = ToscaTemplate(tosca_tpl, - parsed_params={'db_root_pwd': '12345678'}) - - for node in tosca.nodetemplates: - for relationship, trgt in node.relationships.items(): - rel_template = trgt.get_relationship_template()[0] - break - - operation = self._get_operation(rel_template.interfaces, - 'pre_configure_source') - target_test = operation.inputs['target_test'] - self.assertIsInstance(target_test, functions.GetAttribute) - source_port = operation.inputs['source_port'] - self.assertIsInstance(source_port, functions.GetAttribute) - - def test_get_attribute_with_nested_params(self): - self._load_template( - 'functions/test_get_attribute_with_nested_params.yaml') - - def test_implicit_attribute(self): - self.assertIsNotNone(self._load_template( - 'functions/test_get_implicit_attribute.yaml')) - - -class ConcatTest(TestCase): - - def _load_template(self, filename): - return ToscaTemplate(os.path.join( - os.path.dirname(os.path.abspath(__file__)), - filename)) - - def test_validate_concat(self): - tosca = self._load_template("data/functions/test_concat.yaml") - server_url_output = [ - output for output in tosca.outputs if output.name == 'url'][0] - func = functions.get_function(self, tosca.outputs, - server_url_output.value) - self.assertIsInstance(func, functions.Concat) - - self.assertRaises(exception.ValidationError, self._load_template, - 'data/functions/test_concat_invalid.yaml') - exception.ExceptionCollector.assertExceptionMessage( - ValueError, - _('Invalid arguments for function "concat". Expected at least ' - 'one arguments.')) - - -class TokenTest(TestCase): - - def _load_template(self, filename): - return ToscaTemplate(os.path.join( - os.path.dirname(os.path.abspath(__file__)), - filename)) - - def test_validate_token(self): - tosca = self._load_template("data/functions/test_token.yaml") - server_url_output = [ - output for output in tosca.outputs if output.name == 'url'][0] - func = functions.get_function(self, tosca.outputs, - server_url_output.value) - self.assertIsInstance(func, functions.Token) - - self.assertRaises(exception.ValidationError, self._load_template, - 'data/functions/test_token_invalid.yaml') - exception.ExceptionCollector.assertExceptionMessage( - ValueError, - _('Invalid arguments for function "token". Expected at least ' - 'three arguments.')) - exception.ExceptionCollector.assertExceptionMessage( - ValueError, - _('Invalid arguments for function "token". Expected ' - 'integer value as third argument.')) - exception.ExceptionCollector.assertExceptionMessage( - ValueError, - _('Invalid arguments for function "token". Expected ' - 'single char value as second argument.')) diff --git a/nfvparser/src/main/python/toscaparser/tests/test_prereq.py b/nfvparser/src/main/python/toscaparser/tests/test_prereq.py deleted file mode 100644 index 11f4471..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/test_prereq.py +++ /dev/null @@ -1,230 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import os -import shutil -import zipfile - -from toscaparser.common.exception import URLException -from toscaparser.common.exception import ValidationError -from toscaparser.prereq.csar import CSAR -from toscaparser.tests.base import TestCase -import toscaparser.utils -from toscaparser.utils.gettextutils import _ - - -class CSARPrereqTest(TestCase): - - base_path = os.path.dirname(os.path.abspath(__file__)) - - def test_file_exists(self): - path = os.path.join(self.base_path, "data/CSAR/csar_not_there.zip") - csar = CSAR(path) - error = self.assertRaises(ValidationError, csar.validate) - self.assertEqual(_('"%s" does not exist.') % path, str(error)) - self.assertTrue(csar.temp_dir is None or - not os.path.exists(csar.temp_dir)) - - def test_file_is_zip(self): - path = os.path.join(self.base_path, "data/CSAR/csar_not_zip.zip") - csar = CSAR(path) - error = self.assertRaises(ValidationError, csar.validate) - self.assertEqual(_('"%s" is not a valid zip file.') % path, str(error)) - - def test_url_is_zip(self): - path = "https://github.com/openstack/tosca-parser/raw/master/" \ - "toscaparser/tests/data/CSAR/csar_not_zip.zip" - csar = CSAR(path, False) - error = self.assertRaises(ValidationError, csar.validate) - self.assertEqual(_('"%s" is not a valid zip file.') % path, str(error)) - self.assertTrue(csar.temp_dir is None or - not os.path.exists(csar.temp_dir)) - - def test_metadata_file_exists(self): - path = os.path.join(self.base_path, - "data/CSAR/csar_no_metadata_file.zip") - csar = CSAR(path) - error = self.assertRaises(ValidationError, csar.validate) - self.assertEqual(_('"%s" is not a valid CSAR as it does not contain ' - 'the required file "TOSCA.meta" in the folder ' - '"TOSCA-Metadata".') % path, str(error)) - self.assertTrue(csar.temp_dir is None or - not os.path.exists(csar.temp_dir)) - - def test_valid_metadata_file_exists(self): - path = os.path.join(self.base_path, - "data/CSAR/csar_wrong_metadata_file.zip") - csar = CSAR(path) - error = self.assertRaises(ValidationError, csar.validate) - self.assertEqual(_('"%s" is not a valid CSAR as it does not contain ' - 'the required file "TOSCA.meta" in the folder ' - '"TOSCA-Metadata".') % path, str(error)) - self.assertTrue(csar.temp_dir is None or - not os.path.exists(csar.temp_dir)) - - def test_metadata_is_yaml(self): - path = os.path.join(self.base_path, - "data/CSAR/csar_metadata_not_yaml.zip") - csar = CSAR(path) - error = self.assertRaises(ValidationError, csar.validate) - self.assertEqual(_('The file "TOSCA-Metadata/TOSCA.meta" in the CSAR ' - '"%s" does not contain valid YAML content.') % path, - str(error)) - self.assertTrue(csar.temp_dir is None or - not os.path.exists(csar.temp_dir)) - - def test_metadata_exists(self): - path = os.path.join(self.base_path, - "data/CSAR/csar_missing_metadata.zip") - csar = CSAR(path) - error = self.assertRaises(ValidationError, csar.validate) - self.assertEqual(_('The CSAR "%s" is missing the required metadata ' - '"Entry-Definitions" in ' - '"TOSCA-Metadata/TOSCA.meta".') % path, str(error)) - self.assertTrue(csar.temp_dir is None or - not os.path.exists(csar.temp_dir)) - - def test_entry_def_exists(self): - path = os.path.join(self.base_path, - "data/CSAR/csar_invalid_entry_def.zip") - csar = CSAR(path) - error = self.assertRaises(ValidationError, csar.validate) - self.assertEqual(_('The "Entry-Definitions" file defined in the CSAR ' - '"%s" does not exist.') % path, str(error)) - self.assertTrue(csar.temp_dir is None or - not os.path.exists(csar.temp_dir)) - - def test_csar_invalid_import_path(self): - path = os.path.join(self.base_path, - "data/CSAR/csar_wordpress_invalid_import_path.zip") - csar = CSAR(path) - error = self.assertRaises(ImportError, csar.validate) - self.assertEqual(_('Import "Invalid_import_path/wordpress.yaml" is' - ' not valid.'), str(error)) - self.assertTrue(csar.temp_dir is None or - not os.path.exists(csar.temp_dir)) - - def test_csar_invalid_import_url(self): - path = os.path.join(self.base_path, - "data/CSAR/csar_wordpress_invalid_import_url.zip") - csar = CSAR(path) - error = self.assertRaises(URLException, csar.validate) - self.assertEqual(_('Failed to reach server ' - '"https://raw.githubusercontent.com/openstack/' - 'tosca-parser/master/toscaparser/tests/data/CSAR/' - 'tosca_single_instance_wordpress/Definitions/' - 'wordpress1.yaml". Reason is: Not Found.'), - str(error)) - self.assertTrue(csar.temp_dir is None or - not os.path.exists(csar.temp_dir)) - - def test_csar_invalid_script_path(self): - path = os.path.join(self.base_path, - "data/CSAR/csar_wordpress_invalid_script_path.zip") - csar = CSAR(path) - error = self.assertRaises(ValueError, csar.validate) - self.assertTrue( - str(error) == _('The resource "Scripts/WordPress/install.sh" does ' - 'not exist.') or - str(error) == _('The resource "Scripts/WordPress/configure.sh" ' - 'does not exist.')) - self.assertTrue(csar.temp_dir is None or - not os.path.exists(csar.temp_dir)) - - def test_csar_invalid_script_url(self): - path = os.path.join(self.base_path, - "data/CSAR/csar_wordpress_invalid_script_url.zip") - csar = CSAR(path) - error = self.assertRaises(URLException, csar.validate) - self.assertEqual(_('The resource at ' - '"https://raw.githubusercontent.com/openstack/' - 'tosca-parser/master/toscaparser/tests/data/CSAR/' - 'tosca_single_instance_wordpress/Scripts/WordPress/' - 'install1.sh" cannot be accessed.'), - str(error)) - self.assertTrue(csar.temp_dir is None or - not os.path.exists(csar.temp_dir)) - - def test_valid_csar(self): - path = os.path.join(self.base_path, "data/CSAR/csar_hello_world.zip") - csar = CSAR(path) - self.assertTrue(csar.validate()) - self.assertTrue(csar.temp_dir is None or - not os.path.exists(csar.temp_dir)) - - def test_valid_csar_with_url_import_and_script(self): - path = os.path.join(self.base_path, "data/CSAR/csar_wordpress_with_url" - "_import_and_script.zip") - csar = CSAR(path) - self.assertTrue(csar.validate()) - self.assertTrue(csar.temp_dir is None or - not os.path.exists(csar.temp_dir)) - - def test_metadata_invalid_csar(self): - path = os.path.join(self.base_path, - "data/CSAR/csar_metadata_not_yaml.zip") - csar = CSAR(path) - error = self.assertRaises(ValidationError, csar.get_author) - self.assertEqual(_('The file "TOSCA-Metadata/TOSCA.meta" in the CSAR ' - '"%s" does not contain valid YAML content.') % path, - str(error)) - self.assertTrue(csar.temp_dir is None or - not os.path.exists(csar.temp_dir)) - - def test_metadata_valid_csar(self): - path = os.path.join(self.base_path, "data/CSAR/csar_hello_world.zip") - csar = CSAR(path) - expected_meta = {'TOSCA-Meta-File-Version': 1.0, - 'CSAR-Version': 1.1, - 'Created-By': 'OASIS TOSCA TC', - 'Entry-Definitions': 'tosca_helloworld.yaml'} - self.assertEqual(expected_meta, csar.get_metadata(), - 'The extracted metadata of the CSAR %(csar)s does ' - 'not match the expected metadata %(meta)s' - % {'csar': path, 'meta': expected_meta.__str__()}) - self.assertEqual(1.1, csar.get_version()) - self.assertEqual('OASIS TOSCA TC', csar.get_author()) - self.assertEqual('tosca_helloworld.yaml', csar.get_main_template()) - self.assertEqual('Template for deploying a single server with ' - 'predefined properties.', csar.get_description()) - self.assertTrue(csar.temp_dir is None or - not os.path.exists(csar.temp_dir)) - - def test_csar_main_template(self): - path = os.path.join(self.base_path, "data/CSAR/csar_hello_world.zip") - csar = CSAR(path) - yaml_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), - "data/tosca_helloworld.yaml") - expected_yaml = toscaparser.utils.yamlparser.load_yaml(yaml_file) - self.assertEqual(expected_yaml, csar.get_main_template_yaml()) - self.assertTrue(csar.temp_dir is None or - not os.path.exists(csar.temp_dir)) - - def test_decompress(self): - path = os.path.join(self.base_path, "data/CSAR/csar_hello_world.zip") - csar = CSAR(path) - csar.decompress() - zf = zipfile.ZipFile(path) - for name in zf.namelist(): - tmp_path = os.path.join(csar.temp_dir, name) - self.assertTrue(os.path.isdir(tmp_path) or - os.path.isfile(tmp_path)) - shutil.rmtree(csar.temp_dir) - self.assertTrue(csar.temp_dir is None or - not os.path.exists(csar.temp_dir)) - - def test_alternate_csar_extension(self): - path = os.path.join(self.base_path, "data/CSAR/csar_elk.csar") - csar = CSAR(path) - self.assertTrue(csar.validate()) - self.assertTrue(csar.temp_dir is None or - not os.path.exists(csar.temp_dir)) diff --git a/nfvparser/src/main/python/toscaparser/tests/test_properties.py b/nfvparser/src/main/python/toscaparser/tests/test_properties.py deleted file mode 100644 index 6b95537..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/test_properties.py +++ /dev/null @@ -1,368 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from testtools import matchers - -from toscaparser.common import exception -from toscaparser.elements.property_definition import PropertyDef -from toscaparser.nodetemplate import NodeTemplate -from toscaparser.properties import Property -from toscaparser.tests.base import TestCase -from toscaparser.utils.gettextutils import _ -from toscaparser.utils import yamlparser - - -class PropertyTest(TestCase): - - def test_type(self): - test_property_schema = {'type': 'string'} - propertyInstance = Property('test_property', 'Hughes', - test_property_schema) - self.assertEqual('string', propertyInstance.type) - - def test_type_invalid(self): - test_property_schema = {'type': 'Fish'} - propertyInstance = Property('test_property', 'Hughes', - test_property_schema) - error = self.assertRaises(exception.InvalidTypeError, - propertyInstance.validate) - self.assertEqual(_('Type "Fish" is not a valid type.'), str(error)) - - def test_list(self): - test_property_schema = {'type': 'list'} - propertyInstance = Property('test_property', ['a', 'b'], - test_property_schema) - self.assertIsNone(propertyInstance.validate()) - self.assertEqual(['a', 'b'], propertyInstance.value) - - def test_list_invalid(self): - test_property_schema = {'type': 'list'} - propertyInstance = Property('test_property', 'a', - test_property_schema) - error = self.assertRaises(ValueError, propertyInstance.validate) - self.assertEqual(_('"a" is not a list.'), str(error)) - - def test_list_entry_schema(self): - test_property_schema = {'type': 'list', - 'entry_schema': {'type': 'string'}} - propertyInstance = Property('test_property', ['a', 'b'], - test_property_schema) - self.assertIsNone(propertyInstance.validate()) - self.assertEqual(['a', 'b'], propertyInstance.value) - - schema_snippet = ''' - type: list - entry_schema: - type: string - constraints: - - min_length: 2 - ''' - test_property_schema = yamlparser.simple_parse(schema_snippet) - propertyInstance = Property('test_property', ['ab', 'cd'], - test_property_schema) - self.assertIsNone(propertyInstance.validate()) - self.assertEqual(['ab', 'cd'], propertyInstance.value) - - def test_list_entry_schema_invalid(self): - test_property_schema = {'type': 'list', - 'entry_schema': {'type': 'integer'}} - propertyInstance = Property('test_property', [1, 'b'], - test_property_schema) - error = self.assertRaises(ValueError, propertyInstance.validate) - self.assertEqual(_('"b" is not an integer.'), str(error)) - - def test_map(self): - test_property_schema = {'type': 'map'} - propertyInstance = Property('test_property', {'a': 'b'}, - test_property_schema) - self.assertIsNone(propertyInstance.validate()) - self.assertEqual({'a': 'b'}, propertyInstance.value) - - def test_map_invalid(self): - test_property_schema = {'type': 'map'} - propertyInstance = Property('test_property', 12, - test_property_schema) - error = self.assertRaises(ValueError, propertyInstance.validate) - self.assertEqual(_('"12" is not a map.'), str(error)) - - def test_map_entry_schema(self): - test_property_schema = {'type': 'map', - 'entry_schema': {'type': 'boolean'}} - propertyInstance = Property('test_property', - {'valid': True, 'required': True}, - test_property_schema) - self.assertIsNone(propertyInstance.validate()) - self.assertEqual({'valid': True, 'required': True}, - propertyInstance.value) - - def test_map_entry_schema_invalid(self): - test_property_schema = {'type': 'map', - 'entry_schema': {'type': 'boolean'}} - propertyInstance = Property('test_property', - {'valid': True, 'contact_name': 123}, - test_property_schema) - error = self.assertRaises(ValueError, propertyInstance.validate) - self.assertEqual(_('"123" is not a boolean.'), str(error)) - - def test_boolean(self): - test_property_schema = {'type': 'boolean'} - propertyInstance = Property('test_property', 'true', - test_property_schema) - self.assertIsNone(propertyInstance.validate()) - propertyInstance = Property('test_property', True, - test_property_schema) - self.assertIsNone(propertyInstance.validate()) - self.assertEqual(True, propertyInstance.value) - - def test_boolean_invalid(self): - test_property_schema = {'type': 'boolean'} - propertyInstance = Property('test_property', 12, - test_property_schema) - error = self.assertRaises(ValueError, propertyInstance.validate) - self.assertEqual(_('"12" is not a boolean.'), str(error)) - - def test_float(self): - test_property_schema = {'type': 'float'} - propertyInstance = Property('test_property', 0.1, - test_property_schema) - self.assertIsNone(propertyInstance.validate()) - self.assertEqual(0.1, propertyInstance.value) - - def test_float_invalid(self): - test_property_schema = {'type': 'float'} - propertyInstance = Property('test_property', 12, - test_property_schema) - error = self.assertRaises(ValueError, propertyInstance.validate) - self.assertEqual(_('"12" is not a float.'), str(error)) - - def test_timestamp(self): - test_property_schema = {'type': 'timestamp'} - # canonical timestamp - propertyInstance = Property('test_property', '2015-04-01T02:59:43.1Z', - test_property_schema) - self.assertIsNone(propertyInstance.validate()) - self.assertEqual("2015-04-01T02:59:43.1Z", propertyInstance.value) - - # iso8601 timestamp - propertyInstance = Property('test_property', - '2015-04-01t21:59:43.10-05:00', - test_property_schema) - self.assertIsNone(propertyInstance.validate()) - self.assertEqual("2015-04-01t21:59:43.10-05:00", - propertyInstance.value) - - # space separated timestamp - propertyInstance = Property('test_property', - '2015-04-01 21:59:43.10 -5', - test_property_schema) - self.assertIsNone(propertyInstance.validate()) - self.assertEqual("2015-04-01 21:59:43.10 -5", propertyInstance.value) - - # no time zone timestamp - propertyInstance = Property('test_property', '2015-04-01 21:59:43.10', - test_property_schema) - self.assertIsNone(propertyInstance.validate()) - self.assertEqual("2015-04-01 21:59:43.10", propertyInstance.value) - - # date (00:00:00Z) - propertyInstance = Property('test_property', '2015-04-01', - test_property_schema) - self.assertIsNone(propertyInstance.validate()) - self.assertEqual("2015-04-01", propertyInstance.value) - - def test_timestamp_invalid(self): - test_property_schema = {'type': 'timestamp'} - # invalid timestamp - day out of range - value = '2015-04-115T02:59:43.1Z' - propertyInstance = Property('test_property', value, - test_property_schema) - error = self.assertRaises(ValueError, propertyInstance.validate) - expected_message = (_('"%s" is not a valid timestamp.') % value) - self.assertThat(str(error), matchers.StartsWith(expected_message)) - - def test_required(self): - test_property_schema = {'type': 'string'} - propertyInstance = Property('test_property', 'Foo', - test_property_schema) - self.assertEqual(True, propertyInstance.required) - - def test_proprety_inheritance(self): - - tosca_custom_def = ''' - tosca.nodes.SoftwareComponent.MySoftware: - derived_from: SoftwareComponent - properties: - install_path: - required: false - type: string - default: /opt/mysoftware - ''' - - tosca_node_template = ''' - node_templates: - mysoftware_instance: - type: tosca.nodes.SoftwareComponent.MySoftware - properties: - component_version: 3.1 - ''' - - expected_properties = ['component_version', - 'install_path'] - - tpl = self._get_nodetemplate(tosca_node_template, tosca_custom_def) - self.assertIsNone(tpl.validate()) - self.assertEqual(expected_properties, - sorted(tpl.get_properties().keys())) - - def test_missing_property_type(self): - tpl_snippet = ''' - properties: - prop: - typo: tosca.mytesttype.Test - ''' - schema = yamlparser.simple_parse(tpl_snippet) - error = self.assertRaises(exception.InvalidSchemaError, PropertyDef, - 'prop', None, schema['properties']['prop']) - self.assertEqual(_('Schema definition of "prop" must have a "type" ' - 'attribute.'), str(error)) - - def test_invalid_required_value(self): - tpl_snippet = ''' - properties: - prop: - type: tosca.mytesttype.Test - required: dunno - ''' - schema = yamlparser.simple_parse(tpl_snippet) - error = self.assertRaises(exception.InvalidSchemaError, PropertyDef, - 'prop', None, schema['properties']['prop']) - - valid_values = ', '.join(PropertyDef.VALID_REQUIRED_VALUES) - expected_message = (_('Schema definition of "prop" has "required" ' - 'attribute with invalid value "dunno". The ' - 'value must be one of "%s".') % valid_values) - self.assertEqual(expected_message, str(error)) - - def test_invalid_property_status(self): - tpl_snippet = ''' - properties: - prop: - type: string - status: unknown - ''' - schema = yamlparser.simple_parse(tpl_snippet) - error = self.assertRaises(exception.InvalidSchemaError, PropertyDef, - 'prop', None, schema['properties']['prop']) - - valid_values = ', '.join(PropertyDef.VALID_STATUS_VALUES) - expected_message = (_('Schema definition of "prop" has "status" ' - 'attribute with invalid value "unknown". The ' - 'value must be one of "%s".') % valid_values) - self.assertEqual(expected_message, str(error)) - - def test_capability_proprety_inheritance(self): - tosca_custom_def_example1 = ''' - tosca.capabilities.ScalableNew: - derived_from: tosca.capabilities.Scalable - properties: - max_instances: - type: integer - default: 0 - required: no - - tosca.nodes.ComputeNew: - derived_from: tosca.nodes.Compute - capabilities: - scalable: - type: tosca.capabilities.ScalableNew - ''' - - tosca_node_template_example1 = ''' - node_templates: - compute_instance: - type: tosca.nodes.ComputeNew - capabilities: - scalable: - properties: - min_instances: 1 - ''' - - tosca_custom_def_example2 = ''' - tosca.nodes.ComputeNew: - derived_from: tosca.nodes.Compute - capabilities: - new_cap: - type: tosca.capabilities.Scalable - ''' - - tosca_node_template_example2 = ''' - node_templates: - db_server: - type: tosca.nodes.ComputeNew - capabilities: - host: - properties: - num_cpus: 1 - ''' - - tpl1 = self._get_nodetemplate(tosca_node_template_example1, - tosca_custom_def_example1) - self.assertIsNone(tpl1.validate()) - - tpl2 = self._get_nodetemplate(tosca_node_template_example2, - tosca_custom_def_example2) - self.assertIsNone(tpl2.validate()) - - def _get_nodetemplate(self, tpl_snippet, - custom_def_snippet=None): - nodetemplates = yamlparser.\ - simple_parse(tpl_snippet)['node_templates'] - custom_def = [] - if custom_def_snippet: - custom_def = yamlparser.simple_parse(custom_def_snippet) - name = list(nodetemplates.keys())[0] - tpl = NodeTemplate(name, nodetemplates, custom_def) - return tpl - - def test_explicit_relationship_proprety(self): - - tosca_node_template = ''' - node_templates: - - client_node: - type: tosca.nodes.Compute - requirements: - - local_storage: - node: my_storage - relationship: - type: AttachesTo - properties: - location: /mnt/disk - - my_storage: - type: tosca.nodes.BlockStorage - properties: - size: 1 GB - ''' - - expected_properties = ['location'] - - nodetemplates = yamlparser.\ - simple_parse(tosca_node_template)['node_templates'] - tpl = NodeTemplate('client_node', nodetemplates, []) - - self.assertIsNone(tpl.validate()) - rel_tpls = [] - for relationship, trgt in tpl.relationships.items(): - rel_tpls.extend(trgt.get_relationship_template()) - self.assertEqual(expected_properties, - sorted(rel_tpls[0].get_properties().keys())) diff --git a/nfvparser/src/main/python/toscaparser/tests/test_scalarunit.py b/nfvparser/src/main/python/toscaparser/tests/test_scalarunit.py deleted file mode 100644 index 09a24b6..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/test_scalarunit.py +++ /dev/null @@ -1,355 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from toscaparser.common import exception -from toscaparser.elements.scalarunit import ScalarUnit_Frequency -from toscaparser.elements.scalarunit import ScalarUnit_Size -from toscaparser.elements.scalarunit import ScalarUnit_Time -from toscaparser.nodetemplate import NodeTemplate -from toscaparser.tests.base import TestCase -from toscaparser.utils.gettextutils import _ -from toscaparser.utils import yamlparser - - -class ScalarUnitPositiveTest(TestCase): - - scenarios = [ - ( - # tpl_snippet with mem_size given as number+space+MB - 'mem_size_is_number_Space_MB', - dict(tpl_snippet=''' - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - mem_size: 1024 MB - ''', - property='mem_size', - expected='1024 MB') - ), - ( - # tpl_snippet with mem_size given as number+spaces+GB - 'mem_size_is_number_Space_GB', - dict(tpl_snippet=''' - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - mem_size: 1 GB - ''', - property='mem_size', - expected='1 GB') - ), - ( - # tpl_snippet with mem_size given as number+tiB - 'mem_size_is_number_NoSpace_GB', - dict(tpl_snippet=''' - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - mem_size: 1tiB - ''', - property='mem_size', - expected='1 TiB') - ), - ( - # tpl_snippet with mem_size given as number+Spaces+GIB - 'mem_size_is_number_Spaces_GB', - dict(tpl_snippet=''' - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - mem_size: 1 GIB - ''', - property='mem_size', - expected='1 GiB') - ), - ( - # tpl_snippet with mem_size given as number+Space+tib - 'mem_size_is_number_Spaces_GB', - dict(tpl_snippet=''' - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - mem_size: 1 tib - ''', - property='mem_size', - expected='1 TiB') - ), - ( - 'cpu_frequency_is_float_Space_GHz', - dict(tpl_snippet=''' - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - cpu_frequency: 2.5 GHz - ''', - property='cpu_frequency', - expected='2.5 GHz') - ), - ( - 'cpu_frequency_is_float_Space_MHz', - dict(tpl_snippet=''' - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - cpu_frequency: 800 MHz - ''', - property='cpu_frequency', - expected='800 MHz') - ), - ] - - def test_scenario_scalar_unit_positive(self): - tpl = self.tpl_snippet - nodetemplates = yamlparser.simple_parse(tpl) - nodetemplate = NodeTemplate('server', nodetemplates) - props = nodetemplate.get_capability('host').get_properties() - prop_name = self.property - if props and prop_name in props.keys(): - prop = props[prop_name] - self.assertIsNone(prop.validate()) - resolved = prop.value - self.assertEqual(resolved, self.expected) - - -class GetNumFromScalarUnitSizePositive(TestCase): - - scenarios = [ - ( # Note that (1 TB) / (1 GB) = 1000 - 'Input is TB, user input is GB', - dict(InputMemSize='1 TB', - UserInputUnit='gB', - expected=1000) - ), - ( # Note that (1 Tib)/ (1 GB) = 1099 - 'Input is TiB, user input is GB', - dict(InputMemSize='1 TiB', - UserInputUnit='gB', - expected=1099.511627776) - ), - ] - - def test_scenario_get_num_from_scalar_unit_size(self): - resolved = (ScalarUnit_Size(self.InputMemSize). - get_num_from_scalar_unit(self.UserInputUnit)) - self.assertEqual(resolved, self.expected) - - -class GetNumFromScalarUnitFrequencyPositive(TestCase): - - scenarios = [ - ( # Note that (1 GHz) / (1 Hz) = 1000000000 - 'Input is GHz, user input is Hz', - dict(InputMemSize='1 GHz', - UserInputUnit='Hz', - expected=1000000000) - ), - ( - 'Input is GHz, user input is Hz', - dict(InputMemSize='2.4 GHz', - UserInputUnit='Hz', - expected=2400000000) - ), - ( # Note that (1 GHz)/ (1 MHz) = 1000 - 'Input is MHz, user input is GHz', - dict(InputMemSize='800 MHz', - UserInputUnit='GHz', - expected=0.8) - ), - ( - 'Input is GHz, user input is Hz', - dict(InputMemSize='0.9 GHz', - UserInputUnit='MHz', - expected=900) - ), - ( - 'Input is GHz, user input is Hz', - dict(InputMemSize='2.7GHz', - UserInputUnit='MHz', - expected=2700) - ), - ] - - def test_scenario_get_num_from_scalar_unit_frequency(self): - resolved = (ScalarUnit_Frequency(self.InputMemSize). - get_num_from_scalar_unit(self.UserInputUnit)) - self.assertEqual(resolved, self.expected) - - -class GetNumFromScalarUnitTimePositive(TestCase): - - scenarios = [ - ( # Note that (1 s) / (1 ms) = 1000 - 'Input is 500ms, user input is s', - dict(InputMemSize='500 ms', - UserInputUnit='s', - expected=0.5) - ), - ( # Note that (1 h)/ (1 s) = 3600 - 'Input is h, user input is s', - dict(InputMemSize='1 h', - UserInputUnit='s', - expected=3600) - ), - ( # Note that (1 m)/ (1 s) = 60 - 'Input is m, user input is s', - dict(InputMemSize='0.5 m', - UserInputUnit='s', - expected=30) - ), - ( # Note that (1 d)/ (1 h) = 24 - 'Input is d, user input is h', - dict(InputMemSize='1 d', - UserInputUnit='h', - expected=24) - ), - ] - - def test_scenario_get_num_from_scalar_unit_time(self): - resolved = (ScalarUnit_Time(self.InputMemSize). - get_num_from_scalar_unit(self.UserInputUnit)) - self.assertEqual(resolved, self.expected) - - -class GetNumFromScalarUnitSizeNegative(TestCase): - - InputMemSize = '1 GB' - UserInputUnit = 'qB' - - def test_get_num_from_scalar_unit_size_negative(self): - try: - (ScalarUnit_Size(self.InputMemSize). - get_num_from_scalar_unit(self.UserInputUnit)) - except Exception as error: - self.assertIsInstance(error, ValueError) - self.assertEqual(_('The unit "qB" is not valid. Valid units are ' - '"[\'B\', \'GB\', \'GiB\', \'KiB\', \'MB\', ' - '\'MiB\', \'TB\', \'TiB\', \'kB\']".'), - error.__str__()) - - -class GetNumFromScalarUnitFrequencyNegative(TestCase): - - InputFrequency = '2.7 GHz' - UserInputUnit = 'Jz' - - def test_get_num_from_scalar_unit_frequency_negative(self): - try: - (ScalarUnit_Frequency(self.InputFrequency). - get_num_from_scalar_unit(self.UserInputUnit)) - except Exception as error: - self.assertIsInstance(error, ValueError) - self.assertEqual(_('The unit "Jz" is not valid. Valid units are ' - '"[\'GHz\', \'Hz\', \'MHz\', \'kHz\']".'), - error.__str__()) - - -class GetNumFromScalarUnitTimeNegative(TestCase): - - InputTime = '5 ms' - UserInputUnit = 'D' - - def test_get_num_from_scalar_unit_frequency_negative(self): - try: - (ScalarUnit_Time(self.InputTime). - get_num_from_scalar_unit(self.UserInputUnit)) - except Exception as error: - self.assertIsInstance(error, ValueError) - self.assertEqual(_('"Jz" is not a valid scalar-unit.'), - error.__str__()) - - -class ScalarUnitNegativeTest(TestCase): - - custom_def_snippet = ''' - tosca.my.nodes.Compute: - derived_from: tosca.nodes.Root - properties: - cpu_frequency: - required: false - type: scalar-unit.frequency - constraints: - - greater_or_equal: 0.1 GHz - disk_size: - required: false - type: scalar-unit.size - constraints: - - greater_or_equal: 1 GB - mem_size: - required: false - type: scalar-unit.size - constraints: - - in_range: [1 MiB, 1 GiB] - ''' - custom_def = yamlparser.simple_parse(custom_def_snippet) - - # disk_size doesn't provide a value, mem_size uses an invalid unit. - def test_invalid_scalar_unit(self): - tpl_snippet = ''' - server: - type: tosca.my.nodes.Compute - properties: - cpu_frequency: 50.3.6 GHZ - disk_size: MB - mem_size: 1 QB - ''' - nodetemplates = yamlparser.simple_parse(tpl_snippet) - nodetemplate = NodeTemplate('server', nodetemplates, self.custom_def) - for p in nodetemplate.get_properties_objects(): - self.assertRaises(ValueError, p.validate) - - # disk_size is less than 1 GB, mem_size is not in the required range. - # Note: in the spec, the minimum value of mem_size is 1 MiB (> 1 MB) - def test_constraint_for_scalar_unit(self): - tpl_snippet = ''' - server: - type: tosca.my.nodes.Compute - properties: - cpu_frequency: 0.05 GHz - disk_size: 500 MB - mem_size: 1 MB - ''' - nodetemplates = yamlparser.simple_parse(tpl_snippet) - nodetemplate = NodeTemplate('server', nodetemplates, self.custom_def) - props = nodetemplate.get_properties() - if 'cpu_frequency' in props.keys(): - error = self.assertRaises(exception.ValidationError, - props['cpu_frequency'].validate) - self.assertEqual(_('The value "0.05 GHz" of property ' - '"cpu_frequency" must be greater than or equal ' - 'to "0.1 GHz".'), error.__str__()) - if 'disk_size' in props.keys(): - error = self.assertRaises(exception.ValidationError, - props['disk_size'].validate) - self.assertEqual(_('The value "500 MB" of property "disk_size" ' - 'must be greater than or equal to "1 GB".'), - error.__str__()) - - if 'mem_size' in props.keys(): - error = self.assertRaises(exception.ValidationError, - props['mem_size'].validate) - self.assertEqual(_('The value "1 MB" of property "mem_size" is ' - 'out of range "(min:1 MiB, max:1 GiB)".'), - error.__str__()) diff --git a/nfvparser/src/main/python/toscaparser/tests/test_shell.py b/nfvparser/src/main/python/toscaparser/tests/test_shell.py deleted file mode 100644 index bb163ff..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/test_shell.py +++ /dev/null @@ -1,51 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import os - -from toscaparser.common import exception -import toscaparser.shell as shell -from toscaparser.tests.base import TestCase -from toscaparser.utils.gettextutils import _ - - -class ShellTest(TestCase): - - tosca_helloworld = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/tosca_helloworld.yaml") - - errornous_template = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/test_multiple_validation_errors.yaml") - - def test_missing_arg(self): - self.assertRaises(SystemExit, shell.main, '') - - def test_invalid_arg(self): - self.assertRaises(SystemExit, shell.main, 'parse me') - - def test_template_not_exist(self): - error = self.assertRaises( - ValueError, shell.main, ['--template-file=template.txt']) - self.assertEqual(_('"template.txt" is not a valid file.'), str(error)) - - def test_template_invalid(self): - arg = '--template-file=' + self.errornous_template - self.assertRaises(exception.ValidationError, shell.main, [arg]) - - def test_template_valid(self): - arg = '--template-file=' + self.tosca_helloworld - try: - shell.main([arg]) - except Exception: - self.fail(_('The program raised an exception unexpectedly.')) diff --git a/nfvparser/src/main/python/toscaparser/tests/test_topology_template.py b/nfvparser/src/main/python/toscaparser/tests/test_topology_template.py deleted file mode 100644 index 3aabc9b..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/test_topology_template.py +++ /dev/null @@ -1,313 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import os - -from toscaparser.common import exception -from toscaparser.substitution_mappings import SubstitutionMappings -from toscaparser.tests.base import TestCase -from toscaparser.topology_template import TopologyTemplate -from toscaparser.tosca_template import ToscaTemplate -from toscaparser.utils.gettextutils import _ -import toscaparser.utils.yamlparser - -YAML_LOADER = toscaparser.utils.yamlparser.load_yaml - - -class TopologyTemplateTest(TestCase): - - def setUp(self): - TestCase.setUp(self) - '''TOSCA template.''' - self.tosca_tpl_path = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/topology_template/transactionsubsystem.yaml") - self.tpl = YAML_LOADER(self.tosca_tpl_path) - self.topo_tpl = self.tpl.get('topology_template') - self.imports = self.tpl.get('imports') - self.topo = TopologyTemplate(self.topo_tpl, - self._get_all_custom_def()) - - def _get_custom_def(self, type_definition): - custom_defs = {} - for definition in self.imports: - if os.path.isabs(definition): - def_file = definition - else: - tpl_dir = os.path.dirname(os.path.abspath(self.tosca_tpl_path)) - def_file = os.path.join(tpl_dir, definition) - custom_type = YAML_LOADER(def_file) - custom_defs.update(custom_type.get(type_definition)) - return custom_defs - - def _get_all_custom_def(self): - custom_defs = {} - custom_defs.update(self._get_custom_def('node_types')) - custom_defs.update(self._get_custom_def('capability_types')) - return custom_defs - - def _get_custom_types(self): - custom_types = {} - def_file = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/topology_template/definitions.yaml") - custom_type = YAML_LOADER(def_file) - node_types = custom_type['node_types'] - for name in node_types: - defintion = node_types[name] - custom_types[name] = defintion - return custom_types - - def test_description(self): - expected_desc = 'Template of a database including its hosting stack.' - self.assertEqual(expected_desc, self.topo.description) - - def test_inputs(self): - self.assertEqual( - ['mq_server_ip', 'my_cpus', 'receiver_port'], - sorted([input.name for input in self.topo.inputs])) - - input_name = "receiver_port" - expected_description = "Port to be used for receiving messages." - for input in self.topo.inputs: - if input.name == input_name: - self.assertEqual(expected_description, input.description) - - def test_node_tpls(self): - '''Test nodetemplate names.''' - self.assertEqual( - ['app', 'server', 'websrv'], - sorted([tpl.name for tpl in self.topo.nodetemplates])) - - tpl_name = "app" - expected_type = "example.SomeApp" - expected_properties = ['admin_user', 'pool_size'] - expected_capabilities = ['feature', 'message_receiver'] - expected_requirements = [{'host': {'node': 'websrv'}}] - expected_relationshp = ['tosca.relationships.HostedOn'] - expected_host = ['websrv'] - for tpl in self.topo.nodetemplates: - if tpl_name == tpl.name: - '''Test node type.''' - self.assertEqual(tpl.type, expected_type) - - '''Test properties.''' - self.assertEqual( - expected_properties, - sorted(tpl.get_properties().keys())) - - '''Test capabilities.''' - self.assertEqual( - expected_capabilities, - sorted(tpl.get_capabilities().keys())) - - '''Test requirements.''' - self.assertEqual( - expected_requirements, tpl.requirements) - - '''Test relationship.''' - ''' TODO : skip tempororily. need to fix it - ''' - self.assertEqual( - expected_relationshp, - [x.type for x in tpl.relationships.keys()]) - self.assertEqual( - expected_host, - [y.name for y in tpl.relationships.values()]) - '''Test interfaces.''' - # TODO(hurf) add interface test when new template is available - - if tpl.name == 'server': - '''Test property value''' - props = tpl.get_properties() - if props and 'mem_size' in props.keys(): - self.assertEqual(props['mem_size'].value, '4096 MB') - '''Test capability''' - caps = tpl.get_capabilities() - self.assertIn('os', caps.keys()) - os_props_objs = None - os_props = None - os_type_prop = None - if caps and 'os' in caps.keys(): - capability = caps['os'] - os_props_objs = capability.get_properties_objects() - os_props = capability.get_properties() - os_type_prop = capability.get_property_value('type') - break - self.assertEqual( - ['Linux'], - [p.value for p in os_props_objs if p.name == 'type']) - self.assertEqual( - 'Linux', - os_props['type'].value if 'type' in os_props else '') - self.assertEqual('Linux', os_props['type'].value) - self.assertEqual('Linux', os_type_prop) - - def test_outputs(self): - self.assertEqual( - sorted(['receiver_ip', 'receiver_port']), - sorted([output.name for output in self.topo.outputs])) - - def test_groups(self): - group = self.topo.groups[0] - self.assertEqual('webserver_group', group.name) - self.assertEqual(['websrv', 'server'], group.members) - for node in group.get_member_nodes(): - if node.name == 'server': - '''Test property value''' - props = node.get_properties() - if props and 'mem_size' in props.keys(): - self.assertEqual(props['mem_size'].value, '4096 MB') - - def test_system_template(self): - tpl_path = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/topology_template/system.yaml") - system_tosca_template = ToscaTemplate(tpl_path) - self.assertIsNotNone(system_tosca_template) - self.assertEqual( - len(system_tosca_template. - nested_tosca_templates_with_topology), 4) - self.assertTrue(system_tosca_template.has_nested_templates()) - - def test_invalid_keyname(self): - tpl_snippet = ''' - substitution_mappings: - node_type: example.DatabaseSubsystem - capabilities: - database_endpoint: [ db_app, database_endpoint ] - requirements: - receiver1: [ tran_app, receiver1 ] - invalid_key: 123 - ''' - sub_mappings = (toscaparser.utils.yamlparser. - simple_parse(tpl_snippet))['substitution_mappings'] - expected_message = _( - 'SubstitutionMappings contains unknown field ' - '"invalid_key". Refer to the definition ' - 'to verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: SubstitutionMappings(sub_mappings, None, None, - None, None, None)) - self.assertEqual(expected_message, err.__str__()) - - def test_missing_required_keyname(self): - tpl_snippet = ''' - substitution_mappings: - capabilities: - database_endpoint: [ db_app, database_endpoint ] - requirements: - receiver1: [ tran_app, receiver1 ] - ''' - sub_mappings = (toscaparser.utils.yamlparser. - simple_parse(tpl_snippet))['substitution_mappings'] - expected_message = _('SubstitutionMappings used in topology_template ' - 'is missing required field "node_type".') - err = self.assertRaises( - exception.MissingRequiredFieldError, - lambda: SubstitutionMappings(sub_mappings, None, None, - None, None, None)) - self.assertEqual(expected_message, err.__str__()) - - def test_invalid_nodetype(self): - tpl_snippet = ''' - substitution_mappings: - node_type: example.DatabaseSubsystem1 - capabilities: - database_endpoint: [ db_app, database_endpoint ] - requirements: - receiver1: [ tran_app, receiver1 ] - ''' - sub_mappings = (toscaparser.utils.yamlparser. - simple_parse(tpl_snippet))['substitution_mappings'] - custom_defs = self._get_custom_types() - expected_message = _('Node type "example.DatabaseSubsystem1" ' - 'is not a valid type.') - err = self.assertRaises( - exception.InvalidNodeTypeError, - lambda: SubstitutionMappings(sub_mappings, None, None, - None, None, custom_defs)) - self.assertEqual(expected_message, err.__str__()) - - def test_system_with_input_validation(self): - tpl_path0 = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/topology_template/validate/system_invalid_input.yaml") - tpl_path1 = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/topology_template/validate/" - "queuingsubsystem_invalid_input.yaml") - errormsg = _('SubstitutionMappings with node_type ' - 'example.QueuingSubsystem is missing ' - 'required input definition of input "server_port".') - - # It's invalid in nested template. - self.assertRaises(exception.ValidationError, - lambda: ToscaTemplate(tpl_path0)) - exception.ExceptionCollector.assertExceptionMessage( - exception.MissingRequiredInputError, errormsg) - - # Subtemplate deploy standaolone is also invalid. - self.assertRaises(exception.ValidationError, - lambda: ToscaTemplate(tpl_path1)) - exception.ExceptionCollector.assertExceptionMessage( - exception.MissingRequiredInputError, errormsg) - - def test_system_with_unknown_output_validation(self): - tpl_path0 = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/topology_template/validate/" - "system_invalid_unknown_output.yaml") - tpl_path1 = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/topology_template/validate/" - "transactionsubsystem_invalid_unknown_output.yaml") - errormsg = _('Unknown output "my_cpu_output" in SubstitutionMappings ' - 'with node_type example.TransactionSubsystem.') - - # It's invalid in nested template. - self.assertRaises(exception.ValidationError, - lambda: ToscaTemplate(tpl_path0)) - exception.ExceptionCollector.assertExceptionMessage( - exception.UnknownOutputError, errormsg) - - # Subtemplate deploy standaolone is invalid. - self.assertRaises(exception.ValidationError, - lambda: ToscaTemplate(tpl_path1)) - exception.ExceptionCollector.assertExceptionMessage( - exception.UnknownOutputError, errormsg) - - def test_system_with_missing_output_validation(self): - tpl_path0 = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/topology_template/validate/" - "system_invalid_missing_output.yaml") - tpl_path1 = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/topology_template/validate/" - "transactionsubsystem_invalid_missing_output.yaml") - errormsg = _('SubstitutionMappings with node_type ' - 'example.TransactionSubsystem is missing ' - 'required output definition of output "receiver_port".') - - # It's invalid in nested template. - self.assertRaises(exception.ValidationError, - lambda: ToscaTemplate(tpl_path0)) - exception.ExceptionCollector.assertExceptionMessage( - exception.MissingRequiredOutputError, errormsg) - - # Subtemplate deploy standaolone is invalid. - self.assertRaises(exception.ValidationError, - lambda: ToscaTemplate(tpl_path1)) - exception.ExceptionCollector.assertExceptionMessage( - exception.MissingRequiredOutputError, errormsg) diff --git a/nfvparser/src/main/python/toscaparser/tests/test_toscadef.py b/nfvparser/src/main/python/toscaparser/tests/test_toscadef.py deleted file mode 100644 index 2e97b0e..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/test_toscadef.py +++ /dev/null @@ -1,346 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from toscaparser.common import exception -from toscaparser.elements.artifacttype import ArtifactTypeDef -from toscaparser.elements.entity_type import EntityType -from toscaparser.elements.grouptype import GroupType -import toscaparser.elements.interfaces as ifaces -from toscaparser.elements.nodetype import NodeType -from toscaparser.elements.policytype import PolicyType -from toscaparser.tests.base import TestCase - -compute_type = NodeType('tosca.nodes.Compute') -component_type = NodeType('tosca.nodes.SoftwareComponent') -network_type = NodeType('tosca.nodes.network.Network') -network_port_type = NodeType('tosca.nodes.network.Port') -webserver_type = NodeType('tosca.nodes.WebServer') -database_type = NodeType('tosca.nodes.Database') -artif_root_type = ArtifactTypeDef('tosca.artifacts.Root') -artif_file_type = ArtifactTypeDef('tosca.artifacts.File') -artif_bash_type = ArtifactTypeDef('tosca.artifacts.Implementation.Bash') -artif_python_type = ArtifactTypeDef('tosca.artifacts.Implementation.Python') -artif_container_docker_type = ArtifactTypeDef('tosca.artifacts.' - 'Deployment.Image.' - 'Container.Docker') -artif_vm_iso_type = ArtifactTypeDef('tosca.artifacts.' - 'Deployment.Image.VM.ISO') -artif_vm_qcow2_type = ArtifactTypeDef('tosca.artifacts.' - 'Deployment.Image.VM.QCOW2') -policy_root_type = PolicyType('tosca.policies.Root') -policy_placement_type = PolicyType('tosca.policies.Placement') -policy_scaling_type = PolicyType('tosca.policies.Scaling') -policy_update_type = PolicyType('tosca.policies.Update') -policy_performance_type = PolicyType('tosca.policies.Performance') -group_type = GroupType('tosca.groups.Root') - - -class ToscaDefTest(TestCase): - def test_type(self): - self.assertEqual(compute_type.type, "tosca.nodes.Compute") - self.assertRaises(exception.InvalidTypeError, NodeType, - 'tosca.nodes.Invalid') - self.assertEqual(network_type.type, "tosca.nodes.network.Network") - self.assertEqual(network_port_type.type, "tosca.nodes.network.Port") - - def test_parent_type(self): - self.assertEqual(compute_type.parent_type.type, "tosca.nodes.Root") - self.assertEqual(network_type.parent_type.type, "tosca.nodes.Root") - self.assertEqual(network_port_type.parent_type.type, - "tosca.nodes.Root") - - def test_group(self): - self.assertEqual(group_type.type, "tosca.groups.Root") - self.assertIsNone(group_type.parent_type) - self.assertIn(ifaces.LIFECYCLE_SHORTNAME, group_type.interfaces) - - def test_capabilities(self): - # Assure the normative Compute node type - # has all the required Capability types - # regardless of symbloc name - # TODO(Matt) - since Compute IS a normative node type - # we SHOULD test symbolic capability names as well - self.assertEqual( - ['tosca.capabilities.Container', - 'tosca.capabilities.Endpoint.Admin', - 'tosca.capabilities.Node', - 'tosca.capabilities.OperatingSystem', - 'tosca.capabilities.Scalable', - 'tosca.capabilities.network.Bindable'], - sorted([c.type for c in compute_type.get_capabilities_objects()])) - # Assure the normative Network node type - # hsa all the required Capability types - # TODO(Matt) - since Network IS a normative node type - # we SHOULD test symbolic capability names as well - self.assertEqual( - ['tosca.capabilities.Node', - 'tosca.capabilities.network.Linkable'], - sorted([c.type for c in network_type.get_capabilities_objects()])) - - # Assure the normative WebServer node type's - # Endpoint cap. has all required property names - # Note: we are testing them in alphabetic sort order - endpoint_props_def_objects = \ - self._get_capability_properties_def_objects( - webserver_type.get_capabilities_objects(), - 'tosca.capabilities.Endpoint') - # Assure WebServer's Endpoint capability's properties have their - # required keyname value set correctly - self.assertEqual( - [('initiator', False), ('network_name', False), ('port', False), - ('port_name', False), ('ports', False), ('protocol', True), - ('secure', False), ('url_path', False)], - sorted([(p.name, p.required) for p in endpoint_props_def_objects])) - - os_props = self._get_capability_properties_def_objects( - compute_type.get_capabilities_objects(), - 'tosca.capabilities.OperatingSystem') - self.assertEqual( - [('architecture', False), ('distribution', False), ('type', False), - ('version', False)], - sorted([(p.name, p.required) for p in os_props])) - - host_props = self._get_capability_properties_def_objects( - compute_type.get_capabilities_objects(), - 'tosca.capabilities.Container') - self.assertEqual( - [('cpu_frequency', False), ('disk_size', False), - ('mem_size', False), ('num_cpus', False)], - sorted([(p.name, p.required) for p in host_props])) - endpoint_admin_properties = 'secure' - endpoint_admin_props_def_objects = \ - self._get_capability_properties_def_objects( - webserver_type.get_capabilities_objects(), - 'tosca.capabilities.Endpoint.Admin') - self.assertIn( - endpoint_admin_properties, - sorted([p.name for p in endpoint_admin_props_def_objects])) - - def _get_capability_properties_def_objects(self, caps, type): - properties_def = None - for cap in caps: - if cap.type == type: - properties_def = cap.get_properties_def_objects() - break - return properties_def - - def _get_capability_properties_def(self, caps, type): - properties_def = None - for cap in caps: - if cap.type == type: - properties_def = cap.get_properties_def() - break - return properties_def - - def test_properties_def(self): - self.assertEqual( - ['name', 'password', 'port', 'user'], - sorted(database_type.get_properties_def().keys())) - - def test_attributes_def(self): - self.assertEqual( - ['networks', 'ports', 'private_address', 'public_address', - 'state', 'tosca_id', 'tosca_name'], - sorted(compute_type.get_attributes_def().keys())) - - def test_requirements(self): - self.assertEqual( - [{'host': {'capability': 'tosca.capabilities.Container', - 'node': 'tosca.nodes.Compute', - 'relationship': 'tosca.relationships.HostedOn'}}, - {'dependency': {'capability': 'tosca.capabilities.Node', - 'node': 'tosca.nodes.Root', - 'occurrences': [0, 'UNBOUNDED'], - 'relationship': 'tosca.relationships.DependsOn'}} - ], - [r for r in component_type.requirements]) - - def test_relationship(self): - self.assertEqual( - [('tosca.relationships.DependsOn', 'tosca.nodes.Root'), - ('tosca.relationships.HostedOn', 'tosca.nodes.Compute')], - sorted([(relation.type, node.type) for - relation, node in component_type.relationship.items()])) - self.assertIn( - ('tosca.relationships.HostedOn', ['tosca.capabilities.Container']), - [(relation.type, relation.valid_target_types) for - relation in list(component_type.relationship.keys())]) - self.assertIn( - ('tosca.relationships.network.BindsTo', 'tosca.nodes.Compute'), - [(relation.type, node.type) for - relation, node in network_port_type.relationship.items()]) - self.assertIn( - ('tosca.relationships.network.LinksTo', - 'tosca.nodes.network.Network'), - [(relation.type, node.type) for - relation, node in network_port_type.relationship.items()]) - - def test_interfaces(self): - self.assertIsNone(compute_type.interfaces) - root_node = NodeType('tosca.nodes.Root') - self.assertIn(ifaces.LIFECYCLE_SHORTNAME, root_node.interfaces) - - def test_artifacts(self): - self.assertIsNone(artif_root_type.parent_type) - self.assertEqual('tosca.artifacts.Root', - artif_file_type.parent_type.type) - self.assertEqual({}, artif_file_type.parent_artifacts) - self.assertEqual(sorted(['tosca.artifacts.Root'], - key=lambda x: str(x)), - sorted([artif_file_type.get_artifact(name) - for name in artif_file_type.defs], - key=lambda x: str(x))) - - self.assertEqual('tosca.artifacts.Implementation', - artif_bash_type.parent_type.type) - self.assertEqual({'tosca.artifacts.Implementation': - {'derived_from': 'tosca.artifacts.Root', - 'description': - 'TOSCA base type for implementation artifacts'}}, - artif_bash_type.parent_artifacts) - self.assertEqual(sorted([['sh'], 'tosca.artifacts.Implementation', - 'Script artifact for the Unix Bash shell', - 'application/x-sh'], key=lambda x: str(x)), - sorted([artif_bash_type.get_artifact(name) - for name in artif_bash_type.defs], - key=lambda x: str(x))) - - self.assertEqual('tosca.artifacts.Implementation', - artif_python_type.parent_type.type) - self.assertEqual({'tosca.artifacts.Implementation': - {'derived_from': 'tosca.artifacts.Root', - 'description': - 'TOSCA base type for implementation artifacts'}}, - artif_python_type.parent_artifacts) - self.assertEqual(sorted([['py'], 'tosca.artifacts.Implementation', - 'Artifact for the interpreted Python' - ' language', 'application/x-python'], - key=lambda x: str(x)), - sorted([artif_python_type.get_artifact(name) - for name in artif_python_type.defs], - key=lambda x: str(x))) - - self.assertEqual('tosca.artifacts.Deployment.Image', - artif_container_docker_type.parent_type.type) - self.assertEqual({'tosca.artifacts.Deployment': - {'derived_from': 'tosca.artifacts.Root', - 'description': - 'TOSCA base type for deployment artifacts'}, - 'tosca.artifacts.Deployment.Image': - {'derived_from': 'tosca.artifacts.Deployment'}}, - artif_container_docker_type.parent_artifacts) - self.assertEqual(sorted(['tosca.artifacts.Deployment.Image', - 'Docker container image'], - key=lambda x: str(x)), - sorted([artif_container_docker_type. - get_artifact(name) for name in - artif_container_docker_type.defs], - key=lambda x: str(x))) - - self.assertEqual('tosca.artifacts.Deployment.Image', - artif_vm_iso_type.parent_type.type) - self.assertEqual({'tosca.artifacts.Deployment': - {'derived_from': 'tosca.artifacts.Root', - 'description': - 'TOSCA base type for deployment artifacts'}, - 'tosca.artifacts.Deployment.Image': - {'derived_from': 'tosca.artifacts.Deployment'}}, - artif_vm_iso_type.parent_artifacts) - self.assertEqual(sorted(['tosca.artifacts.Deployment.Image', - 'Virtual Machine (VM) image in ' - 'ISO disk format', - 'application/octet-stream', ['iso']], - key=lambda x: str(x)), - sorted([artif_vm_iso_type. - get_artifact(name) for name in - artif_vm_iso_type.defs], - key=lambda x: str(x))) - - self.assertEqual('tosca.artifacts.Deployment.Image', - artif_vm_qcow2_type.parent_type.type) - self.assertEqual({'tosca.artifacts.Deployment': - {'derived_from': 'tosca.artifacts.Root', - 'description': - 'TOSCA base type for deployment artifacts'}, - 'tosca.artifacts.Deployment.Image': - {'derived_from': 'tosca.artifacts.Deployment'}}, - artif_vm_qcow2_type.parent_artifacts) - self.assertEqual(sorted(['tosca.artifacts.Deployment.Image', - 'Virtual Machine (VM) image in QCOW v2 ' - 'standard disk format', - 'application/octet-stream', ['qcow2']], - key=lambda x: str(x)), - sorted([artif_vm_qcow2_type. - get_artifact(name) for name in - artif_vm_qcow2_type.defs], - key=lambda x: str(x))) - - def test_policies(self): - self.assertIsNone(policy_root_type.parent_type) - self.assertEqual('tosca.policies.Root', - policy_placement_type.parent_type.type) - self.assertEqual({}, policy_placement_type.parent_policies) - self.assertEqual(sorted(['tosca.policies.Root', - 'The TOSCA Policy Type definition that is ' - 'used to govern placement of TOSCA nodes or ' - 'groups of nodes.'], - key=lambda x: str(x)), - sorted([policy_placement_type.get_policy(name) - for name in policy_placement_type.defs], - key=lambda x: str(x))) - - self.assertEqual('tosca.policies.Root', - policy_scaling_type.parent_type.type) - self.assertEqual({}, policy_scaling_type.parent_policies) - self.assertEqual(sorted(['tosca.policies.Root', - 'The TOSCA Policy Type definition that is ' - 'used to govern scaling of TOSCA nodes or ' - 'groups of nodes.'], - key=lambda x: str(x)), - sorted([policy_scaling_type.get_policy(name) - for name in policy_scaling_type.defs], - key=lambda x: str(x))) - - self.assertEqual('tosca.policies.Root', - policy_update_type.parent_type.type) - self.assertEqual({}, policy_update_type.parent_policies) - self.assertEqual(sorted(['tosca.policies.Root', - 'The TOSCA Policy Type definition that is ' - 'used to govern update of TOSCA nodes or ' - 'groups of nodes.'], - key=lambda x: str(x)), - sorted([policy_update_type.get_policy(name) - for name in policy_update_type.defs], - key=lambda x: str(x))) - - self.assertEqual('tosca.policies.Root', - policy_performance_type.parent_type.type) - self.assertEqual({}, policy_performance_type.parent_policies) - self.assertEqual(sorted(['tosca.policies.Root', - 'The TOSCA Policy Type definition that is ' - 'used to declare performance requirements ' - 'for TOSCA nodes or groups of nodes.'], - key=lambda x: str(x)), - sorted([policy_performance_type.get_policy(name) - for name in policy_performance_type.defs], - key=lambda x: str(x))) - - def test_port_spec(self): - tosca_def = EntityType.TOSCA_DEF - port_spec = tosca_def.get('tosca.datatypes.network.PortSpec') - self.assertEqual(port_spec.get('derived_from'), - 'tosca.datatypes.Root') - properties = port_spec.get('properties') - self.assertEqual( - sorted(['protocol', 'target', 'target_range', 'source', - 'source_range']), - sorted(properties.keys())) diff --git a/nfvparser/src/main/python/toscaparser/tests/test_toscatpl.py b/nfvparser/src/main/python/toscaparser/tests/test_toscatpl.py deleted file mode 100644 index fac8687..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/test_toscatpl.py +++ /dev/null @@ -1,854 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import os -import six -from toscaparser.common import exception -import toscaparser.elements.interfaces as ifaces -from toscaparser.elements.nodetype import NodeType -from toscaparser.elements.portspectype import PortSpec -from toscaparser.functions import GetInput -from toscaparser.functions import GetProperty -from toscaparser.nodetemplate import NodeTemplate -from toscaparser.tests.base import TestCase -from toscaparser.tosca_template import ToscaTemplate -from toscaparser.utils.gettextutils import _ -import toscaparser.utils.yamlparser - - -class ToscaTemplateTest(TestCase): - '''TOSCA template.''' - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/tosca_single_instance_wordpress.yaml") - params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user', - 'db_root_pwd': '12345678'} - tosca = ToscaTemplate(tosca_tpl, parsed_params=params) - tosca_elk_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/tosca_elk.yaml") - tosca_repo_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/repositories/tosca_repositories_test_definition.yaml") - - def test_version(self): - self.assertEqual(self.tosca.version, "tosca_simple_yaml_1_0") - - def test_description(self): - expected_description = "TOSCA simple profile with wordpress, " \ - "web server and mysql on the same server." - self.assertEqual(self.tosca.description, expected_description) - - def test_inputs(self): - self.assertEqual( - ['cpus', 'db_name', 'db_port', - 'db_pwd', 'db_root_pwd', 'db_user'], - sorted([input.name for input in self.tosca.inputs])) - - input_name = "db_port" - expected_description = "Port for the MySQL database." - for input in self.tosca.inputs: - if input.name == input_name: - self.assertEqual(input.description, expected_description) - - def test_node_tpls(self): - '''Test nodetemplate names.''' - self.assertEqual( - ['mysql_database', 'mysql_dbms', 'server', - 'webserver', 'wordpress'], - sorted([tpl.name for tpl in self.tosca.nodetemplates])) - - tpl_name = "mysql_database" - expected_type = "tosca.nodes.Database" - expected_properties = ['name', 'password', 'user'] - expected_capabilities = ['database_endpoint', 'feature'] - expected_requirements = [{'host': 'mysql_dbms'}] - ''' TODO: needs enhancement in tosca_elk.yaml.. - expected_relationshp = ['tosca.relationships.HostedOn'] - expected_host = ['mysql_dbms'] - ''' - expected_interface = [ifaces.LIFECYCLE_SHORTNAME] - - for tpl in self.tosca.nodetemplates: - if tpl_name == tpl.name: - '''Test node type.''' - self.assertEqual(tpl.type, expected_type) - - '''Test properties.''' - self.assertEqual( - expected_properties, - sorted(tpl.get_properties().keys())) - - '''Test capabilities.''' - self.assertEqual( - expected_capabilities, - sorted(tpl.get_capabilities().keys())) - - '''Test requirements.''' - self.assertEqual( - expected_requirements, tpl.requirements) - - '''Test relationship.''' - ''' needs enhancements in tosca_elk.yaml - self.assertEqual( - expected_relationshp, - [x.type for x in tpl.relationships.keys()]) - self.assertEqual( - expected_host, - [y.name for y in tpl.relationships.values()]) - ''' - '''Test interfaces.''' - self.assertEqual( - expected_interface, - [x.type for x in tpl.interfaces]) - - if tpl.name == 'server': - '''Test property value''' - props = tpl.get_properties() - if props and 'mem_size' in props.keys(): - self.assertEqual(props['mem_size'].value, '4096 MB') - '''Test capability''' - caps = tpl.get_capabilities() - self.assertIn('os', caps.keys()) - os_props_objs = None - os_props = None - os_type_prop = None - if caps and 'os' in caps.keys(): - capability = caps['os'] - os_props_objs = capability.get_properties_objects() - os_props = capability.get_properties() - os_type_prop = capability.get_property_value('type') - break - self.assertEqual( - ['Linux'], - [p.value for p in os_props_objs if p.name == 'type']) - self.assertEqual( - 'Linux', - os_props['type'].value if 'type' in os_props else '') - self.assertEqual('Linux', os_props['type'].value) - self.assertEqual('Linux', os_type_prop) - - def test_node_inheritance_type(self): - wordpress_node = [ - node for node in self.tosca.nodetemplates - if node.name == 'wordpress'][0] - self.assertTrue( - wordpress_node.is_derived_from("tosca.nodes.WebApplication")) - self.assertTrue( - wordpress_node.is_derived_from("tosca.nodes.Root")) - self.assertFalse( - wordpress_node.is_derived_from("tosca.policies.Root")) - - def test_outputs(self): - self.assertEqual( - ['website_url'], - sorted([output.name for output in self.tosca.outputs])) - - def test_interfaces(self): - wordpress_node = [ - node for node in self.tosca.nodetemplates - if node.name == 'wordpress'][0] - interfaces = wordpress_node.interfaces - self.assertEqual(2, len(interfaces)) - for interface in interfaces: - if interface.name == 'create': - self.assertEqual(ifaces.LIFECYCLE_SHORTNAME, - interface.type) - self.assertEqual('wordpress/wordpress_install.sh', - interface.implementation) - self.assertIsNone(interface.inputs) - elif interface.name == 'configure': - self.assertEqual(ifaces.LIFECYCLE_SHORTNAME, - interface.type) - self.assertEqual('wordpress/wordpress_configure.sh', - interface.implementation) - self.assertEqual(3, len(interface.inputs)) - TestCase.skip(self, 'bug #1440247') - wp_db_port = interface.inputs['wp_db_port'] - self.assertIsInstance(wp_db_port, GetProperty) - self.assertEqual('get_property', wp_db_port.name) - self.assertEqual(['SELF', - 'database_endpoint', - 'port'], - wp_db_port.args) - result = wp_db_port.result() - self.assertIsInstance(result, GetInput) - else: - raise AssertionError( - 'Unexpected interface: {0}'.format(interface.name)) - - def test_normative_type_by_short_name(self): - # test template with a short name Compute - template = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/test_tosca_normative_type_by_shortname.yaml") - - tosca_tpl = ToscaTemplate(template) - expected_type = "tosca.nodes.Compute" - for tpl in tosca_tpl.nodetemplates: - self.assertEqual(tpl.type, expected_type) - for tpl in tosca_tpl.nodetemplates: - compute_type = NodeType(tpl.type) - self.assertEqual( - sorted(['tosca.capabilities.Container', - 'tosca.capabilities.Endpoint.Admin', - 'tosca.capabilities.Node', - 'tosca.capabilities.OperatingSystem', - 'tosca.capabilities.network.Bindable', - 'tosca.capabilities.Scalable']), - sorted([c.type - for c in compute_type.get_capabilities_objects()])) - - def test_template_with_no_inputs(self): - tosca_tpl = self._load_template('test_no_inputs_in_template.yaml') - self.assertEqual(0, len(tosca_tpl.inputs)) - - def test_template_with_no_outputs(self): - tosca_tpl = self._load_template('test_no_outputs_in_template.yaml') - self.assertEqual(0, len(tosca_tpl.outputs)) - - def test_relationship_interface(self): - template = ToscaTemplate(self.tosca_elk_tpl) - for node_tpl in template.nodetemplates: - if node_tpl.name == 'logstash': - config_interface = 'Configure' - artifact = 'logstash/configure_elasticsearch.py' - relation = node_tpl.relationships - for key in relation.keys(): - rel_tpl = relation.get(key).get_relationship_template() - if rel_tpl: - self.assertTrue(rel_tpl[0].is_derived_from( - "tosca.relationships.Root")) - interfaces = rel_tpl[0].interfaces - for interface in interfaces: - self.assertEqual(config_interface, - interface.type) - self.assertEqual('pre_configure_source', - interface.name) - self.assertEqual(artifact, - interface.implementation) - - def test_relationship(self): - template = ToscaTemplate(self.tosca_elk_tpl) - for node_tpl in template.nodetemplates: - if node_tpl.name == 'paypal_pizzastore': - expected_relationships = ['tosca.relationships.ConnectsTo', - 'tosca.relationships.HostedOn'] - expected_hosts = ['tosca.nodes.Database', - 'tosca.nodes.WebServer'] - self.assertEqual(len(node_tpl.relationships), 2) - self.assertEqual( - expected_relationships, - sorted([k.type for k in node_tpl.relationships.keys()])) - self.assertEqual( - expected_hosts, - sorted([v.type for v in node_tpl.relationships.values()])) - - def test_repositories(self): - template = ToscaTemplate(self.tosca_repo_tpl) - self.assertEqual( - ['repo_code0', 'repo_code1', 'repo_code2'], - sorted([input.name for input in template.repositories])) - - input_name = "repo_code2" - expected_url = "https://github.com/nandinivemula/intern/master" - for input in template.repositories: - if input.name == input_name: - self.assertEqual(input.url, expected_url) - - def test_template_macro(self): - template = ToscaTemplate(self.tosca_elk_tpl) - for node_tpl in template.nodetemplates: - if node_tpl.name == 'mongo_server': - self.assertEqual( - ['disk_size', 'mem_size', 'num_cpus'], - sorted(node_tpl.get_capability('host'). - get_properties().keys())) - - def test_template_requirements(self): - """Test different formats of requirements - - The requirements can be defined in few different ways, - 1. Requirement expressed as a capability with an implicit relationship. - 2. Requirement expressed with explicit relationship. - 3. Requirement expressed with a relationship template. - 4. Requirement expressed via TOSCA types to provision a node - with explicit relationship. - 5. Requirement expressed via TOSCA types with a filter. - """ - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/requirements/test_requirements.yaml") - tosca = ToscaTemplate(tosca_tpl) - for node_tpl in tosca.nodetemplates: - if node_tpl.name == 'my_app': - expected_relationship = [ - ('tosca.relationships.ConnectsTo', 'mysql_database'), - ('tosca.relationships.HostedOn', 'my_webserver')] - actual_relationship = sorted([ - (relation.type, node.name) for - relation, node in node_tpl.relationships.items()]) - self.assertEqual(expected_relationship, actual_relationship) - if node_tpl.name == 'mysql_database': - self.assertEqual( - [('tosca.relationships.HostedOn', 'my_dbms')], - [(relation.type, node.name) for - relation, - node in node_tpl.relationships.items()]) - if node_tpl.name == 'my_server': - self.assertEqual( - [('tosca.relationships.AttachesTo', 'my_storage')], - [(relation.type, node.name) for - relation, - node in node_tpl.relationships.items()]) - - def test_template_requirements_not_implemented(self): - # TODO(spzala): replace this test with new one once TOSCA types look up - # support is implemented. - """Requirements that yet need to be implemented - - The following requirement formats are not yet implemented, - due to look up dependency: - 1. Requirement expressed via TOSCA types to provision a node - with explicit relationship. - 2. Requirement expressed via TOSCA types with a filter. - """ - tpl_snippet_1 = ''' - node_templates: - mysql_database: - type: tosca.nodes.Database - description: Requires a particular node type and relationship. - To be full-filled via lookup into node repository. - requirements: - - req1: - node: tosca.nodes.DBMS - relationship: tosca.relationships.HostedOn - ''' - - tpl_snippet_2 = ''' - node_templates: - my_webserver: - type: tosca.nodes.WebServer - description: Requires a particular node type with a filter. - To be full-filled via lookup into node repository. - requirements: - - req1: - node: tosca.nodes.Compute - target_filter: - properties: - num_cpus: { in_range: [ 1, 4 ] } - mem_size: { greater_or_equal: 2 } - capabilities: - - tosca.capabilities.OS: - properties: - architecture: x86_64 - type: linux - ''' - - tpl_snippet_3 = ''' - node_templates: - my_webserver2: - type: tosca.nodes.WebServer - description: Requires a node type with a particular capability. - To be full-filled via lookup into node repository. - requirements: - - req1: - node: tosca.nodes.Compute - relationship: tosca.relationships.HostedOn - capability: tosca.capabilities.Container - ''' - self._requirements_not_implemented(tpl_snippet_1, 'mysql_database') - self._requirements_not_implemented(tpl_snippet_2, 'my_webserver') - self._requirements_not_implemented(tpl_snippet_3, 'my_webserver2') - - def _requirements_not_implemented(self, tpl_snippet, tpl_name): - nodetemplates = (toscaparser.utils.yamlparser. - simple_parse(tpl_snippet))['node_templates'] - self.assertRaises( - NotImplementedError, - lambda: NodeTemplate(tpl_name, nodetemplates).relationships) - - # Test the following: - # 1. Custom node type derived from 'WebApplication' named 'TestApp' - # with a custom Capability Type 'TestCapability' - # 2. Same as #1, but referencing a custom 'TestCapability' Capability Type - # that is not defined - def test_custom_capability_type_definition(self): - tpl_snippet = ''' - node_templates: - test_app: - type: tosca.nodes.WebApplication.TestApp - capabilities: - test_cap: - properties: - test: 1 - ''' - # custom node type definition with custom capability type definition - custom_def = ''' - tosca.nodes.WebApplication.TestApp: - derived_from: tosca.nodes.WebApplication - capabilities: - test_cap: - type: tosca.capabilities.TestCapability - tosca.capabilities.TestCapability: - derived_from: tosca.capabilities.Root - properties: - test: - type: integer - required: false - ''' - expected_capabilities = ['app_endpoint', 'feature', 'test_cap'] - nodetemplates = (toscaparser.utils.yamlparser. - simple_parse(tpl_snippet))['node_templates'] - custom_def = (toscaparser.utils.yamlparser. - simple_parse(custom_def)) - name = list(nodetemplates.keys())[0] - tpl = NodeTemplate(name, nodetemplates, custom_def) - self.assertEqual( - expected_capabilities, - sorted(tpl.get_capabilities().keys())) - - # custom definition without valid capability type definition - custom_def = ''' - tosca.nodes.WebApplication.TestApp: - derived_from: tosca.nodes.WebApplication - capabilities: - test_cap: - type: tosca.capabilities.TestCapability - ''' - custom_def = (toscaparser.utils.yamlparser. - simple_parse(custom_def)) - tpl = NodeTemplate(name, nodetemplates, custom_def) - err = self.assertRaises( - exception.InvalidTypeError, - lambda: NodeTemplate(name, nodetemplates, - custom_def).get_capabilities_objects()) - self.assertEqual('Type "tosca.capabilities.TestCapability" is not ' - 'a valid type.', six.text_type(err)) - - def test_local_template_with_local_relpath_import(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/tosca_single_instance_wordpress.yaml") - params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user', - 'db_root_pwd': '12345678'} - tosca = ToscaTemplate(tosca_tpl, parsed_params=params) - self.assertTrue(tosca.topology_template.custom_defs) - - def test_local_template_with_url_import(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/tosca_single_instance_wordpress_with_url_import.yaml") - tosca = ToscaTemplate(tosca_tpl, - parsed_params={'db_root_pwd': '123456'}) - self.assertTrue(tosca.topology_template.custom_defs) - - def test_url_template_with_local_relpath_import(self): - tosca_tpl = ('https://raw.githubusercontent.com/openstack/' - 'tosca-parser/master/toscaparser/tests/data/' - 'tosca_single_instance_wordpress.yaml') - tosca = ToscaTemplate(tosca_tpl, a_file=False, - parsed_params={"db_name": "mysql", - "db_user": "mysql", - "db_root_pwd": "1234", - "db_pwd": "5678", - "db_port": 3306, - "cpus": 4}) - self.assertTrue(tosca.topology_template.custom_defs) - - def test_url_template_with_local_abspath_import(self): - tosca_tpl = ('https://raw.githubusercontent.com/openstack/' - 'tosca-parser/master/toscaparser/tests/data/' - 'tosca_single_instance_wordpress_with_local_abspath_' - 'import.yaml') - self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl, - None, False) - err_msg = (_('Absolute file name "/tmp/tosca-parser/toscaparser/tests' - '/data/custom_types/wordpress.yaml" cannot be used in a ' - 'URL-based input template "%(tpl)s".') - % {'tpl': tosca_tpl}) - exception.ExceptionCollector.assertExceptionMessage(ImportError, - err_msg) - - def test_url_template_with_url_import(self): - tosca_tpl = ('https://raw.githubusercontent.com/openstack/' - 'tosca-parser/master/toscaparser/tests/data/' - 'tosca_single_instance_wordpress_with_url_import.yaml') - tosca = ToscaTemplate(tosca_tpl, a_file=False, - parsed_params={"db_root_pwd": "1234"}) - self.assertTrue(tosca.topology_template.custom_defs) - - def test_csar_parsing_wordpress(self): - csar_archive = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - 'data/CSAR/csar_wordpress.zip') - self.assertTrue(ToscaTemplate(csar_archive, - parsed_params={"db_name": "mysql", - "db_user": "mysql", - "db_root_pwd": "1234", - "db_pwd": "5678", - "db_port": 3306, - "cpus": 4})) - - def test_csar_parsing_elk_url_based(self): - csar_archive = ('https://github.com/openstack/tosca-parser/raw/master/' - 'toscaparser/tests/data/CSAR/csar_elk.zip') - self.assertTrue(ToscaTemplate(csar_archive, a_file=False, - parsed_params={"my_cpus": 4})) - - def test_nested_imports_in_templates(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/test_instance_nested_imports.yaml") - tosca = ToscaTemplate(tosca_tpl) - expected_custom_types = ['tosca.nodes.WebApplication.WordPress', - 'test_namespace_prefix.Rsyslog', - 'Test2ndRsyslogType', - 'test_2nd_namespace_prefix.Rsyslog', - 'tosca.nodes.SoftwareComponent.Logstash', - 'tosca.nodes.SoftwareComponent.Rsyslog.' - 'TestRsyslogType'] - self.assertItemsEqual(tosca.topology_template.custom_defs.keys(), - expected_custom_types) - - def test_invalid_template_file(self): - template_file = 'invalid template file' - expected_msg = (_('"%s" is not a valid file.') % template_file) - self.assertRaises( - exception.ValidationError, - ToscaTemplate, template_file, None, False) - exception.ExceptionCollector.assertExceptionMessage(ValueError, - expected_msg) - - def test_multiple_validation_errors(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/test_multiple_validation_errors.yaml") - self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl, - None) - valid_versions = ', '.join(ToscaTemplate.VALID_TEMPLATE_VERSIONS) - err1_msg = (_('The template version "tosca_simple_yaml_1" is invalid. ' - 'Valid versions are "%s".') % valid_versions) - exception.ExceptionCollector.assertExceptionMessage( - exception.InvalidTemplateVersion, err1_msg) - - err2_msg = _('Import "custom_types/not_there.yaml" is not valid.') - exception.ExceptionCollector.assertExceptionMessage( - ImportError, err2_msg) - - err3_msg = _('Type "tosca.nodes.WebApplication.WordPress" is not a ' - 'valid type.') - exception.ExceptionCollector.assertExceptionMessage( - exception.InvalidTypeError, err3_msg) - - err4_msg = _('Node template "wordpress" contains unknown field ' - '"requirement". Refer to the definition to verify valid ' - 'values.') - exception.ExceptionCollector.assertExceptionMessage( - exception.UnknownFieldError, err4_msg) - - err5_msg = _('\'Property "passwords" was not found in node template ' - '"mysql_database".\'') - exception.ExceptionCollector.assertExceptionMessage( - KeyError, err5_msg) - - err6_msg = _('Template "mysql_dbms" is missing required field "type".') - exception.ExceptionCollector.assertExceptionMessage( - exception.MissingRequiredFieldError, err6_msg) - - err7_msg = _('Node template "mysql_dbms" contains unknown field ' - '"type1". Refer to the definition to verify valid ' - 'values.') - exception.ExceptionCollector.assertExceptionMessage( - exception.UnknownFieldError, err7_msg) - - err8_msg = _('\'Node template "server1" was not found in ' - '"webserver".\'') - exception.ExceptionCollector.assertExceptionMessage( - KeyError, err8_msg) - - err9_msg = _('"relationship" used in template "webserver" is missing ' - 'required field "type".') - exception.ExceptionCollector.assertExceptionMessage( - exception.MissingRequiredFieldError, err9_msg) - - err10_msg = _('Type "tosca.nodes.XYZ" is not a valid type.') - exception.ExceptionCollector.assertExceptionMessage( - exception.InvalidTypeError, err10_msg) - - def test_invalid_section_names(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/test_invalid_section_names.yaml") - self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl, - None) - err1_msg = _('Template contains unknown field ' - '"tosca_definitions_versions". Refer to the definition ' - 'to verify valid values.') - exception.ExceptionCollector.assertExceptionMessage( - exception.UnknownFieldError, err1_msg) - - err2_msg = _('Template contains unknown field "descriptions". ' - 'Refer to the definition to verify valid values.') - exception.ExceptionCollector.assertExceptionMessage( - exception.UnknownFieldError, err2_msg) - - err3_msg = _('Template contains unknown field "import". Refer to ' - 'the definition to verify valid values.') - exception.ExceptionCollector.assertExceptionMessage( - exception.UnknownFieldError, err3_msg) - - err4_msg = _('Template contains unknown field "topology_templates". ' - 'Refer to the definition to verify valid values.') - exception.ExceptionCollector.assertExceptionMessage( - exception.UnknownFieldError, err4_msg) - - def test_csar_with_alternate_extenstion(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/CSAR/csar_elk.csar") - tosca = ToscaTemplate(tosca_tpl, parsed_params={"my_cpus": 2}) - self.assertTrue(tosca.topology_template.custom_defs) - - def test_available_rel_tpls(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/test_available_rel_tpls.yaml") - tosca = ToscaTemplate(tosca_tpl) - for node in tosca.nodetemplates: - for relationship, target in node.relationships.items(): - try: - target.relationships - except TypeError as error: - self.fail(error) - - def test_no_input(self): - self.assertRaises(exception.ValidationError, ToscaTemplate, None, - None, False, None) - err_msg = (('No path or yaml_dict_tpl was provided. ' - 'There is nothing to parse.')) - exception.ExceptionCollector.assertExceptionMessage(ValueError, - err_msg) - - def test_path_and_yaml_dict_tpl_input(self): - test_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/tosca_helloworld.yaml") - - yaml_dict_tpl = toscaparser.utils.yamlparser.load_yaml(test_tpl) - - tosca = ToscaTemplate(test_tpl, yaml_dict_tpl=yaml_dict_tpl) - - self.assertEqual(tosca.version, "tosca_simple_yaml_1_0") - - def test_yaml_dict_tpl_input(self): - test_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/tosca_helloworld.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_0") - - def test_yaml_dict_tpl_with_params_and_url_import(self): - test_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/tosca_single_instance_wordpress_with_url_import.yaml") - - yaml_dict_tpl = toscaparser.utils.yamlparser.load_yaml(test_tpl) - - params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user', - 'db_root_pwd': 'mypasswd'} - - tosca = ToscaTemplate(parsed_params=params, - yaml_dict_tpl=yaml_dict_tpl) - - self.assertEqual(tosca.version, "tosca_simple_yaml_1_0") - - def test_yaml_dict_tpl_with_rel_import(self): - test_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/tosca_single_instance_wordpress.yaml") - - yaml_dict_tpl = toscaparser.utils.yamlparser.load_yaml(test_tpl) - params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user', - 'db_root_pwd': '12345678'} - self.assertRaises(exception.ValidationError, ToscaTemplate, None, - params, False, yaml_dict_tpl) - err_msg = (_('Relative file name "custom_types/wordpress.yaml" ' - 'cannot be used in a pre-parsed input template.')) - exception.ExceptionCollector.assertExceptionMessage(ImportError, - err_msg) - - def test_yaml_dict_tpl_with_fullpath_import(self): - test_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/tosca_single_instance_wordpress.yaml") - - yaml_dict_tpl = toscaparser.utils.yamlparser.load_yaml(test_tpl) - - yaml_dict_tpl['imports'] = [os.path.join(os.path.dirname( - os.path.abspath(__file__)), "data/custom_types/wordpress.yaml")] - - params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user', - 'db_root_pwd': 'mypasswd'} - - tosca = ToscaTemplate(parsed_params=params, - yaml_dict_tpl=yaml_dict_tpl) - - self.assertEqual(tosca.version, "tosca_simple_yaml_1_0") - - def test_policies_for_node_templates(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/policies/tosca_policy_template.yaml") - tosca = ToscaTemplate(tosca_tpl) - - for policy in tosca.topology_template.policies: - self.assertTrue( - policy.is_derived_from("tosca.policies.Root")) - if policy.name == 'my_compute_placement_policy': - self.assertEqual('tosca.policies.Placement', policy.type) - self.assertEqual(['my_server_1', 'my_server_2'], - policy.targets) - self.assertEqual('node_templates', policy.get_targets_type()) - for node in policy.targets_list: - if node.name == 'my_server_1': - '''Test property value''' - props = node.get_properties() - if props and 'mem_size' in props.keys(): - self.assertEqual(props['mem_size'].value, - '4096 MB') - - def test_policies_for_groups(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/policies/tosca_policy_template.yaml") - tosca = ToscaTemplate(tosca_tpl) - - for policy in tosca.topology_template.policies: - self.assertTrue( - policy.is_derived_from("tosca.policies.Root")) - if policy.name == 'my_groups_placement': - self.assertEqual('mycompany.mytypes.myScalingPolicy', - policy.type) - self.assertEqual(['webserver_group'], policy.targets) - self.assertEqual('groups', policy.get_targets_type()) - group = policy.get_targets_list()[0] - for node in group.get_member_nodes(): - if node.name == 'my_server_2': - '''Test property value''' - props = node.get_properties() - if props and 'mem_size' in props.keys(): - self.assertEqual(props['mem_size'].value, - '4096 MB') - - def test_node_filter(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/node_filter/test_node_filter.yaml") - ToscaTemplate(tosca_tpl) - - def test_attributes_inheritance(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/test_attributes_inheritance.yaml") - ToscaTemplate(tosca_tpl) - - def test_repositories_definition(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/repositories/test_repositories_definition.yaml") - ToscaTemplate(tosca_tpl) - - def test_custom_caps_def(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/test_custom_caps_def.yaml") - ToscaTemplate(tosca_tpl) - - def test_custom_rel_with_script(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/test_tosca_custom_rel_with_script.yaml") - tosca = ToscaTemplate(tosca_tpl) - rel = tosca.relationship_templates[0] - self.assertEqual(rel.type, "tosca.relationships.HostedOn") - self.assertTrue(rel.is_derived_from("tosca.relationships.Root")) - self.assertEqual(len(rel.interfaces), 1) - self.assertEqual(rel.interfaces[0].type, "Configure") - - def test_various_portspec_errors(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/datatypes/test_datatype_portspec_add_req.yaml") - self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl, - None) - - # TODO(TBD) find way to reuse error messages from constraints.py - msg = (_('The value "%(pvalue)s" of property "%(pname)s" is out of ' - 'range "(min:%(vmin)s, max:%(vmax)s)".') % - dict(pname=PortSpec.SOURCE, - pvalue='0', - vmin='1', - vmax='65535')) - exception.ExceptionCollector.assertExceptionMessage( - exception.ValidationError, msg) - - # Test value below range min. - msg = (_('The value "%(pvalue)s" of property "%(pname)s" is out of ' - 'range "(min:%(vmin)s, max:%(vmax)s)".') % - dict(pname=PortSpec.SOURCE, - pvalue='1', - vmin='2', - vmax='65534')) - exception.ExceptionCollector.assertExceptionMessage( - exception.RangeValueError, msg) - - # Test value above range max. - msg = (_('The value "%(pvalue)s" of property "%(pname)s" is out of ' - 'range "(min:%(vmin)s, max:%(vmax)s)".') % - dict(pname=PortSpec.SOURCE, - pvalue='65535', - vmin='2', - vmax='65534')) - exception.ExceptionCollector.assertExceptionMessage( - exception.RangeValueError, msg) - - def test_containers(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/containers/test_container_docker_mysql.yaml") - ToscaTemplate(tosca_tpl, parsed_params={"mysql_root_pwd": "12345678"}) - - def test_endpoint_on_compute(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/test_endpoint_on_compute.yaml") - ToscaTemplate(tosca_tpl) - - def test_nested_dsl_def(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/dsl_definitions/test_nested_dsl_def.yaml") - self.assertIsNotNone(ToscaTemplate(tosca_tpl)) - - def test_multiple_policies(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/policies/test_tosca_nfv_multiple_policies.yaml") - tosca = ToscaTemplate(tosca_tpl) - self.assertEqual( - ['ALRM1', 'SP1', 'SP2'], - sorted([policy.name for policy in tosca.policies])) diff --git a/nfvparser/src/main/python/toscaparser/tests/test_toscatplvalidation.py b/nfvparser/src/main/python/toscaparser/tests/test_toscatplvalidation.py deleted file mode 100644 index 911867f..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/test_toscatplvalidation.py +++ /dev/null @@ -1,1784 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import os -import six - -from toscaparser.common import exception -from toscaparser.imports import ImportsLoader -from toscaparser.nodetemplate import NodeTemplate -from toscaparser.parameters import Input -from toscaparser.parameters import Output -from toscaparser.policy import Policy -from toscaparser.relationship_template import RelationshipTemplate -from toscaparser.repositories import Repository -from toscaparser.tests.base import TestCase -from toscaparser.topology_template import TopologyTemplate -from toscaparser.tosca_template import ToscaTemplate -from toscaparser.triggers import Triggers -from toscaparser.utils.gettextutils import _ -import toscaparser.utils.yamlparser - - -class ToscaTemplateValidationTest(TestCase): - - def test_well_defined_template(self): - tpl_path = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/tosca_single_instance_wordpress.yaml") - params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user', - 'db_root_pwd': '12345678'} - self.assertIsNotNone(ToscaTemplate(tpl_path, params)) - - def test_custom_interface_allowed(self): - tpl_path = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/interfaces/test_custom_interface_in_template.yaml") - self.assertIsNotNone(ToscaTemplate(tpl_path)) - - def test_custom_interface_invalid_operation(self): - tpl_path = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/interfaces/test_custom_interface_invalid_operation.yaml") - self.assertRaises(exception.ValidationError, - ToscaTemplate, tpl_path) - exception.ExceptionCollector.assertExceptionMessage( - exception.UnknownFieldError, - _('"interfaces" of template "customInterfaceTest" ' - 'contains unknown field "CustomOp4". ' - 'Refer to the definition to verify valid values.')) - - def test_first_level_sections(self): - tpl_path = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/test_tosca_top_level_error1.yaml") - self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path) - exception.ExceptionCollector.assertExceptionMessage( - exception.MissingRequiredFieldError, - _('Template is missing required field ' - '"tosca_definitions_version".')) - - tpl_path = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/test_tosca_top_level_error2.yaml") - self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path) - exception.ExceptionCollector.assertExceptionMessage( - exception.UnknownFieldError, - _('Template contains unknown field "node_template". Refer to the ' - 'definition to verify valid values.')) - - def test_template_with_imports_validation(self): - tpl_path = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/tosca_imports_validation.yaml") - self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path) - exception.ExceptionCollector.assertExceptionMessage( - exception.UnknownFieldError, - _('Template custom_types/imported_sample.yaml contains unknown ' - 'field "descriptions". Refer to the definition' - ' to verify valid values.')) - exception.ExceptionCollector.assertExceptionMessage( - exception.UnknownFieldError, - _('Template custom_types/imported_sample.yaml contains unknown ' - 'field "node_typess". Refer to the definition to ' - 'verify valid values.')) - exception.ExceptionCollector.assertExceptionMessage( - exception.UnknownFieldError, - _('Template custom_types/imported_sample.yaml contains unknown ' - 'field "tosca1_definitions_version". Refer to the definition' - ' to verify valid values.')) - exception.ExceptionCollector.assertExceptionMessage( - exception.InvalidTemplateVersion, - _('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_profile_for_nfv_1_0_0".')) - exception.ExceptionCollector.assertExceptionMessage( - exception.UnknownFieldError, - _('Template custom_types/imported_sample.yaml contains unknown ' - 'field "policy_types1". Refer to the definition to ' - 'verify valid values.')) - exception.ExceptionCollector.assertExceptionMessage( - exception.UnknownFieldError, - _('Nodetype"tosca.nodes.SoftwareComponent.Logstash" contains ' - 'unknown field "capabilities1". Refer to the definition ' - 'to verify valid values.')) - exception.ExceptionCollector.assertExceptionMessage( - exception.UnknownFieldError, - _('Policy "mycompany.mytypes.myScalingPolicy" contains unknown ' - 'field "derived1_from". Refer to the definition to ' - 'verify valid values.')) - exception.ExceptionCollector.assertExceptionMessage( - exception.UnknownFieldError, - _('Relationshiptype "test.relation.connects" contains unknown ' - 'field "derived_from4". Refer to the definition to ' - 'verify valid values.')) - - def test_getoperation_IncorrectValue(self): - # test case 1 - tpl_snippet = ''' - node_templates: - front_end: - type: tosca.nodes.Compute - interfaces: - Standard: - create: - implementation: scripts/frontend/create.sh - configure: - implementation: scripts/frontend/configure.sh - inputs: - data_dir: {get_operation_output: [front_end,Standard1, - create,data_dir]} - ''' - tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) - err = self.assertRaises(ValueError, - TopologyTemplate, tpl, None) - expectedmessage = _('Enter a valid interface name') - self.assertEqual(expectedmessage, err.__str__()) - # test case 2 - tpl_snippet2 = ''' - node_templates: - front_end: - type: tosca.nodes.Compute - interfaces: - Standard: - create: - implementation: scripts/frontend/create.sh - configure: - implementation: scripts/frontend/configure.sh - inputs: - data_dir: {get_operation_output: [front_end1,Standard, - create,data_dir]} - ''' - tpl2 = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet2)) - err2 = self.assertRaises(KeyError, - TopologyTemplate, tpl2, None) - expectedmessage2 = _('\'Node template "front_end1" was not found.\'') - self.assertEqual(expectedmessage2, err2.__str__()) - # test case 3 - tpl_snippet3 = ''' - node_templates: - front_end: - type: tosca.nodes.Compute - interfaces: - Standard: - create: - implementation: scripts/frontend/create.sh - configure: - implementation: scripts/frontend/configure.sh - inputs: - data_dir: {get_operation_output: [front_end,Standard, - get_target,data_dir]} - ''' - tpl3 = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet3)) - err3 = self.assertRaises(ValueError, - TopologyTemplate, tpl3, None) - expectedmessage3 = _('Enter an operation of Standard interface') - self.assertEqual(expectedmessage3, err3.__str__()) - # test case 4 - tpl_snippet4 = ''' - node_templates: - front_end: - type: tosca.nodes.Compute - interfaces: - Standard: - create: - implementation: scripts/frontend/create.sh - configure: - implementation: scripts/frontend/configure.sh - inputs: - data_dir: {get_operation_output: [front_end,Configure, - create,data_dir]} - ''' - tpl4 = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet4)) - err4 = self.assertRaises(ValueError, - TopologyTemplate, tpl4, None) - expectedmessage4 = _('Enter an operation of Configure interface') - self.assertEqual(expectedmessage4, err4.__str__()) - # test case 5 - tpl_snippet5 = ''' - node_templates: - front_end: - type: tosca.nodes.Compute - interfaces: - Standard: - create: - implementation: scripts/frontend/create.sh - configure: - implementation: scripts/frontend/configure.sh - inputs: - data_dir: {get_operation_output: [front_end,Standard, - create]} - ''' - tpl5 = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet5)) - err5 = self.assertRaises(ValueError, - TopologyTemplate, tpl5, None) - expectedmessage5 = _('Illegal arguments for function' - ' "get_operation_output".' - ' Expected arguments: "template_name",' - '"interface_name",' - '"operation_name","output_variable_name"') - self.assertEqual(expectedmessage5, err5.__str__()) - - def test_unsupported_type(self): - tpl_snippet = ''' - node_templates: - invalid_type: - type: tosca.test.invalidtype - properties: - size: { get_input: storage_size } - snapshot_id: { get_input: storage_snapshot_id } - ''' - tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) - err = self.assertRaises(exception.UnsupportedTypeError, - TopologyTemplate, tpl, None) - expectedmessage = _('Type "tosca.test.invalidtype" is valid' - ' TOSCA type but not supported at this time.') - self.assertEqual(expectedmessage, err.__str__()) - - def test_inputs(self): - tpl_snippet1 = ''' - inputs: - cpus: - type: integer - description: Number of CPUs for the server. - constraint: - - valid_values: [ 1, 2, 4 ] - required: yes - status: supported - ''' - tpl_snippet2 = ''' - inputs: - cpus: - type: integer - description: Number of CPUs for the server. - constraints: - - valid_values: [ 1, 2, 4 ] - required: yes - status: supported - ''' - tpl_snippet3 = ''' - inputs: - some_list: - type: list - description: List of items - entry_schema: - type: string - default: [] - ''' - inputs1 = (toscaparser.utils.yamlparser. - simple_parse(tpl_snippet1)['inputs']) - name1, attrs1 = list(inputs1.items())[0] - inputs2 = (toscaparser.utils.yamlparser. - simple_parse(tpl_snippet2)['inputs']) - name2, attrs2 = list(inputs2.items())[0] - try: - Input(name1, attrs1) - except Exception as err: - self.assertEqual(_('Input "cpus" contains unknown field ' - '"constraint". Refer to the definition to ' - 'verify valid values.'), - err.__str__()) - input2 = Input(name2, attrs2) - self.assertTrue(input2.required) - toscaparser.utils.yamlparser.simple_parse(tpl_snippet3)['inputs'] - - def _imports_content_test(self, tpl_snippet, path, custom_type_def): - imports = (toscaparser.utils.yamlparser. - simple_parse(tpl_snippet)['imports']) - loader = ImportsLoader(imports, path, custom_type_def) - return loader.get_custom_defs() - - def test_imports_without_templates(self): - tpl_snippet = ''' - imports: - # omitted here for brevity - ''' - path = 'toscaparser/tests/data/tosca_elk.yaml' - errormsg = _('"imports" keyname is defined without including ' - 'templates.') - err = self.assertRaises(exception.ValidationError, - self._imports_content_test, - tpl_snippet, - path, - "node_types") - self.assertEqual(errormsg, err.__str__()) - - def test_imports_with_name_without_templates(self): - tpl_snippet = ''' - imports: - - some_definitions: - ''' - path = 'toscaparser/tests/data/tosca_elk.yaml' - errormsg = _('A template file name is not provided with import ' - 'definition "some_definitions".') - err = self.assertRaises(exception.ValidationError, - self._imports_content_test, - tpl_snippet, path, None) - self.assertEqual(errormsg, err.__str__()) - - def test_imports_without_import_name(self): - tpl_snippet = ''' - imports: - - custom_types/paypalpizzastore_nodejs_app.yaml - - https://raw.githubusercontent.com/openstack/\ -tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml - ''' - path = 'toscaparser/tests/data/tosca_elk.yaml' - custom_defs = self._imports_content_test(tpl_snippet, - path, - "node_types") - self.assertTrue(custom_defs) - - def test_imports_wth_import_name(self): - tpl_snippet = ''' - imports: - - some_definitions: custom_types/paypalpizzastore_nodejs_app.yaml - - more_definitions: - file: 'https://raw.githubusercontent.com/openstack/tosca-parser\ -/master/toscaparser/tests/data/custom_types/wordpress.yaml' - namespace_prefix: single_instance_wordpress - ''' - path = 'toscaparser/tests/data/tosca_elk.yaml' - custom_defs = self._imports_content_test(tpl_snippet, - path, - "node_types") - self.assertTrue(custom_defs.get("single_instance_wordpress.tosca." - "nodes.WebApplication.WordPress")) - - def test_imports_wth_namespace_prefix(self): - tpl_snippet = ''' - imports: - - more_definitions: - file: custom_types/nested_rsyslog.yaml - namespace_prefix: testprefix - ''' - path = 'toscaparser/tests/data/tosca_elk.yaml' - custom_defs = self._imports_content_test(tpl_snippet, - path, - "node_types") - self.assertTrue(custom_defs.get("testprefix.Rsyslog")) - - def test_imports_with_no_main_template(self): - tpl_snippet = ''' - imports: - - some_definitions: https://raw.githubusercontent.com/openstack/\ -tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml - - some_definitions: - file: my_defns/my_typesdefs_n.yaml - ''' - errormsg = _('Input tosca template is not provided.') - err = self.assertRaises(exception.ValidationError, - self._imports_content_test, - tpl_snippet, None, None) - self.assertEqual(errormsg, err.__str__()) - - def test_imports_duplicate_name(self): - tpl_snippet = ''' - imports: - - some_definitions: https://raw.githubusercontent.com/openstack/\ -tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml - - some_definitions: - file: my_defns/my_typesdefs_n.yaml - ''' - errormsg = _('Duplicate import name "some_definitions" was found.') - path = 'toscaparser/tests/data/tosca_elk.yaml' - err = self.assertRaises(exception.ValidationError, - self._imports_content_test, - tpl_snippet, path, None) - self.assertEqual(errormsg, err.__str__()) - - def test_imports_missing_req_field_in_def(self): - tpl_snippet = ''' - imports: - - more_definitions: - file1: my_defns/my_typesdefs_n.yaml - repository: my_company_repo - namespace_uri: http://mycompany.com/ns/tosca/2.0 - namespace_prefix: mycompany - ''' - errormsg = _('Import of template "more_definitions" is missing ' - 'required field "file".') - path = 'toscaparser/tests/data/tosca_elk.yaml' - err = self.assertRaises(exception.MissingRequiredFieldError, - self._imports_content_test, - tpl_snippet, path, None) - self.assertEqual(errormsg, err.__str__()) - - def test_imports_file_with_uri(self): - tpl_snippet = ''' - imports: - - more_definitions: - file: https://raw.githubusercontent.com/openstack/\ -tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml - ''' - path = 'https://raw.githubusercontent.com/openstack/\ -tosca-parser/master/toscaparser/tests/data/\ -tosca_single_instance_wordpress_with_url_import.yaml' - custom_defs = self._imports_content_test(tpl_snippet, - path, - "node_types") - self.assertTrue(custom_defs.get("tosca.nodes." - "WebApplication.WordPress")) - - def test_imports_file_namespace_fields(self): - tpl_snippet = ''' - imports: - - more_definitions: - file: https://raw.githubusercontent.com/openstack/\ -heat-translator/master/translator/tests/data/custom_types/wordpress.yaml - namespace_prefix: mycompany - namespace_uri: http://docs.oasis-open.org/tosca/ns/simple/yaml/1.0 - ''' - path = 'toscaparser/tests/data/tosca_elk.yaml' - custom_defs = self._imports_content_test(tpl_snippet, - path, - "node_types") - self.assertTrue(custom_defs.get("mycompany.tosca.nodes." - "WebApplication.WordPress")) - - def test_import_error_file_uri(self): - tpl_snippet = ''' - imports: - - more_definitions: - file: mycompany.com/ns/tosca/2.0/toscaparser/tests/data\ -/tosca_elk.yaml - namespace_prefix: mycompany - namespace_uri: http://docs.oasis-open.org/tosca/ns/simple/yaml/1.0 - ''' - path = 'toscaparser/tests/data/tosca_elk.yaml' - self.assertRaises(ImportError, - self._imports_content_test, - tpl_snippet, path, None) - - def test_import_single_line_error(self): - tpl_snippet = ''' - imports: - - some_definitions: abc.com/tests/data/tosca_elk.yaml - ''' - errormsg = _('Import "abc.com/tests/data/tosca_elk.yaml" is not ' - 'valid.') - path = 'toscaparser/tests/data/tosca_elk.yaml' - err = self.assertRaises(ImportError, - self._imports_content_test, - tpl_snippet, path, None) - self.assertEqual(errormsg, err.__str__()) - - def test_outputs(self): - tpl_snippet = ''' - outputs: - server_address: - description: IP address of server instance. - values: { get_property: [server, private_address] } - ''' - outputs = (toscaparser.utils.yamlparser. - simple_parse(tpl_snippet)['outputs']) - name, attrs = list(outputs.items())[0] - output = Output(name, attrs) - try: - output.validate() - except Exception as err: - self.assertTrue( - isinstance(err, exception.MissingRequiredFieldError)) - self.assertEqual(_('Output "server_address" is missing required ' - 'field "value".'), err.__str__()) - - tpl_snippet = ''' - outputs: - server_address: - descriptions: IP address of server instance. - value: { get_property: [server, private_address] } - ''' - outputs = (toscaparser.utils.yamlparser. - simple_parse(tpl_snippet)['outputs']) - name, attrs = list(outputs.items())[0] - output = Output(name, attrs) - try: - output.validate() - except Exception as err: - self.assertIsInstance(err, exception.UnknownFieldError) - self.assertEqual(_('Output "server_address" contains unknown ' - 'field "descriptions". Refer to the definition ' - 'to verify valid values.'), - err.__str__()) - - def _repo_content(self, path): - repositories = path['repositories'] - reposit = [] - for name, val in repositories.items(): - reposits = Repository(name, val) - reposit.append(reposits) - return reposit - - def test_repositories(self): - tpl_snippet = ''' - repositories: - repo_code0: https://raw.githubusercontent.com/nandinivemula/intern - repo_code1: - description: My project's code Repository in github usercontent. - url: https://github.com/nandinivemula/intern - credential: - user: nandini - password: tcs@12345 - repo_code2: - description: My Project's code Repository in github. - url: https://github.com/nandinivemula/intern - credential: - user: xyzw - password: xyz@123 - ''' - tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) - repoobject = self._repo_content(tpl) - actualrepo_names = [] - for repo in repoobject: - repos = repo.name - actualrepo_names.append(repos) - reposname = list(tpl.values()) - reposnames = reposname[0] - expected_reponames = list(reposnames.keys()) - self.assertEqual(expected_reponames, actualrepo_names) - - def test_repositories_with_missing_required_field(self): - tpl_snippet = ''' - repositories: - repo_code0: https://raw.githubusercontent.com/nandinivemula/intern - repo_code1: - description: My project's code Repository in github usercontent. - credential: - user: nandini - password: tcs@12345 - repo_code2: - description: My Project's code Repository in github. - url: https://github.com/nandinivemula/intern - credential: - user: xyzw - password: xyz@123 - ''' - tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) - err = self.assertRaises(exception.MissingRequiredFieldError, - self._repo_content, tpl) - expectedmessage = _('Repository "repo_code1" is missing ' - 'required field "url".') - self.assertEqual(expectedmessage, err.__str__()) - - def test_repositories_with_unknown_field(self): - tpl_snippet = ''' - repositories: - repo_code0: https://raw.githubusercontent.com/nandinivemula/intern - repo_code1: - description: My project's code Repository in github usercontent. - url: https://github.com/nandinivemula/intern - credential: - user: nandini - password: tcs@12345 - repo_code2: - descripton: My Project's code Repository in github. - url: https://github.com/nandinivemula/intern - credential: - user: xyzw - password: xyz@123 - ''' - tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) - err = self.assertRaises(exception.UnknownFieldError, - self._repo_content, tpl) - expectedmessage = _('repositories "repo_code2" contains unknown field' - ' "descripton". Refer to the definition to verify' - ' valid values.') - self.assertEqual(expectedmessage, err.__str__()) - - def test_repositories_with_invalid_url(self): - tpl_snippet = ''' - repositories: - repo_code0: https://raw.githubusercontent.com/nandinivemula/intern - repo_code1: - description: My project's code Repository in github usercontent. - url: h - credential: - user: nandini - password: tcs@12345 - repo_code2: - description: My Project's code Repository in github. - url: https://github.com/nandinivemula/intern - credential: - user: xyzw - password: xyz@123 - ''' - tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) - err = self.assertRaises(exception.URLException, - self._repo_content, tpl) - expectedmessage = _('repsositories "repo_code1" Invalid Url') - self.assertEqual(expectedmessage, err.__str__()) - - def test_groups(self): - tpl_snippet = ''' - node_templates: - server: - type: tosca.nodes.Compute - requirements: - - log_endpoint: - capability: log_endpoint - - mysql_dbms: - type: tosca.nodes.DBMS - properties: - root_password: aaa - port: 3376 - - groups: - webserver_group: - type: tosca.groups.Root - members: [ server, mysql_dbms ] - ''' - tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) - TopologyTemplate(tpl, None) - - def test_groups_with_missing_required_field(self): - tpl_snippet = ''' - node_templates: - server: - type: tosca.nodes.Compute - requirements: - - log_endpoint: - capability: log_endpoint - - mysql_dbms: - type: tosca.nodes.DBMS - properties: - root_password: aaa - port: 3376 - - groups: - webserver_group: - members: ['server', 'mysql_dbms'] - ''' - tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) - err = self.assertRaises(exception.MissingRequiredFieldError, - TopologyTemplate, tpl, None) - expectedmessage = _('Template "webserver_group" is missing ' - 'required field "type".') - self.assertEqual(expectedmessage, err.__str__()) - - def test_groups_with_unknown_target(self): - tpl_snippet = ''' - node_templates: - server: - type: tosca.nodes.Compute - requirements: - - log_endpoint: - capability: log_endpoint - - mysql_dbms: - type: tosca.nodes.DBMS - properties: - root_password: aaa - port: 3376 - - groups: - webserver_group: - type: tosca.groups.Root - members: [ serv, mysql_dbms ] - ''' - tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) - expectedmessage = _('"Target member "serv" is not found in ' - 'node_templates"') - err = self.assertRaises(exception.InvalidGroupTargetException, - TopologyTemplate, tpl, None) - self.assertEqual(expectedmessage, err.__str__()) - - def test_groups_with_repeated_targets(self): - tpl_snippet = ''' - node_templates: - server: - type: tosca.nodes.Compute - requirements: - - log_endpoint: - capability: log_endpoint - - mysql_dbms: - type: tosca.nodes.DBMS - properties: - root_password: aaa - port: 3376 - - groups: - webserver_group: - type: tosca.groups.Root - members: [ server, server, mysql_dbms ] - ''' - tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) - expectedmessage = _('"Member nodes ' - '"[\'server\', \'server\', \'mysql_dbms\']" ' - 'should be >= 1 and not repeated"') - err = self.assertRaises(exception.InvalidGroupTargetException, - TopologyTemplate, tpl, None) - self.assertEqual(expectedmessage, err.__str__()) - - def test_groups_with_only_one_target(self): - tpl_snippet = ''' - node_templates: - server: - type: tosca.nodes.Compute - requirements: - - log_endpoint: - capability: log_endpoint - - mysql_dbms: - type: tosca.nodes.DBMS - properties: - root_password: aaa - port: 3376 - - groups: - webserver_group: - type: tosca.groups.Root - members: [] - ''' - tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) - expectedmessage = _('"Member nodes "[]" should be >= 1 ' - 'and not repeated"') - err = self.assertRaises(exception.InvalidGroupTargetException, - TopologyTemplate, tpl, None) - self.assertEqual(expectedmessage, err.__str__()) - - def _custom_types(self): - custom_types = {} - def_file = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/custom_types/wordpress.yaml") - custom_type = toscaparser.utils.yamlparser.load_yaml(def_file) - node_types = custom_type['node_types'] - for name in node_types: - defintion = node_types[name] - custom_types[name] = defintion - return custom_types - - def _single_node_template_content_test(self, tpl_snippet): - nodetemplates = (toscaparser.utils.yamlparser. - simple_ordered_parse(tpl_snippet))['node_templates'] - name = list(nodetemplates.keys())[0] - nodetemplate = NodeTemplate(name, nodetemplates, - self._custom_types()) - nodetemplate.validate() - nodetemplate.requirements - nodetemplate.get_capabilities_objects() - nodetemplate.get_properties_objects() - nodetemplate.interfaces - - def test_node_templates(self): - tpl_snippet = ''' - node_templates: - server: - capabilities: - host: - properties: - disk_size: 10 - num_cpus: 4 - mem_size: 4096 - os: - properties: - architecture: x86_64 - type: Linux - distribution: Fedora - version: 18.0 - ''' - expectedmessage = _('Template "server" is missing required field ' - '"type".') - err = self.assertRaises( - exception.MissingRequiredFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_node_template_with_wrong_properties_keyname(self): - """Node template keyname 'properties' given as 'propertiessss'.""" - tpl_snippet = ''' - node_templates: - mysql_dbms: - type: tosca.nodes.DBMS - propertiessss: - root_password: aaa - port: 3376 - ''' - expectedmessage = _('Node template "mysql_dbms" contains unknown ' - 'field "propertiessss". Refer to the definition ' - 'to verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_node_template_with_wrong_requirements_keyname(self): - """Node template keyname 'requirements' given as 'requirement'.""" - tpl_snippet = ''' - node_templates: - mysql_dbms: - type: tosca.nodes.DBMS - properties: - root_password: aaa - port: 3376 - requirement: - - host: server - ''' - expectedmessage = _('Node template "mysql_dbms" contains unknown ' - 'field "requirement". Refer to the definition to ' - 'verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_node_template_with_wrong_interfaces_keyname(self): - """Node template keyname 'interfaces' given as 'interfac'.""" - tpl_snippet = ''' - node_templates: - mysql_dbms: - type: tosca.nodes.DBMS - properties: - root_password: aaa - port: 3376 - requirements: - - host: server - interfac: - Standard: - configure: mysql_database_configure.sh - ''' - expectedmessage = _('Node template "mysql_dbms" contains unknown ' - 'field "interfac". Refer to the definition to ' - 'verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_node_template_with_wrong_capabilities_keyname(self): - """Node template keyname 'capabilities' given as 'capabilitiis'.""" - tpl_snippet = ''' - node_templates: - mysql_database: - type: tosca.nodes.Database - properties: - db_name: { get_input: db_name } - db_user: { get_input: db_user } - db_password: { get_input: db_pwd } - capabilitiis: - database_endpoint: - properties: - port: { get_input: db_port } - ''' - expectedmessage = _('Node template "mysql_database" contains unknown ' - 'field "capabilitiis". Refer to the definition to ' - 'verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_node_template_with_wrong_artifacts_keyname(self): - """Node template keyname 'artifacts' given as 'artifactsss'.""" - tpl_snippet = ''' - node_templates: - mysql_database: - type: tosca.nodes.Database - artifactsss: - db_content: - implementation: files/my_db_content.txt - type: tosca.artifacts.File - ''' - expectedmessage = _('Node template "mysql_database" contains unknown ' - 'field "artifactsss". Refer to the definition to ' - 'verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_node_template_with_multiple_wrong_keynames(self): - """Node templates given with multiple wrong keynames.""" - tpl_snippet = ''' - node_templates: - mysql_dbms: - type: tosca.nodes.DBMS - propertieees: - root_password: aaa - port: 3376 - requirements: - - host: server - interfacs: - Standard: - configure: mysql_database_configure.sh - ''' - expectedmessage = _('Node template "mysql_dbms" contains unknown ' - 'field "propertieees". Refer to the definition to ' - 'verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - tpl_snippet = ''' - node_templates: - mysql_database: - type: tosca.nodes.Database - properties: - name: { get_input: db_name } - user: { get_input: db_user } - password: { get_input: db_pwd } - capabilitiiiies: - database_endpoint: - properties: - port: { get_input: db_port } - requirementsss: - - host: - node: mysql_dbms - interfac: - Standard: - configure: mysql_database_configure.sh - - ''' - expectedmessage = _('Node template "mysql_database" contains unknown ' - 'field "capabilitiiiies". Refer to the definition ' - 'to verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_node_template_type(self): - tpl_snippet = ''' - node_templates: - mysql_database: - type: tosca.nodes.Databases - properties: - db_name: { get_input: db_name } - db_user: { get_input: db_user } - db_password: { get_input: db_pwd } - capabilities: - database_endpoint: - properties: - port: { get_input: db_port } - requirements: - - host: mysql_dbms - interfaces: - Standard: - configure: mysql_database_configure.sh - ''' - expectedmessage = _('Type "tosca.nodes.Databases" is not ' - 'a valid type.') - err = self.assertRaises( - exception.InvalidTypeError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_node_template_requirements(self): - tpl_snippet = ''' - node_templates: - webserver: - type: tosca.nodes.WebServer - requirements: - host: server - interfaces: - Standard: - create: webserver_install.sh - start: d.sh - ''' - expectedmessage = _('"requirements" of template "webserver" must be ' - 'of type "list".') - err = self.assertRaises( - exception.TypeMismatchError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - tpl_snippet = ''' - node_templates: - mysql_database: - type: tosca.nodes.Database - properties: - db_name: { get_input: db_name } - db_user: { get_input: db_user } - db_password: { get_input: db_pwd } - capabilities: - database_endpoint: - properties: - port: { get_input: db_port } - requirements: - - host: mysql_dbms - - database_endpoint: mysql_database - interfaces: - Standard: - configure: mysql_database_configure.sh - ''' - expectedmessage = _('"requirements" of template "mysql_database" ' - 'contains unknown field "database_endpoint". ' - 'Refer to the definition to verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_node_template_requirements_with_wrong_node_keyname(self): - """Node template requirements keyname 'node' given as 'nodes'.""" - tpl_snippet = ''' - node_templates: - mysql_database: - type: tosca.nodes.Database - requirements: - - host: - nodes: mysql_dbms - - ''' - expectedmessage = _('"requirements" of template "mysql_database" ' - 'contains unknown field "nodes". Refer to the ' - 'definition to verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_node_template_requirements_with_wrong_capability_keyname(self): - """Incorrect node template requirements keyname - - Node template requirements keyname 'capability' given as - 'capabilityy'. - """ - tpl_snippet = ''' - node_templates: - mysql_database: - type: tosca.nodes.Database - requirements: - - host: - node: mysql_dbms - - log_endpoint: - node: logstash - capabilityy: log_endpoint - relationship: - type: tosca.relationships.ConnectsTo - - ''' - expectedmessage = _('"requirements" of template "mysql_database" ' - 'contains unknown field "capabilityy". Refer to ' - 'the definition to verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_node_template_requirements_with_wrong_relationship_keyname(self): - """Incorrect node template requirements keyname - - Node template requirements keyname 'relationship' given as - 'relationshipppp'. - """ - tpl_snippet = ''' - node_templates: - mysql_database: - type: tosca.nodes.Database - requirements: - - host: - node: mysql_dbms - - log_endpoint: - node: logstash - capability: log_endpoint - relationshipppp: - type: tosca.relationships.ConnectsTo - - ''' - expectedmessage = _('"requirements" of template "mysql_database" ' - 'contains unknown field "relationshipppp". Refer ' - 'to the definition to verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_node_template_requirements_with_wrong_occurrences_keyname(self): - """Incorrect node template requirements keyname - - Node template requirements keyname 'occurrences' given as - 'occurences'. - """ - tpl_snippet = ''' - node_templates: - mysql_database: - type: tosca.nodes.Database - requirements: - - host: - node: mysql_dbms - - log_endpoint: - node: logstash - capability: log_endpoint - relationship: - type: tosca.relationships.ConnectsTo - occurences: [0, UNBOUNDED] - ''' - expectedmessage = _('"requirements" of template "mysql_database" ' - 'contains unknown field "occurences". Refer to ' - 'the definition to verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_node_template_requirements_with_multiple_wrong_keynames(self): - """Node templates given with multiple wrong requirements keynames.""" - tpl_snippet = ''' - node_templates: - mysql_database: - type: tosca.nodes.Database - requirements: - - host: - node: mysql_dbms - - log_endpoint: - nod: logstash - capabilit: log_endpoint - relationshipppp: - type: tosca.relationships.ConnectsTo - - ''' - expectedmessage = _('"requirements" of template "mysql_database" ' - 'contains unknown field "nod". Refer to the ' - 'definition to verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - tpl_snippet = ''' - node_templates: - mysql_database: - type: tosca.nodes.Database - requirements: - - host: - node: mysql_dbms - - log_endpoint: - node: logstash - capabilit: log_endpoint - relationshipppp: - type: tosca.relationships.ConnectsTo - - ''' - expectedmessage = _('"requirements" of template "mysql_database" ' - 'contains unknown field "capabilit". Refer to the ' - 'definition to verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_node_template_requirements_invalid_occurrences(self): - tpl_snippet = ''' - node_templates: - server: - type: tosca.nodes.Compute - requirements: - - log_endpoint: - capability: log_endpoint - occurrences: [0, -1] - ''' - expectedmessage = _('Value of property "[0, -1]" is invalid.') - err = self.assertRaises( - exception.InvalidPropertyValueError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - tpl_snippet = ''' - node_templates: - server: - type: tosca.nodes.Compute - requirements: - - log_endpoint: - capability: log_endpoint - occurrences: [a, w] - ''' - expectedmessage = _('"a" is not an integer.') - err = self.assertRaises( - ValueError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - tpl_snippet = ''' - node_templates: - server: - type: tosca.nodes.Compute - requirements: - - log_endpoint: - capability: log_endpoint - occurrences: -1 - ''' - expectedmessage = _('"-1" is not a list.') - err = self.assertRaises( - ValueError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - tpl_snippet = ''' - node_templates: - server: - type: tosca.nodes.Compute - requirements: - - log_endpoint: - capability: log_endpoint - occurrences: [5, 1] - ''' - expectedmessage = _('Value of property "[5, 1]" is invalid.') - err = self.assertRaises( - exception.InvalidPropertyValueError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - tpl_snippet = ''' - node_templates: - server: - type: tosca.nodes.Compute - requirements: - - log_endpoint: - capability: log_endpoint - occurrences: [0, 0] - ''' - expectedmessage = _('Value of property "[0, 0]" is invalid.') - err = self.assertRaises( - exception.InvalidPropertyValueError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_node_template_requirements_valid_occurrences(self): - tpl_snippet = ''' - node_templates: - server: - type: tosca.nodes.Compute - requirements: - - log_endpoint: - capability: log_endpoint - occurrences: [2, 2] - ''' - self._single_node_template_content_test(tpl_snippet) - - def test_node_template_capabilities(self): - tpl_snippet = ''' - node_templates: - mysql_database: - type: tosca.nodes.Database - properties: - db_name: { get_input: db_name } - db_user: { get_input: db_user } - db_password: { get_input: db_pwd } - capabilities: - http_endpoint: - properties: - port: { get_input: db_port } - requirements: - - host: mysql_dbms - interfaces: - Standard: - configure: mysql_database_configure.sh - ''' - expectedmessage = _('"capabilities" of template "mysql_database" ' - 'contains unknown field "http_endpoint". Refer to ' - 'the definition to verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_node_template_properties(self): - tpl_snippet = ''' - node_templates: - server: - type: tosca.nodes.Compute - properties: - os_image: F18_x86_64 - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: cpus } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Fedora - version: 18.0 - ''' - expectedmessage = _('"properties" of template "server" contains ' - 'unknown field "os_image". Refer to the ' - 'definition to verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_node_template_interfaces(self): - tpl_snippet = ''' - node_templates: - wordpress: - type: tosca.nodes.WebApplication.WordPress - requirements: - - host: webserver - - database_endpoint: mysql_database - interfaces: - Standards: - create: wordpress_install.sh - configure: - implementation: wordpress_configure.sh - inputs: - wp_db_name: { get_property: [ mysql_database, db_name ] } - wp_db_user: { get_property: [ mysql_database, db_user ] } - wp_db_password: { get_property: [ mysql_database, \ - db_password ] } - wp_db_port: { get_property: [ SELF, \ - database_endpoint, port ] } - ''' - expectedmessage = _('"interfaces" of template "wordpress" contains ' - 'unknown field "Standards". Refer to the ' - 'definition to verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - tpl_snippet = ''' - node_templates: - wordpress: - type: tosca.nodes.WebApplication.WordPress - requirements: - - host: webserver - - database_endpoint: mysql_database - interfaces: - Standard: - create: wordpress_install.sh - config: - implementation: wordpress_configure.sh - inputs: - wp_db_name: { get_property: [ mysql_database, db_name ] } - wp_db_user: { get_property: [ mysql_database, db_user ] } - wp_db_password: { get_property: [ mysql_database, \ - db_password ] } - wp_db_port: { get_property: [ SELF, \ - database_endpoint, port ] } - ''' - expectedmessage = _('"interfaces" of template "wordpress" contains ' - 'unknown field "config". Refer to the definition ' - 'to verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - tpl_snippet = ''' - node_templates: - wordpress: - type: tosca.nodes.WebApplication.WordPress - requirements: - - host: webserver - - database_endpoint: mysql_database - interfaces: - Standard: - create: wordpress_install.sh - configure: - implementation: wordpress_configure.sh - input: - wp_db_name: { get_property: [ mysql_database, db_name ] } - wp_db_user: { get_property: [ mysql_database, db_user ] } - wp_db_password: { get_property: [ mysql_database, \ - db_password ] } - wp_db_port: { get_ref_property: [ database_endpoint, \ - database_endpoint, port ] } - ''' - expectedmessage = _('"interfaces" of template "wordpress" contains ' - 'unknown field "input". Refer to the definition ' - 'to verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_relationship_template_properties(self): - tpl_snippet = ''' - relationship_templates: - storage_attachto: - type: AttachesTo - properties: - device: test_device - ''' - expectedmessage = _('"properties" of template "storage_attachto" is ' - 'missing required field "[\'location\']".') - rel_template = (toscaparser.utils.yamlparser. - simple_parse(tpl_snippet))['relationship_templates'] - name = list(rel_template.keys())[0] - rel_template = RelationshipTemplate(rel_template[name], name) - err = self.assertRaises(exception.MissingRequiredFieldError, - rel_template.validate) - self.assertEqual(expectedmessage, six.text_type(err)) - - def test_invalid_template_version(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/test_invalid_template_version.yaml") - self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl) - valid_versions = ', '.join(ToscaTemplate.VALID_TEMPLATE_VERSIONS) - exception.ExceptionCollector.assertExceptionMessage( - exception.InvalidTemplateVersion, - (_('The template version "tosca_xyz" is invalid. Valid versions ' - 'are "%s".') % valid_versions)) - - def test_node_template_capabilities_properties(self): - # validating capability property values - tpl_snippet = ''' - node_templates: - server: - type: tosca.nodes.WebServer - capabilities: - data_endpoint: - properties: - initiator: test - ''' - expectedmessage = _('The value "test" of property "initiator" is ' - 'not valid. Expected a value from "[source, ' - 'target, peer]".') - - err = self.assertRaises( - exception.ValidationError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - tpl_snippet = ''' - node_templates: - server: - type: tosca.nodes.Compute - capabilities: - host: - properties: - disk_size: 10 GB - num_cpus: { get_input: cpus } - mem_size: 4096 MB - os: - properties: - architecture: x86_64 - type: Linux - distribution: Fedora - version: 18.0 - scalable: - properties: - min_instances: 1 - max_instances: 3 - default_instances: 5 - ''' - expectedmessage = _('"properties" of template "server": ' - '"default_instances" value is not between ' - '"min_instances" and "max_instances".') - err = self.assertRaises( - exception.ValidationError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_node_template_objectstorage_without_required_property(self): - tpl_snippet = ''' - node_templates: - server: - type: tosca.nodes.ObjectStorage - properties: - maxsize: 1 GB - ''' - expectedmessage = _('"properties" of template "server" is missing ' - 'required field "[\'name\']".') - err = self.assertRaises( - exception.MissingRequiredFieldError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_node_template_objectstorage_with_invalid_scalar_unit(self): - tpl_snippet = ''' - node_templates: - server: - type: tosca.nodes.ObjectStorage - properties: - name: test - maxsize: -1 - ''' - expectedmessage = _('"-1" is not a valid scalar-unit.') - err = self.assertRaises( - ValueError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_node_template_objectstorage_with_invalid_scalar_type(self): - tpl_snippet = ''' - node_templates: - server: - type: tosca.nodes.ObjectStorage - properties: - name: test - maxsize: 1 XB - ''' - expectedmessage = _('"1 XB" is not a valid scalar-unit.') - err = self.assertRaises( - ValueError, - lambda: self._single_node_template_content_test(tpl_snippet)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_special_keywords(self): - """Test special keywords - - Test that special keywords, e.g. metadata, which are not part - of specification do not throw any validation error. - """ - tpl_snippet_metadata_map = ''' - node_templates: - server: - type: tosca.nodes.Compute - metadata: - name: server A - role: master - ''' - self._single_node_template_content_test(tpl_snippet_metadata_map) - - tpl_snippet_metadata_inline = ''' - node_templates: - server: - type: tosca.nodes.Compute - metadata: none - ''' - self._single_node_template_content_test(tpl_snippet_metadata_inline) - - def test_policy_valid_keynames(self): - tpl_snippet = ''' - policies: - - servers_placement: - type: tosca.policies.Placement - description: Apply placement policy to servers - metadata: { user1: 1001, user2: 1002 } - targets: [ serv1, serv2 ] - ''' - policies = (toscaparser.utils.yamlparser. - simple_parse(tpl_snippet))['policies'][0] - name = list(policies.keys())[0] - Policy(name, policies[name], None, None) - - def test_policy_invalid_keyname(self): - tpl_snippet = ''' - policies: - - servers_placement: - type: tosca.policies.Placement - testkey: testvalue - ''' - policies = (toscaparser.utils.yamlparser. - simple_parse(tpl_snippet))['policies'][0] - name = list(policies.keys())[0] - - expectedmessage = _('Policy "servers_placement" contains ' - 'unknown field "testkey". Refer to the ' - 'definition to verify valid values.') - err = self.assertRaises( - exception.UnknownFieldError, - lambda: Policy(name, policies[name], None, None)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_policy_trigger_valid_keyname(self): - tpl_snippet = ''' - triggers: - - resize_compute: - description: trigger - event_type: tosca.events.resource.utilization - schedule: - start_time: "2015-05-07T07:00:00Z" - end_time: "2015-06-07T07:00:00Z" - target_filter: - node: master-container - requirement: host - capability: Container - condition: - constraint: { greater_than: 50 } - period: 60 - evaluations: 1 - method : average - action: - resize: # Operation name - inputs: - strategy: LEAST_USED - implementation: Senlin.webhook() - ''' - 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(self): - tpl_snippet = ''' - triggers: - - resize_compute: - description: trigger - event_type: tosca.events.resource.utilization - schedule: - start_time: "2015-05-07T07:00:00Z" - end_time: "2015-06-07T07:00:00Z" - target_filter1: - node: master-container - requirement: host - capability: Container - condition: - constraint: utilization greater_than 50% - period1: 60 - evaluations: 1 - method: average - action: - resize: # Operation name - inputs: - strategy: LEAST_USED - implementation: Senlin.webhook() - ''' - triggers = (toscaparser.utils.yamlparser. - simple_parse(tpl_snippet))['triggers'][0] - name = list(triggers.keys())[0] - expectedmessage = _( - 'Triggers "resize_compute" contains unknown field ' - '"target_filter1". 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: - - servers_placement: - description: test description - ''' - policies = (toscaparser.utils.yamlparser. - simple_parse(tpl_snippet))['policies'][0] - name = list(policies.keys())[0] - - expectedmessage = _('Template "servers_placement" is missing ' - 'required field "type".') - err = self.assertRaises( - exception.MissingRequiredFieldError, - lambda: Policy(name, policies[name], None, None)) - self.assertEqual(expectedmessage, err.__str__()) - - def test_credential_datatype(self): - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/test_credential_datatype.yaml") - self.assertIsNotNone(ToscaTemplate(tosca_tpl)) - - def test_invalid_default_value(self): - tpl_path = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/test_invalid_input_defaults.yaml") - self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path) - exception.ExceptionCollector.assertExceptionMessage( - ValueError, _('"two" is not an integer.')) - - def test_invalid_capability(self): - tpl_snippet = ''' - node_templates: - server: - type: tosca.nodes.Compute - capabilities: - oss: - properties: - architecture: x86_64 - ''' - tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) - err = self.assertRaises(exception.UnknownFieldError, - TopologyTemplate, tpl, None) - expectedmessage = _('"capabilities" of template "server" contains ' - 'unknown field "oss". Refer to the definition ' - 'to verify valid values.') - self.assertEqual(expectedmessage, err.__str__()) - - def test_qualified_name(self): - tpl_snippet_full_name = ''' - node_templates: - supported_type: - type: tosca.nodes.Compute - ''' - tpl = ( - toscaparser.utils.yamlparser.simple_parse( - tpl_snippet_full_name)) - TopologyTemplate(tpl, None) - - tpl_snippet_short_name = ''' - node_templates: - supported_type: - type: Compute - ''' - tpl = ( - toscaparser.utils.yamlparser.simple_parse( - tpl_snippet_short_name)) - TopologyTemplate(tpl, None) - - tpl_snippet_qualified_name = ''' - node_templates: - supported_type: - type: tosca:Compute - ''' - tpl = ( - toscaparser.utils.yamlparser.simple_parse( - tpl_snippet_qualified_name)) - TopologyTemplate(tpl, None) - - def test_requirements_as_list(self): - """Node template with requirements provided with or without list - - Node template requirements are required to be provided as list. - """ - - expectedmessage = _('"requirements" of template "my_webserver"' - ' must be of type "list".') - - # requirements provided as dictionary - tpl_snippet1 = ''' - node_templates: - my_webserver: - type: tosca.nodes.WebServer - requirements: - host: server - server: - type: tosca.nodes.Compute - ''' - err1 = self.assertRaises( - exception.TypeMismatchError, - lambda: self._single_node_template_content_test(tpl_snippet1)) - self.assertEqual(expectedmessage, err1.__str__()) - - # requirements provided as string - tpl_snippet2 = ''' - node_templates: - my_webserver: - type: tosca.nodes.WebServer - requirements: server - server: - type: tosca.nodes.Compute - ''' - err2 = self.assertRaises( - exception.TypeMismatchError, - lambda: self._single_node_template_content_test(tpl_snippet2)) - self.assertEqual(expectedmessage, err2.__str__()) - - # requirements provided as list - tpl_snippet3 = ''' - node_templates: - my_webserver: - type: tosca.nodes.WebServer - requirements: - - host: server - server: - type: tosca.nodes.Compute - ''' - self.assertIsNone( - self._single_node_template_content_test(tpl_snippet3)) - - def test_properties_override_with_flavor_and_image(self): - tpl_path = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "data/test_normative_type_properties_override.yaml") - self.assertIsNotNone(ToscaTemplate(tpl_path)) diff --git a/nfvparser/src/main/python/toscaparser/tests/test_utils.py b/nfvparser/src/main/python/toscaparser/tests/test_utils.py deleted file mode 100644 index fca024d..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/test_utils.py +++ /dev/null @@ -1,48 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from toscaparser.tests.base import TestCase -import toscaparser.utils.urlutils -import toscaparser.utils.yamlparser - -YAML_LOADER = toscaparser.utils.yamlparser.load_yaml - - -class UrlUtilsTest(TestCase): - - url_utils = toscaparser.utils.urlutils.UrlUtils - - def test_urlutils_validate_url(self): - self.assertTrue(self.url_utils.validate_url("http://www.github.com/")) - self.assertTrue( - self.url_utils.validate_url("https://github.com:81/a/2/a.b")) - self.assertTrue(self.url_utils.validate_url("ftp://github.com")) - self.assertFalse(self.url_utils.validate_url("github.com")) - self.assertFalse(self.url_utils.validate_url("123")) - self.assertFalse(self.url_utils.validate_url("a/b/c")) - self.assertTrue(self.url_utils.validate_url("file:///dir/file.ext")) - - def test_urlutils_join_url(self): - self.assertEqual( - self.url_utils.join_url("http://github.com/proj1", "proj2"), - "http://github.com/proj2") - self.assertEqual( - self.url_utils.join_url("http://github.com/proj1/scripts/a.js", - "b.js"), - "http://github.com/proj1/scripts/b.js") - self.assertEqual( - self.url_utils.join_url("http://github.com/proj1/scripts", "b.js"), - "http://github.com/proj1/b.js") - self.assertEqual( - self.url_utils.join_url("http://github.com/proj1/scripts", - "scripts/b.js"), - "http://github.com/proj1/scripts/b.js") diff --git a/nfvparser/src/main/python/toscaparser/tests/test_validate_tosca_version.py b/nfvparser/src/main/python/toscaparser/tests/test_validate_tosca_version.py deleted file mode 100644 index e9a8ac2..0000000 --- a/nfvparser/src/main/python/toscaparser/tests/test_validate_tosca_version.py +++ /dev/null @@ -1,132 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -from toscaparser.common.exception import ( - InvalidTOSCAVersionPropertyException) -from toscaparser.tests.base import TestCase -from toscaparser.utils.gettextutils import _ -from toscaparser.utils.validateutils import TOSCAVersionProperty - - -class TOSCAVersionPropertyTest(TestCase): - - def test_tosca_version_property(self): - version = '18.0.3.beta-1' - expected_output = '18.0.3.beta-1' - output = TOSCAVersionProperty(version).get_version() - self.assertEqual(output, expected_output) - - version = 18 - expected_output = '18.0' - output = TOSCAVersionProperty(version).get_version() - self.assertEqual(output, expected_output) - - version = 18.0 - expected_output = '18.0' - output = TOSCAVersionProperty(version).get_version() - self.assertEqual(output, expected_output) - - version = '18.0.3' - expected_output = '18.0.3' - output = TOSCAVersionProperty(version).get_version() - self.assertEqual(output, expected_output) - - version = 0 - expected_output = None - output = TOSCAVersionProperty(version).get_version() - self.assertEqual(output, expected_output) - - version = 00 - expected_output = None - output = TOSCAVersionProperty(version).get_version() - self.assertEqual(output, expected_output) - - version = 0.0 - expected_output = None - output = TOSCAVersionProperty(version).get_version() - self.assertEqual(output, expected_output) - - version = 00.00 - expected_output = None - output = TOSCAVersionProperty(version).get_version() - self.assertEqual(output, expected_output) - - version = '0.0.0' - expected_output = None - output = TOSCAVersionProperty(version).get_version() - self.assertEqual(output, expected_output) - - def test_tosca_version_property_invalid_major_version(self): - - version = 'x' - exp_msg = _('Value of TOSCA version property "x" is invalid.') - err = self.assertRaises(InvalidTOSCAVersionPropertyException, - TOSCAVersionProperty, version) - self.assertEqual(exp_msg, err.__str__()) - - def test_tosca_version_property_invalid_minor_version(self): - - version = '18.x' - exp_msg = _('Value of TOSCA version property "18.x" is invalid.') - err = self.assertRaises(InvalidTOSCAVersionPropertyException, - TOSCAVersionProperty, version) - self.assertEqual(exp_msg, err.__str__()) - - version = '18.x.y' - exp_msg = _('Value of TOSCA version property "18.x.y" is invalid.') - err = self.assertRaises(InvalidTOSCAVersionPropertyException, - TOSCAVersionProperty, version) - self.assertEqual(exp_msg, err.__str__()) - - version = '18-2' - exp_msg = _('Value of TOSCA version property "18-2" is invalid.') - err = self.assertRaises(InvalidTOSCAVersionPropertyException, - TOSCAVersionProperty, version) - self.assertEqual(exp_msg, err.__str__()) - - def test_tosca_version_property_invalid_fix_version(self): - - version = '18.0.a' - exp_msg = _('Value of TOSCA version property "18.0.a" is invalid.') - err = self.assertRaises(InvalidTOSCAVersionPropertyException, - TOSCAVersionProperty, version) - self.assertEqual(exp_msg, err.__str__()) - - def test_tosca_version_property_invalid_qualifier(self): - - version = '18.0.1-xyz' - exp_msg = _('Value of TOSCA version property "18.0.1-xyz" is invalid.') - err = self.assertRaises(InvalidTOSCAVersionPropertyException, - TOSCAVersionProperty, version) - self.assertEqual(exp_msg, err.__str__()) - - version = '0.0.0.abc' - exp_msg = _('Value of TOSCA version property "0.0.0.abc" is invalid.') - err = self.assertRaises(InvalidTOSCAVersionPropertyException, - TOSCAVersionProperty, version) - self.assertEqual(exp_msg, err.__str__()) - - def test_tosca_version_property_invalid_build_version(self): - - version = '18.0.1.abc-x' - exp_msg = _('Value of TOSCA version property ' - '"18.0.1.abc-x" is invalid.') - err = self.assertRaises(InvalidTOSCAVersionPropertyException, - TOSCAVersionProperty, version) - self.assertEqual(exp_msg, err.__str__()) - - version = '0.0.0.abc-x' - exp_msg = _('Value of TOSCA version property "0.0.0.abc-x" is ' - 'invalid.') - err = self.assertRaises(InvalidTOSCAVersionPropertyException, - TOSCAVersionProperty, version) - self.assertEqual(exp_msg, err.__str__()) diff --git a/nfvparser/src/main/python/toscaparser/topology_template.py b/nfvparser/src/main/python/toscaparser/topology_template.py deleted file mode 100644 index 4571fe7..0000000 --- a/nfvparser/src/main/python/toscaparser/topology_template.py +++ /dev/null @@ -1,310 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - - -import logging - -from toscaparser.common import exception -from toscaparser.dataentity import DataEntity -from toscaparser import functions -from toscaparser.groups import Group -from toscaparser.nodetemplate import NodeTemplate -from toscaparser.parameters import Input -from toscaparser.parameters import Output -from toscaparser.policy import Policy -from toscaparser.relationship_template import RelationshipTemplate -from toscaparser.substitution_mappings import SubstitutionMappings -from toscaparser.tpl_relationship_graph import ToscaGraph -from toscaparser.utils.gettextutils import _ - - -# Topology template key names -SECTIONS = (DESCRIPTION, INPUTS, NODE_TEMPLATES, - RELATIONSHIP_TEMPLATES, OUTPUTS, GROUPS, - SUBSTITUION_MAPPINGS, POLICIES) = \ - ('description', 'inputs', 'node_templates', - 'relationship_templates', 'outputs', 'groups', - 'substitution_mappings', 'policies') - -log = logging.getLogger("tosca.model") - - -class TopologyTemplate(object): - - '''Load the template data.''' - def __init__(self, template, custom_defs, - rel_types=None, parsed_params=None, - sub_mapped_node_template=None): - self.tpl = template - self.sub_mapped_node_template = sub_mapped_node_template - if self.tpl: - self.custom_defs = custom_defs - self.rel_types = rel_types - self.parsed_params = parsed_params - self._validate_field() - self.description = self._tpl_description() - self.inputs = self._inputs() - self.relationship_templates = self._relationship_templates() - self.nodetemplates = self._nodetemplates() - self.outputs = self._outputs() - if hasattr(self, 'nodetemplates'): - self.graph = ToscaGraph(self.nodetemplates) - self.groups = self._groups() - self.policies = self._policies() - self._process_intrinsic_functions() - self.substitution_mappings = self._substitution_mappings() - - def _inputs(self): - inputs = [] - for name, attrs in self._tpl_inputs().items(): - input = Input(name, attrs) - if self.parsed_params and name in self.parsed_params: - input.validate(self.parsed_params[name]) - else: - default = input.default - if default: - input.validate(default) - if (self.parsed_params and input.name not in self.parsed_params - or self.parsed_params is None) and input.required \ - and input.default is None: - exception.ExceptionCollector.appendException( - exception.MissingRequiredParameterError( - what='Template', - input_name=input.name)) - - inputs.append(input) - return inputs - - def _nodetemplates(self): - nodetemplates = [] - tpls = self._tpl_nodetemplates() - if tpls: - for name in tpls: - tpl = NodeTemplate(name, tpls, self.custom_defs, - self.relationship_templates, - self.rel_types) - if (tpl.type_definition and - (tpl.type in tpl.type_definition.TOSCA_DEF or - (tpl.type not in tpl.type_definition.TOSCA_DEF and - bool(tpl.custom_def)))): - tpl.validate(self) - nodetemplates.append(tpl) - return nodetemplates - - def _relationship_templates(self): - rel_templates = [] - tpls = self._tpl_relationship_templates() - for name in tpls: - tpl = RelationshipTemplate(tpls[name], name, self.custom_defs) - rel_templates.append(tpl) - return rel_templates - - def _outputs(self): - outputs = [] - for name, attrs in self._tpl_outputs().items(): - output = Output(name, attrs) - output.validate() - outputs.append(output) - return outputs - - def _substitution_mappings(self): - tpl_substitution_mapping = self._tpl_substitution_mappings() - # if tpl_substitution_mapping and self.sub_mapped_node_template: - if tpl_substitution_mapping: - return SubstitutionMappings(tpl_substitution_mapping, - self.nodetemplates, - self.inputs, - self.outputs, - self.sub_mapped_node_template, - self.custom_defs) - - def _policies(self): - policies = [] - for policy in self._tpl_policies(): - for policy_name, policy_tpl in policy.items(): - target_list = policy_tpl.get('targets') - target_objects = [] - targets_type = "groups" - if target_list and len(target_list) >= 1: - target_objects = self._get_policy_groups(target_list) - if not target_objects: - targets_type = "node_templates" - target_objects = self._get_group_members(target_list) - policyObj = Policy(policy_name, policy_tpl, - target_objects, targets_type, - self.custom_defs) - policies.append(policyObj) - return policies - - def _groups(self): - groups = [] - member_nodes = None - for group_name, group_tpl in self._tpl_groups().items(): - member_names = group_tpl.get('members') - if member_names is not None: - DataEntity.validate_datatype('list', member_names) - if len(member_names) < 1 or \ - len(member_names) != len(set(member_names)): - exception.ExceptionCollector.appendException( - exception.InvalidGroupTargetException( - message=_('Member nodes "%s" should be >= 1 ' - 'and not repeated') % member_names)) - else: - member_nodes = self._get_group_members(member_names) - group = Group(group_name, group_tpl, - member_nodes, - self.custom_defs) - groups.append(group) - return groups - - def _get_group_members(self, member_names): - member_nodes = [] - self._validate_group_members(member_names) - for member in member_names: - for node in self.nodetemplates: - if node.name == member: - member_nodes.append(node) - return member_nodes - - def _get_policy_groups(self, member_names): - member_groups = [] - for member in member_names: - for group in self.groups: - if group.name == member: - member_groups.append(group) - return member_groups - - def _validate_group_members(self, members): - node_names = [] - for node in self.nodetemplates: - node_names.append(node.name) - for member in members: - if member not in node_names: - exception.ExceptionCollector.appendException( - exception.InvalidGroupTargetException( - message=_('Target member "%s" is not found in ' - 'node_templates') % member)) - - # topology template can act like node template - # it is exposed by substitution_mappings. - def nodetype(self): - return self.substitution_mappings.node_type \ - if self.substitution_mappings else None - - def capabilities(self): - return self.substitution_mappings.capabilities \ - if self.substitution_mappings else None - - def requirements(self): - return self.substitution_mappings.requirements \ - if self.substitution_mappings else None - - def _tpl_description(self): - description = self.tpl.get(DESCRIPTION) - if description: - return description.rstrip() - - def _tpl_inputs(self): - return self.tpl.get(INPUTS) or {} - - def _tpl_nodetemplates(self): - return self.tpl.get(NODE_TEMPLATES) - - def _tpl_relationship_templates(self): - return self.tpl.get(RELATIONSHIP_TEMPLATES) or {} - - def _tpl_outputs(self): - return self.tpl.get(OUTPUTS) or {} - - def _tpl_substitution_mappings(self): - return self.tpl.get(SUBSTITUION_MAPPINGS) or {} - - def _tpl_groups(self): - return self.tpl.get(GROUPS) or {} - - def _tpl_policies(self): - return self.tpl.get(POLICIES) or {} - - def _validate_field(self): - for name in self.tpl: - if name not in SECTIONS: - exception.ExceptionCollector.appendException( - exception.UnknownFieldError(what='Template', field=name)) - - def _process_intrinsic_functions(self): - """Process intrinsic functions - - Current implementation processes functions within node template - properties, requirements, interfaces inputs and template outputs. - """ - if hasattr(self, 'nodetemplates'): - for node_template in self.nodetemplates: - for prop in node_template.get_properties_objects(): - prop.value = functions.get_function(self, - node_template, - prop.value) - for interface in node_template.interfaces: - if interface.inputs: - for name, value in interface.inputs.items(): - interface.inputs[name] = functions.get_function( - self, - node_template, - value) - if node_template.requirements and \ - isinstance(node_template.requirements, list): - for req in node_template.requirements: - rel = req - for req_name, req_item in req.items(): - if isinstance(req_item, dict): - rel = req_item.get('relationship') - break - if rel and 'properties' in rel: - for key, value in rel['properties'].items(): - rel['properties'][key] = \ - functions.get_function(self, - req, - value) - if node_template.get_capabilities_objects(): - for cap in node_template.get_capabilities_objects(): - if cap.get_properties_objects(): - for prop in cap.get_properties_objects(): - propvalue = functions.get_function( - self, - node_template, - prop.value) - if isinstance(propvalue, functions.GetInput): - propvalue = propvalue.result() - for p, v in cap._properties.items(): - if p == prop.name: - cap._properties[p] = propvalue - for rel, node in node_template.relationships.items(): - rel_tpls = node.relationship_tpl - if rel_tpls: - for rel_tpl in rel_tpls: - for interface in rel_tpl.interfaces: - if interface.inputs: - for name, value in \ - interface.inputs.items(): - interface.inputs[name] = \ - functions.get_function(self, - rel_tpl, - value) - for output in self.outputs: - func = functions.get_function(self, self.outputs, output.value) - if isinstance(func, functions.GetAttribute): - output.attrs[output.VALUE] = func - - @classmethod - def get_sub_mapping_node_type(cls, topology_tpl): - if topology_tpl and isinstance(topology_tpl, dict): - submap_tpl = topology_tpl.get(SUBSTITUION_MAPPINGS) - return SubstitutionMappings.get_node_type(submap_tpl) diff --git a/nfvparser/src/main/python/toscaparser/tosca_template.py b/nfvparser/src/main/python/toscaparser/tosca_template.py deleted file mode 100644 index f48078f..0000000 --- a/nfvparser/src/main/python/toscaparser/tosca_template.py +++ /dev/null @@ -1,344 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - - -import logging -import os - -from copy import deepcopy -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import InvalidTemplateVersion -from toscaparser.common.exception import MissingRequiredFieldError -from toscaparser.common.exception import UnknownFieldError -from toscaparser.common.exception import ValidationError -from toscaparser.elements.entity_type import update_definitions -from toscaparser.extensions.exttools import ExtTools -import toscaparser.imports -from toscaparser.prereq.csar import CSAR -from toscaparser.repositories import Repository -from toscaparser.topology_template import TopologyTemplate -from toscaparser.tpl_relationship_graph import ToscaGraph -from toscaparser.utils.gettextutils import _ -import toscaparser.utils.yamlparser - - -# TOSCA template key names -SECTIONS = (DEFINITION_VERSION, DEFAULT_NAMESPACE, TEMPLATE_NAME, - TOPOLOGY_TEMPLATE, TEMPLATE_AUTHOR, TEMPLATE_VERSION, - DESCRIPTION, IMPORTS, DSL_DEFINITIONS, NODE_TYPES, - RELATIONSHIP_TYPES, RELATIONSHIP_TEMPLATES, - CAPABILITY_TYPES, ARTIFACT_TYPES, DATA_TYPES, INTERFACE_TYPES, - POLICY_TYPES, GROUP_TYPES, REPOSITORIES) = \ - ('tosca_definitions_version', 'tosca_default_namespace', - 'template_name', 'topology_template', 'template_author', - 'template_version', 'description', 'imports', 'dsl_definitions', - 'node_types', 'relationship_types', 'relationship_templates', - 'capability_types', 'artifact_types', 'data_types', - 'interface_types', 'policy_types', 'group_types', 'repositories') -# Sections that are specific to individual template definitions -SPECIAL_SECTIONS = (METADATA) = ('metadata') - -log = logging.getLogger("tosca.model") - -YAML_LOADER = toscaparser.utils.yamlparser.load_yaml - - -class ToscaTemplate(object): - exttools = ExtTools() - - VALID_TEMPLATE_VERSIONS = ['tosca_simple_yaml_1_0'] - - VALID_TEMPLATE_VERSIONS.extend(exttools.get_versions()) - - ADDITIONAL_SECTIONS = {'tosca_simple_yaml_1_0': SPECIAL_SECTIONS} - - ADDITIONAL_SECTIONS.update(exttools.get_sections()) - - '''Load the template data.''' - def __init__(self, path=None, parsed_params=None, a_file=True, - yaml_dict_tpl=None, sub_mapped_node_template=None): - if sub_mapped_node_template is None: - ExceptionCollector.start() - self.a_file = a_file - self.input_path = None - self.path = None - self.tpl = None - self.sub_mapped_node_template = sub_mapped_node_template - self.nested_tosca_tpls_with_topology = {} - self.nested_tosca_templates_with_topology = [] - if path: - self.input_path = path - self.path = self._get_path(path) - if self.path: - self.tpl = YAML_LOADER(self.path, self.a_file) - if yaml_dict_tpl: - msg = (_('Both path and yaml_dict_tpl arguments were ' - 'provided. Using path and ignoring yaml_dict_tpl.')) - log.info(msg) - print(msg) - else: - if yaml_dict_tpl: - self.tpl = yaml_dict_tpl - else: - ExceptionCollector.appendException( - ValueError(_('No path or yaml_dict_tpl was provided. ' - 'There is nothing to parse.'))) - - if self.tpl: - self.parsed_params = parsed_params - self._validate_field() - self.version = self._tpl_version() - self.relationship_types = self._tpl_relationship_types() - self.description = self._tpl_description() - self.topology_template = self._topology_template() - self.repositories = self._tpl_repositories() - if self.topology_template.tpl: - self.inputs = self._inputs() - self.relationship_templates = self._relationship_templates() - self.nodetemplates = self._nodetemplates() - self.outputs = self._outputs() - self.policies = self._policies() - self._handle_nested_tosca_templates_with_topology() - self.graph = ToscaGraph(self.nodetemplates) - - if sub_mapped_node_template is None: - ExceptionCollector.stop() - self.verify_template() - - def _topology_template(self): - return TopologyTemplate(self._tpl_topology_template(), - self._get_all_custom_defs(), - self.relationship_types, - self.parsed_params, - self.sub_mapped_node_template) - - def _inputs(self): - return self.topology_template.inputs - - def _nodetemplates(self): - return self.topology_template.nodetemplates - - def _relationship_templates(self): - return self.topology_template.relationship_templates - - def _outputs(self): - return self.topology_template.outputs - - def _tpl_version(self): - return self.tpl.get(DEFINITION_VERSION) - - def _tpl_description(self): - desc = self.tpl.get(DESCRIPTION) - if desc: - return desc.rstrip() - - def _tpl_imports(self): - return self.tpl.get(IMPORTS) - - def _tpl_repositories(self): - repositories = self.tpl.get(REPOSITORIES) - reposit = [] - if repositories: - for name, val in repositories.items(): - reposits = Repository(name, val) - reposit.append(reposits) - return reposit - - def _tpl_relationship_types(self): - return self._get_custom_types(RELATIONSHIP_TYPES) - - def _tpl_relationship_templates(self): - topology_template = self._tpl_topology_template() - return topology_template.get(RELATIONSHIP_TEMPLATES) - - def _tpl_topology_template(self): - return self.tpl.get(TOPOLOGY_TEMPLATE) - - def _policies(self): - return self.topology_template.policies - - def _get_all_custom_defs(self, imports=None): - types = [IMPORTS, NODE_TYPES, CAPABILITY_TYPES, RELATIONSHIP_TYPES, - DATA_TYPES, INTERFACE_TYPES, POLICY_TYPES, GROUP_TYPES] - custom_defs_final = {} - custom_defs = self._get_custom_types(types, imports) - if custom_defs: - custom_defs_final.update(custom_defs) - if custom_defs.get(IMPORTS): - import_defs = self._get_all_custom_defs( - custom_defs.get(IMPORTS)) - custom_defs_final.update(import_defs) - - # As imports are not custom_types, removing from the dict - custom_defs_final.pop(IMPORTS, None) - return custom_defs_final - - def _get_custom_types(self, type_definitions, imports=None): - """Handle custom types defined in imported template files - - This method loads the custom type definitions referenced in "imports" - section of the TOSCA YAML template. - """ - - custom_defs = {} - type_defs = [] - if not isinstance(type_definitions, list): - type_defs.append(type_definitions) - else: - type_defs = type_definitions - - if not imports: - imports = self._tpl_imports() - - if imports: - custom_service = toscaparser.imports.\ - ImportsLoader(imports, self.path, - type_defs, self.tpl) - - nested_tosca_tpls = custom_service.get_nested_tosca_tpls() - self._update_nested_tosca_tpls_with_topology(nested_tosca_tpls) - - custom_defs = custom_service.get_custom_defs() - if not custom_defs: - return - - # Handle custom types defined in current template file - for type_def in type_defs: - if type_def != IMPORTS: - inner_custom_types = self.tpl.get(type_def) or {} - if inner_custom_types: - custom_defs.update(inner_custom_types) - return custom_defs - - def _update_nested_tosca_tpls_with_topology(self, nested_tosca_tpls): - for tpl in nested_tosca_tpls: - filename, tosca_tpl = list(tpl.items())[0] - if (tosca_tpl.get(TOPOLOGY_TEMPLATE) and - filename not in list( - self.nested_tosca_tpls_with_topology.keys())): - self.nested_tosca_tpls_with_topology.update(tpl) - - def _handle_nested_tosca_templates_with_topology(self): - for fname, tosca_tpl in self.nested_tosca_tpls_with_topology.items(): - for nodetemplate in self.nodetemplates: - if self._is_sub_mapped_node(nodetemplate, tosca_tpl): - parsed_params = self._get_params_for_nested_template( - nodetemplate) - nested_template = ToscaTemplate( - path=fname, parsed_params=parsed_params, - yaml_dict_tpl=tosca_tpl, - sub_mapped_node_template=nodetemplate) - if nested_template._has_substitution_mappings(): - # Record the nested templates in top level template - self.nested_tosca_templates_with_topology.\ - append(nested_template) - # Set the substitution toscatemplate for mapped node - nodetemplate.sub_mapping_tosca_template = \ - nested_template - - def _validate_field(self): - version = self._tpl_version() - if not version: - ExceptionCollector.appendException( - MissingRequiredFieldError(what='Template', - required=DEFINITION_VERSION)) - else: - self._validate_version(version) - self.version = version - - for name in self.tpl: - if (name not in SECTIONS and - name not in self.ADDITIONAL_SECTIONS.get(version, ())): - ExceptionCollector.appendException( - UnknownFieldError(what='Template', field=name)) - - def _validate_version(self, version): - if version not in self.VALID_TEMPLATE_VERSIONS: - ExceptionCollector.appendException( - InvalidTemplateVersion( - what=version, - valid_versions=', '. join(self.VALID_TEMPLATE_VERSIONS))) - else: - if version != 'tosca_simple_yaml_1_0': - update_definitions(version) - - def _get_path(self, path): - if path.lower().endswith('.yaml'): - return path - elif path.lower().endswith(('.zip', '.csar')): - # a CSAR archive - csar = CSAR(path, self.a_file) - if csar.validate(): - csar.decompress() - self.a_file = True # the file has been decompressed locally - return os.path.join(csar.temp_dir, csar.get_main_template()) - else: - ExceptionCollector.appendException( - ValueError(_('"%(path)s" is not a valid file.') - % {'path': path})) - - def verify_template(self): - if ExceptionCollector.exceptionsCaught(): - if self.input_path: - raise ValidationError( - message=(_('\nThe input "%(path)s" failed validation with ' - 'the following error(s): \n\n\t') - % {'path': self.input_path}) + - '\n\t'.join(ExceptionCollector.getExceptionsReport())) - else: - raise ValidationError( - message=_('\nThe pre-parsed input failed validation with ' - 'the following error(s): \n\n\t') + - '\n\t'.join(ExceptionCollector.getExceptionsReport())) - else: - if self.input_path: - msg = (_('The input "%(path)s" successfully passed ' - 'validation.') % {'path': self.input_path}) - else: - msg = _('The pre-parsed input successfully passed validation.') - - log.info(msg) - - def _is_sub_mapped_node(self, nodetemplate, tosca_tpl): - """Return True if the nodetemple is substituted.""" - if (nodetemplate and not nodetemplate.substitution_mapped and - self.get_sub_mapping_node_type(tosca_tpl) == nodetemplate.type - and len(nodetemplate.interfaces) < 1): - return True - else: - return False - - def _get_params_for_nested_template(self, nodetemplate): - """Return total params for nested_template.""" - parsed_params = deepcopy(self.parsed_params) \ - if self.parsed_params else {} - if nodetemplate: - for pname in nodetemplate.get_properties(): - parsed_params.update({pname: - nodetemplate.get_property_value(pname)}) - return parsed_params - - def get_sub_mapping_node_type(self, tosca_tpl): - """Return substitution mappings node type.""" - if tosca_tpl: - return TopologyTemplate.get_sub_mapping_node_type( - tosca_tpl.get(TOPOLOGY_TEMPLATE)) - - def _has_substitution_mappings(self): - """Return True if the template has valid substitution mappings.""" - return self.topology_template is not None and \ - self.topology_template.substitution_mappings is not None - - def has_nested_templates(self): - """Return True if the tosca template has nested templates.""" - return self.nested_tosca_templates_with_topology is not None and \ - len(self.nested_tosca_templates_with_topology) >= 1 diff --git a/nfvparser/src/main/python/toscaparser/tpl_relationship_graph.py b/nfvparser/src/main/python/toscaparser/tpl_relationship_graph.py deleted file mode 100644 index 1a5ea7b..0000000 --- a/nfvparser/src/main/python/toscaparser/tpl_relationship_graph.py +++ /dev/null @@ -1,46 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - - -class ToscaGraph(object): - '''Graph of Tosca Node Templates.''' - def __init__(self, nodetemplates): - self.nodetemplates = nodetemplates - self.vertices = {} - self._create() - - def _create_vertex(self, node): - if node not in self.vertices: - self.vertices[node.name] = node - - def _create_edge(self, node1, node2, relationship): - if node1 not in self.vertices: - self._create_vertex(node1) - self.vertices[node1.name]._add_next(node2, - relationship) - - def vertex(self, node): - if node in self.vertices: - return self.vertices[node] - - def __iter__(self): - return iter(self.vertices.values()) - - def _create(self): - for node in self.nodetemplates: - relation = node.relationships - if relation: - for rel, nodetpls in relation.items(): - for tpl in self.nodetemplates: - if tpl.name == nodetpls.name: - self._create_edge(node, tpl, rel) - self._create_vertex(node) diff --git a/nfvparser/src/main/python/toscaparser/triggers.py b/nfvparser/src/main/python/toscaparser/triggers.py deleted file mode 100644 index 9edeef4..0000000 --- a/nfvparser/src/main/python/toscaparser/triggers.py +++ /dev/null @@ -1,68 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - - -import logging - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import UnknownFieldError -from toscaparser.entity_template import EntityTemplate - -SECTIONS = (DESCRIPTION, EVENT, SCHEDULE, TARGET_FILTER, CONDITION, ACTION) = \ - ('description', 'event_type', 'schedule', - 'target_filter', 'condition', 'action') -CONDITION_KEYNAMES = (CONTRAINT, PERIOD, EVALUATIONS, METHOD) = \ - ('constraint', 'period', 'evaluations', 'method') -log = logging.getLogger('tosca') - - -class Triggers(EntityTemplate): - - '''Triggers defined in policies of topology template''' - - def __init__(self, name, trigger_tpl): - self.name = name - self.trigger_tpl = trigger_tpl - self._validate_keys() - self._validate_condition() - - def get_description(self): - return self.trigger_tpl['description'] - - def get_event(self): - return self.trigger_tpl['event_type'] - - def get_schedule(self): - return self.trigger_tpl['schedule'] - - def get_target_filter(self): - return self.trigger_tpl['target_filter'] - - def get_condition(self): - return self.trigger_tpl['condition'] - - def get_action(self): - return self.trigger_tpl['action'] - - def _validate_keys(self): - for key in self.trigger_tpl.keys(): - if key not in SECTIONS: - ExceptionCollector.appendException( - UnknownFieldError(what='Triggers "%s"' % self.name, - field=key)) - - def _validate_condition(self): - for key in self.get_condition(): - if key not in CONDITION_KEYNAMES: - ExceptionCollector.appendException( - UnknownFieldError(what='Triggers "%s"' % self.name, - field=key)) diff --git a/nfvparser/src/main/python/toscaparser/unsupportedtype.py b/nfvparser/src/main/python/toscaparser/unsupportedtype.py deleted file mode 100644 index a0c11f0..0000000 --- a/nfvparser/src/main/python/toscaparser/unsupportedtype.py +++ /dev/null @@ -1,50 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. -import logging - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import UnsupportedTypeError -from toscaparser.utils.gettextutils import _ - -log = logging.getLogger('tosca') - - -class UnsupportedType(object): - - """Note: TOSCA spec version related - - The tosca.nodes.Storage.ObjectStorage and tosca.nodes.Storage.BlockStorage - used here as un_supported_types are part of the name changes in TOSCA spec - version 1.1. The original name as specified in version 1.0 are, - tosca.nodes.BlockStorage and tosca.nodes.ObjectStorage which are supported - by the tosca-parser. Since there are little overlapping in version support - currently in the tosca-parser, the names tosca.nodes.Storage.ObjectStorage - and tosca.nodes.Storage.BlockStorage are used here to demonstrate the usage - of un_supported_types. As tosca-parser move to provide support for version - 1.1 and higher, they will be removed. - """ - un_supported_types = ['tosca.test.invalidtype', - 'tosca.nodes.Storage.ObjectStorage', - 'tosca.nodes.Storage.BlockStorage'] - - def __init__(self): - pass - - @staticmethod - def validate_type(entitytype): - if entitytype in UnsupportedType.un_supported_types: - ExceptionCollector.appendException(UnsupportedTypeError( - what=_('%s') - % entitytype)) - return True - else: - return False diff --git a/nfvparser/src/main/python/toscaparser/utils/__init__.py b/nfvparser/src/main/python/toscaparser/utils/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/nfvparser/src/main/python/toscaparser/utils/gettextutils.py b/nfvparser/src/main/python/toscaparser/utils/gettextutils.py deleted file mode 100644 index d631ac8..0000000 --- a/nfvparser/src/main/python/toscaparser/utils/gettextutils.py +++ /dev/null @@ -1,23 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import gettext -import os - -_localedir = os.environ.get('tosca-parser'.upper() + '_LOCALEDIR') -_t = gettext.translation('tosca-parser', localedir=_localedir, - fallback=True) - - -def _(msg): - # type: (object) -> object - return _t.gettext(msg) diff --git a/nfvparser/src/main/python/toscaparser/utils/urlutils.py b/nfvparser/src/main/python/toscaparser/utils/urlutils.py deleted file mode 100644 index 546acca..0000000 --- a/nfvparser/src/main/python/toscaparser/utils/urlutils.py +++ /dev/null @@ -1,65 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - - -from six.moves.urllib.parse import urljoin -from six.moves.urllib.parse import urlparse -from toscaparser.common.exception import ExceptionCollector -from toscaparser.utils.gettextutils import _ - -try: - # Python 3.x - import urllib.request as urllib2 -except ImportError: - # Python 2.x - import urllib2 - - -class UrlUtils(object): - - @staticmethod - def validate_url(path): - """Validates whether the given path is a URL or not. - - If the given path includes a scheme (http, https, ftp, ...) and a net - location (a domain name such as www.github.com) it is validated as a - URL. - """ - parsed = urlparse(path) - if parsed.scheme == 'file': - # If the url uses the file scheme netloc will be "" - return True - else: - return bool(parsed.scheme) and bool(parsed.netloc) - - @staticmethod - def join_url(url, relative_path): - """Builds a new URL from the given URL and the relative path. - - Example: - url: http://www.githib.com/openstack/heat - relative_path: heat-translator - - joined: http://www.githib.com/openstack/heat-translator - """ - if not UrlUtils.validate_url(url): - ExceptionCollector.appendException( - ValueError(_('"%s" is not a valid URL.') % url)) - return urljoin(url, relative_path) - - @staticmethod - def url_accessible(url): - """Validates whether the given URL is accessible. - - Returns true if the get call returns a 200 response code. - Otherwise, returns false. - """ - return urllib2.urlopen(url).getcode() == 200 diff --git a/nfvparser/src/main/python/toscaparser/utils/validateutils.py b/nfvparser/src/main/python/toscaparser/utils/validateutils.py deleted file mode 100644 index b280576..0000000 --- a/nfvparser/src/main/python/toscaparser/utils/validateutils.py +++ /dev/null @@ -1,236 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import collections -import dateutil.parser -import logging -import numbers -import re -import six - -# from toscaparser.elements import constraints -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import InvalidTOSCAVersionPropertyException -from toscaparser.common.exception import RangeValueError -from toscaparser.utils.gettextutils import _ - -log = logging.getLogger('tosca') - -RANGE_UNBOUNDED = 'UNBOUNDED' - - -def str_to_num(value): - '''Convert a string representation of a number into a numeric type.''' - # TODO(TBD) we should not allow numeric values in, input should be str - if isinstance(value, numbers.Number): - return value - try: - return int(value) - except ValueError: - return float(value) - - -def validate_numeric(value): - if not isinstance(value, numbers.Number): - ExceptionCollector.appendException( - ValueError(_('"%s" is not a numeric.') % value)) - return value - - -def validate_integer(value): - if not isinstance(value, int): - try: - value = int(value) - except Exception: - ExceptionCollector.appendException( - ValueError(_('"%s" is not an integer.') % value)) - return value - - -def validate_float(value): - if not isinstance(value, float): - ExceptionCollector.appendException( - ValueError(_('"%s" is not a float.') % value)) - return value - - -def validate_string(value): - if not isinstance(value, six.string_types): - ExceptionCollector.appendException( - ValueError(_('"%s" is not a string.') % value)) - return value - - -def validate_list(value): - if not isinstance(value, list): - ExceptionCollector.appendException( - ValueError(_('"%s" is not a list.') % value)) - return value - - -def validate_range(range): - # list class check - validate_list(range) - # validate range list has a min and max - if len(range) != 2: - ExceptionCollector.appendException( - ValueError(_('"%s" is not a valid range.') % range)) - # validate min and max are numerics or the keyword UNBOUNDED - min_test = max_test = False - if not range[0] == RANGE_UNBOUNDED: - min = validate_numeric(range[0]) - else: - min_test = True - if not range[1] == RANGE_UNBOUNDED: - max = validate_numeric(range[1]) - else: - max_test = True - # validate the max > min (account for UNBOUNDED) - if not min_test and not max_test: - # Note: min == max is allowed - if min > max: - ExceptionCollector.appendException( - ValueError(_('"%s" is not a valid range.') % range)) - - return range - - -def validate_value_in_range(value, range, prop_name): - validate_numeric(value) - validate_range(range) - - # Note: value is valid if equal to min - if range[0] != RANGE_UNBOUNDED: - if value < range[0]: - ExceptionCollector.appendException( - RangeValueError(pname=prop_name, - pvalue=value, - vmin=range[0], - vmax=range[1])) - # Note: value is valid if equal to max - if range[1] != RANGE_UNBOUNDED: - if value > range[1]: - ExceptionCollector.appendException( - RangeValueError(pname=prop_name, - pvalue=value, - vmin=range[0], - vmax=range[1])) - return value - - -def validate_map(value): - if not isinstance(value, collections.Mapping): - ExceptionCollector.appendException( - ValueError(_('"%s" is not a map.') % value)) - return value - - -def validate_boolean(value): - if isinstance(value, bool): - return value - - if isinstance(value, str): - normalised = value.lower() - if normalised in ['true', 'false']: - return normalised == 'true' - - ExceptionCollector.appendException( - ValueError(_('"%s" is not a boolean.') % value)) - - -def validate_timestamp(value): - try: - # Note: we must return our own exception message - # as dateutil's parser returns different types / values on - # different systems. OSX, for example, returns a tuple - # containing a different error message than Linux - dateutil.parser.parse(value) - except Exception as e: - original_err_msg = str(e) - log.error(original_err_msg) - ExceptionCollector.appendException( - ValueError(_('"%(val)s" is not a valid timestamp. "%(msg)s"') % - {'val': value, 'msg': original_err_msg})) - return - - -class TOSCAVersionProperty(object): - - VERSION_RE = re.compile('^(?P([0-9][0-9]*))' - '(\.(?P([0-9][0-9]*)))?' - '(\.(?P([0-9][0-9]*)))?' - '(\.(?P([0-9A-Za-z]+)))?' - '(\-(?P[0-9])*)?$') - - def __init__(self, version): - self.version = str(version) - match = self.VERSION_RE.match(self.version) - if not match: - ExceptionCollector.appendException( - InvalidTOSCAVersionPropertyException(what=(self.version))) - return - ver = match.groupdict() - if self.version in ['0', '0.0', '0.0.0']: - log.warning(_('Version assumed as not provided')) - self.version = None - self.minor_version = ver['minor_version'] - self.major_version = ver['major_version'] - self.fix_version = ver['fix_version'] - self.qualifier = self._validate_qualifier(ver['qualifier']) - self.build_version = self._validate_build(ver['build_version']) - self._validate_major_version(self.major_version) - - def _validate_major_version(self, value): - """Validate major version - - Checks if only major version is provided and assumes - minor version as 0. - Eg: If version = 18, then it returns version = '18.0' - """ - - if self.minor_version is None and self.build_version is None and \ - value != '0': - log.warning(_('Minor version assumed "0".')) - self.version = '.'.join([value, '0']) - return value - - def _validate_qualifier(self, value): - """Validate qualifier - - TOSCA version is invalid if a qualifier is present without the - fix version or with all of major, minor and fix version 0s. - - For example, the following versions are invalid - 18.0.abc - 0.0.0.abc - """ - if (self.fix_version is None and value) or \ - (self.minor_version == self.major_version == - self.fix_version == '0' and value): - ExceptionCollector.appendException( - InvalidTOSCAVersionPropertyException(what=(self.version))) - return value - - def _validate_build(self, value): - """Validate build version - - TOSCA version is invalid if build version is present without the - qualifier. - Eg: version = 18.0.0-1 is invalid. - """ - if not self.qualifier and value: - ExceptionCollector.appendException( - InvalidTOSCAVersionPropertyException(what=(self.version))) - return value - - def get_version(self): - return self.version diff --git a/nfvparser/src/main/python/toscaparser/utils/yamlparser.py b/nfvparser/src/main/python/toscaparser/utils/yamlparser.py deleted file mode 100644 index 713650d..0000000 --- a/nfvparser/src/main/python/toscaparser/utils/yamlparser.py +++ /dev/null @@ -1,86 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file 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. - -import codecs -from collections import OrderedDict - -from six.moves import urllib -import yaml - -from toscaparser.common.exception import ExceptionCollector -from toscaparser.common.exception import URLException -from toscaparser.utils.gettextutils import _ - - -if hasattr(yaml, 'CSafeLoader'): - yaml_loader = yaml.CSafeLoader -else: - yaml_loader = yaml.SafeLoader - - -def load_yaml(path, a_file=True): - f = None - try: - f = codecs.open(path, encoding='utf-8', errors='strict') if a_file \ - else urllib.request.urlopen(path) - except urllib.error.URLError as e: - if hasattr(e, 'reason'): - msg = (_('Failed to reach server "%(path)s". Reason is: ' - '%(reason)s.') - % {'path': path, 'reason': e.reason}) - ExceptionCollector.appendException(URLException(what=msg)) - return - elif hasattr(e, 'code'): - msg = (_('The server "%(path)s" couldn\'t fulfill the request. ' - 'Error code: "%(code)s".') - % {'path': path, 'code': e.code}) - ExceptionCollector.appendException(URLException(what=msg)) - return - except Exception as e: - raise - return yaml.load(f.read(), Loader=yaml_loader) - - -def simple_parse(tmpl_str): - try: - tpl = yaml.load(tmpl_str, Loader=yaml_loader) - except yaml.YAMLError as yea: - ExceptionCollector.appendException(ValueError(yea)) - else: - if tpl is None: - tpl = {} - return tpl - - -def ordered_load(stream, Loader=yaml.Loader, object_pairs_hook=OrderedDict): - class OrderedLoader(Loader): - pass - - def construct_mapping(loader, node): - loader.flatten_mapping(node) - return object_pairs_hook(loader.construct_pairs(node)) - - OrderedLoader.add_constructor( - yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, - construct_mapping) - return yaml.load(stream, OrderedLoader) - - -def simple_ordered_parse(tmpl_str): - try: - tpl = ordered_load(tmpl_str) - except yaml.YAMLError as yea: - ExceptionCollector.appendException(ValueError(yea)) - else: - if tpl is None: - tpl = {} - return tpl diff --git a/nfvparser/src/main/python/tox.ini b/nfvparser/src/main/python/tox.ini deleted file mode 100644 index 8fc2a88..0000000 --- a/nfvparser/src/main/python/tox.ini +++ /dev/null @@ -1,37 +0,0 @@ -[tox] -minversion = 1.6 -envlist = py27,pep8 -skipsdist = True - -[testenv] -usedevelop = True -install_command = pip install -U {opts} {packages} -setenv = - VIRTUAL_ENV={envdir} -deps = -r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt -commands = python setup.py testr --slowest --testr-args='{posargs}' - -[testenv:pep8] -commands = flake8 - -[testenv:venv] -commands = {posargs} - -[testenv:cover] -commands = python setup.py testr --coverage --coverage-package-name=toscaparser --testr-args='{posargs}' - -[testenv:docs] -commands = python setup.py build_sphinx - -[testenv:debug] -commands = oslo_debug_helper -t toscaparser/tests {posargs} - -[flake8] -# H803 skipped on purpose per list discussion. -# E123, E125 skipped as they are invalid PEP-8. - -show-source = True -ignore = E123,E125,H803 -builtins = _ -exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build diff --git a/nfvparser/test-requirements.txt b/nfvparser/test-requirements.txt new file mode 100644 index 0000000..d4b59c3 --- /dev/null +++ b/nfvparser/test-requirements.txt @@ -0,0 +1,13 @@ +# The order of packages is significant, because pip processes them in the order +# of appearance. Changing the order has an impact on the overall integration +# process, which may cause wedges in the gate later. +hacking<0.11,>=0.10.0 +coverage>=4.0 # Apache-2.0 +fixtures>=3.0.0 # Apache-2.0/BSD +oslotest>=1.10.0 # Apache-2.0 +oslosphinx>=4.7.0 # Apache-2.0 +python-subunit>=0.0.18 # Apache-2.0/BSD +sphinx>=1.5.1 # BSD +testrepository>=0.0.18 # Apache-2.0/BSD +testscenarios>=0.4 # Apache-2.0/BSD +testtools>=1.4.0 # MIT diff --git a/nfvparser/tools/tox_install.sh b/nfvparser/tools/tox_install.sh new file mode 100644 index 0000000..e61b63a --- /dev/null +++ b/nfvparser/tools/tox_install.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +# Client constraint file contains this client version pin that is in conflict +# with installing the client from source. We should remove the version pin in +# the constraints file before applying it for from-source installation. + +CONSTRAINTS_FILE="$1" +shift 1 + +set -e + +# NOTE(tonyb): Place this in the tox enviroment's log dir so it will get +# published to logs.openstack.org for easy debugging. +localfile="$VIRTUAL_ENV/log/upper-constraints.txt" + +if [[ "$CONSTRAINTS_FILE" != http* ]]; then + CONSTRAINTS_FILE="file://$CONSTRAINTS_FILE" +fi +# NOTE(tonyb): need to add curl to bindep.txt if the project supports bindep +curl "$CONSTRAINTS_FILE" --insecure --progress-bar --output "$localfile" + +pip install -c"$localfile" openstack-requirements + +# This is the main purpose of the script: Allow local installation of +# the current repo. It is listed in constraints file and thus any +# install will be constrained and we need to unconstrain it. +edit-constraints "$localfile" -- "$CLIENT_NAME" + +pip install -c"$localfile" -U "$@" +exit $? diff --git a/nfvparser/tosca_parser.py b/nfvparser/tosca_parser.py new file mode 100644 index 0000000..0d2de75 --- /dev/null +++ b/nfvparser/tosca_parser.py @@ -0,0 +1,32 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + + +from toscaparser import shell as parser_shell + +""" +Test utility to show how TOSCA Parser can be used programmatically + +It can be used as, +#python tosca_parser.py --template-file= +#python tosca_parser.py --template-file= +#python tosca_parser.py --template-file= + +e.g. +#python tosca_parser.py +--template-file=toscaparser/tests/data/tosca_helloworld.yaml +#python tosca_parser.py +--template-file=toscaparser/tests/data/CSAR/csar_hello_world.zip +""" + +if __name__ == '__main__': + parser_shell.main() diff --git a/nfvparser/toscaparser/__init__.py b/nfvparser/toscaparser/__init__.py new file mode 100644 index 0000000..d9745ed --- /dev/null +++ b/nfvparser/toscaparser/__init__.py @@ -0,0 +1,17 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import pbr.version + + +__version__ = pbr.version.VersionInfo( + 'tosca-parser').version_string() diff --git a/nfvparser/toscaparser/capabilities.py b/nfvparser/toscaparser/capabilities.py new file mode 100644 index 0000000..c23ef72 --- /dev/null +++ b/nfvparser/toscaparser/capabilities.py @@ -0,0 +1,45 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from toscaparser.properties import Property + + +class Capability(object): + '''TOSCA built-in capabilities type.''' + + def __init__(self, name, properties, definition): + self.name = name + self._properties = properties + self.definition = definition + + def get_properties_objects(self): + '''Return a list of property objects.''' + properties = [] + props = self._properties + if props: + for name, value in props.items(): + props_def = self.definition.get_properties_def() + if props_def and name in props_def: + properties.append(Property(name, value, + props_def[name].schema)) + return properties + + def get_properties(self): + '''Return a dictionary of property name-object pairs.''' + return {prop.name: prop + for prop in self.get_properties_objects()} + + def get_property_value(self, name): + '''Return the value of a given property name.''' + props = self.get_properties() + if props and name in props: + return props[name].value diff --git a/nfvparser/toscaparser/common/__init__.py b/nfvparser/toscaparser/common/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nfvparser/toscaparser/common/exception.py b/nfvparser/toscaparser/common/exception.py new file mode 100644 index 0000000..13ccabd --- /dev/null +++ b/nfvparser/toscaparser/common/exception.py @@ -0,0 +1,246 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +''' +TOSCA exception classes +''' +import logging +import sys +import traceback + +from toscaparser.utils.gettextutils import _ + + +log = logging.getLogger(__name__) + + +class TOSCAException(Exception): + '''Base exception class for TOSCA + + To correctly use this class, inherit from it and define + a 'msg_fmt' property. + + ''' + + _FATAL_EXCEPTION_FORMAT_ERRORS = False + + message = _('An unknown exception occurred.') + + def __init__(self, **kwargs): + try: + self.message = self.msg_fmt % kwargs + except KeyError: + exc_info = sys.exc_info() + log.exception(_('Exception in string format operation: %s') + % exc_info[1]) + + if TOSCAException._FATAL_EXCEPTION_FORMAT_ERRORS: + raise exc_info[0] + + def __str__(self): + return self.message + + @staticmethod + def generate_inv_schema_property_error(self, attr, value, valid_values): + msg = (_('Schema definition of "%(propname)s" has ' + '"%(attr)s" attribute with invalid value ' + '"%(value1)s". The value must be one of ' + '"%(value2)s".') % {"propname": self.name, + "attr": attr, + "value1": value, + "value2": valid_values}) + ExceptionCollector.appendException( + InvalidSchemaError(message=msg)) + + @staticmethod + def set_fatal_format_exception(flag): + if isinstance(flag, bool): + TOSCAException._FATAL_EXCEPTION_FORMAT_ERRORS = flag + + +class UnsupportedTypeError(TOSCAException): + msg_fmt = _('Type "%(what)s" is valid TOSCA type' + ' but not supported at this time.') + + +class MissingRequiredFieldError(TOSCAException): + msg_fmt = _('%(what)s is missing required field "%(required)s".') + + +class UnknownFieldError(TOSCAException): + msg_fmt = _('%(what)s contains unknown field "%(field)s". Refer to the ' + 'definition to verify valid values.') + + +class TypeMismatchError(TOSCAException): + msg_fmt = _('%(what)s must be of type "%(type)s".') + + +class InvalidNodeTypeError(TOSCAException): + msg_fmt = _('Node type "%(what)s" is not a valid type.') + + +class InvalidTypeError(TOSCAException): + msg_fmt = _('Type "%(what)s" is not a valid type.') + + +class InvalidTypeAdditionalRequirementsError(TOSCAException): + msg_fmt = _('Additional requirements for type "%(type)s" not met.') + + +class RangeValueError(TOSCAException): + msg_fmt = _('The value "%(pvalue)s" of property "%(pname)s" is out of ' + 'range "(min:%(vmin)s, max:%(vmax)s)".') + + +class InvalidSchemaError(TOSCAException): + msg_fmt = _('%(message)s') + + +class ValidationError(TOSCAException): + msg_fmt = _('%(message)s') + + +class UnknownInputError(TOSCAException): + msg_fmt = _('Unknown input "%(input_name)s".') + + +class UnknownOutputError(TOSCAException): + msg_fmt = _('Unknown output "%(output_name)s" in %(where)s.') + + +class MissingRequiredInputError(TOSCAException): + msg_fmt = _('%(what)s is missing required input definition ' + 'of input "%(input_name)s".') + + +class MissingRequiredParameterError(TOSCAException): + msg_fmt = _('%(what)s is missing required parameter for input ' + '"%(input_name)s".') + + +class MissingDefaultValueError(TOSCAException): + msg_fmt = _('%(what)s is missing required default value ' + 'of input "%(input_name)s".') + + +class MissingRequiredOutputError(TOSCAException): + msg_fmt = _('%(what)s is missing required output definition ' + 'of output "%(output_name)s".') + + +class InvalidPropertyValueError(TOSCAException): + msg_fmt = _('Value of property "%(what)s" is invalid.') + + +class InvalidTemplateVersion(TOSCAException): + msg_fmt = _('The template version "%(what)s" is invalid. ' + 'Valid versions are "%(valid_versions)s".') + + +class InvalidTOSCAVersionPropertyException(TOSCAException): + msg_fmt = _('Value of TOSCA version property "%(what)s" is invalid.') + + +class URLException(TOSCAException): + msg_fmt = _('%(what)s') + + +class ToscaExtImportError(TOSCAException): + msg_fmt = _('Unable to import extension "%(ext_name)s". ' + 'Check to see that it exists and has no ' + 'language definition errors.') + + +class ToscaExtAttributeError(TOSCAException): + msg_fmt = _('Missing attribute in extension "%(ext_name)s". ' + 'Check to see that it has required attributes ' + '"%(attrs)s" defined.') + + +class InvalidGroupTargetException(TOSCAException): + msg_fmt = _('"%(message)s"') + + +class ExceptionCollector(object): + + exceptions = [] + collecting = False + + @staticmethod + def clear(): + del ExceptionCollector.exceptions[:] + + @staticmethod + def start(): + ExceptionCollector.clear() + ExceptionCollector.collecting = True + + @staticmethod + def stop(): + ExceptionCollector.collecting = False + + @staticmethod + def contains(exception): + for ex in ExceptionCollector.exceptions: + if str(ex) == str(exception): + return True + return False + + @staticmethod + def appendException(exception): + if ExceptionCollector.collecting: + if not ExceptionCollector.contains(exception): + exception.trace = traceback.extract_stack()[:-1] + ExceptionCollector.exceptions.append(exception) + else: + raise exception + + @staticmethod + def exceptionsCaught(): + return len(ExceptionCollector.exceptions) > 0 + + @staticmethod + def getTraceString(traceList): + traceString = '' + for entry in traceList: + f, l, m, c = entry[0], entry[1], entry[2], entry[3] + traceString += (_('\t\tFile %(file)s, line %(line)s, in ' + '%(method)s\n\t\t\t%(call)s\n') + % {'file': f, 'line': l, 'method': m, 'call': c}) + return traceString + + @staticmethod + def getExceptionReportEntry(exception, full=True): + entry = exception.__class__.__name__ + ': ' + str(exception) + if full: + entry += '\n' + ExceptionCollector.getTraceString(exception.trace) + return entry + + @staticmethod + def getExceptions(): + return ExceptionCollector.exceptions + + @staticmethod + def getExceptionsReport(full=True): + report = [] + for exception in ExceptionCollector.exceptions: + report.append( + ExceptionCollector.getExceptionReportEntry(exception, full)) + return report + + @staticmethod + def assertExceptionMessage(exception, message): + err_msg = exception.__name__ + ': ' + message + report = ExceptionCollector.getExceptionsReport(False) + assert err_msg in report, (_('Could not find "%(msg)s" in "%(rep)s".') + % {'rep': report.__str__(), 'msg': err_msg}) diff --git a/nfvparser/toscaparser/dataentity.py b/nfvparser/toscaparser/dataentity.py new file mode 100644 index 0000000..507c899 --- /dev/null +++ b/nfvparser/toscaparser/dataentity.py @@ -0,0 +1,182 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import MissingRequiredFieldError +from toscaparser.common.exception import TypeMismatchError +from toscaparser.common.exception import UnknownFieldError +from toscaparser.elements.constraints import Schema +from toscaparser.elements.datatype import DataType +from toscaparser.elements.portspectype import PortSpec +from toscaparser.elements.scalarunit import ScalarUnit_Frequency +from toscaparser.elements.scalarunit import ScalarUnit_Size +from toscaparser.elements.scalarunit import ScalarUnit_Time +from toscaparser.utils.gettextutils import _ +from toscaparser.utils import validateutils + + +class DataEntity(object): + '''A complex data value entity.''' + + def __init__(self, datatypename, value_dict, custom_def=None, + prop_name=None): + self.custom_def = custom_def + self.datatype = DataType(datatypename, custom_def) + self.schema = self.datatype.get_all_properties() + self.value = value_dict + self.property_name = prop_name + + def validate(self): + '''Validate the value by the definition of the datatype.''' + + # A datatype can not have both 'type' and 'properties' definitions. + # If the datatype has 'type' definition + if self.datatype.value_type: + self.value = DataEntity.validate_datatype(self.datatype.value_type, + self.value, + None, + self.custom_def) + schema = Schema(self.property_name, self.datatype.defs) + for constraint in schema.constraints: + constraint.validate(self.value) + # If the datatype has 'properties' definition + else: + if not isinstance(self.value, dict): + ExceptionCollector.appendException( + TypeMismatchError(what=self.value, + type=self.datatype.type)) + allowed_props = [] + required_props = [] + default_props = {} + if self.schema: + allowed_props = self.schema.keys() + for name, prop_def in self.schema.items(): + if prop_def.required: + required_props.append(name) + if prop_def.default: + default_props[name] = prop_def.default + + # check allowed field + for value_key in list(self.value.keys()): + if value_key not in allowed_props: + ExceptionCollector.appendException( + UnknownFieldError(what=(_('Data value of type "%s"') + % self.datatype.type), + field=value_key)) + + # check default field + for def_key, def_value in list(default_props.items()): + if def_key not in list(self.value.keys()): + self.value[def_key] = def_value + + # check missing field + missingprop = [] + for req_key in required_props: + if req_key not in list(self.value.keys()): + missingprop.append(req_key) + if missingprop: + ExceptionCollector.appendException( + MissingRequiredFieldError( + what=(_('Data value of type "%s"') + % self.datatype.type), required=missingprop)) + + # check every field + for name, value in list(self.value.items()): + schema_name = self._find_schema(name) + if not schema_name: + continue + prop_schema = Schema(name, schema_name) + # check if field value meets type defined + DataEntity.validate_datatype(prop_schema.type, value, + prop_schema.entry_schema, + self.custom_def) + # check if field value meets constraints defined + if prop_schema.constraints: + for constraint in prop_schema.constraints: + if isinstance(value, list): + for val in value: + constraint.validate(val) + else: + constraint.validate(value) + + return self.value + + def _find_schema(self, name): + if self.schema and name in self.schema.keys(): + return self.schema[name].schema + + @staticmethod + def validate_datatype(type, value, entry_schema=None, custom_def=None, + prop_name=None): + '''Validate value with given type. + + If type is list or map, validate its entry by entry_schema(if defined) + If type is a user-defined complex datatype, custom_def is required. + ''' + from toscaparser.functions import is_function + if is_function(value): + return value + if type == Schema.STRING: + return validateutils.validate_string(value) + elif type == Schema.INTEGER: + return validateutils.validate_integer(value) + elif type == Schema.FLOAT: + return validateutils.validate_float(value) + elif type == Schema.NUMBER: + return validateutils.validate_numeric(value) + elif type == Schema.BOOLEAN: + return validateutils.validate_boolean(value) + elif type == Schema.RANGE: + return validateutils.validate_range(value) + elif type == Schema.TIMESTAMP: + validateutils.validate_timestamp(value) + return value + elif type == Schema.LIST: + validateutils.validate_list(value) + if entry_schema: + DataEntity.validate_entry(value, entry_schema, custom_def) + return value + elif type == Schema.SCALAR_UNIT_SIZE: + return ScalarUnit_Size(value).validate_scalar_unit() + elif type == Schema.SCALAR_UNIT_FREQUENCY: + return ScalarUnit_Frequency(value).validate_scalar_unit() + elif type == Schema.SCALAR_UNIT_TIME: + return ScalarUnit_Time(value).validate_scalar_unit() + elif type == Schema.VERSION: + return validateutils.TOSCAVersionProperty(value).get_version() + elif type == Schema.MAP: + validateutils.validate_map(value) + if entry_schema: + DataEntity.validate_entry(value, entry_schema, custom_def) + return value + elif type == Schema.PORTSPEC: + # TODO(TBD) bug 1567063, validate source & target as PortDef type + # as complex types not just as integers + PortSpec.validate_additional_req(value, prop_name, custom_def) + else: + data = DataEntity(type, value, custom_def) + return data.validate() + + @staticmethod + def validate_entry(value, entry_schema, custom_def=None): + '''Validate entries for map and list.''' + schema = Schema(None, entry_schema) + valuelist = value + if isinstance(value, dict): + valuelist = list(value.values()) + for v in valuelist: + DataEntity.validate_datatype(schema.type, v, schema.entry_schema, + custom_def) + if schema.constraints: + for constraint in schema.constraints: + constraint.validate(v) + return value diff --git a/nfvparser/toscaparser/elements/TOSCA_definition_1_0.yaml b/nfvparser/toscaparser/elements/TOSCA_definition_1_0.yaml new file mode 100644 index 0000000..9f3369e --- /dev/null +++ b/nfvparser/toscaparser/elements/TOSCA_definition_1_0.yaml @@ -0,0 +1,952 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +########################################################################## +# The content of this file reflects TOSCA Simple Profile in YAML version +# 1.0.0. It describes the definition for TOSCA types including Node Type, +# Relationship Type, Capability Type and Interfaces. +########################################################################## +tosca_definitions_version: tosca_simple_yaml_1_0 + +########################################################################## +# Node Type. +# A Node Type is a reusable entity that defines the type of one or more +# Node Templates. +########################################################################## +node_types: + tosca.nodes.Root: + description: > + The TOSCA root node all other TOSCA base node types derive from. + attributes: + tosca_id: + type: string + tosca_name: + type: string + state: + type: string + capabilities: + feature: + type: tosca.capabilities.Node + requirements: + - dependency: + capability: tosca.capabilities.Node + node: tosca.nodes.Root + relationship: tosca.relationships.DependsOn + occurrences: [ 0, UNBOUNDED ] + interfaces: + Standard: + type: tosca.interfaces.node.lifecycle.Standard + + tosca.nodes.Compute: + derived_from: tosca.nodes.Root + attributes: + private_address: + type: string + public_address: + type: string + networks: + type: map + entry_schema: + type: tosca.datatypes.network.NetworkInfo + ports: + type: map + entry_schema: + type: tosca.datatypes.network.PortInfo + capabilities: + host: + type: tosca.capabilities.Container + binding: + type: tosca.capabilities.network.Bindable + os: + type: tosca.capabilities.OperatingSystem + scalable: + type: tosca.capabilities.Scalable + endpoint: + type: tosca.capabilities.Endpoint.Admin + requirements: + - local_storage: + capability: tosca.capabilities.Attachment + node: tosca.nodes.BlockStorage + relationship: tosca.relationships.AttachesTo + occurrences: [0, UNBOUNDED] + + tosca.nodes.SoftwareComponent: + derived_from: tosca.nodes.Root + properties: + # domain-specific software component version + component_version: + type: version + required: false + description: > + Software component version. + admin_credential: + type: tosca.datatypes.Credential + required: false + requirements: + - host: + capability: tosca.capabilities.Container + node: tosca.nodes.Compute + relationship: tosca.relationships.HostedOn + + tosca.nodes.DBMS: + derived_from: tosca.nodes.SoftwareComponent + properties: + port: + required: false + type: integer + description: > + The port the DBMS service will listen to for data and requests. + root_password: + required: false + type: string + description: > + The root password for the DBMS service. + capabilities: + host: + type: tosca.capabilities.Container + valid_source_types: [tosca.nodes.Database] + + tosca.nodes.Database: + derived_from: tosca.nodes.Root + properties: + user: + required: false + type: string + description: > + User account name for DB administration + port: + required: false + type: integer + description: > + The port the database service will use to listen for incoming data and + requests. + name: + required: false + type: string + description: > + The name of the database. + password: + required: false + type: string + description: > + The password for the DB user account + requirements: + - host: + capability: tosca.capabilities.Container + node: tosca.nodes.DBMS + relationship: tosca.relationships.HostedOn + capabilities: + database_endpoint: + type: tosca.capabilities.Endpoint.Database + + tosca.nodes.WebServer: + derived_from: tosca.nodes.SoftwareComponent + capabilities: + data_endpoint: + type: tosca.capabilities.Endpoint + admin_endpoint: + type: tosca.capabilities.Endpoint.Admin + host: + type: tosca.capabilities.Container + valid_source_types: [tosca.nodes.WebApplication] + + tosca.nodes.WebApplication: + derived_from: tosca.nodes.Root + properties: + context_root: + type: string + required: false + requirements: + - host: + capability: tosca.capabilities.Container + node: tosca.nodes.WebServer + relationship: tosca.relationships.HostedOn + capabilities: + app_endpoint: + type: tosca.capabilities.Endpoint + + tosca.nodes.BlockStorage: + derived_from: tosca.nodes.Root + properties: + size: + type: scalar-unit.size + constraints: + - greater_or_equal: 1 MB + volume_id: + type: string + required: false + snapshot_id: + type: string + required: false + attributes: + volume_id: + type: string + capabilities: + attachment: + type: tosca.capabilities.Attachment + + tosca.nodes.network.Network: + derived_from: tosca.nodes.Root + description: > + The TOSCA Network node represents a simple, logical network service. + properties: + ip_version: + type: integer + required: false + default: 4 + constraints: + - valid_values: [ 4, 6 ] + description: > + The IP version of the requested network. Valid values are 4 for ipv4 + or 6 for ipv6. + cidr: + type: string + required: false + description: > + The cidr block of the requested network. + start_ip: + type: string + required: false + description: > + The IP address to be used as the start of a pool of addresses within + the full IP range derived from the cidr block. + end_ip: + type: string + required: false + description: > + The IP address to be used as the end of a pool of addresses within + the full IP range derived from the cidr block. + gateway_ip: + type: string + required: false + description: > + The gateway IP address. + network_name: + type: string + required: false + description: > + An identifier that represents an existing Network instance in the + underlying cloud infrastructure or can be used as the name of the + newly created network. If network_name is provided and no other + properties are provided (with exception of network_id), then an + existing network instance will be used. If network_name is provided + alongside with more properties then a new network with this name will + be created. + network_id: + type: string + required: false + description: > + An identifier that represents an existing Network instance in the + underlying cloud infrastructure. This property is mutually exclusive + with all other properties except network_name. This can be used alone + or together with network_name to identify an existing network. + segmentation_id: + type: string + required: false + description: > + A segmentation identifier in the underlying cloud infrastructure. + E.g. VLAN ID, GRE tunnel ID, etc.. + network_type: + type: string + required: false + description: > + It specifies the nature of the physical network in the underlying + cloud infrastructure. Examples are flat, vlan, gre or vxlan. + For flat and vlan types, physical_network should be provided too. + physical_network: + type: string + required: false + description: > + It identifies the physical network on top of which the network is + implemented, e.g. physnet1. This property is required if network_type + is flat or vlan. + dhcp_enabled: + type: boolean + required: false + default: true + description: > + Indicates should DHCP service be enabled on the network or not. + capabilities: + link: + type: tosca.capabilities.network.Linkable + + tosca.nodes.network.Port: + derived_from: tosca.nodes.Root + description: > + The TOSCA Port node represents a logical entity that associates between + Compute and Network normative types. The Port node type effectively + represents a single virtual NIC on the Compute node instance. + properties: + ip_address: + type: string + required: false + description: > + Allow the user to set a static IP. + order: + type: integer + required: false + default: 0 + constraints: + - greater_or_equal: 0 + description: > + The order of the NIC on the compute instance (e.g. eth2). + is_default: + type: boolean + required: false + default: false + description: > + If is_default=true this port will be used for the default gateway + route. Only one port that is associated to single compute node can + set as is_default=true. + ip_range_start: + type: string + required: false + description: > + Defines the starting IP of a range to be allocated for the compute + instances that are associated with this Port. + ip_range_end: + type: string + required: false + description: > + Defines the ending IP of a range to be allocated for the compute + instances that are associated with this Port. + attributes: + ip_address: + type: string + requirements: + - binding: + description: > + Binding requirement expresses the relationship between Port and + Compute nodes. Effectively it indicates that the Port will be + attached to specific Compute node instance + capability: tosca.capabilities.network.Bindable + relationship: tosca.relationships.network.BindsTo + node: tosca.nodes.Compute + - link: + description: > + Link requirement expresses the relationship between Port and Network + nodes. It indicates which network this port will connect to. + capability: tosca.capabilities.network.Linkable + relationship: tosca.relationships.network.LinksTo + node: tosca.nodes.network.Network + + tosca.nodes.ObjectStorage: + derived_from: tosca.nodes.Root + description: > + The TOSCA ObjectStorage node represents storage that provides the ability + to store data as objects (or BLOBs of data) without consideration for the + underlying filesystem or devices + properties: + name: + type: string + required: true + description: > + The logical name of the object store (or container). + size: + type: scalar-unit.size + required: false + constraints: + - greater_or_equal: 0 GB + description: > + The requested initial storage size. + maxsize: + type: scalar-unit.size + required: false + constraints: + - greater_or_equal: 0 GB + description: > + The requested maximum storage size. + capabilities: + storage_endpoint: + type: tosca.capabilities.Endpoint + + tosca.nodes.LoadBalancer: + derived_from: tosca.nodes.Root + properties: + algorithm: + type: string + required: false + status: experimental + capabilities: + client: + type: tosca.capabilities.Endpoint.Public + occurrences: [0, UNBOUNDED] + description: the Floating (IP) client’s on the public network can connect to + requirements: + - application: + capability: tosca.capabilities.Endpoint + relationship: tosca.relationships.RoutesTo + occurrences: [0, UNBOUNDED] + description: Connection to one or more load balanced applications + + tosca.nodes.Container.Application: + derived_from: tosca.nodes.Root + requirements: + - host: + capability: tosca.capabilities.Container + node: tosca.nodes.Container.Runtime + relationship: tosca.relationships.HostedOn + + tosca.nodes.Container.Runtime: + derived_from: tosca.nodes.SoftwareComponent + capabilities: + host: + type: tosca.capabilities.Container + scalable: + type: tosca.capabilities.Scalable + + tosca.nodes.Container.Application.Docker: + derived_from: tosca.nodes.Container.Application + requirements: + - host: + capability: tosca.capabilities.Container.Docker + +########################################################################## +# Relationship Type. +# A Relationship Type is a reusable entity that defines the type of one +# or more relationships between Node Types or Node Templates. +########################################################################## +relationship_types: + tosca.relationships.Root: + description: > + The TOSCA root Relationship Type all other TOSCA base Relationship Types + derive from. + attributes: + tosca_id: + type: string + tosca_name: + type: string + interfaces: + Configure: + type: tosca.interfaces.relationship.Configure + + tosca.relationships.DependsOn: + derived_from: tosca.relationships.Root + + tosca.relationships.HostedOn: + derived_from: tosca.relationships.Root + valid_target_types: [ tosca.capabilities.Container ] + + tosca.relationships.ConnectsTo: + derived_from: tosca.relationships.Root + valid_target_types: [ tosca.capabilities.Endpoint ] + credential: + type: tosca.datatypes.Credential + required: false + + tosca.relationships.AttachesTo: + derived_from: tosca.relationships.Root + valid_target_types: [ tosca.capabilities.Attachment ] + properties: + location: + required: true + type: string + constraints: + - min_length: 1 + device: + required: false + type: string + + tosca.relationships.RoutesTo: + derived_from: tosca.relationships.ConnectsTo + valid_target_types: [ tosca.capabilities.Endpoint ] + + tosca.relationships.network.LinksTo: + derived_from: tosca.relationships.DependsOn + valid_target_types: [ tosca.capabilities.network.Linkable ] + + tosca.relationships.network.BindsTo: + derived_from: tosca.relationships.DependsOn + valid_target_types: [ tosca.capabilities.network.Bindable ] + +########################################################################## +# Capability Type. +# A Capability Type is a reusable entity that describes a kind of +# capability that a Node Type can declare to expose. +########################################################################## +capability_types: + tosca.capabilities.Root: + description: > + The TOSCA root Capability Type all other TOSCA base Capability Types + derive from. + + tosca.capabilities.Node: + derived_from: tosca.capabilities.Root + + tosca.capabilities.Container: + derived_from: tosca.capabilities.Root + properties: + num_cpus: + required: false + type: integer + constraints: + - greater_or_equal: 1 + cpu_frequency: + required: false + type: scalar-unit.frequency + constraints: + - greater_or_equal: 0.1 GHz + disk_size: + required: false + type: scalar-unit.size + constraints: + - greater_or_equal: 0 MB + mem_size: + required: false + type: scalar-unit.size + constraints: + - greater_or_equal: 0 MB + + tosca.capabilities.Endpoint: + derived_from: tosca.capabilities.Root + properties: + protocol: + type: string + required: true + default: tcp + port: + type: tosca.datatypes.network.PortDef + required: false + secure: + type: boolean + required: false + default: false + url_path: + type: string + required: false + port_name: + type: string + required: false + network_name: + type: string + required: false + default: PRIVATE + initiator: + type: string + required: false + default: source + constraints: + - valid_values: [source, target, peer] + ports: + type: map + required: false + constraints: + - min_length: 1 + entry_schema: + type: tosca.datatypes.network.PortSpec + attributes: + ip_address: + type: string + + tosca.capabilities.Endpoint.Admin: + derived_from: tosca.capabilities.Endpoint + properties: + secure: + type: boolean + default: true + constraints: + - equal: true + + tosca.capabilities.Endpoint.Public: + derived_from: tosca.capabilities.Endpoint + properties: + # Change the default network_name to use the first public network found + network_name: + type: string + default: PUBLIC + constraints: + - equal: PUBLIC + floating: + description: > + Indicates that the public address should be allocated from a pool of + floating IPs that are associated with the network. + type: boolean + default: false + status: experimental + dns_name: + description: The optional name to register with DNS + type: string + required: false + status: experimental + + tosca.capabilities.Scalable: + derived_from: tosca.capabilities.Root + properties: + min_instances: + type: integer + required: true + default: 1 + description: > + This property is used to indicate the minimum number of instances + that should be created for the associated TOSCA Node Template by + a TOSCA orchestrator. + max_instances: + type: integer + required: true + default: 1 + description: > + This property is used to indicate the maximum number of instances + that should be created for the associated TOSCA Node Template by + a TOSCA orchestrator. + default_instances: + type: integer + required: false + description: > + An optional property that indicates the requested default number + of instances that should be the starting number of instances a + TOSCA orchestrator should attempt to allocate. + The value for this property MUST be in the range between the values + set for min_instances and max_instances properties. + + tosca.capabilities.Endpoint.Database: + derived_from: tosca.capabilities.Endpoint + + tosca.capabilities.Attachment: + derived_from: tosca.capabilities.Root + + tosca.capabilities.network.Linkable: + derived_from: tosca.capabilities.Root + description: > + A node type that includes the Linkable capability indicates that it can + be pointed by tosca.relationships.network.LinksTo relationship type, which + represents an association relationship between Port and Network node types. + + tosca.capabilities.network.Bindable: + derived_from: tosca.capabilities.Root + description: > + A node type that includes the Bindable capability indicates that it can + be pointed by tosca.relationships.network.BindsTo relationship type, which + represents a network association relationship between Port and Compute node + types. + + tosca.capabilities.OperatingSystem: + derived_from: tosca.capabilities.Root + properties: + architecture: + required: false + type: string + description: > + The host Operating System (OS) architecture. + type: + required: false + type: string + description: > + The host Operating System (OS) type. + distribution: + required: false + type: string + description: > + The host Operating System (OS) distribution. Examples of valid values + for an “type” of “Linux” would include: + debian, fedora, rhel and ubuntu. + version: + required: false + type: version + description: > + The host Operating System version. + + tosca.capabilities.Container.Docker: + derived_from: tosca.capabilities.Container + properties: + version: + type: list + required: false + entry_schema: + type: version + description: > + The Docker version capability. + publish_all: + type: boolean + default: false + required: false + description: > + Indicates that all ports (ranges) listed in the dockerfile + using the EXPOSE keyword be published. + publish_ports: + type: list + entry_schema: + type: tosca.datatypes.network.PortSpec + required: false + description: > + List of ports mappings from source (Docker container) + to target (host) ports to publish. + expose_ports: + type: list + entry_schema: + type: tosca.datatypes.network.PortSpec + required: false + description: > + List of ports mappings from source (Docker container) to expose + to other Docker containers (not accessible outside host). + volumes: + type: list + entry_schema: + type: string + required: false + description: > + The dockerfile VOLUME command which is used to enable access + from the Docker container to a directory on the host machine. + host_id: + type: string + required: false + description: > + The optional identifier of an existing host resource + that should be used to run this container on. + volume_id: + type: string + required: false + description: > + The optional identifier of an existing storage volume (resource) + that should be used to create the container's mount point(s) on. + +########################################################################## + # Interfaces Type. + # The Interfaces element describes a list of one or more interface + # definitions for a modelable entity (e.g., a Node or Relationship Type) + # as defined within the TOSCA Simple Profile specification. +########################################################################## +interface_types: + tosca.interfaces.node.lifecycle.Standard: + create: + description: Standard lifecycle create operation. + configure: + description: Standard lifecycle configure operation. + start: + description: Standard lifecycle start operation. + stop: + description: Standard lifecycle stop operation. + delete: + description: Standard lifecycle delete operation. + + tosca.interfaces.relationship.Configure: + pre_configure_source: + description: Operation to pre-configure the source endpoint. + pre_configure_target: + description: Operation to pre-configure the target endpoint. + post_configure_source: + description: Operation to post-configure the source endpoint. + post_configure_target: + description: Operation to post-configure the target endpoint. + add_target: + description: Operation to add a target node. + remove_target: + description: Operation to remove a target node. + add_source: > + description: Operation to notify the target node of a source node which + is now available via a relationship. + description: + target_changed: > + description: Operation to notify source some property or attribute of the + target changed + +########################################################################## + # Data Type. + # A Datatype is a complex data type declaration which contains other + # complex or simple data types. +########################################################################## +data_types: + tosca.datatypes.Root: + description: > + The TOSCA root Data Type all other TOSCA base Data Types derive from + + tosca.datatypes.network.NetworkInfo: + derived_from: tosca.datatypes.Root + properties: + network_name: + type: string + network_id: + type: string + addresses: + type: list + entry_schema: + type: string + + tosca.datatypes.network.PortInfo: + derived_from: tosca.datatypes.Root + properties: + port_name: + type: string + port_id: + type: string + network_id: + type: string + mac_address: + type: string + addresses: + type: list + entry_schema: + type: string + + tosca.datatypes.network.PortDef: + derived_from: tosca.datatypes.Root + type: integer + constraints: + - in_range: [ 1, 65535 ] + + tosca.datatypes.network.PortSpec: + derived_from: tosca.datatypes.Root + properties: + protocol: + type: string + required: true + default: tcp + constraints: + - valid_values: [ udp, tcp, igmp ] + target: + type: tosca.datatypes.network.PortDef + required: false + target_range: + type: range + required: false + constraints: + - in_range: [ 1, 65535 ] + source: + type: tosca.datatypes.network.PortDef + required: false + source_range: + type: range + required: false + constraints: + - in_range: [ 1, 65535 ] + + tosca.datatypes.Credential: + derived_from: tosca.datatypes.Root + properties: + protocol: + type: string + required: false + token_type: + type: string + default: password + required: true + token: + type: string + required: true + keys: + type: map + entry_schema: + type: string + required: false + user: + type: string + required: false + +########################################################################## + # Artifact Type. + # An Artifact Type is a reusable entity that defines the type of one or more + # files which Node Types or Node Templates can have dependent relationships + # and used during operations such as during installation or deployment. +########################################################################## +artifact_types: + tosca.artifacts.Root: + description: > + The TOSCA Artifact Type all other TOSCA Artifact Types derive from + properties: + version: version + + tosca.artifacts.File: + derived_from: tosca.artifacts.Root + + tosca.artifacts.Deployment: + derived_from: tosca.artifacts.Root + description: TOSCA base type for deployment artifacts + + tosca.artifacts.Deployment.Image: + derived_from: tosca.artifacts.Deployment + + tosca.artifacts.Deployment.Image.VM: + derived_from: tosca.artifacts.Deployment.Image + + tosca.artifacts.Implementation: + derived_from: tosca.artifacts.Root + description: TOSCA base type for implementation artifacts + + tosca.artifacts.Implementation.Bash: + derived_from: tosca.artifacts.Implementation + description: Script artifact for the Unix Bash shell + mime_type: application/x-sh + file_ext: [ sh ] + + tosca.artifacts.Implementation.Python: + derived_from: tosca.artifacts.Implementation + description: Artifact for the interpreted Python language + mime_type: application/x-python + file_ext: [ py ] + + tosca.artifacts.Deployment.Image.Container.Docker: + derived_from: tosca.artifacts.Deployment.Image + description: Docker container image + + tosca.artifacts.Deployment.Image.VM.ISO: + derived_from: tosca.artifacts.Deployment.Image + description: Virtual Machine (VM) image in ISO disk format + mime_type: application/octet-stream + file_ext: [ iso ] + + tosca.artifacts.Deployment.Image.VM.QCOW2: + derived_from: tosca.artifacts.Deployment.Image + description: Virtual Machine (VM) image in QCOW v2 standard disk format + mime_type: application/octet-stream + file_ext: [ qcow2 ] + +########################################################################## + # Policy Type. + # TOSCA Policy Types represent logical grouping of TOSCA nodes that have + # an implied relationship and need to be orchestrated or managed together + # to achieve some result. +########################################################################## +policy_types: + tosca.policies.Root: + description: The TOSCA Policy Type all other TOSCA Policy Types derive from. + + tosca.policies.Placement: + derived_from: tosca.policies.Root + description: The TOSCA Policy Type definition that is used to govern + placement of TOSCA nodes or groups of nodes. + + tosca.policies.Placement.Colocate: + derived_from: tosca.policies.Placement + description: The TOSCA Policy Type definition that is used to govern + colocate placement of TOSCA nodes or groups of nodes. + + tosca.policies.Placement.Antilocate: + derived_from: tosca.policies.Placement + description: The TOSCA Policy Type definition that is used to govern + anti-locate placement of TOSCA nodes or groups of nodes. + + tosca.policies.Scaling: + derived_from: tosca.policies.Root + description: The TOSCA Policy Type definition that is used to govern + scaling of TOSCA nodes or groups of nodes. + + tosca.policies.Update: + derived_from: tosca.policies.Root + description: The TOSCA Policy Type definition that is used to govern + update of TOSCA nodes or groups of nodes. + + tosca.policies.Performance: + derived_from: tosca.policies.Root + description: The TOSCA Policy Type definition that is used to declare + performance requirements for TOSCA nodes or groups of nodes. + +########################################################################## + # Group Type. + # Group Type represents logical grouping of TOSCA nodes that have an + # implied membership relationship and may need to be orchestrated or + # managed together to achieve some result. +########################################################################## +group_types: + tosca.groups.Root: + description: The TOSCA Group Type all other TOSCA Group Types derive from + interfaces: + Standard: + type: tosca.interfaces.node.lifecycle.Standard diff --git a/nfvparser/toscaparser/elements/__init__.py b/nfvparser/toscaparser/elements/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nfvparser/toscaparser/elements/artifacttype.py b/nfvparser/toscaparser/elements/artifacttype.py new file mode 100644 index 0000000..bf379fc --- /dev/null +++ b/nfvparser/toscaparser/elements/artifacttype.py @@ -0,0 +1,50 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from toscaparser.elements.statefulentitytype import StatefulEntityType + + +class ArtifactTypeDef(StatefulEntityType): + '''TOSCA built-in artifacts type.''' + + def __init__(self, atype, custom_def=None): + super(ArtifactTypeDef, self).__init__(atype, self.ARTIFACT_PREFIX, + custom_def) + self.type = atype + self.custom_def = custom_def + self.properties = None + if self.PROPERTIES in self.defs: + self.properties = self.defs[self.PROPERTIES] + self.parent_artifacts = self._get_parent_artifacts() + + def _get_parent_artifacts(self): + artifacts = {} + parent_artif = self.parent_type.type if self.parent_type else None + if parent_artif: + while parent_artif != 'tosca.artifacts.Root': + artifacts[parent_artif] = self.TOSCA_DEF[parent_artif] + parent_artif = artifacts[parent_artif]['derived_from'] + return artifacts + + @property + def parent_type(self): + '''Return a artifact entity from which this entity is derived.''' + if not hasattr(self, 'defs'): + return None + partifact_entity = self.derived_from(self.defs) + if partifact_entity: + return ArtifactTypeDef(partifact_entity, self.custom_def) + + def get_artifact(self, name): + '''Return the definition of an artifact field by name.''' + if name in self.defs: + return self.defs[name] diff --git a/nfvparser/toscaparser/elements/attribute_definition.py b/nfvparser/toscaparser/elements/attribute_definition.py new file mode 100644 index 0000000..35ba27f --- /dev/null +++ b/nfvparser/toscaparser/elements/attribute_definition.py @@ -0,0 +1,20 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + + +class AttributeDef(object): + '''TOSCA built-in Attribute type.''' + + def __init__(self, name, value=None, schema=None): + self.name = name + self.value = value + self.schema = schema diff --git a/nfvparser/toscaparser/elements/capabilitytype.py b/nfvparser/toscaparser/elements/capabilitytype.py new file mode 100644 index 0000000..5fa9661 --- /dev/null +++ b/nfvparser/toscaparser/elements/capabilitytype.py @@ -0,0 +1,96 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from toscaparser.elements.property_definition import PropertyDef +from toscaparser.elements.statefulentitytype import StatefulEntityType + + +class CapabilityTypeDef(StatefulEntityType): + '''TOSCA built-in capabilities type.''' + TOSCA_TYPEURI_CAPABILITY_ROOT = 'tosca.capabilities.Root' + + def __init__(self, name, ctype, ntype, custom_def=None): + self.name = name + super(CapabilityTypeDef, self).__init__(ctype, self.CAPABILITY_PREFIX, + custom_def) + self.nodetype = ntype + self.properties = None + self.custom_def = custom_def + if self.PROPERTIES in self.defs: + self.properties = self.defs[self.PROPERTIES] + self.parent_capabilities = self._get_parent_capabilities(custom_def) + + def get_properties_def_objects(self): + '''Return a list of property definition objects.''' + properties = [] + parent_properties = {} + if self.parent_capabilities: + for type, value in self.parent_capabilities.items(): + parent_properties[type] = value.get('properties') + if self.properties: + for prop, schema in self.properties.items(): + properties.append(PropertyDef(prop, None, schema)) + if parent_properties: + for parent, props in parent_properties.items(): + for prop, schema in props.items(): + # add parent property if not overridden by children type + if not self.properties or \ + prop not in self.properties.keys(): + properties.append(PropertyDef(prop, None, schema)) + return properties + + def get_properties_def(self): + '''Return a dictionary of property definition name-object pairs.''' + return {prop.name: prop + for prop in self.get_properties_def_objects()} + + def get_property_def_value(self, name): + '''Return the definition of a given property name.''' + props_def = self.get_properties_def() + if props_def and name in props_def: + return props_def[name].value + + def _get_parent_capabilities(self, custom_def=None): + capabilities = {} + parent_cap = self.parent_type + if parent_cap: + parent_cap = parent_cap.type + while parent_cap != self.TOSCA_TYPEURI_CAPABILITY_ROOT: + if parent_cap in self.TOSCA_DEF.keys(): + capabilities[parent_cap] = self.TOSCA_DEF[parent_cap] + elif custom_def and parent_cap in custom_def.keys(): + capabilities[parent_cap] = custom_def[parent_cap] + parent_cap = capabilities[parent_cap]['derived_from'] + return capabilities + + @property + def parent_type(self): + '''Return a capability this capability is derived from.''' + if not hasattr(self, 'defs'): + return None + pnode = self.derived_from(self.defs) + if pnode: + return CapabilityTypeDef(self.name, pnode, + self.nodetype, self.custom_def) + + def inherits_from(self, type_names): + '''Check this capability is in type_names + + Check if this capability or some of its parent types + are in the list of types: type_names + ''' + if self.type in type_names: + return True + elif self.parent_type: + return self.parent_type.inherits_from(type_names) + else: + return False diff --git a/nfvparser/toscaparser/elements/constraints.py b/nfvparser/toscaparser/elements/constraints.py new file mode 100644 index 0000000..70863bc --- /dev/null +++ b/nfvparser/toscaparser/elements/constraints.py @@ -0,0 +1,615 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import collections +import datetime +import re + +import toscaparser +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import InvalidSchemaError +from toscaparser.common.exception import ValidationError +from toscaparser.elements.portspectype import PortSpec +from toscaparser.elements import scalarunit +from toscaparser.utils.gettextutils import _ + + +class Schema(collections.Mapping): + + KEYS = ( + TYPE, REQUIRED, DESCRIPTION, + DEFAULT, CONSTRAINTS, ENTRYSCHEMA, STATUS + ) = ( + 'type', 'required', 'description', + 'default', 'constraints', 'entry_schema', 'status' + ) + + PROPERTY_TYPES = ( + INTEGER, STRING, BOOLEAN, FLOAT, RANGE, + NUMBER, TIMESTAMP, LIST, MAP, + SCALAR_UNIT_SIZE, SCALAR_UNIT_FREQUENCY, SCALAR_UNIT_TIME, + VERSION, PORTDEF, PORTSPEC + ) = ( + 'integer', 'string', 'boolean', 'float', 'range', + 'number', 'timestamp', 'list', 'map', + 'scalar-unit.size', 'scalar-unit.frequency', 'scalar-unit.time', + 'version', 'PortDef', PortSpec.SHORTNAME + ) + + SCALAR_UNIT_SIZE_DEFAULT = 'B' + SCALAR_UNIT_SIZE_DICT = {'B': 1, 'KB': 1000, 'KIB': 1024, 'MB': 1000000, + 'MIB': 1048576, 'GB': 1000000000, + 'GIB': 1073741824, 'TB': 1000000000000, + 'TIB': 1099511627776} + + def __init__(self, name, schema_dict): + self.name = name + if not isinstance(schema_dict, collections.Mapping): + msg = (_('Schema definition of "%(pname)s" must be a dict.') + % dict(pname=name)) + ExceptionCollector.appendException(InvalidSchemaError(message=msg)) + + try: + schema_dict['type'] + except KeyError: + msg = (_('Schema definition of "%(pname)s" must have a "type" ' + 'attribute.') % dict(pname=name)) + ExceptionCollector.appendException(InvalidSchemaError(message=msg)) + + self.schema = schema_dict + self._len = None + self.constraints_list = [] + + @property + def type(self): + return self.schema[self.TYPE] + + @property + def required(self): + return self.schema.get(self.REQUIRED, True) + + @property + def description(self): + return self.schema.get(self.DESCRIPTION, '') + + @property + def default(self): + return self.schema.get(self.DEFAULT) + + @property + def status(self): + return self.schema.get(self.STATUS, '') + + @property + def constraints(self): + if not self.constraints_list: + constraint_schemata = self.schema.get(self.CONSTRAINTS) + if constraint_schemata: + self.constraints_list = [Constraint(self.name, + self.type, + cschema) + for cschema in constraint_schemata] + return self.constraints_list + + @property + def entry_schema(self): + return self.schema.get(self.ENTRYSCHEMA) + + def __getitem__(self, key): + return self.schema[key] + + def __iter__(self): + for k in self.KEYS: + try: + self.schema[k] + except KeyError: + pass + else: + yield k + + def __len__(self): + if self._len is None: + self._len = len(list(iter(self))) + return self._len + + +class Constraint(object): + '''Parent class for constraints for a Property or Input.''' + + CONSTRAINTS = (EQUAL, GREATER_THAN, + GREATER_OR_EQUAL, LESS_THAN, LESS_OR_EQUAL, IN_RANGE, + VALID_VALUES, LENGTH, MIN_LENGTH, MAX_LENGTH, PATTERN) = \ + ('equal', 'greater_than', 'greater_or_equal', 'less_than', + 'less_or_equal', 'in_range', 'valid_values', 'length', + 'min_length', 'max_length', 'pattern') + + def __new__(cls, property_name, property_type, constraint): + if cls is not Constraint: + return super(Constraint, cls).__new__(cls) + + if(not isinstance(constraint, collections.Mapping) or + len(constraint) != 1): + ExceptionCollector.appendException( + InvalidSchemaError(message=_('Invalid constraint schema.'))) + + for type in constraint.keys(): + ConstraintClass = get_constraint_class(type) + if not ConstraintClass: + msg = _('Invalid property "%s".') % type + ExceptionCollector.appendException( + InvalidSchemaError(message=msg)) + + return ConstraintClass(property_name, property_type, constraint) + + def __init__(self, property_name, property_type, constraint): + self.property_name = property_name + self.property_type = property_type + self.constraint_value = constraint[self.constraint_key] + self.constraint_value_msg = self.constraint_value + if self.property_type in scalarunit.ScalarUnit.SCALAR_UNIT_TYPES: + self.constraint_value = self._get_scalarunit_constraint_value() + # check if constraint is valid for property type + if property_type not in self.valid_prop_types: + msg = _('Property "%(ctype)s" is not valid for data type ' + '"%(dtype)s".') % dict( + ctype=self.constraint_key, + dtype=property_type) + ExceptionCollector.appendException(InvalidSchemaError(message=msg)) + + def _get_scalarunit_constraint_value(self): + if self.property_type in scalarunit.ScalarUnit.SCALAR_UNIT_TYPES: + ScalarUnit_Class = (scalarunit. + get_scalarunit_class(self.property_type)) + if isinstance(self.constraint_value, list): + return [ScalarUnit_Class(v).get_num_from_scalar_unit() + for v in self.constraint_value] + else: + return (ScalarUnit_Class(self.constraint_value). + get_num_from_scalar_unit()) + + def _err_msg(self, value): + return _('Property "%s" could not be validated.') % self.property_name + + def validate(self, value): + self.value_msg = value + if self.property_type in scalarunit.ScalarUnit.SCALAR_UNIT_TYPES: + value = scalarunit.get_scalarunit_value(self.property_type, value) + if not self._is_valid(value): + err_msg = self._err_msg(value) + ExceptionCollector.appendException( + ValidationError(message=err_msg)) + + +class Equal(Constraint): + """Constraint class for "equal" + + Constrains a property or parameter to a value equal to ('=') + the value declared. + """ + + constraint_key = Constraint.EQUAL + + valid_prop_types = Schema.PROPERTY_TYPES + + def _is_valid(self, value): + if value == self.constraint_value: + return True + + return False + + def _err_msg(self, value): + return (_('The value "%(pvalue)s" of property "%(pname)s" is not ' + 'equal to "%(cvalue)s".') % + dict(pname=self.property_name, + pvalue=self.value_msg, + cvalue=self.constraint_value_msg)) + + +class GreaterThan(Constraint): + """Constraint class for "greater_than" + + Constrains a property or parameter to a value greater than ('>') + the value declared. + """ + + constraint_key = Constraint.GREATER_THAN + + valid_types = (int, float, datetime.date, + datetime.time, datetime.datetime) + + valid_prop_types = (Schema.INTEGER, Schema.FLOAT, Schema.TIMESTAMP, + Schema.SCALAR_UNIT_SIZE, Schema.SCALAR_UNIT_FREQUENCY, + Schema.SCALAR_UNIT_TIME) + + def __init__(self, property_name, property_type, constraint): + super(GreaterThan, self).__init__(property_name, property_type, + constraint) + if not isinstance(constraint[self.GREATER_THAN], self.valid_types): + ExceptionCollector.appendException( + InvalidSchemaError(message=_('The property "greater_than" ' + 'expects comparable values.'))) + + def _is_valid(self, value): + if value > self.constraint_value: + return True + + return False + + def _err_msg(self, value): + return (_('The value "%(pvalue)s" of property "%(pname)s" must be ' + 'greater than "%(cvalue)s".') % + dict(pname=self.property_name, + pvalue=self.value_msg, + cvalue=self.constraint_value_msg)) + + +class GreaterOrEqual(Constraint): + """Constraint class for "greater_or_equal" + + Constrains a property or parameter to a value greater than or equal + to ('>=') the value declared. + """ + + constraint_key = Constraint.GREATER_OR_EQUAL + + valid_types = (int, float, datetime.date, + datetime.time, datetime.datetime) + + valid_prop_types = (Schema.INTEGER, Schema.FLOAT, Schema.TIMESTAMP, + Schema.SCALAR_UNIT_SIZE, Schema.SCALAR_UNIT_FREQUENCY, + Schema.SCALAR_UNIT_TIME) + + def __init__(self, property_name, property_type, constraint): + super(GreaterOrEqual, self).__init__(property_name, property_type, + constraint) + if not isinstance(self.constraint_value, self.valid_types): + ExceptionCollector.appendException( + InvalidSchemaError(message=_('The property ' + '"greater_or_equal" expects ' + 'comparable values.'))) + + def _is_valid(self, value): + if toscaparser.functions.is_function(value) or \ + value >= self.constraint_value: + return True + return False + + def _err_msg(self, value): + return (_('The value "%(pvalue)s" of property "%(pname)s" must be ' + 'greater than or equal to "%(cvalue)s".') % + dict(pname=self.property_name, + pvalue=self.value_msg, + cvalue=self.constraint_value_msg)) + + +class LessThan(Constraint): + """Constraint class for "less_than" + + Constrains a property or parameter to a value less than ('<') + the value declared. + """ + + constraint_key = Constraint.LESS_THAN + + valid_types = (int, float, datetime.date, + datetime.time, datetime.datetime) + + valid_prop_types = (Schema.INTEGER, Schema.FLOAT, Schema.TIMESTAMP, + Schema.SCALAR_UNIT_SIZE, Schema.SCALAR_UNIT_FREQUENCY, + Schema.SCALAR_UNIT_TIME) + + def __init__(self, property_name, property_type, constraint): + super(LessThan, self).__init__(property_name, property_type, + constraint) + if not isinstance(self.constraint_value, self.valid_types): + ExceptionCollector.appendException( + InvalidSchemaError(message=_('The property "less_than" ' + 'expects comparable values.'))) + + def _is_valid(self, value): + if value < self.constraint_value: + return True + + return False + + def _err_msg(self, value): + return (_('The value "%(pvalue)s" of property "%(pname)s" must be ' + 'less than "%(cvalue)s".') % + dict(pname=self.property_name, + pvalue=self.value_msg, + cvalue=self.constraint_value_msg)) + + +class LessOrEqual(Constraint): + """Constraint class for "less_or_equal" + + Constrains a property or parameter to a value less than or equal + to ('<=') the value declared. + """ + + constraint_key = Constraint.LESS_OR_EQUAL + + valid_types = (int, float, datetime.date, + datetime.time, datetime.datetime) + + valid_prop_types = (Schema.INTEGER, Schema.FLOAT, Schema.TIMESTAMP, + Schema.SCALAR_UNIT_SIZE, Schema.SCALAR_UNIT_FREQUENCY, + Schema.SCALAR_UNIT_TIME) + + def __init__(self, property_name, property_type, constraint): + super(LessOrEqual, self).__init__(property_name, property_type, + constraint) + if not isinstance(self.constraint_value, self.valid_types): + ExceptionCollector.appendException( + InvalidSchemaError(message=_('The property "less_or_equal" ' + 'expects comparable values.'))) + + def _is_valid(self, value): + if value <= self.constraint_value: + return True + + return False + + def _err_msg(self, value): + return (_('The value "%(pvalue)s" of property "%(pname)s" must be ' + 'less than or equal to "%(cvalue)s".') % + dict(pname=self.property_name, + pvalue=self.value_msg, + cvalue=self.constraint_value_msg)) + + +class InRange(Constraint): + """Constraint class for "in_range" + + Constrains a property or parameter to a value in range of (inclusive) + the two values declared. + """ + UNBOUNDED = 'UNBOUNDED' + + constraint_key = Constraint.IN_RANGE + + valid_types = (int, float, datetime.date, + datetime.time, datetime.datetime, str) + + valid_prop_types = (Schema.INTEGER, Schema.FLOAT, Schema.TIMESTAMP, + Schema.SCALAR_UNIT_SIZE, Schema.SCALAR_UNIT_FREQUENCY, + Schema.SCALAR_UNIT_TIME, Schema.RANGE) + + def __init__(self, property_name, property_type, constraint): + super(InRange, self).__init__(property_name, property_type, constraint) + if(not isinstance(self.constraint_value, collections.Sequence) or + (len(constraint[self.IN_RANGE]) != 2)): + ExceptionCollector.appendException( + InvalidSchemaError(message=_('The property "in_range" ' + 'expects a list.'))) + + msg = _('The property "in_range" expects comparable values.') + for value in self.constraint_value: + if not isinstance(value, self.valid_types): + ExceptionCollector.appendException( + InvalidSchemaError(message=msg)) + # The only string we allow for range is the special value + # 'UNBOUNDED' + if(isinstance(value, str) and value != self.UNBOUNDED): + ExceptionCollector.appendException( + InvalidSchemaError(message=msg)) + + self.min = self.constraint_value[0] + self.max = self.constraint_value[1] + + def _is_valid(self, value): + if not isinstance(self.min, str): + if value < self.min: + return False + elif self.min != self.UNBOUNDED: + return False + if not isinstance(self.max, str): + if value > self.max: + return False + elif self.max != self.UNBOUNDED: + return False + return True + + def _err_msg(self, value): + return (_('The value "%(pvalue)s" of property "%(pname)s" is out of ' + 'range "(min:%(vmin)s, max:%(vmax)s)".') % + dict(pname=self.property_name, + pvalue=self.value_msg, + vmin=self.constraint_value_msg[0], + vmax=self.constraint_value_msg[1])) + + +class ValidValues(Constraint): + """Constraint class for "valid_values" + + Constrains a property or parameter to a value that is in the list of + declared values. + """ + constraint_key = Constraint.VALID_VALUES + + valid_prop_types = Schema.PROPERTY_TYPES + + def __init__(self, property_name, property_type, constraint): + super(ValidValues, self).__init__(property_name, property_type, + constraint) + if not isinstance(self.constraint_value, collections.Sequence): + ExceptionCollector.appendException( + InvalidSchemaError(message=_('The property "valid_values" ' + 'expects a list.'))) + + def _is_valid(self, value): + if isinstance(value, list): + return all(v in self.constraint_value for v in value) + return value in self.constraint_value + + def _err_msg(self, value): + allowed = '[%s]' % ', '.join(str(a) for a in self.constraint_value) + return (_('The value "%(pvalue)s" of property "%(pname)s" is not ' + 'valid. Expected a value from "%(cvalue)s".') % + dict(pname=self.property_name, + pvalue=value, + cvalue=allowed)) + + +class Length(Constraint): + """Constraint class for "length" + + Constrains the property or parameter to a value of a given length. + """ + + constraint_key = Constraint.LENGTH + + valid_types = (int, ) + + valid_prop_types = (Schema.STRING, ) + + def __init__(self, property_name, property_type, constraint): + super(Length, self).__init__(property_name, property_type, constraint) + if not isinstance(self.constraint_value, self.valid_types): + ExceptionCollector.appendException( + InvalidSchemaError(message=_('The property "length" expects ' + 'an integer.'))) + + def _is_valid(self, value): + if isinstance(value, str) and len(value) == self.constraint_value: + return True + + return False + + def _err_msg(self, value): + return (_('Length of value "%(pvalue)s" of property "%(pname)s" ' + 'must be equal to "%(cvalue)s".') % + dict(pname=self.property_name, + pvalue=value, + cvalue=self.constraint_value)) + + +class MinLength(Constraint): + """Constraint class for "min_length" + + Constrains the property or parameter to a value to a minimum length. + """ + + constraint_key = Constraint.MIN_LENGTH + + valid_types = (int, ) + + valid_prop_types = (Schema.STRING, Schema.MAP) + + def __init__(self, property_name, property_type, constraint): + super(MinLength, self).__init__(property_name, property_type, + constraint) + if not isinstance(self.constraint_value, self.valid_types): + ExceptionCollector.appendException( + InvalidSchemaError(message=_('The property "min_length" ' + 'expects an integer.'))) + + def _is_valid(self, value): + if ((isinstance(value, str) or isinstance(value, dict)) and + len(value) >= self.constraint_value): + return True + + return False + + def _err_msg(self, value): + return (_('Length of value "%(pvalue)s" of property "%(pname)s" ' + 'must be at least "%(cvalue)s".') % + dict(pname=self.property_name, + pvalue=value, + cvalue=self.constraint_value)) + + +class MaxLength(Constraint): + """Constraint class for "max_length" + + Constrains the property or parameter to a value to a maximum length. + """ + + constraint_key = Constraint.MAX_LENGTH + + valid_types = (int, ) + + valid_prop_types = (Schema.STRING, Schema.MAP) + + def __init__(self, property_name, property_type, constraint): + super(MaxLength, self).__init__(property_name, property_type, + constraint) + if not isinstance(self.constraint_value, self.valid_types): + ExceptionCollector.appendException( + InvalidSchemaError(message=_('The property "max_length" ' + 'expects an integer.'))) + + def _is_valid(self, value): + if ((isinstance(value, str) or isinstance(value, dict)) and + len(value) <= self.constraint_value): + return True + + return False + + def _err_msg(self, value): + return (_('Length of value "%(pvalue)s" of property "%(pname)s" ' + 'must be no greater than "%(cvalue)s".') % + dict(pname=self.property_name, + pvalue=value, + cvalue=self.constraint_value)) + + +class Pattern(Constraint): + """Constraint class for "pattern" + + Constrains the property or parameter to a value that is allowed by + the provided regular expression. + """ + + constraint_key = Constraint.PATTERN + + valid_types = (str, ) + + valid_prop_types = (Schema.STRING, ) + + def __init__(self, property_name, property_type, constraint): + super(Pattern, self).__init__(property_name, property_type, constraint) + if not isinstance(self.constraint_value, self.valid_types): + ExceptionCollector.appendException( + InvalidSchemaError(message=_('The property "pattern" ' + 'expects a string.'))) + self.match = re.compile(self.constraint_value).match + + def _is_valid(self, value): + match = self.match(value) + return match is not None and match.end() == len(value) + + def _err_msg(self, value): + return (_('The value "%(pvalue)s" of property "%(pname)s" does not ' + 'match pattern "%(cvalue)s".') % + dict(pname=self.property_name, + pvalue=value, + cvalue=self.constraint_value)) + + +constraint_mapping = { + Constraint.EQUAL: Equal, + Constraint.GREATER_THAN: GreaterThan, + Constraint.GREATER_OR_EQUAL: GreaterOrEqual, + Constraint.LESS_THAN: LessThan, + Constraint.LESS_OR_EQUAL: LessOrEqual, + Constraint.IN_RANGE: InRange, + Constraint.VALID_VALUES: ValidValues, + Constraint.LENGTH: Length, + Constraint.MIN_LENGTH: MinLength, + Constraint.MAX_LENGTH: MaxLength, + Constraint.PATTERN: Pattern + } + + +def get_constraint_class(type): + return constraint_mapping.get(type) diff --git a/nfvparser/toscaparser/elements/datatype.py b/nfvparser/toscaparser/elements/datatype.py new file mode 100644 index 0000000..93d1b3a --- /dev/null +++ b/nfvparser/toscaparser/elements/datatype.py @@ -0,0 +1,57 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + + +from toscaparser.elements.statefulentitytype import StatefulEntityType + + +class DataType(StatefulEntityType): + '''TOSCA built-in and user defined complex data type.''' + + def __init__(self, datatypename, custom_def=None): + super(DataType, self).__init__(datatypename, + self.DATATYPE_NETWORK_PREFIX, + custom_def) + self.custom_def = custom_def + + @property + def parent_type(self): + '''Return a datatype this datatype is derived from.''' + ptype = self.derived_from(self.defs) + if ptype: + return DataType(ptype, self.custom_def) + return None + + @property + def value_type(self): + '''Return 'type' section in the datatype schema.''' + return self.entity_value(self.defs, 'type') + + def get_all_properties_objects(self): + '''Return all properties objects defined in type and parent type.''' + props_def = self.get_properties_def_objects() + ptype = self.parent_type + while ptype: + props_def.extend(ptype.get_properties_def_objects()) + ptype = ptype.parent_type + return props_def + + def get_all_properties(self): + '''Return a dictionary of all property definition name-object pairs.''' + return {prop.name: prop + for prop in self.get_all_properties_objects()} + + def get_all_property_value(self, name): + '''Return the value of a given property name.''' + props_def = self.get_all_properties() + if props_def and name in props_def.key(): + return props_def[name].value diff --git a/nfvparser/toscaparser/elements/entity_type.py b/nfvparser/toscaparser/elements/entity_type.py new file mode 100644 index 0000000..9fd6c4d --- /dev/null +++ b/nfvparser/toscaparser/elements/entity_type.py @@ -0,0 +1,170 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import copy +import logging +import os +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import ValidationError +from toscaparser.extensions.exttools import ExtTools +import toscaparser.utils.yamlparser + +log = logging.getLogger('tosca') + + +class EntityType(object): + '''Base class for TOSCA elements.''' + + SECTIONS = (DERIVED_FROM, PROPERTIES, ATTRIBUTES, REQUIREMENTS, + INTERFACES, CAPABILITIES, TYPE, ARTIFACTS) = \ + ('derived_from', 'properties', 'attributes', 'requirements', + 'interfaces', 'capabilities', 'type', 'artifacts') + + TOSCA_DEF_SECTIONS = ['node_types', 'data_types', 'artifact_types', + 'group_types', 'relationship_types', + 'capability_types', 'interface_types', + 'policy_types'] + + '''TOSCA definition file.''' + TOSCA_DEF_FILE = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "TOSCA_definition_1_0.yaml") + + loader = toscaparser.utils.yamlparser.load_yaml + + TOSCA_DEF_LOAD_AS_IS = loader(TOSCA_DEF_FILE) + + # Map of definition with pre-loaded values of TOSCA_DEF_FILE_SECTIONS + TOSCA_DEF = {} + for section in TOSCA_DEF_SECTIONS: + if section in TOSCA_DEF_LOAD_AS_IS.keys(): + value = TOSCA_DEF_LOAD_AS_IS[section] + for key in value.keys(): + TOSCA_DEF[key] = value[key] + + RELATIONSHIP_TYPE = (DEPENDSON, HOSTEDON, CONNECTSTO, ATTACHESTO, + LINKSTO, BINDSTO) = \ + ('tosca.relationships.DependsOn', + 'tosca.relationships.HostedOn', + 'tosca.relationships.ConnectsTo', + 'tosca.relationships.AttachesTo', + 'tosca.relationships.network.LinksTo', + 'tosca.relationships.network.BindsTo') + + NODE_PREFIX = 'tosca.nodes.' + RELATIONSHIP_PREFIX = 'tosca.relationships.' + CAPABILITY_PREFIX = 'tosca.capabilities.' + INTERFACE_PREFIX = 'tosca.interfaces.' + ARTIFACT_PREFIX = 'tosca.artifacts.' + POLICY_PREFIX = 'tosca.policies.' + GROUP_PREFIX = 'tosca.groups.' + # currently the data types are defined only for network + # but may have changes in the future. + DATATYPE_PREFIX = 'tosca.datatypes.' + DATATYPE_NETWORK_PREFIX = DATATYPE_PREFIX + 'network.' + TOSCA = 'tosca' + + def derived_from(self, defs): + '''Return a type this type is derived from.''' + return self.entity_value(defs, 'derived_from') + + def is_derived_from(self, type_str): + '''Check if object inherits from the given type. + + Returns true if this object is derived from 'type_str'. + False otherwise. + ''' + if not self.type: + return False + elif self.type == type_str: + return True + elif self.parent_type: + return self.parent_type.is_derived_from(type_str) + else: + return False + + def entity_value(self, defs, key): + if defs and key in defs: + return defs[key] + + def get_value(self, ndtype, defs=None, parent=None): + value = None + if defs is None: + if not hasattr(self, 'defs'): + return None + defs = self.defs + if defs and ndtype in defs: + # copy the value to avoid that next operations add items in the + # item definitions + value = copy.copy(defs[ndtype]) + if parent: + p = self + if p: + while p: + if p.defs and ndtype in p.defs: + # get the parent value + parent_value = p.defs[ndtype] + if value: + if isinstance(value, dict): + for k, v in parent_value.items(): + if k not in value.keys(): + value[k] = v + if isinstance(value, list): + for p_value in parent_value: + if isinstance(p_value, dict): + if list(p_value.keys())[0] not in [ + list(item.keys())[0] for item in + value]: + value.append(p_value) + else: + if p_value not in value: + value.append(p_value) + else: + value = copy.copy(parent_value) + p = p.parent_type + return value + + def get_definition(self, ndtype): + value = None + if not hasattr(self, 'defs'): + defs = None + ExceptionCollector.appendException( + ValidationError(message="defs is " + str(defs))) + else: + defs = self.defs + if defs is not None and ndtype in defs: + value = defs[ndtype] + p = self.parent_type + if p: + inherited = p.get_definition(ndtype) + if inherited: + inherited = dict(inherited) + if not value: + value = inherited + else: + inherited.update(value) + value.update(inherited) + return value + + +def update_definitions(version): + exttools = ExtTools() + extension_defs_file = exttools.get_defs_file(version) + loader = toscaparser.utils.yamlparser.load_yaml + nfv_def_file = loader(extension_defs_file) + nfv_def = {} + for section in EntityType.TOSCA_DEF_SECTIONS: + if section in nfv_def_file.keys(): + value = nfv_def_file[section] + for key in value.keys(): + nfv_def[key] = value[key] + EntityType.TOSCA_DEF.update(nfv_def) diff --git a/nfvparser/toscaparser/elements/grouptype.py b/nfvparser/toscaparser/elements/grouptype.py new file mode 100644 index 0000000..4e58d64 --- /dev/null +++ b/nfvparser/toscaparser/elements/grouptype.py @@ -0,0 +1,95 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import InvalidTypeError +from toscaparser.common.exception import UnknownFieldError +from toscaparser.elements.statefulentitytype import StatefulEntityType + + +class GroupType(StatefulEntityType): + '''TOSCA built-in group type.''' + + SECTIONS = (DERIVED_FROM, VERSION, METADATA, DESCRIPTION, PROPERTIES, + MEMBERS, INTERFACES) = \ + ("derived_from", "version", "metadata", "description", + "properties", "members", "interfaces") + + def __init__(self, grouptype, custom_def=None): + super(GroupType, self).__init__(grouptype, self.GROUP_PREFIX, + custom_def) + self.custom_def = custom_def + self.grouptype = grouptype + self._validate_fields() + self.group_description = None + if self.DESCRIPTION in self.defs: + self.group_description = self.defs[self.DESCRIPTION] + + self.group_version = None + if self.VERSION in self.defs: + self.group_version = self.defs[self.VERSION] + + self.group_properties = None + if self.PROPERTIES in self.defs: + self.group_properties = self.defs[self.PROPERTIES] + + self.group_members = None + if self.MEMBERS in self.defs: + self.group_members = self.defs[self.MEMBERS] + + if self.METADATA in self.defs: + self.meta_data = self.defs[self.METADATA] + self._validate_metadata(self.meta_data) + + @property + def parent_type(self): + '''Return a group statefulentity of this entity is derived from.''' + if not hasattr(self, 'defs'): + return None + pgroup_entity = self.derived_from(self.defs) + if pgroup_entity: + return GroupType(pgroup_entity, self.custom_def) + + @property + def description(self): + return self.group_description + + @property + def version(self): + return self.group_version + + @property + def interfaces(self): + return self.get_value(self.INTERFACES) + + def _validate_fields(self): + if self.defs: + for name in self.defs.keys(): + if name not in self.SECTIONS: + ExceptionCollector.appendException( + UnknownFieldError(what='Group Type %s' + % self.grouptype, field=name)) + + def _validate_metadata(self, meta_data): + if not meta_data.get('type') in ['map', 'tosca:map']: + ExceptionCollector.appendException( + InvalidTypeError(what='"%s" defined in group for ' + 'metadata' % (meta_data.get('type')))) + for entry_schema, entry_schema_type in meta_data.items(): + if isinstance(entry_schema_type, dict) and not \ + entry_schema_type.get('type') == 'string': + ExceptionCollector.appendException( + InvalidTypeError(what='"%s" defined in group for ' + 'metadata "%s"' + % (entry_schema_type.get('type'), + entry_schema))) diff --git a/nfvparser/toscaparser/elements/interfaces.py b/nfvparser/toscaparser/elements/interfaces.py new file mode 100644 index 0000000..47ec90a --- /dev/null +++ b/nfvparser/toscaparser/elements/interfaces.py @@ -0,0 +1,87 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import UnknownFieldError +from toscaparser.elements.statefulentitytype import StatefulEntityType + +SECTIONS = (LIFECYCLE, CONFIGURE, LIFECYCLE_SHORTNAME, + CONFIGURE_SHORTNAME) = \ + ('tosca.interfaces.node.lifecycle.Standard', + 'tosca.interfaces.relationship.Configure', + 'Standard', 'Configure') + +INTERFACEVALUE = (IMPLEMENTATION, INPUTS) = ('implementation', 'inputs') + +INTERFACE_DEF_RESERVED_WORDS = ['type', 'inputs', 'derived_from', 'version', + 'description'] + + +class InterfacesDef(StatefulEntityType): + '''TOSCA built-in interfaces type.''' + + def __init__(self, node_type, interfacetype, + node_template=None, name=None, value=None): + self.ntype = node_type + self.node_template = node_template + self.type = interfacetype + self.name = name + self.value = value + self.implementation = None + self.inputs = None + self.defs = {} + if interfacetype == LIFECYCLE_SHORTNAME: + interfacetype = LIFECYCLE + if interfacetype == CONFIGURE_SHORTNAME: + interfacetype = CONFIGURE + if hasattr(self.ntype, 'interfaces') \ + and self.ntype.interfaces \ + and interfacetype in self.ntype.interfaces: + interfacetype = self.ntype.interfaces[interfacetype]['type'] + if node_type: + if self.node_template and self.node_template.custom_def \ + and interfacetype in self.node_template.custom_def: + self.defs = self.node_template.custom_def[interfacetype] + else: + self.defs = self.TOSCA_DEF[interfacetype] + if value: + if isinstance(self.value, dict): + for i, j in self.value.items(): + if i == IMPLEMENTATION: + self.implementation = j + elif i == INPUTS: + self.inputs = j + else: + what = ('"interfaces" of template "%s"' % + self.node_template.name) + ExceptionCollector.appendException( + UnknownFieldError(what=what, field=i)) + else: + self.implementation = value + + @property + def lifecycle_ops(self): + if self.defs: + if self.type == LIFECYCLE: + return self._ops() + + @property + def configure_ops(self): + if self.defs: + if self.type == CONFIGURE: + return self._ops() + + def _ops(self): + ops = [] + for name in list(self.defs.keys()): + ops.append(name) + return ops diff --git a/nfvparser/toscaparser/elements/nodetype.py b/nfvparser/toscaparser/elements/nodetype.py new file mode 100644 index 0000000..7f3da2d --- /dev/null +++ b/nfvparser/toscaparser/elements/nodetype.py @@ -0,0 +1,213 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import UnknownFieldError +from toscaparser.elements.capabilitytype import CapabilityTypeDef +import toscaparser.elements.interfaces as ifaces +from toscaparser.elements.interfaces import InterfacesDef +from toscaparser.elements.relationshiptype import RelationshipType +from toscaparser.elements.statefulentitytype import StatefulEntityType + + +class NodeType(StatefulEntityType): + '''TOSCA built-in node type.''' + SECTIONS = (DERIVED_FROM, METADATA, PROPERTIES, VERSION, DESCRIPTION, ATTRIBUTES, REQUIREMENTS, CAPABILITIES, INTERFACES, ARTIFACTS) = \ + ('derived_from', 'metadata', 'properties', 'version', + 'description', 'attributes', 'requirements', 'capabilities', + 'interfaces', 'artifacts') + + def __init__(self, ntype, custom_def=None): + super(NodeType, self).__init__(ntype, self.NODE_PREFIX, custom_def) + self.ntype = ntype + self.custom_def = custom_def + self._validate_keys() + + @property + def parent_type(self): + '''Return a node this node is derived from.''' + if not hasattr(self, 'defs'): + return None + pnode = self.derived_from(self.defs) + if pnode: + return NodeType(pnode, self.custom_def) + + @property + def relationship(self): + '''Return a dictionary of relationships to other node types. + + This method returns a dictionary of named relationships that nodes + of the current node type (self) can have to other nodes (of specific + types) in a TOSCA template. + + ''' + relationship = {} + requires = self.get_all_requirements() + if requires: + # NOTE(sdmonov): Check if requires is a dict. + # If it is a dict convert it to a list of dicts. + # This is needed because currently the code below supports only + # lists as requirements definition. The following check will + # make sure if a map (dict) was provided it will be converted to + # a list before proceeding to the parsing. + if isinstance(requires, dict): + requires = [{key: value} for key, value in requires.items()] + + keyword = None + node_type = None + for require in requires: + for key, req in require.items(): + if 'relationship' in req: + relation = req.get('relationship') + if 'type' in relation: + relation = relation.get('type') + node_type = req.get('node') + value = req + if node_type: + keyword = 'node' + else: + # If value is a dict and has a type key + # we need to lookup the node type using + # the capability type + value = req + if isinstance(value, dict): + captype = value['capability'] + value = (self. + _get_node_type_by_cap(captype)) + # _get_node_type_by_cap(key, captype)) + # relation = self._get_relation(key, value) + keyword = key + node_type = value + rtype = RelationshipType(relation, keyword, self.custom_def) + relatednode = NodeType(node_type, self.custom_def) + relationship[rtype] = relatednode + return relationship + + def _get_node_type_by_cap(self, cap): + '''Find the node type that has the provided capability + + This method will lookup all node types if they have the + provided capability. + ''' + + # Filter the node types + node_types = [node_type for node_type in self.TOSCA_DEF.keys() + if node_type.startswith(self.NODE_PREFIX) and + node_type != 'tosca.nodes.Root'] + custom_node_types = [node_type for node_type in self.custom_def.keys() + if node_type.startswith(self.NODE_PREFIX) and + node_type != 'tosca.nodes.Root'] + + for node_type in node_types + custom_node_types: + if node_type in self.TOSCA_DEF: + node_def = self.TOSCA_DEF[node_type] + else: + node_def = self.custom_def[node_type] + if isinstance(node_def, dict) and 'capabilities' in node_def: + node_caps = node_def['capabilities'] + for value in node_caps.values(): + if isinstance(value, dict) and \ + 'type' in value and value['type'] == cap: + return node_type + + def _get_relation(self, key, ndtype): + relation = None + ntype = NodeType(ndtype, self.custom_def) + caps = ntype.get_capabilities() + if caps and key in caps.keys(): + c = caps[key] + for r in self.RELATIONSHIP_TYPE: + rtypedef = ntype.TOSCA_DEF[r] + for properties in rtypedef.values(): + if c.type in properties: + relation = r + break + if relation: + break + else: + for properties in rtypedef.values(): + if c.parent_type in properties: + relation = r + break + return relation + + def get_capabilities_objects(self): + '''Return a list of capability objects.''' + typecapabilities = [] + caps = self.get_value(self.CAPABILITIES, None, True) + if caps: + # 'name' is symbolic name of the capability + # 'value' is a dict { 'type': } + for name, value in caps.items(): + ctype = value.get('type') + cap = CapabilityTypeDef(name, ctype, self.type, + self.custom_def) + typecapabilities.append(cap) + return typecapabilities + + def get_capabilities(self): + '''Return a dictionary of capability name-objects pairs.''' + return {cap.name: cap + for cap in self.get_capabilities_objects()} + + @property + def requirements(self): + return self.get_value(self.REQUIREMENTS, None, True) + + def get_all_requirements(self): + return self.requirements + + @property + def interfaces(self): + return self.get_value(self.INTERFACES) + + @property + def lifecycle_inputs(self): + '''Return inputs to life cycle operations if found.''' + inputs = [] + interfaces = self.interfaces + if interfaces: + for name, value in interfaces.items(): + if name == ifaces.LIFECYCLE: + for x, y in value.items(): + if x == 'inputs': + for i in y.iterkeys(): + inputs.append(i) + return inputs + + @property + def lifecycle_operations(self): + '''Return available life cycle operations if found.''' + ops = None + interfaces = self.interfaces + if interfaces: + i = InterfacesDef(self.type, ifaces.LIFECYCLE) + ops = i.lifecycle_ops + return ops + + def get_capability(self, name): + caps = self.get_capabilities() + if caps and name in caps.keys(): + return caps[name].value + + def get_capability_type(self, name): + captype = self.get_capability(name) + if captype and name in captype.keys(): + return captype[name].value + + def _validate_keys(self): + if self.defs: + for key in self.defs.keys(): + if key not in self.SECTIONS: + ExceptionCollector.appendException( + UnknownFieldError(what='Nodetype"%s"' % self.ntype, + field=key)) diff --git a/nfvparser/toscaparser/elements/policytype.py b/nfvparser/toscaparser/elements/policytype.py new file mode 100644 index 0000000..a922d26 --- /dev/null +++ b/nfvparser/toscaparser/elements/policytype.py @@ -0,0 +1,121 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import InvalidTypeError +from toscaparser.common.exception import UnknownFieldError +from toscaparser.elements.statefulentitytype import StatefulEntityType +from toscaparser.utils.validateutils import TOSCAVersionProperty + + +class PolicyType(StatefulEntityType): + + '''TOSCA built-in policies type.''' + SECTIONS = (DERIVED_FROM, METADATA, PROPERTIES, VERSION, DESCRIPTION, + TARGETS, TRIGGERS, TYPE) = \ + ('derived_from', 'metadata', 'properties', 'version', + 'description', 'targets', 'triggers', 'type') + + def __init__(self, ptype, custom_def=None): + super(PolicyType, self).__init__(ptype, self.POLICY_PREFIX, + custom_def) + self.type = ptype + self.custom_def = custom_def + self._validate_keys() + + self.meta_data = None + if self.METADATA in self.defs: + self.meta_data = self.defs[self.METADATA] + self._validate_metadata(self.meta_data) + + self.properties = None + if self.PROPERTIES in self.defs: + self.properties = self.defs[self.PROPERTIES] + self.parent_policies = self._get_parent_policies() + + self.policy_version = None + if self.VERSION in self.defs: + self.policy_version = TOSCAVersionProperty( + self.defs[self.VERSION]).get_version() + + self.policy_description = self.defs[self.DESCRIPTION] \ + if self.DESCRIPTION in self.defs else None + + self.targets_list = None + if self.TARGETS in self.defs: + self.targets_list = self.defs[self.TARGETS] + self._validate_targets(self.targets_list, custom_def) + + def _get_parent_policies(self): + policies = {} + parent_policy = self.parent_type.type if self.parent_type else None + if parent_policy: + while parent_policy != 'tosca.policies.Root': + policies[parent_policy] = self.TOSCA_DEF[parent_policy] + parent_policy = policies[parent_policy]['derived_from'] + return policies + + @property + def parent_type(self): + '''Return a policy statefulentity of this node is derived from.''' + if not hasattr(self, 'defs'): + return None + ppolicy_entity = self.derived_from(self.defs) + if ppolicy_entity: + return PolicyType(ppolicy_entity, self.custom_def) + + def get_policy(self, name): + '''Return the definition of a policy field by name.''' + if name in self.defs: + return self.defs[name] + + @property + def targets(self): + '''Return targets.''' + return self.targets_list + + @property + def description(self): + return self.policy_description + + @property + def version(self): + return self.policy_version + + def _validate_keys(self): + for key in self.defs.keys(): + if key not in self.SECTIONS: + ExceptionCollector.appendException( + UnknownFieldError(what='Policy "%s"' % self.type, + field=key)) + + def _validate_targets(self, targets_list, custom_def): + for nodetype in targets_list: + if nodetype not in custom_def: + ExceptionCollector.appendException( + InvalidTypeError(what='"%s" defined in targets for ' + 'policy "%s"' % (nodetype, self.type))) + + def _validate_metadata(self, meta_data): + if not meta_data.get('type') in ['map', 'tosca:map']: + ExceptionCollector.appendException( + InvalidTypeError(what='"%s" defined in policy for ' + 'metadata' % (meta_data.get('type')))) + + for entry_schema, entry_schema_type in meta_data.items(): + if isinstance(entry_schema_type, dict) and not \ + entry_schema_type.get('type') == 'string': + ExceptionCollector.appendException( + InvalidTypeError(what='"%s" defined in policy for ' + 'metadata "%s"' + % (entry_schema_type.get('type'), + entry_schema))) diff --git a/nfvparser/toscaparser/elements/portspectype.py b/nfvparser/toscaparser/elements/portspectype.py new file mode 100644 index 0000000..0218305 --- /dev/null +++ b/nfvparser/toscaparser/elements/portspectype.py @@ -0,0 +1,86 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import logging + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import InvalidTypeAdditionalRequirementsError +from toscaparser.utils.gettextutils import _ +import toscaparser.utils.validateutils as validateutils + +log = logging.getLogger('tosca') + + +class PortSpec(object): + '''Parent class for tosca.datatypes.network.PortSpec type.''' + + SHORTNAME = 'PortSpec' + TYPE_URI = 'tosca.datatypes.network.' + SHORTNAME + + PROPERTY_NAMES = ( + PROTOCOL, SOURCE, SOURCE_RANGE, + TARGET, TARGET_RANGE + ) = ( + 'protocol', 'source', 'source_range', + 'target', 'target_range' + ) + + # TODO(TBD) May want to make this a subclass of DataType + # and change init method to set PortSpec's properties + def __init__(self): + pass + + # The following additional requirements MUST be tested: + # 1) A valid PortSpec MUST have at least one of the following properties: + # target, target_range, source or source_range. + # 2) A valid PortSpec MUST have a value for the source property that + # is within the numeric range specified by the property source_range + # when source_range is specified. + # 3) A valid PortSpec MUST have a value for the target property that is + # within the numeric range specified by the property target_range + # when target_range is specified. + @staticmethod + def validate_additional_req(properties, prop_name, custom_def=None, ): + try: + source = properties.get(PortSpec.SOURCE) + source_range = properties.get(PortSpec.SOURCE_RANGE) + target = properties.get(PortSpec.TARGET) + target_range = properties.get(PortSpec.TARGET_RANGE) + + # verify one of the specified values is set + if source is None and source_range is None and \ + target is None and target_range is None: + ExceptionCollector.appendException( + InvalidTypeAdditionalRequirementsError( + type=PortSpec.TYPE_URI)) + # Validate source value is in specified range + if source and source_range: + validateutils.validate_value_in_range(source, source_range, + PortSpec.SOURCE) + else: + from toscaparser.dataentity import DataEntity + portdef = DataEntity('PortDef', source, None, PortSpec.SOURCE) + portdef.validate() + # Validate target value is in specified range + if target and target_range: + validateutils.validate_value_in_range(target, target_range, + PortSpec.TARGET) + else: + from toscaparser.dataentity import DataEntity + portdef = DataEntity('PortDef', source, None, PortSpec.TARGET) + portdef.validate() + except Exception: + msg = _('"%(value)s" do not meet requirements ' + 'for type "%(type)s".') \ + % {'value': properties, 'type': PortSpec.SHORTNAME} + ExceptionCollector.appendException( + ValueError(msg)) diff --git a/nfvparser/toscaparser/elements/property_definition.py b/nfvparser/toscaparser/elements/property_definition.py new file mode 100644 index 0000000..a242ddf --- /dev/null +++ b/nfvparser/toscaparser/elements/property_definition.py @@ -0,0 +1,100 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import InvalidSchemaError +from toscaparser.common.exception import TOSCAException +from toscaparser.utils.gettextutils import _ + + +class PropertyDef(object): + '''TOSCA built-in Property type.''' + + VALID_PROPERTY_KEYNAMES = (PROPERTY_KEYNAME_DEFAULT, + PROPERTY_KEYNAME_REQUIRED, + PROPERTY_KEYNAME_STATUS) = \ + ('default', 'required', 'status') + + PROPERTY_REQUIRED_DEFAULT = True + + VALID_REQUIRED_VALUES = ['true', 'false'] + VALID_STATUS_VALUES = (PROPERTY_STATUS_SUPPORTED, + PROPERTY_STATUS_EXPERIMENTAL) = \ + ('supported', 'experimental') + + PROPERTY_STATUS_DEFAULT = PROPERTY_STATUS_SUPPORTED + + def __init__(self, name, value=None, schema=None): + self.name = name + self.value = value + self.schema = schema + self._status = self.PROPERTY_STATUS_DEFAULT + self._required = self.PROPERTY_REQUIRED_DEFAULT + + # Validate required 'type' property exists + try: + self.schema['type'] + except KeyError: + msg = (_('Schema definition of "%(pname)s" must have a "type" ' + 'attribute.') % dict(pname=self.name)) + ExceptionCollector.appendException( + InvalidSchemaError(message=msg)) + + if self.schema: + self._load_required_attr_from_schema() + self._load_status_attr_from_schema() + + @property + def default(self): + if self.schema: + for prop_key, prop_value in self.schema.items(): + if prop_key == self.PROPERTY_KEYNAME_DEFAULT: + return prop_value + return None + + @property + def required(self): + return self._required + + def _load_required_attr_from_schema(self): + # IF 'required' keyname exists verify it's a boolean, + # if so override default + if self.PROPERTY_KEYNAME_REQUIRED in self.schema: + value = self.schema[self.PROPERTY_KEYNAME_REQUIRED] + if isinstance(value, bool): + self._required = value + else: + valid_values = ', '.join(self.VALID_REQUIRED_VALUES) + attr = self.PROPERTY_KEYNAME_REQUIRED + TOSCAException.generate_inv_schema_property_error(self, + attr, + value, + valid_values) + + @property + def status(self): + return self._status + + def _load_status_attr_from_schema(self): + # IF 'status' keyname exists verify it's a valid value, + # if so override default + if self.PROPERTY_KEYNAME_STATUS in self.schema: + value = self.schema[self.PROPERTY_KEYNAME_STATUS] + if value in self.VALID_STATUS_VALUES: + self._status = value + else: + valid_values = ', '.join(self.VALID_STATUS_VALUES) + attr = self.PROPERTY_KEYNAME_STATUS + TOSCAException.generate_inv_schema_property_error(self, + attr, + value, + valid_values) diff --git a/nfvparser/toscaparser/elements/relationshiptype.py b/nfvparser/toscaparser/elements/relationshiptype.py new file mode 100644 index 0000000..8eefbea --- /dev/null +++ b/nfvparser/toscaparser/elements/relationshiptype.py @@ -0,0 +1,49 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import UnknownFieldError +from toscaparser.elements.statefulentitytype import StatefulEntityType + + +class RelationshipType(StatefulEntityType): + '''TOSCA built-in relationship type.''' + SECTIONS = (DERIVED_FROM, VALID_TARGET_TYPES, INTERFACES, + ATTRIBUTES, PROPERTIES, DESCRIPTION, VERSION, + CREDENTIAL) = ('derived_from', 'valid_target_types', + 'interfaces', 'attributes', 'properties', + 'description', 'version', 'credential') + + def __init__(self, type, capability_name=None, custom_def=None): + super(RelationshipType, self).__init__(type, self.RELATIONSHIP_PREFIX, + custom_def) + self.capability_name = capability_name + self.custom_def = custom_def + self._validate_keys() + + @property + def parent_type(self): + '''Return a relationship this reletionship is derived from.''' + prel = self.derived_from(self.defs) + if prel: + return RelationshipType(prel, self.custom_def) + + @property + def valid_target_types(self): + return self.entity_value(self.defs, 'valid_target_types') + + def _validate_keys(self): + for key in self.defs.keys(): + if key not in self.SECTIONS: + ExceptionCollector.appendException( + UnknownFieldError(what='Relationshiptype "%s"' % self.type, + field=key)) diff --git a/nfvparser/toscaparser/elements/scalarunit.py b/nfvparser/toscaparser/elements/scalarunit.py new file mode 100644 index 0000000..d7f72e6 --- /dev/null +++ b/nfvparser/toscaparser/elements/scalarunit.py @@ -0,0 +1,129 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import logging +import re + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.utils.gettextutils import _ +from toscaparser.utils import validateutils + +log = logging.getLogger('tosca') + + +class ScalarUnit(object): + '''Parent class for scalar-unit type.''' + + SCALAR_UNIT_TYPES = ( + SCALAR_UNIT_SIZE, SCALAR_UNIT_FREQUENCY, SCALAR_UNIT_TIME + ) = ( + 'scalar-unit.size', 'scalar-unit.frequency', 'scalar-unit.time' + ) + + def __init__(self, value): + self.value = value + + def _check_unit_in_scalar_standard_units(self, input_unit): + """Check whether the input unit is following specified standard + + If unit is not following specified standard, convert it to standard + unit after displaying a warning message. + """ + if input_unit in self.SCALAR_UNIT_DICT.keys(): + return input_unit + else: + for key in self.SCALAR_UNIT_DICT.keys(): + if key.upper() == input_unit.upper(): + log.warning(_('The unit "%(unit)s" does not follow ' + 'scalar unit standards; using "%(key)s" ' + 'instead.') % {'unit': input_unit, + 'key': key}) + return key + msg = (_('The unit "%(unit)s" is not valid. Valid units are ' + '"%(valid_units)s".') % + {'unit': input_unit, + 'valid_units': sorted(self.SCALAR_UNIT_DICT.keys())}) + ExceptionCollector.appendException(ValueError(msg)) + + def validate_scalar_unit(self): + regex = re.compile('([0-9.]+)\s*(\w+)') + try: + result = regex.match(str(self.value)).groups() + validateutils.str_to_num(result[0]) + scalar_unit = self._check_unit_in_scalar_standard_units(result[1]) + self.value = ' '.join([result[0], scalar_unit]) + return self.value + + except Exception: + ExceptionCollector.appendException( + ValueError(_('"%s" is not a valid scalar-unit.') + % self.value)) + + def get_num_from_scalar_unit(self, unit=None): + if unit: + unit = self._check_unit_in_scalar_standard_units(unit) + else: + unit = self.SCALAR_UNIT_DEFAULT + self.validate_scalar_unit() + + regex = re.compile('([0-9.]+)\s*(\w+)') + result = regex.match(str(self.value)).groups() + converted = (float(validateutils.str_to_num(result[0])) + * self.SCALAR_UNIT_DICT[result[1]] + / self.SCALAR_UNIT_DICT[unit]) + if converted - int(converted) < 0.0000000000001: + converted = int(converted) + return converted + + +class ScalarUnit_Size(ScalarUnit): + + SCALAR_UNIT_DEFAULT = 'B' + SCALAR_UNIT_DICT = {'B': 1, 'kB': 1000, 'KiB': 1024, 'MB': 1000000, + 'MiB': 1048576, 'GB': 1000000000, + 'GiB': 1073741824, 'TB': 1000000000000, + 'TiB': 1099511627776} + + +class ScalarUnit_Time(ScalarUnit): + + SCALAR_UNIT_DEFAULT = 'ms' + SCALAR_UNIT_DICT = {'d': 86400, 'h': 3600, 'm': 60, 's': 1, + 'ms': 0.001, 'us': 0.000001, 'ns': 0.000000001} + + +class ScalarUnit_Frequency(ScalarUnit): + + SCALAR_UNIT_DEFAULT = 'GHz' + SCALAR_UNIT_DICT = {'Hz': 1, 'kHz': 1000, + 'MHz': 1000000, 'GHz': 1000000000} + + +scalarunit_mapping = { + ScalarUnit.SCALAR_UNIT_FREQUENCY: ScalarUnit_Frequency, + ScalarUnit.SCALAR_UNIT_SIZE: ScalarUnit_Size, + ScalarUnit.SCALAR_UNIT_TIME: ScalarUnit_Time, + } + + +def get_scalarunit_class(type): + return scalarunit_mapping.get(type) + + +def get_scalarunit_value(type, value, unit=None): + if type in ScalarUnit.SCALAR_UNIT_TYPES: + ScalarUnit_Class = get_scalarunit_class(type) + return (ScalarUnit_Class(value). + get_num_from_scalar_unit(unit)) + else: + ExceptionCollector.appendException( + TypeError(_('"%s" is not a valid scalar-unit type.') % type)) diff --git a/nfvparser/toscaparser/elements/statefulentitytype.py b/nfvparser/toscaparser/elements/statefulentitytype.py new file mode 100644 index 0000000..2f221b3 --- /dev/null +++ b/nfvparser/toscaparser/elements/statefulentitytype.py @@ -0,0 +1,91 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import InvalidTypeError +from toscaparser.elements.attribute_definition import AttributeDef +from toscaparser.elements.entity_type import EntityType +from toscaparser.elements.property_definition import PropertyDef +from toscaparser.unsupportedtype import UnsupportedType + + +class StatefulEntityType(EntityType): + '''Class representing TOSCA states.''' + + interfaces_node_lifecycle_operations = ['create', + 'configure', 'start', + 'stop', 'delete'] + + interfaces_relationship_configure_operations = ['post_configure_source', + 'post_configure_target', + 'add_target', + 'remove_target'] + + def __init__(self, entitytype, prefix, custom_def=None): + entire_entitytype = entitytype + if UnsupportedType.validate_type(entire_entitytype): + self.defs = None + else: + if entitytype.startswith(self.TOSCA + ":"): + entitytype = entitytype[(len(self.TOSCA) + 1):] + entire_entitytype = prefix + entitytype + if not entitytype.startswith(self.TOSCA): + entire_entitytype = prefix + entitytype + if entire_entitytype in list(self.TOSCA_DEF.keys()): + self.defs = self.TOSCA_DEF[entire_entitytype] + entitytype = entire_entitytype + elif custom_def and entitytype in list(custom_def.keys()): + self.defs = custom_def[entitytype] + else: + self.defs = None + ExceptionCollector.appendException( + InvalidTypeError(what=entitytype)) + self.type = entitytype + + def get_properties_def_objects(self): + '''Return a list of property definition objects.''' + properties = [] + props = self.get_definition(self.PROPERTIES) + if props: + for prop, schema in props.items(): + properties.append(PropertyDef(prop, None, schema)) + return properties + + def get_properties_def(self): + '''Return a dictionary of property definition name-object pairs.''' + return {prop.name: prop + for prop in self.get_properties_def_objects()} + + def get_property_def_value(self, name): + '''Return the property definition associated with a given name.''' + props_def = self.get_properties_def() + if props_def and name in props_def.keys(): + return props_def[name].value + + def get_attributes_def_objects(self): + '''Return a list of attribute definition objects.''' + attrs = self.get_value(self.ATTRIBUTES, parent=True) + if attrs: + return [AttributeDef(attr, None, schema) + for attr, schema in attrs.items()] + return [] + + def get_attributes_def(self): + '''Return a dictionary of attribute definition name-object pairs.''' + return {attr.name: attr + for attr in self.get_attributes_def_objects()} + + def get_attribute_def_value(self, name): + '''Return the attribute definition associated with a given name.''' + attrs_def = self.get_attributes_def() + if attrs_def and name in attrs_def.keys(): + return attrs_def[name].value diff --git a/nfvparser/toscaparser/elements/tosca_type_validation.py b/nfvparser/toscaparser/elements/tosca_type_validation.py new file mode 100644 index 0000000..82b0b46 --- /dev/null +++ b/nfvparser/toscaparser/elements/tosca_type_validation.py @@ -0,0 +1,59 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import InvalidTemplateVersion +from toscaparser.common.exception import UnknownFieldError +from toscaparser.extensions.exttools import ExtTools + + +class TypeValidation(object): + + ALLOWED_TYPE_SECTIONS = (DEFINITION_VERSION, DESCRIPTION, IMPORTS, + DSL_DEFINITIONS, NODE_TYPES, REPOSITORIES, + DATA_TYPES, ARTIFACT_TYPES, GROUP_TYPES, + RELATIONSHIP_TYPES, CAPABILITY_TYPES, + INTERFACE_TYPES, POLICY_TYPES, + TOPOLOGY_TEMPLATE) = \ + ('tosca_definitions_version', 'description', 'imports', + 'dsl_definitions', 'node_types', 'repositories', + 'data_types', 'artifact_types', 'group_types', + 'relationship_types', 'capability_types', + 'interface_types', 'policy_types', 'topology_template') + VALID_TEMPLATE_VERSIONS = ['tosca_simple_yaml_1_0'] + exttools = ExtTools() + VALID_TEMPLATE_VERSIONS.extend(exttools.get_versions()) + + def __init__(self, custom_types, import_def): + self.import_def = import_def + self._validate_type_keys(custom_types) + + def _validate_type_keys(self, custom_type): + version = custom_type[self.DEFINITION_VERSION] \ + if self.DEFINITION_VERSION in custom_type \ + else None + if version: + self._validate_type_version(version) + self.version = version + + for name in custom_type: + if name not in self.ALLOWED_TYPE_SECTIONS: + ExceptionCollector.appendException( + UnknownFieldError(what='Template ' + (self.import_def), + field=name)) + + def _validate_type_version(self, version): + if version not in self.VALID_TEMPLATE_VERSIONS: + ExceptionCollector.appendException( + InvalidTemplateVersion( + what=version + ' in ' + self.import_def, + valid_versions=', '. join(self.VALID_TEMPLATE_VERSIONS))) diff --git a/nfvparser/toscaparser/entity_template.py b/nfvparser/toscaparser/entity_template.py new file mode 100644 index 0000000..cc3d620 --- /dev/null +++ b/nfvparser/toscaparser/entity_template.py @@ -0,0 +1,329 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from toscaparser.capabilities import Capability +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import MissingRequiredFieldError +from toscaparser.common.exception import UnknownFieldError +from toscaparser.common.exception import ValidationError +from toscaparser.elements.grouptype import GroupType +from toscaparser.elements.interfaces import InterfacesDef +from toscaparser.elements.nodetype import NodeType +from toscaparser.elements.policytype import PolicyType +from toscaparser.elements.relationshiptype import RelationshipType +from toscaparser.properties import Property +from toscaparser.unsupportedtype import UnsupportedType +from toscaparser.utils.gettextutils import _ + + +class EntityTemplate(object): + '''Base class for TOSCA templates.''' + + SECTIONS = (DERIVED_FROM, PROPERTIES, REQUIREMENTS, + INTERFACES, CAPABILITIES, TYPE, DESCRIPTION, DIRECTIVES, + ATTRIBUTES, ARTIFACTS, NODE_FILTER, COPY) = \ + ('derived_from', 'properties', 'requirements', 'interfaces', + 'capabilities', 'type', 'description', 'directives', + 'attributes', 'artifacts', 'node_filter', 'copy') + REQUIREMENTS_SECTION = (NODE, CAPABILITY, RELATIONSHIP, OCCURRENCES, NODE_FILTER) = \ + ('node', 'capability', 'relationship', + 'occurrences', 'node_filter') + # Special key names + SPECIAL_SECTIONS = (METADATA) = ('metadata') + + def __init__(self, name, template, entity_name, custom_def=None): + self.name = name + self.entity_tpl = template + self.custom_def = custom_def + self._validate_field(self.entity_tpl) + type = self.entity_tpl.get('type') + UnsupportedType.validate_type(type) + if entity_name == 'node_type': + self.type_definition = NodeType(type, custom_def) \ + if type is not None else None + if entity_name == 'relationship_type': + relationship = template.get('relationship') + type = None + if relationship and isinstance(relationship, dict): + type = relationship.get('type') + elif isinstance(relationship, str): + type = self.entity_tpl['relationship'] + else: + type = self.entity_tpl['type'] + UnsupportedType.validate_type(type) + self.type_definition = RelationshipType(type, + None, custom_def) + if entity_name == 'policy_type': + if not type: + msg = (_('Policy definition of "%(pname)s" must have' + ' a "type" ''attribute.') % dict(pname=name)) + ExceptionCollector.appendException( + ValidationError(msg)) + self.type_definition = PolicyType(type, custom_def) + if entity_name == 'group_type': + self.type_definition = GroupType(type, custom_def) \ + if type is not None else None + self._properties = None + self._interfaces = None + self._requirements = None + self._capabilities = None + + @property + def type(self): + if self.type_definition: + return self.type_definition.type + + @property + def parent_type(self): + if self.type_definition: + return self.type_definition.parent_type + + @property + def requirements(self): + if self._requirements is None: + self._requirements = self.type_definition.get_value( + self.REQUIREMENTS, + self.entity_tpl) or [] + return self._requirements + + def get_properties_objects(self): + '''Return properties objects for this template.''' + if self._properties is None: + self._properties = self._create_properties() + return self._properties + + def get_properties(self): + '''Return a dictionary of property name-object pairs.''' + return {prop.name: prop + for prop in self.get_properties_objects()} + + def get_property_value(self, name): + '''Return the value of a given property name.''' + props = self.get_properties() + if props and name in props.keys(): + return props[name].value + + @property + def interfaces(self): + if self._interfaces is None: + self._interfaces = self._create_interfaces() + return self._interfaces + + def get_capabilities_objects(self): + '''Return capabilities objects for this template.''' + if not self._capabilities: + self._capabilities = self._create_capabilities() + return self._capabilities + + def get_capabilities(self): + '''Return a dictionary of capability name-object pairs.''' + return {cap.name: cap + for cap in self.get_capabilities_objects()} + + def is_derived_from(self, type_str): + '''Check if object inherits from the given type. + + Returns true if this object is derived from 'type_str'. + False otherwise. + ''' + if not self.type: + return False + elif self.type == type_str: + return True + elif self.parent_type: + return self.parent_type.is_derived_from(type_str) + else: + return False + + def _create_capabilities(self): + capability = [] + caps = self.type_definition.get_value(self.CAPABILITIES, + self.entity_tpl, True) + if caps: + for name, props in caps.items(): + capabilities = self.type_definition.get_capabilities() + if name in capabilities.keys(): + c = capabilities[name] + properties = {} + # first use the definition default value + if c.properties: + for property_name in c.properties.keys(): + prop_def = c.properties[property_name] + if 'default' in prop_def: + properties[property_name] = prop_def['default'] + # then update (if available) with the node properties + if 'properties' in props and props['properties']: + properties.update(props['properties']) + + cap = Capability(name, properties, c) + capability.append(cap) + return capability + + def _validate_properties(self, template, entitytype): + properties = entitytype.get_value(self.PROPERTIES, template) + self._common_validate_properties(entitytype, properties) + + def _validate_capabilities(self): + type_capabilities = self.type_definition.get_capabilities() + allowed_caps = \ + type_capabilities.keys() if type_capabilities else [] + capabilities = self.type_definition.get_value(self.CAPABILITIES, + self.entity_tpl) + if capabilities: + self._common_validate_field(capabilities, allowed_caps, + 'capabilities') + self._validate_capabilities_properties(capabilities) + + def _validate_capabilities_properties(self, capabilities): + for cap, props in capabilities.items(): + capability = self.get_capability(cap) + if not capability: + continue + capabilitydef = capability.definition + self._common_validate_properties(capabilitydef, + props[self.PROPERTIES]) + + # validating capability properties values + for prop in self.get_capability(cap).get_properties_objects(): + prop.validate() + + # TODO(srinivas_tadepalli): temporary work around to validate + # default_instances until standardized in specification + if cap == "scalable" and prop.name == "default_instances": + prop_dict = props[self.PROPERTIES] + min_instances = prop_dict.get("min_instances") + max_instances = prop_dict.get("max_instances") + default_instances = prop_dict.get("default_instances") + if not (min_instances <= default_instances + <= max_instances): + err_msg = ('"properties" of template "%s": ' + '"default_instances" value is not between ' + '"min_instances" and "max_instances".' % + self.name) + ExceptionCollector.appendException( + ValidationError(message=err_msg)) + + def _common_validate_properties(self, entitytype, properties): + allowed_props = [] + required_props = [] + for p in entitytype.get_properties_def_objects(): + allowed_props.append(p.name) + # If property is 'required' and has no 'default' value then record + if p.required and p.default is None: + required_props.append(p.name) + # validate all required properties have values + if properties: + req_props_no_value_or_default = [] + self._common_validate_field(properties, allowed_props, + 'properties') + # make sure it's not missing any property required by a tosca type + for r in required_props: + if r not in properties.keys(): + req_props_no_value_or_default.append(r) + # Required properties found without value or a default value + if req_props_no_value_or_default: + ExceptionCollector.appendException( + MissingRequiredFieldError( + what='"properties" of template "%s"' % self.name, + required=req_props_no_value_or_default)) + else: + # Required properties in schema, but not in template + if required_props: + ExceptionCollector.appendException( + MissingRequiredFieldError( + what='"properties" of template "%s"' % self.name, + required=required_props)) + + def _validate_field(self, template): + if not isinstance(template, dict): + ExceptionCollector.appendException( + MissingRequiredFieldError( + what='Template "%s"' % self.name, required=self.TYPE)) + try: + relationship = template.get('relationship') + if relationship and not isinstance(relationship, str): + relationship[self.TYPE] + elif isinstance(relationship, str): + template['relationship'] + else: + template[self.TYPE] + except KeyError: + ExceptionCollector.appendException( + MissingRequiredFieldError( + what='Template "%s"' % self.name, required=self.TYPE)) + + def _common_validate_field(self, schema, allowedlist, section): + for name in schema: + if name not in allowedlist: + ExceptionCollector.appendException( + UnknownFieldError( + what=('"%(section)s" of template "%(nodename)s"' + % {'section': section, 'nodename': self.name}), + field=name)) + + def _create_properties(self): + props = [] + properties = self.type_definition.get_value(self.PROPERTIES, + self.entity_tpl) or {} + for name, value in properties.items(): + props_def = self.type_definition.get_properties_def() + if props_def and name in props_def: + prop = Property(name, value, + props_def[name].schema, self.custom_def) + props.append(prop) + for p in self.type_definition.get_properties_def_objects(): + if p.default is not None and p.name not in properties.keys(): + prop = Property(p.name, p.default, p.schema, self.custom_def) + props.append(prop) + return props + + def _create_interfaces(self): + interfaces = [] + type_interfaces = None + if isinstance(self.type_definition, RelationshipType): + if isinstance(self.entity_tpl, dict): + if self.INTERFACES in self.entity_tpl: + type_interfaces = self.entity_tpl[self.INTERFACES] + else: + for rel_def, value in self.entity_tpl.items(): + if rel_def != 'type': + rel_def = self.entity_tpl.get(rel_def) + rel = None + if isinstance(rel_def, dict): + rel = rel_def.get('relationship') + if rel: + if self.INTERFACES in rel: + type_interfaces = rel[self.INTERFACES] + break + else: + type_interfaces = self.type_definition.get_value(self.INTERFACES, + self.entity_tpl) + if type_interfaces: + for interface_type, value in type_interfaces.items(): + for op, op_def in value.items(): + iface = InterfacesDef(self.type_definition, + interfacetype=interface_type, + node_template=self, + name=op, + value=op_def) + interfaces.append(iface) + return interfaces + + def get_capability(self, name): + """Provide named capability + + :param name: name of capability + :return: capability object if found, None otherwise + """ + caps = self.get_capabilities() + if caps and name in caps.keys(): + return caps[name] diff --git a/nfvparser/toscaparser/extensions/__init__.py b/nfvparser/toscaparser/extensions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nfvparser/toscaparser/extensions/exttools.py b/nfvparser/toscaparser/extensions/exttools.py new file mode 100644 index 0000000..5310422 --- /dev/null +++ b/nfvparser/toscaparser/extensions/exttools.py @@ -0,0 +1,88 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import importlib +import logging +import os + +from toscaparser.common.exception import ToscaExtAttributeError +from toscaparser.common.exception import ToscaExtImportError + +log = logging.getLogger("tosca.model") + +REQUIRED_ATTRIBUTES = ['VERSION', 'DEFS_FILE'] + + +class ExtTools(object): + def __init__(self): + self.EXTENSION_INFO = self._load_extensions() + + def _load_extensions(self): + '''Dynamically load all the extensions .''' + extensions = {} + + # Use the absolute path of the class path + abs_path = os.path.dirname(os.path.abspath(__file__)) + + extdirs = [e for e in os.listdir(abs_path) if + not e.startswith('tests') and + os.path.isdir(os.path.join(abs_path, e))] + + for e in extdirs: + log.info(e) + extpath = abs_path + '/' + e + # Grab all the extension files in the given path + ext_files = [f for f in os.listdir(extpath) if f.endswith('.py') + and not f.startswith('__init__')] + + # For each module, pick out the target translation class + for f in ext_files: + log.info(f) + ext_name = 'toscaparser/extensions/' + e + '/' + f.strip('.py') + ext_name = ext_name.replace('/', '.') + try: + extinfo = importlib.import_module(ext_name) + version = getattr(extinfo, 'VERSION') + defs_file = extpath + '/' + getattr(extinfo, 'DEFS_FILE') + + # Sections is an optional attribute + sections = getattr(extinfo, 'SECTIONS', ()) + + extensions[version] = {'sections': sections, + 'defs_file': defs_file} + except ImportError: + raise ToscaExtImportError(ext_name=ext_name) + except AttributeError: + attrs = ', '.join(REQUIRED_ATTRIBUTES) + raise ToscaExtAttributeError(ext_name=ext_name, + attrs=attrs) + + return extensions + + def get_versions(self): + return self.EXTENSION_INFO.keys() + + def get_sections(self): + sections = {} + for version in self.EXTENSION_INFO.keys(): + sections[version] = self.EXTENSION_INFO[version]['sections'] + + return sections + + def get_defs_file(self, version): + versiondata = self.EXTENSION_INFO.get(version) + + if versiondata: + return versiondata.get('defs_file') + else: + return None diff --git a/nfvparser/toscaparser/extensions/nfv/TOSCA_nfv_definition_1_0_0.yaml b/nfvparser/toscaparser/extensions/nfv/TOSCA_nfv_definition_1_0_0.yaml new file mode 100644 index 0000000..365d70e --- /dev/null +++ b/nfvparser/toscaparser/extensions/nfv/TOSCA_nfv_definition_1_0_0.yaml @@ -0,0 +1,240 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +########################################################################## +# The content of this file reflects TOSCA NFV Profile in YAML version +# 1.0.0. It describes the definition for TOSCA NFV types including Node Type, +# Relationship Type, Capability Type and Interfaces. +########################################################################## +tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 + +########################################################################## +# Node Type. +# A Node Type is a reusable entity that defines the type of one or more +# Node Templates. +########################################################################## +node_types: + tosca.nodes.nfv.VNF: + derived_from: tosca.nodes.Root # Or should this be its own top - level type? + properties: + id: + type: string + description: ID of this VNF + vendor: + type: string + description: name of the vendor who generate this VNF + version: + type: version + description: version of the software for this VNF + requirements: + - virtualLink: + capability: tosca.capabilities.nfv.VirtualLinkable + relationship: tosca.relationships.nfv.VirtualLinksTo + node: tosca.nodes.nfv.VL + + tosca.nodes.nfv.VDU: + derived_from: tosca.nodes.Compute + capabilities: + high_availability: + type: tosca.capabilities.nfv.HA + virtualbinding: + type: tosca.capabilities.nfv.VirtualBindable + monitoring_parameter: + type: tosca.capabilities.nfv.Metric + requirements: + - high_availability: + capability: tosca.capabilities.nfv.HA + relationship: tosca.relationships.nfv.HA + node: tosca.nodes.nfv.VDU + occurrences: [ 0, 1 ] + + tosca.nodes.nfv.CP: + derived_from: tosca.nodes.network.Port + properties: + type: + type: string + required: false + requirements: + - virtualLink: + capability: tosca.capabilities.nfv.VirtualLinkable + relationship: tosca.relationships.nfv.VirtualLinksTo + node: tosca.nodes.nfv.VL + - virtualBinding: + capability: tosca.capabilities.nfv.VirtualBindable + relationship: tosca.relationships.nfv.VirtualBindsTo + node: tosca.nodes.nfv.VDU + attributes: + address: + type: string + + tosca.nodes.nfv.VL: + derived_from: tosca.nodes.network.Network + properties: + vendor: + type: string + required: true + description: name of the vendor who generate this VL + capabilities: + virtual_linkable: + type: tosca.capabilities.nfv.VirtualLinkable + + tosca.nodes.nfv.VL.ELine: + derived_from: tosca.nodes.nfv.VL + capabilities: + virtual_linkable: + occurrences: 2 + + tosca.nodes.nfv.VL.ELAN: + derived_from: tosca.nodes.nfv.VL + + tosca.nodes.nfv.VL.ETree: + derived_from: tosca.nodes.nfv.VL + + tosca.nodes.nfv.FP: + derived_from: tosca.nodes.Root + properties: + policy: + type: string + required: false + description: name of the vendor who generate this VL + requirements: + - forwarder: + capability: tosca.capabilities.nfv.Forwarder + relationship: tosca.relationships.nfv.ForwardsTo + +########################################################################## +# Relationship Type. +# A Relationship Type is a reusable entity that defines the type of one +# or more relationships between Node Types or Node Templates. +########################################################################## + +relationship_types: + tosca.relationships.nfv.VirtualLinksTo: + derived_from: tosca.relationships.network.LinksTo + valid_target_types: [ tosca.capabilities.nfv.VirtualLinkable ] + + tosca.relationships.nfv.VirtualBindsTo: + derived_from: tosca.relationships.network.BindsTo + valid_target_types: [ tosca.capabilities.nfv.VirtualBindable ] + + tosca.relationships.nfv.HA: + derived_from: tosca.relationships.Root + valid_target_types: [ tosca.capabilities.nfv.HA ] + + tosca.relationships.nfv.Monitor: + derived_from: tosca.relationships.ConnectsTo + valid_target_types: [ tosca.capabilities.nfv.Metric ] + + tosca.relationships.nfv.ForwardsTo: + derived_from: tosca.relationships.root + valid_target_types: [ tosca.capabilities.nfv.Forwarder] + +########################################################################## +# Capability Type. +# A Capability Type is a reusable entity that describes a kind of +# capability that a Node Type can declare to expose. +########################################################################## + +capability_types: + tosca.capabilities.nfv.VirtualLinkable: + derived_from: tosca.capabilities.network.Linkable + + tosca.capabilities.nfv.VirtualBindable: + derived_from: tosca.capabilities.network.Bindable + + tosca.capabilities.nfv.HA: + derived_from: tosca.capabilities.Root + valid_source_types: [ tosca.nodes.nfv.VDU ] + + tosca.capabilities.nfv.HA.ActiveActive: + derived_from: tosca.capabilities.nfv.HA + + tosca.capabilities.nfv.HA.ActivePassive: + derived_from: tosca.capabilities.nfv.HA + + tosca.capabilities.nfv.Metric: + derived_from: tosca.capabilities.Root + + tosca.capabilities.nfv.Forwarder: + derived_from: tosca.capabilities.Root + +########################################################################## + # Interfaces Type. + # The Interfaces element describes a list of one or more interface + # definitions for a modelable entity (e.g., a Node or Relationship Type) + # as defined within the TOSCA Simple Profile specification. +########################################################################## + +########################################################################## + # Data Type. + # A Datatype is a complex data type declaration which contains other + # complex or simple data types. +########################################################################## + +########################################################################## + # Artifact Type. + # An Artifact Type is a reusable entity that defines the type of one or more + # files which Node Types or Node Templates can have dependent relationships + # and used during operations such as during installation or deployment. +########################################################################## + +########################################################################## + # Policy Type. + # TOSCA Policy Types represent logical grouping of TOSCA nodes that have + # an implied relationship and need to be orchestrated or managed together + # to achieve some result. +########################################################################## + +########################################################################## + # Group Type + # +########################################################################## +group_types: + tosca.groups.nfv.VNFFG: + derived_from: tosca.groups.Root + + properties: + vendor: + type: string + required: true + description: name of the vendor who generate this VNFFG + + version: + type: string + required: true + description: version of this VNFFG + + number_of_endpoints: + type: integer + required: true + description: count of the external endpoints included in this VNFFG + + dependent_virtual_link: + type: list + entry_schema: + type: string + required: true + description: Reference to a VLD used in this Forwarding Graph + + connection_point: + type: list + entry_schema: + type: string + required: true + description: Reference to Connection Points forming the VNFFG + + constituent_vnfs: + type: list + entry_schema: + type: string + required: true + description: Reference to a list of VNFD used in this VNF Forwarding Graph diff --git a/nfvparser/toscaparser/extensions/nfv/__init__.py b/nfvparser/toscaparser/extensions/nfv/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nfvparser/toscaparser/extensions/nfv/tests/__init__.py b/nfvparser/toscaparser/extensions/nfv/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nfvparser/toscaparser/extensions/nfv/tests/data/tosca_helloworld_nfv.yaml b/nfvparser/toscaparser/extensions/nfv/tests/data/tosca_helloworld_nfv.yaml new file mode 100644 index 0000000..6afa9f0 --- /dev/null +++ b/nfvparser/toscaparser/extensions/nfv/tests/data/tosca_helloworld_nfv.yaml @@ -0,0 +1,31 @@ +tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 + +description: Template for deploying a single server with predefined properties. + +metadata: + template_name: TOSCA NFV Sample Template + +topology_template: + node_templates: + VNF1: + type: tosca.nodes.nfv.VNF + properties: + id: vnf1 + vendor: acmetelco + version: 1.0 + + VDU1: + type: tosca.nodes.nfv.VDU + + CP1: + type: tosca.nodes.nfv.CP + properties: + type: vPort + requirements: + - virtualLink: PrivateNetwork + - virtualBinding: VDU1 + + PrivateNetwork: + type: tosca.nodes.nfv.VL + properties: + vendor: ACME Networks diff --git a/nfvparser/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/rnc_definition.yaml b/nfvparser/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/rnc_definition.yaml new file mode 100644 index 0000000..52fbd4c --- /dev/null +++ b/nfvparser/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/rnc_definition.yaml @@ -0,0 +1,173 @@ +## Licensed under the Apache License, Version 2.0 (the "License"); you may +## not use this file 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. + +tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 + +#metadata: +# template_name: tosca_simple_profile_for_nfv_vRNC +# template_author: opnfv_parser_project +# template_version: tosca_simple_profile_for_nfv_1_0 + +# Optional description of the definitions inside the file. +description: > + NFV TOSCA simple profile for RNC types + 1. Compute Node MM, CM, DM, LB... + 1.1 MM: MaintainModule; + 1.2 CM: Control Module; + 1.3 DM: Data Module; + 1.4 LB: LineCard Module. + 2. Network Node VL and CP + +# The import section shall be ignored if the value of tosca_definitions_version +# is tosca_simple_profile_for_nfv_1_0_0, otherwise will be needed. + +# list of node type definitions +node_types: + rnc.nodes.VNF: + derived_from: tosca.nodes.nfv.VNF + properties: + vnftype: + type: string + description: type of the RNC + default: UMTS + required: false + constraints: + - valid_values: [ TDS-CDMA, UMTS, CDMA ] + attributes: + private_ip_of_MM: + type: string + description: IP of master MM + private_ip_of_CM: + type: string + description: IP of master CM + private_ip_of_DM: + type: string + description: IP of master DM + private_ip_of_LB: + type: string + description: IP of master LB + requirements: + - virtualLink_VNFM: + capability: tosca.capabilities.nfv.VirtualLinkable + relationship: tosca.relationships.nfv.VirtualLinksTo + node: rnc.nodes.VL + - virtualLink_EMS: + capability: tosca.capabilities.nfv.VirtualLinkable + relationship: tosca.relationships.nfv.VirtualLinksTo + node: rnc.nodes.VL + - virtualLink_TRAFFIC: + capability: tosca.capabilities.nfv.VirtualLinkable + relationship: tosca.relationships.nfv.VirtualLinksTo + node: rnc.nodes.VL + + rnc.nodes.compute.MM: + derived_from: tosca.nodes.nfv.VDU + properties: + activestatus: + type: integer + required: false + description: 1 for active or 0 for passive + constraints: + - valid_values: [ 0, 1 ] + id: + type: string + defaule: MM + required: false + description: > + A identifier of this VDU within the scope of the VNFD, + including version functional description and other + identification information. + + rnc.nodes.compute.CM: + derived_from: tosca.nodes.nfv.VDU + properties: + activestatus: + type: integer + required: false + description: 1 for active or 0 for passive + constraints: + - valid_values: [ 0, 1 ] + + rnc.nodes.compute.DM: + derived_from: tosca.nodes.nfv.VDU + + rnc.nodes.compute.LB: + derived_from: tosca.nodes.nfv.VDU + + rnc.nodes.BlockStorage: + derived_from: tosca.nodes.BlockStorage + + rnc.nodes.VL: + derived_from: tosca.nodes.nfv.VL + + rnc.nodes.CP: + derived_from: tosca.nodes.nfv.CP + + rnc.nodes.CP.MM: + derived_from: tosca.nodes.nfv.CP + # It's ok here because of the weakly validation. + + rnc.nodes.CP.CM: + derived_from: tosca.nodes.nfv.CP + requirements: + - virtualLink: + capability: tosca.capabilities.nfv.VirtualLinkable + relationship: tosca.relationships.nfv.VirtualLinksTo + node: rnc.nodes.VL + - virtualBinding: + capability: tosca.capabilities.nfv.VirtualBindable + relationship: tosca.relationships.nfv.VirtualBindsTo + node: rnc.nodes.compute.CM + + rnc.nodes.CP.DM: + derived_from: tosca.nodes.nfv.CP + requirements: + - virtualLink: + capability: tosca.capabilities.nfv.VirtualLinkable + relationship: tosca.relationships.nfv.VirtualLinksTo + node: rnc.nodes.VL + - virtualBinding: + capability: tosca.capabilities.nfv.VirtualBindable + relationship: tosca.relationships.nfv.VirtualBindsTo + node: rnc.nodes.compute.DM + + rnc.nodes.CP.LB: + derived_from: tosca.nodes.nfv.CP + requirements: + - virtualLink: + capability: tosca.capabilities.nfv.VirtualLinkable + relationship: tosca.relationships.nfv.VirtualLinksTo + node: rnc.nodes.VL + - virtualBinding: + capability: tosca.capabilities.nfv.VirtualBindable + relationship: tosca.relationships.nfv.VirtualBindsTo + node: rnc.nodes.compute.LB + +# list of capability type definitions +capability_types: + rnc.capabilities.Container: + derived_from: tosca.capabilities.Container + properties: + swap: + type: scalar-unit.size + description: swap info + required: false + default: 0 + constraints: + - greater_or_equal: 0 MB + iops: + type: integer + description: IOPS for disk + required: false + default: 0 + constraints: + - greater_than: 0 diff --git a/nfvparser/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/vRNC.yaml b/nfvparser/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/vRNC.yaml new file mode 100644 index 0000000..4441372 --- /dev/null +++ b/nfvparser/toscaparser/extensions/nfv/tests/data/vRNC/Definitions/vRNC.yaml @@ -0,0 +1,552 @@ +## Licensed under the Apache License, Version 2.0 (the "License"); you may +## not use this file 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. + +tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 + +metadata: + template_name: tosca_simple_profile_for_nfv_vRNC + template_author: opnfv_parser_project + template_version: tosca_simple_profile_for_nfv_1_0 + +# Optional description of the definitions inside the file. +description: > + TOSCA simple profile for RNC + 1. Compute Node MM, CM, DM, LB... + 1.1 MM: MaintainModule; + 1.2 CM: Control Module; + 1.3 DM: Data Module; + 1.4 LB: LineCard Module + 2. Network Node VL and CP + +imports: + - rnc_definition.yaml + +# list of YAML alias anchors (or macros) +dsl_definitions: + compute_props_os_DEF: &compute_props_os_DEF + architecture: x86_64 + type: Linux + distribution: Cirros + version: 0.3.2 + + compute_props_host_MM: &compute_props_host_MM + disk_size: 1 GB + num_cpus: 1 + mem_size: 512 MB + + compute_props_host_CM: &compute_props_host_CM + disk_size: 0 GB + num_cpus: 1 + mem_size: 512 MB + + compute_props_host_DM: &compute_props_host_DM + disk_size: 0 GB + num_cpus: 1 + mem_size: 512 MB + + compute_props_host_LB: &compute_props_host_LB + disk_size: 0 GB + num_cpus: 1 + mem_size: 512 MB + +# topology template definition of the cloud application or service +topology_template: + # a description of the topology template + description: > + simple RNC template + + inputs: + mm_storage_size: + type: integer + default: 1 + description: mm additional block storage size + constraints: + - in_range: [ 1, 200 ] + id: + type: string + description: ID of this VNF + default: UMTS + vendor: + type: string + description: name of the vendor who generate this VNF + default: opnfv_parser_project + version: + type: version + description: version of the software for this VNF + default: 1.0 + + substitution_mappings: + node_type: rnc.nodes.VNF + requirements: + virtualLink_VNFM: [ MM_Port_CTRL, virtualLink ] + virtualLink_EMS: [ MM_Port_EMS, virtualLink ] + virtualLink_TRAFFIC: [ LB_Port_EXTERMEDIA, virtualLink ] + + # definition of the node templates of the topology + node_templates: + MM_Active: + type: tosca.nodes.SoftwareComponent + properties: + component_version: 1.0 + requirements: + - host: MM_Active_Host + interfaces: + Standard: + create: + implementation: ./Scripts/MM/mm_install.sh + configure: + implementation: ./Scripts/MM/mm_active_configure.sh + + MM_Active_Host: + type: rnc.nodes.compute.MM + capabilities: + os: + properties: *compute_props_os_DEF + host: + properties: *compute_props_host_MM + requirements: + - local_storage: + node: MM_BlockStorage + relationship: Storage_attachesto + artifacts: + #the VM image of MM + vm_image: mm.image + + MM_Passive: + type: tosca.nodes.SoftwareComponent + properties: + component_version: 1.0 + requirements: + - host: MM_Passive_Host + interfaces: + Standard: + create: + implementation: ./Scripts/MM/mm_install.sh + configure: + implementation: ./Scripts/MM/mm_passvie_configure.sh + + MM_Passive_Host: + type: rnc.nodes.compute.MM + capabilities: + os: + properties: *compute_props_os_DEF + host: + properties: *compute_props_host_MM + requirements: + - local_storage: + node: MM_BlockStorage + relationship: Storage_attachesto + - high_availability: MM_Active_Host + artifacts: + #the VM image of MM + vm_image: mm.image + + MM_BlockStorage: + type: rnc.nodes.BlockStorage + properties: + size: { get_input: mm_storage_size } + interfaces: + Configure: + post_configure_target: + implementation: ./Scripts/MM/storage_script.sh + + CM_Active: + type: tosca.nodes.SoftwareComponent + properties: + component_version: 1.0 + requirements: + - host: CM_Active_Host + interfaces: + Standard: + create: + implementation: ./Scripts/CM/cm_install.sh + configure: + implementation: ./Scripts/CM/cm_active_configure.sh + + CM_Active_Host: + type: rnc.nodes.compute.CM + capabilities: + os: + properties: *compute_props_os_DEF + host: + properties: *compute_props_host_CM + scalable: + properties: + min_instances: 1 + max_instances: 12 + default_instances: 1 + artifacts: + #the VM image of CM + vm_image: cm.image + + CM_Passive: + type: tosca.nodes.SoftwareComponent + properties: + component_version: 1.0 + requirements: + - host: CM_Passive_Host + interfaces: + Standard: + create: + implementation: ./Scripts/CM/cm_install.sh + configure: + implementation: ./Scripts/CM/cm_passvie_configure.sh + + CM_Passive_Host: + type: rnc.nodes.compute.CM + capabilities: + os: + properties: *compute_props_os_DEF + host: + properties: *compute_props_host_CM + scalable: + properties: + min_instances: 1 + max_instances: 12 + default_instances: 1 + requirements: + - high_availability: CM_Active_Host + artifacts: + #the VM image of CM + vm_image: mm.image + + DM: + type: tosca.nodes.SoftwareComponent + properties: + component_version: 1.0 + requirements: + - host: DM_Host + interfaces: + Standard: + create: + implementation: ./Scripts/DM/dm_install.sh + configure: + implementation: ./Scripts/DM/dm_configure.sh + + DM_Host: + type: rnc.nodes.compute.DM + capabilities: + os: + properties: *compute_props_os_DEF + host: + properties: *compute_props_host_DM + scalable: + properties: + min_instances: 1 + max_instances: 12 + default_instances: 1 + artifacts: + vm_image: dm.image + + LB: + type: tosca.nodes.SoftwareComponent + properties: + component_version: 1.0 + requirements: + - host: LB_Host + interfaces: + Standard: + create: + implementation: ./Scripts/LB/lb_install.sh + configure: + implementation: ./Scripts/LB/lb_configure.sh + + LB_Host: + type: rnc.nodes.compute.LB + capabilities: + os: + properties: *compute_props_os_DEF + host: + properties: *compute_props_host_LB + scalable: + properties: + min_instances: 1 + max_instances: 2 + default_instances: 1 + artifacts: + #the VM image of LB + vm_image: lb.image + + CTRL_Net: + type: rnc.nodes.VL + properties: + vendor: ZTE + cidr: "128.0.0.0/8" + network_name: Ctrl_Net + network_type: vlan + segmentation_id: 110 + dhcp_enabled: false + + INTERMEDIA_Net: + type: rnc.nodes.VL + properties: + vendor: ZTE + cidr: 10.0.0.0/8 + start_ip: 10.1.0.1 + end_ip: 10.1.2.254 + network_name: InterMedia_Net + network_type: vlan + segmentation_id: 111 + dhcp_enabled: false + + EXTERMEDIA_Net: + type: rnc.nodes.VL + properties: + vendor: ZTE + cidr: 172.1.0.0/16 + start_ip: 172.1.0.2 + end_ip: 172.1.2.254 + gateway_ip: 172.1.0.1 + network_name: ExterMdedia_Net + network_type: vlan + segmentation_id: 100 + dhcp_enabled: false + + EMS_Net: + type: rnc.nodes.VL + properties: + vendor: ZTE + cidr: 129.0.0.0/24 + start_ip: 129.0.0.2 + end_ip: 129.0.0.64 + gateway_ip: 129.0.0.1 + network_name: Ems_Net + network_type: vlan + segmentation_id: 101 + dhcp_enabled: false + + MM_Active_Port_EMS: + type: rnc.nodes.CP.MM + properties: + order: 0 + is_default: true + requirements: + - virtualBinding: MM_Active_Host + - virtualLink: EMS_Net + + MM_Active_Port_EXTERMEDIA: + type: rnc.nodes.CP.MM + properties: + order: 1 + is_default: true + requirements: + - virtualBinding: MM_Active_Host + - virtualLink: EMS_Net + + MM_Active_Port_CTRL: + type: rnc.nodes.CP.MM + properties: + order: 2 + is_default: false + requirements: + - virtualBinding: MM_Active_Host + - virtualLink: CTRL_Net + + MM_Active_Port_INTERMEDIA: + type: rnc.nodes.CP.MM + properties: + order: 3 + is_default: false + requirements: + - virtualBinding: MM_Active_Host + - virtualLink: EXTERMEDIA_Net + + MM_Passive_Port_EMS: + type: rnc.nodes.CP.MM + properties: + order: 0 + is_default: true + requirements: + - virtualBinding: MM_Passive_Host + - virtualLink: EMS_Net + + MM_Passive_Port_EXTERMEDIA: + type: rnc.nodes.CP.MM + properties: + order: 1 + is_default: true + requirements: + - virtualBinding: MM_Passive_Host + - virtualLink: EXTERMEDIA_Net + + MM_Passive_Port_CTRL: + type: rnc.nodes.CP.MM + properties: + order: 2 + is_default: false + requirements: + - virtualBinding: MM_Passive_Host + - virtualLink: CTRL_Net + + MM_Passive_Port_INTERMEDIA: + type: rnc.nodes.CP.MM + properties: + order: 3 + is_default: false + requirements: + - virtualBinding: MM_Passive_Host + - virtualLink: INTERMEDIA_Net + + CM_Active_Port_CTRL: + type: rnc.nodes.CP.CM + properties: + order: 0 + is_default: true + requirements: + - virtualBinding: CM_Active_Host + - virtualLink: CTRL_Net + + CM_Active_Port_INTERMEDIA: + type: rnc.nodes.CP.CM + properties: + order: 1 + is_default: false + requirements: + - virtualBinding: CM_Active_Host + - virtualLink: INTERMEDIA_Net + + CM_Passive_Port_CTRL: + type: rnc.nodes.CP.CM + properties: + order: 0 + is_default: true + requirements: + - virtualBinding: CM_Passive_Host + - virtualLink: CTRL_Net + + CM_Passive_Port_INTERMEDIA: + type: rnc.nodes.CP.CM + properties: + order: 1 + is_default: false + requirements: + - virtualBinding: CM_Passive_Host + - virtualLink: INTERMEDIA_Net + + DM_Port_CTRL: + type: rnc.nodes.CP.DM + properties: + order: 0 + is_default: true + requirements: + - virtualBinding: DM_Host + - virtualLink: CTRL_Net + + DM_Port_INTERMEDIA: + type: rnc.nodes.CP.DM + properties: + order: 1 + is_default: false + requirements: + - virtualBinding: DM_Host + - virtualLink: INTERMEDIA_Net + + LB_Port_CTRL: + type: rnc.nodes.CP.LB + properties: + order: 0 + is_default: true + requirements: + - virtualBinding: LB_Host + - virtualLink: CTRL_Net + + LB_Port_INTERMEDIA: + type: rnc.nodes.CP.LB + properties: + order: 1 + is_default: false + requirements: + - virtualBinding: LB_Host + - virtualLink: INTERMEDIA_Net + + LB_Port_EXTERMEDIA: + type: rnc.nodes.CP.LB + properties: + order: 2 + is_default: false + requirements: + - virtualBinding: LB_Host + - virtualLink: EXTERMEDIA_Net + + # definition of the relationship templates of the topology + relationship_templates: + Storage_attachesto: + type: tosca.relationships.AttachesTo + properties: + location: /data_location + + # definition of output parameters for the topology template + outputs: + private_ip_of_MM: + description: The Inner(CtrPlane) IP address of the MM. + value: { get_attribute: [ MM_Active_Host, private_address ] } + + private_ip_of_CM: + description: The Inner(CtrPlane) IP address of the CM. + value: { get_attribute: [ CM_Active_Host, private_address ] } + + private_ip_of_DM: + description: The Inner(CtrPlane) IP address of the DM. + value: { get_attribute: [ DM_Host, private_address ] } + + private_ip_of_LB: + description: The Inner(CtrPlane) IP address of the LB. + value: { get_attribute: [ LB_Host, private_address ] } + + # definition of logical groups of node templates within the topology + # To be continue about this section + groups: + AntiAffinityServerGroup: + type: tosca.groups.Root + description: > + Logical component grouping for anti affinity placement, + MM_Acitve, MM_Passive, CM_Acitve, CM_Passive, LB must host + on different host to reduce the impact to each other. + members: [ MM_Active, MM_Passive, CM_Active, CM_Passive, LB ] + + AffinityServerGroup: + type: tosca.groups.Root + description: > + Logical component grouping for affinity placement, + CM and DM will be host on the same host to get high performence + members: [ CM_Active, DM ] + + policies: + - AntiAffinityPolicy: + # type: tosca.policies.Placement + type: tosca.policies.Placement.Antilocate + # Current only placement in openstack community + description: Apply anti-locate placement policy to group + targets: [ AntiAffinityServerGroup ] + + - AffinityPolicy: + #type: tosca.policies.Placement + type: tosca.policies.Placement.Colocate + # Current only placement in openstack community + description: Apply anti-locate placement policy to group + targets: [ AffinityServerGroup ] + + # ServerGroupScaling_DM: # added future + # members: [ DM, ]# only one, will be error + # policies: + # - name: MyScaleUpPolicy + # - type: tosca.policy.scale.up | tosca.policy.scale.down + # - rule: fn.utilizaton [ DM ], greater_than: 80 + # - trigger: script_dm + + # ServerGroupScaling_LB: # added future + # members: [ LB, ] # only one, will be error + # policies: + # - name: MyScaleUpPolicy + # - type: tosca.policy.scale.up | tosca.policy.scale.down + # - rule: fn.utilizaton [ LB ], greater_than: 80 + # - trigger: script_lb diff --git a/nfvparser/toscaparser/extensions/nfv/tests/data/vRNC/README.txt b/nfvparser/toscaparser/extensions/nfv/tests/data/vRNC/README.txt new file mode 100644 index 0000000..9ea77a4 --- /dev/null +++ b/nfvparser/toscaparser/extensions/nfv/tests/data/vRNC/README.txt @@ -0,0 +1,22 @@ +README: + +This CSAR contains all definitions that are required for deploying a simple +vRNC(virtual Radio Network Controller) on a cloud. + +Entry information for processing through an orchestrator is contained in file +TOSCA-Metadata/TOSCA.meta. This file provides high-level information such as +CSAR version or creator of the CSAR. Furthermore, it provides pointers to the +various TOSCA definitions files that contain the real details. +The entry 'Entry-Definitions' points to the definitions file which holds the +service template for the workload. +'Entry-Definitions' is optional. An orchestrator can also process the contents +like this: +1) Read in and process each definitions file. +2) For each definitions file: + 2.1) Read in all * type definitions (node types, capability types, etc.) and + store them in an internal map +3) Verify and build dependencies (e.g. inheritance) between all type definitions + previously read in. Orchestrator built-in types (e.g. TOSCA base types) are + also considered in this step. +4) Process the actual service template (the file with a node_templates section). + Validate using previously obtained type information. \ No newline at end of file diff --git a/nfvparser/toscaparser/extensions/nfv/tests/data/vRNC/TOSCA-Metadata/TOSCA.meta b/nfvparser/toscaparser/extensions/nfv/tests/data/vRNC/TOSCA-Metadata/TOSCA.meta new file mode 100644 index 0000000..45f9ab2 --- /dev/null +++ b/nfvparser/toscaparser/extensions/nfv/tests/data/vRNC/TOSCA-Metadata/TOSCA.meta @@ -0,0 +1,4 @@ +TOSCA-Meta-File-Version: 1.0 +CSAR-Version: 1.1 +Created-By: shang.xiaodog@zte.com.cn +Entry-Definitions: Definitions/vRNC.yaml \ No newline at end of file diff --git a/nfvparser/toscaparser/extensions/nfv/tests/test_tosca_nfv_tpl.py b/nfvparser/toscaparser/extensions/nfv/tests/test_tosca_nfv_tpl.py new file mode 100644 index 0000000..b166d83 --- /dev/null +++ b/nfvparser/toscaparser/extensions/nfv/tests/test_tosca_nfv_tpl.py @@ -0,0 +1,29 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import os + +from toscaparser.tests.base import TestCase +from toscaparser.tosca_template import ToscaTemplate + + +class ToscaNFVTemplateTest(TestCase): + + '''TOSCA NFV template.''' + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/tosca_helloworld_nfv.yaml") + tosca = ToscaTemplate(tosca_tpl) + + def test_version(self): + self.assertEqual(self.tosca.version, + "tosca_simple_profile_for_nfv_1_0_0") diff --git a/nfvparser/toscaparser/extensions/nfv/tests/test_tosca_vRNC.py b/nfvparser/toscaparser/extensions/nfv/tests/test_tosca_vRNC.py new file mode 100644 index 0000000..a0ffc21 --- /dev/null +++ b/nfvparser/toscaparser/extensions/nfv/tests/test_tosca_vRNC.py @@ -0,0 +1,62 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import os + +from toscaparser.tests.base import TestCase +from toscaparser.tosca_template import ToscaTemplate + + +class ToscaVRNCTemplateTest(TestCase): + + '''NFV TOSCA vRNC template.''' + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/vRNC/Definitions/vRNC.yaml") + tosca = ToscaTemplate(tosca_tpl) + + def test_version(self): + self.assertEqual(self.tosca.version, + "tosca_simple_profile_for_nfv_1_0_0") + + def test_input(self): + input_names = sorted(["mm_storage_size", "id", + "vendor", "version"]) + self.assertEqual(sorted([i.name for i in self.tosca.inputs]), + input_names) + + def test_nodetemplates(self): + expected_node_list = sorted( + ["MM_Active", "MM_Passive", "MM_BlockStorage", + "MM_Active_Host", "MM_Passive_Host", + "CM_Active", "CM_Passive", "DM", "LB", + "CM_Active_Host", "CM_Passive_Host", "DM_Host", "LB_Host", + "EXTERMEDIA_Net", "INTERMEDIA_Net", "EMS_Net", "CTRL_Net", + "MM_Active_Port_EMS", "MM_Active_Port_CTRL", + "MM_Active_Port_EXTERMEDIA", "MM_Active_Port_INTERMEDIA", + "MM_Passive_Port_EMS", "MM_Passive_Port_CTRL", + "MM_Passive_Port_EXTERMEDIA", "MM_Passive_Port_INTERMEDIA", + "CM_Active_Port_CTRL", "CM_Active_Port_INTERMEDIA", + "CM_Passive_Port_CTRL", "CM_Passive_Port_INTERMEDIA", + "DM_Port_CTRL", "DM_Port_INTERMEDIA", + "LB_Port_INTERMEDIA", "LB_Port_EXTERMEDIA", "LB_Port_CTRL"]) + + node_list = sorted([node.name for node in self.tosca.nodetemplates]) + self.assertEqual(node_list, expected_node_list) + + def test_output(self): + expected_output_name = sorted( + ["private_ip_of_CM", "private_ip_of_DM", + "private_ip_of_LB", "private_ip_of_MM"]) + + output_list = sorted([output.name for output in self.tosca.outputs]) + self.assertEqual(output_list, expected_output_name) diff --git a/nfvparser/toscaparser/extensions/nfv/tosca_simple_profile_for_nfv_1_0_0.py b/nfvparser/toscaparser/extensions/nfv/tosca_simple_profile_for_nfv_1_0_0.py new file mode 100644 index 0000000..24eabab --- /dev/null +++ b/nfvparser/toscaparser/extensions/nfv/tosca_simple_profile_for_nfv_1_0_0.py @@ -0,0 +1,19 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +# VERSION and DEFS_FILE are required for all extensions + +VERSION = 'tosca_simple_profile_for_nfv_1_0_0' + +DEFS_FILE = "TOSCA_nfv_definition_1_0_0.yaml" + +SECTIONS = ('metadata') diff --git a/nfvparser/toscaparser/functions.py b/nfvparser/toscaparser/functions.py new file mode 100644 index 0000000..d498229 --- /dev/null +++ b/nfvparser/toscaparser/functions.py @@ -0,0 +1,826 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + + +import abc +import six +import toscaparser.elements.interfaces + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import UnknownInputError +from toscaparser.dataentity import DataEntity +from toscaparser.elements.constraints import Schema +from toscaparser.elements.datatype import DataType +from toscaparser.elements.entity_type import EntityType +from toscaparser.elements.relationshiptype import RelationshipType +from toscaparser.elements.statefulentitytype import StatefulEntityType +from toscaparser.utils.gettextutils import _ + + +GET_PROPERTY = 'get_property' +GET_ATTRIBUTE = 'get_attribute' +GET_INPUT = 'get_input' +GET_OPERATION_OUTPUT = 'get_operation_output' +CONCAT = 'concat' +TOKEN = 'token' + +SELF = 'SELF' +HOST = 'HOST' +TARGET = 'TARGET' +SOURCE = 'SOURCE' + +HOSTED_ON = 'tosca.relationships.HostedOn' + + +@six.add_metaclass(abc.ABCMeta) +class Function(object): + """An abstract type for representing a Tosca template function.""" + + def __init__(self, tosca_tpl, context, name, args): + self.tosca_tpl = tosca_tpl + self.context = context + self.name = name + self.args = args + self.validate() + + @abc.abstractmethod + def result(self): + """Invokes the function and returns its result + + Some methods invocation may only be relevant on runtime (for example, + getting runtime properties) and therefore its the responsibility of + the orchestrator/translator to take care of such functions invocation. + + :return: Function invocation result. + """ + return {self.name: self.args} + + @abc.abstractmethod + def validate(self): + """Validates function arguments.""" + pass + + +class GetInput(Function): + """Get a property value declared within the input of the service template. + + Arguments: + + * Input name. + + Example: + + * get_input: port + """ + + def validate(self): + if len(self.args) != 1: + ExceptionCollector.appendException( + ValueError(_( + 'Expected one argument for function "get_input" but ' + 'received "%s".') % self.args)) + inputs = [input.name for input in self.tosca_tpl.inputs] + if self.args[0] not in inputs: + ExceptionCollector.appendException( + UnknownInputError(input_name=self.args[0])) + + def result(self): + if self.tosca_tpl.parsed_params and \ + self.input_name in self.tosca_tpl.parsed_params: + return DataEntity.validate_datatype( + self.tosca_tpl.tpl['inputs'][self.input_name]['type'], + self.tosca_tpl.parsed_params[self.input_name]) + + input = [input_def for input_def in self.tosca_tpl.inputs + if self.input_name == input_def.name][0] + return input.default + + @property + def input_name(self): + return self.args[0] + + +class GetAttribute(Function): + """Get an attribute value of an entity defined in the service template + + Node template attributes values are set in runtime and therefore its the + responsibility of the Tosca engine to implement the evaluation of + get_attribute functions. + + Arguments: + + * Node template name | HOST. + * Attribute name. + + If the HOST keyword is passed as the node template name argument the + function will search each node template along the HostedOn relationship + chain until a node which contains the attribute is found. + + Examples: + + * { get_attribute: [ server, private_address ] } + * { get_attribute: [ HOST, private_address ] } + * { get_attribute: [ HOST, private_address, 0 ] } + * { get_attribute: [ HOST, private_address, 0, some_prop] } + """ + + def validate(self): + if len(self.args) < 2: + ExceptionCollector.appendException( + ValueError(_('Illegal arguments for function "{0}". Expected ' + 'arguments: "node-template-name", "req-or-cap"' + '(optional), "property name"' + ).format(GET_ATTRIBUTE))) + return + elif len(self.args) == 2: + self._find_node_template_containing_attribute() + else: + node_tpl = self._find_node_template(self.args[0]) + if node_tpl is None: + return + index = 2 + attrs = node_tpl.type_definition.get_attributes_def() + found = [attrs[self.args[1]]] if self.args[1] in attrs else [] + if found: + attr = found[0] + else: + index = 3 + # then check the req or caps + attr = self._find_req_or_cap_attribute(self.args[1], + self.args[2]) + + value_type = attr.schema['type'] + if len(self.args) > index: + for elem in self.args[index:]: + if value_type == "list": + if not isinstance(elem, int): + ExceptionCollector.appendException( + ValueError(_('Illegal arguments for function' + ' "{0}". "{1}" Expected positive' + ' integer argument' + ).format(GET_ATTRIBUTE, elem))) + value_type = attr.schema['entry_schema']['type'] + elif value_type == "map": + value_type = attr.schema['entry_schema']['type'] + elif value_type in Schema.PROPERTY_TYPES: + ExceptionCollector.appendException( + ValueError(_('Illegal arguments for function' + ' "{0}". Unexpected attribute/' + 'index value "{1}"' + ).format(GET_ATTRIBUTE, elem))) + return + else: # It is a complex type + data_type = DataType(value_type) + props = data_type.get_all_properties() + found = [props[elem]] if elem in props else [] + if found: + prop = found[0] + value_type = prop.schema['type'] + else: + ExceptionCollector.appendException( + KeyError(_('Illegal arguments for function' + ' "{0}". Attribute name "{1}" not' + ' found in "{2}"' + ).format(GET_ATTRIBUTE, + elem, + value_type))) + + def result(self): + return self + + def get_referenced_node_template(self): + """Gets the NodeTemplate instance the get_attribute function refers to. + + If HOST keyword was used as the node template argument, the node + template which contains the attribute along the HostedOn relationship + chain will be returned. + """ + return self._find_node_template_containing_attribute() + + # Attributes can be explicitly created as part of the type definition + # or a property name can be implicitly used as an attribute name + def _find_node_template_containing_attribute(self): + node_tpl = self._find_node_template(self.args[0]) + if node_tpl and \ + not self._attribute_exists_in_type(node_tpl.type_definition) \ + and self.attribute_name not in node_tpl.get_properties(): + ExceptionCollector.appendException( + KeyError(_('Attribute "%(att)s" was not found in node ' + 'template "%(ntpl)s".') % + {'att': self.attribute_name, + 'ntpl': node_tpl.name})) + return node_tpl + + def _attribute_exists_in_type(self, type_definition): + attrs_def = type_definition.get_attributes_def() + found = [attrs_def[self.attribute_name]] \ + if self.attribute_name in attrs_def else [] + return len(found) == 1 + + def _find_host_containing_attribute(self, node_template_name=SELF): + node_template = self._find_node_template(node_template_name) + if node_template: + hosted_on_rel = EntityType.TOSCA_DEF[HOSTED_ON] + for r in node_template.requirements: + for requirement, target_name in r.items(): + target_node = self._find_node_template(target_name) + target_type = target_node.type_definition + for capability in target_type.get_capabilities_objects(): + if capability.type in \ + hosted_on_rel['valid_target_types']: + if self._attribute_exists_in_type(target_type): + return target_node + return self._find_host_containing_attribute( + target_name) + + def _find_node_template(self, node_template_name): + if node_template_name == HOST: + # Currently this is the only way to tell whether the function + # is used within the outputs section of the TOSCA template. + if isinstance(self.context, list): + ExceptionCollector.appendException( + ValueError(_( + '"get_attribute: [ HOST, ... ]" is not allowed in ' + '"outputs" section of the TOSCA template.'))) + return + node_tpl = self._find_host_containing_attribute() + if not node_tpl: + ExceptionCollector.appendException( + ValueError(_( + '"get_attribute: [ HOST, ... ]" was used in node ' + 'template "{0}" but "{1}" was not found in ' + 'the relationship chain.').format(self.context.name, + HOSTED_ON))) + return + return node_tpl + if node_template_name == TARGET: + if not isinstance(self.context.type_definition, RelationshipType): + ExceptionCollector.appendException( + KeyError(_('"TARGET" keyword can only be used in context' + ' to "Relationships" target node'))) + return + return self.context.target + if node_template_name == SOURCE: + if not isinstance(self.context.type_definition, RelationshipType): + ExceptionCollector.appendException( + KeyError(_('"SOURCE" keyword can only be used in context' + ' to "Relationships" source node'))) + return + return self.context.source + name = self.context.name \ + if node_template_name == SELF and \ + not isinstance(self.context, list) \ + else node_template_name + for node_template in self.tosca_tpl.nodetemplates: + if node_template.name == name: + return node_template + ExceptionCollector.appendException( + KeyError(_( + 'Node template "{0}" was not found.' + ).format(node_template_name))) + + def _find_req_or_cap_attribute(self, req_or_cap, attr_name): + node_tpl = self._find_node_template(self.args[0]) + # Find attribute in node template's requirements + for r in node_tpl.requirements: + for req, node_name in r.items(): + if req == req_or_cap: + node_template = self._find_node_template(node_name) + return self._get_capability_attribute( + node_template, + req, + attr_name) + # If requirement was not found, look in node template's capabilities + return self._get_capability_attribute(node_tpl, + req_or_cap, + attr_name) + + def _get_capability_attribute(self, + node_template, + capability_name, + attr_name): + """Gets a node template capability attribute.""" + caps = node_template.get_capabilities() + if caps and capability_name in caps.keys(): + cap = caps[capability_name] + attribute = None + attrs = cap.definition.get_attributes_def() + if attrs and attr_name in attrs.keys(): + attribute = attrs[attr_name] + if not attribute: + ExceptionCollector.appendException( + KeyError(_('Attribute "%(attr)s" was not found in ' + 'capability "%(cap)s" of node template ' + '"%(ntpl1)s" referenced from node template ' + '"%(ntpl2)s".') % {'attr': attr_name, + 'cap': capability_name, + 'ntpl1': node_template.name, + 'ntpl2': self.context.name})) + return attribute + msg = _('Requirement/Capability "{0}" referenced from node template ' + '"{1}" was not found in node template "{2}".').format( + capability_name, + self.context.name, + node_template.name) + ExceptionCollector.appendException(KeyError(msg)) + + @property + def node_template_name(self): + return self.args[0] + + @property + def attribute_name(self): + return self.args[1] + + +class GetProperty(Function): + """Get a property value of an entity defined in the same service template. + + Arguments: + + * Node template name | SELF | HOST | SOURCE | TARGET. + * Requirement or capability name (optional). + * Property name. + + If requirement or capability name is specified, the behavior is as follows: + The req or cap name is first looked up in the specified node template's + requirements. + If found, it would search for a matching capability + of an other node template and get its property as specified in function + arguments. + Otherwise, the req or cap name would be looked up in the specified + node template's capabilities and if found, it would return the property of + the capability as specified in function arguments. + + Examples: + + * { get_property: [ mysql_server, port ] } + * { get_property: [ SELF, db_port ] } + * { get_property: [ SELF, database_endpoint, port ] } + * { get_property: [ SELF, database_endpoint, port, 1 ] } + """ + + def validate(self): + if len(self.args) < 2: + ExceptionCollector.appendException( + ValueError(_( + 'Expected arguments: "node-template-name", "req-or-cap" ' + '(optional), "property name".'))) + return + if len(self.args) == 2: + found_prop = self._find_property(self.args[1]) + if not found_prop: + return + prop = found_prop.value + if not isinstance(prop, Function): + get_function(self.tosca_tpl, self.context, prop) + elif len(self.args) >= 3: + # do not use _find_property to avoid raise KeyError + # if the prop is not found + # First check if there is property with this name + node_tpl = self._find_node_template(self.args[0]) + props = node_tpl.get_properties() if node_tpl else [] + index = 2 + found = [props[self.args[1]]] if self.args[1] in props else [] + if found: + property_value = found[0].value + else: + index = 3 + # then check the req or caps + property_value = self._find_req_or_cap_property(self.args[1], + self.args[2]) + if len(self.args) > index: + for elem in self.args[index:]: + if isinstance(property_value, list): + int_elem = int(elem) + property_value = self._get_index_value(property_value, + int_elem) + else: + property_value = self._get_attribute_value( + property_value, + elem) + + def _find_req_or_cap_property(self, req_or_cap, property_name): + node_tpl = self._find_node_template(self.args[0]) + # Find property in node template's requirements + for r in node_tpl.requirements: + for req, node_name in r.items(): + if req == req_or_cap: + node_template = self._find_node_template(node_name) + return self._get_capability_property( + node_template, + req, + property_name) + # If requirement was not found, look in node template's capabilities + return self._get_capability_property(node_tpl, + req_or_cap, + property_name) + + def _get_capability_property(self, + node_template, + capability_name, + property_name): + """Gets a node template capability property.""" + caps = node_template.get_capabilities() + if caps and capability_name in caps.keys(): + cap = caps[capability_name] + property = None + props = cap.get_properties() + if props and property_name in props.keys(): + property = props[property_name].value + if not property: + ExceptionCollector.appendException( + KeyError(_('Property "%(prop)s" was not found in ' + 'capability "%(cap)s" of node template ' + '"%(ntpl1)s" referenced from node template ' + '"%(ntpl2)s".') % {'prop': property_name, + 'cap': capability_name, + 'ntpl1': node_template.name, + 'ntpl2': self.context.name})) + return property + msg = _('Requirement/Capability "{0}" referenced from node template ' + '"{1}" was not found in node template "{2}".').format( + capability_name, + self.context.name, + node_template.name) + ExceptionCollector.appendException(KeyError(msg)) + + def _find_property(self, property_name): + node_tpl = self._find_node_template(self.args[0]) + if not node_tpl: + return + props = node_tpl.get_properties() + found = [props[property_name]] if property_name in props else [] + if len(found) == 0: + ExceptionCollector.appendException( + KeyError(_('Property "%(prop)s" was not found in node ' + 'template "%(ntpl)s".') % + {'prop': property_name, + 'ntpl': node_tpl.name})) + return None + return found[0] + + def _find_node_template(self, node_template_name): + if node_template_name == SELF: + return self.context + # enable the HOST value in the function + if node_template_name == HOST: + return self._find_host_containing_property() + if node_template_name == TARGET: + if not isinstance(self.context.type_definition, RelationshipType): + ExceptionCollector.appendException( + KeyError(_('"TARGET" keyword can only be used in context' + ' to "Relationships" target node'))) + return + return self.context.target + if node_template_name == SOURCE: + if not isinstance(self.context.type_definition, RelationshipType): + ExceptionCollector.appendException( + KeyError(_('"SOURCE" keyword can only be used in context' + ' to "Relationships" source node'))) + return + return self.context.source + if not hasattr(self.tosca_tpl, 'nodetemplates'): + return + for node_template in self.tosca_tpl.nodetemplates: + if node_template.name == node_template_name: + return node_template + ExceptionCollector.appendException( + KeyError(_( + 'Node template "{0}" was not found.' + ).format(node_template_name))) + + def _get_index_value(self, value, index): + if isinstance(value, list): + if index < len(value): + return value[index] + else: + ExceptionCollector.appendException( + KeyError(_( + "Property '{0}' found in capability '{1}'" + " referenced from node template {2}" + " must have an element with index {3}."). + format(self.args[2], + self.args[1], + self.context.name, + index))) + else: + ExceptionCollector.appendException( + KeyError(_( + "Property '{0}' found in capability '{1}'" + " referenced from node template {2}" + " must be a list.").format(self.args[2], + self.args[1], + self.context.name))) + + def _get_attribute_value(self, value, attibute): + if isinstance(value, dict): + if attibute in value: + return value[attibute] + else: + ExceptionCollector.appendException( + KeyError(_( + "Property '{0}' found in capability '{1}'" + " referenced from node template {2}" + " must have an attribute named {3}."). + format(self.args[2], + self.args[1], + self.context.name, + attibute))) + else: + ExceptionCollector.appendException( + KeyError(_( + "Property '{0}' found in capability '{1}'" + " referenced from node template {2}" + " must be a dict.").format(self.args[2], + self.args[1], + self.context.name))) + + # Add this functions similar to get_attribute case + def _find_host_containing_property(self, node_template_name=SELF): + node_template = self._find_node_template(node_template_name) + hosted_on_rel = EntityType.TOSCA_DEF[HOSTED_ON] + for r in node_template.requirements: + for requirement, target_name in r.items(): + target_node = self._find_node_template(target_name) + target_type = target_node.type_definition + for capability in target_type.get_capabilities_objects(): + if capability.type in hosted_on_rel['valid_target_types']: + if self._property_exists_in_type(target_type): + return target_node + return self._find_host_containing_property( + target_name) + return None + + def _property_exists_in_type(self, type_definition): + props_def = type_definition.get_properties_def() + found = [props_def[self.args[1]]] \ + if self.args[1] in props_def else [] + return len(found) == 1 + + def result(self): + if len(self.args) >= 3: + # First check if there is property with this name + node_tpl = self._find_node_template(self.args[0]) + props = node_tpl.get_properties() if node_tpl else [] + index = 2 + found = [props[self.args[1]]] if self.args[1] in props else [] + if found: + property_value = found[0].value + else: + index = 3 + # then check the req or caps + property_value = self._find_req_or_cap_property(self.args[1], + self.args[2]) + if len(self.args) > index: + for elem in self.args[index:]: + if isinstance(property_value, list): + int_elem = int(elem) + property_value = self._get_index_value(property_value, + int_elem) + else: + property_value = self._get_attribute_value( + property_value, + elem) + else: + property_value = self._find_property(self.args[1]).value + if isinstance(property_value, Function): + return property_value.result() + return get_function(self.tosca_tpl, + self.context, + property_value) + + @property + def node_template_name(self): + return self.args[0] + + @property + def property_name(self): + if len(self.args) > 2: + return self.args[2] + return self.args[1] + + @property + def req_or_cap(self): + if len(self.args) > 2: + return self.args[1] + return None + + +class GetOperationOutput(Function): + def validate(self): + if len(self.args) == 4: + self._find_node_template(self.args[0]) + interface_name = self._find_interface_name(self.args[1]) + self._find_operation_name(interface_name, self.args[2]) + else: + ExceptionCollector.appendException( + ValueError(_('Illegal arguments for function "{0}". Expected ' + 'arguments: "template_name","interface_name",' + '"operation_name","output_variable_name"' + ).format(GET_OPERATION_OUTPUT))) + return + + def _find_interface_name(self, interface_name): + if interface_name in toscaparser.elements.interfaces.SECTIONS: + return interface_name + else: + ExceptionCollector.appendException( + ValueError(_('Enter a valid interface name' + ).format(GET_OPERATION_OUTPUT))) + return + + def _find_operation_name(self, interface_name, operation_name): + if(interface_name == 'Configure' or + interface_name == 'tosca.interfaces.node.relationship.Configure'): + if(operation_name in + StatefulEntityType. + interfaces_relationship_configure_operations): + return operation_name + else: + ExceptionCollector.appendException( + ValueError(_('Enter an operation of Configure interface' + ).format(GET_OPERATION_OUTPUT))) + return + elif(interface_name == 'Standard' or + interface_name == 'tosca.interfaces.node.lifecycle.Standard'): + if(operation_name in + StatefulEntityType.interfaces_node_lifecycle_operations): + return operation_name + else: + ExceptionCollector.appendException( + ValueError(_('Enter an operation of Standard interface' + ).format(GET_OPERATION_OUTPUT))) + return + else: + ExceptionCollector.appendException( + ValueError(_('Enter a valid operation name' + ).format(GET_OPERATION_OUTPUT))) + return + + def _find_node_template(self, node_template_name): + if node_template_name == TARGET: + if not isinstance(self.context.type_definition, RelationshipType): + ExceptionCollector.appendException( + KeyError(_('"TARGET" keyword can only be used in context' + ' to "Relationships" target node'))) + return + return self.context.target + if node_template_name == SOURCE: + if not isinstance(self.context.type_definition, RelationshipType): + ExceptionCollector.appendException( + KeyError(_('"SOURCE" keyword can only be used in context' + ' to "Relationships" source node'))) + return + return self.context.source + name = self.context.name \ + if node_template_name == SELF and \ + not isinstance(self.context, list) \ + else node_template_name + for node_template in self.tosca_tpl.nodetemplates: + if node_template.name == name: + return node_template + ExceptionCollector.appendException( + KeyError(_( + 'Node template "{0}" was not found.' + ).format(node_template_name))) + + def result(self): + return self + + +class Concat(Function): + """Validate the function and provide an instance of the function + + Concatenation of values are supposed to be produced at runtime and + therefore its the responsibility of the TOSCA engine to implement the + evaluation of Concat functions. + + Arguments: + + * List of strings that needs to be concatenated + + Example: + + [ 'http://', + get_attribute: [ server, public_address ], + ':' , + get_attribute: [ server, port ] ] + """ + + def validate(self): + if len(self.args) < 1: + ExceptionCollector.appendException( + ValueError(_('Invalid arguments for function "{0}". Expected ' + 'at least one arguments.').format(CONCAT))) + + def result(self): + return self + + +class Token(Function): + """Validate the function and provide an instance of the function + + The token function is used within a TOSCA service template on a string to + parse out (tokenize) substrings separated by one or more token characters + within a larger string. + + + Arguments: + + * The composite string that contains one or more substrings separated by + token characters. + * The string that contains one or more token characters that separate + substrings within the composite string. + * The integer indicates the index of the substring to return from the + composite string. Note that the first substring is denoted by using + the '0' (zero) integer value. + + Example: + + [ get_attribute: [ my_server, data_endpoint, ip_address ], ':', 1 ] + + """ + + def validate(self): + if len(self.args) < 3: + ExceptionCollector.appendException( + ValueError(_('Invalid arguments for function "{0}". Expected ' + 'at least three arguments.').format(TOKEN))) + else: + if not isinstance(self.args[1], str) or len(self.args[1]) != 1: + ExceptionCollector.appendException( + ValueError(_('Invalid arguments for function "{0}". ' + 'Expected single char value as second ' + 'argument.').format(TOKEN))) + + if not isinstance(self.args[2], int): + ExceptionCollector.appendException( + ValueError(_('Invalid arguments for function "{0}". ' + 'Expected integer value as third ' + 'argument.').format(TOKEN))) + + def result(self): + return self + +function_mappings = { + GET_PROPERTY: GetProperty, + GET_INPUT: GetInput, + GET_ATTRIBUTE: GetAttribute, + GET_OPERATION_OUTPUT: GetOperationOutput, + CONCAT: Concat, + TOKEN: Token +} + + +def is_function(function): + """Returns True if the provided function is a Tosca intrinsic function. + + Examples: + + * "{ get_property: { SELF, port } }" + * "{ get_input: db_name }" + * Function instance + + :param function: Function as string or a Function instance. + :return: True if function is a Tosca intrinsic function, otherwise False. + """ + if isinstance(function, dict) and len(function) == 1: + func_name = list(function.keys())[0] + return func_name in function_mappings + return isinstance(function, Function) + + +def get_function(tosca_tpl, node_template, raw_function): + """Gets a Function instance representing the provided template function. + + If the format provided raw_function format is not relevant for template + functions or if the function name doesn't exist in function mapping the + method returns the provided raw_function. + + :param tosca_tpl: The tosca template. + :param node_template: The node template the function is specified for. + :param raw_function: The raw function as dict. + :return: Template function as Function instance or the raw_function if + parsing was unsuccessful. + """ + if is_function(raw_function): + if isinstance(raw_function, dict): + func_name = list(raw_function.keys())[0] + if func_name in function_mappings: + func = function_mappings[func_name] + func_args = list(raw_function.values())[0] + if not isinstance(func_args, list): + func_args = [func_args] + return func(tosca_tpl, node_template, func_name, func_args) + return raw_function diff --git a/nfvparser/toscaparser/groups.py b/nfvparser/toscaparser/groups.py new file mode 100644 index 0000000..6a3e5c7 --- /dev/null +++ b/nfvparser/toscaparser/groups.py @@ -0,0 +1,55 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import UnknownFieldError +from toscaparser.entity_template import EntityTemplate +from toscaparser.utils import validateutils + +SECTIONS = (TYPE, METADATA, DESCRIPTION, PROPERTIES, MEMBERS, INTERFACES) = \ + ('type', 'metadata', 'description', + 'properties', 'members', 'interfaces') + + +class Group(EntityTemplate): + + def __init__(self, name, group_templates, member_nodes, custom_defs=None): + super(Group, self).__init__(name, + group_templates, + 'group_type', + custom_defs) + self.name = name + self.tpl = group_templates + self.meta_data = None + if self.METADATA in self.tpl: + self.meta_data = self.tpl.get(self.METADATA) + validateutils.validate_map(self.meta_data) + self.member_nodes = member_nodes + self._validate_keys() + + @property + def members(self): + return self.entity_tpl.get('members') + + @property + def description(self): + return self.entity_tpl.get('description') + + def get_member_nodes(self): + return self.member_nodes + + def _validate_keys(self): + for key in self.entity_tpl.keys(): + if key not in SECTIONS: + ExceptionCollector.appendException( + UnknownFieldError(what='Groups "%s"' % self.name, + field=key)) diff --git a/nfvparser/toscaparser/imports.py b/nfvparser/toscaparser/imports.py new file mode 100644 index 0000000..429a396 --- /dev/null +++ b/nfvparser/toscaparser/imports.py @@ -0,0 +1,290 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import logging +import os + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import InvalidPropertyValueError +from toscaparser.common.exception import MissingRequiredFieldError +from toscaparser.common.exception import UnknownFieldError +from toscaparser.common.exception import ValidationError +from toscaparser.elements.tosca_type_validation import TypeValidation +from toscaparser.utils.gettextutils import _ +import toscaparser.utils.urlutils +import toscaparser.utils.yamlparser + +YAML_LOADER = toscaparser.utils.yamlparser.load_yaml +log = logging.getLogger("tosca") + + +class ImportsLoader(object): + + IMPORTS_SECTION = (FILE, REPOSITORY, NAMESPACE_URI, NAMESPACE_PREFIX) = \ + ('file', 'repository', 'namespace_uri', + 'namespace_prefix') + + def __init__(self, importslist, path, type_definition_list=None, + tpl=None): + self.importslist = importslist + self.custom_defs = {} + self.nested_tosca_tpls = [] + if not path and not tpl: + msg = _('Input tosca template is not provided.') + log.warning(msg) + ExceptionCollector.appendException(ValidationError(message=msg)) + self.path = path + self.repositories = {} + if tpl and tpl.get('repositories'): + self.repositories = tpl.get('repositories') + self.type_definition_list = [] + if type_definition_list: + if isinstance(type_definition_list, list): + self.type_definition_list = type_definition_list + else: + self.type_definition_list.append(type_definition_list) + self._validate_and_load_imports() + + def get_custom_defs(self): + return self.custom_defs + + def get_nested_tosca_tpls(self): + return self.nested_tosca_tpls + + def _validate_and_load_imports(self): + imports_names = set() + + if not self.importslist: + msg = _('"imports" keyname is defined without including ' + 'templates.') + log.error(msg) + ExceptionCollector.appendException(ValidationError(message=msg)) + return + + for import_def in self.importslist: + if isinstance(import_def, dict): + for import_name, import_uri in import_def.items(): + if import_name in imports_names: + msg = (_('Duplicate import name "%s" was found.') % + import_name) + log.error(msg) + ExceptionCollector.appendException( + ValidationError(message=msg)) + imports_names.add(import_name) + + full_file_name, custom_type = self._load_import_template( + import_name, import_uri) + namespace_prefix = None + if isinstance(import_uri, dict): + namespace_prefix = import_uri.get( + self.NAMESPACE_PREFIX) + if custom_type: + TypeValidation(custom_type, import_def) + self._update_custom_def(custom_type, namespace_prefix) + else: # old style of imports + full_file_name, custom_type = self._load_import_template( + None, import_def) + if custom_type: + TypeValidation( + custom_type, import_def) + self._update_custom_def(custom_type, None) + + self._update_nested_tosca_tpls(full_file_name, custom_type) + + def _update_custom_def(self, custom_type, namespace_prefix): + outer_custom_types = {} + for type_def in self.type_definition_list: + outer_custom_types = custom_type.get(type_def) + if outer_custom_types: + if type_def == "imports": + for i in self.custom_defs.get('imports', []): + if i not in outer_custom_types: + outer_custom_types.append(i) + self.custom_defs.update({'imports': outer_custom_types}) + else: + if namespace_prefix: + prefix_custom_types = {} + for type_def_key in outer_custom_types.keys(): + namespace_prefix_to_key = (namespace_prefix + + "." + type_def_key) + prefix_custom_types[namespace_prefix_to_key] = \ + outer_custom_types[type_def_key] + self.custom_defs.update(prefix_custom_types) + else: + self.custom_defs.update(outer_custom_types) + + def _update_nested_tosca_tpls(self, full_file_name, custom_tpl): + if full_file_name and custom_tpl: + topo_tpl = {full_file_name: custom_tpl} + self.nested_tosca_tpls.append(topo_tpl) + + def _validate_import_keys(self, import_name, import_uri_def): + if self.FILE not in import_uri_def.keys(): + log.warning(_('Missing keyname "file" in import "%(name)s".') + % {'name': import_name}) + ExceptionCollector.appendException( + MissingRequiredFieldError( + what='Import of template "%s"' % import_name, + required=self.FILE)) + for key in import_uri_def.keys(): + if key not in self.IMPORTS_SECTION: + log.warning(_('Unknown keyname "%(key)s" error in ' + 'imported definition "%(def)s".') + % {'key': key, 'def': import_name}) + ExceptionCollector.appendException( + UnknownFieldError( + what='Import of template "%s"' % import_name, + field=key)) + + def _load_import_template(self, import_name, import_uri_def): + """Handle custom types defined in imported template files + + This method loads the custom type definitions referenced in "imports" + section of the TOSCA YAML template by determining whether each import + is specified via a file reference (by relative or absolute path) or a + URL reference. + + Possibilities: + +----------+--------+------------------------------+ + | template | import | comment | + +----------+--------+------------------------------+ + | file | file | OK | + | file | URL | OK | + | preparsed| file | file must be a full path | + | preparsed| URL | OK | + | URL | file | file must be a relative path | + | URL | URL | OK | + +----------+--------+------------------------------+ + """ + short_import_notation = False + if isinstance(import_uri_def, dict): + self._validate_import_keys(import_name, import_uri_def) + file_name = import_uri_def.get(self.FILE) + repository = import_uri_def.get(self.REPOSITORY) + repos = self.repositories.keys() + if repository is not None: + if repository not in repos: + ExceptionCollector.appendException( + InvalidPropertyValueError( + what=_('Repository is not found in "%s"') % repos)) + else: + file_name = import_uri_def + repository = None + short_import_notation = True + + if not file_name: + msg = (_('A template file name is not provided with import ' + 'definition "%(import_name)s".') + % {'import_name': import_name}) + log.error(msg) + ExceptionCollector.appendException(ValidationError(message=msg)) + return None, None + + if toscaparser.utils.urlutils.UrlUtils.validate_url(file_name): + return file_name, YAML_LOADER(file_name, False) + elif not repository: + import_template = None + if self.path: + if toscaparser.utils.urlutils.UrlUtils.validate_url(self.path): + if os.path.isabs(file_name): + msg = (_('Absolute file name "%(name)s" cannot be ' + 'used in a URL-based input template ' + '"%(template)s".') + % {'name': file_name, 'template': self.path}) + log.error(msg) + ExceptionCollector.appendException(ImportError(msg)) + return None, None + import_template = toscaparser.utils.urlutils.UrlUtils.\ + join_url(self.path, file_name) + a_file = False + else: + a_file = True + main_a_file = os.path.isfile(self.path) + + if main_a_file: + if os.path.isfile(file_name): + import_template = file_name + else: + full_path = os.path.join( + os.path.dirname(os.path.abspath(self.path)), + file_name) + if os.path.isfile(full_path): + import_template = full_path + else: + file_path = file_name.rpartition("/") + dir_path = os.path.dirname(os.path.abspath( + self.path)) + if file_path[0] != '' and dir_path.endswith( + file_path[0]): + import_template = dir_path + "/" +\ + file_path[2] + if not os.path.isfile(import_template): + msg = (_('"%(import_template)s" is' + 'not a valid file') + % {'import_template': + import_template}) + log.error(msg) + ExceptionCollector.appendException + (ValueError(msg)) + else: # template is pre-parsed + if os.path.isabs(file_name) and os.path.isfile(file_name): + a_file = True + import_template = file_name + else: + msg = (_('Relative file name "%(name)s" cannot be used ' + 'in a pre-parsed input template.') + % {'name': file_name}) + log.error(msg) + ExceptionCollector.appendException(ImportError(msg)) + return None, None + + if not import_template: + log.error(_('Import "%(name)s" is not valid.') % + {'name': import_uri_def}) + ExceptionCollector.appendException( + ImportError(_('Import "%s" is not valid.') % + import_uri_def)) + return None, None + return import_template, YAML_LOADER(import_template, a_file) + + if short_import_notation: + log.error(_('Import "%(name)s" is not valid.') % import_uri_def) + ExceptionCollector.appendException( + ImportError(_('Import "%s" is not valid.') % import_uri_def)) + return None, None + + full_url = "" + if repository: + if self.repositories: + for repo_name, repo_def in self.repositories.items(): + if repo_name == repository: + # Remove leading, ending spaces and strip + # the last character if "/" + repo_url = ((repo_def['url']).strip()).rstrip("//") + full_url = repo_url + "/" + file_name + + if not full_url: + msg = (_('referenced repository "%(n_uri)s" in import ' + 'definition "%(tpl)s" not found.') + % {'n_uri': repository, 'tpl': import_name}) + log.error(msg) + ExceptionCollector.appendException(ImportError(msg)) + return None, None + + if toscaparser.utils.urlutils.UrlUtils.validate_url(full_url): + return full_url, YAML_LOADER(full_url, False) + else: + msg = (_('repository url "%(n_uri)s" is not valid in import ' + 'definition "%(tpl)s".') + % {'n_uri': repo_url, 'tpl': import_name}) + log.error(msg) + ExceptionCollector.appendException(ImportError(msg)) diff --git a/nfvparser/toscaparser/nodetemplate.py b/nfvparser/toscaparser/nodetemplate.py new file mode 100644 index 0000000..0d65ac5 --- /dev/null +++ b/nfvparser/toscaparser/nodetemplate.py @@ -0,0 +1,298 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + + +import logging + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import InvalidPropertyValueError +from toscaparser.common.exception import MissingRequiredFieldError +from toscaparser.common.exception import TypeMismatchError +from toscaparser.common.exception import UnknownFieldError +from toscaparser.common.exception import ValidationError +from toscaparser.dataentity import DataEntity +from toscaparser.elements.interfaces import CONFIGURE +from toscaparser.elements.interfaces import CONFIGURE_SHORTNAME +from toscaparser.elements.interfaces import INTERFACE_DEF_RESERVED_WORDS +from toscaparser.elements.interfaces import InterfacesDef +from toscaparser.elements.interfaces import LIFECYCLE +from toscaparser.elements.interfaces import LIFECYCLE_SHORTNAME +from toscaparser.elements.relationshiptype import RelationshipType +from toscaparser.entity_template import EntityTemplate +from toscaparser.relationship_template import RelationshipTemplate +from toscaparser.utils.gettextutils import _ + +log = logging.getLogger('tosca') + + +class NodeTemplate(EntityTemplate): + '''Node template from a Tosca profile.''' + def __init__(self, name, node_templates, custom_def=None, + available_rel_tpls=None, available_rel_types=None): + super(NodeTemplate, self).__init__(name, node_templates[name], + 'node_type', + custom_def) + self.templates = node_templates + self._validate_fields(node_templates[name]) + self.custom_def = custom_def + self.related = {} + self.relationship_tpl = [] + self.available_rel_tpls = available_rel_tpls + self.available_rel_types = available_rel_types + self._relationships = {} + self.substitution_mapped = None + + @property + def relationships(self): + if not self._relationships: + requires = self.requirements + if requires and isinstance(requires, list): + for r in requires: + for r1, value in r.items(): + explicit = self._get_explicit_relationship(r, value) + if explicit: + for key, value in explicit.items(): + self._relationships[key] = value + return self._relationships + + def _get_explicit_relationship(self, req, value): + """Handle explicit relationship + + For example, + - req: + node: DBMS + relationship: tosca.relationships.HostedOn + """ + explicit_relation = {} + node = value.get('node') if isinstance(value, dict) else value + + if node: + # TODO(spzala) implement look up once Glance meta data is available + # to find a matching TOSCA node using the TOSCA types + msg = _('Lookup by TOSCA types is not supported. ' + 'Requirement node "%(node)s" for "%(name)s"' + ' can not be full-filled.') \ + % {'node': node, 'name': self.name} + if (node in list(self.type_definition.TOSCA_DEF.keys()) + or node in self.custom_def): + ExceptionCollector.appendException(NotImplementedError(msg)) + return + + if node not in self.templates: + ExceptionCollector.appendException( + KeyError(_('Node template "%(node)s" was not found' + ' in "%(name)s".') + % {'node': node, 'name': self.name})) + return + + related_tpl = NodeTemplate(node, self.templates, self.custom_def) + relationship = value.get('relationship') \ + if isinstance(value, dict) else None + # check if it's type has relationship defined + if not relationship: + parent_reqs = self.type_definition.get_all_requirements() + if parent_reqs is None: + ExceptionCollector.appendException( + ValidationError(message='parent_req is ' + + str(parent_reqs))) + else: + for key in req.keys(): + for req_dict in parent_reqs: + if key in req_dict.keys(): + relationship = (req_dict.get(key). + get('relationship')) + break + if relationship: + found_relationship_tpl = False + + # apply available relationship templates if found + if self.available_rel_tpls: + for tpl in self.available_rel_tpls: + if tpl.name == relationship: + rtype = RelationshipType(tpl.type, None, + self.custom_def) + explicit_relation[rtype] = related_tpl + tpl.target = related_tpl + tpl.source = self + self.relationship_tpl.append(tpl) + found_relationship_tpl = True + # create relationship template object. + rel_prfx = self.type_definition.RELATIONSHIP_PREFIX + if not found_relationship_tpl: + if isinstance(relationship, dict): + relationship = relationship.get('type') + if relationship: + if self.available_rel_types and \ + relationship in self.available_rel_types.keys(): + pass + elif not relationship.startswith(rel_prfx): + relationship = rel_prfx + relationship + else: + ExceptionCollector.appendException( + MissingRequiredFieldError( + what=_('"relationship" used in template ' + '"%s"') % related_tpl.name, + required=self.TYPE)) + for rtype in self.type_definition.relationship.keys(): + if rtype.type == relationship: + explicit_relation[rtype] = related_tpl + related_tpl._add_relationship_template(req, + rtype.type, + self) + elif self.available_rel_types: + if relationship in self.available_rel_types.keys(): + rel_type_def = self.available_rel_types.\ + get(relationship) + if 'derived_from' in rel_type_def: + super_type = \ + rel_type_def.get('derived_from') + if not super_type.startswith(rel_prfx): + super_type = rel_prfx + super_type + if rtype.type == super_type: + explicit_relation[rtype] = related_tpl + related_tpl.\ + _add_relationship_template( + req, rtype.type, self) + return explicit_relation + + def _add_relationship_template(self, requirement, rtype, source): + req = requirement.copy() + req['type'] = rtype + tpl = RelationshipTemplate(req, rtype, self.custom_def, self, source) + self.relationship_tpl.append(tpl) + + def get_relationship_template(self): + return self.relationship_tpl + + def _add_next(self, nodetpl, relationship): + self.related[nodetpl] = relationship + + @property + def related_nodes(self): + if not self.related: + for relation, node in self.type_definition.relationship.items(): + for tpl in self.templates: + if tpl == node.type: + self.related[NodeTemplate(tpl)] = relation + return self.related.keys() + + def validate(self, tosca_tpl=None): + self._validate_capabilities() + self._validate_requirements() + self._validate_properties(self.entity_tpl, self.type_definition) + self._validate_interfaces() + for prop in self.get_properties_objects(): + prop.validate() + + def _validate_requirements(self): + type_requires = self.type_definition.get_all_requirements() + allowed_reqs = ["template"] + if type_requires: + for treq in type_requires: + for key, value in treq.items(): + allowed_reqs.append(key) + if isinstance(value, dict): + for key in value: + allowed_reqs.append(key) + + requires = self.type_definition.get_value(self.REQUIREMENTS, + self.entity_tpl) + if requires: + if not isinstance(requires, list): + ExceptionCollector.appendException( + TypeMismatchError( + what='"requirements" of template "%s"' % self.name, + type='list')) + else: + for req in requires: + for r1, value in req.items(): + if isinstance(value, dict): + self._validate_requirements_keys(value) + self._validate_requirements_properties(value) + allowed_reqs.append(r1) + self._common_validate_field(req, allowed_reqs, + 'requirements') + + def _validate_requirements_properties(self, requirements): + # TODO(anyone): Only occurrences property of the requirements is + # validated here. Validation of other requirement properties are being + # validated in different files. Better to keep all the requirements + # properties validation here. + for key, value in requirements.items(): + if key == 'occurrences': + self._validate_occurrences(value) + break + + def _validate_occurrences(self, occurrences): + DataEntity.validate_datatype('list', occurrences) + for value in occurrences: + DataEntity.validate_datatype('integer', value) + if len(occurrences) != 2 or not (0 <= occurrences[0] <= occurrences[1]) \ + or occurrences[1] == 0: + ExceptionCollector.appendException( + InvalidPropertyValueError(what=(occurrences))) + + def _validate_requirements_keys(self, requirement): + for key in requirement.keys(): + if key not in self.REQUIREMENTS_SECTION: + ExceptionCollector.appendException( + UnknownFieldError( + what='"requirements" of template "%s"' % self.name, + field=key)) + + def _validate_interfaces(self): + ifaces = self.type_definition.get_value(self.INTERFACES, + self.entity_tpl) + if ifaces: + for name, value in ifaces.items(): + if name in (LIFECYCLE, LIFECYCLE_SHORTNAME): + self._common_validate_field( + value, InterfacesDef. + interfaces_node_lifecycle_operations, + 'interfaces') + elif name in (CONFIGURE, CONFIGURE_SHORTNAME): + self._common_validate_field( + value, InterfacesDef. + interfaces_relationship_configure_operations, + 'interfaces') + elif name in self.type_definition.interfaces.keys(): + self._common_validate_field( + value, + self._collect_custom_iface_operations(name), + 'interfaces') + else: + ExceptionCollector.appendException( + UnknownFieldError( + what='"interfaces" of template "%s"' % + self.name, field=name)) + + def _collect_custom_iface_operations(self, name): + allowed_operations = [] + nodetype_iface_def = self.type_definition.interfaces[name] + allowed_operations.extend(nodetype_iface_def.keys()) + if 'type' in nodetype_iface_def: + iface_type = nodetype_iface_def['type'] + if iface_type in self.type_definition.custom_def: + iface_type_def = self.type_definition.custom_def[iface_type] + else: + iface_type_def = self.type_definition.TOSCA_DEF[iface_type] + allowed_operations.extend(iface_type_def.keys()) + allowed_operations = [op for op in allowed_operations if + op not in INTERFACE_DEF_RESERVED_WORDS] + return allowed_operations + + def _validate_fields(self, nodetemplate): + for name in nodetemplate.keys(): + if name not in self.SECTIONS and name not in self.SPECIAL_SECTIONS: + ExceptionCollector.appendException( + UnknownFieldError(what='Node template "%s"' % self.name, + field=name)) diff --git a/nfvparser/toscaparser/parameters.py b/nfvparser/toscaparser/parameters.py new file mode 100644 index 0000000..787db00 --- /dev/null +++ b/nfvparser/toscaparser/parameters.py @@ -0,0 +1,128 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + + +import logging + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import MissingRequiredFieldError +from toscaparser.common.exception import UnknownFieldError +from toscaparser.dataentity import DataEntity +from toscaparser.elements.constraints import Schema +from toscaparser.elements.entity_type import EntityType +from toscaparser.utils.gettextutils import _ + + +log = logging.getLogger('tosca') + + +class Input(object): + + INPUTFIELD = (TYPE, DESCRIPTION, DEFAULT, CONSTRAINTS, REQUIRED, STATUS, + ENTRY_SCHEMA) = ('type', 'description', 'default', + 'constraints', 'required', 'status', + 'entry_schema') + + def __init__(self, name, schema_dict): + self.name = name + self.schema = Schema(name, schema_dict) + + self._validate_field() + self.validate_type(self.type) + + @property + def type(self): + return self.schema.type + + @property + def required(self): + return self.schema.required + + @property + def description(self): + return self.schema.description + + @property + def default(self): + return self.schema.default + + @property + def constraints(self): + return self.schema.constraints + + @property + def status(self): + return self.schema.status + + def validate(self, value=None): + if value is not None: + self._validate_value(value) + + def _validate_field(self): + for name in self.schema.schema: + if name not in self.INPUTFIELD: + ExceptionCollector.appendException( + UnknownFieldError(what='Input "%s"' % self.name, + field=name)) + + def validate_type(self, input_type): + if input_type not in Schema.PROPERTY_TYPES: + ExceptionCollector.appendException( + ValueError(_('Invalid type "%s".') % type)) + + # TODO(anyone) Need to test for any built-in datatype not just network + # that is, tosca.datatypes.* and not assume tosca.datatypes.network.* + # TODO(anyone) Add support for tosca.datatypes.Credential + def _validate_value(self, value): + tosca = EntityType.TOSCA_DEF + datatype = None + if self.type in tosca: + datatype = tosca[self.type] + elif EntityType.DATATYPE_NETWORK_PREFIX + self.type in tosca: + datatype = tosca[EntityType.DATATYPE_NETWORK_PREFIX + self.type] + + DataEntity.validate_datatype(self.type, value, None, datatype) + + +class Output(object): + + OUTPUTFIELD = (DESCRIPTION, VALUE) = ('description', 'value') + + def __init__(self, name, attrs): + self.name = name + self.attrs = attrs + + @property + def description(self): + return self.attrs.get(self.DESCRIPTION) + + @property + def value(self): + return self.attrs.get(self.VALUE) + + def validate(self): + self._validate_field() + + def _validate_field(self): + if not isinstance(self.attrs, dict): + ExceptionCollector.appendException( + MissingRequiredFieldError(what='Output "%s"' % self.name, + required=self.VALUE)) + if self.value is None: + ExceptionCollector.appendException( + MissingRequiredFieldError(what='Output "%s"' % self.name, + required=self.VALUE)) + for name in self.attrs: + if name not in self.OUTPUTFIELD: + ExceptionCollector.appendException( + UnknownFieldError(what='Output "%s"' % self.name, + field=name)) diff --git a/nfvparser/toscaparser/policy.py b/nfvparser/toscaparser/policy.py new file mode 100644 index 0000000..fedbeb4 --- /dev/null +++ b/nfvparser/toscaparser/policy.py @@ -0,0 +1,81 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + + +import logging + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import UnknownFieldError +from toscaparser.entity_template import EntityTemplate +from toscaparser.triggers import Triggers +from toscaparser.utils import validateutils + + +SECTIONS = (TYPE, METADATA, DESCRIPTION, PROPERTIES, TARGETS, TRIGGERS) = \ + ('type', 'metadata', 'description', + 'properties', 'targets', 'triggers') + +log = logging.getLogger('tosca') + + +class Policy(EntityTemplate): + '''Policies defined in Topology template.''' + def __init__(self, name, policy, targets=None, targets_type=None, + custom_def=None): + super(Policy, self).__init__(name, + policy, + 'policy_type', + custom_def) + self.meta_data = None + if self.METADATA in policy: + self.meta_data = policy.get(self.METADATA) + validateutils.validate_map(self.meta_data) + self.targets_list = targets + self.targets_type = targets_type + self.triggers = self._triggers(policy.get(TRIGGERS)) + self.properties = None + if 'properties' in policy: + self.properties = policy['properties'] + self._validate_keys() + + @property + def targets(self): + return self.entity_tpl.get('targets') + + @property + def description(self): + return self.entity_tpl.get('description') + + @property + def metadata(self): + return self.entity_tpl.get('metadata') + + def get_targets_type(self): + return self.targets_type + + def get_targets_list(self): + return self.targets_list + + def _triggers(self, triggers): + triggerObjs = [] + if triggers: + for name, trigger_tpl in triggers.items(): + triggersObj = Triggers(name, trigger_tpl) + triggerObjs.append(triggersObj) + return triggerObjs + + def _validate_keys(self): + for key in self.entity_tpl.keys(): + if key not in SECTIONS: + ExceptionCollector.appendException( + UnknownFieldError(what='Policy "%s"' % self.name, + field=key)) diff --git a/nfvparser/toscaparser/prereq/__init__.py b/nfvparser/toscaparser/prereq/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nfvparser/toscaparser/prereq/csar.py b/nfvparser/toscaparser/prereq/csar.py new file mode 100644 index 0000000..1cba5c4 --- /dev/null +++ b/nfvparser/toscaparser/prereq/csar.py @@ -0,0 +1,286 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import os.path +import requests +import shutil +import six +import tempfile +import yaml +import zipfile + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import URLException +from toscaparser.common.exception import ValidationError +from toscaparser.imports import ImportsLoader +from toscaparser.utils.gettextutils import _ +from toscaparser.utils.urlutils import UrlUtils + +try: # Python 2.x + from BytesIO import BytesIO +except ImportError: # Python 3.x + from io import BytesIO + + +class CSAR(object): + + def __init__(self, csar_file, a_file=True): + self.path = csar_file + self.a_file = a_file + self.is_validated = False + self.error_caught = False + self.csar = None + self.temp_dir = None + + def validate(self): + """Validate the provided CSAR file.""" + + self.is_validated = True + + # validate that the file or URL exists + missing_err_msg = (_('"%s" does not exist.') % self.path) + if self.a_file: + if not os.path.isfile(self.path): + ExceptionCollector.appendException( + ValidationError(message=missing_err_msg)) + return False + else: + self.csar = self.path + else: # a URL + if not UrlUtils.validate_url(self.path): + ExceptionCollector.appendException( + ValidationError(message=missing_err_msg)) + return False + else: + response = requests.get(self.path) + self.csar = BytesIO(response.content) + + # validate that it is a valid zip file + if not zipfile.is_zipfile(self.csar): + err_msg = (_('"%s" is not a valid zip file.') % self.path) + ExceptionCollector.appendException( + ValidationError(message=err_msg)) + return False + + # validate that it contains the metadata file in the correct location + self.zfile = zipfile.ZipFile(self.csar, 'r') + filelist = self.zfile.namelist() + if 'TOSCA-Metadata/TOSCA.meta' not in filelist: + err_msg = (_('"%s" is not a valid CSAR as it does not contain the ' + 'required file "TOSCA.meta" in the folder ' + '"TOSCA-Metadata".') % self.path) + ExceptionCollector.appendException( + ValidationError(message=err_msg)) + return False + + # validate that 'Entry-Definitions' property exists in TOSCA.meta + data = self.zfile.read('TOSCA-Metadata/TOSCA.meta') + invalid_yaml_err_msg = (_('The file "TOSCA-Metadata/TOSCA.meta" in ' + 'the CSAR "%s" does not contain valid YAML ' + 'content.') % self.path) + try: + meta = yaml.load(data) + if type(meta) is dict: + self.metadata = meta + else: + ExceptionCollector.appendException( + ValidationError(message=invalid_yaml_err_msg)) + return False + except yaml.YAMLError: + ExceptionCollector.appendException( + ValidationError(message=invalid_yaml_err_msg)) + return False + + if 'Entry-Definitions' not in self.metadata: + err_msg = (_('The CSAR "%s" is missing the required metadata ' + '"Entry-Definitions" in ' + '"TOSCA-Metadata/TOSCA.meta".') + % self.path) + ExceptionCollector.appendException( + ValidationError(message=err_msg)) + return False + + # validate that 'Entry-Definitions' metadata value points to an + # existing file in the CSAR + entry = self.metadata.get('Entry-Definitions') + if entry and entry not in filelist: + err_msg = (_('The "Entry-Definitions" file defined in the ' + 'CSAR "%s" does not exist.') % self.path) + ExceptionCollector.appendException( + ValidationError(message=err_msg)) + return False + + # validate that external references in the main template actually + # exist and are accessible + self._validate_external_references() + return not self.error_caught + + def get_metadata(self): + """Return the metadata dictionary.""" + + # validate the csar if not already validated + if not self.is_validated: + self.validate() + + # return a copy to avoid changes overwrite the original + return dict(self.metadata) if self.metadata else None + + def _get_metadata(self, key): + if not self.is_validated: + self.validate() + return self.metadata.get(key) + + def get_author(self): + return self._get_metadata('Created-By') + + def get_version(self): + return self._get_metadata('CSAR-Version') + + def get_main_template(self): + entry_def = self._get_metadata('Entry-Definitions') + if entry_def in self.zfile.namelist(): + return entry_def + + def get_main_template_yaml(self): + main_template = self.get_main_template() + if main_template: + data = self.zfile.read(main_template) + invalid_tosca_yaml_err_msg = ( + _('The file "%(template)s" in the CSAR "%(csar)s" does not ' + 'contain valid TOSCA YAML content.') % + {'template': main_template, 'csar': self.path}) + try: + tosca_yaml = yaml.load(data) + if type(tosca_yaml) is not dict: + ExceptionCollector.appendException( + ValidationError(message=invalid_tosca_yaml_err_msg)) + return tosca_yaml + except Exception: + ExceptionCollector.appendException( + ValidationError(message=invalid_tosca_yaml_err_msg)) + + def get_description(self): + desc = self._get_metadata('Description') + if desc is not None: + return desc + + self.metadata['Description'] = \ + self.get_main_template_yaml().get('description') + return self.metadata['Description'] + + def decompress(self): + if not self.is_validated: + self.validate() + self.temp_dir = tempfile.NamedTemporaryFile().name + with zipfile.ZipFile(self.csar, "r") as zf: + zf.extractall(self.temp_dir) + + def _validate_external_references(self): + """Extracts files referenced in the main template + + These references are currently supported: + * imports + * interface implementations + * artifacts + """ + try: + self.decompress() + main_tpl_file = self.get_main_template() + if not main_tpl_file: + return + main_tpl = self.get_main_template_yaml() + + if 'imports' in main_tpl: + ImportsLoader(main_tpl['imports'], + os.path.join(self.temp_dir, main_tpl_file)) + + if 'topology_template' in main_tpl: + topology_template = main_tpl['topology_template'] + + if 'node_templates' in topology_template: + node_templates = topology_template['node_templates'] + + for node_template_key in node_templates: + node_template = node_templates[node_template_key] + if 'artifacts' in node_template: + artifacts = node_template['artifacts'] + for artifact_key in artifacts: + artifact = artifacts[artifact_key] + if isinstance(artifact, six.string_types): + self._validate_external_reference( + main_tpl_file, + artifact) + elif isinstance(artifact, dict): + if 'file' in artifact: + self._validate_external_reference( + main_tpl_file, + artifact['file']) + else: + ExceptionCollector.appendException( + ValueError(_('Unexpected artifact ' + 'definition for "%s".') + % artifact_key)) + self.error_caught = True + if 'interfaces' in node_template: + interfaces = node_template['interfaces'] + for interface_key in interfaces: + interface = interfaces[interface_key] + for opertation_key in interface: + operation = interface[opertation_key] + if isinstance(operation, six.string_types): + self._validate_external_reference( + main_tpl_file, + operation, + False) + elif isinstance(operation, dict): + if 'implementation' in operation: + self._validate_external_reference( + main_tpl_file, + operation['implementation']) + finally: + if self.temp_dir: + shutil.rmtree(self.temp_dir) + + def _validate_external_reference(self, tpl_file, resource_file, + raise_exc=True): + """Verify that the external resource exists + + If resource_file is a URL verify that the URL is valid. + If resource_file is a relative path verify that the path is valid + considering base folder (self.temp_dir) and tpl_file. + Note that in a CSAR resource_file cannot be an absolute path. + """ + if UrlUtils.validate_url(resource_file): + msg = (_('The resource at "%s" cannot be accessed.') % + resource_file) + try: + if UrlUtils.url_accessible(resource_file): + return + else: + ExceptionCollector.appendException( + URLException(what=msg)) + self.error_caught = True + except Exception: + ExceptionCollector.appendException( + URLException(what=msg)) + self.error_caught = True + + if os.path.isfile(os.path.join(self.temp_dir, + os.path.dirname(tpl_file), + resource_file)): + return + + if raise_exc: + ExceptionCollector.appendException( + ValueError(_('The resource "%s" does not exist.') + % resource_file)) + self.error_caught = True diff --git a/nfvparser/toscaparser/properties.py b/nfvparser/toscaparser/properties.py new file mode 100644 index 0000000..c69b151 --- /dev/null +++ b/nfvparser/toscaparser/properties.py @@ -0,0 +1,77 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from toscaparser.dataentity import DataEntity +from toscaparser.elements.constraints import Schema +from toscaparser.functions import is_function + + +class Property(object): + '''TOSCA built-in Property type.''' + + PROPERTY_KEYS = ( + TYPE, REQUIRED, DESCRIPTION, DEFAULT, CONSTRAINTS + ) = ( + 'type', 'required', 'description', 'default', 'constraints' + ) + + ENTRY_SCHEMA_KEYS = ( + ENTRYTYPE, ENTRYPROPERTIES + ) = ( + 'type', 'properties' + ) + + def __init__(self, property_name, value, schema_dict, custom_def=None): + self.name = property_name + self.value = value + self.custom_def = custom_def + self.schema = Schema(property_name, schema_dict) + + @property + def type(self): + return self.schema.type + + @property + def required(self): + return self.schema.required + + @property + def description(self): + return self.schema.description + + @property + def default(self): + return self.schema.default + + @property + def constraints(self): + return self.schema.constraints + + @property + def entry_schema(self): + return self.schema.entry_schema + + def validate(self): + '''Validate if not a reference property.''' + if not is_function(self.value): + if self.type == Schema.STRING: + self.value = str(self.value) + self.value = DataEntity.validate_datatype(self.type, self.value, + self.entry_schema, + self.custom_def, + self.name) + self._validate_constraints() + + def _validate_constraints(self): + if self.constraints: + for constraint in self.constraints: + constraint.validate(self.value) diff --git a/nfvparser/toscaparser/relationship_template.py b/nfvparser/toscaparser/relationship_template.py new file mode 100644 index 0000000..db334c4 --- /dev/null +++ b/nfvparser/toscaparser/relationship_template.py @@ -0,0 +1,78 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + + +import logging + +from toscaparser.entity_template import EntityTemplate +from toscaparser.properties import Property + +SECTIONS = (DERIVED_FROM, PROPERTIES, REQUIREMENTS, + INTERFACES, CAPABILITIES, TYPE) = \ + ('derived_from', 'properties', 'requirements', 'interfaces', + 'capabilities', 'type') + +log = logging.getLogger('tosca') + + +class RelationshipTemplate(EntityTemplate): + '''Relationship template.''' + def __init__(self, relationship_template, name, custom_def=None, + target=None, source=None): + super(RelationshipTemplate, self).__init__(name, + relationship_template, + 'relationship_type', + custom_def) + self.name = name.lower() + self.target = target + self.source = source + + def get_properties_objects(self): + '''Return properties objects for this template.''' + if self._properties is None: + self._properties = self._create_relationship_properties() + return self._properties + + def _create_relationship_properties(self): + props = [] + properties = {} + relationship = self.entity_tpl.get('relationship') + + if not relationship: + for value in self.entity_tpl.values(): + if isinstance(value, dict): + relationship = value.get('relationship') + break + + if relationship: + properties = self.type_definition.get_value(self.PROPERTIES, + relationship) or {} + if not properties: + properties = self.entity_tpl.get(self.PROPERTIES) or {} + + if properties: + for name, value in properties.items(): + props_def = self.type_definition.get_properties_def() + if props_def and name in props_def: + if name in properties.keys(): + value = properties.get(name) + prop = Property(name, value, + props_def[name].schema, self.custom_def) + props.append(prop) + for p in self.type_definition.get_properties_def_objects(): + if p.default is not None and p.name not in properties.keys(): + prop = Property(p.name, p.default, p.schema, self.custom_def) + props.append(prop) + return props + + def validate(self): + self._validate_properties(self.entity_tpl, self.type_definition) diff --git a/nfvparser/toscaparser/repositories.py b/nfvparser/toscaparser/repositories.py new file mode 100644 index 0000000..184eba4 --- /dev/null +++ b/nfvparser/toscaparser/repositories.py @@ -0,0 +1,52 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import MissingRequiredFieldError +from toscaparser.common.exception import UnknownFieldError +from toscaparser.common.exception import URLException +from toscaparser.utils.gettextutils import _ +import toscaparser.utils.urlutils + +SECTIONS = (DESCRIPTION, URL, CREDENTIAL) = \ + ('description', 'url', 'credential') + + +class Repository(object): + def __init__(self, repositories, values): + self.name = repositories + self.reposit = values + if isinstance(self.reposit, dict): + if 'url' not in self.reposit.keys(): + ExceptionCollector.appendException( + MissingRequiredFieldError(what=_('Repository "%s"') + % self.name, required='url')) + self.url = self.reposit['url'] + self.load_and_validate(self.name, self.reposit) + + def load_and_validate(self, val, reposit_def): + self.keyname = val + if isinstance(reposit_def, dict): + for key in reposit_def.keys(): + if key not in SECTIONS: + ExceptionCollector.appendException( + UnknownFieldError(what=_('repositories "%s"') + % self.keyname, field=key)) + + if URL in reposit_def.keys(): + reposit_url = reposit_def.get(URL) + url_val = toscaparser.utils.urlutils.UrlUtils.\ + validate_url(reposit_url) + if url_val is not True: + ExceptionCollector.appendException( + URLException(what=_('repsositories "%s" Invalid Url') + % self.keyname)) diff --git a/nfvparser/toscaparser/shell.py b/nfvparser/toscaparser/shell.py new file mode 100644 index 0000000..1d98f1a --- /dev/null +++ b/nfvparser/toscaparser/shell.py @@ -0,0 +1,120 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + + +import argparse +import os +import sys + +from toscaparser.tosca_template import ToscaTemplate +from toscaparser.utils.gettextutils import _ +import toscaparser.utils.urlutils + +""" +CLI entry point to show how TOSCA Parser can be used programmatically + +This is a basic command line utility showing the entry point in the +TOSCA Parser and how to iterate over parsed template. It can be extended +or modified to fit an individual need. + +It can be used as, +#tosca-parser --template-file= +#tosca-parser --template-file= +#tosca-parser --template-file= + +e.g. +#tosca-parser + --template-file=toscaparser/tests/data/tosca_helloworld.yaml +#tosca-parser + --template-file=toscaparser/tests/data/CSAR/csar_hello_world.zip +""" + + +class ParserShell(object): + + def get_parser(self, argv): + parser = argparse.ArgumentParser(prog="tosca-parser") + + parser.add_argument('--template-file', + metavar='', + required=True, + help=_('YAML template or CSAR file to parse.')) + + return parser + + def main(self, argv): + parser = self.get_parser(argv) + (args, extra_args) = parser.parse_known_args(argv) + path = args.template_file + if os.path.isfile(path): + self.parse(path) + elif toscaparser.utils.urlutils.UrlUtils.validate_url(path): + self.parse(path, False) + else: + raise ValueError(_('"%(path)s" is not a valid file.') + % {'path': path}) + + def parse(self, path, a_file=True): + output = None + tosca = ToscaTemplate(path, None, a_file) + + version = tosca.version + if tosca.version: + print("\nversion: " + version) + + if hasattr(tosca, 'description'): + description = tosca.description + if description: + print("\ndescription: " + description) + + if hasattr(tosca, 'inputs'): + inputs = tosca.inputs + if inputs: + print("\ninputs:") + for input in inputs: + print("\t" + input.name) + + if hasattr(tosca, 'nodetemplates'): + nodetemplates = tosca.nodetemplates + if nodetemplates: + print("\nnodetemplates:") + for node in nodetemplates: + print("\t" + node.name) + + # example of retrieving policy object + '''if hasattr(tosca, 'policies'): + policies = tosca.policies + if policies: + print("policies:") + for policy in policies: + print("\t" + policy.name) + if policy.triggers: + print("\ttriggers:") + for trigger in policy.triggers: + print("\ttrigger name:" + trigger.name)''' + + if hasattr(tosca, 'outputs'): + outputs = tosca.outputs + if outputs: + print("\noutputs:") + for output in outputs: + print("\t" + output.name) + + +def main(args=None): + if args is None: + args = sys.argv[1:] + ParserShell().main(args) + + +if __name__ == '__main__': + main() diff --git a/nfvparser/toscaparser/substitution_mappings.py b/nfvparser/toscaparser/substitution_mappings.py new file mode 100644 index 0000000..dea5de7 --- /dev/null +++ b/nfvparser/toscaparser/substitution_mappings.py @@ -0,0 +1,228 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import logging + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import InvalidNodeTypeError +from toscaparser.common.exception import MissingDefaultValueError +from toscaparser.common.exception import MissingRequiredFieldError +from toscaparser.common.exception import MissingRequiredInputError +from toscaparser.common.exception import MissingRequiredOutputError +from toscaparser.common.exception import UnknownFieldError +from toscaparser.common.exception import UnknownOutputError +from toscaparser.elements.nodetype import NodeType +from toscaparser.utils.gettextutils import _ + +log = logging.getLogger('tosca') + + +class SubstitutionMappings(object): + '''SubstitutionMappings class declaration + + SubstitutionMappings exports the topology template as an + implementation of a Node type. + ''' + + SECTIONS = (NODE_TYPE, REQUIREMENTS, CAPABILITIES) = \ + ('node_type', 'requirements', 'capabilities') + + OPTIONAL_OUTPUTS = ['tosca_id', 'tosca_name', 'state'] + + def __init__(self, sub_mapping_def, nodetemplates, inputs, outputs, + sub_mapped_node_template, custom_defs): + self.nodetemplates = nodetemplates + self.sub_mapping_def = sub_mapping_def + self.inputs = inputs or [] + self.outputs = outputs or [] + self.sub_mapped_node_template = sub_mapped_node_template + self.custom_defs = custom_defs or {} + self._validate() + + self._capabilities = None + self._requirements = None + + @property + def type(self): + if self.sub_mapping_def: + return self.sub_mapping_def.get(self.NODE_TYPE) + + @classmethod + def get_node_type(cls, sub_mapping_def): + if isinstance(sub_mapping_def, dict): + return sub_mapping_def.get(cls.NODE_TYPE) + + @property + def node_type(self): + return self.sub_mapping_def.get(self.NODE_TYPE) + + @property + def capabilities(self): + return self.sub_mapping_def.get(self.CAPABILITIES) + + @property + def requirements(self): + return self.sub_mapping_def.get(self.REQUIREMENTS) + + @property + def node_definition(self): + return NodeType(self.node_type, self.custom_defs) + + def _validate(self): + # Basic validation + self._validate_keys() + self._validate_type() + + # SubstitutionMapping class syntax validation + self._validate_inputs() + self._validate_capabilities() + self._validate_requirements() + self._validate_outputs() + + def _validate_keys(self): + """validate the keys of substitution mappings.""" + for key in self.sub_mapping_def.keys(): + if key not in self.SECTIONS: + ExceptionCollector.appendException( + UnknownFieldError(what=_('SubstitutionMappings'), + field=key)) + + def _validate_type(self): + """validate the node_type of substitution mappings.""" + node_type = self.sub_mapping_def.get(self.NODE_TYPE) + if not node_type: + ExceptionCollector.appendException( + MissingRequiredFieldError( + what=_('SubstitutionMappings used in topology_template'), + required=self.NODE_TYPE)) + + node_type_def = self.custom_defs.get(node_type) + if not node_type_def: + ExceptionCollector.appendException( + InvalidNodeTypeError(what=node_type)) + + def _validate_inputs(self): + """validate the inputs of substitution mappings. + + The inputs defined by the topology template have to match the + properties of the node type or the substituted node template. If + there are more inputs than the substituted node has properties, + default values must be defined for those inputs. + """ + + all_inputs = set([input.name for input in self.inputs]) + required_properties = set([p.name for p in + self.node_definition. + get_properties_def_objects() + if p.required and p.default is None]) + # Must provide inputs for required properties of node type. + for property in required_properties: + # Check property which is 'required' and has no 'default' value + if property not in all_inputs: + ExceptionCollector.appendException( + MissingRequiredInputError( + what=_('SubstitutionMappings with node_type ') + + self.node_type, + input_name=property)) + + # If the optional properties of node type need to be customized by + # substituted node, it also is necessary to define inputs for them, + # otherwise they are not mandatory to be defined. + customized_parameters = set(self.sub_mapped_node_template + .get_properties().keys() + if self.sub_mapped_node_template else []) + all_properties = set(self.node_definition.get_properties_def()) + for parameter in customized_parameters - all_inputs: + if parameter in all_properties: + ExceptionCollector.appendException( + MissingRequiredInputError( + what=_('SubstitutionMappings with node_type ') + + self.node_type, + input_name=parameter)) + + # Additional inputs are not in the properties of node type must + # provide default values. Currently the scenario may not happen + # because of parameters validation in nodetemplate, here is a + # guarantee. + for input in self.inputs: + if input.name in all_inputs - all_properties \ + and input.default is None: + ExceptionCollector.appendException( + MissingDefaultValueError( + what=_('SubstitutionMappings with node_type ') + + self.node_type, + input_name=input.name)) + + def _validate_capabilities(self): + """validate the capabilities of substitution mappings.""" + + # The capabilites must be in node template wchich be mapped. + tpls_capabilities = self.sub_mapping_def.get(self.CAPABILITIES) + node_capabiliteys = self.sub_mapped_node_template.get_capabilities() \ + if self.sub_mapped_node_template else None + for cap in node_capabiliteys.keys() if node_capabiliteys else []: + if (tpls_capabilities and + cap not in list(tpls_capabilities.keys())): + pass + # ExceptionCollector.appendException( + # UnknownFieldError(what='SubstitutionMappings', + # field=cap)) + + def _validate_requirements(self): + """validate the requirements of substitution mappings.""" + + # The requirements must be in node template wchich be mapped. + tpls_requirements = self.sub_mapping_def.get(self.REQUIREMENTS) + node_requirements = self.sub_mapped_node_template.requirements \ + if self.sub_mapped_node_template else None + for req in node_requirements if node_requirements else []: + if (tpls_requirements and + req not in list(tpls_requirements.keys())): + pass + # ExceptionCollector.appendException( + # UnknownFieldError(what='SubstitutionMappings', + # field=req)) + + def _validate_outputs(self): + """validate the outputs of substitution mappings. + + The outputs defined by the topology template have to match the + attributes of the node type or the substituted node template, + and the observable attributes of the substituted node template + have to be defined as attributes of the node type or outputs in + the topology template. + """ + + # The outputs defined by the topology template have to match the + # attributes of the node type according to the specification, but + # it's reasonable that there are more inputs than the node type + # has properties, the specification will be amended? + for output in self.outputs: + if output.name not in self.node_definition.get_attributes_def(): + ExceptionCollector.appendException( + UnknownOutputError( + where=_('SubstitutionMappings with node_type ') + + self.node_type, + output_name=output.name)) + + # The observable attributes of the substituted node template + # have to be defined as attributes of the node type or outputs in + # the topology template, the attributes in tosca.node.root are + # optional. + for attribute in self.node_definition.get_attributes_def(): + if attribute not in [output.name for output in self.outputs] \ + and attribute not in self.OPTIONAL_OUTPUTS: + ExceptionCollector.appendException( + MissingRequiredOutputError( + what=_('SubstitutionMappings with node_type ') + + self.node_type, + output_name=attribute)) diff --git a/nfvparser/toscaparser/tests/__init__.py b/nfvparser/toscaparser/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nfvparser/toscaparser/tests/artifacts/collectd/config.py b/nfvparser/toscaparser/tests/artifacts/collectd/config.py new file mode 100644 index 0000000..686bbd1 --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/collectd/config.py @@ -0,0 +1,25 @@ +#!/usr/bin/python + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +# This script configures collectd to send metric data to the +# logstash server port 25826 +# The environment variable logstash_ip is expected to be set up +import os +with open("/etc/collectd/collectd.conf.d/tosca_elk.conf", "w") as fh: + fh.write(""" + LoadPlugin network + + Server "%s" "25826" + + """ % (os.environ['logstash_ip'])) diff --git a/nfvparser/toscaparser/tests/artifacts/collectd/create.sh b/nfvparser/toscaparser/tests/artifacts/collectd/create.sh new file mode 100644 index 0000000..a483b88 --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/collectd/create.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# This script install collectd for monitoring data + +apt-get update +apt-get install -y collectd diff --git a/nfvparser/toscaparser/tests/artifacts/collectd/start.sh b/nfvparser/toscaparser/tests/artifacts/collectd/start.sh new file mode 100644 index 0000000..7e8e033 --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/collectd/start.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# This script starts collectd as a service in init.d +service collectd stop +service collectd start diff --git a/nfvparser/toscaparser/tests/artifacts/elasticsearch/create.sh b/nfvparser/toscaparser/tests/artifacts/elasticsearch/create.sh new file mode 100644 index 0000000..c34126c --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/elasticsearch/create.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# This script installs java and elasticsearch + +apt-get update +apt-get install -y openjdk-7-jre-headless + +wget -qO - https://packages.elasticsearch.org/GPG-KEY-elasticsearch | apt-key add - +echo "deb http://packages.elasticsearch.org/elasticsearch/1.5/debian stable main" | tee -a /etc/apt/sources.list + +apt-get update +apt-get install -y elasticsearch + +# set up to run as service +update-rc.d elasticsearch defaults 95 10 diff --git a/nfvparser/toscaparser/tests/artifacts/elasticsearch/start.sh b/nfvparser/toscaparser/tests/artifacts/elasticsearch/start.sh new file mode 100644 index 0000000..bbc0347 --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/elasticsearch/start.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# This script starts elasticsearch as a service in init.d +service elasticsearch stop +service elasticsearch start diff --git a/nfvparser/toscaparser/tests/artifacts/kibana/config.sh b/nfvparser/toscaparser/tests/artifacts/kibana/config.sh new file mode 100644 index 0000000..f28215a --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/kibana/config.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# This script configures kibana to connect to the elasticsearch server +# to access data and to export the app url on port 5601: +# The environment variable elasticsearch_ip and kibana_ip are expected +# to be set up. +sed -i 's/localhost/'$elasticsearch_ip'/' /opt/kibana/config/kibana.yml +sed -i 's/0.0.0.0/'$kibana_ip'/' /opt/kibana/config/kibana.yml diff --git a/nfvparser/toscaparser/tests/artifacts/kibana/create.sh b/nfvparser/toscaparser/tests/artifacts/kibana/create.sh new file mode 100644 index 0000000..41914b1 --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/kibana/create.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# This script installs kibana and sets it up to run as a service in init.d +cd /opt +wget https://download.elastic.co/kibana/kibana/kibana-4.1.0-linux-x64.tar.gz +tar xzvf kibana-4.1.0-linux-x64.tar.gz +mv kibana-4.1.0-linux-x64 kibana + +# set up to run as service +cd /etc/init.d +wget https://gist.githubusercontent.com/thisismitch/8b15ac909aed214ad04a/raw/bce61d85643c2dcdfbc2728c55a41dab444dca20/kibana4 +chmod +x kibana4 +update-rc.d kibana4 defaults 96 9 diff --git a/nfvparser/toscaparser/tests/artifacts/kibana/start.sh b/nfvparser/toscaparser/tests/artifacts/kibana/start.sh new file mode 100644 index 0000000..5149bb3 --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/kibana/start.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# This script starts kibana as a service in init.d +service kibana4 stop +service kibana4 start diff --git a/nfvparser/toscaparser/tests/artifacts/logstash/configure_collectd.py b/nfvparser/toscaparser/tests/artifacts/logstash/configure_collectd.py new file mode 100644 index 0000000..18fdacf --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/logstash/configure_collectd.py @@ -0,0 +1,28 @@ +#!/usr/bin/python + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +# This script configures the logstash input using the udp protocol on +# port 25826. This is intended to receive data from collectd from +# any source +with open("/etc/logstash/conf.d/collectd.conf", "w") as fh: + fh.write(""" + input { + udp { + port => 25826 # 25826 is the default for collectd + buffer_size => 1452 # 1452 is the default for collectd + codec => collectd { } + tags => ["metrics"] + type => "collectd" + } + }""") diff --git a/nfvparser/toscaparser/tests/artifacts/logstash/configure_elasticsearch.py b/nfvparser/toscaparser/tests/artifacts/logstash/configure_elasticsearch.py new file mode 100644 index 0000000..2e5389c --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/logstash/configure_elasticsearch.py @@ -0,0 +1,26 @@ +#!/usr/bin/python + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +# This script configures the logstash output to forward to elasticsearch +# The environment variable elasticsearch_ip is expected to be set up +import os +with open("/etc/logstash/conf.d/elasticsearch.conf", 'w') as fh: + fh.write(""" + output { + elasticsearch { + action => index + host => "%s" + protocol => "http" + } + }""" % (os.environ['elasticsearch_ip'])) diff --git a/nfvparser/toscaparser/tests/artifacts/logstash/configure_rsyslog.py b/nfvparser/toscaparser/tests/artifacts/logstash/configure_rsyslog.py new file mode 100644 index 0000000..fc610c2 --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/logstash/configure_rsyslog.py @@ -0,0 +1,25 @@ +#!/usr/bin/python + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +# This script configures the logstash input using the RELP protocol on +# port 2514 This is intended to receive logs from rsyslog from +# any source +with open("/etc/logstash/conf.d/rsyslog.conf", "w") as fh: + fh.write(""" + input { + relp { + port => 2514 + tags => ["logs"] + } + }""") diff --git a/nfvparser/toscaparser/tests/artifacts/logstash/create.sh b/nfvparser/toscaparser/tests/artifacts/logstash/create.sh new file mode 100644 index 0000000..77cc8fd --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/logstash/create.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# This script installs java, logstash and the contrib package for logstash +# install java as prereq + +apt-get update +apt-get install -y openjdk-7-jre-headless +mkdir /etc/logstash + +# install by apt-get from repo +wget -O - http://packages.elasticsearch.org/GPG-KEY-elasticsearch | apt-key add - +echo "deb http://packages.elasticsearch.org/logstash/1.4/debian stable main" | tee -a /etc/apt/sources.list + +apt-get update +apt-get install -y logstash + +# install contrib to get the relp plugin +/opt/logstash/bin/plugin install contrib + +# set up to run as service +update-rc.d logstash defaults 95 10 diff --git a/nfvparser/toscaparser/tests/artifacts/logstash/start.sh b/nfvparser/toscaparser/tests/artifacts/logstash/start.sh new file mode 100644 index 0000000..a73cf61 --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/logstash/start.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# Run logstash as service in init.d +service logstash stop +service logstash start diff --git a/nfvparser/toscaparser/tests/artifacts/mongodb/config.sh b/nfvparser/toscaparser/tests/artifacts/mongodb/config.sh new file mode 100644 index 0000000..78f484e --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/mongodb/config.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# Edit the file /etc/mongod.conf, update with real IP of Mongo server +# This script configures the mongodb server to export its service on +# the server IP +# bind_ip = 127.0.0.1 -> bind_ip = +# The environment variable mongodb_ip is expected to be set up +sed -i "s/= 127.0.0.1/= $mongodb_ip,127.0.0.1/" /etc/mongod.conf diff --git a/nfvparser/toscaparser/tests/artifacts/mongodb/create.sh b/nfvparser/toscaparser/tests/artifacts/mongodb/create.sh new file mode 100644 index 0000000..d84c275 --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/mongodb/create.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# This script installs mongodb + +apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 +echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.0.list + +apt-get update +apt-get install -y mongodb-org + +#Wait for mongodb initialization +while [[ ! -d "/var/lib/mongodb/_tmp" ]]; do + echo "Waiting for mongodb initialization ..." + sleep 5 +done diff --git a/nfvparser/toscaparser/tests/artifacts/mongodb/create_database.sh b/nfvparser/toscaparser/tests/artifacts/mongodb/create_database.sh new file mode 100644 index 0000000..16f1358 --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/mongodb/create_database.sh @@ -0,0 +1,5 @@ +#!/bin/bash +echo "conn = new Mongo();" > setup.js +echo "db = conn.getDB('paypal_pizza');" >> setup.js +echo "db.about.insert({'name': 'PayPal Pizza Store'});" >> setup.js +mongo setup.js diff --git a/nfvparser/toscaparser/tests/artifacts/mongodb/start.sh b/nfvparser/toscaparser/tests/artifacts/mongodb/start.sh new file mode 100644 index 0000000..ac200a5 --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/mongodb/start.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# This script starts mongodb +service mongod stop +rm /var/lib/mongodb/mongod.lock +service mongod start diff --git a/nfvparser/toscaparser/tests/artifacts/mysql/mysql_database_configure.sh b/nfvparser/toscaparser/tests/artifacts/mysql/mysql_database_configure.sh new file mode 100644 index 0000000..092136a --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/mysql/mysql_database_configure.sh @@ -0,0 +1,8 @@ +#!/bin/sh +cat << EOF | mysql -u root --password=$db_root_password +CREATE DATABASE $db_name; +GRANT ALL PRIVILEGES ON $db_name.* TO "$db_user"@"localhost" +IDENTIFIED BY "$db_password"; +FLUSH PRIVILEGES; +EXIT +EOF \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/artifacts/mysql/mysql_dbms_configure.sh b/nfvparser/toscaparser/tests/artifacts/mysql/mysql_dbms_configure.sh new file mode 100644 index 0000000..d4ef6b4 --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/mysql/mysql_dbms_configure.sh @@ -0,0 +1,5 @@ +#!/bin/sh +sed --regexp-extended "s/(port\s*=\s*)[0-9]*/\1$db_port/g" /tmp/my.cnf +mv -f /tmp/my.cnf /etc/mysql/my.cnf +/etc/init.d/mysql stop +/etc/init.d/mysql start \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/artifacts/mysql/mysql_dbms_install.sh b/nfvparser/toscaparser/tests/artifacts/mysql/mysql_dbms_install.sh new file mode 100644 index 0000000..38628b9 --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/mysql/mysql_dbms_install.sh @@ -0,0 +1,9 @@ +#!/bin/bash +#This script installs mysql server + +apt-get update + +debconf-set-selections <<< "mysql-server mysql-server/root_password password $db_root_password" +debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $db_root_password" + +apt-get -y install --fix-missing mysql-server \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/artifacts/mysql/mysql_dbms_start.sh b/nfvparser/toscaparser/tests/artifacts/mysql/mysql_dbms_start.sh new file mode 100644 index 0000000..3378670 --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/mysql/mysql_dbms_start.sh @@ -0,0 +1,2 @@ +#!/bin/sh +/etc/init.d/mysql start \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/artifacts/nodejs/config.sh b/nfvparser/toscaparser/tests/artifacts/nodejs/config.sh new file mode 100644 index 0000000..1e149a2 --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/nodejs/config.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# This script installs an app for nodejs: the app intended is the paypal app +# and it is configured to connect to the mongodb server +# The environment variables github_url and mongodb_ip are expected to be set up +export app_dir=/opt/app +git clone $github_url /opt/app +if [ -f /opt/app/package.json ]; then + cd /opt/app/ && npm install + sed -i "s/localhost/$mongodb_ip/" config.json +fi + +cat > /etc/init/nodeapp.conf <> /var/log/nodeapp.log 2>&1 & +end script +EOS diff --git a/nfvparser/toscaparser/tests/artifacts/nodejs/create.sh b/nfvparser/toscaparser/tests/artifacts/nodejs/create.sh new file mode 100644 index 0000000..04fd6c6 --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/nodejs/create.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# This script installs nodejs and the prereq + +add-apt-repository ppa:chris-lea/node.js + +apt-get update +apt-get install -y nodejs build-essential diff --git a/nfvparser/toscaparser/tests/artifacts/nodejs/start.sh b/nfvparser/toscaparser/tests/artifacts/nodejs/start.sh new file mode 100644 index 0000000..6939cb7 --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/nodejs/start.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# This script starts the nodejs application +start nodeapp diff --git a/nfvparser/toscaparser/tests/artifacts/rsyslog/config.sh b/nfvparser/toscaparser/tests/artifacts/rsyslog/config.sh new file mode 100644 index 0000000..630767d --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/rsyslog/config.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# This script configures the output for rsyslogd to send logs to the +# logstash server port 2514 using the RELP protocol +# The environment variable logstash_ip is expected to be set up +echo "module(load=\"omrelp\") +action(type=\"omrelp\" target=\"$logstash_ip\" port=\"2514\")" > /etc/rsyslog.d/tosca_elk.conf + +# Remove the /dev/xconsole configuration as xconsole +# is not available by default +l=`awk '/=warn.*\|.*\/dev\/xconsole/{print NR - 1}' /etc/rsyslog.d/50-default.conf` +if [ ! -z $l ]; then + l=`expr $l + 1` + line=`cat /etc/rsyslog.d/50-default.conf | head -n $l | tail -1` + if [[ ! $line == \#* ]]; then + l0=`expr $l - 3` + sed -i -r -e "${l0},${l}s/^.{0}/&#/" /etc/rsyslog.d/50-default.conf + fi +fi + +# Enable nodejs logs for rsyslog +if ! grep -q nodeapp "/etc/rsyslog.conf"; then + sed -i 's/\$PrivDropToGroup\ syslog/\$PrivDropToGroup adm/' /etc/rsyslog.conf + echo "\$ModLoad imfile.so +\$InputFileName /var/log/nodeapp.log +\$InputFileTag paypal_pizza: +\$InputFileStateFile stat-nodeapp +\$InputRunFileMonitor +\$InputFilePollInterval 1" >> /etc/rsyslog.conf +fi diff --git a/nfvparser/toscaparser/tests/artifacts/rsyslog/create.sh b/nfvparser/toscaparser/tests/artifacts/rsyslog/create.sh new file mode 100644 index 0000000..affdd6e --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/rsyslog/create.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# This script installs rsyslog and the library for RELP + +apt-get update +apt-get install -y rsyslog rsyslog-relp diff --git a/nfvparser/toscaparser/tests/artifacts/rsyslog/start.sh b/nfvparser/toscaparser/tests/artifacts/rsyslog/start.sh new file mode 100644 index 0000000..3de82d1 --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/rsyslog/start.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# This script starts rsyslogd as a service in init.d +service rsyslog stop +service rsyslog start diff --git a/nfvparser/toscaparser/tests/artifacts/webserver/webserver_install.sh b/nfvparser/toscaparser/tests/artifacts/webserver/webserver_install.sh new file mode 100644 index 0000000..4ca9b4e --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/webserver/webserver_install.sh @@ -0,0 +1,5 @@ +#!/bin/sh +#This script installs apache web server + +apt-get update +apt-get install -y apache2 \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/artifacts/webserver/webserver_start.sh b/nfvparser/toscaparser/tests/artifacts/webserver/webserver_start.sh new file mode 100644 index 0000000..e962ca5 --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/webserver/webserver_start.sh @@ -0,0 +1,2 @@ +#!/bin/sh +service apache2 start \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/artifacts/wordpress/wordpress_configure.sh b/nfvparser/toscaparser/tests/artifacts/wordpress/wordpress_configure.sh new file mode 100644 index 0000000..5598b4f --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/wordpress/wordpress_configure.sh @@ -0,0 +1,4 @@ +#!/bin/sh +ln -s /usr/share/wordpress /var/www/html/wordpress +gzip -d /usr/share/doc/wordpress/examples/setup-mysql.gz +echo $wp_db_password | bash /usr/share/doc/wordpress/examples/setup-mysql -e $wp_db_name -u $wp_db_user localhost \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/artifacts/wordpress/wordpress_install.sh b/nfvparser/toscaparser/tests/artifacts/wordpress/wordpress_install.sh new file mode 100644 index 0000000..1320443 --- /dev/null +++ b/nfvparser/toscaparser/tests/artifacts/wordpress/wordpress_install.sh @@ -0,0 +1,5 @@ +#!/bin/sh +#This script installs wordpress + +apt-get update +apt-get install -y wordpress \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/base.py b/nfvparser/toscaparser/tests/base.py new file mode 100644 index 0000000..2619889 --- /dev/null +++ b/nfvparser/toscaparser/tests/base.py @@ -0,0 +1,65 @@ +# Copyright 2010-2011 OpenStack Foundation +# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import os + +import fixtures +import testscenarios +import testtools + +from toscaparser.tosca_template import ToscaTemplate + +_TRUE_VALUES = ('True', 'true', '1', 'yes') + + +class TestCase(testscenarios.TestWithScenarios, testtools.TestCase): + + """Test case base class for all unit tests.""" + + def setUp(self): + """Run before each test method to initialize test environment.""" + + super(TestCase, self).setUp() + test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) + try: + test_timeout = int(test_timeout) + except ValueError: + # If timeout value is invalid do not set a timeout. + test_timeout = 0 + if test_timeout > 0: + self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) + + self.useFixture(fixtures.NestedTempfile()) + self.useFixture(fixtures.TempHomeDir()) + + if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES: + stdout = self.useFixture(fixtures.StringStream('stdout')).stream + self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) + if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES: + stderr = self.useFixture(fixtures.StringStream('stderr')).stream + self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) + + self.log_fixture = self.useFixture(fixtures.FakeLogger()) + + def _load_template(self, filename): + """Load a Tosca template from tests data folder. + + :param filename: Tosca template file name to load. + :return: ToscaTemplate + """ + return ToscaTemplate(os.path.join( + os.path.dirname(os.path.abspath(__file__)), + 'data', + filename)) diff --git a/nfvparser/toscaparser/tests/data/CSAR/csar_elk.csar b/nfvparser/toscaparser/tests/data/CSAR/csar_elk.csar new file mode 100644 index 0000000..a514dc6 Binary files /dev/null and b/nfvparser/toscaparser/tests/data/CSAR/csar_elk.csar differ diff --git a/nfvparser/toscaparser/tests/data/CSAR/csar_elk.zip b/nfvparser/toscaparser/tests/data/CSAR/csar_elk.zip new file mode 100644 index 0000000..0d860d4 Binary files /dev/null and b/nfvparser/toscaparser/tests/data/CSAR/csar_elk.zip differ diff --git a/nfvparser/toscaparser/tests/data/CSAR/csar_hello_world.zip b/nfvparser/toscaparser/tests/data/CSAR/csar_hello_world.zip new file mode 100644 index 0000000..43ffbbc Binary files /dev/null and b/nfvparser/toscaparser/tests/data/CSAR/csar_hello_world.zip differ diff --git a/nfvparser/toscaparser/tests/data/CSAR/csar_invalid_entry_def.zip b/nfvparser/toscaparser/tests/data/CSAR/csar_invalid_entry_def.zip new file mode 100644 index 0000000..382f790 Binary files /dev/null and b/nfvparser/toscaparser/tests/data/CSAR/csar_invalid_entry_def.zip differ diff --git a/nfvparser/toscaparser/tests/data/CSAR/csar_metadata_not_yaml.zip b/nfvparser/toscaparser/tests/data/CSAR/csar_metadata_not_yaml.zip new file mode 100644 index 0000000..3e6120b Binary files /dev/null and b/nfvparser/toscaparser/tests/data/CSAR/csar_metadata_not_yaml.zip differ diff --git a/nfvparser/toscaparser/tests/data/CSAR/csar_missing_metadata.zip b/nfvparser/toscaparser/tests/data/CSAR/csar_missing_metadata.zip new file mode 100644 index 0000000..5ec7a99 Binary files /dev/null and b/nfvparser/toscaparser/tests/data/CSAR/csar_missing_metadata.zip differ diff --git a/nfvparser/toscaparser/tests/data/CSAR/csar_no_metadata_file.zip b/nfvparser/toscaparser/tests/data/CSAR/csar_no_metadata_file.zip new file mode 100644 index 0000000..b0df9b9 Binary files /dev/null and b/nfvparser/toscaparser/tests/data/CSAR/csar_no_metadata_file.zip differ diff --git a/nfvparser/toscaparser/tests/data/CSAR/csar_not_zip.zip b/nfvparser/toscaparser/tests/data/CSAR/csar_not_zip.zip new file mode 100644 index 0000000..43b7f5f --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/csar_not_zip.zip @@ -0,0 +1 @@ +This is an invalid CSAR file. \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/data/CSAR/csar_wordpress.zip b/nfvparser/toscaparser/tests/data/CSAR/csar_wordpress.zip new file mode 100644 index 0000000..5df7b48 Binary files /dev/null and b/nfvparser/toscaparser/tests/data/CSAR/csar_wordpress.zip differ diff --git a/nfvparser/toscaparser/tests/data/CSAR/csar_wordpress_invalid_import_path.zip b/nfvparser/toscaparser/tests/data/CSAR/csar_wordpress_invalid_import_path.zip new file mode 100644 index 0000000..9dc6c9a Binary files /dev/null and b/nfvparser/toscaparser/tests/data/CSAR/csar_wordpress_invalid_import_path.zip differ diff --git a/nfvparser/toscaparser/tests/data/CSAR/csar_wordpress_invalid_import_url.zip b/nfvparser/toscaparser/tests/data/CSAR/csar_wordpress_invalid_import_url.zip new file mode 100644 index 0000000..c7a260f Binary files /dev/null and b/nfvparser/toscaparser/tests/data/CSAR/csar_wordpress_invalid_import_url.zip differ diff --git a/nfvparser/toscaparser/tests/data/CSAR/csar_wordpress_invalid_script_path.zip b/nfvparser/toscaparser/tests/data/CSAR/csar_wordpress_invalid_script_path.zip new file mode 100644 index 0000000..5e4f9e0 Binary files /dev/null and b/nfvparser/toscaparser/tests/data/CSAR/csar_wordpress_invalid_script_path.zip differ diff --git a/nfvparser/toscaparser/tests/data/CSAR/csar_wordpress_invalid_script_url.zip b/nfvparser/toscaparser/tests/data/CSAR/csar_wordpress_invalid_script_url.zip new file mode 100644 index 0000000..b4133b6 Binary files /dev/null and b/nfvparser/toscaparser/tests/data/CSAR/csar_wordpress_invalid_script_url.zip differ diff --git a/nfvparser/toscaparser/tests/data/CSAR/csar_wordpress_with_url_import_and_script.zip b/nfvparser/toscaparser/tests/data/CSAR/csar_wordpress_with_url_import_and_script.zip new file mode 100644 index 0000000..5dedfcd Binary files /dev/null and b/nfvparser/toscaparser/tests/data/CSAR/csar_wordpress_with_url_import_and_script.zip differ diff --git a/nfvparser/toscaparser/tests/data/CSAR/csar_wrong_metadata_file.zip b/nfvparser/toscaparser/tests/data/CSAR/csar_wrong_metadata_file.zip new file mode 100644 index 0000000..85d660a Binary files /dev/null and b/nfvparser/toscaparser/tests/data/CSAR/csar_wrong_metadata_file.zip differ diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/collectd.yaml b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/collectd.yaml new file mode 100644 index 0000000..1ac0935 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/collectd.yaml @@ -0,0 +1,13 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + collectd is a daemon which gathers statistics about the system it is running on. + +node_types: + tosca.nodes.SoftwareComponent.Collectd: + derived_from: tosca.nodes.SoftwareComponent + requirements: + - log_endpoint: + capability: tosca.capabilities.Endpoint + node: tosca.nodes.SoftwareComponent.Logstash + relationship: tosca.relationships.ConnectsTo \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/elasticsearch.yaml b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/elasticsearch.yaml new file mode 100644 index 0000000..4a1770f --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/elasticsearch.yaml @@ -0,0 +1,11 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Elasticsearch is an open-source search engine built on top of Apache Lucene, a full-text search-engine library. + +node_types: + tosca.nodes.SoftwareComponent.Elasticsearch: + derived_from: tosca.nodes.SoftwareComponent + capabilities: + search_endpoint: + type: tosca.capabilities.Endpoint diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/kibana.yaml b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/kibana.yaml new file mode 100644 index 0000000..3a4351c --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/kibana.yaml @@ -0,0 +1,16 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Kibana is an open source analytics and visualization platform designed to work with Elasticsearch. + You use Kibana to search, view, and interact with data stored in Elasticsearch. + +node_types: + tosca.nodes.SoftwareComponent.Kibana: + derived_from: tosca.nodes.SoftwareComponent + requirements: + - search_endpoint: + capability: tosca.capabilities.Endpoint + node: tosca.nodes.SoftwareComponent.Elasticsearch + relationship: tosca.relationships.ConnectsTo + + diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/logstash.yaml b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/logstash.yaml new file mode 100644 index 0000000..8495954 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/logstash.yaml @@ -0,0 +1,25 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Logstash is a tool for receiving, processing and outputting logs. All kinds of logs. System logs, webserver logs, + error logs, application logs, and just about anything you can throw at it. + +node_types: + tosca.nodes.SoftwareComponent.Logstash: + derived_from: tosca.nodes.SoftwareComponent + requirements: + - search_endpoint: + capability: tosca.capabilities.Endpoint + node: tosca.nodes.SoftwareComponent.Elasticsearch + relationship: + type: tosca.relationships.ConnectsTo + interfaces: + Configure: + pre_configure_source: + inputs: + elasticsearch_ip: + type: string + capabilities: + log_endpoint: + type: tosca.capabilities.Endpoint + diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/paypalpizzastore_nodejs_app.yaml b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/paypalpizzastore_nodejs_app.yaml new file mode 100644 index 0000000..cdabeae --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/paypalpizzastore_nodejs_app.yaml @@ -0,0 +1,29 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Pizza store app that allows you to explore the features provided by PayPal's REST APIs. + More detail can be found at https://github.com/paypal/rest-api-sample-app-nodejs/ + +node_types: + tosca.nodes.WebApplication.PayPalPizzaStore: + derived_from: tosca.nodes.WebApplication + properties: + github_url: + required: false + type: string + description: location of the application on the github. + default: https://github.com/sample.git + requirements: + #WebApplication inherits Computer, so host implied. + - database_connection: + capability: tosca.capabilities.Endpoint.Database + node: tosca.nodes.Database + relationship: tosca.relationships.ConnectsTo + interfaces: + Standard: + configure: + inputs: + github_url: + type: string + mongodb_ip: + type: string diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/rsyslog.yaml b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/rsyslog.yaml new file mode 100644 index 0000000..4614ee7 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/rsyslog.yaml @@ -0,0 +1,13 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + RSYSLOG is the Rocket-fast SYStem for LOG processing. + +node_types: + tosca.nodes.SoftwareComponent.Rsyslog: + derived_from: tosca.nodes.SoftwareComponent + requirements: + - log_endpoint: + capability: tosca.capabilities.Endpoint + node: tosca.nodes.SoftwareComponent.Logstash + relationship: tosca.relationships.ConnectsTo diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/tosca_elk.yaml b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/tosca_elk.yaml new file mode 100644 index 0000000..932f131 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Definitions/tosca_elk.yaml @@ -0,0 +1,217 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + This TOSCA simple profile deploys nodejs, mongodb, elasticsearch, logstash and kibana each on a separate server + with monitoring enabled for nodejs server where a sample nodejs application is running. The rsyslog and collectd are + installed on a nodejs server. + +imports: + - paypalpizzastore_nodejs_app.yaml + - elasticsearch.yaml + - logstash.yaml + - kibana.yaml + - collectd.yaml + - rsyslog.yaml + +dsl_definitions: + host_capabilities: &host_capabilities + # container properties (flavor) + disk_size: 10 GB + num_cpus: { get_input: my_cpus } + mem_size: 4096 MB + os_capabilities: &os_capabilities + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 + +topology_template: + inputs: + my_cpus: + type: integer + description: Number of CPUs for the server. + constraints: + - valid_values: [ 1, 2, 4, 8 ] + github_url: + type: string + description: The URL to download nodejs. + default: http://github.com/paypal/rest-api-sample-app-nodejs.git + + node_templates: + paypal_pizzastore: + type: tosca.nodes.WebApplication.PayPalPizzaStore + properties: + github_url: { get_input: github_url } + requirements: + - host: nodejs + - database_connection: mongo_db + interfaces: + Standard: + configure: + implementation: ../Scripts/nodejs/config.sh + inputs: + github_url: { get_property: [ SELF, github_url ] } + mongodb_ip: { get_attribute: [mongo_server, private_address] } + start: ../Scripts/nodejs/start.sh + nodejs: + type: tosca.nodes.WebServer + requirements: + - host: + node: app_server + interfaces: + Standard: + create: ../Scripts/nodejs/create.sh + mongo_db: + type: tosca.nodes.Database + requirements: + - host: mongo_dbms + interfaces: + Standard: + create: ../Scripts/mongodb/create_database.sh + mongo_dbms: + type: tosca.nodes.DBMS + requirements: + - host: mongo_server + interfaces: + Standard: + create: ../Scripts/mongodb/create.sh + configure: + implementation: ../Scripts/mongodb/config.sh + inputs: + mongodb_ip: { get_attribute: [mongo_server, private_address] } + start: ../Scripts/mongodb/start.sh + elasticsearch: + type: tosca.nodes.SoftwareComponent.Elasticsearch + requirements: + - host: elasticsearch_server + interfaces: + Standard: + create: ../Scripts/elasticsearch/create.sh + start: ../Scripts/elasticsearch/start.sh + logstash: + type: tosca.nodes.SoftwareComponent.Logstash + requirements: + - host: logstash_server + - search_endpoint: + node: elasticsearch + capability: search_endpoint + relationship: + type: tosca.relationships.ConnectsTo + interfaces: + Configure: + pre_configure_source: + implementation: ../Python/logstash/configure_elasticsearch.py + inputs: + elasticsearch_ip: { get_attribute: [elasticsearch_server, private_address] } + interfaces: + Standard: + create: ../Scripts/logstash/create.sh + start: ../Scripts/logstash/start.sh + kibana: + type: tosca.nodes.SoftwareComponent.Kibana + requirements: + - host: kibana_server + - search_endpoint: elasticsearch + interfaces: + Standard: + create: ../Scripts/kibana/create.sh + configure: + implementation: ../Scripts/kibana/config.sh + inputs: + elasticsearch_ip: { get_attribute: [elasticsearch_server, private_address] } + kibana_ip: { get_attribute: [kibana_server, private_address] } + start: ../Scripts/kibana/start.sh + app_collectd: + type: tosca.nodes.SoftwareComponent.Collectd + requirements: + - host: app_server + - log_endpoint: + node: logstash + capability: log_endpoint + relationship: + type: tosca.relationships.ConnectsTo + interfaces: + Configure: + pre_configure_target: + implementation: ../Python/logstash/configure_collectd.py + interfaces: + Standard: + create: ../Scripts/collectd/create.sh + configure: + implementation: ../Python/collectd/config.py + inputs: + logstash_ip: { get_attribute: [logstash_server, private_address] } + start: ../Scripts/collectd/start.sh + app_rsyslog: + type: tosca.nodes.SoftwareComponent.Rsyslog + requirements: + - host: app_server + - log_endpoint: + node: logstash + capability: log_endpoint + relationship: + type: tosca.relationships.ConnectsTo + interfaces: + Configure: + pre_configure_target: + implementation: ../Python/logstash/configure_rsyslog.py + interfaces: + Standard: + create: ../Scripts/rsyslog/create.sh + configure: + implementation: ../Scripts/rsyslog/config.sh + inputs: + logstash_ip: { get_attribute: [logstash_server, private_address] } + start: ../Scripts/rsyslog/start.sh + app_server: + type: tosca.nodes.Compute + capabilities: + host: + properties: *host_capabilities + os: + properties: *os_capabilities + mongo_server: + type: tosca.nodes.Compute + capabilities: + host: + properties: *host_capabilities + os: + properties: *os_capabilities + elasticsearch_server: + type: tosca.nodes.Compute + capabilities: + host: + properties: *host_capabilities + os: + properties: *os_capabilities + logstash_server: + type: tosca.nodes.Compute + capabilities: + host: + properties: *host_capabilities + os: + properties: *os_capabilities + kibana_server: + type: tosca.nodes.Compute + capabilities: + host: + properties: *host_capabilities + os: + properties: *os_capabilities + + outputs: + nodejs_url: + description: URL for the nodejs server, http://:3000 + value: { get_attribute: [ app_server, private_address ] } + mongodb_url: + description: URL for the mongodb server. + value: { get_attribute: [ mongo_server, private_address ] } + elasticsearch_url: + description: URL for the elasticsearch server. + value: { get_attribute: [ elasticsearch_server, private_address ] } + logstash_url: + description: URL for the logstash server. + value: { get_attribute: [ logstash_server, private_address ] } + kibana_url: + description: URL for the kibana server. + value: { get_attribute: [ kibana_server, private_address ] } diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Python/collectd/config.py b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Python/collectd/config.py new file mode 100644 index 0000000..686bbd1 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Python/collectd/config.py @@ -0,0 +1,25 @@ +#!/usr/bin/python + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +# This script configures collectd to send metric data to the +# logstash server port 25826 +# The environment variable logstash_ip is expected to be set up +import os +with open("/etc/collectd/collectd.conf.d/tosca_elk.conf", "w") as fh: + fh.write(""" + LoadPlugin network + + Server "%s" "25826" + + """ % (os.environ['logstash_ip'])) diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_collectd.py b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_collectd.py new file mode 100644 index 0000000..18fdacf --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_collectd.py @@ -0,0 +1,28 @@ +#!/usr/bin/python + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +# This script configures the logstash input using the udp protocol on +# port 25826. This is intended to receive data from collectd from +# any source +with open("/etc/logstash/conf.d/collectd.conf", "w") as fh: + fh.write(""" + input { + udp { + port => 25826 # 25826 is the default for collectd + buffer_size => 1452 # 1452 is the default for collectd + codec => collectd { } + tags => ["metrics"] + type => "collectd" + } + }""") diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_elasticsearch.py b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_elasticsearch.py new file mode 100644 index 0000000..2e5389c --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_elasticsearch.py @@ -0,0 +1,26 @@ +#!/usr/bin/python + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +# This script configures the logstash output to forward to elasticsearch +# The environment variable elasticsearch_ip is expected to be set up +import os +with open("/etc/logstash/conf.d/elasticsearch.conf", 'w') as fh: + fh.write(""" + output { + elasticsearch { + action => index + host => "%s" + protocol => "http" + } + }""" % (os.environ['elasticsearch_ip'])) diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_rsyslog.py b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_rsyslog.py new file mode 100644 index 0000000..fc610c2 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Python/logstash/configure_rsyslog.py @@ -0,0 +1,25 @@ +#!/usr/bin/python + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +# This script configures the logstash input using the RELP protocol on +# port 2514 This is intended to receive logs from rsyslog from +# any source +with open("/etc/logstash/conf.d/rsyslog.conf", "w") as fh: + fh.write(""" + input { + relp { + port => 2514 + tags => ["logs"] + } + }""") diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/README.txt b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/README.txt new file mode 100644 index 0000000..382c9b0 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/README.txt @@ -0,0 +1,5 @@ +README: + +This TOSCA simple profile deploys nodejs, mongodb, elasticsearch, logstash and kibana each on a separate server with monitoring enabled for nodejs server where a sample nodejs application is running. The syslog and collectd are installed on a nodejs server. + +Entry information for processing through an orchestrator is contained in file TOSCA-Metadata/TOSCA.meta. This file provides high-level information such as CSAR version or creator of the CSAR. Furthermore, it provides pointers to the entry template under 'Entry-Definitions' key. The entry template itself may contain pointers to one or more files that are used to define TOSCA base type, unless provided by orchestrator as built-in TOSCA basetypes, and other non-normative types. These are typically provided under 'imports' section in the entry template file. Those type definitions will be read and processed by orchestrator or TOSCA parser to create an internal graph showing dependencies and relationships between various TOSCA types. The entry template may have references to various artifacts required for deployment and will be processed accordingly. diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/collectd/create.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/collectd/create.sh new file mode 100644 index 0000000..a483b88 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/collectd/create.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# This script install collectd for monitoring data + +apt-get update +apt-get install -y collectd diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/collectd/start.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/collectd/start.sh new file mode 100644 index 0000000..7e8e033 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/collectd/start.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# This script starts collectd as a service in init.d +service collectd stop +service collectd start diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/elasticsearch/create.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/elasticsearch/create.sh new file mode 100644 index 0000000..c34126c --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/elasticsearch/create.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# This script installs java and elasticsearch + +apt-get update +apt-get install -y openjdk-7-jre-headless + +wget -qO - https://packages.elasticsearch.org/GPG-KEY-elasticsearch | apt-key add - +echo "deb http://packages.elasticsearch.org/elasticsearch/1.5/debian stable main" | tee -a /etc/apt/sources.list + +apt-get update +apt-get install -y elasticsearch + +# set up to run as service +update-rc.d elasticsearch defaults 95 10 diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/elasticsearch/start.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/elasticsearch/start.sh new file mode 100644 index 0000000..bbc0347 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/elasticsearch/start.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# This script starts elasticsearch as a service in init.d +service elasticsearch stop +service elasticsearch start diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/config.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/config.sh new file mode 100644 index 0000000..f28215a --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/config.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# This script configures kibana to connect to the elasticsearch server +# to access data and to export the app url on port 5601: +# The environment variable elasticsearch_ip and kibana_ip are expected +# to be set up. +sed -i 's/localhost/'$elasticsearch_ip'/' /opt/kibana/config/kibana.yml +sed -i 's/0.0.0.0/'$kibana_ip'/' /opt/kibana/config/kibana.yml diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/create.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/create.sh new file mode 100644 index 0000000..41914b1 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/create.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# This script installs kibana and sets it up to run as a service in init.d +cd /opt +wget https://download.elastic.co/kibana/kibana/kibana-4.1.0-linux-x64.tar.gz +tar xzvf kibana-4.1.0-linux-x64.tar.gz +mv kibana-4.1.0-linux-x64 kibana + +# set up to run as service +cd /etc/init.d +wget https://gist.githubusercontent.com/thisismitch/8b15ac909aed214ad04a/raw/bce61d85643c2dcdfbc2728c55a41dab444dca20/kibana4 +chmod +x kibana4 +update-rc.d kibana4 defaults 96 9 diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/start.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/start.sh new file mode 100644 index 0000000..5149bb3 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/kibana/start.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# This script starts kibana as a service in init.d +service kibana4 stop +service kibana4 start diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/logstash/create.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/logstash/create.sh new file mode 100644 index 0000000..77cc8fd --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/logstash/create.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# This script installs java, logstash and the contrib package for logstash +# install java as prereq + +apt-get update +apt-get install -y openjdk-7-jre-headless +mkdir /etc/logstash + +# install by apt-get from repo +wget -O - http://packages.elasticsearch.org/GPG-KEY-elasticsearch | apt-key add - +echo "deb http://packages.elasticsearch.org/logstash/1.4/debian stable main" | tee -a /etc/apt/sources.list + +apt-get update +apt-get install -y logstash + +# install contrib to get the relp plugin +/opt/logstash/bin/plugin install contrib + +# set up to run as service +update-rc.d logstash defaults 95 10 diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/logstash/start.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/logstash/start.sh new file mode 100644 index 0000000..a73cf61 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/logstash/start.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# Run logstash as service in init.d +service logstash stop +service logstash start diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/config.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/config.sh new file mode 100644 index 0000000..78f484e --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/config.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# Edit the file /etc/mongod.conf, update with real IP of Mongo server +# This script configures the mongodb server to export its service on +# the server IP +# bind_ip = 127.0.0.1 -> bind_ip = +# The environment variable mongodb_ip is expected to be set up +sed -i "s/= 127.0.0.1/= $mongodb_ip,127.0.0.1/" /etc/mongod.conf diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/create.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/create.sh new file mode 100644 index 0000000..d84c275 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/create.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# This script installs mongodb + +apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 +echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.0.list + +apt-get update +apt-get install -y mongodb-org + +#Wait for mongodb initialization +while [[ ! -d "/var/lib/mongodb/_tmp" ]]; do + echo "Waiting for mongodb initialization ..." + sleep 5 +done diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/create_database.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/create_database.sh new file mode 100644 index 0000000..16f1358 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/create_database.sh @@ -0,0 +1,5 @@ +#!/bin/bash +echo "conn = new Mongo();" > setup.js +echo "db = conn.getDB('paypal_pizza');" >> setup.js +echo "db.about.insert({'name': 'PayPal Pizza Store'});" >> setup.js +mongo setup.js diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/start.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/start.sh new file mode 100644 index 0000000..ac200a5 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/mongodb/start.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# This script starts mongodb +service mongod stop +rm /var/lib/mongodb/mongod.lock +service mongod start diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/config.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/config.sh new file mode 100644 index 0000000..1e149a2 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/config.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# This script installs an app for nodejs: the app intended is the paypal app +# and it is configured to connect to the mongodb server +# The environment variables github_url and mongodb_ip are expected to be set up +export app_dir=/opt/app +git clone $github_url /opt/app +if [ -f /opt/app/package.json ]; then + cd /opt/app/ && npm install + sed -i "s/localhost/$mongodb_ip/" config.json +fi + +cat > /etc/init/nodeapp.conf <> /var/log/nodeapp.log 2>&1 & +end script +EOS diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/create.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/create.sh new file mode 100644 index 0000000..04fd6c6 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/create.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# This script installs nodejs and the prereq + +add-apt-repository ppa:chris-lea/node.js + +apt-get update +apt-get install -y nodejs build-essential diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/start.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/start.sh new file mode 100644 index 0000000..6939cb7 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/nodejs/start.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# This script starts the nodejs application +start nodeapp diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/config.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/config.sh new file mode 100644 index 0000000..630767d --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/config.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# This script configures the output for rsyslogd to send logs to the +# logstash server port 2514 using the RELP protocol +# The environment variable logstash_ip is expected to be set up +echo "module(load=\"omrelp\") +action(type=\"omrelp\" target=\"$logstash_ip\" port=\"2514\")" > /etc/rsyslog.d/tosca_elk.conf + +# Remove the /dev/xconsole configuration as xconsole +# is not available by default +l=`awk '/=warn.*\|.*\/dev\/xconsole/{print NR - 1}' /etc/rsyslog.d/50-default.conf` +if [ ! -z $l ]; then + l=`expr $l + 1` + line=`cat /etc/rsyslog.d/50-default.conf | head -n $l | tail -1` + if [[ ! $line == \#* ]]; then + l0=`expr $l - 3` + sed -i -r -e "${l0},${l}s/^.{0}/&#/" /etc/rsyslog.d/50-default.conf + fi +fi + +# Enable nodejs logs for rsyslog +if ! grep -q nodeapp "/etc/rsyslog.conf"; then + sed -i 's/\$PrivDropToGroup\ syslog/\$PrivDropToGroup adm/' /etc/rsyslog.conf + echo "\$ModLoad imfile.so +\$InputFileName /var/log/nodeapp.log +\$InputFileTag paypal_pizza: +\$InputFileStateFile stat-nodeapp +\$InputRunFileMonitor +\$InputFilePollInterval 1" >> /etc/rsyslog.conf +fi diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/create.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/create.sh new file mode 100644 index 0000000..affdd6e --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/create.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# This script installs rsyslog and the library for RELP + +apt-get update +apt-get install -y rsyslog rsyslog-relp diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/start.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/start.sh new file mode 100644 index 0000000..3de82d1 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/Scripts/rsyslog/start.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# This script starts rsyslogd as a service in init.d +service rsyslog stop +service rsyslog start diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/TOSCA-Metadata/TOSCA.meta b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/TOSCA-Metadata/TOSCA.meta new file mode 100644 index 0000000..feb3d4f --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_elk/TOSCA-Metadata/TOSCA.meta @@ -0,0 +1,4 @@ +TOSCA-Meta-File-Version: 1.0 +CSAR-Version: 1.1 +Created-By: OASIS TOSCA TC +Entry-Definitions: Definitions/tosca_elk.yaml \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Definitions/tosca_single_instance_wordpress.yaml b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Definitions/tosca_single_instance_wordpress.yaml new file mode 100644 index 0000000..1dd195a --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Definitions/tosca_single_instance_wordpress.yaml @@ -0,0 +1,109 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with wordpress, web server and mysql on the same server. + +imports: + - wordpress.yaml + +topology_template: + inputs: + cpus: + type: integer + description: Number of CPUs for the server. + constraints: + - valid_values: [ 1, 2, 4, 8 ] + db_name: + type: string + description: The name of the database. + db_user: + type: string + description: The user name of the DB user. + db_pwd: + type: string + description: The WordPress database admin account password. + db_root_pwd: + type: string + description: Root password for MySQL. + db_port: + type: PortDef + description: Port for the MySQL database. + + node_templates: + wordpress: + type: tosca.nodes.WebApplication.WordPress + requirements: + - host: webserver + - database_endpoint: mysql_database + interfaces: + Standard: + create: ../Scripts/WordPress/install.sh + configure: + implementation: ../Scripts/WordPress/configure.sh + inputs: + wp_db_name: { get_property: [ mysql_database, name ] } + wp_db_user: { get_property: [ mysql_database, user ] } + wp_db_password: { get_property: [ mysql_database, password ] } + + mysql_database: + type: tosca.nodes.Database + properties: + name: { get_input: db_name } + user: { get_input: db_user } + password: { get_input: db_pwd } + requirements: + - host: mysql_dbms + interfaces: + Standard: + configure: + implementation: ../Scripts/MYSQLDatabase/configure.sh + inputs: + db_name: { get_property: [ SELF, name ] } + db_user: { get_property: [ SELF, user ] } + db_password: { get_property: [ SELF, password ] } + db_root_password: { get_property: [ mysql_dbms, root_password ] } + + mysql_dbms: + type: tosca.nodes.DBMS + properties: + root_password: { get_input: db_root_pwd } + port: { get_input: db_port } + requirements: + - host: server + interfaces: + Standard: + create: ../Scripts/MYSQLDBMS/install.sh + start: ../Scripts/MYSQLDBMS/start.sh + configure: + implementation: ../Scripts/MYSQLDBMS/configure.sh + inputs: + root_password: { get_property: [ mysql_dbms, root_password ] } + + webserver: + type: tosca.nodes.WebServer + requirements: + - host: server + interfaces: + Standard: + create: ../Scripts/WebServer/install.sh + start: ../Scripts/WebServer/start.sh + + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Fedora + version: 18.0 + + outputs: + website_url: + description: IP address for Wordpress wiki. + value: { get_attribute: [server, private_address] } diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Definitions/wordpress.yaml b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Definitions/wordpress.yaml new file mode 100644 index 0000000..5899ed9 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Definitions/wordpress.yaml @@ -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/CSAR/tosca_single_instance_wordpress/README.txt b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/README.txt new file mode 100644 index 0000000..e882ff6 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/README.txt @@ -0,0 +1,22 @@ +README: + +This CSAR contains all definitions that are required for deploying WordPress +and MySQL on a single compute instance. + +Entry information for processing through an orchestrator is contained in file +TOSCA-Metadata/TOSCA.meta. This file provides high-level information such as +CSAR version or creator of the CSAR. Furthermore, it provides pointers to the +various TOSCA definitions files that contain the real details. +The entry 'Entry-Definitions' points to the definitions file which holds the +service template for the workload. +'Entry-Definitions' is optional. An orchestrator can also process the contents +like this: +1) Read in and process each definitions file. +2) For each definitions file: + 2.1) Read in all * type definitions (node types, capability types, etc.) and + store them in an internal map +3) Verify and build dependencies (e.g. inheritance) between all type definitions + previously read in. Orchestrator built-in types (e.g. TOSCA base types) are + also considered in this step. +4) Process the actual service template (the file with a node_templates section). + Validate using previously obtained type information. diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/configure.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/configure.sh new file mode 100644 index 0000000..d4ef6b4 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/configure.sh @@ -0,0 +1,5 @@ +#!/bin/sh +sed --regexp-extended "s/(port\s*=\s*)[0-9]*/\1$db_port/g" /tmp/my.cnf +mv -f /tmp/my.cnf /etc/mysql/my.cnf +/etc/init.d/mysql stop +/etc/init.d/mysql start \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/install.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/install.sh new file mode 100644 index 0000000..38628b9 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/install.sh @@ -0,0 +1,9 @@ +#!/bin/bash +#This script installs mysql server + +apt-get update + +debconf-set-selections <<< "mysql-server mysql-server/root_password password $db_root_password" +debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $db_root_password" + +apt-get -y install --fix-missing mysql-server \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/start.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/start.sh new file mode 100644 index 0000000..3378670 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDBMS/start.sh @@ -0,0 +1,2 @@ +#!/bin/sh +/etc/init.d/mysql start \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDatabase/configure.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDatabase/configure.sh new file mode 100644 index 0000000..092136a --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/MYSQLDatabase/configure.sh @@ -0,0 +1,8 @@ +#!/bin/sh +cat << EOF | mysql -u root --password=$db_root_password +CREATE DATABASE $db_name; +GRANT ALL PRIVILEGES ON $db_name.* TO "$db_user"@"localhost" +IDENTIFIED BY "$db_password"; +FLUSH PRIVILEGES; +EXIT +EOF \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WebServer/install.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WebServer/install.sh new file mode 100644 index 0000000..4ca9b4e --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WebServer/install.sh @@ -0,0 +1,5 @@ +#!/bin/sh +#This script installs apache web server + +apt-get update +apt-get install -y apache2 \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WebServer/start.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WebServer/start.sh new file mode 100644 index 0000000..e962ca5 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WebServer/start.sh @@ -0,0 +1,2 @@ +#!/bin/sh +service apache2 start \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WordPress/configure.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WordPress/configure.sh new file mode 100644 index 0000000..5598b4f --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WordPress/configure.sh @@ -0,0 +1,4 @@ +#!/bin/sh +ln -s /usr/share/wordpress /var/www/html/wordpress +gzip -d /usr/share/doc/wordpress/examples/setup-mysql.gz +echo $wp_db_password | bash /usr/share/doc/wordpress/examples/setup-mysql -e $wp_db_name -u $wp_db_user localhost \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WordPress/install.sh b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WordPress/install.sh new file mode 100644 index 0000000..1320443 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/Scripts/WordPress/install.sh @@ -0,0 +1,5 @@ +#!/bin/sh +#This script installs wordpress + +apt-get update +apt-get install -y wordpress \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/TOSCA-Metadata/TOSCA.meta b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/TOSCA-Metadata/TOSCA.meta new file mode 100644 index 0000000..5208113 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/CSAR/tosca_single_instance_wordpress/TOSCA-Metadata/TOSCA.meta @@ -0,0 +1,5 @@ +TOSCA-Meta-File-Version: 1.0 +CSAR-Version: 1.1 +Created-By: OASIS TOSCA TC +Entry-Definitions: Definitions/tosca_single_instance_wordpress.yaml +Content-Type: application/vnd.oasis.tosca.definitions.yaml diff --git a/nfvparser/toscaparser/tests/data/containers/test_container_docker_mysql.yaml b/nfvparser/toscaparser/tests/data/containers/test_container_docker_mysql.yaml new file mode 100644 index 0000000..3fd4466 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/containers/test_container_docker_mysql.yaml @@ -0,0 +1,44 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with mysql docker container. + +# Repositories to retrieve code artifacts from +repositories: + docker_hub: https://registry.hub.docker.com/ + +topology_template: + + inputs: + mysql_root_pwd: + type: string + description: Root password for MySQL. + + node_templates: + # The MYSQL container based on official MySQL image in Docker hub + mysql_container: + type: tosca.nodes.Container.Application.Docker + requirements: + - host: mysql_runtime + artifacts: + my_image: + file: mysql + type: tosca.artifacts.Deployment.Image.Container.Docker + repository: docker_hub + interfaces: + Standard: + create: + implementation: my_image + inputs: + MYSQL_ROOT_PASSWORD: { get_input: mysql_root_pwd } + + # The properties of the runtime to host the container + mysql_runtime: + type: tosca.nodes.Container.Runtime + capabilities: + host: + properties: + num_cpus: 1 + disk_size: 10 GB + mem_size: 2 MB + diff --git a/nfvparser/toscaparser/tests/data/custom_types/collectd.yaml b/nfvparser/toscaparser/tests/data/custom_types/collectd.yaml new file mode 100644 index 0000000..1ac0935 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/custom_types/collectd.yaml @@ -0,0 +1,13 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + collectd is a daemon which gathers statistics about the system it is running on. + +node_types: + tosca.nodes.SoftwareComponent.Collectd: + derived_from: tosca.nodes.SoftwareComponent + requirements: + - log_endpoint: + capability: tosca.capabilities.Endpoint + node: tosca.nodes.SoftwareComponent.Logstash + relationship: tosca.relationships.ConnectsTo \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/data/custom_types/compute_with_attribute_list.yaml b/nfvparser/toscaparser/tests/data/custom_types/compute_with_attribute_list.yaml new file mode 100644 index 0000000..3487433 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/custom_types/compute_with_attribute_list.yaml @@ -0,0 +1,13 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: Compute node type with a list attribute + +node_types: + tosca.nodes.ComputeWithAttrList: + derived_from: tosca.nodes.Compute + attributes: + attr_list: + type: map + entry_schema: + type: string + diff --git a/nfvparser/toscaparser/tests/data/custom_types/compute_with_nested_atributes.yaml b/nfvparser/toscaparser/tests/data/custom_types/compute_with_nested_atributes.yaml new file mode 100644 index 0000000..909a297 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/custom_types/compute_with_nested_atributes.yaml @@ -0,0 +1,22 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: Compute node type with capability with an attribute of type list + +capability_types: + + tosca.capabilities.indigo.Endpoint: + derived_from: tosca.capabilities.Endpoint + attributes: + credential: + type: list + entry_schema: + type: tosca.datatypes.Credential + +node_types: + + tosca.nodes.ComputeWithCapWithAttr: + derived_from: tosca.nodes.Compute + capabilities: + endpoint: + type: tosca.capabilities.indigo.Endpoint + diff --git a/nfvparser/toscaparser/tests/data/custom_types/compute_with_prop.yaml b/nfvparser/toscaparser/tests/data/custom_types/compute_with_prop.yaml new file mode 100644 index 0000000..93a82af --- /dev/null +++ b/nfvparser/toscaparser/tests/data/custom_types/compute_with_prop.yaml @@ -0,0 +1,13 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Compute node type with a parameter for the get property with host test + +node_types: + tosca.nodes.ComputeWithProp: + derived_from: tosca.nodes.Compute + properties: + test: + required: false + type: integer + diff --git a/nfvparser/toscaparser/tests/data/custom_types/custom_caps_def.yaml b/nfvparser/toscaparser/tests/data/custom_types/custom_caps_def.yaml new file mode 100644 index 0000000..337c38f --- /dev/null +++ b/nfvparser/toscaparser/tests/data/custom_types/custom_caps_def.yaml @@ -0,0 +1,22 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Definition of a node with a capiblity and a parent capability + defined in an imported file + +capability_types: + + tosca.capabilities.SomeCap: + derived_from: tosca.capabilities.Root + + tosca.capabilities.SomeChildCap: + derived_from: tosca.capabilities.SomeCap + +node_types: + + tosca.nodes.SomeNode: + derived_from: tosca.nodes.Root + capabilities: + lrms: + type: tosca.capabilities.SomeChildCap + diff --git a/nfvparser/toscaparser/tests/data/custom_types/custom_interface.yaml b/nfvparser/toscaparser/tests/data/custom_types/custom_interface.yaml new file mode 100644 index 0000000..2d9bec4 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/custom_types/custom_interface.yaml @@ -0,0 +1,20 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + This template contains custom defined interface type + and a node type which uses this custom interface + +interface_types: + tosca.interfaces.CustomInterface: + derived_from: tosca.interfaces.Root + CustomOp: + CustomOp2: + +node_types: + tosca.nodes.CustomInterfaceTest: + derived_from: tosca.nodes.WebApplication + interfaces: + CustomInterface: + type: tosca.interfaces.CustomInterface + CustomOp3: + diff --git a/nfvparser/toscaparser/tests/data/custom_types/custom_relationship_type_defs.yaml b/nfvparser/toscaparser/tests/data/custom_types/custom_relationship_type_defs.yaml new file mode 100644 index 0000000..cf5c2b4 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/custom_types/custom_relationship_type_defs.yaml @@ -0,0 +1,23 @@ +node_types: + tosca.nodes.HACompute: + derived_from: tosca.nodes.Compute + capabilities: + high_availability: + type: tosca.capabilities.HA + requirements: + - high_availability: + capability: tosca.capabilities.HA + relationship: tosca.relationships.HA + node: tosca.nodes.HACompute + occurences: [ 0, 1 ] + +relationship_types: + tosca.relationships.HA: + derived_from: tosca.relationships.Root + valid_target_types: [ tosca.capabilities.HA ] + +capability_types: + tosca.capabilities.HA: + derived_from: tosca.capabilities.Root + valid_source_types: [ tosca.nodes.HACompute ] + diff --git a/nfvparser/toscaparser/tests/data/custom_types/db_with_list_param.yaml b/nfvparser/toscaparser/tests/data/custom_types/db_with_list_param.yaml new file mode 100644 index 0000000..57ce279 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/custom_types/db_with_list_param.yaml @@ -0,0 +1,10 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +node_types: + tosca.nodes.DatabaseWithListParam: + derived_from: tosca.nodes.Database + properties: + list_prop: + type: list + entry_schema: + type: integer diff --git a/nfvparser/toscaparser/tests/data/custom_types/elasticsearch.yaml b/nfvparser/toscaparser/tests/data/custom_types/elasticsearch.yaml new file mode 100644 index 0000000..b140a32 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/custom_types/elasticsearch.yaml @@ -0,0 +1,12 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Elasticsearch is an open-source search engine built on top of Apache Lucene, + a full-text search-engine library. + +node_types: + tosca.nodes.SoftwareComponent.Elasticsearch: + derived_from: tosca.nodes.SoftwareComponent + capabilities: + search_endpoint: + type: tosca.capabilities.Endpoint diff --git a/nfvparser/toscaparser/tests/data/custom_types/imported_sample.yaml b/nfvparser/toscaparser/tests/data/custom_types/imported_sample.yaml new file mode 100644 index 0000000..c8e4532 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/custom_types/imported_sample.yaml @@ -0,0 +1,38 @@ +tosca1_definitions_version: tosca_simple_yaml_1_0 +tosca_definitions_version: tosca_simple_yaml_1_10 + +descriptions: > + Pizza store app that allows you to explore the features provided by PayPal's REST APIs. + More detail can be found at https://github.com/paypal/rest-api-sample-app-nodejs/ + +node_typess: +node_types: + tosca.nodes.SoftwareComponent.Logstash: + derived_from: tosca.nodes.SoftwareComponent + requirements: + - search_endpoint: + capability: tosca.capabilities.Endpoint + node: tosca.nodes.SoftwareComponent.Elasticsearch + relationship: + type: tosca.relationships.ConnectsTo + interfaces: + Configure: + pre_configure_source: + inputs: + elasticsearch_ip: + type: string + capabilities1: + log_endpoint: + type: tosca.capabilities.Endpoint +policy_types1: +policy_types: + mycompany.mytypes.myScalingPolicy: + derived1_from: tosca.policies.Scaling + metadata: + type: map + entry_schema: + type: string +relationship_types1: +relationship_types: + test.relation.connects: + derived_from4: tosca.relationships.ConnectsTo diff --git a/nfvparser/toscaparser/tests/data/custom_types/kibana.yaml b/nfvparser/toscaparser/tests/data/custom_types/kibana.yaml new file mode 100644 index 0000000..5701e69 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/custom_types/kibana.yaml @@ -0,0 +1,14 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Kibana is an open source analytics and visualization platform designed to work with Elasticsearch. + You use Kibana to search, view, and interact with data stored in Elasticsearch. + +node_types: + tosca.nodes.SoftwareComponent.Kibana: + derived_from: tosca.nodes.SoftwareComponent + requirements: + - search_endpoint: + capability: tosca.capabilities.Endpoint + node: tosca.nodes.SoftwareComponent.Elasticsearch + relationship: tosca.relationships.ConnectsTo diff --git a/nfvparser/toscaparser/tests/data/custom_types/logstash.yaml b/nfvparser/toscaparser/tests/data/custom_types/logstash.yaml new file mode 100644 index 0000000..cf60521 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/custom_types/logstash.yaml @@ -0,0 +1,25 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Logstash is a tool for receiving, processing and outputting logs. All kinds + of logs. System logs, webserver logs, error logs, application logs, and just + about anything you can throw at it. + +node_types: + tosca.nodes.SoftwareComponent.Logstash: + derived_from: tosca.nodes.SoftwareComponent + requirements: + - search_endpoint: + capability: tosca.capabilities.Endpoint + node: tosca.nodes.SoftwareComponent.Elasticsearch + relationship: + type: tosca.relationships.ConnectsTo + interfaces: + Configure: + pre_configure_source: + inputs: + elasticsearch_ip: + type: string + capabilities: + log_endpoint: + type: tosca.capabilities.Endpoint diff --git a/nfvparser/toscaparser/tests/data/custom_types/nested_rsyslog.yaml b/nfvparser/toscaparser/tests/data/custom_types/nested_rsyslog.yaml new file mode 100644 index 0000000..8c04171 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/custom_types/nested_rsyslog.yaml @@ -0,0 +1,17 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + RSYSLOG is the Rocket-fast SYStem for LOG processing. + +imports: + - test_import: + file: custom_types/logstash.yaml + +node_types: + Rsyslog: + derived_from: tosca.nodes.SoftwareComponent + requirements: + - log_endpoint: + capability: tosca.capabilities.Endpoint + node: tosca.nodes.SoftwareComponent.Logstash + relationship: tosca.relationships.ConnectsTo diff --git a/nfvparser/toscaparser/tests/data/custom_types/nested_test_wordpress.yaml b/nfvparser/toscaparser/tests/data/custom_types/nested_test_wordpress.yaml new file mode 100644 index 0000000..4df277d --- /dev/null +++ b/nfvparser/toscaparser/tests/data/custom_types/nested_test_wordpress.yaml @@ -0,0 +1,32 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 +imports: + - test_prefix_defs: + file: custom_types/nested_rsyslog.yaml + namespace_prefix: test_namespace_prefix + - test_second_time_with_another_prefix: + file: custom_types/nested_rsyslog.yaml + namespace_prefix: test_2nd_namespace_prefix + +node_types: + tosca.nodes.SoftwareComponent.Rsyslog.TestRsyslogType: + derived_from: test_namespace_prefix.Rsyslog + + Test2ndRsyslogType: + derived_from: test_2nd_namespace_prefix.Rsyslog + + 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/custom_types/node_with_cap.yaml b/nfvparser/toscaparser/tests/data/custom_types/node_with_cap.yaml new file mode 100644 index 0000000..b17513f --- /dev/null +++ b/nfvparser/toscaparser/tests/data/custom_types/node_with_cap.yaml @@ -0,0 +1,33 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Node type that has a requirement of a capability with a defined value + +capability_types: + + tosca.capabilities.SomeCap: + derived_from: tosca.capabilities.Root + properties: + type: + type: string + required: true + default: someval + constraints: + - equal: someval + +node_types: + + tosca.nodes.SomeNode: + derived_from: tosca.nodes.Root + requirements: + - some_req: + capability: tosca.capabilities.SomeCap + node: tosca.nodes.NodeWithCap + relationship: tosca.relationships.HostedOn + + tosca.nodes.NodeWithCap: + derived_from: tosca.nodes.Root + capabilities: + some_req: + type: tosca.capabilities.SomeCap + diff --git a/nfvparser/toscaparser/tests/data/custom_types/paypalpizzastore_nodejs_app.yaml b/nfvparser/toscaparser/tests/data/custom_types/paypalpizzastore_nodejs_app.yaml new file mode 100644 index 0000000..cdabeae --- /dev/null +++ b/nfvparser/toscaparser/tests/data/custom_types/paypalpizzastore_nodejs_app.yaml @@ -0,0 +1,29 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Pizza store app that allows you to explore the features provided by PayPal's REST APIs. + More detail can be found at https://github.com/paypal/rest-api-sample-app-nodejs/ + +node_types: + tosca.nodes.WebApplication.PayPalPizzaStore: + derived_from: tosca.nodes.WebApplication + properties: + github_url: + required: false + type: string + description: location of the application on the github. + default: https://github.com/sample.git + requirements: + #WebApplication inherits Computer, so host implied. + - database_connection: + capability: tosca.capabilities.Endpoint.Database + node: tosca.nodes.Database + relationship: tosca.relationships.ConnectsTo + interfaces: + Standard: + configure: + inputs: + github_url: + type: string + mongodb_ip: + type: string diff --git a/nfvparser/toscaparser/tests/data/custom_types/rsyslog.yaml b/nfvparser/toscaparser/tests/data/custom_types/rsyslog.yaml new file mode 100644 index 0000000..4614ee7 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/custom_types/rsyslog.yaml @@ -0,0 +1,13 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + RSYSLOG is the Rocket-fast SYStem for LOG processing. + +node_types: + tosca.nodes.SoftwareComponent.Rsyslog: + derived_from: tosca.nodes.SoftwareComponent + requirements: + - log_endpoint: + capability: tosca.capabilities.Endpoint + node: tosca.nodes.SoftwareComponent.Logstash + relationship: tosca.relationships.ConnectsTo diff --git a/nfvparser/toscaparser/tests/data/custom_types/wordpress.yaml b/nfvparser/toscaparser/tests/data/custom_types/wordpress.yaml new file mode 100644 index 0000000..5899ed9 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/custom_types/wordpress.yaml @@ -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/datatypes/custom_datatype_def.yaml b/nfvparser/toscaparser/tests/data/datatypes/custom_datatype_def.yaml new file mode 100644 index 0000000..b1fb402 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/datatypes/custom_datatype_def.yaml @@ -0,0 +1,53 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Custom type and node definition used to test custom datatypes. + +node_types: + tosca.nodes.my.SomeNode: + derived_from: tosca.nodes.Root + properties: + people: + type: tosca.my.datatypes.People + +data_types: + tosca.my.datatypes.PeopleBase: + properties: + name: + type: string + required: true + constraints: + - min_length: 2 + gender: + type: string + required: false + default: unknown + + tosca.my.datatypes.People: + derived_from: tosca.my.datatypes.PeopleBase + properties: + addresses: + type: map + required: false + entry_schema: + type: string + contacts: + type: list + required: false + entry_schema: + type: tosca.my.datatypes.ContactInfo + + tosca.my.datatypes.ContactInfo: + description: simple contact information + properties: + contact_name: + type: string + required: true + constraints: + - min_length: 2 + contact_email: + type: string + required: false + contact_phone: + type: string + required: false diff --git a/nfvparser/toscaparser/tests/data/datatypes/test_custom_datatypes_in_current_template.yaml b/nfvparser/toscaparser/tests/data/datatypes/test_custom_datatypes_in_current_template.yaml new file mode 100644 index 0000000..befa198 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/datatypes/test_custom_datatypes_in_current_template.yaml @@ -0,0 +1,70 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA templates used to test custom datatypes. + +node_types: + tosca.nodes.my.SomeNode: + derived_from: tosca.nodes.Root + properties: + people: + type: tosca.my.datatypes.People + +data_types: + tosca.my.datatypes.PeopleBase: + properties: + name: + type: string + required: true + constraints: + - min_length: 2 + gender: + type: string + required: false + default: unknown + + tosca.my.datatypes.People: + derived_from: tosca.my.datatypes.PeopleBase + properties: + addresses: + type: map + required: false + entry_schema: + type: string + contacts: + type: list + required: false + entry_schema: + type: tosca.my.datatypes.ContactInfo + + tosca.my.datatypes.ContactInfo: + description: simple contact information + properties: + contact_name: + type: string + required: true + constraints: + - min_length: 2 + contact_email: + type: string + required: false + contact_phone: + type: string + required: false + +topology_template: + node_templates: + positive: + type: tosca.nodes.my.SomeNode + properties: + people: + name: Mike + gender: male + addresses: {Home: 1 foo street, Office: 9 bar avenue} + contacts: + - {contact_name: Tom, + contact_email: tom@email.com, + contact_phone: '123456789'} + - {contact_name: Jerry, + contact_email: jerry@email.com, + contact_phone: '321654987'} diff --git a/nfvparser/toscaparser/tests/data/datatypes/test_custom_datatypes_nested_datatype_error.yaml b/nfvparser/toscaparser/tests/data/datatypes/test_custom_datatypes_nested_datatype_error.yaml new file mode 100644 index 0000000..b28f499 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/datatypes/test_custom_datatypes_nested_datatype_error.yaml @@ -0,0 +1,25 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA templates used to test custom datatypes. + +imports: + - custom_datatype_def.yaml + +topology_template: + node_templates: + # 123456789 is not a string + error in nested datatype: + type: tosca.nodes.my.SomeNode + properties: + people: + name: Mike + gender: male + addresses: {Home: 1 foo street, Office: 9 bar avenue} + contacts: + - {contact_name: Tom, + contact_email: tom@email.com, + contact_phone: 123456789} + - {contact_name: Jerry, + contact_email: jerry@email.com, + contact_phone: '321654987'} diff --git a/nfvparser/toscaparser/tests/data/datatypes/test_custom_datatypes_positive.yaml b/nfvparser/toscaparser/tests/data/datatypes/test_custom_datatypes_positive.yaml new file mode 100644 index 0000000..f1762f4 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/datatypes/test_custom_datatypes_positive.yaml @@ -0,0 +1,24 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA templates used to test custom datatypes. + +imports: + - custom_datatype_def.yaml + +topology_template: + node_templates: + positive: + type: tosca.nodes.my.SomeNode + properties: + people: + name: Mike + gender: male + addresses: {Home: 1 foo street, Office: 9 bar avenue} + contacts: + - {contact_name: Tom, + contact_email: tom@email.com, + contact_phone: '123456789'} + - {contact_name: Jerry, + contact_email: jerry@email.com, + contact_phone: '321654987'} diff --git a/nfvparser/toscaparser/tests/data/datatypes/test_custom_datatypes_value_error.yaml b/nfvparser/toscaparser/tests/data/datatypes/test_custom_datatypes_value_error.yaml new file mode 100644 index 0000000..31cf681 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/datatypes/test_custom_datatypes_value_error.yaml @@ -0,0 +1,18 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA templates used to test custom datatypes. + +imports: + - custom_datatype_def.yaml + +topology_template: + node_templates: + # addresses is not a map + error in field value: + type: tosca.nodes.my.SomeNode + properties: + people: + name: Mike + gender: male + addresses: [1 foo street, 9 bar avenue] diff --git a/nfvparser/toscaparser/tests/data/datatypes/test_datatype_portspec_add_req.yaml b/nfvparser/toscaparser/tests/data/datatypes/test_datatype_portspec_add_req.yaml new file mode 100644 index 0000000..f944927 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/datatypes/test_datatype_portspec_add_req.yaml @@ -0,0 +1,41 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: TOSCA test PortSpec Additional Requirement clauses + +node_types: + + MyNodeType: + derived_from: Root + properties: + test_port: + type: PortSpec + +topology_template: + + node_templates: + + # Test invalid source value below (default) specified range constraint + test_node2: + type: MyNodeType + properties: + test_port: + protocol: tcp + source: 0 + + # Test invalid source value over specified range + test_node3: + type: MyNodeType + properties: + test_port: + protocol: tcp + source: 65535 + source_range: [ 2, 65534 ] + + # Test invalid source value under specified range + test_node4: + type: MyNodeType + properties: + test_port: + protocol: tcp + source: 1 + source_range: [ 2, 65534 ] diff --git a/nfvparser/toscaparser/tests/data/dsl_definitions/test_nested_dsl_def.yaml b/nfvparser/toscaparser/tests/data/dsl_definitions/test_nested_dsl_def.yaml new file mode 100644 index 0000000..6155595 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/dsl_definitions/test_nested_dsl_def.yaml @@ -0,0 +1,23 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: Test template demonstrating usage of nested dsl_definitions value. + +dsl_definitions: + caps: &caps + host: + properties: + disk_size: 10 GB + num_cpus: 2 + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 + +topology_template: + node_templates: + my_server: + type: tosca.nodes.Compute + capabilities: *caps \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/data/functions/test_capabilties_inheritance.yaml b/nfvparser/toscaparser/tests/data/functions/test_capabilties_inheritance.yaml new file mode 100644 index 0000000..f0bec84 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_capabilties_inheritance.yaml @@ -0,0 +1,25 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: TOSCA simple profile to test the attribute inheritance + +imports: + - ../custom_types/node_with_cap.yaml + +topology_template: + + node_templates: + + some_node: + type: tosca.nodes.SomeNode + requirements: + - some_req: node_cap + interfaces: + Standard: + configure: + implementation: some_script.sh + inputs: + some_input: { get_property: [ SELF, some_req, type ] } + + node_cap: + type: tosca.nodes.NodeWithCap + diff --git a/nfvparser/toscaparser/tests/data/functions/test_concat.yaml b/nfvparser/toscaparser/tests/data/functions/test_concat.yaml new file mode 100644 index 0000000..22fcfb4 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_concat.yaml @@ -0,0 +1,30 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: Template for deploying a single server with concat function. + +topology_template: + node_templates: + 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 + outputs: + url: + description: Concatenate the URL for a server from template values. + value: { concat: [ 'http://', + get_attribute: [ server, public_address ], + ':' , + get_attribute: [ server, port ] ] } \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/data/functions/test_concat_invalid.yaml b/nfvparser/toscaparser/tests/data/functions/test_concat_invalid.yaml new file mode 100644 index 0000000..7c7b0aa --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_concat_invalid.yaml @@ -0,0 +1,9 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: Template for deploying a single server with invalid concat function. + +topology_template: + outputs: + invalid_concat_syntax: + description: test concat with invalid syntax. + value: { concat: []} \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/data/functions/test_get_attribute_host_keyword.yaml b/nfvparser/toscaparser/tests/data/functions/test_get_attribute_host_keyword.yaml new file mode 100644 index 0000000..90ffbe2 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_get_attribute_host_keyword.yaml @@ -0,0 +1,33 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA template for testing get_attribute with HOST keyword. + +topology_template: + node_templates: + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + num_cpus: 2 + dbms: + type: tosca.nodes.DBMS + requirements: + - host: server + interfaces: + Standard: + configure: + implementation: configure.sh + inputs: + ip_address: { get_attribute: [ HOST, private_address ] } + database: + type: tosca.nodes.Database + requirements: + - host: dbms + interfaces: + Standard: + configure: + implementation: configure.sh + inputs: + ip_address: { get_attribute: [ HOST, private_address ] } diff --git a/nfvparser/toscaparser/tests/data/functions/test_get_attribute_host_not_found.yaml b/nfvparser/toscaparser/tests/data/functions/test_get_attribute_host_not_found.yaml new file mode 100644 index 0000000..69679ff --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_get_attribute_host_not_found.yaml @@ -0,0 +1,20 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA template for testing get_attribute with HOST keyword. + +topology_template: + node_templates: + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + num_cpus: 2 + interfaces: + Standard: + configure: + implementation: configure.sh + inputs: + ip_address: { get_attribute: [ HOST, private_address ] } + diff --git a/nfvparser/toscaparser/tests/data/functions/test_get_attribute_illegal_host_in_outputs.yaml b/nfvparser/toscaparser/tests/data/functions/test_get_attribute_illegal_host_in_outputs.yaml new file mode 100644 index 0000000..6c7d9bb --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_get_attribute_illegal_host_in_outputs.yaml @@ -0,0 +1,17 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA template for testing get_attribute with HOST keyword. + +topology_template: + node_templates: + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + num_cpus: 2 + + outputs: + ip_address: + value: { get_attribute: [ HOST, private_address ] } diff --git a/nfvparser/toscaparser/tests/data/functions/test_get_attribute_source_target_keywords.yaml b/nfvparser/toscaparser/tests/data/functions/test_get_attribute_source_target_keywords.yaml new file mode 100644 index 0000000..047387f --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_get_attribute_source_target_keywords.yaml @@ -0,0 +1,30 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA template for testing get_attribute with TARGET ans SOURCE keywords. + +topology_template: + + node_templates: + + mysql: + type: tosca.nodes.DBMS + properties: + root_password: rootpw + port: 3306 + requirements: + - host: + node: db_server + relationship: + type: tosca.relationships.HostedOn + interfaces: + Configure: + pre_configure_source: + implementation: some_script.sh + inputs: + target_test: { get_attribute: [ TARGET, public_address ] } + source_port: { get_attribute: [ SOURCE, tosca_name ] } + + db_server: + type: tosca.nodes.Compute + diff --git a/nfvparser/toscaparser/tests/data/functions/test_get_attribute_unknown_attribute_name.yaml b/nfvparser/toscaparser/tests/data/functions/test_get_attribute_unknown_attribute_name.yaml new file mode 100644 index 0000000..0570c7c --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_get_attribute_unknown_attribute_name.yaml @@ -0,0 +1,28 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Tosca template for testing unknown attribute name in get_attribute + function. + +topology_template: + inputs: + image_id: + type: string + + node_templates: + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + num_cpus: 2 + interfaces: + Standard: + configure: + implementation: start_server.sh + inputs: + image_id: { get_input: image_id } + + outputs: + ip_address: + value: { get_attribute: [ server, unknown_attribute ] } diff --git a/nfvparser/toscaparser/tests/data/functions/test_get_attribute_unknown_node_template_name.yaml b/nfvparser/toscaparser/tests/data/functions/test_get_attribute_unknown_node_template_name.yaml new file mode 100644 index 0000000..34c1c33 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_get_attribute_unknown_node_template_name.yaml @@ -0,0 +1,30 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Tosca template for testing unknown node template name in get_attribute + function. + +topology_template: + inputs: + image_id: + type: string + + node_templates: + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + num_cpus: 2 + interfaces: + Standard: + configure: + implementation: start_server.sh + inputs: + image_id: { get_input: image_id } + + outputs: + ip_address: + value: { get_attribute: [ unknown_node_template, private_address ] } + network: + value: { get_attribute: [ unknown_node_template, networks, public ] } diff --git a/nfvparser/toscaparser/tests/data/functions/test_get_attribute_with_index.yaml b/nfvparser/toscaparser/tests/data/functions/test_get_attribute_with_index.yaml new file mode 100644 index 0000000..5766490 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_get_attribute_with_index.yaml @@ -0,0 +1,19 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA template for testing get_attribute with a list attribute and an index + +imports: + - ../custom_types/compute_with_attribute_list.yaml + +topology_template: + node_templates: + server: + type: tosca.nodes.ComputeWithAttrList + interfaces: + Standard: + configure: + implementation: configure.sh + inputs: + ip_address: { get_attribute: [ SELF, attr_list, 0 ] } + diff --git a/nfvparser/toscaparser/tests/data/functions/test_get_attribute_with_index_error.yaml b/nfvparser/toscaparser/tests/data/functions/test_get_attribute_with_index_error.yaml new file mode 100644 index 0000000..7511999 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_get_attribute_with_index_error.yaml @@ -0,0 +1,19 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA template for testing get_attribute with an incorrect index + +imports: + - ../custom_types/compute_with_attribute_list.yaml + +topology_template: + node_templates: + server: + type: tosca.nodes.ComputeWithAttrList + interfaces: + Standard: + configure: + implementation: configure.sh + inputs: + ip_address: { get_attribute: [ SELF, private_address, 0 ] } + diff --git a/nfvparser/toscaparser/tests/data/functions/test_get_attribute_with_nested_params.yaml b/nfvparser/toscaparser/tests/data/functions/test_get_attribute_with_nested_params.yaml new file mode 100644 index 0000000..79e632c --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_get_attribute_with_nested_params.yaml @@ -0,0 +1,23 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA template for testing get_attribute with nested attributes + +imports: + - ../custom_types/compute_with_nested_atributes.yaml + +topology_template: + node_templates: + server: + type: tosca.nodes.ComputeWithCapWithAttr + capabilities: + endpoint: + properties: + port: 80 + interfaces: + Standard: + configure: + implementation: configure.sh + inputs: + ip_address: { get_attribute: [ SELF, endpoint, credential, 0, token ] } + diff --git a/nfvparser/toscaparser/tests/data/functions/test_get_implicit_attribute.yaml b/nfvparser/toscaparser/tests/data/functions/test_get_implicit_attribute.yaml new file mode 100644 index 0000000..a269005 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_get_implicit_attribute.yaml @@ -0,0 +1,25 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Attribute can be defined explicitly as part of type definition + or implicitly via property. This TOSCA template tests validation + of attribute name implicitly created as a property and referenced + via get_attribute function. + +node_types: + ServerNode: + derived_from: SoftwareComponent + properties: + notification_port: + type: integer + +topology_template: + node_templates: + my_server: + type: ServerNode + properties: + notification_port: 8000 + + outputs: + ip_address: + value: { get_attribute: [ my_server, notification_port ] } \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/data/functions/test_get_property_source_target_keywords.yaml b/nfvparser/toscaparser/tests/data/functions/test_get_property_source_target_keywords.yaml new file mode 100644 index 0000000..c460257 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_get_property_source_target_keywords.yaml @@ -0,0 +1,35 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA template for testing get_property with TARGET ans SOURCE keywords. + +imports: + - ../custom_types/compute_with_prop.yaml + +topology_template: + + node_templates: + + mysql: + type: tosca.nodes.DBMS + properties: + root_password: rootpw + port: 3306 + requirements: + - host: + node: db_server + relationship: + type: tosca.relationships.HostedOn + interfaces: + Configure: + pre_configure_source: + implementation: some_script.sh + inputs: + target_test: { get_property: [ TARGET, test ] } + source_port: { get_property: [ SOURCE, port ] } + + db_server: + type: tosca.nodes.ComputeWithProp + properties: + test: 1 + diff --git a/nfvparser/toscaparser/tests/data/functions/test_get_property_with_host.yaml b/nfvparser/toscaparser/tests/data/functions/test_get_property_with_host.yaml new file mode 100644 index 0000000..1ca69ca --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_get_property_with_host.yaml @@ -0,0 +1,65 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile to test the get property function with HOST parameter + +imports: + - ../custom_types/compute_with_prop.yaml + +topology_template: + inputs: + db_name: + type: string + description: The name of the database. + default: wordpress + db_user: + type: string + description: The user name of the DB user. + default: wp_user + db_pwd: + type: string + description: The WordPress database admin account password. + default: wp_pass + db_root_pwd: + type: string + description: Root password for MySQL. + db_port: + type: PortDef + description: Port for the MySQL database. + default: 3306 + + node_templates: + + mysql_database: + type: tosca.nodes.Database + properties: + name: { get_input: db_name } + user: { get_input: db_user } + password: { get_input: db_pwd } + capabilities: + database_endpoint: + properties: + port: { get_input: db_port } + requirements: + - host: mysql_dbms + interfaces: + Standard: + configure: + implementation: mysql/mysql_database_configure.sh + inputs: + db_port: { get_property: [ HOST, port ] } + test: { get_property: [ HOST, test ] } + + mysql_dbms: + type: tosca.nodes.DBMS + properties: + root_password: { get_input: db_root_pwd } + port: { get_input: db_port } + requirements: + - host: server + + server: + type: tosca.nodes.ComputeWithProp + properties: + test: 1 + diff --git a/nfvparser/toscaparser/tests/data/functions/test_invalid_function_signature.yaml b/nfvparser/toscaparser/tests/data/functions/test_invalid_function_signature.yaml new file mode 100644 index 0000000..dde8427 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_invalid_function_signature.yaml @@ -0,0 +1,34 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile template to test invalid get_input function. + +topology_template: + inputs: + cpus: + type: integer + description: Number of CPUs for the server. + constraints: + - valid_values: [ 1, 2, 4, 8 ] + + node_templates: + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + # compute properties (flavor) + disk_size: 10 GB + num_cpus: { get_input: [cpus, cpus] } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Fedora + version: 18.0 + + outputs: + server_address: + description: IP address of server instance. + value: { get_attribute: [server, private_address] } diff --git a/nfvparser/toscaparser/tests/data/functions/test_token.yaml b/nfvparser/toscaparser/tests/data/functions/test_token.yaml new file mode 100644 index 0000000..495a930 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_token.yaml @@ -0,0 +1,15 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: Template for deploying a single server with token function. + +topology_template: + node_templates: + server: + type: tosca.nodes.Compute + + outputs: + url: + description: Get the first part of the ip + value: { token: [ get_attribute: [ server, public_address ], + '.' , + 0 ] } diff --git a/nfvparser/toscaparser/tests/data/functions/test_token_invalid.yaml b/nfvparser/toscaparser/tests/data/functions/test_token_invalid.yaml new file mode 100644 index 0000000..35ae2ff --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_token_invalid.yaml @@ -0,0 +1,17 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: Template for deploying a single server with invalid token function. + +topology_template: + outputs: + invalid_token_syntax_1: + description: test token with only two paremeters. + value: { token: ["some_string", "_"]} + + invalid_token_syntax_2: + description: test token with invalid string as third argument. + value: { token: ["some_string", "_", "1"]} + + invalid_token_syntax_3: + description: test token with invalid string as second argument. + value: { token: ["some_string", "aa", "1"]} diff --git a/nfvparser/toscaparser/tests/data/functions/test_unknown_capability_property.yaml b/nfvparser/toscaparser/tests/data/functions/test_unknown_capability_property.yaml new file mode 100644 index 0000000..4a92530 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_unknown_capability_property.yaml @@ -0,0 +1,36 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Tosca template for testing an unknown capability property. + +topology_template: + node_templates: + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + num_cpus: 2 + dbms: + type: tosca.nodes.DBMS + properties: + root_password: 1234 + port: 3672 + database: + type: tosca.nodes.Database + properties: + name: my_db + user: abcd + password: 1234 + capabilities: + database_endpoint: + properties: + port: { get_property: [ dbms, port ] } + requirements: + - host: dbms + interfaces: + Standard: + configure: + implementation: database_configure.sh + inputs: + db_port: { get_property: [ SELF, database_endpoint, unknown ] } diff --git a/nfvparser/toscaparser/tests/data/functions/test_unknown_input_in_interface.yaml b/nfvparser/toscaparser/tests/data/functions/test_unknown_input_in_interface.yaml new file mode 100644 index 0000000..cbfb391 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_unknown_input_in_interface.yaml @@ -0,0 +1,20 @@ + +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Tosca template for testing an unknown input. + +topology_template: + node_templates: + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + num_cpus: 2 + interfaces: + Standard: + configure: + implementation: start_server.sh + inputs: + image_id: { get_input: image_id } diff --git a/nfvparser/toscaparser/tests/data/functions/test_unknown_input_in_property.yaml b/nfvparser/toscaparser/tests/data/functions/test_unknown_input_in_property.yaml new file mode 100644 index 0000000..9ba7ee5 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/test_unknown_input_in_property.yaml @@ -0,0 +1,13 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Tosca template for testing an unknown input. + +topology_template: + node_templates: + obj_store_server: + type: tosca.nodes.ObjectStorage + properties: + name: { get_input: objectstore_name } + size: 1024 MB + maxsize: 1 GB diff --git a/nfvparser/toscaparser/tests/data/functions/tosca_nested_property_names_indexes.yaml b/nfvparser/toscaparser/tests/data/functions/tosca_nested_property_names_indexes.yaml new file mode 100644 index 0000000..8fb7b96 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/functions/tosca_nested_property_names_indexes.yaml @@ -0,0 +1,47 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: TOSCA simple profile with nested property names or indexes. + +imports: + - ../custom_types/wordpress.yaml + - ../custom_types/db_with_list_param.yaml + +topology_template: + + node_templates: + + wordpress: + type: tosca.nodes.WebApplication.WordPress + requirements: + - host: server + - database_endpoint: mysql_database + interfaces: + Standard: + configure: + implementation: wordpress/wordpress_configure.sh + inputs: + wp_endpoint_protocol: { get_property: [ SELF, database_endpoint, ports, user_port, protocol ] } + wp_list_prop: { get_property: [ mysql_database, list_prop, 2 ] } + + mysql_database: + type: tosca.nodes.DatabaseWithListParam + properties: + list_prop: [1,2,3] + capabilities: + database_endpoint: + properties: + ports: + user_port: + protocol: tcp + target: 50000 + source: 9000 + requirements: + - host: mysql_dbms + + mysql_dbms: + type: tosca.nodes.DBMS + requirements: + - host: server + + server: + type: tosca.nodes.Compute diff --git a/nfvparser/toscaparser/tests/data/groups/definitions.yaml b/nfvparser/toscaparser/tests/data/groups/definitions.yaml new file mode 100644 index 0000000..40c1d8b --- /dev/null +++ b/nfvparser/toscaparser/tests/data/groups/definitions.yaml @@ -0,0 +1,10 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +group_types: + mycompany.mytypes.groups.placement: + description: My company's group type for placing nodes of type Compute + members: [ tosca.nodes.Compute ] + metadata: + type: map + entry_schema: + type: string diff --git a/nfvparser/toscaparser/tests/data/groups/tosca_group_template.yaml b/nfvparser/toscaparser/tests/data/groups/tosca_group_template.yaml new file mode 100644 index 0000000..0e94240 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/groups/tosca_group_template.yaml @@ -0,0 +1,54 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Service template with topology_template, act as a nested system inside another system. + +imports: + - definitions.yaml + +topology_template: + description: Template of a database including its hosting stack. + + inputs: + mq_server_ip: + type: string + description: IP address of the message queuing server to receive messages from. + receiver_port: + type: string + description: Port to be used for receiving messages. + my_cpus: + type: integer + description: Number of CPUs for the server. + constraints: + - valid_values: [ 1, 2, 4, 8 ] + + node_templates: + websrv: + type: tosca.nodes.WebServer + capabilities: + data_endpoint: + properties: + port_name: { get_input: receiver_port } + requirements: + - host: + node: server + + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: my_cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 + + groups: + webserver_group: + type: mycompany.mytypes.groups.placement + members: [ websrv, server ] diff --git a/nfvparser/toscaparser/tests/data/interfaces/test_custom_interface_in_template.yaml b/nfvparser/toscaparser/tests/data/interfaces/test_custom_interface_in_template.yaml new file mode 100644 index 0000000..c23917c --- /dev/null +++ b/nfvparser/toscaparser/tests/data/interfaces/test_custom_interface_in_template.yaml @@ -0,0 +1,23 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with valid custom interface and operations. + +imports: + - ../custom_types/custom_interface.yaml + +topology_template: + + node_templates: + customInterfaceTest: + type: tosca.nodes.CustomInterfaceTest + interfaces: + CustomInterface: + CustomOp: # operation from interface_type with additional inputs + inputs: + param: + type: string + CustomOp3: # operation from node_type with additional inputs + inputs: + param3: + type: string diff --git a/nfvparser/toscaparser/tests/data/interfaces/test_custom_interface_invalid_operation.yaml b/nfvparser/toscaparser/tests/data/interfaces/test_custom_interface_invalid_operation.yaml new file mode 100644 index 0000000..d56ad9c --- /dev/null +++ b/nfvparser/toscaparser/tests/data/interfaces/test_custom_interface_invalid_operation.yaml @@ -0,0 +1,19 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with invalid custom operation. + +imports: + - ../custom_types/custom_interface.yaml + +topology_template: + + node_templates: + customInterfaceTest: + type: tosca.nodes.CustomInterfaceTest + interfaces: + CustomInterface: + CustomOp4: # invalid operation + inputs: + param3: + type: string diff --git a/nfvparser/toscaparser/tests/data/load_balancer/tosca_load_balancer.yaml b/nfvparser/toscaparser/tests/data/load_balancer/tosca_load_balancer.yaml new file mode 100644 index 0000000..2fcdb48 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/load_balancer/tosca_load_balancer.yaml @@ -0,0 +1,75 @@ +# Note: this could eventually be translated to a Neutron Load Balancer +# However, in Heat/HOT the preferred way of doing this is creating an Autoscale Group +# +#heat_template_version: 2015-04-30 ... +#resources: +#load_bal_resource: +# type: OS::Neutron::Pool +# properties: +# admin_state_up: Boolean +# description: String +# lb_method: String +# monitors: [Value, Value, ...] +# name: String +# protocol: String +# provider: String +# subnet: String +# vip: { +# "description": String, +# "name": String, +# "connection_limit": Integer, +# "protocol_port": Integer, +# "subnet": String, +# "address": String, +# "admin_state_up": Boolean, +# "session_persistence": +# { +# "cookie_name": String, +# "type": String} +# } +# +# example from: https://gist.github.com/therve/9231701 +# +#resources: +# web_server_group: +# type: AWS::AutoScaling::AutoScalingGroup +# properties: +# AvailabilityZones: [nova] +# LaunchConfigurationName: {get_resource: launch_config} +# MinSize: 1 +# MaxSize: 3 +# LoadBalancerNames: +# - {get_resource: mylb} +# mypool: +# type: OS::Neutron::Pool +# properties: +# protocol: HTTP +# monitors: [{get_resource: mymonitor}] +# subnet_id: {get_param: subnet_id} +# lb_method: ROUND_ROBIN +# vip: +# protocol_port: 80 +# mylb: +# type: OS::Neutron::LoadBalancer +# properties: +# protocol_port: 80 +# pool_id: {get_resource: mypool} + +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: Template for deploying a load balancer with predefined endpoint properties. + +topology_template: + node_templates: + simple_load_balancer: + type: tosca.nodes.LoadBalancer + capabilities: + # properties: + # algorithm: DEFAULT (define new keyword, ROUND_ROBIN?) + # Client, public facing endpoint + client: + properties: + network_name: PUBLIC + floating: true + dns_name: http://mycompany.com/ + diff --git a/nfvparser/toscaparser/tests/data/node_filter/test_node_filter.yaml b/nfvparser/toscaparser/tests/data/node_filter/test_node_filter.yaml new file mode 100644 index 0000000..3dd8e26 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/node_filter/test_node_filter.yaml @@ -0,0 +1,18 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: Template with requirements against hosting infrastructure. + +topology_template: + + node_templates: + test: + type: tosca.nodes.DBMS + requirements: + - host: + node_filter: + capabilities: + - host: + properties: + - num_cpus: { in_range: [ 1, 4 ] } + - mem_size: { greater_or_equal: 2 GB } + diff --git a/nfvparser/toscaparser/tests/data/policies/custom_definitions.yaml b/nfvparser/toscaparser/tests/data/policies/custom_definitions.yaml new file mode 100644 index 0000000..7f15ade --- /dev/null +++ b/nfvparser/toscaparser/tests/data/policies/custom_definitions.yaml @@ -0,0 +1,10 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +policy_types: + mycompany.mytypes.myScalingPolicy: + derived_from: tosca.policies.Scaling + metadata: + type: map + entry_schema: + type: string + diff --git a/nfvparser/toscaparser/tests/data/policies/tacker_defs.yaml b/nfvparser/toscaparser/tests/data/policies/tacker_defs.yaml new file mode 100644 index 0000000..96b0d45 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/policies/tacker_defs.yaml @@ -0,0 +1,183 @@ +tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 + +data_types: + tosca.datatypes.tacker.ActionMap: + properties: + trigger: + type: string + required: true + action: + type: string + required: true + params: + type: map + entry_schema: + type: string + required: false + + tosca.datatypes.tacker.MonitoringParams: + properties: + monitoring_delay: + type: int + required: false + count: + type: int + required: false + interval: + type: int + required: false + timeout: + type: int + required: false + retry: + type: int + required: false + port: + type: int + required: false + + tosca.datatypes.tacker.MonitoringType: + properties: + name: + type: string + required: true + actions: + type: map + required: true + parameters: + type: tosca.datatypes.tacker.MonitoringParams + required: false + + tosca.datatypes.compute_properties: + properties: + num_cpus: + type: integer + required: false + mem_size: + type: string + required: false + disk_size: + type: string + required: false + mem_page_size: + type: string + required: false + numa_node_count: + type: integer + constraints: + - greater_or_equal: 2 + required: false + numa_nodes: + type: map + required: false + cpu_allocation: + type: map + required: false + +policy_types: + tosca.policies.tacker.Placement: + derived_from: tosca.policies.Root + + tosca.policies.tacker.Failure: + derived_from: tosca.policies.Root + action: + type: string + + tosca.policies.tacker.Failure.Respawn: + derived_from: tosca.policies.tacker.Failure + action: respawn + + tosca.policies.tacker.Failure.Terminate: + derived_from: tosca.policies.tacker.Failure + action: log_and_kill + + tosca.policies.tacker.Failure.Log: + derived_from: tosca.policies.tacker.Failure + action: log + + tosca.policies.tacker.Monitoring: + derived_from: tosca.policies.Root + properties: + name: + type: string + required: true + parameters: + type: map + entry_schema: + type: string + required: false + actions: + type: map + entry_schema: + type: string + required: true + + tosca.policies.tacker.Monitoring.NoOp: + derived_from: tosca.policies.tacker.Monitoring + properties: + name: noop + + tosca.policies.tacker.Monitoring.Ping: + derived_from: tosca.policies.tacker.Monitoring + properties: + name: ping + + tosca.policies.tacker.Monitoring.HttpPing: + derived_from: tosca.policies.tacker.Monitoring.Ping + properties: + name: http-ping + + tosca.policies.tacker.Alarming: + derived_from: tosca.policies.Monitoring + triggers: + resize_compute: + event_type: + type: map + entry_schema: + type: string + required: true + metrics: + type: string + required: true + condition: + type: map + entry_schema: + type: string + required: false + action: + type: map + entry_schema: + type: string + required: true + + tosca.policies.tacker.Scaling: + derived_from: tosca.policies.Scaling + description: Defines policy for scaling the given targets. + properties: + increment: + type: integer + required: true + description: Number of nodes to add or remove during the scale out/in. + targets: + type: list + entry_schema: + type: string + required: true + description: List of Scaling nodes. + min_instances: + type: integer + required: true + description: Minimum number of instances to scale in. + max_instances: + type: integer + required: true + description: Maximum number of instances to scale out. + default_instances: + type: integer + required: true + description: Initial number of instances. + cooldown: + type: integer + required: false + default: 120 + description: Wait time (in seconds) between consecutive scaling operations. During the cooldown period... diff --git a/nfvparser/toscaparser/tests/data/policies/tacker_nfv_defs.yaml b/nfvparser/toscaparser/tests/data/policies/tacker_nfv_defs.yaml new file mode 100644 index 0000000..1387509 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/policies/tacker_nfv_defs.yaml @@ -0,0 +1,261 @@ +tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 + +data_types: + tosca.nfv.datatypes.pathType: + properties: + forwarder: + type: string + required: true + capability: + type: string + required: true + + tosca.nfv.datatypes.aclType: + properties: + eth_type: + type: string + required: false + eth_src: + type: string + required: false + eth_dst: + type: string + required: false + vlan_id: + type: integer + constraints: + - in_range: [ 1, 4094 ] + required: false + vlan_pcp: + type: integer + constraints: + - in_range: [ 0, 7 ] + required: false + mpls_label: + type: integer + constraints: + - in_range: [ 16, 1048575] + required: false + mpls_tc: + type: integer + constraints: + - in_range: [ 0, 7 ] + required: false + ip_dscp: + type: integer + constraints: + - in_range: [ 0, 63 ] + required: false + ip_ecn: + type: integer + constraints: + - in_range: [ 0, 3 ] + required: false + ip_src_prefix: + type: string + required: false + ip_dst_prefix: + type: string + required: false + ip_proto: + type: integer + constraints: + - in_range: [ 1, 254 ] + required: false + destination_port_range: + type: string + required: false + source_port_range: + type: string + required: false + network_src_port_id: + type: string + required: false + network_dst_port_id: + type: string + required: false + network_id: + type: string + required: false + network_name: + type: string + required: false + tenant_id: + type: string + required: false + icmpv4_type: + type: integer + constraints: + - in_range: [ 0, 254 ] + required: false + icmpv4_code: + type: integer + constraints: + - in_range: [ 0, 15 ] + required: false + arp_op: + type: integer + constraints: + - in_range: [ 1, 25 ] + required: false + arp_spa: + type: string + required: false + arp_tpa: + type: string + required: false + arp_sha: + type: string + required: false + arp_tha: + type: string + required: false + ipv6_src: + type: string + required: false + ipv6_dst: + type: string + required: false + ipv6_flabel: + type: integer + constraints: + - in_range: [ 0, 1048575] + required: false + icmpv6_type: + type: integer + constraints: + - in_range: [ 0, 255] + required: false + icmpv6_code: + type: integer + constraints: + - in_range: [ 0, 7] + required: false + ipv6_nd_target: + type: string + required: false + ipv6_nd_sll: + type: string + required: false + ipv6_nd_tll: + type: string + required: false + + tosca.nfv.datatypes.policyType: + properties: + type: + type: string + required: false + constraints: + - valid_values: [ ACL ] + criteria: + type: list + required: true + entry_schema: + type: tosca.nfv.datatypes.aclType + +node_types: + tosca.nodes.nfv.VDU.Tacker: + derived_from: tosca.nodes.nfv.VDU + capabilities: + nfv_compute: + type: tosca.datatypes.compute_properties + properties: + name: + type: string + required: false + image: +# type: tosca.artifacts.Deployment.Image.VM + type: string + required: false + flavor: + type: string + required: false + availability_zone: + type: string + required: false + metadata: + type: map + entry_schema: + type: string + required: false + config_drive: + type: boolean + default: false + required: false + + placement_policy: +# type: tosca.policies.tacker.Placement + type: string + required: false + + monitoring_policy: +# type: tosca.policies.tacker.Monitoring +# type: tosca.datatypes.tacker.MonitoringType + type: map + required: false + + config: + type: string + required: false + + mgmt_driver: + type: string + default: noop + required: false + + service_type: + type: string + required: false + + user_data: + type: string + required: false + + user_data_format: + type: string + required: false + + key_name: + type: string + required: false + + tosca.nodes.nfv.CP.Tacker: + derived_from: tosca.nodes.nfv.CP + properties: + mac_address: + type: string + required: false + name: + type: string + required: false + management: + type: boolean + required: false + anti_spoofing_protection: + type: boolean + required: false + security_groups: + type: list + required: false + type: + type: string + required: false + constraints: + - valid_values: [ sriov, vnic ] + + tosca.nodes.nfv.FP.Tacker: + derived_from: tosca.nodes.Root + properties: + id: + type: integer + required: false + policy: + type: tosca.nfv.datatypes.policyType + required: true + description: policy to use to match traffic for this FP + path: + type: list + required: true + entry_schema: + type: tosca.nfv.datatypes.pathType diff --git a/nfvparser/toscaparser/tests/data/policies/test_tosca_nfv_multiple_policies.yaml b/nfvparser/toscaparser/tests/data/policies/test_tosca_nfv_multiple_policies.yaml new file mode 100644 index 0000000..452dbb5 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/policies/test_tosca_nfv_multiple_policies.yaml @@ -0,0 +1,95 @@ +tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 + +description: sample-tosca-vnfd-scaling + +imports: + - tacker_defs.yaml + - tacker_nfv_defs.yaml + +metadata: + template_name: sample-tosca-vnfd-scaling + +topology_template: + node_templates: + VDU1: + type: tosca.nodes.nfv.VDU.Tacker + properties: + image: cirros-0.3.4-x86_64-uec + mgmt_driver: noop + availability_zone: nova + flavor: m1.tiny + + CP1: + type: tosca.nodes.nfv.CP.Tacker + properties: + management: true + order: 0 + anti_spoofing_protection: false + requirements: + - virtualLink: + node: VL1 + - virtualBinding: + node: VDU1 + + VDU2: + type: tosca.nodes.nfv.VDU.Tacker + properties: + image: cirros-0.3.4-x86_64-uec + mgmt_driver: noop + availability_zone: nova + flavor: m1.tiny + + CP2: + type: tosca.nodes.nfv.CP.Tacker + properties: + management: true + order: 0 + anti_spoofing_protection: false + requirements: + - virtualLink: + node: VL1 + - virtualBinding: + node: VDU2 + + VL1: + type: tosca.nodes.nfv.VL + properties: + network_name: net_mgmt + vendor: Tacker + + policies: + - SP1: + type: tosca.policies.tacker.Scaling + targets: [VDU1] + properties: + increment: 1 + cooldown: 120 + min_instances: 1 + max_instances: 2 + default_instances: 1 + + - SP2: + type: tosca.policies.tacker.Scaling + targets: [VDU2] + properties: + increment: 1 + cooldown: 120 + min_instances: 1 + max_instances: 2 + default_instances: 1 + + - ALRM1: + type: tosca.policies.tacker.Monitoring + triggers: + resize_compute: + event_type: + type: tosca.events.resource.utilization + implementation: ceilometer + condition: + constraint: 50 + period: 600 + evaluations: 1 + method: avg + action: + resize_compute: + action_name: SP1 diff --git a/nfvparser/toscaparser/tests/data/policies/tosca_policy_template.yaml b/nfvparser/toscaparser/tests/data/policies/tosca_policy_template.yaml new file mode 100644 index 0000000..47f7870 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/policies/tosca_policy_template.yaml @@ -0,0 +1,85 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Template for deploying servers based on policies. + +imports: + - custom_definitions.yaml + +topology_template: + node_templates: + my_server_1: + 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 + + my_server_2: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: 2 + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 + + groups: + webserver_group: + members: [ my_server_1, my_server_2 ] + type: tosca.groups.Root + metadata: { user1: 1008, user2: 1002 } + + + policies: + - my_compute_placement_policy: + type: tosca.policies.Placement + description: Apply placement policy to servers + metadata: { user1: 1001, user2: 1002 } + targets: [ my_server_1, my_server_2 ] + triggers: + resize_compute: + description: trigger + event_type: tosca.events.resource.utilization + schedule: + start_time: "2015-05-07T07:00:00Z" + end_time: "2015-06-07T07:00:00Z" + target_filter: + node: master-container + requirement: host + capability: Container + condition: + constraint: { greater_than: 50 } + period: 60 + evaluations: 1 + method: average + action: + resize: # Operation name + inputs: + strategy: LEAST_USED + implementation: Senlin.webhook() + - my_groups_placement: + type: mycompany.mytypes.myScalingPolicy + targets: [ webserver_group ] + description: my company scaling policy + metadata: + user1: 1001 + user2: 1003 + diff --git a/nfvparser/toscaparser/tests/data/relationship/test_custom_relationship.yaml b/nfvparser/toscaparser/tests/data/relationship/test_custom_relationship.yaml new file mode 100644 index 0000000..81b92b4 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/relationship/test_custom_relationship.yaml @@ -0,0 +1,48 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: Test template for deploying a single server with predefined properties and custom relationship types + +imports: + - ../custom_types/custom_relationship_type_defs.yaml + +topology_template: + node_templates: + server1: + type: tosca.nodes.HACompute + 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 + requirements: + - high_availability: server2 + + server2: + type: tosca.nodes.HACompute + 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 + requirements: + - high_availability: server1 diff --git a/nfvparser/toscaparser/tests/data/repositories/test_repositories_definition.yaml b/nfvparser/toscaparser/tests/data/repositories/test_repositories_definition.yaml new file mode 100644 index 0000000..c2856c8 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/repositories/test_repositories_definition.yaml @@ -0,0 +1,23 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +repositories: + some_repository: + description: Some repo + url: https://raw.githubusercontent.com/openstack/tosca-parser/master/toscaparser/tests/data/custom_types/ + credential: #type: Credential + token_type: basic_auth + token: myusername:mypassword +imports: + - some_import: + file: compute_with_prop.yaml + repository: some_repository + +description: > + TOSCA test for testing repositories definition + + node_templates: + + server: + type: tosca.nodes.ComputeWithProp + properties: + test: yes diff --git a/nfvparser/toscaparser/tests/data/repositories/tosca_repositories_test_definition.yaml b/nfvparser/toscaparser/tests/data/repositories/tosca_repositories_test_definition.yaml new file mode 100644 index 0000000..0001d06 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/repositories/tosca_repositories_test_definition.yaml @@ -0,0 +1,26 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: TOSCA simple profile with repositories validation and imports. + +repositories: + repo_code0: https://raw.githubusercontent.com/nandinivemula/intern + repo_code1: + description: My project's code Repository in github usercontent. + url: https://raw.githubusercontent.com/nandinivemula/intern/master + credential: #type: Credential + token_type: basic_auth + token: myusername:mypassword + + repo_code2: + description: My Project's code Repository in github. + url: https://github.com/nandinivemula/intern/master + credential: #type: Credential + token_type: basic_auth + token: myusername:mypassword + +imports: + - sample_import: + file: tosca_repository_import.yaml + repository: repo_code1 + namespace_uri: https://github.com/nandinivemula/intern + namespace_prefix: intern diff --git a/nfvparser/toscaparser/tests/data/requirements/test_requirements.yaml b/nfvparser/toscaparser/tests/data/requirements/test_requirements.yaml new file mode 100644 index 0000000..bb67577 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/requirements/test_requirements.yaml @@ -0,0 +1,67 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Test Requirements. + +imports: + - ../custom_types/wordpress.yaml + +topology_template: + node_templates: + my_app: + description: > + Specify multiple requirement via node and relationship keyword, + as an explicit relationship. Also demonstrates relationship with + type keyword and without it as an in-line reference. + type: tosca.nodes.WebApplication.WordPress + requirements: + - req1: + node: my_webserver + relationship: tosca.relationships.HostedOn + - req2: + node: mysql_database + relationship: + type: tosca.relationships.ConnectsTo + mysql_database: + description: Specify requirement via a capability as an implicit relationship. + type: tosca.nodes.Database + requirements: + - host: + node: my_dbms + relationship: tosca.relationships.HostedOn + my_dbms: + type: tosca.nodes.DBMS + my_webserver: + type: tosca.nodes.WebServer + my_server: + description: > + Specify requirement via a relationship template, as an explicit relationship. + type: tosca.nodes.Compute + capabilities: + host: + properties: + num_cpus: 2 + disk_size: 10 GB + mem_size: 4 MB + os: + properties: + # host Operating System image properties + architecture: x86_64 + type: linux + distribution: rhel + version: 6.5 + requirements: + - req1: + node: my_storage + relationship: storage_attachment + my_storage: + type: tosca.nodes.BlockStorage + properties: + size: 1 GiB + snapshot_id: id + + relationship_templates: + storage_attachment: + type: tosca.relationships.AttachesTo + properties: + location: /temp diff --git a/nfvparser/toscaparser/tests/data/test_attributes_inheritance.yaml b/nfvparser/toscaparser/tests/data/test_attributes_inheritance.yaml new file mode 100644 index 0000000..0649c11 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_attributes_inheritance.yaml @@ -0,0 +1,28 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: TOSCA simple profile to test the attribute inheritance + +imports: + - custom_types/compute_with_prop.yaml + +topology_template: + + node_templates: + + server: + type: tosca.nodes.ComputeWithProp + properties: + test: yes + capabilities: + host: + properties: + num_cpus: 1 + mem_size: 1 GB + os: + properties: + type: linux + + outputs: + server_ip: + value: { get_attribute: [ server, public_address ] } + diff --git a/nfvparser/toscaparser/tests/data/test_available_rel_tpls.yaml b/nfvparser/toscaparser/tests/data/test_available_rel_tpls.yaml new file mode 100644 index 0000000..e8d9045 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_available_rel_tpls.yaml @@ -0,0 +1,23 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: TOSCA test for bug 1527214 + +topology_template: + + node_templates: + + test_db: + type: tosca.nodes.Database + requirements: + - host: + node: mysql + + mysql: + type: tosca.nodes.DBMS + requirements: + - host: + node: db_server + + db_server: + type: tosca.nodes.Compute + diff --git a/nfvparser/toscaparser/tests/data/test_containers.yaml b/nfvparser/toscaparser/tests/data/test_containers.yaml new file mode 100644 index 0000000..ba1cc16 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_containers.yaml @@ -0,0 +1,44 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with mysql docker container. + +# Repositories to retrieve code artifacts from +repositories: + docker_hub: https://registry.hub.docker.com/ + +topology_template: + + inputs: + mysql_root_pwd: + type: string + description: Root password for MySQL. + + node_templates: + # The MYSQL container based on official MySQL image in Docker hub + mysql_container: + type: tosca.nodes.Container.Application + requirements: + - host: mysql_runtime + artifacts: + my_image: + file: mysql + type: tosca.artifacts.Deployment.Image.Container.Docker + repository: docker_hub + interfaces: + Standard: + create: + implementation: my_image + inputs: + MYSQL_ROOT_PASSWORD: { get_input: mysql_root_pwd } + + # The properties of the runtime to host the container + mysql_runtime: + type: tosca.nodes.Container.Runtime + capabilities: + host: + properties: + num_cpus: 1 + disk_size: 10 GB + mem_size: 2 MB + diff --git a/nfvparser/toscaparser/tests/data/test_credential_datatype.yaml b/nfvparser/toscaparser/tests/data/test_credential_datatype.yaml new file mode 100644 index 0000000..583ec82 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_credential_datatype.yaml @@ -0,0 +1,77 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with to demonstrate the usage of the + TOSCA Credential Data Type. + +imports: + - custom_types/wordpress.yaml + +relationship_types: + my.types.WordpressDbConnection: + derived_from: tosca.relationships.ConnectsTo + properties: + credential: + user: db_user + token: db_pwd + +topology_template: + node_templates: + wordpress: + type: tosca.nodes.WebApplication.WordPress + requirements: + - host: webserver + - database_endpoint: + node: mysql_database + relationship: my.types.WordpressDbConnection + + mysql_database: + type: tosca.nodes.Database + properties: + name: db_name + user: db_user + password: db_pwd + capabilities: + database_endpoint: + properties: + port: 3306 + requirements: + - host: + node: mysql_dbms + + mysql_dbms: + type: tosca.nodes.DBMS + properties: + root_password: db_root_pwd + port: 3306 + requirements: + - host: server + + webserver: + type: tosca.nodes.WebServer + properties: + admin_credential: + user: username + token: some_pass + requirements: + - host: server + + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: 1 + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 + + outputs: + website_url: + description: URL for Wordpress wiki. + value: { get_attribute: [server, private_address] } diff --git a/nfvparser/toscaparser/tests/data/test_custom_caps_def.yaml b/nfvparser/toscaparser/tests/data/test_custom_caps_def.yaml new file mode 100644 index 0000000..0b0984a --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_custom_caps_def.yaml @@ -0,0 +1,13 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: TOSCA simple profile to test a custom defined capability + +imports: + - custom_types/custom_caps_def.yaml + +topology_template: + + node_templates: + + server: + type: tosca.nodes.SomeNode diff --git a/nfvparser/toscaparser/tests/data/test_custom_relationships.yaml b/nfvparser/toscaparser/tests/data/test_custom_relationships.yaml new file mode 100644 index 0000000..9c8171d --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_custom_relationships.yaml @@ -0,0 +1,48 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: Test template for deploying a single server with predefined properties and custom relationship types + +imports: + - custom_types/custom_relationship_type_defs.yaml + +topology_template: + node_templates: + server1: + type: tosca.nodes.HACompute + 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 + requirements: + - high_availability: server2 + + server2: + type: tosca.nodes.HACompute + 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 + requirements: + - high_availability: server1 diff --git a/nfvparser/toscaparser/tests/data/test_endpoint_on_compute.yaml b/nfvparser/toscaparser/tests/data/test_endpoint_on_compute.yaml new file mode 100644 index 0000000..cf2ec94 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_endpoint_on_compute.yaml @@ -0,0 +1,21 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +topology_template: + node_templates: + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: 1 + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 + endpoint: + properties: + network_name: PUBLIC diff --git a/nfvparser/toscaparser/tests/data/test_instance_nested_imports.yaml b/nfvparser/toscaparser/tests/data/test_instance_nested_imports.yaml new file mode 100644 index 0000000..6aa9307 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_instance_nested_imports.yaml @@ -0,0 +1,22 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with wordpress, web server and mysql on the same server. + +imports: + - wordpress: custom_types/nested_test_wordpress.yaml + +topology_template: + + node_templates: + wordpress: + type: tosca.nodes.WebApplication.WordPress + + testrsyslogtype: + type: tosca.nodes.SoftwareComponent.Rsyslog.TestRsyslogType + + rsyslog: + type: Test2ndRsyslogType + + logstash: + type: tosca.nodes.SoftwareComponent.Logstash diff --git a/nfvparser/toscaparser/tests/data/test_invalid_input_defaults.yaml b/nfvparser/toscaparser/tests/data/test_invalid_input_defaults.yaml new file mode 100644 index 0000000..f8f4ae7 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_invalid_input_defaults.yaml @@ -0,0 +1,12 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: Test template with default not matching required type. + +topology_template: + inputs: + invalid_default: + type: integer + default: two + valid_default: + type: integer + default: 2 diff --git a/nfvparser/toscaparser/tests/data/test_invalid_section_names.yaml b/nfvparser/toscaparser/tests/data/test_invalid_section_names.yaml new file mode 100644 index 0000000..6241585 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_invalid_section_names.yaml @@ -0,0 +1,25 @@ +tosca_definitions_versions: tosca_simple_yaml_1_0 + +descriptions: > + TOSCA profile with invalid top-level section names. + +import: + - imported.yaml + +topology_templates: + + node_templates: + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: 1 + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 diff --git a/nfvparser/toscaparser/tests/data/test_invalid_template_version.yaml b/nfvparser/toscaparser/tests/data/test_invalid_template_version.yaml new file mode 100644 index 0000000..86dce79 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_invalid_template_version.yaml @@ -0,0 +1,14 @@ +tosca_definitions_version: tosca_xyz + +description: > + Test template with an invalid template version. + +topology_template: + node_templates: + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + num_cpus: 2 + diff --git a/nfvparser/toscaparser/tests/data/test_multiple_validation_errors.yaml b/nfvparser/toscaparser/tests/data/test_multiple_validation_errors.yaml new file mode 100644 index 0000000..479a1ec --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_multiple_validation_errors.yaml @@ -0,0 +1,128 @@ +tosca_definitions_version: tosca_simple_yaml_1 + +description: > + TOSCA simple profile with wordpress, web server and mysql on the same server. + +imports: + - custom_types/not_there.yaml + +topology_template: + inputs: + cpus: + type: integer + description: Number of CPUs for the server. + constraints: + - valid_values: [ 1, 2, 4, 8 ] + default: 1 + db_name: + type: string + description: The name of the database. + default: wordpress + db_user: + type: string + description: The user name of the DB user. + default: wp_user + db_pwd: + type: string + description: The WordPress database admin account password. + default: wp_pass + db_root_pwd: + type: string + description: Root password for MySQL. + db_port: + type: PortDef + description: Port for the MySQL database. + default: 3306 + + node_templates: + xyz: + type: tosca.nodes.XYZ + + wordpress: + type: tosca.nodes.WebApplication.WordPress + requirement: + - host: webserver + - database_endpoint: mysql_database + interfaces: + Standard: + create: wordpress/wordpress_install.sh + configure: + implementation: wordpress/wordpress_configure.sh + inputs: + wp_db_name: { get_property: [ mysql_database, name ] } + wp_db_user: { get_property: [ mysql_database, user ] } + wp_db_password: { get_property: [ mysql_database, password ] } + + mysql_database: + type: tosca.nodes.Database + properties: + name: { get_input: db_name } + user: { get_input: db_user } + password: { get_input: db_pwd } + capabilities: + database_endpoint: + properties: + port: { get_input: db_port } + requirements: + - host: mysql_dbms + interfaces: + Standard: + configure: + implementation: mysql/mysql_database_configure.sh + inputs: + db_name: { get_property: [ SELF, name ] } + db_user: { get_property: [ SELF, user ] } + db_password: { get_property: [ SELF, passwords ] } + db_root_password: { get_property: [ mysql_dbms, root_password ] } + + mysql_dbms: + type1: tosca.nodes.DBMS + properties: + root_password: { get_input: db_root_pwd } + port: { get_input: db_port } + requirements: + - host: server + interfaces: + Standard: + create: + implementation: mysql/mysql_dbms_install.sh + inputs: + db_root_password: { get_property: [ mysql_dbms, root_password ] } + start: mysql/mysql_dbms_start.sh + configure: + implementation: mysql/mysql_dbms_configure.sh + inputs: + db_port: { get_property: [ mysql_dbms, port ] } + + webserver: + type: tosca.nodes.WebServer + requirements: + - host: server1 + - database_endpoint: + node: webserver + relationship: + type1: tosca.relationships.ConnectsTo + interfaces: + Standard: + create: webserver/webserver_install.sh + start: webserver/webserver_start.sh + + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 + + outputs: + website_url: + description: URL for Wordpress wiki. + value: { get_attribute: [server, private_address] } diff --git a/nfvparser/toscaparser/tests/data/test_no_inputs_in_template.yaml b/nfvparser/toscaparser/tests/data/test_no_inputs_in_template.yaml new file mode 100644 index 0000000..0b9da4c --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_no_inputs_in_template.yaml @@ -0,0 +1,17 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Tosca template for testing a template with no inputs. + +metadata: test + +topology_template: + node_templates: + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + num_cpus: 2 + + outputs: diff --git a/nfvparser/toscaparser/tests/data/test_no_outputs_in_template.yaml b/nfvparser/toscaparser/tests/data/test_no_outputs_in_template.yaml new file mode 100644 index 0000000..51d42ff --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_no_outputs_in_template.yaml @@ -0,0 +1,15 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Tosca template for testing a template with no outputs. + +topology_template: + inputs: + + node_templates: + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + num_cpus: 2 diff --git a/nfvparser/toscaparser/tests/data/test_node_filter.yaml b/nfvparser/toscaparser/tests/data/test_node_filter.yaml new file mode 100644 index 0000000..3dd8e26 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_node_filter.yaml @@ -0,0 +1,18 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: Template with requirements against hosting infrastructure. + +topology_template: + + node_templates: + test: + type: tosca.nodes.DBMS + requirements: + - host: + node_filter: + capabilities: + - host: + properties: + - num_cpus: { in_range: [ 1, 4 ] } + - mem_size: { greater_or_equal: 2 GB } + diff --git a/nfvparser/toscaparser/tests/data/test_normative_type_properties_override.yaml b/nfvparser/toscaparser/tests/data/test_normative_type_properties_override.yaml new file mode 100644 index 0000000..3c3e272 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_normative_type_properties_override.yaml @@ -0,0 +1,37 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Test template for deploying a server with custom properties for image, + flavor and key_name. This template provides an example of how to + override TOSCA normative type's (e.g. Compute) properties. Here new + properties are injected in the tosca.nodes.myserver which derives from + tosca.nodes.Compute. Note that tosca.nodes.myserver can not be a name of + another normative type (e.g. tosca.nodes.WebServer or tosca.nodes.nfv.VDU) + because that will create conflict while resolving type definition by the + TOSCA Parser. + +node_types: + tosca.nodes.myserver: + derived_from: tosca.nodes.Compute + properties: + key_name: + type: string + image: + type: string + flavor: + type: string + +topology_template: + inputs: + key_name: + type: string + default: inputkey + + node_templates: + my_server: + type: tosca.nodes.myserver + properties: + flavor: m1.medium + image: rhel-6.5-test-image + key_name: + get_input: key_name diff --git a/nfvparser/toscaparser/tests/data/test_repositories_definition.yaml b/nfvparser/toscaparser/tests/data/test_repositories_definition.yaml new file mode 100644 index 0000000..c2856c8 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_repositories_definition.yaml @@ -0,0 +1,23 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +repositories: + some_repository: + description: Some repo + url: https://raw.githubusercontent.com/openstack/tosca-parser/master/toscaparser/tests/data/custom_types/ + credential: #type: Credential + token_type: basic_auth + token: myusername:mypassword +imports: + - some_import: + file: compute_with_prop.yaml + repository: some_repository + +description: > + TOSCA test for testing repositories definition + + node_templates: + + server: + type: tosca.nodes.ComputeWithProp + properties: + test: yes diff --git a/nfvparser/toscaparser/tests/data/test_requirements.yaml b/nfvparser/toscaparser/tests/data/test_requirements.yaml new file mode 100644 index 0000000..269c46d --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_requirements.yaml @@ -0,0 +1,67 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Test Requirements. + +imports: + - custom_types/wordpress.yaml + +topology_template: + node_templates: + my_app: + description: > + Specify multiple requirement via node and relationship keyword, + as an explicit relationship. Also demonstrates relationship with + type keyword and without it as an in-line reference. + type: tosca.nodes.WebApplication.WordPress + requirements: + - req1: + node: my_webserver + relationship: tosca.relationships.HostedOn + - req2: + node: mysql_database + relationship: + type: tosca.relationships.ConnectsTo + mysql_database: + description: Specify requirement via a capability as an implicit relationship. + type: tosca.nodes.Database + requirements: + - host: + node: my_dbms + relationship: tosca.relationships.HostedOn + my_dbms: + type: tosca.nodes.DBMS + my_webserver: + type: tosca.nodes.WebServer + my_server: + description: > + Specify requirement via a relationship template, as an explicit relationship. + type: tosca.nodes.Compute + capabilities: + host: + properties: + num_cpus: 2 + disk_size: 10 GB + mem_size: 4 MB + os: + properties: + # host Operating System image properties + architecture: x86_64 + type: linux + distribution: rhel + version: 6.5 + requirements: + - req1: + node: my_storage + relationship: storage_attachment + my_storage: + type: tosca.nodes.BlockStorage + properties: + size: 1 GiB + snapshot_id: id + + relationship_templates: + storage_attachment: + type: tosca.relationships.AttachesTo + properties: + location: /temp diff --git a/nfvparser/toscaparser/tests/data/test_tosca_custom_rel_with_script.yaml b/nfvparser/toscaparser/tests/data/test_tosca_custom_rel_with_script.yaml new file mode 100644 index 0000000..18a94a3 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_tosca_custom_rel_with_script.yaml @@ -0,0 +1,23 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: Test template of a custom relationship with a configure script + +topology_template: + + node_templates: + apache: + type: tosca.nodes.WebServer + requirements: + - host: + node: web_server + relationship: my_custom_rel + + web_server: + type: tosca.nodes.Compute + + relationship_templates: + my_custom_rel: + type: HostedOn + interfaces: + Configure: + pre_configure_source: scripts/wp_db_configure.sh diff --git a/nfvparser/toscaparser/tests/data/test_tosca_normative_type_by_shortname.yaml b/nfvparser/toscaparser/tests/data/test_tosca_normative_type_by_shortname.yaml new file mode 100644 index 0000000..c0653e7 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_tosca_normative_type_by_shortname.yaml @@ -0,0 +1,34 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with short type name for Compute. + +topology_template: + inputs: + cpus: + type: integer + description: Number of CPUs for the server. + constraints: + - valid_values: [ 1, 2, 4, 8 ] + default: 2 + + node_templates: + server: + type: Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Fedora + version: 18.0 + + outputs: + server_address: + description: IP address of server instance. + value: { get_attribute: [server, private_address] } diff --git a/nfvparser/toscaparser/tests/data/test_tosca_top_level_error1.yaml b/nfvparser/toscaparser/tests/data/test_tosca_top_level_error1.yaml new file mode 100644 index 0000000..d35c022 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_tosca_top_level_error1.yaml @@ -0,0 +1,2 @@ +description: > + TOSCA simple profile missing version section. \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/data/test_tosca_top_level_error2.yaml b/nfvparser/toscaparser/tests/data/test_tosca_top_level_error2.yaml new file mode 100644 index 0000000..b3e80f9 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/test_tosca_top_level_error2.yaml @@ -0,0 +1,11 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with invalid top-level key: 'node_template'. + +topology_template: + + node_template: + server: + type: tosca.nodes.Compute + diff --git a/nfvparser/toscaparser/tests/data/topology_template/databasesubsystem.yaml b/nfvparser/toscaparser/tests/data/topology_template/databasesubsystem.yaml new file mode 100644 index 0000000..b6e9c42 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/topology_template/databasesubsystem.yaml @@ -0,0 +1,81 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Database subsystem, which is service template with topology_template, + act as a nested system inside another system and also act as stand + alone service template. + +imports: + - definitions.yaml + +topology_template: + description: Template of a database including its hosting stack. + + inputs: + user: + type: string + description: the user name of database. + default: test + port: + type: integer + description: the port of database. + default: 3306 + name: + type: string + description: the name of database. + default: test + my_cpus: + type: integer + description: Number of CPUs for the server. + default: 2 + constraints: + - valid_values: [ 1, 2, 4, 8 ] + + substitution_mappings: + node_type: example.DatabaseSubsystem + capabilities: + database_endpoint: [ db_app, database_endpoint ] + + node_templates: + db_app: + type: tosca.nodes.Database + properties: + user: { get_input: user } + port: { get_input: port } + name: { get_input: name } + capabilities: + database_endpoint: + properties: + port: 1234 + requirements: + - host: + node: dbms + + dbms: + type: tosca.nodes.DBMS + properties: + port: 3306 + root_password: 123456789 + requirements: + - host: + node: server + + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: my_cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 + + groups: + dbserver_group: + members: [ dbms, server ] + type: tosca.groups.Root diff --git a/nfvparser/toscaparser/tests/data/topology_template/definitions.yaml b/nfvparser/toscaparser/tests/data/topology_template/definitions.yaml new file mode 100644 index 0000000..ba5eac1 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/topology_template/definitions.yaml @@ -0,0 +1,74 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +node_types: + example.QueuingSubsystem: + derived_from: tosca.nodes.SoftwareComponent + properties: + server_ip: + type: string + server_port: + type: integer + attributes: + server_ip: + type: string + server_port: + type: integer + requirements: + - receiver1: + node: example.TransactionSubsystem + capability: example.capabilities.Receiver + relationship: tosca.relationships.ConnectsTo + - receiver2: + node: example.TransactionSubsystem + capability: example.capabilities.Receiver + relationship: tosca.relationships.ConnectsTo + + example.TransactionSubsystem: + properties: + mq_server_ip: + type: string + required: False + receiver_port: + type: integer + required: False + attributes: + receiver_ip: + type: string + receiver_port: + type: integer + capabilities: + message_receiver: + type: example.capabilities.Receiver + requirements: + - database_endpoint: + node: tosca.nodes.Database + capability: tosca.capabilities.Endpoint.Database + relationship: tosca.relationships.ConnectsTo + + example.DatabaseSubsystem: + derived_from: tosca.nodes.Database + + example.SomeApp: + derived_from: tosca.nodes.SoftwareComponent + properties: + admin_user: + type: string + required: False + pool_size: + type: integer + required: False + capabilities: + message_receiver: + type: example.capabilities.Receiver + requirements: + - database: + node: tosca.nodes.Database + capability: tosca.capabilities.Endpoint.Database + relationship: tosca.relationships.ConnectsTo + +capability_types: + example.capabilities.Receiver: + derived_from: tosca.capabilities.Endpoint + properties: + server_ip: + type: string diff --git a/nfvparser/toscaparser/tests/data/topology_template/queuingsubsystem.yaml b/nfvparser/toscaparser/tests/data/topology_template/queuingsubsystem.yaml new file mode 100644 index 0000000..578aa4a --- /dev/null +++ b/nfvparser/toscaparser/tests/data/topology_template/queuingsubsystem.yaml @@ -0,0 +1,75 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Queue subsystem, which is service template with topology_template, + act as a nested system inside another system and also act as stand + alone service template. + +imports: + - definitions.yaml + +topology_template: + description: Template of a database including its hosting stack. + + inputs: + server_ip: + type: string + description: IP address of the message queuing server to receive messages from. + default: 127.0.0.1 + server_port: + type: integer + description: Port to be used for receiving messages. + default: 8080 + my_cpus: + type: integer + description: Number of CPUs for the server. + default: 2 + constraints: + - valid_values: [ 1, 2, 4, 8 ] + + substitution_mappings: + node_type: example.QueuingSubsystem + # capabilities: + # message_receiver: [ app, message_receiver ] + requirements: + receiver1: [ tran_app, receiver1 ] + receiver2: [ tran_app, receiver2 ] + + node_templates: + tran_app: + type: example.QueuingSubsystem + properties: + server_ip: { get_input: server_ip } + server_port: { get_input: server_port } + requirements: + - host: + node: server + + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: my_cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 + + outputs: + server_ip: + description: server_ip of the message receiver application + value: { get_input: server_ip } + + server_port: + description: server_port of the message receiver application + value: { get_input: server_port } + + groups: + tran_server_group: + members: [ tran_app, server ] + type: tosca.groups.Root diff --git a/nfvparser/toscaparser/tests/data/topology_template/system.yaml b/nfvparser/toscaparser/tests/data/topology_template/system.yaml new file mode 100644 index 0000000..f4e10ae --- /dev/null +++ b/nfvparser/toscaparser/tests/data/topology_template/system.yaml @@ -0,0 +1,62 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +imports: + - queuingsubsystem.yaml + - transactionsubsystem.yaml + - databasesubsystem.yaml + +topology_template: + description: Template of online transaction processing service. + + inputs: + mq_server_ip: + type: string + default: 127.0.0.1 + description: IP address of the message queuing server to receive messages from. + mq_server_port: + type: integer + default: 8080 + description: Port to be used for receiving messages. + + node_templates: + mq: + type: example.QueuingSubsystem + properties: + server_ip: { get_input: mq_server_ip } + server_port: { get_input: mq_server_port } + # capabilities: + # message_queue_endpoint: + # to be updated when substitution_mapping is validated later + requirements: + - receiver1: trans1 + - receiver2: trans2 + + trans1: + type: example.TransactionSubsystem + properties: + mq_server_ip: { get_attribute: [ mq, server_ip ] } + receiver_port: { get_attribute: [ mq, server_port ] } + # capabilities: + # message_receiver: + # to be updated when substitution_mapping is validated later + requirements: + - database_endpoint: dbsys + + trans2: + type: example.TransactionSubsystem + properties: + mq_server_ip: { get_attribute: [ mq, server_ip ] } + receiver_port: { get_attribute: [ mq, server_port ] } + # capabilities: + # message_receiver: + # to be updated when substitution_mapping is validated later + requirements: + - database_endpoint: dbsys + + dbsys: + type: example.DatabaseSubsystem + # properties: + # to be updated when substitution_mapping is validated later + # capabilities: + # database_endpoint: + # to be updated when substitution_mapping is validated later diff --git a/nfvparser/toscaparser/tests/data/topology_template/transactionsubsystem.yaml b/nfvparser/toscaparser/tests/data/topology_template/transactionsubsystem.yaml new file mode 100644 index 0000000..42e100a --- /dev/null +++ b/nfvparser/toscaparser/tests/data/topology_template/transactionsubsystem.yaml @@ -0,0 +1,88 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Transaction subsystem, which is service template with topology_template, + act as a nested system inside another system and also act as stand + alone service template. + +imports: + - definitions.yaml + +topology_template: + description: Template of a database including its hosting stack. + + inputs: + mq_server_ip: + type: string + description: IP address of the message queuing server to receive messages from. + default: 127.0.0.1 + receiver_port: + type: integer + description: Port to be used for receiving messages. + default: 8080 + my_cpus: + type: integer + description: Number of CPUs for the server. + default: 2 + constraints: + - valid_values: [ 1, 2, 4, 8 ] + + substitution_mappings: + node_type: example.TransactionSubsystem + capabilities: + message_receiver: [ app, message_receiver ] + requirements: + database_endpoint: [ app, database ] + + node_templates: + app: + type: example.SomeApp + properties: + admin_user: foo + pool_size: 10 + capabilities: + message_receiver: + properties: + server_ip: { get_input: mq_server_ip } + requirements: + - host: + node: websrv + + websrv: + type: tosca.nodes.WebServer + capabilities: + data_endpoint: + properties: + port_name: { get_input: receiver_port } + requirements: + - host: + node: server + + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: my_cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 + + outputs: + receiver_ip: + description: private IP address of the message receiver application + value: { get_attribute: [ server, private_address ] } + + receiver_port: + description: receiver_port of the message receiver application + value: { get_input: receiver_port } + + groups: + webserver_group: + members: [ websrv, server ] + type: tosca.groups.Root diff --git a/nfvparser/toscaparser/tests/data/topology_template/validate/queuingsubsystem_invalid_input.yaml b/nfvparser/toscaparser/tests/data/topology_template/validate/queuingsubsystem_invalid_input.yaml new file mode 100644 index 0000000..67ef341 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/topology_template/validate/queuingsubsystem_invalid_input.yaml @@ -0,0 +1,76 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + This template is a test template which contains invalid input needed for substitution mappings. + The required properties without default value in substituted node template which be mapped must be + as inputs of nested service template which defines substutition mappings, and the inputs of nested + service template which are not in the properties of the substituted node template must provide + default values. + This template provides an additional input of server_port1/my_cpus/my_input which are not defined + in example.QueuingSubsystem, and the default value are 8080/2/123, all of these are right. But the + required property of server_port defined in example.QueuingSubsystem is not appeared in inputs + definiton, so will raise excepton of "MissingRequiredInputError". + +imports: + - ../definitions.yaml + +topology_template: + description: Template of a database including its hosting stack. + + inputs: + server_ip: + type: string + description: IP address of the message queuing server to receive messages from. + default: 127.0.0.1 + server_port1: + type: integer + description: Port to be used for receiving messages. + default: 8080 + my_cpus: + type: integer + description: Number of CPUs for the server. + default: 2 + constraints: + - valid_values: [ 1, 2, 4, 8 ] + my_input: + type: integer + description: test for input validation. + default: 123 + + substitution_mappings: + node_type: example.QueuingSubsystem + + node_templates: + tran_app: + type: example.QueuingSubsystem + properties: + server_ip: { get_input: server_ip } + server_port: { get_input: server_port1 } + requirements: + - host: + node: server + + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: my_cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 + + outputs: + receiver_ip: + description: private IP address of the message receiver application + value: { get_attribute: [ server, private_address ] } + + groups: + tran_server_group: + members: [ tran_app, server ] + type: tosca.groups.Root diff --git a/nfvparser/toscaparser/tests/data/topology_template/validate/system_invalid_input.yaml b/nfvparser/toscaparser/tests/data/topology_template/validate/system_invalid_input.yaml new file mode 100644 index 0000000..e3cdd71 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/topology_template/validate/system_invalid_input.yaml @@ -0,0 +1,24 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +imports: + - queuingsubsystem_invalid_input.yaml + +topology_template: + description: Test template with invalid input. + + inputs: + mq_server_ip: + type: string + default: 127.0.0.1 + description: IP address of the message queuing server to receive messages from. + mq_server_port: + type: integer + default: 8080 + description: Port to be used for receiving messages. + + node_templates: + mq: + type: example.QueuingSubsystem + properties: + server_ip: { get_input: mq_server_ip } + server_port: { get_input: mq_server_port } diff --git a/nfvparser/toscaparser/tests/data/topology_template/validate/system_invalid_missing_output.yaml b/nfvparser/toscaparser/tests/data/topology_template/validate/system_invalid_missing_output.yaml new file mode 100644 index 0000000..2028c38 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/topology_template/validate/system_invalid_missing_output.yaml @@ -0,0 +1,24 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +imports: + - transactionsubsystem_invalid_missing_output.yaml + +topology_template: + description: Test template with invalid missing output. + + inputs: + mq_server_ip: + type: string + default: 127.0.0.1 + description: IP address of the message queuing server to receive messages from. + mq_server_port: + type: integer + default: 8080 + description: Port to be used for receiving messages. + + node_templates: + trans: + type: example.TransactionSubsystem + properties: + mq_server_ip: { get_input: mq_server_ip } + receiver_port: { get_input: mq_server_port } diff --git a/nfvparser/toscaparser/tests/data/topology_template/validate/system_invalid_unknown_output.yaml b/nfvparser/toscaparser/tests/data/topology_template/validate/system_invalid_unknown_output.yaml new file mode 100644 index 0000000..de16ca2 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/topology_template/validate/system_invalid_unknown_output.yaml @@ -0,0 +1,24 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +imports: + - transactionsubsystem_invalid_unknown_output.yaml + +topology_template: + description: Test template with invalid unknown output. + + inputs: + mq_server_ip: + type: string + default: 127.0.0.1 + description: IP address of the message queuing server to receive messages from. + mq_server_port: + type: integer + default: 8080 + description: Port to be used for receiving messages. + + node_templates: + trans: + type: example.TransactionSubsystem + properties: + mq_server_ip: { get_input: mq_server_ip } + receiver_port: { get_input: mq_server_port } diff --git a/nfvparser/toscaparser/tests/data/topology_template/validate/test_example_app_substitution_mappings.yaml b/nfvparser/toscaparser/tests/data/topology_template/validate/test_example_app_substitution_mappings.yaml new file mode 100644 index 0000000..718022a --- /dev/null +++ b/nfvparser/toscaparser/tests/data/topology_template/validate/test_example_app_substitution_mappings.yaml @@ -0,0 +1,70 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Template showing an example TOSCA type to demonstrate usage + of output in the substitution mappings. + +node_types: + example.app: + derived_from: tosca.nodes.WebApplication + properties: + mq_server_ip: + type: string + required: False + receiver_port: + type: integer + required: False + attributes: + receiver_ip: + type: string + receiver_port: + type: integer + +topology_template: + inputs: + mq_server_ip: + type: string + description: IP address of the message queuing server to receive messages from. + default: 127.0.0.1 + receiver_port: + type: integer + description: Port to be used for receiving messages. + default: 8080 + my_cpus: + type: integer + description: Number of CPUs for the server. + default: 2 + constraints: + - valid_values: [ 1, 2, 4, 8 ] + + substitution_mappings: + node_type: example.app + + node_templates: + app: + type: example.app + properties: + mq_server_ip: { get_input: mq_server_ip } + receiver_port: { get_input: receiver_port } + requirements: + - host: + node: websrv + websrv: + type: tosca.nodes.WebServer + requirements: + - host: + node: server + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: my_cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 diff --git a/nfvparser/toscaparser/tests/data/topology_template/validate/test_substitution_mappings_invalid_output.yaml b/nfvparser/toscaparser/tests/data/topology_template/validate/test_substitution_mappings_invalid_output.yaml new file mode 100644 index 0000000..ef21811 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/topology_template/validate/test_substitution_mappings_invalid_output.yaml @@ -0,0 +1,31 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +imports: + - test_example_app_substitution_mappings.yaml + +topology_template: + description: > + Test template showing valid output section containing attribute defined + in the substitution mappings in the imported yaml file. + + inputs: + mq_server_ip: + type: string + default: 127.0.0.1 + description: IP address of the message queuing server to receive messages from. + mq_server_port: + type: integer + default: 8080 + description: Port to be used for receiving messages. + + node_templates: + substitute_app: + type: example.app + properties: + mq_server_ip: { get_input: mq_server_ip } + receiver_port: { get_input: mq_server_port } + + outputs: + receiver_ip: + description: private IP address of the message receiver application + value: { get_attribute: [ substitute_app, my_cpu_output ] } \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/data/topology_template/validate/test_substitution_mappings_valid_output.yaml b/nfvparser/toscaparser/tests/data/topology_template/validate/test_substitution_mappings_valid_output.yaml new file mode 100644 index 0000000..766ca87 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/topology_template/validate/test_substitution_mappings_valid_output.yaml @@ -0,0 +1,31 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +imports: + - test_example_app_substitution_mappings.yaml + +topology_template: + description: > + Test template showing valid output section containing attribute defined + in the substitution mappings in the imported yaml file. + + inputs: + mq_server_ip: + type: string + default: 127.0.0.1 + description: IP address of the message queuing server to receive messages from. + mq_server_port: + type: integer + default: 8080 + description: Port to be used for receiving messages. + + node_templates: + sustitute_app: + type: example.app + properties: + mq_server_ip: { get_input: mq_server_ip } + receiver_port: { get_input: mq_server_port } + + outputs: + receiver_ip: + description: private IP address of the message receiver application + value: { get_attribute: [ sustitute_app, receiver_ip ] } \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/data/topology_template/validate/transactionsubsystem_invalid_missing_output.yaml b/nfvparser/toscaparser/tests/data/topology_template/validate/transactionsubsystem_invalid_missing_output.yaml new file mode 100644 index 0000000..c92e5f8 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/topology_template/validate/transactionsubsystem_invalid_missing_output.yaml @@ -0,0 +1,92 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + This template is a test template which contains invalid output + needed for substitution mappings. + The outputs defined by the topology template have to match the + attributes of the node type or the substituted node template, + and the observable attributes of the substituted node template + have to be defined as attributes of the node type or outputs in + the topology template. + But this template misses output of receiver_port which is not + defined in node type of example.TransactionSubsystem, so it will + be validated error for substitution mappings. + +imports: + - ../definitions.yaml + +topology_template: + description: Template of a database including its hosting stack. + + inputs: + mq_server_ip: + type: string + description: IP address of the message queuing server to receive messages from. + default: 127.0.0.1 + receiver_port: + type: integer + description: Port to be used for receiving messages. + default: 8080 + my_cpus: + type: integer + description: Number of CPUs for the server. + default: 2 + constraints: + - valid_values: [ 1, 2, 4, 8 ] + + substitution_mappings: + node_type: example.TransactionSubsystem + capabilities: + message_receiver: [ app, message_receiver ] + requirements: + database_endpoint: [ app, database ] + + node_templates: + app: + type: example.SomeApp + properties: + admin_user: foo + pool_size: 10 + capabilities: + message_receiver: + properties: + server_ip: { get_input: mq_server_ip } + requirements: + - host: + node: websrv + + websrv: + type: tosca.nodes.WebServer + capabilities: + data_endpoint: + properties: + port_name: { get_input: receiver_port } + requirements: + - host: + node: server + + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: my_cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 + + outputs: + receiver_ip: + description: private IP address of the message receiver application + value: { get_attribute: [ server, private_address ] } + + # This output is invalid if comment receiver_out out only for + # substituion mappings +# receiver_port: +# description: receiver_port of the message receiver application +# value: { get_input: receiver_port } diff --git a/nfvparser/toscaparser/tests/data/topology_template/validate/transactionsubsystem_invalid_unknown_output.yaml b/nfvparser/toscaparser/tests/data/topology_template/validate/transactionsubsystem_invalid_unknown_output.yaml new file mode 100644 index 0000000..ffca24b --- /dev/null +++ b/nfvparser/toscaparser/tests/data/topology_template/validate/transactionsubsystem_invalid_unknown_output.yaml @@ -0,0 +1,94 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + This template is a test template which contains invalid output + needed for substitution mappings. + The outputs defined by the topology template have to match the + attributes of the node type or the substituted node template, + and the observable attributes of the substituted node template + have to be defined as attributes of the node type or outputs in + the topology template. + But this template contains output of my_cpu_output which is not + defined in node type of example.TransactionSubsystem, so it will + be validated error for substitution mappings. + +imports: + - ../definitions.yaml + +topology_template: + description: Template of a database including its hosting stack. + + inputs: + mq_server_ip: + type: string + description: IP address of the message queuing server to receive messages from. + default: 127.0.0.1 + receiver_port: + type: integer + description: Port to be used for receiving messages. + default: 8080 + my_cpus: + type: integer + description: Number of CPUs for the server. + default: 2 + constraints: + - valid_values: [ 1, 2, 4, 8 ] + + substitution_mappings: + node_type: example.TransactionSubsystem + capabilities: + message_receiver: [ app, message_receiver ] + requirements: + database_endpoint: [ app, database ] + + node_templates: + app: + type: example.SomeApp + properties: + admin_user: foo + pool_size: 10 + capabilities: + message_receiver: + properties: + server_ip: { get_input: mq_server_ip } + requirements: + - host: + node: websrv + + websrv: + type: tosca.nodes.WebServer + capabilities: + data_endpoint: + properties: + port_name: { get_input: receiver_port } + requirements: + - host: + node: server + + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: my_cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 + + outputs: + receiver_ip: + description: private IP address of the message receiver application + value: { get_attribute: [ server, private_address ] } + + receiver_port: + description: receiver_port of the message receiver application + value: { get_input: receiver_port } + + my_cpu_output: + description: this output is only invalid for substitution mappings + value: { get_input: my_cpus } diff --git a/nfvparser/toscaparser/tests/data/tosca_elk.yaml b/nfvparser/toscaparser/tests/data/tosca_elk.yaml new file mode 100644 index 0000000..6fc1756 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/tosca_elk.yaml @@ -0,0 +1,217 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + This TOSCA simple profile deploys nodejs, mongodb, elasticsearch, logstash + and kibana each on a separate server with monitoring enabled for nodejs + server where a sample nodejs application is running. The rsyslog and collectd + are installed on a nodejs server. + +imports: + - custom_types/paypalpizzastore_nodejs_app.yaml + - custom_types/elasticsearch.yaml + - custom_types/logstash.yaml + - custom_types/kibana.yaml + - custom_types/collectd.yaml + - custom_types/rsyslog.yaml + +dsl_definitions: + host_capabilities: &host_capabilities + disk_size: 10 GB + num_cpus: { get_input: my_cpus } + mem_size: 4096 MB + os_capabilities: &os_capabilities + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 + +topology_template: + inputs: + my_cpus: + type: integer + description: Number of CPUs for the server. + constraints: + - valid_values: [ 1, 2, 4, 8 ] + default: 1 + github_url: + type: string + description: The URL to download nodejs. + default: http://github.com/paypal/rest-api-sample-app-nodejs.git + + node_templates: + paypal_pizzastore: + type: tosca.nodes.WebApplication.PayPalPizzaStore + properties: + github_url: { get_input: github_url } + requirements: + - host: nodejs + - database_connection: mongo_db + interfaces: + Standard: + configure: + implementation: nodejs/config.sh + inputs: + github_url: { get_property: [ SELF, github_url ] } + mongodb_ip: { get_attribute: [mongo_server, private_address] } + start: nodejs/start.sh + nodejs: + type: tosca.nodes.WebServer + requirements: + - host: app_server + interfaces: + Standard: + create: nodejs/create.sh + mongo_db: + type: tosca.nodes.Database + requirements: + - host: mongo_dbms + interfaces: + Standard: + create: mongodb/create_database.sh + mongo_dbms: + type: tosca.nodes.DBMS + requirements: + - host: mongo_server + interfaces: + Standard: + create: mongodb/create.sh + configure: + implementation: mongodb/config.sh + inputs: + mongodb_ip: { get_attribute: [mongo_server, private_address] } + start: mongodb/start.sh + elasticsearch: + type: tosca.nodes.SoftwareComponent.Elasticsearch + requirements: + - host: elasticsearch_server + interfaces: + Standard: + create: elasticsearch/create.sh + start: elasticsearch/start.sh + logstash: + type: tosca.nodes.SoftwareComponent.Logstash + requirements: + - host: logstash_server + - search_endpoint: + node: elasticsearch + capability: search_endpoint + relationship: + type: tosca.relationships.ConnectsTo + interfaces: + Configure: + pre_configure_source: + implementation: logstash/configure_elasticsearch.py + inputs: + elasticsearch_ip: { get_attribute: [elasticsearch_server, private_address] } + interfaces: + Standard: + create: logstash/create.sh + start: logstash/start.sh + kibana: + type: tosca.nodes.SoftwareComponent.Kibana + requirements: + - host: kibana_server + - search_endpoint: elasticsearch + interfaces: + Standard: + create: kibana/create.sh + configure: + implementation: kibana/config.sh + inputs: + elasticsearch_ip: { get_attribute: [elasticsearch_server, private_address] } + kibana_ip: { get_attribute: [kibana_server, private_address] } + start: kibana/start.sh + app_collectd: + type: tosca.nodes.SoftwareComponent.Collectd + requirements: + - host: app_server + - log_endpoint: + node: logstash + capability: log_endpoint + relationship: + type: tosca.relationships.ConnectsTo + interfaces: + Configure: + pre_configure_target: + implementation: logstash/configure_collectd.py + interfaces: + Standard: + create: collectd/create.sh + configure: + implementation: collectd/config.py + inputs: + logstash_ip: { get_attribute: [logstash_server, private_address] } + start: collectd/start.sh + app_rsyslog: + type: tosca.nodes.SoftwareComponent.Rsyslog + requirements: + - host: app_server + - log_endpoint: + node: logstash + capability: log_endpoint + relationship: + type: tosca.relationships.ConnectsTo + interfaces: + Configure: + pre_configure_target: + implementation: logstash/configure_rsyslog.py + interfaces: + Standard: + create: rsyslog/create.sh + configure: + implementation: rsyslog/config.sh + inputs: + logstash_ip: { get_attribute: [logstash_server, private_address] } + start: rsyslog/start.sh + app_server: + type: tosca.nodes.Compute + capabilities: + host: + properties: *host_capabilities + os: + properties: *os_capabilities + mongo_server: + type: tosca.nodes.Compute + capabilities: + host: + properties: *host_capabilities + os: + properties: *os_capabilities + elasticsearch_server: + type: tosca.nodes.Compute + capabilities: + host: + properties: *host_capabilities + os: + properties: *os_capabilities + logstash_server: + type: tosca.nodes.Compute + capabilities: + host: + properties: *host_capabilities + os: + properties: *os_capabilities + kibana_server: + type: tosca.nodes.Compute + capabilities: + host: + properties: *host_capabilities + os: + properties: *os_capabilities + + outputs: + nodejs_url: + description: URL for the nodejs server, http://:3000 + value: { get_attribute: [ app_server, private_address ] } + mongodb_url: + description: URL for the mongodb server. + value: { get_attribute: [ mongo_server, private_address ] } + elasticsearch_url: + description: URL for the elasticsearch server. + value: { get_attribute: [ elasticsearch_server, private_address ] } + logstash_url: + description: URL for the logstash server. + value: { get_attribute: [ logstash_server, private_address ] } + kibana_url: + description: URL for the kibana server. + value: { get_attribute: [ kibana_server, private_address ] } diff --git a/nfvparser/toscaparser/tests/data/tosca_helloworld.yaml b/nfvparser/toscaparser/tests/data/tosca_helloworld.yaml new file mode 100644 index 0000000..5b913ff --- /dev/null +++ b/nfvparser/toscaparser/tests/data/tosca_helloworld.yaml @@ -0,0 +1,23 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +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/data/tosca_imports_validation.yaml b/nfvparser/toscaparser/tests/data/tosca_imports_validation.yaml new file mode 100644 index 0000000..257beb8 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/tosca_imports_validation.yaml @@ -0,0 +1,45 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: Template to test invalid imports. + +imports: + - custom_types/imported_sample.yaml + +topology_template: + node_templates: + logstash: + type: tosca.nodes.SoftwareComponent.Logstash + requirements: + - search_endpoint: + capability: search_endpoint + relationship: + type: tosca.relationships.ConnectsTo + interfaces: + Configure: + pre_configure_source: + implementation: logstash/configure_elasticsearch.py + inputs: + elasticsearch_ip: { get_attribute: [elasticsearch_server, private_address] } + interfaces: + Standard: + create: logstash/create.sh + start: logstash/start.sh + policies: + - my_compute_placement_policy: + type: tosca.policies.Placement + description: Apply placement policy to servers + metadata: { user1: 1001, user2: 1002 } + targets: [ my_server_1, my_server_2 ] + - my_groups_placement: + type: mycompany.mytypes.myScalingPolicy + targets: [ webserver_group ] + description: my company scaling policy + metadata: + user1: 1001 + user2: 1003 + relationship_templates: + my_custom_rel: + type: test.relation.connects + interfaces: + Configure: + pre_configure_source: scripts/wp_db_configure.sh diff --git a/nfvparser/toscaparser/tests/data/tosca_load_balancer.yaml b/nfvparser/toscaparser/tests/data/tosca_load_balancer.yaml new file mode 100644 index 0000000..2fcdb48 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/tosca_load_balancer.yaml @@ -0,0 +1,75 @@ +# Note: this could eventually be translated to a Neutron Load Balancer +# However, in Heat/HOT the preferred way of doing this is creating an Autoscale Group +# +#heat_template_version: 2015-04-30 ... +#resources: +#load_bal_resource: +# type: OS::Neutron::Pool +# properties: +# admin_state_up: Boolean +# description: String +# lb_method: String +# monitors: [Value, Value, ...] +# name: String +# protocol: String +# provider: String +# subnet: String +# vip: { +# "description": String, +# "name": String, +# "connection_limit": Integer, +# "protocol_port": Integer, +# "subnet": String, +# "address": String, +# "admin_state_up": Boolean, +# "session_persistence": +# { +# "cookie_name": String, +# "type": String} +# } +# +# example from: https://gist.github.com/therve/9231701 +# +#resources: +# web_server_group: +# type: AWS::AutoScaling::AutoScalingGroup +# properties: +# AvailabilityZones: [nova] +# LaunchConfigurationName: {get_resource: launch_config} +# MinSize: 1 +# MaxSize: 3 +# LoadBalancerNames: +# - {get_resource: mylb} +# mypool: +# type: OS::Neutron::Pool +# properties: +# protocol: HTTP +# monitors: [{get_resource: mymonitor}] +# subnet_id: {get_param: subnet_id} +# lb_method: ROUND_ROBIN +# vip: +# protocol_port: 80 +# mylb: +# type: OS::Neutron::LoadBalancer +# properties: +# protocol_port: 80 +# pool_id: {get_resource: mypool} + +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: Template for deploying a load balancer with predefined endpoint properties. + +topology_template: + node_templates: + simple_load_balancer: + type: tosca.nodes.LoadBalancer + capabilities: + # properties: + # algorithm: DEFAULT (define new keyword, ROUND_ROBIN?) + # Client, public facing endpoint + client: + properties: + network_name: PUBLIC + floating: true + dns_name: http://mycompany.com/ + diff --git a/nfvparser/toscaparser/tests/data/tosca_repositories_test_definition.yaml b/nfvparser/toscaparser/tests/data/tosca_repositories_test_definition.yaml new file mode 100644 index 0000000..0001d06 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/tosca_repositories_test_definition.yaml @@ -0,0 +1,26 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: TOSCA simple profile with repositories validation and imports. + +repositories: + repo_code0: https://raw.githubusercontent.com/nandinivemula/intern + repo_code1: + description: My project's code Repository in github usercontent. + url: https://raw.githubusercontent.com/nandinivemula/intern/master + credential: #type: Credential + token_type: basic_auth + token: myusername:mypassword + + repo_code2: + description: My Project's code Repository in github. + url: https://github.com/nandinivemula/intern/master + credential: #type: Credential + token_type: basic_auth + token: myusername:mypassword + +imports: + - sample_import: + file: tosca_repository_import.yaml + repository: repo_code1 + namespace_uri: https://github.com/nandinivemula/intern + namespace_prefix: intern diff --git a/nfvparser/toscaparser/tests/data/tosca_single_instance_wordpress.yaml b/nfvparser/toscaparser/tests/data/tosca_single_instance_wordpress.yaml new file mode 100644 index 0000000..9e686ab --- /dev/null +++ b/nfvparser/toscaparser/tests/data/tosca_single_instance_wordpress.yaml @@ -0,0 +1,121 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with wordpress, web server and mysql on the same server. + +imports: + - custom_types/wordpress.yaml + +topology_template: + inputs: + cpus: + type: integer + description: Number of CPUs for the server. + constraints: + - valid_values: [ 1, 2, 4, 8 ] + default: 1 + db_name: + type: string + description: The name of the database. + default: wordpress + db_user: + type: string + description: The user name of the DB user. + default: wp_user + db_pwd: + type: string + description: The WordPress database admin account password. + default: wp_pass + db_root_pwd: + type: string + description: Root password for MySQL. + db_port: + type: PortDef + description: Port for the MySQL database. + default: 3306 + + node_templates: + wordpress: + type: tosca.nodes.WebApplication.WordPress + requirements: + - host: webserver + - database_endpoint: mysql_database + interfaces: + Standard: + create: wordpress/wordpress_install.sh + configure: + implementation: wordpress/wordpress_configure.sh + inputs: + wp_db_name: { get_property: [ mysql_database, name ] } + wp_db_user: { get_property: [ mysql_database, user ] } + wp_db_password: { get_property: [ mysql_database, password ] } + + mysql_database: + type: tosca.nodes.Database + properties: + name: { get_input: db_name } + user: { get_input: db_user } + password: { get_input: db_pwd } + capabilities: + database_endpoint: + properties: + port: { get_input: db_port } + requirements: + - host: mysql_dbms + interfaces: + Standard: + configure: + implementation: mysql/mysql_database_configure.sh + inputs: + db_name: { get_property: [ SELF, name ] } + db_user: { get_property: [ SELF, user ] } + db_password: { get_property: [ SELF, password ] } + db_root_password: { get_property: [ mysql_dbms, root_password ] } + + mysql_dbms: + type: tosca.nodes.DBMS + properties: + root_password: { get_input: db_root_pwd } + port: { get_input: db_port } + requirements: + - host: server + interfaces: + Standard: + create: + implementation: mysql/mysql_dbms_install.sh + inputs: + db_root_password: { get_property: [ mysql_dbms, root_password ] } + start: mysql/mysql_dbms_start.sh + configure: + implementation: mysql/mysql_dbms_configure.sh + inputs: + db_port: { get_property: [ mysql_dbms, port ] } + + webserver: + type: tosca.nodes.WebServer + requirements: + - host: server + interfaces: + Standard: + create: webserver/webserver_install.sh + start: webserver/webserver_start.sh + + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 + + outputs: + website_url: + description: URL for Wordpress wiki. + value: { get_attribute: [server, private_address] } diff --git a/nfvparser/toscaparser/tests/data/tosca_single_instance_wordpress_with_local_abspath_import.yaml b/nfvparser/toscaparser/tests/data/tosca_single_instance_wordpress_with_local_abspath_import.yaml new file mode 100644 index 0000000..6caac11 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/tosca_single_instance_wordpress_with_local_abspath_import.yaml @@ -0,0 +1,122 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with wordpress, web server and mysql on the same server. + Parsing of this test template will fail with errors if provided imports does + not refer to a valid absolute path. + +imports: + - /tmp/tosca-parser/toscaparser/tests/data/custom_types/wordpress.yaml + +topology_template: + inputs: + cpus: + type: integer + description: Number of CPUs for the server. + constraints: + - valid_values: [ 1, 2, 4, 8 ] + default: 1 + db_name: + type: string + description: The name of the database. + default: wordpress + db_user: + type: string + description: The user name of the DB user. + default: wp_user + db_pwd: + type: string + description: The WordPress database admin account password. + default: wp_pass + db_root_pwd: + type: string + description: Root password for MySQL. + db_port: + type: PortDef + description: Port for the MySQL database. + default: 3306 + + node_templates: + wordpress: + type: tosca.nodes.WebApplication.WordPress + requirements: + - host: webserver + - database_endpoint: mysql_database + interfaces: + Standard: + create: wordpress/wordpress_install.sh + configure: + implementation: wordpress/wordpress_configure.sh + inputs: + wp_db_name: wordpress + wp_db_user: wp_user + wp_db_password: wp_pass + + mysql_database: + type: tosca.nodes.Database + properties: + name: { get_input: db_name } + user: { get_input: db_user } + password: { get_input: db_pwd } + capabilities: + database_endpoint: + properties: + port: { get_input: db_port } + requirements: + - host: + node: mysql_dbms + interfaces: + Standard: + configure: + implementation: mysql/mysql_database_configure.sh + inputs: + db_name: wordpress + db_user: wp_user + db_password: wp_pass + db_root_password: passw0rd + mysql_dbms: + type: tosca.nodes.DBMS + properties: + root_password: { get_input: db_root_pwd } + port: { get_input: db_port } + requirements: + - host: server + interfaces: + Standard: + create: + implementation: mysql/mysql_dbms_install.sh + inputs: + db_root_password: passw0rd + start: mysql/mysql_dbms_start.sh + configure: + implementation: mysql/mysql_dbms_configure.sh + inputs: + db_port: 3366 + + webserver: + type: tosca.nodes.WebServer + requirements: + - host: server + interfaces: + Standard: + create: webserver/webserver_install.sh + start: webserver/webserver_start.sh + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 + + outputs: + website_url: + description: URL for Wordpress wiki. + value: { get_attribute: [server, private_address] } diff --git a/nfvparser/toscaparser/tests/data/tosca_single_instance_wordpress_with_url_import.yaml b/nfvparser/toscaparser/tests/data/tosca_single_instance_wordpress_with_url_import.yaml new file mode 100644 index 0000000..e5f1580 --- /dev/null +++ b/nfvparser/toscaparser/tests/data/tosca_single_instance_wordpress_with_url_import.yaml @@ -0,0 +1,120 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with wordpress, web server and mysql on the same server. + +imports: + - https://raw.githubusercontent.com/openstack/heat-translator/master/translator/tests/data/custom_types/wordpress.yaml + +topology_template: + inputs: + cpus: + type: integer + description: Number of CPUs for the server. + constraints: + - valid_values: [ 1, 2, 4, 8 ] + default: 1 + db_name: + type: string + description: The name of the database. + default: wordpress + db_user: + type: string + description: The user name of the DB user. + default: wp_user + db_pwd: + type: string + description: The WordPress database admin account password. + default: wp_pass + db_root_pwd: + type: string + description: Root password for MySQL. + db_port: + type: PortDef + description: Port for the MySQL database. + default: 3306 + + node_templates: + wordpress: + type: tosca.nodes.WebApplication.WordPress + requirements: + - host: webserver + - database_endpoint: mysql_database + interfaces: + Standard: + create: wordpress/wordpress_install.sh + configure: + implementation: wordpress/wordpress_configure.sh + inputs: + wp_db_name: wordpress + wp_db_user: wp_user + wp_db_password: wp_pass + + mysql_database: + type: tosca.nodes.Database + properties: + name: { get_input: db_name } + user: { get_input: db_user } + password: { get_input: db_pwd } + capabilities: + database_endpoint: + properties: + port: { get_input: db_port } + requirements: + - host: + node: mysql_dbms + interfaces: + Standard: + configure: + implementation: mysql/mysql_database_configure.sh + inputs: + db_name: wordpress + db_user: wp_user + db_password: wp_pass + db_root_password: passw0rd + mysql_dbms: + type: tosca.nodes.DBMS + properties: + root_password: { get_input: db_root_pwd } + port: { get_input: db_port } + requirements: + - host: server + interfaces: + Standard: + create: + implementation: mysql/mysql_dbms_install.sh + inputs: + db_root_password: passw0rd + start: mysql/mysql_dbms_start.sh + configure: + implementation: mysql/mysql_dbms_configure.sh + inputs: + db_port: 3366 + + webserver: + type: tosca.nodes.WebServer + requirements: + - host: server + interfaces: + Standard: + create: webserver/webserver_install.sh + start: webserver/webserver_start.sh + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 + + outputs: + website_url: + description: URL for Wordpress wiki. + value: { get_attribute: [server, private_address] } diff --git a/nfvparser/toscaparser/tests/data/tosca_test_get_operation_output.yaml b/nfvparser/toscaparser/tests/data/tosca_test_get_operation_output.yaml new file mode 100644 index 0000000..f47f33c --- /dev/null +++ b/nfvparser/toscaparser/tests/data/tosca_test_get_operation_output.yaml @@ -0,0 +1,19 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: TOSCA simple profile to test the GET OPERATION OUTPUT functionality + +imports: + - custom_types/compute_with_prop.yaml + +topology_template: + + node_templates: + + front_end: + type: tosca.nodes.ComputeWithProp + interfaces: + Standard: + create: + implementation: nodejs/create.sh + inputs: + data_dir: {get_operation_output: [front_end,Standard,create,data_dir]} diff --git a/nfvparser/toscaparser/tests/spec_samples/v1.0/network/tosca_one_server_one_network.yaml b/nfvparser/toscaparser/tests/spec_samples/v1.0/network/tosca_one_server_one_network.yaml new file mode 100644 index 0000000..8e58fa9 --- /dev/null +++ b/nfvparser/toscaparser/tests/spec_samples/v1.0/network/tosca_one_server_one_network.yaml @@ -0,0 +1,43 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with 1 server bound to a new network + +topology_template: + + inputs: + network_name: + type: string + description: Network name + + node_templates: + my_server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: 1 + mem_size: 512 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: CirrOS + version: 0.3.2 + + my_network: + type: tosca.nodes.network.Network + properties: + network_name: { get_input: network_name } + ip_version: 4 + cidr: '192.168.0.0/24' + start_ip: '192.168.0.50' + end_ip: '192.168.0.200' + gateway_ip: '192.168.0.1' + + my_port: + type: tosca.nodes.network.Port + requirements: + - binding: my_server + - link: my_network diff --git a/nfvparser/toscaparser/tests/spec_samples/v1.0/network/tosca_one_server_three_networks.yaml b/nfvparser/toscaparser/tests/spec_samples/v1.0/network/tosca_one_server_three_networks.yaml new file mode 100644 index 0000000..d791b17 --- /dev/null +++ b/nfvparser/toscaparser/tests/spec_samples/v1.0/network/tosca_one_server_three_networks.yaml @@ -0,0 +1,64 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with 1 server bound to 3 networks + +topology_template: + + node_templates: + my_server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: 1 + mem_size: 512 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: CirrOS + version: 0.3.2 + + my_network1: + type: tosca.nodes.network.Network + properties: + cidr: '192.168.1.0/24' + network_name: net1 + + my_network2: + type: tosca.nodes.network.Network + properties: + cidr: '192.168.2.0/24' + network_name: net2 + + my_network3: + type: tosca.nodes.network.Network + properties: + cidr: '192.168.3.0/24' + network_name: net3 + + my_port1: + type: tosca.nodes.network.Port + properties: + order: 0 + requirements: + - binding: my_server + - link: my_network1 + + my_port2: + type: tosca.nodes.network.Port + properties: + order: 1 + requirements: + - binding: my_server + - link: my_network2 + + my_port3: + type: tosca.nodes.network.Port + properties: + order: 2 + requirements: + - binding: my_server + - link: my_network3 diff --git a/nfvparser/toscaparser/tests/spec_samples/v1.0/network/tosca_server_on_existing_network.yaml b/nfvparser/toscaparser/tests/spec_samples/v1.0/network/tosca_server_on_existing_network.yaml new file mode 100644 index 0000000..7fedc13 --- /dev/null +++ b/nfvparser/toscaparser/tests/spec_samples/v1.0/network/tosca_server_on_existing_network.yaml @@ -0,0 +1,39 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with 1 server bound to an existing network + +topology_template: + inputs: + network_name: + type: string + description: Network name + + node_templates: + my_server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: 1 + mem_size: 512 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: CirrOS + version: 0.3.2 + + my_network: + type: tosca.nodes.network.Network + properties: + network_name: { get_input: network_name } + + my_port: + type: tosca.nodes.network.Port + requirements: + - binding: + node: my_server + - link: + node: my_network diff --git a/nfvparser/toscaparser/tests/spec_samples/v1.0/network/tosca_two_servers_one_network.yaml b/nfvparser/toscaparser/tests/spec_samples/v1.0/network/tosca_two_servers_one_network.yaml new file mode 100644 index 0000000..1473a8d --- /dev/null +++ b/nfvparser/toscaparser/tests/spec_samples/v1.0/network/tosca_two_servers_one_network.yaml @@ -0,0 +1,79 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with 2 servers bound to the 1 network + +topology_template: + + inputs: + network_name: + type: string + description: Network name + network_cidr: + type: string + default: 10.0.0.0/24 + description: CIDR for the network + network_start_ip: + type: string + default: 10.0.0.100 + description: Start IP for the allocation pool + network_end_ip: + type: string + default: 10.0.0.150 + description: End IP for the allocation pool + + node_templates: + my_server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: 1 + mem_size: 512 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: CirrOS + version: 0.3.2 + + my_server2: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: 1 + mem_size: 512 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: CirrOS + version: 0.3.2 + + my_network: + type: tosca.nodes.network.Network + properties: + ip_version: 4 + cidr: { get_input: network_cidr } + network_name: { get_input: network_name } + start_ip: { get_input: network_start_ip } + end_ip: { get_input: network_end_ip } + + my_port: + type: tosca.nodes.network.Port + requirements: + - binding: + node: my_server + - link: + node: my_network + + my_port2: + type: tosca.nodes.network.Port + requirements: + - binding: + node: my_server2 + - link: + node: my_network diff --git a/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment.yaml b/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment.yaml new file mode 100644 index 0000000..460fa4c --- /dev/null +++ b/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment.yaml @@ -0,0 +1,61 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with server and attached block storage using the normative AttachesTo Relationship Type. + +topology_template: + + inputs: + cpus: + type: integer + description: Number of CPUs for the server. + constraints: + - valid_values: [ 1, 2, 4, 8 ] + storage_size: + type: scalar-unit.size + description: Size of the storage to be created. + default: 1 GB + storage_snapshot_id: + type: string + description: > + Optional identifier for an existing snapshot to use when creating storage. + storage_location: + type: string + description: Block storage mount point (filesystem path). + + node_templates: + my_server: + type: Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: cpus } + mem_size: 4096 kB + os: + properties: + architecture: x86_64 + type: linux + distribution: fedora + version: 18.0 + requirements: + - local_storage: + node: my_storage + relationship: + type: AttachesTo + properties: + location: { get_input: storage_location } + + my_storage: + type: BlockStorage + properties: + size: { get_input: storage_size } + snapshot_id: { get_input: storage_snapshot_id } + + outputs: + private_ip: + description: The private IP address of the newly created compute instance. + value: { get_attribute: [my_server, private_address] } + volume_id: + description: The volume id of the block storage instance. + value: { get_attribute: [my_storage, volume_id] } diff --git a/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment_notation1.yaml b/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment_notation1.yaml new file mode 100644 index 0000000..df22d72 --- /dev/null +++ b/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment_notation1.yaml @@ -0,0 +1,87 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with a Single Block Storage node shared by 2-Tier Application with custom AttachesTo Type and implied relationships. + +relationship_types: + MyAttachesTo: + derived_from: tosca.relationships.AttachesTo + properties: + location: + type: string + default: /default_location + +topology_template: + inputs: + cpus: + type: integer + description: Number of CPUs for the server. + constraints: + - valid_values: [ 1, 2, 4, 8 ] + storage_size: + type: scalar-unit.size + default: 1 GB + description: Size of the storage to be created. + storage_snapshot_id: + type: string + description: > + Optional identifier for an existing snapshot to use when creating storage. + + node_templates: + my_web_app_tier_1: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Fedora + version: 18.0 + requirements: + - local_storage: + node: my_storage + relationship: MyAttachesTo + + my_web_app_tier_2: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Fedora + version: 18.0 + requirements: + - local_storage: + node: my_storage + relationship: + type: MyAttachesTo + properties: + location: /some_other_data_location + + my_storage: + type: tosca.nodes.BlockStorage + properties: + size: { get_input: storage_size } + snapshot_id: { get_input: storage_snapshot_id } + + outputs: + private_ip_1: + description: The private IP address of the application's first tier. + value: { get_attribute: [my_web_app_tier_1, private_address] } + private_ip_2: + description: The private IP address of the application's second tier. + value: { get_attribute: [my_web_app_tier_2, private_address] } + volume_id: + description: The volume id of the block storage instance. + value: { get_attribute: [my_storage, volume_id] } diff --git a/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment_notation2.yaml b/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment_notation2.yaml new file mode 100644 index 0000000..cb1c17a --- /dev/null +++ b/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_attachment_notation2.yaml @@ -0,0 +1,99 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with a single Block Storage node shared by 2-Tier Application with custom AttachesTo Type and explicit Relationship Templates. + +relationship_types: + MyAttachesTo: + derived_from: tosca.relationships.AttachesTo + properties: + location: + type: string + default: /default_location + +topology_template: + inputs: + cpus: + type: integer + description: Number of CPUs for the server. + constraints: + - valid_values: [ 1, 2, 4, 8 ] + storage_size: + type: scalar-unit.size + default: 1 GB + description: Size of the storage to be created. + storage_snapshot_id: + type: string + description: > + Optional identifier for an existing snapshot to use when creating storage. + storage_location: + type: string + description: > + Block storage mount point (filesystem path). + + node_templates: + + my_web_app_tier_1: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: cpus } + mem_size: 4096 kB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Fedora + version: 18.0 + requirements: + - local_storage: + node: my_storage + relationship: storage_attachesto_1 + + my_web_app_tier_2: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: cpus } + mem_size: 4096 kB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Fedora + version: 18.0 + requirements: + - local_storage: + node: my_storage + relationship: storage_attachesto_2 + + my_storage: + type: tosca.nodes.BlockStorage + properties: + size: { get_input: storage_size } + snapshot_id: { get_input: storage_snapshot_id } + + relationship_templates: + storage_attachesto_1: + type: MyAttachesTo + properties: + location: /my_data_location + + storage_attachesto_2: + type: MyAttachesTo + properties: + location: /some_other_data_location + outputs: + private_ip_1: + description: The private IP address of the application's first tier. + value: { get_attribute: [my_web_app_tier_1, private_address] } + private_ip_2: + description: The private IP address of the application's second tier. + value: { get_attribute: [my_web_app_tier_2, private_address] } + volume_id: + description: The volume id of the block storage instance. + value: { get_attribute: [my_storage, volume_id] } diff --git a/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_custom_relationship_type.yaml b/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_custom_relationship_type.yaml new file mode 100644 index 0000000..932f89e --- /dev/null +++ b/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_custom_relationship_type.yaml @@ -0,0 +1,64 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with server and attached block storage using a custom AttachesTo Relationship Type. + +relationship_types: + MyCustomAttachesTo: + derived_from: AttachesTo + +topology_template: + inputs: + cpus: + type: integer + description: Number of CPUs for the server. + constraints: + - valid_values: [ 1, 2, 4, 8 ] + storage_size: + type: scalar-unit.size + description: Size of the storage to be created. + default: 1 GB + storage_snapshot_id: + type: string + description: > + Optional identifier for an existing snapshot to use when creating storage. + storage_location: + type: string + description: Block storage mount point (filesystem path). + + node_templates: + my_server: + type: Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: cpus } + mem_size: 4 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Fedora + version: 18.0 + requirements: + - local_storage: + node: my_storage + # Declare custom AttachesTo type using the 'relationship' keyword + relationship: + type: MyCustomAttachesTo + properties: + location: { get_input: storage_location } + my_storage: + type: BlockStorage + properties: + size: { get_input: storage_size } + snapshot_id: { get_input: storage_snapshot_id } + + outputs: + private_ip: + description: The private IP address of the newly created compute instance. + value: { get_attribute: [my_server, private_address] } + volume_id: + description: The volume id of the block storage instance. + value: { get_attribute: [my_storage, volume_id] } diff --git a/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_relationship_template.yaml b/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_relationship_template.yaml new file mode 100644 index 0000000..c31a4da --- /dev/null +++ b/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_blockstorage_with_relationship_template.yaml @@ -0,0 +1,59 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with server and attached block storage using a named Relationship Template for the storage attachment. + +topology_template: + inputs: + cpus: + type: integer + description: Number of CPUs for the server. + constraints: + - valid_values: [ 1, 2, 4, 8 ] + storage_size: + type: scalar-unit.size + description: Size of the storage to be created. + default: 1 GB + storage_location: + type: string + description: Block storage mount point (filesystem path). + + node_templates: + my_server: + type: Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: cpus } + mem_size: 4 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Fedora + version: 18.0 + requirements: + - local_storage: + node: my_storage + # Declare template to use with 'relationship' keyword + relationship: storage_attachment + + my_storage: + type: BlockStorage + properties: + size: { get_input: storage_size } + + relationship_templates: + storage_attachment: + type: AttachesTo + properties: + location: { get_input: storage_location } + + outputs: + private_ip: + description: The private IP address of the newly created compute instance. + value: { get_attribute: [my_server, private_address] } + volume_id: + description: The volume id of the block storage instance. + value: { get_attribute: [my_storage, volume_id] } diff --git a/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_multiple_blockstorage_with_attachment.yaml b/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_multiple_blockstorage_with_attachment.yaml new file mode 100644 index 0000000..aa4647e --- /dev/null +++ b/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_multiple_blockstorage_with_attachment.yaml @@ -0,0 +1,93 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with 2 servers each with different attached block storage. + +topology_template: + inputs: + cpus: + type: integer + description: Number of CPUs for the server. + constraints: + - valid_values: [ 1, 2, 4, 8 ] + storage_size: + type: scalar-unit.size + default: 1 GB + description: Size of the storage to be created. + storage_snapshot_id: + type: string + description: > + Optional identifier for an existing snapshot to use when creating storage. + storage_location: + type: string + description: > + Block storage mount point (filesystem path). + + node_templates: + my_server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Fedora + version: 18.0 + requirements: + - local_storage: + node: my_storage + relationship: + type: AttachesTo + properties: + location: { get_input: storage_location } + my_storage: + type: tosca.nodes.BlockStorage + properties: + size: { get_input: storage_size } + snapshot_id: { get_input: storage_snapshot_id } + + my_server2: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Fedora + version: 18.0 + requirements: + - local_storage: + node: my_storage2 + relationship: + type: AttachesTo + properties: + location: { get_input: storage_location } + my_storage2: + type: tosca.nodes.BlockStorage + properties: + size: { get_input: storage_size } + snapshot_id: { get_input: storage_snapshot_id } + + outputs: + server_ip_1: + description: The private IP address of the application's first server. + value: { get_attribute: [my_server, private_address] } + server_ip_2: + description: The private IP address of the application's second server. + value: { get_attribute: [my_server2, private_address] } + volume_id_1: + description: The volume id of the first block storage instance. + value: { get_attribute: [my_storage, volume_id] } + volume_id_2: + description: The volume id of the second block storage instance. + value: { get_attribute: [my_storage2, volume_id] } diff --git a/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_single_object_store.yaml b/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_single_object_store.yaml new file mode 100644 index 0000000..869af48 --- /dev/null +++ b/nfvparser/toscaparser/tests/spec_samples/v1.0/storage/tosca_single_object_store.yaml @@ -0,0 +1,17 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + Tosca template for creating an object storage service. + +topology_template: + inputs: + objectstore_name: + type: string + + node_templates: + obj_store_server: + type: tosca.nodes.ObjectStorage + properties: + name: { get_input: objectstore_name } + size: 1024 kB + maxsize: 1 GB diff --git a/nfvparser/toscaparser/tests/spec_samples/v1.0/tosca_nodejs_mongodb_two_instances.yaml b/nfvparser/toscaparser/tests/spec_samples/v1.0/tosca_nodejs_mongodb_two_instances.yaml new file mode 100644 index 0000000..f611071 --- /dev/null +++ b/nfvparser/toscaparser/tests/spec_samples/v1.0/tosca_nodejs_mongodb_two_instances.yaml @@ -0,0 +1,96 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile with nodejs and mongodb. + +imports: + - custom_types/paypalpizzastore_nodejs_app.yaml + +dsl_definitions: + host_capabilities: &host_capabilities + disk_size: 10 GB + num_cpus: 1 + mem_size: 4096 MB + os_capabilities: &os_capabilities + architecture: x86_64 + type: Linux + distribution: Ubuntu + version: 14.04 + +topology_template: + inputs: + my_cpus: + type: integer + description: Number of CPUs for the server. + constraints: + - valid_values: [ 1, 2, 4, 8 ] + default: 1 + github_url: + type: string + description: The URL to download nodejs. + default: http://github.com/paypal/rest-api-sample-app-nodejs.git + + node_templates: + paypal_pizzastore: + type: tosca.nodes.WebApplication.PayPalPizzaStore + properties: + github_url: { get_input: github_url } + requirements: + - host: nodejs + - database_connection: mongo_db + interfaces: + Standard: + configure: + implementation: nodejs/config.sh + inputs: + github_url: http://github.com/paypal/rest-api-sample-app-nodejs.git + mongodb_ip: { get_attribute: [mongo_server, private_address] } + start: nodejs/start.sh + nodejs: + type: tosca.nodes.WebServer + requirements: + - host: app_server + interfaces: + Standard: + create: nodejs/create.sh + mongo_db: + type: tosca.nodes.Database + requirements: + - host: mongo_dbms + interfaces: + Standard: + create: mongodb/create_database.sh + mongo_dbms: + type: tosca.nodes.DBMS + requirements: + - host: mongo_server + interfaces: + Standard: + create: mongodb/create.sh + configure: + implementation: mongodb/config.sh + inputs: + mongodb_ip: { get_attribute: [mongo_server, private_address] } + start: mongodb/start.sh + mongo_server: + type: tosca.nodes.Compute + capabilities: + host: + properties: *host_capabilities + os: + properties: *os_capabilities + app_server: + type: tosca.nodes.Compute + capabilities: + host: + properties: *host_capabilities + os: + properties: *os_capabilities + + outputs: + nodejs_url: + description: URL for the nodejs server, http://:3000 + value: { get_attribute: [app_server, private_address] } + mongodb_url: + description: URL for the mongodb server. + value: { get_attribute: [mongo_server, private_address] } diff --git a/nfvparser/toscaparser/tests/spec_samples/v1.0/tosca_single_server.yaml b/nfvparser/toscaparser/tests/spec_samples/v1.0/tosca_single_server.yaml new file mode 100644 index 0000000..c4cce9d --- /dev/null +++ b/nfvparser/toscaparser/tests/spec_samples/v1.0/tosca_single_server.yaml @@ -0,0 +1,32 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +description: > + TOSCA simple profile that just defines a single compute instance and selects a (guest) host Operating System from the Compute node's properties. Note, this example does not include default values on inputs properties. + +topology_template: + inputs: + cpus: + type: integer + description: Number of CPUs for the server. + constraints: + - valid_values: [ 1, 2, 4, 8 ] + + node_templates: + my_server: + type: Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: cpus } + mem_size: 4 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: ubuntu + version: 12.04 + outputs: + private_ip: + description: The private IP address of the deployed server instance. + value: { get_attribute: [my_server, private_address] } \ No newline at end of file diff --git a/nfvparser/toscaparser/tests/test_constraints.py b/nfvparser/toscaparser/tests/test_constraints.py new file mode 100644 index 0000000..07cb910 --- /dev/null +++ b/nfvparser/toscaparser/tests/test_constraints.py @@ -0,0 +1,373 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import datetime +import yaml + +from toscaparser.common import exception +from toscaparser.elements.constraints import Constraint +from toscaparser.elements.constraints import Schema +from toscaparser.tests.base import TestCase +from toscaparser.utils.gettextutils import _ +from toscaparser.utils import yamlparser + + +class ConstraintTest(TestCase): + + def test_schema_dict(self): + tpl_snippet = ''' + cpus: + type: integer + description: Number of CPUs for the server. + ''' + schema = yamlparser.simple_parse(tpl_snippet) + cpus_schema = Schema('cpus', schema['cpus']) + self.assertEqual(len(cpus_schema), 2) + self.assertEqual('integer', cpus_schema.type) + self.assertEqual('Number of CPUs for the server.', + cpus_schema.description) + self.assertEqual(True, cpus_schema.required) + self.assertIsNone(cpus_schema.default) + + def test_schema_not_dict(self): + tpl_snippet = ''' + cpus: + - type: integer + - description: Number of CPUs for the server. + ''' + schema = yamlparser.simple_parse(tpl_snippet) + error = self.assertRaises(exception.InvalidSchemaError, Schema, + 'cpus', schema['cpus']) + self.assertEqual(_('Schema definition of "cpus" must be a dict.'), + str(error)) + + def test_schema_miss_type(self): + tpl_snippet = ''' + cpus: + description: Number of CPUs for the server. + ''' + schema = yamlparser.simple_parse(tpl_snippet) + error = self.assertRaises(exception.InvalidSchemaError, Schema, + 'cpus', schema['cpus']) + self.assertEqual(_('Schema definition of "cpus" must have a "type" ' + 'attribute.'), str(error)) + + def test_schema_none_description(self): + tpl_snippet = ''' + cpus: + type: integer + ''' + schema = yamlparser.simple_parse(tpl_snippet) + cpus_schema = Schema('cpus', schema['cpus']) + self.assertEqual('', cpus_schema.description) + + def test_invalid_constraint_type(self): + schema = {'invalid_type': 2} + error = self.assertRaises(exception.InvalidSchemaError, Constraint, + 'prop', Schema.INTEGER, + schema) + self.assertEqual(_('Invalid property "invalid_type".'), + str(error)) + + def test_invalid_prop_type(self): + schema = {'length': 5} + error = self.assertRaises(exception.InvalidSchemaError, Constraint, + 'prop', Schema.INTEGER, + schema) + self.assertEqual(_('Property "length" is not valid for data type ' + '"integer".'), str(error)) + + def test_invalid_validvalues(self): + schema = {'valid_values': 2} + error = self.assertRaises(exception.InvalidSchemaError, Constraint, + 'prop', Schema.INTEGER, + schema) + self.assertEqual(_('The property "valid_values" expects a list.'), + str(error)) + + def test_validvalues_validate(self): + schema = {'valid_values': [2, 4, 6, 8]} + constraint = Constraint('prop', Schema.INTEGER, schema) + self.assertIsNone(constraint.validate(4)) + + def test_validvalues_validate_fail(self): + schema = {'valid_values': [2, 4, 6, 8]} + constraint = Constraint('prop', Schema.INTEGER, schema) + error = self.assertRaises(exception.ValidationError, + constraint.validate, 5) + self.assertEqual(_('The value "5" of property "prop" is not valid. ' + 'Expected a value from "[2, 4, 6, 8]".'), + str(error)) + + def test_invalid_in_range(self): + snippet = 'in_range: {2, 6}' + schema = yaml.load(snippet) + error = self.assertRaises(exception.InvalidSchemaError, Constraint, + 'prop', Schema.INTEGER, + schema) + self.assertEqual(_('The property "in_range" expects a list.'), + str(error)) + + def test_in_range_min_max(self): + schema = {'in_range': [2, 6]} + constraint = Constraint('prop', Schema.INTEGER, schema) + self.assertEqual(2, constraint.min) + self.assertEqual(6, constraint.max) + + def test_in_range_validate(self): + schema = {'in_range': [2, 6]} + constraint = Constraint('prop', Schema.INTEGER, schema) + self.assertIsNone(constraint.validate(2)) + self.assertIsNone(constraint.validate(4)) + self.assertIsNone(constraint.validate(6)) + + def test_in_range_validate_fail(self): + schema = {'in_range': [2, 6]} + constraint = Constraint('prop', Schema.INTEGER, schema) + error = self.assertRaises(exception.ValidationError, + constraint.validate, 8) + self.assertEqual(_('The value "8" of property "prop" is out of range ' + '"(min:2, max:6)".'), str(error)) + + def test_equal_validate(self): + schema = {'equal': 4} + constraint = Constraint('prop', Schema.INTEGER, schema) + self.assertIsNone(constraint.validate(4)) + + def test_equal_validate_fail(self): + schema = {'equal': 4} + constraint = Constraint('prop', Schema.INTEGER, schema) + error = self.assertRaises(exception.ValidationError, + constraint.validate, 8) + self.assertEqual('The value "8" of property "prop" is not equal to ' + '"4".', str(error)) + + def test_greater_than_validate(self): + schema = {'greater_than': 4} + constraint = Constraint('prop', Schema.INTEGER, schema) + self.assertIsNone(constraint.validate(6)) + + def test_greater_than_validate_fail(self): + schema = {'greater_than': 4} + constraint = Constraint('prop', Schema.INTEGER, schema) + error = self.assertRaises(exception.ValidationError, + constraint.validate, 3) + self.assertEqual(_('The value "3" of property "prop" must be greater ' + 'than "4".'), str(error)) + + error = self.assertRaises(exception.ValidationError, + constraint.validate, 4) + self.assertEqual(_('The value "4" of property "prop" must be greater ' + 'than "4".'), str(error)) + + def test_greater_than_invalid(self): + snippet = 'greater_than: {4}' + schema = yaml.load(snippet) + error = self.assertRaises(exception.InvalidSchemaError, Constraint, + 'prop', Schema.INTEGER, + schema) + self.assertEqual(_('The property "greater_than" expects comparable ' + 'values.'), str(error)) + + def test_greater_or_equal_validate(self): + schema = {'greater_or_equal': 3.9} + constraint = Constraint('prop', Schema.FLOAT, schema) + self.assertIsNone(constraint.validate(3.9)) + self.assertIsNone(constraint.validate(4.0)) + + def test_greater_or_equal_validate_fail(self): + schema = {'greater_or_equal': 3.9} + constraint = Constraint('prop', Schema.FLOAT, schema) + error = self.assertRaises(exception.ValidationError, + constraint.validate, 3.0) + self.assertEqual(_('The value "3.0" of property "prop" must be ' + 'greater than or equal to "3.9".'), + str(error)) + + error = self.assertRaises(exception.ValidationError, + constraint.validate, 3.8) + self.assertEqual(_('The value "3.8" of property "prop" must be ' + 'greater than or equal to "3.9".'), + str(error)) + + def test_greater_or_equal_invalid(self): + snippet = 'greater_or_equal: {3.9}' + schema = yaml.load(snippet) + error = self.assertRaises(exception.InvalidSchemaError, Constraint, + 'prop', Schema.INTEGER, + schema) + self.assertEqual(_('The property "greater_or_equal" expects ' + 'comparable values.'), str(error)) + + def test_less_than_validate(self): + schema = {'less_than': datetime.date(2014, 0o7, 25)} + constraint = Constraint('prop', Schema.TIMESTAMP, schema) + self.assertIsNone(constraint.validate(datetime.date(2014, 0o7, 20))) + self.assertIsNone(constraint.validate(datetime.date(2014, 0o7, 24))) + + def test_less_than_validate_fail(self): + schema = {'less_than': datetime.date(2014, 0o7, 25)} + constraint = Constraint('prop', Schema.TIMESTAMP, schema) + error = self.assertRaises(exception.ValidationError, + constraint.validate, + datetime.date(2014, 0o7, 25)) + self.assertEqual(_('The value "2014-07-25" of property "prop" must be ' + 'less than "2014-07-25".'), + str(error)) + + error = self.assertRaises(exception.ValidationError, + constraint.validate, + datetime.date(2014, 0o7, 27)) + self.assertEqual(_('The value "2014-07-27" of property "prop" must be ' + 'less than "2014-07-25".'), + str(error)) + + def test_less_than_invalid(self): + snippet = 'less_than: {3.9}' + schema = yaml.load(snippet) + error = self.assertRaises(exception.InvalidSchemaError, Constraint, + 'prop', Schema.INTEGER, + schema) + self.assertEqual(_('The property "less_than" expects comparable ' + 'values.'), str(error)) + + def test_less_or_equal_validate(self): + schema = {'less_or_equal': 4} + constraint = Constraint('prop', Schema.INTEGER, schema) + self.assertIsNone(constraint.validate(4)) + self.assertIsNone(constraint.validate(3)) + + def test_less_or_equal_validate_fail(self): + schema = {'less_or_equal': 4} + constraint = Constraint('prop', Schema.INTEGER, schema) + error = self.assertRaises(exception.ValidationError, + constraint.validate, 5) + self.assertEqual(_('The value "5" of property "prop" must be less ' + 'than or equal to "4".'), str(error)) + + def test_less_or_equal_invalid(self): + snippet = 'less_or_equal: {3.9}' + schema = yaml.load(snippet) + error = self.assertRaises(exception.InvalidSchemaError, Constraint, + 'prop', Schema.INTEGER, + schema) + self.assertEqual(_('The property "less_or_equal" expects comparable ' + 'values.'), str(error)) + + def test_invalid_length(self): + schema = {'length': 'four'} + error = self.assertRaises(exception.InvalidSchemaError, Constraint, + 'prop', Schema.STRING, + schema) + self.assertEqual(_('The property "length" expects an integer.'), + str(error)) + + schema = {'length': 4.5} + error = self.assertRaises(exception.InvalidSchemaError, Constraint, + 'prop', Schema.STRING, + schema) + self.assertEqual(_('The property "length" expects an integer.'), + str(error)) + + def test_length_validate(self): + schema = {'length': 4} + constraint = Constraint('prop', Schema.STRING, schema) + self.assertIsNone(constraint.validate('abcd')) + + def test_length_validate_fail(self): + schema = {'length': 4} + constraint = Constraint('prop', Schema.STRING, schema) + error = self.assertRaises(exception.ValidationError, + constraint.validate, 'abc') + self.assertEqual(_('Length of value "abc" of property "prop" must ' + 'be equal to "4".'), str(error)) + + error = self.assertRaises(exception.ValidationError, + constraint.validate, + 'abcde') + self.assertEqual(_('Length of value "abcde" of property "prop" must ' + 'be equal to "4".'), str(error)) + + def test_invalid_min_length(self): + schema = {'min_length': 'four'} + error = self.assertRaises(exception.InvalidSchemaError, Constraint, + 'prop', Schema.STRING, + schema) + self.assertEqual(_('The property "min_length" expects an integer.'), + str(error)) + + def test_min_length_validate(self): + schema = {'min_length': 4} + constraint = Constraint('prop', Schema.STRING, schema) + self.assertIsNone(constraint.validate('abcd')) + self.assertIsNone(constraint.validate('abcde')) + + def test_min_length_validate_fail(self): + schema = {'min_length': 4} + constraint = Constraint('prop', Schema.STRING, schema) + error = self.assertRaises(exception.ValidationError, + constraint.validate, 'abc') + self.assertEqual(_('Length of value "abc" of property "prop" must ' + 'be at least "4".'), str(error)) + + def test_invalid_max_length(self): + schema = {'max_length': 'four'} + error = self.assertRaises(exception.InvalidSchemaError, Constraint, + 'prop', Schema.STRING, + schema) + self.assertEqual(_('The property "max_length" expects an integer.'), + str(error)) + + def test_max_length_validate(self): + schema = {'max_length': 4} + constraint = Constraint('prop', Schema.STRING, schema) + self.assertIsNone(constraint.validate('abcd')) + self.assertIsNone(constraint.validate('abc')) + + def test_max_length_validate_fail(self): + schema = {'max_length': 4} + constraint = Constraint('prop', Schema.STRING, schema) + error = self.assertRaises(exception.ValidationError, + constraint.validate, + 'abcde') + self.assertEqual(_('Length of value "abcde" of property "prop" ' + 'must be no greater than "4".'), + str(error)) + + def test_pattern_validate(self): + schema = {'pattern': '[0-9]*'} + constraint = Constraint('prop', Schema.STRING, schema) + self.assertIsNone(constraint.validate('123')) + + def test_pattern_validate_fail(self): + schema = {'pattern': '[0-9]*'} + constraint = Constraint('prop', Schema.STRING, schema) + error = self.assertRaises(exception.ValidationError, + constraint.validate, 'abc') + self.assertEqual(_('The value "abc" of property "prop" does not ' + 'match pattern "[0-9]*".'), str(error)) + + def test_min_length_with_map(self): + schema = {'min_length': 1} + constraint = Constraint('prop', Schema.MAP, schema) + try: + constraint.validate({"k": "v"}) + except Exception as ex: + self.fail(ex) + + def test_max_length_with_map(self): + schema = {'max_length': 1} + constraint = Constraint('prop', Schema.MAP, schema) + try: + constraint.validate({"k": "v"}) + except Exception as ex: + self.fail(ex) diff --git a/nfvparser/toscaparser/tests/test_custom_relationships.py b/nfvparser/toscaparser/tests/test_custom_relationships.py new file mode 100644 index 0000000..9ae85d5 --- /dev/null +++ b/nfvparser/toscaparser/tests/test_custom_relationships.py @@ -0,0 +1,35 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import os + +from toscaparser.tests.base import TestCase +from toscaparser.tosca_template import ToscaTemplate + + +class CustomRelationshipTypesTest(TestCase): + + '''TOSCA template.''' + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/relationship/test_custom_relationship.yaml") + tosca = ToscaTemplate(tosca_tpl) + + def test_version(self): + self.assertEqual(self.tosca.version, "tosca_simple_yaml_1_0") + + def test_custom_types(self): + expected_custom_types = ['tosca.capabilities.HA', + 'tosca.nodes.HACompute', + 'tosca.relationships.HA'] + self.assertItemsEqual(self.tosca.topology_template.custom_defs.keys(), + expected_custom_types) diff --git a/nfvparser/toscaparser/tests/test_datatypes.py b/nfvparser/toscaparser/tests/test_datatypes.py new file mode 100644 index 0000000..0a6cfe0 --- /dev/null +++ b/nfvparser/toscaparser/tests/test_datatypes.py @@ -0,0 +1,517 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import os + +from testtools.testcase import skip +from toscaparser.common import exception +from toscaparser.dataentity import DataEntity +from toscaparser.elements.datatype import DataType +from toscaparser.parameters import Input +from toscaparser.tests.base import TestCase +from toscaparser.tosca_template import ToscaTemplate +from toscaparser.utils.gettextutils import _ +from toscaparser.utils import yamlparser + + +class DataTypeTest(TestCase): + + custom_type_schema = ''' + tosca.my.datatypes.PeopleBase: + properties: + name: + type: string + required: true + constraints: + - min_length: 2 + gender: + type: string + default: unknown + + tosca.my.datatypes.People: + derived_from: tosca.my.datatypes.PeopleBase + properties: + addresses: + type: map + required: false + entry_schema: + type: string + contacts: + type: list + required: false + entry_schema: + type: tosca.my.datatypes.ContactInfo + + tosca.my.datatypes.ContactInfo: + description: simple contact information + properties: + contact_name: + type: string + required: true + constraints: + - min_length: 2 + contact_email: + type: string + contact_phone: + type: string + + tosca.my.datatypes.TestLab: + properties: + humidity: + type: range + required: false + constraints: + - in_range: [-256, INFINITY] + temperature1: + type: range + required: false + constraints: + - in_range: [-256, UNBOUNDED] + temperature2: + type: range + required: false + constraints: + - in_range: [UNBOUNDED, 256] + ''' + custom_type_def = yamlparser.simple_parse(custom_type_schema) + + def test_empty_template(self): + value_snippet = '' + value = yamlparser.simple_parse(value_snippet) + self.assertEqual(value, {}) + + def test_built_in_datatype(self): + value_snippet = ''' + private_network: + network_name: private + network_id: 3e54214f-5c09-1bc9-9999-44100326da1b + addresses: [ 10.111.128.10 ] + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.datatypes.network.NetworkInfo', + value.get('private_network')) + self.assertIsNotNone(data.validate()) + + value_snippet = ''' + portspec_valid: + protocol: tcp + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.datatypes.network.PortSpec', + value.get('portspec_valid')) + self.assertIsNotNone(data.validate()) + + value_snippet = ''' + portspec_invalid: + protocol: xyz + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.datatypes.network.PortSpec', + value.get('portspec_invalid')) + err = self.assertRaises(exception.ValidationError, data.validate) + self.assertEqual(_('The value "xyz" of property "protocol" is not ' + 'valid. Expected a value from "[udp, tcp, igmp]".' + ), + err.__str__()) + + def test_built_in_datatype_with_short_name(self): + value_snippet = ''' + ethernet_port: + port_name: port1 + port_id: 2c0c7a37-691a-23a6-7709-2d10ad041467 + network_id: 3e54214f-5c09-1bc9-9999-44100326da1b + mac_address: f1:18:3b:41:92:1e + addresses: [ 172.24.9.102 ] + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('PortInfo', value.get('ethernet_port')) + self.assertIsNotNone(data.validate()) + + # Test normative PortSpec datatype's additional requirements + # TODO(Matt) - opened as bug 1555300 + # Need a test for PortSpec normative data type + # that tests the spec. requirement: "A valid PortSpec + # must have at least one of the following properties: + # target, target_range, source or source_range." + # TODO(Matt) - opened as bug 1555310 + # test PortSpec value for source and target + # against the source_range and target_range + # when specified. + def test_port_spec_addl_reqs(self): + value_snippet = ''' + test_port: + protocol: tcp + target: 65535 + target_range: [ 1, 65535 ] + source: 1 + source_range: [ 1, 65535 ] + + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.datatypes.network.PortSpec', + value.get('test_port')) + self.assertIsNotNone(data.validate()) + + def test_built_in_datatype_without_properties(self): + value_snippet = ''' + 2 + ''' + value = yamlparser.simple_parse(value_snippet) + datatype = DataType('PortDef') + self.assertEqual('integer', datatype.value_type) + data = DataEntity('PortDef', value) + self.assertIsNotNone(data.validate()) + + @skip('The example in TOSCA spec may have some problem.') + def test_built_in_nested_datatype(self): + value_snippet = ''' + user_port: + protocol: tcp + target: [50000] + source: [9000] + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('PortSpec', value.get('user_port')) + self.assertIsNotNone(data.validate()) + + def test_built_in_nested_datatype_portdef(self): + tpl_snippet = ''' + inputs: + db_port: + type: PortDef + description: Port for the MySQL database + ''' + inputs = yamlparser.simple_parse(tpl_snippet)['inputs'] + name, attrs = list(inputs.items())[0] + input = Input(name, attrs) + self.assertIsNone(input.validate(3360)) + err = self.assertRaises(exception.ValidationError, input.validate, + 336000) + self.assertEqual(_('The value "336000" of property "None" is out of ' + 'range "(min:1, max:65535)".'), + err.__str__()) + + def test_custom_datatype(self): + value_snippet = ''' + name: Mike + gender: male + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.my.datatypes.PeopleBase', value, + DataTypeTest.custom_type_def) + self.assertIsNotNone(data.validate()) + + def test_custom_datatype_with_parent(self): + value_snippet = ''' + name: Mike + gender: male + contacts: + - {contact_name: Tom, + contact_email: tom@email.com, + contact_phone: '123456789'} + - {contact_name: Jerry, + contact_email: jerry@email.com, + contact_phone: '321654987'} + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.my.datatypes.People', value, + DataTypeTest.custom_type_def) + self.assertIsNotNone(data.validate()) + + # [Tom, Jerry] is not a dict, it can't be a value of datatype PeopleBase + def test_non_dict_value_for_datatype(self): + value_snippet = ''' + [Tom, Jerry] + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.my.datatypes.PeopleBase', value, + DataTypeTest.custom_type_def) + error = self.assertRaises(exception.TypeMismatchError, data.validate) + self.assertEqual(_('[\'Tom\', \'Jerry\'] must be of type ' + '"tosca.my.datatypes.PeopleBase".'), + error.__str__()) + + # 'nema' is an invalid field name + def test_field_error_in_dataentity(self): + value_snippet = ''' + nema: Mike + gender: male + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.my.datatypes.PeopleBase', value, + DataTypeTest.custom_type_def) + error = self.assertRaises(exception.UnknownFieldError, data.validate) + self.assertEqual(_('Data value of type ' + '"tosca.my.datatypes.PeopleBase" contains unknown ' + 'field "nema". Refer to the definition to verify ' + 'valid values.'), + error.__str__()) + + def test_default_field_in_dataentity(self): + value_snippet = ''' + name: Mike + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.my.datatypes.PeopleBase', value, + DataTypeTest.custom_type_def) + data = data.validate() + self.assertEqual('unknown', data.get('gender')) + + # required field 'name' is missing + def test_missing_field_in_dataentity(self): + value_snippet = ''' + gender: male + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.my.datatypes.PeopleBase', value, + DataTypeTest.custom_type_def) + error = self.assertRaises(exception.MissingRequiredFieldError, + data.validate) + self.assertEqual(_('Data value of type ' + '"tosca.my.datatypes.PeopleBase" is missing ' + 'required field "[\'name\']".'), + error.__str__()) + + # the value of name field is not a string + def test_type_error_in_dataentity(self): + value_snippet = ''' + name: 123 + gender: male + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.my.datatypes.PeopleBase', value, + DataTypeTest.custom_type_def) + error = self.assertRaises(ValueError, data.validate) + self.assertEqual(_('"123" is not a string.'), error.__str__()) + + # the value of name doesn't meet the defined constraint + def test_value_error_in_dataentity(self): + value_snippet = ''' + name: M + gender: male + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.my.datatypes.PeopleBase', value, + DataTypeTest.custom_type_def) + error = self.assertRaises(exception.ValidationError, data.validate) + self.assertEqual(_('Length of value "M" of property "name" must be ' + 'at least "2".'), error.__str__()) + + # value of addresses doesn't fit the entry_schema + def test_validation_in_collection_entry(self): + value_snippet = ''' + name: Mike + gender: male + addresses: {Home: 1, Office: 9 bar avenue} + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.my.datatypes.People', value, + DataTypeTest.custom_type_def) + error = self.assertRaises(ValueError, data.validate) + self.assertEqual(_('"1" is not a string.'), error.__str__()) + + # 'contact_pone' is an invalid attribute name in nested datatype below + def test_validation_in_nested_datatype(self): + value_snippet = ''' + name: Mike + gender: male + contacts: + - {contact_name: Tom, + contact_email: tom@email.com, + contact_pone: '123456789'} + - {contact_name: Jerry, + contact_email: jerry@email.com, + contact_phone: '321654987'} + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.my.datatypes.People', value, + DataTypeTest.custom_type_def) + error = self.assertRaises(exception.UnknownFieldError, data.validate) + self.assertEqual(_('Data value of type ' + '"tosca.my.datatypes.ContactInfo" contains unknown ' + 'field "contact_pone". Refer to the definition to ' + 'verify valid values.'), + error.__str__()) + + def test_datatype_in_current_template(self): + tpl_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/datatypes/test_custom_datatypes_in_current_template.yaml") + self.assertIsNotNone(ToscaTemplate(tpl_path)) + + def test_datatype_in_template_positive(self): + tpl_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/datatypes/test_custom_datatypes_positive.yaml") + self.assertIsNotNone(ToscaTemplate(tpl_path)) + + def test_datatype_in_template_invalid_value(self): + tpl_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/datatypes/test_custom_datatypes_value_error.yaml") + self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path) + exception.ExceptionCollector.assertExceptionMessage( + ValueError, + _('"[\'1 foo street\', \'9 bar avenue\']" is not a map.')) + + def test_datatype_in_template_nested_datatype_error(self): + tpl_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/datatypes/test_custom_datatypes_nested_datatype_error.yaml") + self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path) + exception.ExceptionCollector.assertExceptionMessage( + ValueError, _('"123456789" is not a string.')) + + def test_valid_range_type(self): + value_snippet = ''' + user_port: + protocol: tcp + target_range: [20000, 60000] + source_range: [1000, 3000] + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('PortSpec', value.get('user_port')) + self.assertIsNotNone(data.validate()) + + def test_invalid_range_datatype(self): + value_snippet = ''' + user_port: + protocol: tcp + target: 1 + target_range: [20000] + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('PortSpec', value.get('user_port')) + err = self.assertRaises(ValueError, data.validate) + self.assertEqual(_('"[20000]" is not a valid range.' + ), + err.__str__()) + + value_snippet = ''' + user_port: + protocol: tcp + target: 1 + target_range: [20000, 3000] + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('PortSpec', value.get('user_port')) + err = self.assertRaises(ValueError, data.validate) + self.assertEqual(_('"[20000, 3000]" is not a valid range.' + ), + err.__str__()) + + value_snippet = ''' + humidity: [-100, 100] + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.my.datatypes.TestLab', + value, DataTypeTest.custom_type_def) + err = self.assertRaises(exception.InvalidSchemaError, + lambda: data.validate()) + self.assertEqual(_('The property "in_range" expects comparable values.' + ), + err.__str__()) + + def test_range_unbounded(self): + value_snippet = ''' + humidity: [-100, 100] + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.my.datatypes.TestLab', + value, DataTypeTest.custom_type_def) + err = self.assertRaises(exception.InvalidSchemaError, + lambda: data.validate()) + self.assertEqual(_('The property "in_range" expects comparable values.' + ), + err.__str__()) + + def test_invalid_ranges_against_constraints(self): + # The TestLab range type has min=-256, max=UNBOUNDED + value_snippet = ''' + temperature1: [-257, 999999] + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.my.datatypes.TestLab', value, + DataTypeTest.custom_type_def) + err = self.assertRaises(exception.ValidationError, data.validate) + self.assertEqual(_('The value "-257" of property "temperature1" is ' + 'out of range "(min:-256, max:UNBOUNDED)".'), + err.__str__()) + + value_snippet = ''' + temperature2: [-999999, 257] + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.my.datatypes.TestLab', value, + DataTypeTest.custom_type_def) + err = self.assertRaises(exception.ValidationError, data.validate) + self.assertEqual(_('The value "257" of property "temperature2" is ' + 'out of range "(min:UNBOUNDED, max:256)".'), + err.__str__()) + + def test_valid_ranges_against_constraints(self): + + # The TestLab range type has max=UNBOUNDED + value_snippet = ''' + temperature1: [-255, 999999] + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.my.datatypes.TestLab', value, + DataTypeTest.custom_type_def) + self.assertIsNotNone(data.validate()) + + # The TestLab range type has min=UNBOUNDED + value_snippet = ''' + temperature2: [-999999, 255] + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.my.datatypes.TestLab', value, + DataTypeTest.custom_type_def) + self.assertIsNotNone(data.validate()) + + def test_incorrect_field_in_datatype(self): + tpl_snippet = ''' + tosca_definitions_version: tosca_simple_yaml_1_0 + topology_template: + node_templates: + server: + type: tosca.nodes.Compute + + webserver: + type: tosca.nodes.WebServer + properties: + admin_credential: + user: username + token: some_pass + some_field: value + requirements: + - host: server + ''' + tpl = yamlparser.simple_parse(tpl_snippet) + err = self.assertRaises(exception.ValidationError, ToscaTemplate, + None, None, None, tpl) + self.assertIn(_('The pre-parsed input failed validation with the ' + 'following error(s): \n\n\tUnknownFieldError: Data ' + 'value of type "tosca.datatypes.Credential" contains' + ' unknown field "some_field". Refer to the definition' + ' to verify valid values'), err.__str__()) + + def test_functions_datatype(self): + value_snippet = ''' + admin_credential: + user: username + token: { get_input: password } + ''' + value = yamlparser.simple_parse(value_snippet) + data = DataEntity('tosca.datatypes.Credential', + value.get('admin_credential')) + self.assertIsNotNone(data.validate()) diff --git a/nfvparser/toscaparser/tests/test_exception.py b/nfvparser/toscaparser/tests/test_exception.py new file mode 100644 index 0000000..a404f4f --- /dev/null +++ b/nfvparser/toscaparser/tests/test_exception.py @@ -0,0 +1,42 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from toscaparser.common import exception +from toscaparser.tests.base import TestCase +from toscaparser.utils.gettextutils import _ + + +class ExceptionTest(TestCase): + + def setUp(self): + super(TestCase, self).setUp() + exception.TOSCAException.set_fatal_format_exception(False) + + def test_message(self): + ex = exception.MissingRequiredFieldError(what='Template', + required='type') + self.assertEqual(_('Template is missing required field "type".'), + ex.__str__()) + + def test_set_flag(self): + exception.TOSCAException.set_fatal_format_exception('True') + self.assertFalse( + exception.TOSCAException._FATAL_EXCEPTION_FORMAT_ERRORS) + + def test_format_error(self): + ex = exception.UnknownFieldError(what='Template') + self.assertEqual(_('An unknown exception occurred.'), ex.__str__(),) + self.assertRaises(KeyError, self._formate_exception) + + def _formate_exception(self): + exception.UnknownFieldError.set_fatal_format_exception(True) + raise exception.UnknownFieldError(what='Template') diff --git a/nfvparser/toscaparser/tests/test_functions.py b/nfvparser/toscaparser/tests/test_functions.py new file mode 100644 index 0000000..fa60140 --- /dev/null +++ b/nfvparser/toscaparser/tests/test_functions.py @@ -0,0 +1,373 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import os +import six +from toscaparser.common import exception +from toscaparser import functions +from toscaparser.tests.base import TestCase +from toscaparser.tosca_template import ToscaTemplate +from toscaparser.utils.gettextutils import _ + + +class IntrinsicFunctionsTest(TestCase): + + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/tosca_single_instance_wordpress.yaml") + params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user', + 'db_root_pwd': '12345678'} + tosca = ToscaTemplate(tosca_tpl, parsed_params=params) + + def _get_node(self, node_name, tosca=None): + if tosca is None: + tosca = self.tosca + return [ + node for node in tosca.nodetemplates + if node.name == node_name][0] + + def _get_operation(self, interfaces, operation): + return [ + interface for interface in interfaces + if interface.name == operation][0] + + def _get_property(self, node_template, property_name): + return [prop.value for prop in node_template.get_properties_objects() + if prop.name == property_name][0] + + def _get_inputs_dict(self): + inputs = {} + for input in self.tosca.inputs: + inputs[input.name] = input.default + return inputs + + def _get_input(self, name): + self._get_inputs_dict()[name] + + def test_get_property(self): + wordpress = self._get_node('wordpress') + operation = self._get_operation(wordpress.interfaces, 'configure') + wp_db_password = operation.inputs['wp_db_password'] + self.assertIsInstance(wp_db_password, functions.GetProperty) + result = wp_db_password.result() + self.assertEqual('wp_pass', result) + + def test_get_property_with_input_param(self): + wordpress = self._get_node('wordpress') + operation = self._get_operation(wordpress.interfaces, 'configure') + wp_db_user = operation.inputs['wp_db_user'] + self.assertIsInstance(wp_db_user, functions.GetProperty) + result = wp_db_user.result() + self.assertEqual('my_db_user', result) + + def test_unknown_capability_property(self): + self.assertRaises(exception.ValidationError, self._load_template, + 'functions/test_unknown_capability_property.yaml') + exception.ExceptionCollector.assertExceptionMessage( + KeyError, + _('\'Property "unknown" was not found in capability ' + '"database_endpoint" of node template "database" referenced ' + 'from node template "database".\'')) + + def test_get_input_in_properties(self): + mysql_dbms = self._get_node('mysql_dbms') + expected_inputs = ['db_root_pwd', 'db_port'] + props = mysql_dbms.get_properties() + for key in props.keys(): + prop = props[key] + self.assertIsInstance(prop.value, functions.GetInput) + expected_inputs.remove(prop.value.input_name) + self.assertListEqual(expected_inputs, []) + + def test_get_input_validation(self): + self.assertRaises( + exception.ValidationError, self._load_template, + 'functions/test_unknown_input_in_property.yaml') + exception.ExceptionCollector.assertExceptionMessage( + exception.UnknownInputError, + _('Unknown input "objectstore_name".')) + + self.assertRaises( + exception.ValidationError, self._load_template, + 'functions/test_unknown_input_in_interface.yaml') + exception.ExceptionCollector.assertExceptionMessage( + exception.UnknownInputError, + _('Unknown input "image_id".')) + + self.assertRaises( + exception.ValidationError, self._load_template, + 'functions/test_invalid_function_signature.yaml') + exception.ExceptionCollector.assertExceptionMessage( + ValueError, + _('Expected one argument for function "get_input" but received ' + '"[\'cpus\', \'cpus\']".')) + + def test_get_input_default_value_result(self): + mysql_dbms = self._get_node('mysql_dbms') + dbms_port = self._get_property(mysql_dbms, 'port') + self.assertEqual(3306, dbms_port.result()) + dbms_root_password = self._get_property(mysql_dbms, + 'root_password') + self.assertEqual(dbms_root_password.result(), '12345678') + + def test_get_property_with_host(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/functions/test_get_property_with_host.yaml") + mysql_database = self._get_node('mysql_database', + ToscaTemplate(tosca_tpl, + parsed_params={ + 'db_root_pwd': '123' + })) + operation = self._get_operation(mysql_database.interfaces, 'configure') + db_port = operation.inputs['db_port'] + self.assertIsInstance(db_port, functions.GetProperty) + result = db_port.result() + self.assertEqual(3306, result) + test = operation.inputs['test'] + self.assertIsInstance(test, functions.GetProperty) + result = test.result() + self.assertEqual(1, result) + + def test_get_property_with_nested_params(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/functions/tosca_nested_property_names_indexes.yaml") + webserver = self._get_node('wordpress', + ToscaTemplate(tosca_tpl, + parsed_params={ + 'db_root_pwd': '1234'})) + operation = self._get_operation(webserver.interfaces, 'configure') + wp_endpoint_prot = operation.inputs['wp_endpoint_protocol'] + self.assertIsInstance(wp_endpoint_prot, functions.GetProperty) + self.assertEqual('tcp', wp_endpoint_prot.result()) + wp_list_prop = operation.inputs['wp_list_prop'] + self.assertIsInstance(wp_list_prop, functions.GetProperty) + self.assertEqual(3, wp_list_prop.result()) + + def test_get_property_with_capabilties_inheritance(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/functions/test_capabilties_inheritance.yaml") + some_node = self._get_node('some_node', + ToscaTemplate(tosca_tpl, + parsed_params={ + 'db_root_pwd': '1234'})) + operation = self._get_operation(some_node.interfaces, 'configure') + some_input = operation.inputs['some_input'] + self.assertIsInstance(some_input, functions.GetProperty) + self.assertEqual('someval', some_input.result()) + + def test_get_property_source_target_keywords(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/functions/test_get_property_source_target_keywords.yaml") + tosca = ToscaTemplate(tosca_tpl, + parsed_params={'db_root_pwd': '1234'}) + + for node in tosca.nodetemplates: + for relationship, trgt in node.relationships.items(): + rel_template = trgt.get_relationship_template()[0] + break + + operation = self._get_operation(rel_template.interfaces, + 'pre_configure_source') + target_test = operation.inputs['target_test'] + self.assertIsInstance(target_test, functions.GetProperty) + self.assertEqual(1, target_test.result()) + source_port = operation.inputs['source_port'] + self.assertIsInstance(source_port, functions.GetProperty) + self.assertEqual(3306, source_port.result()) + + +class GetAttributeTest(TestCase): + + def _load_template(self, filename): + return ToscaTemplate(os.path.join( + os.path.dirname(os.path.abspath(__file__)), + 'data', + filename), + parsed_params={'db_root_pwd': '1234'}) + + def _get_operation(self, interfaces, operation): + return [ + interface for interface in interfaces + if interface.name == operation][0] + + def test_get_attribute_in_outputs(self): + tpl = self._load_template('tosca_single_instance_wordpress.yaml') + website_url_output = [ + x for x in tpl.outputs if x.name == 'website_url'][0] + self.assertIsInstance(website_url_output.value, functions.GetAttribute) + self.assertEqual('server', website_url_output.value.node_template_name) + self.assertEqual('private_address', + website_url_output.value.attribute_name) + + def test_get_attribute_invalid_args(self): + expected_msg = _('Illegal arguments for function "get_attribute".' + ' Expected arguments: "node-template-name", ' + '"req-or-cap"(optional), "property name"') + err = self.assertRaises(ValueError, + functions.get_function, None, None, + {'get_attribute': []}) + self.assertIn(expected_msg, six.text_type(err)) + err = self.assertRaises(ValueError, + functions.get_function, None, None, + {'get_attribute': ['x']}) + self.assertIn(expected_msg, six.text_type(err)) + + def test_get_attribute_unknown_node_template_name(self): + self.assertRaises( + exception.ValidationError, self._load_template, + 'functions/test_get_attribute_unknown_node_template_name.yaml') + exception.ExceptionCollector.assertExceptionMessage( + KeyError, + _('\'Node template "unknown_node_template" was not found.\'')) + + def test_get_attribute_unknown_attribute(self): + self.assertRaises( + exception.ValidationError, self._load_template, + 'functions/test_get_attribute_unknown_attribute_name.yaml') + exception.ExceptionCollector.assertExceptionMessage( + KeyError, + _('\'Attribute "unknown_attribute" was not found in node template ' + '"server".\'')) + + def test_get_attribute_host_keyword(self): + tpl = self._load_template( + 'functions/test_get_attribute_host_keyword.yaml') + + def assert_get_attribute_host_functionality(node_template_name): + node = [x for x in tpl.nodetemplates + if x.name == node_template_name][0] + configure_op = [ + x for x in node.interfaces if x.name == 'configure'][0] + ip_addr_input = configure_op.inputs['ip_address'] + self.assertIsInstance(ip_addr_input, functions.GetAttribute) + self.assertEqual('server', + ip_addr_input.get_referenced_node_template().name) + + assert_get_attribute_host_functionality('dbms') + assert_get_attribute_host_functionality('database') + + def test_get_attribute_host_not_found(self): + self.assertRaises( + exception.ValidationError, self._load_template, + 'functions/test_get_attribute_host_not_found.yaml') + exception.ExceptionCollector.assertExceptionMessage( + ValueError, + _('"get_attribute: [ HOST, ... ]" was used in node template ' + '"server" but "tosca.relationships.HostedOn" was not found in ' + 'the relationship chain.')) + + def test_get_attribute_illegal_host_in_outputs(self): + self.assertRaises( + exception.ValidationError, self._load_template, + 'functions/test_get_attribute_illegal_host_in_outputs.yaml') + exception.ExceptionCollector.assertExceptionMessage( + ValueError, + _('"get_attribute: [ HOST, ... ]" is not allowed in "outputs" ' + 'section of the TOSCA template.')) + + def test_get_attribute_with_index(self): + self._load_template( + 'functions/test_get_attribute_with_index.yaml') + + def test_get_attribute_with_index_error(self): + self.assertRaises( + exception.ValidationError, self._load_template, + 'functions/test_get_attribute_with_index_error.yaml') + exception.ExceptionCollector.assertExceptionMessage( + ValueError, + _('Illegal arguments for function "get_attribute". ' + 'Unexpected attribute/index value "0"')) + + def test_get_attribute_source_target_keywords(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/functions/test_get_attribute_source_target_keywords.yaml") + tosca = ToscaTemplate(tosca_tpl, + parsed_params={'db_root_pwd': '12345678'}) + + for node in tosca.nodetemplates: + for relationship, trgt in node.relationships.items(): + rel_template = trgt.get_relationship_template()[0] + break + + operation = self._get_operation(rel_template.interfaces, + 'pre_configure_source') + target_test = operation.inputs['target_test'] + self.assertIsInstance(target_test, functions.GetAttribute) + source_port = operation.inputs['source_port'] + self.assertIsInstance(source_port, functions.GetAttribute) + + def test_get_attribute_with_nested_params(self): + self._load_template( + 'functions/test_get_attribute_with_nested_params.yaml') + + def test_implicit_attribute(self): + self.assertIsNotNone(self._load_template( + 'functions/test_get_implicit_attribute.yaml')) + + +class ConcatTest(TestCase): + + def _load_template(self, filename): + return ToscaTemplate(os.path.join( + os.path.dirname(os.path.abspath(__file__)), + filename)) + + def test_validate_concat(self): + tosca = self._load_template("data/functions/test_concat.yaml") + server_url_output = [ + output for output in tosca.outputs if output.name == 'url'][0] + func = functions.get_function(self, tosca.outputs, + server_url_output.value) + self.assertIsInstance(func, functions.Concat) + + self.assertRaises(exception.ValidationError, self._load_template, + 'data/functions/test_concat_invalid.yaml') + exception.ExceptionCollector.assertExceptionMessage( + ValueError, + _('Invalid arguments for function "concat". Expected at least ' + 'one arguments.')) + + +class TokenTest(TestCase): + + def _load_template(self, filename): + return ToscaTemplate(os.path.join( + os.path.dirname(os.path.abspath(__file__)), + filename)) + + def test_validate_token(self): + tosca = self._load_template("data/functions/test_token.yaml") + server_url_output = [ + output for output in tosca.outputs if output.name == 'url'][0] + func = functions.get_function(self, tosca.outputs, + server_url_output.value) + self.assertIsInstance(func, functions.Token) + + self.assertRaises(exception.ValidationError, self._load_template, + 'data/functions/test_token_invalid.yaml') + exception.ExceptionCollector.assertExceptionMessage( + ValueError, + _('Invalid arguments for function "token". Expected at least ' + 'three arguments.')) + exception.ExceptionCollector.assertExceptionMessage( + ValueError, + _('Invalid arguments for function "token". Expected ' + 'integer value as third argument.')) + exception.ExceptionCollector.assertExceptionMessage( + ValueError, + _('Invalid arguments for function "token". Expected ' + 'single char value as second argument.')) diff --git a/nfvparser/toscaparser/tests/test_prereq.py b/nfvparser/toscaparser/tests/test_prereq.py new file mode 100644 index 0000000..11f4471 --- /dev/null +++ b/nfvparser/toscaparser/tests/test_prereq.py @@ -0,0 +1,230 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import os +import shutil +import zipfile + +from toscaparser.common.exception import URLException +from toscaparser.common.exception import ValidationError +from toscaparser.prereq.csar import CSAR +from toscaparser.tests.base import TestCase +import toscaparser.utils +from toscaparser.utils.gettextutils import _ + + +class CSARPrereqTest(TestCase): + + base_path = os.path.dirname(os.path.abspath(__file__)) + + def test_file_exists(self): + path = os.path.join(self.base_path, "data/CSAR/csar_not_there.zip") + csar = CSAR(path) + error = self.assertRaises(ValidationError, csar.validate) + self.assertEqual(_('"%s" does not exist.') % path, str(error)) + self.assertTrue(csar.temp_dir is None or + not os.path.exists(csar.temp_dir)) + + def test_file_is_zip(self): + path = os.path.join(self.base_path, "data/CSAR/csar_not_zip.zip") + csar = CSAR(path) + error = self.assertRaises(ValidationError, csar.validate) + self.assertEqual(_('"%s" is not a valid zip file.') % path, str(error)) + + def test_url_is_zip(self): + path = "https://github.com/openstack/tosca-parser/raw/master/" \ + "toscaparser/tests/data/CSAR/csar_not_zip.zip" + csar = CSAR(path, False) + error = self.assertRaises(ValidationError, csar.validate) + self.assertEqual(_('"%s" is not a valid zip file.') % path, str(error)) + self.assertTrue(csar.temp_dir is None or + not os.path.exists(csar.temp_dir)) + + def test_metadata_file_exists(self): + path = os.path.join(self.base_path, + "data/CSAR/csar_no_metadata_file.zip") + csar = CSAR(path) + error = self.assertRaises(ValidationError, csar.validate) + self.assertEqual(_('"%s" is not a valid CSAR as it does not contain ' + 'the required file "TOSCA.meta" in the folder ' + '"TOSCA-Metadata".') % path, str(error)) + self.assertTrue(csar.temp_dir is None or + not os.path.exists(csar.temp_dir)) + + def test_valid_metadata_file_exists(self): + path = os.path.join(self.base_path, + "data/CSAR/csar_wrong_metadata_file.zip") + csar = CSAR(path) + error = self.assertRaises(ValidationError, csar.validate) + self.assertEqual(_('"%s" is not a valid CSAR as it does not contain ' + 'the required file "TOSCA.meta" in the folder ' + '"TOSCA-Metadata".') % path, str(error)) + self.assertTrue(csar.temp_dir is None or + not os.path.exists(csar.temp_dir)) + + def test_metadata_is_yaml(self): + path = os.path.join(self.base_path, + "data/CSAR/csar_metadata_not_yaml.zip") + csar = CSAR(path) + error = self.assertRaises(ValidationError, csar.validate) + self.assertEqual(_('The file "TOSCA-Metadata/TOSCA.meta" in the CSAR ' + '"%s" does not contain valid YAML content.') % path, + str(error)) + self.assertTrue(csar.temp_dir is None or + not os.path.exists(csar.temp_dir)) + + def test_metadata_exists(self): + path = os.path.join(self.base_path, + "data/CSAR/csar_missing_metadata.zip") + csar = CSAR(path) + error = self.assertRaises(ValidationError, csar.validate) + self.assertEqual(_('The CSAR "%s" is missing the required metadata ' + '"Entry-Definitions" in ' + '"TOSCA-Metadata/TOSCA.meta".') % path, str(error)) + self.assertTrue(csar.temp_dir is None or + not os.path.exists(csar.temp_dir)) + + def test_entry_def_exists(self): + path = os.path.join(self.base_path, + "data/CSAR/csar_invalid_entry_def.zip") + csar = CSAR(path) + error = self.assertRaises(ValidationError, csar.validate) + self.assertEqual(_('The "Entry-Definitions" file defined in the CSAR ' + '"%s" does not exist.') % path, str(error)) + self.assertTrue(csar.temp_dir is None or + not os.path.exists(csar.temp_dir)) + + def test_csar_invalid_import_path(self): + path = os.path.join(self.base_path, + "data/CSAR/csar_wordpress_invalid_import_path.zip") + csar = CSAR(path) + error = self.assertRaises(ImportError, csar.validate) + self.assertEqual(_('Import "Invalid_import_path/wordpress.yaml" is' + ' not valid.'), str(error)) + self.assertTrue(csar.temp_dir is None or + not os.path.exists(csar.temp_dir)) + + def test_csar_invalid_import_url(self): + path = os.path.join(self.base_path, + "data/CSAR/csar_wordpress_invalid_import_url.zip") + csar = CSAR(path) + error = self.assertRaises(URLException, csar.validate) + self.assertEqual(_('Failed to reach server ' + '"https://raw.githubusercontent.com/openstack/' + 'tosca-parser/master/toscaparser/tests/data/CSAR/' + 'tosca_single_instance_wordpress/Definitions/' + 'wordpress1.yaml". Reason is: Not Found.'), + str(error)) + self.assertTrue(csar.temp_dir is None or + not os.path.exists(csar.temp_dir)) + + def test_csar_invalid_script_path(self): + path = os.path.join(self.base_path, + "data/CSAR/csar_wordpress_invalid_script_path.zip") + csar = CSAR(path) + error = self.assertRaises(ValueError, csar.validate) + self.assertTrue( + str(error) == _('The resource "Scripts/WordPress/install.sh" does ' + 'not exist.') or + str(error) == _('The resource "Scripts/WordPress/configure.sh" ' + 'does not exist.')) + self.assertTrue(csar.temp_dir is None or + not os.path.exists(csar.temp_dir)) + + def test_csar_invalid_script_url(self): + path = os.path.join(self.base_path, + "data/CSAR/csar_wordpress_invalid_script_url.zip") + csar = CSAR(path) + error = self.assertRaises(URLException, csar.validate) + self.assertEqual(_('The resource at ' + '"https://raw.githubusercontent.com/openstack/' + 'tosca-parser/master/toscaparser/tests/data/CSAR/' + 'tosca_single_instance_wordpress/Scripts/WordPress/' + 'install1.sh" cannot be accessed.'), + str(error)) + self.assertTrue(csar.temp_dir is None or + not os.path.exists(csar.temp_dir)) + + def test_valid_csar(self): + path = os.path.join(self.base_path, "data/CSAR/csar_hello_world.zip") + csar = CSAR(path) + self.assertTrue(csar.validate()) + self.assertTrue(csar.temp_dir is None or + not os.path.exists(csar.temp_dir)) + + def test_valid_csar_with_url_import_and_script(self): + path = os.path.join(self.base_path, "data/CSAR/csar_wordpress_with_url" + "_import_and_script.zip") + csar = CSAR(path) + self.assertTrue(csar.validate()) + self.assertTrue(csar.temp_dir is None or + not os.path.exists(csar.temp_dir)) + + def test_metadata_invalid_csar(self): + path = os.path.join(self.base_path, + "data/CSAR/csar_metadata_not_yaml.zip") + csar = CSAR(path) + error = self.assertRaises(ValidationError, csar.get_author) + self.assertEqual(_('The file "TOSCA-Metadata/TOSCA.meta" in the CSAR ' + '"%s" does not contain valid YAML content.') % path, + str(error)) + self.assertTrue(csar.temp_dir is None or + not os.path.exists(csar.temp_dir)) + + def test_metadata_valid_csar(self): + path = os.path.join(self.base_path, "data/CSAR/csar_hello_world.zip") + csar = CSAR(path) + expected_meta = {'TOSCA-Meta-File-Version': 1.0, + 'CSAR-Version': 1.1, + 'Created-By': 'OASIS TOSCA TC', + 'Entry-Definitions': 'tosca_helloworld.yaml'} + self.assertEqual(expected_meta, csar.get_metadata(), + 'The extracted metadata of the CSAR %(csar)s does ' + 'not match the expected metadata %(meta)s' + % {'csar': path, 'meta': expected_meta.__str__()}) + self.assertEqual(1.1, csar.get_version()) + self.assertEqual('OASIS TOSCA TC', csar.get_author()) + self.assertEqual('tosca_helloworld.yaml', csar.get_main_template()) + self.assertEqual('Template for deploying a single server with ' + 'predefined properties.', csar.get_description()) + self.assertTrue(csar.temp_dir is None or + not os.path.exists(csar.temp_dir)) + + def test_csar_main_template(self): + path = os.path.join(self.base_path, "data/CSAR/csar_hello_world.zip") + csar = CSAR(path) + yaml_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), + "data/tosca_helloworld.yaml") + expected_yaml = toscaparser.utils.yamlparser.load_yaml(yaml_file) + self.assertEqual(expected_yaml, csar.get_main_template_yaml()) + self.assertTrue(csar.temp_dir is None or + not os.path.exists(csar.temp_dir)) + + def test_decompress(self): + path = os.path.join(self.base_path, "data/CSAR/csar_hello_world.zip") + csar = CSAR(path) + csar.decompress() + zf = zipfile.ZipFile(path) + for name in zf.namelist(): + tmp_path = os.path.join(csar.temp_dir, name) + self.assertTrue(os.path.isdir(tmp_path) or + os.path.isfile(tmp_path)) + shutil.rmtree(csar.temp_dir) + self.assertTrue(csar.temp_dir is None or + not os.path.exists(csar.temp_dir)) + + def test_alternate_csar_extension(self): + path = os.path.join(self.base_path, "data/CSAR/csar_elk.csar") + csar = CSAR(path) + self.assertTrue(csar.validate()) + self.assertTrue(csar.temp_dir is None or + not os.path.exists(csar.temp_dir)) diff --git a/nfvparser/toscaparser/tests/test_properties.py b/nfvparser/toscaparser/tests/test_properties.py new file mode 100644 index 0000000..6b95537 --- /dev/null +++ b/nfvparser/toscaparser/tests/test_properties.py @@ -0,0 +1,368 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from testtools import matchers + +from toscaparser.common import exception +from toscaparser.elements.property_definition import PropertyDef +from toscaparser.nodetemplate import NodeTemplate +from toscaparser.properties import Property +from toscaparser.tests.base import TestCase +from toscaparser.utils.gettextutils import _ +from toscaparser.utils import yamlparser + + +class PropertyTest(TestCase): + + def test_type(self): + test_property_schema = {'type': 'string'} + propertyInstance = Property('test_property', 'Hughes', + test_property_schema) + self.assertEqual('string', propertyInstance.type) + + def test_type_invalid(self): + test_property_schema = {'type': 'Fish'} + propertyInstance = Property('test_property', 'Hughes', + test_property_schema) + error = self.assertRaises(exception.InvalidTypeError, + propertyInstance.validate) + self.assertEqual(_('Type "Fish" is not a valid type.'), str(error)) + + def test_list(self): + test_property_schema = {'type': 'list'} + propertyInstance = Property('test_property', ['a', 'b'], + test_property_schema) + self.assertIsNone(propertyInstance.validate()) + self.assertEqual(['a', 'b'], propertyInstance.value) + + def test_list_invalid(self): + test_property_schema = {'type': 'list'} + propertyInstance = Property('test_property', 'a', + test_property_schema) + error = self.assertRaises(ValueError, propertyInstance.validate) + self.assertEqual(_('"a" is not a list.'), str(error)) + + def test_list_entry_schema(self): + test_property_schema = {'type': 'list', + 'entry_schema': {'type': 'string'}} + propertyInstance = Property('test_property', ['a', 'b'], + test_property_schema) + self.assertIsNone(propertyInstance.validate()) + self.assertEqual(['a', 'b'], propertyInstance.value) + + schema_snippet = ''' + type: list + entry_schema: + type: string + constraints: + - min_length: 2 + ''' + test_property_schema = yamlparser.simple_parse(schema_snippet) + propertyInstance = Property('test_property', ['ab', 'cd'], + test_property_schema) + self.assertIsNone(propertyInstance.validate()) + self.assertEqual(['ab', 'cd'], propertyInstance.value) + + def test_list_entry_schema_invalid(self): + test_property_schema = {'type': 'list', + 'entry_schema': {'type': 'integer'}} + propertyInstance = Property('test_property', [1, 'b'], + test_property_schema) + error = self.assertRaises(ValueError, propertyInstance.validate) + self.assertEqual(_('"b" is not an integer.'), str(error)) + + def test_map(self): + test_property_schema = {'type': 'map'} + propertyInstance = Property('test_property', {'a': 'b'}, + test_property_schema) + self.assertIsNone(propertyInstance.validate()) + self.assertEqual({'a': 'b'}, propertyInstance.value) + + def test_map_invalid(self): + test_property_schema = {'type': 'map'} + propertyInstance = Property('test_property', 12, + test_property_schema) + error = self.assertRaises(ValueError, propertyInstance.validate) + self.assertEqual(_('"12" is not a map.'), str(error)) + + def test_map_entry_schema(self): + test_property_schema = {'type': 'map', + 'entry_schema': {'type': 'boolean'}} + propertyInstance = Property('test_property', + {'valid': True, 'required': True}, + test_property_schema) + self.assertIsNone(propertyInstance.validate()) + self.assertEqual({'valid': True, 'required': True}, + propertyInstance.value) + + def test_map_entry_schema_invalid(self): + test_property_schema = {'type': 'map', + 'entry_schema': {'type': 'boolean'}} + propertyInstance = Property('test_property', + {'valid': True, 'contact_name': 123}, + test_property_schema) + error = self.assertRaises(ValueError, propertyInstance.validate) + self.assertEqual(_('"123" is not a boolean.'), str(error)) + + def test_boolean(self): + test_property_schema = {'type': 'boolean'} + propertyInstance = Property('test_property', 'true', + test_property_schema) + self.assertIsNone(propertyInstance.validate()) + propertyInstance = Property('test_property', True, + test_property_schema) + self.assertIsNone(propertyInstance.validate()) + self.assertEqual(True, propertyInstance.value) + + def test_boolean_invalid(self): + test_property_schema = {'type': 'boolean'} + propertyInstance = Property('test_property', 12, + test_property_schema) + error = self.assertRaises(ValueError, propertyInstance.validate) + self.assertEqual(_('"12" is not a boolean.'), str(error)) + + def test_float(self): + test_property_schema = {'type': 'float'} + propertyInstance = Property('test_property', 0.1, + test_property_schema) + self.assertIsNone(propertyInstance.validate()) + self.assertEqual(0.1, propertyInstance.value) + + def test_float_invalid(self): + test_property_schema = {'type': 'float'} + propertyInstance = Property('test_property', 12, + test_property_schema) + error = self.assertRaises(ValueError, propertyInstance.validate) + self.assertEqual(_('"12" is not a float.'), str(error)) + + def test_timestamp(self): + test_property_schema = {'type': 'timestamp'} + # canonical timestamp + propertyInstance = Property('test_property', '2015-04-01T02:59:43.1Z', + test_property_schema) + self.assertIsNone(propertyInstance.validate()) + self.assertEqual("2015-04-01T02:59:43.1Z", propertyInstance.value) + + # iso8601 timestamp + propertyInstance = Property('test_property', + '2015-04-01t21:59:43.10-05:00', + test_property_schema) + self.assertIsNone(propertyInstance.validate()) + self.assertEqual("2015-04-01t21:59:43.10-05:00", + propertyInstance.value) + + # space separated timestamp + propertyInstance = Property('test_property', + '2015-04-01 21:59:43.10 -5', + test_property_schema) + self.assertIsNone(propertyInstance.validate()) + self.assertEqual("2015-04-01 21:59:43.10 -5", propertyInstance.value) + + # no time zone timestamp + propertyInstance = Property('test_property', '2015-04-01 21:59:43.10', + test_property_schema) + self.assertIsNone(propertyInstance.validate()) + self.assertEqual("2015-04-01 21:59:43.10", propertyInstance.value) + + # date (00:00:00Z) + propertyInstance = Property('test_property', '2015-04-01', + test_property_schema) + self.assertIsNone(propertyInstance.validate()) + self.assertEqual("2015-04-01", propertyInstance.value) + + def test_timestamp_invalid(self): + test_property_schema = {'type': 'timestamp'} + # invalid timestamp - day out of range + value = '2015-04-115T02:59:43.1Z' + propertyInstance = Property('test_property', value, + test_property_schema) + error = self.assertRaises(ValueError, propertyInstance.validate) + expected_message = (_('"%s" is not a valid timestamp.') % value) + self.assertThat(str(error), matchers.StartsWith(expected_message)) + + def test_required(self): + test_property_schema = {'type': 'string'} + propertyInstance = Property('test_property', 'Foo', + test_property_schema) + self.assertEqual(True, propertyInstance.required) + + def test_proprety_inheritance(self): + + tosca_custom_def = ''' + tosca.nodes.SoftwareComponent.MySoftware: + derived_from: SoftwareComponent + properties: + install_path: + required: false + type: string + default: /opt/mysoftware + ''' + + tosca_node_template = ''' + node_templates: + mysoftware_instance: + type: tosca.nodes.SoftwareComponent.MySoftware + properties: + component_version: 3.1 + ''' + + expected_properties = ['component_version', + 'install_path'] + + tpl = self._get_nodetemplate(tosca_node_template, tosca_custom_def) + self.assertIsNone(tpl.validate()) + self.assertEqual(expected_properties, + sorted(tpl.get_properties().keys())) + + def test_missing_property_type(self): + tpl_snippet = ''' + properties: + prop: + typo: tosca.mytesttype.Test + ''' + schema = yamlparser.simple_parse(tpl_snippet) + error = self.assertRaises(exception.InvalidSchemaError, PropertyDef, + 'prop', None, schema['properties']['prop']) + self.assertEqual(_('Schema definition of "prop" must have a "type" ' + 'attribute.'), str(error)) + + def test_invalid_required_value(self): + tpl_snippet = ''' + properties: + prop: + type: tosca.mytesttype.Test + required: dunno + ''' + schema = yamlparser.simple_parse(tpl_snippet) + error = self.assertRaises(exception.InvalidSchemaError, PropertyDef, + 'prop', None, schema['properties']['prop']) + + valid_values = ', '.join(PropertyDef.VALID_REQUIRED_VALUES) + expected_message = (_('Schema definition of "prop" has "required" ' + 'attribute with invalid value "dunno". The ' + 'value must be one of "%s".') % valid_values) + self.assertEqual(expected_message, str(error)) + + def test_invalid_property_status(self): + tpl_snippet = ''' + properties: + prop: + type: string + status: unknown + ''' + schema = yamlparser.simple_parse(tpl_snippet) + error = self.assertRaises(exception.InvalidSchemaError, PropertyDef, + 'prop', None, schema['properties']['prop']) + + valid_values = ', '.join(PropertyDef.VALID_STATUS_VALUES) + expected_message = (_('Schema definition of "prop" has "status" ' + 'attribute with invalid value "unknown". The ' + 'value must be one of "%s".') % valid_values) + self.assertEqual(expected_message, str(error)) + + def test_capability_proprety_inheritance(self): + tosca_custom_def_example1 = ''' + tosca.capabilities.ScalableNew: + derived_from: tosca.capabilities.Scalable + properties: + max_instances: + type: integer + default: 0 + required: no + + tosca.nodes.ComputeNew: + derived_from: tosca.nodes.Compute + capabilities: + scalable: + type: tosca.capabilities.ScalableNew + ''' + + tosca_node_template_example1 = ''' + node_templates: + compute_instance: + type: tosca.nodes.ComputeNew + capabilities: + scalable: + properties: + min_instances: 1 + ''' + + tosca_custom_def_example2 = ''' + tosca.nodes.ComputeNew: + derived_from: tosca.nodes.Compute + capabilities: + new_cap: + type: tosca.capabilities.Scalable + ''' + + tosca_node_template_example2 = ''' + node_templates: + db_server: + type: tosca.nodes.ComputeNew + capabilities: + host: + properties: + num_cpus: 1 + ''' + + tpl1 = self._get_nodetemplate(tosca_node_template_example1, + tosca_custom_def_example1) + self.assertIsNone(tpl1.validate()) + + tpl2 = self._get_nodetemplate(tosca_node_template_example2, + tosca_custom_def_example2) + self.assertIsNone(tpl2.validate()) + + def _get_nodetemplate(self, tpl_snippet, + custom_def_snippet=None): + nodetemplates = yamlparser.\ + simple_parse(tpl_snippet)['node_templates'] + custom_def = [] + if custom_def_snippet: + custom_def = yamlparser.simple_parse(custom_def_snippet) + name = list(nodetemplates.keys())[0] + tpl = NodeTemplate(name, nodetemplates, custom_def) + return tpl + + def test_explicit_relationship_proprety(self): + + tosca_node_template = ''' + node_templates: + + client_node: + type: tosca.nodes.Compute + requirements: + - local_storage: + node: my_storage + relationship: + type: AttachesTo + properties: + location: /mnt/disk + + my_storage: + type: tosca.nodes.BlockStorage + properties: + size: 1 GB + ''' + + expected_properties = ['location'] + + nodetemplates = yamlparser.\ + simple_parse(tosca_node_template)['node_templates'] + tpl = NodeTemplate('client_node', nodetemplates, []) + + self.assertIsNone(tpl.validate()) + rel_tpls = [] + for relationship, trgt in tpl.relationships.items(): + rel_tpls.extend(trgt.get_relationship_template()) + self.assertEqual(expected_properties, + sorted(rel_tpls[0].get_properties().keys())) diff --git a/nfvparser/toscaparser/tests/test_scalarunit.py b/nfvparser/toscaparser/tests/test_scalarunit.py new file mode 100644 index 0000000..09a24b6 --- /dev/null +++ b/nfvparser/toscaparser/tests/test_scalarunit.py @@ -0,0 +1,355 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from toscaparser.common import exception +from toscaparser.elements.scalarunit import ScalarUnit_Frequency +from toscaparser.elements.scalarunit import ScalarUnit_Size +from toscaparser.elements.scalarunit import ScalarUnit_Time +from toscaparser.nodetemplate import NodeTemplate +from toscaparser.tests.base import TestCase +from toscaparser.utils.gettextutils import _ +from toscaparser.utils import yamlparser + + +class ScalarUnitPositiveTest(TestCase): + + scenarios = [ + ( + # tpl_snippet with mem_size given as number+space+MB + 'mem_size_is_number_Space_MB', + dict(tpl_snippet=''' + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + mem_size: 1024 MB + ''', + property='mem_size', + expected='1024 MB') + ), + ( + # tpl_snippet with mem_size given as number+spaces+GB + 'mem_size_is_number_Space_GB', + dict(tpl_snippet=''' + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + mem_size: 1 GB + ''', + property='mem_size', + expected='1 GB') + ), + ( + # tpl_snippet with mem_size given as number+tiB + 'mem_size_is_number_NoSpace_GB', + dict(tpl_snippet=''' + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + mem_size: 1tiB + ''', + property='mem_size', + expected='1 TiB') + ), + ( + # tpl_snippet with mem_size given as number+Spaces+GIB + 'mem_size_is_number_Spaces_GB', + dict(tpl_snippet=''' + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + mem_size: 1 GIB + ''', + property='mem_size', + expected='1 GiB') + ), + ( + # tpl_snippet with mem_size given as number+Space+tib + 'mem_size_is_number_Spaces_GB', + dict(tpl_snippet=''' + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + mem_size: 1 tib + ''', + property='mem_size', + expected='1 TiB') + ), + ( + 'cpu_frequency_is_float_Space_GHz', + dict(tpl_snippet=''' + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + cpu_frequency: 2.5 GHz + ''', + property='cpu_frequency', + expected='2.5 GHz') + ), + ( + 'cpu_frequency_is_float_Space_MHz', + dict(tpl_snippet=''' + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + cpu_frequency: 800 MHz + ''', + property='cpu_frequency', + expected='800 MHz') + ), + ] + + def test_scenario_scalar_unit_positive(self): + tpl = self.tpl_snippet + nodetemplates = yamlparser.simple_parse(tpl) + nodetemplate = NodeTemplate('server', nodetemplates) + props = nodetemplate.get_capability('host').get_properties() + prop_name = self.property + if props and prop_name in props.keys(): + prop = props[prop_name] + self.assertIsNone(prop.validate()) + resolved = prop.value + self.assertEqual(resolved, self.expected) + + +class GetNumFromScalarUnitSizePositive(TestCase): + + scenarios = [ + ( # Note that (1 TB) / (1 GB) = 1000 + 'Input is TB, user input is GB', + dict(InputMemSize='1 TB', + UserInputUnit='gB', + expected=1000) + ), + ( # Note that (1 Tib)/ (1 GB) = 1099 + 'Input is TiB, user input is GB', + dict(InputMemSize='1 TiB', + UserInputUnit='gB', + expected=1099.511627776) + ), + ] + + def test_scenario_get_num_from_scalar_unit_size(self): + resolved = (ScalarUnit_Size(self.InputMemSize). + get_num_from_scalar_unit(self.UserInputUnit)) + self.assertEqual(resolved, self.expected) + + +class GetNumFromScalarUnitFrequencyPositive(TestCase): + + scenarios = [ + ( # Note that (1 GHz) / (1 Hz) = 1000000000 + 'Input is GHz, user input is Hz', + dict(InputMemSize='1 GHz', + UserInputUnit='Hz', + expected=1000000000) + ), + ( + 'Input is GHz, user input is Hz', + dict(InputMemSize='2.4 GHz', + UserInputUnit='Hz', + expected=2400000000) + ), + ( # Note that (1 GHz)/ (1 MHz) = 1000 + 'Input is MHz, user input is GHz', + dict(InputMemSize='800 MHz', + UserInputUnit='GHz', + expected=0.8) + ), + ( + 'Input is GHz, user input is Hz', + dict(InputMemSize='0.9 GHz', + UserInputUnit='MHz', + expected=900) + ), + ( + 'Input is GHz, user input is Hz', + dict(InputMemSize='2.7GHz', + UserInputUnit='MHz', + expected=2700) + ), + ] + + def test_scenario_get_num_from_scalar_unit_frequency(self): + resolved = (ScalarUnit_Frequency(self.InputMemSize). + get_num_from_scalar_unit(self.UserInputUnit)) + self.assertEqual(resolved, self.expected) + + +class GetNumFromScalarUnitTimePositive(TestCase): + + scenarios = [ + ( # Note that (1 s) / (1 ms) = 1000 + 'Input is 500ms, user input is s', + dict(InputMemSize='500 ms', + UserInputUnit='s', + expected=0.5) + ), + ( # Note that (1 h)/ (1 s) = 3600 + 'Input is h, user input is s', + dict(InputMemSize='1 h', + UserInputUnit='s', + expected=3600) + ), + ( # Note that (1 m)/ (1 s) = 60 + 'Input is m, user input is s', + dict(InputMemSize='0.5 m', + UserInputUnit='s', + expected=30) + ), + ( # Note that (1 d)/ (1 h) = 24 + 'Input is d, user input is h', + dict(InputMemSize='1 d', + UserInputUnit='h', + expected=24) + ), + ] + + def test_scenario_get_num_from_scalar_unit_time(self): + resolved = (ScalarUnit_Time(self.InputMemSize). + get_num_from_scalar_unit(self.UserInputUnit)) + self.assertEqual(resolved, self.expected) + + +class GetNumFromScalarUnitSizeNegative(TestCase): + + InputMemSize = '1 GB' + UserInputUnit = 'qB' + + def test_get_num_from_scalar_unit_size_negative(self): + try: + (ScalarUnit_Size(self.InputMemSize). + get_num_from_scalar_unit(self.UserInputUnit)) + except Exception as error: + self.assertIsInstance(error, ValueError) + self.assertEqual(_('The unit "qB" is not valid. Valid units are ' + '"[\'B\', \'GB\', \'GiB\', \'KiB\', \'MB\', ' + '\'MiB\', \'TB\', \'TiB\', \'kB\']".'), + error.__str__()) + + +class GetNumFromScalarUnitFrequencyNegative(TestCase): + + InputFrequency = '2.7 GHz' + UserInputUnit = 'Jz' + + def test_get_num_from_scalar_unit_frequency_negative(self): + try: + (ScalarUnit_Frequency(self.InputFrequency). + get_num_from_scalar_unit(self.UserInputUnit)) + except Exception as error: + self.assertIsInstance(error, ValueError) + self.assertEqual(_('The unit "Jz" is not valid. Valid units are ' + '"[\'GHz\', \'Hz\', \'MHz\', \'kHz\']".'), + error.__str__()) + + +class GetNumFromScalarUnitTimeNegative(TestCase): + + InputTime = '5 ms' + UserInputUnit = 'D' + + def test_get_num_from_scalar_unit_frequency_negative(self): + try: + (ScalarUnit_Time(self.InputTime). + get_num_from_scalar_unit(self.UserInputUnit)) + except Exception as error: + self.assertIsInstance(error, ValueError) + self.assertEqual(_('"Jz" is not a valid scalar-unit.'), + error.__str__()) + + +class ScalarUnitNegativeTest(TestCase): + + custom_def_snippet = ''' + tosca.my.nodes.Compute: + derived_from: tosca.nodes.Root + properties: + cpu_frequency: + required: false + type: scalar-unit.frequency + constraints: + - greater_or_equal: 0.1 GHz + disk_size: + required: false + type: scalar-unit.size + constraints: + - greater_or_equal: 1 GB + mem_size: + required: false + type: scalar-unit.size + constraints: + - in_range: [1 MiB, 1 GiB] + ''' + custom_def = yamlparser.simple_parse(custom_def_snippet) + + # disk_size doesn't provide a value, mem_size uses an invalid unit. + def test_invalid_scalar_unit(self): + tpl_snippet = ''' + server: + type: tosca.my.nodes.Compute + properties: + cpu_frequency: 50.3.6 GHZ + disk_size: MB + mem_size: 1 QB + ''' + nodetemplates = yamlparser.simple_parse(tpl_snippet) + nodetemplate = NodeTemplate('server', nodetemplates, self.custom_def) + for p in nodetemplate.get_properties_objects(): + self.assertRaises(ValueError, p.validate) + + # disk_size is less than 1 GB, mem_size is not in the required range. + # Note: in the spec, the minimum value of mem_size is 1 MiB (> 1 MB) + def test_constraint_for_scalar_unit(self): + tpl_snippet = ''' + server: + type: tosca.my.nodes.Compute + properties: + cpu_frequency: 0.05 GHz + disk_size: 500 MB + mem_size: 1 MB + ''' + nodetemplates = yamlparser.simple_parse(tpl_snippet) + nodetemplate = NodeTemplate('server', nodetemplates, self.custom_def) + props = nodetemplate.get_properties() + if 'cpu_frequency' in props.keys(): + error = self.assertRaises(exception.ValidationError, + props['cpu_frequency'].validate) + self.assertEqual(_('The value "0.05 GHz" of property ' + '"cpu_frequency" must be greater than or equal ' + 'to "0.1 GHz".'), error.__str__()) + if 'disk_size' in props.keys(): + error = self.assertRaises(exception.ValidationError, + props['disk_size'].validate) + self.assertEqual(_('The value "500 MB" of property "disk_size" ' + 'must be greater than or equal to "1 GB".'), + error.__str__()) + + if 'mem_size' in props.keys(): + error = self.assertRaises(exception.ValidationError, + props['mem_size'].validate) + self.assertEqual(_('The value "1 MB" of property "mem_size" is ' + 'out of range "(min:1 MiB, max:1 GiB)".'), + error.__str__()) diff --git a/nfvparser/toscaparser/tests/test_shell.py b/nfvparser/toscaparser/tests/test_shell.py new file mode 100644 index 0000000..bb163ff --- /dev/null +++ b/nfvparser/toscaparser/tests/test_shell.py @@ -0,0 +1,51 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import os + +from toscaparser.common import exception +import toscaparser.shell as shell +from toscaparser.tests.base import TestCase +from toscaparser.utils.gettextutils import _ + + +class ShellTest(TestCase): + + tosca_helloworld = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/tosca_helloworld.yaml") + + errornous_template = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_multiple_validation_errors.yaml") + + def test_missing_arg(self): + self.assertRaises(SystemExit, shell.main, '') + + def test_invalid_arg(self): + self.assertRaises(SystemExit, shell.main, 'parse me') + + def test_template_not_exist(self): + error = self.assertRaises( + ValueError, shell.main, ['--template-file=template.txt']) + self.assertEqual(_('"template.txt" is not a valid file.'), str(error)) + + def test_template_invalid(self): + arg = '--template-file=' + self.errornous_template + self.assertRaises(exception.ValidationError, shell.main, [arg]) + + def test_template_valid(self): + arg = '--template-file=' + self.tosca_helloworld + try: + shell.main([arg]) + except Exception: + self.fail(_('The program raised an exception unexpectedly.')) diff --git a/nfvparser/toscaparser/tests/test_topology_template.py b/nfvparser/toscaparser/tests/test_topology_template.py new file mode 100644 index 0000000..3aabc9b --- /dev/null +++ b/nfvparser/toscaparser/tests/test_topology_template.py @@ -0,0 +1,313 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import os + +from toscaparser.common import exception +from toscaparser.substitution_mappings import SubstitutionMappings +from toscaparser.tests.base import TestCase +from toscaparser.topology_template import TopologyTemplate +from toscaparser.tosca_template import ToscaTemplate +from toscaparser.utils.gettextutils import _ +import toscaparser.utils.yamlparser + +YAML_LOADER = toscaparser.utils.yamlparser.load_yaml + + +class TopologyTemplateTest(TestCase): + + def setUp(self): + TestCase.setUp(self) + '''TOSCA template.''' + self.tosca_tpl_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/topology_template/transactionsubsystem.yaml") + self.tpl = YAML_LOADER(self.tosca_tpl_path) + self.topo_tpl = self.tpl.get('topology_template') + self.imports = self.tpl.get('imports') + self.topo = TopologyTemplate(self.topo_tpl, + self._get_all_custom_def()) + + def _get_custom_def(self, type_definition): + custom_defs = {} + for definition in self.imports: + if os.path.isabs(definition): + def_file = definition + else: + tpl_dir = os.path.dirname(os.path.abspath(self.tosca_tpl_path)) + def_file = os.path.join(tpl_dir, definition) + custom_type = YAML_LOADER(def_file) + custom_defs.update(custom_type.get(type_definition)) + return custom_defs + + def _get_all_custom_def(self): + custom_defs = {} + custom_defs.update(self._get_custom_def('node_types')) + custom_defs.update(self._get_custom_def('capability_types')) + return custom_defs + + def _get_custom_types(self): + custom_types = {} + def_file = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/topology_template/definitions.yaml") + custom_type = YAML_LOADER(def_file) + node_types = custom_type['node_types'] + for name in node_types: + defintion = node_types[name] + custom_types[name] = defintion + return custom_types + + def test_description(self): + expected_desc = 'Template of a database including its hosting stack.' + self.assertEqual(expected_desc, self.topo.description) + + def test_inputs(self): + self.assertEqual( + ['mq_server_ip', 'my_cpus', 'receiver_port'], + sorted([input.name for input in self.topo.inputs])) + + input_name = "receiver_port" + expected_description = "Port to be used for receiving messages." + for input in self.topo.inputs: + if input.name == input_name: + self.assertEqual(expected_description, input.description) + + def test_node_tpls(self): + '''Test nodetemplate names.''' + self.assertEqual( + ['app', 'server', 'websrv'], + sorted([tpl.name for tpl in self.topo.nodetemplates])) + + tpl_name = "app" + expected_type = "example.SomeApp" + expected_properties = ['admin_user', 'pool_size'] + expected_capabilities = ['feature', 'message_receiver'] + expected_requirements = [{'host': {'node': 'websrv'}}] + expected_relationshp = ['tosca.relationships.HostedOn'] + expected_host = ['websrv'] + for tpl in self.topo.nodetemplates: + if tpl_name == tpl.name: + '''Test node type.''' + self.assertEqual(tpl.type, expected_type) + + '''Test properties.''' + self.assertEqual( + expected_properties, + sorted(tpl.get_properties().keys())) + + '''Test capabilities.''' + self.assertEqual( + expected_capabilities, + sorted(tpl.get_capabilities().keys())) + + '''Test requirements.''' + self.assertEqual( + expected_requirements, tpl.requirements) + + '''Test relationship.''' + ''' TODO : skip tempororily. need to fix it + ''' + self.assertEqual( + expected_relationshp, + [x.type for x in tpl.relationships.keys()]) + self.assertEqual( + expected_host, + [y.name for y in tpl.relationships.values()]) + '''Test interfaces.''' + # TODO(hurf) add interface test when new template is available + + if tpl.name == 'server': + '''Test property value''' + props = tpl.get_properties() + if props and 'mem_size' in props.keys(): + self.assertEqual(props['mem_size'].value, '4096 MB') + '''Test capability''' + caps = tpl.get_capabilities() + self.assertIn('os', caps.keys()) + os_props_objs = None + os_props = None + os_type_prop = None + if caps and 'os' in caps.keys(): + capability = caps['os'] + os_props_objs = capability.get_properties_objects() + os_props = capability.get_properties() + os_type_prop = capability.get_property_value('type') + break + self.assertEqual( + ['Linux'], + [p.value for p in os_props_objs if p.name == 'type']) + self.assertEqual( + 'Linux', + os_props['type'].value if 'type' in os_props else '') + self.assertEqual('Linux', os_props['type'].value) + self.assertEqual('Linux', os_type_prop) + + def test_outputs(self): + self.assertEqual( + sorted(['receiver_ip', 'receiver_port']), + sorted([output.name for output in self.topo.outputs])) + + def test_groups(self): + group = self.topo.groups[0] + self.assertEqual('webserver_group', group.name) + self.assertEqual(['websrv', 'server'], group.members) + for node in group.get_member_nodes(): + if node.name == 'server': + '''Test property value''' + props = node.get_properties() + if props and 'mem_size' in props.keys(): + self.assertEqual(props['mem_size'].value, '4096 MB') + + def test_system_template(self): + tpl_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/topology_template/system.yaml") + system_tosca_template = ToscaTemplate(tpl_path) + self.assertIsNotNone(system_tosca_template) + self.assertEqual( + len(system_tosca_template. + nested_tosca_templates_with_topology), 4) + self.assertTrue(system_tosca_template.has_nested_templates()) + + def test_invalid_keyname(self): + tpl_snippet = ''' + substitution_mappings: + node_type: example.DatabaseSubsystem + capabilities: + database_endpoint: [ db_app, database_endpoint ] + requirements: + receiver1: [ tran_app, receiver1 ] + invalid_key: 123 + ''' + sub_mappings = (toscaparser.utils.yamlparser. + simple_parse(tpl_snippet))['substitution_mappings'] + expected_message = _( + 'SubstitutionMappings contains unknown field ' + '"invalid_key". Refer to the definition ' + 'to verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: SubstitutionMappings(sub_mappings, None, None, + None, None, None)) + self.assertEqual(expected_message, err.__str__()) + + def test_missing_required_keyname(self): + tpl_snippet = ''' + substitution_mappings: + capabilities: + database_endpoint: [ db_app, database_endpoint ] + requirements: + receiver1: [ tran_app, receiver1 ] + ''' + sub_mappings = (toscaparser.utils.yamlparser. + simple_parse(tpl_snippet))['substitution_mappings'] + expected_message = _('SubstitutionMappings used in topology_template ' + 'is missing required field "node_type".') + err = self.assertRaises( + exception.MissingRequiredFieldError, + lambda: SubstitutionMappings(sub_mappings, None, None, + None, None, None)) + self.assertEqual(expected_message, err.__str__()) + + def test_invalid_nodetype(self): + tpl_snippet = ''' + substitution_mappings: + node_type: example.DatabaseSubsystem1 + capabilities: + database_endpoint: [ db_app, database_endpoint ] + requirements: + receiver1: [ tran_app, receiver1 ] + ''' + sub_mappings = (toscaparser.utils.yamlparser. + simple_parse(tpl_snippet))['substitution_mappings'] + custom_defs = self._get_custom_types() + expected_message = _('Node type "example.DatabaseSubsystem1" ' + 'is not a valid type.') + err = self.assertRaises( + exception.InvalidNodeTypeError, + lambda: SubstitutionMappings(sub_mappings, None, None, + None, None, custom_defs)) + self.assertEqual(expected_message, err.__str__()) + + def test_system_with_input_validation(self): + tpl_path0 = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/topology_template/validate/system_invalid_input.yaml") + tpl_path1 = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/topology_template/validate/" + "queuingsubsystem_invalid_input.yaml") + errormsg = _('SubstitutionMappings with node_type ' + 'example.QueuingSubsystem is missing ' + 'required input definition of input "server_port".') + + # It's invalid in nested template. + self.assertRaises(exception.ValidationError, + lambda: ToscaTemplate(tpl_path0)) + exception.ExceptionCollector.assertExceptionMessage( + exception.MissingRequiredInputError, errormsg) + + # Subtemplate deploy standaolone is also invalid. + self.assertRaises(exception.ValidationError, + lambda: ToscaTemplate(tpl_path1)) + exception.ExceptionCollector.assertExceptionMessage( + exception.MissingRequiredInputError, errormsg) + + def test_system_with_unknown_output_validation(self): + tpl_path0 = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/topology_template/validate/" + "system_invalid_unknown_output.yaml") + tpl_path1 = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/topology_template/validate/" + "transactionsubsystem_invalid_unknown_output.yaml") + errormsg = _('Unknown output "my_cpu_output" in SubstitutionMappings ' + 'with node_type example.TransactionSubsystem.') + + # It's invalid in nested template. + self.assertRaises(exception.ValidationError, + lambda: ToscaTemplate(tpl_path0)) + exception.ExceptionCollector.assertExceptionMessage( + exception.UnknownOutputError, errormsg) + + # Subtemplate deploy standaolone is invalid. + self.assertRaises(exception.ValidationError, + lambda: ToscaTemplate(tpl_path1)) + exception.ExceptionCollector.assertExceptionMessage( + exception.UnknownOutputError, errormsg) + + def test_system_with_missing_output_validation(self): + tpl_path0 = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/topology_template/validate/" + "system_invalid_missing_output.yaml") + tpl_path1 = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/topology_template/validate/" + "transactionsubsystem_invalid_missing_output.yaml") + errormsg = _('SubstitutionMappings with node_type ' + 'example.TransactionSubsystem is missing ' + 'required output definition of output "receiver_port".') + + # It's invalid in nested template. + self.assertRaises(exception.ValidationError, + lambda: ToscaTemplate(tpl_path0)) + exception.ExceptionCollector.assertExceptionMessage( + exception.MissingRequiredOutputError, errormsg) + + # Subtemplate deploy standaolone is invalid. + self.assertRaises(exception.ValidationError, + lambda: ToscaTemplate(tpl_path1)) + exception.ExceptionCollector.assertExceptionMessage( + exception.MissingRequiredOutputError, errormsg) diff --git a/nfvparser/toscaparser/tests/test_toscadef.py b/nfvparser/toscaparser/tests/test_toscadef.py new file mode 100644 index 0000000..2e97b0e --- /dev/null +++ b/nfvparser/toscaparser/tests/test_toscadef.py @@ -0,0 +1,346 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from toscaparser.common import exception +from toscaparser.elements.artifacttype import ArtifactTypeDef +from toscaparser.elements.entity_type import EntityType +from toscaparser.elements.grouptype import GroupType +import toscaparser.elements.interfaces as ifaces +from toscaparser.elements.nodetype import NodeType +from toscaparser.elements.policytype import PolicyType +from toscaparser.tests.base import TestCase + +compute_type = NodeType('tosca.nodes.Compute') +component_type = NodeType('tosca.nodes.SoftwareComponent') +network_type = NodeType('tosca.nodes.network.Network') +network_port_type = NodeType('tosca.nodes.network.Port') +webserver_type = NodeType('tosca.nodes.WebServer') +database_type = NodeType('tosca.nodes.Database') +artif_root_type = ArtifactTypeDef('tosca.artifacts.Root') +artif_file_type = ArtifactTypeDef('tosca.artifacts.File') +artif_bash_type = ArtifactTypeDef('tosca.artifacts.Implementation.Bash') +artif_python_type = ArtifactTypeDef('tosca.artifacts.Implementation.Python') +artif_container_docker_type = ArtifactTypeDef('tosca.artifacts.' + 'Deployment.Image.' + 'Container.Docker') +artif_vm_iso_type = ArtifactTypeDef('tosca.artifacts.' + 'Deployment.Image.VM.ISO') +artif_vm_qcow2_type = ArtifactTypeDef('tosca.artifacts.' + 'Deployment.Image.VM.QCOW2') +policy_root_type = PolicyType('tosca.policies.Root') +policy_placement_type = PolicyType('tosca.policies.Placement') +policy_scaling_type = PolicyType('tosca.policies.Scaling') +policy_update_type = PolicyType('tosca.policies.Update') +policy_performance_type = PolicyType('tosca.policies.Performance') +group_type = GroupType('tosca.groups.Root') + + +class ToscaDefTest(TestCase): + def test_type(self): + self.assertEqual(compute_type.type, "tosca.nodes.Compute") + self.assertRaises(exception.InvalidTypeError, NodeType, + 'tosca.nodes.Invalid') + self.assertEqual(network_type.type, "tosca.nodes.network.Network") + self.assertEqual(network_port_type.type, "tosca.nodes.network.Port") + + def test_parent_type(self): + self.assertEqual(compute_type.parent_type.type, "tosca.nodes.Root") + self.assertEqual(network_type.parent_type.type, "tosca.nodes.Root") + self.assertEqual(network_port_type.parent_type.type, + "tosca.nodes.Root") + + def test_group(self): + self.assertEqual(group_type.type, "tosca.groups.Root") + self.assertIsNone(group_type.parent_type) + self.assertIn(ifaces.LIFECYCLE_SHORTNAME, group_type.interfaces) + + def test_capabilities(self): + # Assure the normative Compute node type + # has all the required Capability types + # regardless of symbloc name + # TODO(Matt) - since Compute IS a normative node type + # we SHOULD test symbolic capability names as well + self.assertEqual( + ['tosca.capabilities.Container', + 'tosca.capabilities.Endpoint.Admin', + 'tosca.capabilities.Node', + 'tosca.capabilities.OperatingSystem', + 'tosca.capabilities.Scalable', + 'tosca.capabilities.network.Bindable'], + sorted([c.type for c in compute_type.get_capabilities_objects()])) + # Assure the normative Network node type + # hsa all the required Capability types + # TODO(Matt) - since Network IS a normative node type + # we SHOULD test symbolic capability names as well + self.assertEqual( + ['tosca.capabilities.Node', + 'tosca.capabilities.network.Linkable'], + sorted([c.type for c in network_type.get_capabilities_objects()])) + + # Assure the normative WebServer node type's + # Endpoint cap. has all required property names + # Note: we are testing them in alphabetic sort order + endpoint_props_def_objects = \ + self._get_capability_properties_def_objects( + webserver_type.get_capabilities_objects(), + 'tosca.capabilities.Endpoint') + # Assure WebServer's Endpoint capability's properties have their + # required keyname value set correctly + self.assertEqual( + [('initiator', False), ('network_name', False), ('port', False), + ('port_name', False), ('ports', False), ('protocol', True), + ('secure', False), ('url_path', False)], + sorted([(p.name, p.required) for p in endpoint_props_def_objects])) + + os_props = self._get_capability_properties_def_objects( + compute_type.get_capabilities_objects(), + 'tosca.capabilities.OperatingSystem') + self.assertEqual( + [('architecture', False), ('distribution', False), ('type', False), + ('version', False)], + sorted([(p.name, p.required) for p in os_props])) + + host_props = self._get_capability_properties_def_objects( + compute_type.get_capabilities_objects(), + 'tosca.capabilities.Container') + self.assertEqual( + [('cpu_frequency', False), ('disk_size', False), + ('mem_size', False), ('num_cpus', False)], + sorted([(p.name, p.required) for p in host_props])) + endpoint_admin_properties = 'secure' + endpoint_admin_props_def_objects = \ + self._get_capability_properties_def_objects( + webserver_type.get_capabilities_objects(), + 'tosca.capabilities.Endpoint.Admin') + self.assertIn( + endpoint_admin_properties, + sorted([p.name for p in endpoint_admin_props_def_objects])) + + def _get_capability_properties_def_objects(self, caps, type): + properties_def = None + for cap in caps: + if cap.type == type: + properties_def = cap.get_properties_def_objects() + break + return properties_def + + def _get_capability_properties_def(self, caps, type): + properties_def = None + for cap in caps: + if cap.type == type: + properties_def = cap.get_properties_def() + break + return properties_def + + def test_properties_def(self): + self.assertEqual( + ['name', 'password', 'port', 'user'], + sorted(database_type.get_properties_def().keys())) + + def test_attributes_def(self): + self.assertEqual( + ['networks', 'ports', 'private_address', 'public_address', + 'state', 'tosca_id', 'tosca_name'], + sorted(compute_type.get_attributes_def().keys())) + + def test_requirements(self): + self.assertEqual( + [{'host': {'capability': 'tosca.capabilities.Container', + 'node': 'tosca.nodes.Compute', + 'relationship': 'tosca.relationships.HostedOn'}}, + {'dependency': {'capability': 'tosca.capabilities.Node', + 'node': 'tosca.nodes.Root', + 'occurrences': [0, 'UNBOUNDED'], + 'relationship': 'tosca.relationships.DependsOn'}} + ], + [r for r in component_type.requirements]) + + def test_relationship(self): + self.assertEqual( + [('tosca.relationships.DependsOn', 'tosca.nodes.Root'), + ('tosca.relationships.HostedOn', 'tosca.nodes.Compute')], + sorted([(relation.type, node.type) for + relation, node in component_type.relationship.items()])) + self.assertIn( + ('tosca.relationships.HostedOn', ['tosca.capabilities.Container']), + [(relation.type, relation.valid_target_types) for + relation in list(component_type.relationship.keys())]) + self.assertIn( + ('tosca.relationships.network.BindsTo', 'tosca.nodes.Compute'), + [(relation.type, node.type) for + relation, node in network_port_type.relationship.items()]) + self.assertIn( + ('tosca.relationships.network.LinksTo', + 'tosca.nodes.network.Network'), + [(relation.type, node.type) for + relation, node in network_port_type.relationship.items()]) + + def test_interfaces(self): + self.assertIsNone(compute_type.interfaces) + root_node = NodeType('tosca.nodes.Root') + self.assertIn(ifaces.LIFECYCLE_SHORTNAME, root_node.interfaces) + + def test_artifacts(self): + self.assertIsNone(artif_root_type.parent_type) + self.assertEqual('tosca.artifacts.Root', + artif_file_type.parent_type.type) + self.assertEqual({}, artif_file_type.parent_artifacts) + self.assertEqual(sorted(['tosca.artifacts.Root'], + key=lambda x: str(x)), + sorted([artif_file_type.get_artifact(name) + for name in artif_file_type.defs], + key=lambda x: str(x))) + + self.assertEqual('tosca.artifacts.Implementation', + artif_bash_type.parent_type.type) + self.assertEqual({'tosca.artifacts.Implementation': + {'derived_from': 'tosca.artifacts.Root', + 'description': + 'TOSCA base type for implementation artifacts'}}, + artif_bash_type.parent_artifacts) + self.assertEqual(sorted([['sh'], 'tosca.artifacts.Implementation', + 'Script artifact for the Unix Bash shell', + 'application/x-sh'], key=lambda x: str(x)), + sorted([artif_bash_type.get_artifact(name) + for name in artif_bash_type.defs], + key=lambda x: str(x))) + + self.assertEqual('tosca.artifacts.Implementation', + artif_python_type.parent_type.type) + self.assertEqual({'tosca.artifacts.Implementation': + {'derived_from': 'tosca.artifacts.Root', + 'description': + 'TOSCA base type for implementation artifacts'}}, + artif_python_type.parent_artifacts) + self.assertEqual(sorted([['py'], 'tosca.artifacts.Implementation', + 'Artifact for the interpreted Python' + ' language', 'application/x-python'], + key=lambda x: str(x)), + sorted([artif_python_type.get_artifact(name) + for name in artif_python_type.defs], + key=lambda x: str(x))) + + self.assertEqual('tosca.artifacts.Deployment.Image', + artif_container_docker_type.parent_type.type) + self.assertEqual({'tosca.artifacts.Deployment': + {'derived_from': 'tosca.artifacts.Root', + 'description': + 'TOSCA base type for deployment artifacts'}, + 'tosca.artifacts.Deployment.Image': + {'derived_from': 'tosca.artifacts.Deployment'}}, + artif_container_docker_type.parent_artifacts) + self.assertEqual(sorted(['tosca.artifacts.Deployment.Image', + 'Docker container image'], + key=lambda x: str(x)), + sorted([artif_container_docker_type. + get_artifact(name) for name in + artif_container_docker_type.defs], + key=lambda x: str(x))) + + self.assertEqual('tosca.artifacts.Deployment.Image', + artif_vm_iso_type.parent_type.type) + self.assertEqual({'tosca.artifacts.Deployment': + {'derived_from': 'tosca.artifacts.Root', + 'description': + 'TOSCA base type for deployment artifacts'}, + 'tosca.artifacts.Deployment.Image': + {'derived_from': 'tosca.artifacts.Deployment'}}, + artif_vm_iso_type.parent_artifacts) + self.assertEqual(sorted(['tosca.artifacts.Deployment.Image', + 'Virtual Machine (VM) image in ' + 'ISO disk format', + 'application/octet-stream', ['iso']], + key=lambda x: str(x)), + sorted([artif_vm_iso_type. + get_artifact(name) for name in + artif_vm_iso_type.defs], + key=lambda x: str(x))) + + self.assertEqual('tosca.artifacts.Deployment.Image', + artif_vm_qcow2_type.parent_type.type) + self.assertEqual({'tosca.artifacts.Deployment': + {'derived_from': 'tosca.artifacts.Root', + 'description': + 'TOSCA base type for deployment artifacts'}, + 'tosca.artifacts.Deployment.Image': + {'derived_from': 'tosca.artifacts.Deployment'}}, + artif_vm_qcow2_type.parent_artifacts) + self.assertEqual(sorted(['tosca.artifacts.Deployment.Image', + 'Virtual Machine (VM) image in QCOW v2 ' + 'standard disk format', + 'application/octet-stream', ['qcow2']], + key=lambda x: str(x)), + sorted([artif_vm_qcow2_type. + get_artifact(name) for name in + artif_vm_qcow2_type.defs], + key=lambda x: str(x))) + + def test_policies(self): + self.assertIsNone(policy_root_type.parent_type) + self.assertEqual('tosca.policies.Root', + policy_placement_type.parent_type.type) + self.assertEqual({}, policy_placement_type.parent_policies) + self.assertEqual(sorted(['tosca.policies.Root', + 'The TOSCA Policy Type definition that is ' + 'used to govern placement of TOSCA nodes or ' + 'groups of nodes.'], + key=lambda x: str(x)), + sorted([policy_placement_type.get_policy(name) + for name in policy_placement_type.defs], + key=lambda x: str(x))) + + self.assertEqual('tosca.policies.Root', + policy_scaling_type.parent_type.type) + self.assertEqual({}, policy_scaling_type.parent_policies) + self.assertEqual(sorted(['tosca.policies.Root', + 'The TOSCA Policy Type definition that is ' + 'used to govern scaling of TOSCA nodes or ' + 'groups of nodes.'], + key=lambda x: str(x)), + sorted([policy_scaling_type.get_policy(name) + for name in policy_scaling_type.defs], + key=lambda x: str(x))) + + self.assertEqual('tosca.policies.Root', + policy_update_type.parent_type.type) + self.assertEqual({}, policy_update_type.parent_policies) + self.assertEqual(sorted(['tosca.policies.Root', + 'The TOSCA Policy Type definition that is ' + 'used to govern update of TOSCA nodes or ' + 'groups of nodes.'], + key=lambda x: str(x)), + sorted([policy_update_type.get_policy(name) + for name in policy_update_type.defs], + key=lambda x: str(x))) + + self.assertEqual('tosca.policies.Root', + policy_performance_type.parent_type.type) + self.assertEqual({}, policy_performance_type.parent_policies) + self.assertEqual(sorted(['tosca.policies.Root', + 'The TOSCA Policy Type definition that is ' + 'used to declare performance requirements ' + 'for TOSCA nodes or groups of nodes.'], + key=lambda x: str(x)), + sorted([policy_performance_type.get_policy(name) + for name in policy_performance_type.defs], + key=lambda x: str(x))) + + def test_port_spec(self): + tosca_def = EntityType.TOSCA_DEF + port_spec = tosca_def.get('tosca.datatypes.network.PortSpec') + self.assertEqual(port_spec.get('derived_from'), + 'tosca.datatypes.Root') + properties = port_spec.get('properties') + self.assertEqual( + sorted(['protocol', 'target', 'target_range', 'source', + 'source_range']), + sorted(properties.keys())) diff --git a/nfvparser/toscaparser/tests/test_toscatpl.py b/nfvparser/toscaparser/tests/test_toscatpl.py new file mode 100644 index 0000000..fac8687 --- /dev/null +++ b/nfvparser/toscaparser/tests/test_toscatpl.py @@ -0,0 +1,854 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import os +import six +from toscaparser.common import exception +import toscaparser.elements.interfaces as ifaces +from toscaparser.elements.nodetype import NodeType +from toscaparser.elements.portspectype import PortSpec +from toscaparser.functions import GetInput +from toscaparser.functions import GetProperty +from toscaparser.nodetemplate import NodeTemplate +from toscaparser.tests.base import TestCase +from toscaparser.tosca_template import ToscaTemplate +from toscaparser.utils.gettextutils import _ +import toscaparser.utils.yamlparser + + +class ToscaTemplateTest(TestCase): + '''TOSCA template.''' + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/tosca_single_instance_wordpress.yaml") + params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user', + 'db_root_pwd': '12345678'} + tosca = ToscaTemplate(tosca_tpl, parsed_params=params) + tosca_elk_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/tosca_elk.yaml") + tosca_repo_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/repositories/tosca_repositories_test_definition.yaml") + + def test_version(self): + self.assertEqual(self.tosca.version, "tosca_simple_yaml_1_0") + + def test_description(self): + expected_description = "TOSCA simple profile with wordpress, " \ + "web server and mysql on the same server." + self.assertEqual(self.tosca.description, expected_description) + + def test_inputs(self): + self.assertEqual( + ['cpus', 'db_name', 'db_port', + 'db_pwd', 'db_root_pwd', 'db_user'], + sorted([input.name for input in self.tosca.inputs])) + + input_name = "db_port" + expected_description = "Port for the MySQL database." + for input in self.tosca.inputs: + if input.name == input_name: + self.assertEqual(input.description, expected_description) + + def test_node_tpls(self): + '''Test nodetemplate names.''' + self.assertEqual( + ['mysql_database', 'mysql_dbms', 'server', + 'webserver', 'wordpress'], + sorted([tpl.name for tpl in self.tosca.nodetemplates])) + + tpl_name = "mysql_database" + expected_type = "tosca.nodes.Database" + expected_properties = ['name', 'password', 'user'] + expected_capabilities = ['database_endpoint', 'feature'] + expected_requirements = [{'host': 'mysql_dbms'}] + ''' TODO: needs enhancement in tosca_elk.yaml.. + expected_relationshp = ['tosca.relationships.HostedOn'] + expected_host = ['mysql_dbms'] + ''' + expected_interface = [ifaces.LIFECYCLE_SHORTNAME] + + for tpl in self.tosca.nodetemplates: + if tpl_name == tpl.name: + '''Test node type.''' + self.assertEqual(tpl.type, expected_type) + + '''Test properties.''' + self.assertEqual( + expected_properties, + sorted(tpl.get_properties().keys())) + + '''Test capabilities.''' + self.assertEqual( + expected_capabilities, + sorted(tpl.get_capabilities().keys())) + + '''Test requirements.''' + self.assertEqual( + expected_requirements, tpl.requirements) + + '''Test relationship.''' + ''' needs enhancements in tosca_elk.yaml + self.assertEqual( + expected_relationshp, + [x.type for x in tpl.relationships.keys()]) + self.assertEqual( + expected_host, + [y.name for y in tpl.relationships.values()]) + ''' + '''Test interfaces.''' + self.assertEqual( + expected_interface, + [x.type for x in tpl.interfaces]) + + if tpl.name == 'server': + '''Test property value''' + props = tpl.get_properties() + if props and 'mem_size' in props.keys(): + self.assertEqual(props['mem_size'].value, '4096 MB') + '''Test capability''' + caps = tpl.get_capabilities() + self.assertIn('os', caps.keys()) + os_props_objs = None + os_props = None + os_type_prop = None + if caps and 'os' in caps.keys(): + capability = caps['os'] + os_props_objs = capability.get_properties_objects() + os_props = capability.get_properties() + os_type_prop = capability.get_property_value('type') + break + self.assertEqual( + ['Linux'], + [p.value for p in os_props_objs if p.name == 'type']) + self.assertEqual( + 'Linux', + os_props['type'].value if 'type' in os_props else '') + self.assertEqual('Linux', os_props['type'].value) + self.assertEqual('Linux', os_type_prop) + + def test_node_inheritance_type(self): + wordpress_node = [ + node for node in self.tosca.nodetemplates + if node.name == 'wordpress'][0] + self.assertTrue( + wordpress_node.is_derived_from("tosca.nodes.WebApplication")) + self.assertTrue( + wordpress_node.is_derived_from("tosca.nodes.Root")) + self.assertFalse( + wordpress_node.is_derived_from("tosca.policies.Root")) + + def test_outputs(self): + self.assertEqual( + ['website_url'], + sorted([output.name for output in self.tosca.outputs])) + + def test_interfaces(self): + wordpress_node = [ + node for node in self.tosca.nodetemplates + if node.name == 'wordpress'][0] + interfaces = wordpress_node.interfaces + self.assertEqual(2, len(interfaces)) + for interface in interfaces: + if interface.name == 'create': + self.assertEqual(ifaces.LIFECYCLE_SHORTNAME, + interface.type) + self.assertEqual('wordpress/wordpress_install.sh', + interface.implementation) + self.assertIsNone(interface.inputs) + elif interface.name == 'configure': + self.assertEqual(ifaces.LIFECYCLE_SHORTNAME, + interface.type) + self.assertEqual('wordpress/wordpress_configure.sh', + interface.implementation) + self.assertEqual(3, len(interface.inputs)) + TestCase.skip(self, 'bug #1440247') + wp_db_port = interface.inputs['wp_db_port'] + self.assertIsInstance(wp_db_port, GetProperty) + self.assertEqual('get_property', wp_db_port.name) + self.assertEqual(['SELF', + 'database_endpoint', + 'port'], + wp_db_port.args) + result = wp_db_port.result() + self.assertIsInstance(result, GetInput) + else: + raise AssertionError( + 'Unexpected interface: {0}'.format(interface.name)) + + def test_normative_type_by_short_name(self): + # test template with a short name Compute + template = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_tosca_normative_type_by_shortname.yaml") + + tosca_tpl = ToscaTemplate(template) + expected_type = "tosca.nodes.Compute" + for tpl in tosca_tpl.nodetemplates: + self.assertEqual(tpl.type, expected_type) + for tpl in tosca_tpl.nodetemplates: + compute_type = NodeType(tpl.type) + self.assertEqual( + sorted(['tosca.capabilities.Container', + 'tosca.capabilities.Endpoint.Admin', + 'tosca.capabilities.Node', + 'tosca.capabilities.OperatingSystem', + 'tosca.capabilities.network.Bindable', + 'tosca.capabilities.Scalable']), + sorted([c.type + for c in compute_type.get_capabilities_objects()])) + + def test_template_with_no_inputs(self): + tosca_tpl = self._load_template('test_no_inputs_in_template.yaml') + self.assertEqual(0, len(tosca_tpl.inputs)) + + def test_template_with_no_outputs(self): + tosca_tpl = self._load_template('test_no_outputs_in_template.yaml') + self.assertEqual(0, len(tosca_tpl.outputs)) + + def test_relationship_interface(self): + template = ToscaTemplate(self.tosca_elk_tpl) + for node_tpl in template.nodetemplates: + if node_tpl.name == 'logstash': + config_interface = 'Configure' + artifact = 'logstash/configure_elasticsearch.py' + relation = node_tpl.relationships + for key in relation.keys(): + rel_tpl = relation.get(key).get_relationship_template() + if rel_tpl: + self.assertTrue(rel_tpl[0].is_derived_from( + "tosca.relationships.Root")) + interfaces = rel_tpl[0].interfaces + for interface in interfaces: + self.assertEqual(config_interface, + interface.type) + self.assertEqual('pre_configure_source', + interface.name) + self.assertEqual(artifact, + interface.implementation) + + def test_relationship(self): + template = ToscaTemplate(self.tosca_elk_tpl) + for node_tpl in template.nodetemplates: + if node_tpl.name == 'paypal_pizzastore': + expected_relationships = ['tosca.relationships.ConnectsTo', + 'tosca.relationships.HostedOn'] + expected_hosts = ['tosca.nodes.Database', + 'tosca.nodes.WebServer'] + self.assertEqual(len(node_tpl.relationships), 2) + self.assertEqual( + expected_relationships, + sorted([k.type for k in node_tpl.relationships.keys()])) + self.assertEqual( + expected_hosts, + sorted([v.type for v in node_tpl.relationships.values()])) + + def test_repositories(self): + template = ToscaTemplate(self.tosca_repo_tpl) + self.assertEqual( + ['repo_code0', 'repo_code1', 'repo_code2'], + sorted([input.name for input in template.repositories])) + + input_name = "repo_code2" + expected_url = "https://github.com/nandinivemula/intern/master" + for input in template.repositories: + if input.name == input_name: + self.assertEqual(input.url, expected_url) + + def test_template_macro(self): + template = ToscaTemplate(self.tosca_elk_tpl) + for node_tpl in template.nodetemplates: + if node_tpl.name == 'mongo_server': + self.assertEqual( + ['disk_size', 'mem_size', 'num_cpus'], + sorted(node_tpl.get_capability('host'). + get_properties().keys())) + + def test_template_requirements(self): + """Test different formats of requirements + + The requirements can be defined in few different ways, + 1. Requirement expressed as a capability with an implicit relationship. + 2. Requirement expressed with explicit relationship. + 3. Requirement expressed with a relationship template. + 4. Requirement expressed via TOSCA types to provision a node + with explicit relationship. + 5. Requirement expressed via TOSCA types with a filter. + """ + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/requirements/test_requirements.yaml") + tosca = ToscaTemplate(tosca_tpl) + for node_tpl in tosca.nodetemplates: + if node_tpl.name == 'my_app': + expected_relationship = [ + ('tosca.relationships.ConnectsTo', 'mysql_database'), + ('tosca.relationships.HostedOn', 'my_webserver')] + actual_relationship = sorted([ + (relation.type, node.name) for + relation, node in node_tpl.relationships.items()]) + self.assertEqual(expected_relationship, actual_relationship) + if node_tpl.name == 'mysql_database': + self.assertEqual( + [('tosca.relationships.HostedOn', 'my_dbms')], + [(relation.type, node.name) for + relation, + node in node_tpl.relationships.items()]) + if node_tpl.name == 'my_server': + self.assertEqual( + [('tosca.relationships.AttachesTo', 'my_storage')], + [(relation.type, node.name) for + relation, + node in node_tpl.relationships.items()]) + + def test_template_requirements_not_implemented(self): + # TODO(spzala): replace this test with new one once TOSCA types look up + # support is implemented. + """Requirements that yet need to be implemented + + The following requirement formats are not yet implemented, + due to look up dependency: + 1. Requirement expressed via TOSCA types to provision a node + with explicit relationship. + 2. Requirement expressed via TOSCA types with a filter. + """ + tpl_snippet_1 = ''' + node_templates: + mysql_database: + type: tosca.nodes.Database + description: Requires a particular node type and relationship. + To be full-filled via lookup into node repository. + requirements: + - req1: + node: tosca.nodes.DBMS + relationship: tosca.relationships.HostedOn + ''' + + tpl_snippet_2 = ''' + node_templates: + my_webserver: + type: tosca.nodes.WebServer + description: Requires a particular node type with a filter. + To be full-filled via lookup into node repository. + requirements: + - req1: + node: tosca.nodes.Compute + target_filter: + properties: + num_cpus: { in_range: [ 1, 4 ] } + mem_size: { greater_or_equal: 2 } + capabilities: + - tosca.capabilities.OS: + properties: + architecture: x86_64 + type: linux + ''' + + tpl_snippet_3 = ''' + node_templates: + my_webserver2: + type: tosca.nodes.WebServer + description: Requires a node type with a particular capability. + To be full-filled via lookup into node repository. + requirements: + - req1: + node: tosca.nodes.Compute + relationship: tosca.relationships.HostedOn + capability: tosca.capabilities.Container + ''' + self._requirements_not_implemented(tpl_snippet_1, 'mysql_database') + self._requirements_not_implemented(tpl_snippet_2, 'my_webserver') + self._requirements_not_implemented(tpl_snippet_3, 'my_webserver2') + + def _requirements_not_implemented(self, tpl_snippet, tpl_name): + nodetemplates = (toscaparser.utils.yamlparser. + simple_parse(tpl_snippet))['node_templates'] + self.assertRaises( + NotImplementedError, + lambda: NodeTemplate(tpl_name, nodetemplates).relationships) + + # Test the following: + # 1. Custom node type derived from 'WebApplication' named 'TestApp' + # with a custom Capability Type 'TestCapability' + # 2. Same as #1, but referencing a custom 'TestCapability' Capability Type + # that is not defined + def test_custom_capability_type_definition(self): + tpl_snippet = ''' + node_templates: + test_app: + type: tosca.nodes.WebApplication.TestApp + capabilities: + test_cap: + properties: + test: 1 + ''' + # custom node type definition with custom capability type definition + custom_def = ''' + tosca.nodes.WebApplication.TestApp: + derived_from: tosca.nodes.WebApplication + capabilities: + test_cap: + type: tosca.capabilities.TestCapability + tosca.capabilities.TestCapability: + derived_from: tosca.capabilities.Root + properties: + test: + type: integer + required: false + ''' + expected_capabilities = ['app_endpoint', 'feature', 'test_cap'] + nodetemplates = (toscaparser.utils.yamlparser. + simple_parse(tpl_snippet))['node_templates'] + custom_def = (toscaparser.utils.yamlparser. + simple_parse(custom_def)) + name = list(nodetemplates.keys())[0] + tpl = NodeTemplate(name, nodetemplates, custom_def) + self.assertEqual( + expected_capabilities, + sorted(tpl.get_capabilities().keys())) + + # custom definition without valid capability type definition + custom_def = ''' + tosca.nodes.WebApplication.TestApp: + derived_from: tosca.nodes.WebApplication + capabilities: + test_cap: + type: tosca.capabilities.TestCapability + ''' + custom_def = (toscaparser.utils.yamlparser. + simple_parse(custom_def)) + tpl = NodeTemplate(name, nodetemplates, custom_def) + err = self.assertRaises( + exception.InvalidTypeError, + lambda: NodeTemplate(name, nodetemplates, + custom_def).get_capabilities_objects()) + self.assertEqual('Type "tosca.capabilities.TestCapability" is not ' + 'a valid type.', six.text_type(err)) + + def test_local_template_with_local_relpath_import(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/tosca_single_instance_wordpress.yaml") + params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user', + 'db_root_pwd': '12345678'} + tosca = ToscaTemplate(tosca_tpl, parsed_params=params) + self.assertTrue(tosca.topology_template.custom_defs) + + def test_local_template_with_url_import(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/tosca_single_instance_wordpress_with_url_import.yaml") + tosca = ToscaTemplate(tosca_tpl, + parsed_params={'db_root_pwd': '123456'}) + self.assertTrue(tosca.topology_template.custom_defs) + + def test_url_template_with_local_relpath_import(self): + tosca_tpl = ('https://raw.githubusercontent.com/openstack/' + 'tosca-parser/master/toscaparser/tests/data/' + 'tosca_single_instance_wordpress.yaml') + tosca = ToscaTemplate(tosca_tpl, a_file=False, + parsed_params={"db_name": "mysql", + "db_user": "mysql", + "db_root_pwd": "1234", + "db_pwd": "5678", + "db_port": 3306, + "cpus": 4}) + self.assertTrue(tosca.topology_template.custom_defs) + + def test_url_template_with_local_abspath_import(self): + tosca_tpl = ('https://raw.githubusercontent.com/openstack/' + 'tosca-parser/master/toscaparser/tests/data/' + 'tosca_single_instance_wordpress_with_local_abspath_' + 'import.yaml') + self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl, + None, False) + err_msg = (_('Absolute file name "/tmp/tosca-parser/toscaparser/tests' + '/data/custom_types/wordpress.yaml" cannot be used in a ' + 'URL-based input template "%(tpl)s".') + % {'tpl': tosca_tpl}) + exception.ExceptionCollector.assertExceptionMessage(ImportError, + err_msg) + + def test_url_template_with_url_import(self): + tosca_tpl = ('https://raw.githubusercontent.com/openstack/' + 'tosca-parser/master/toscaparser/tests/data/' + 'tosca_single_instance_wordpress_with_url_import.yaml') + tosca = ToscaTemplate(tosca_tpl, a_file=False, + parsed_params={"db_root_pwd": "1234"}) + self.assertTrue(tosca.topology_template.custom_defs) + + def test_csar_parsing_wordpress(self): + csar_archive = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + 'data/CSAR/csar_wordpress.zip') + self.assertTrue(ToscaTemplate(csar_archive, + parsed_params={"db_name": "mysql", + "db_user": "mysql", + "db_root_pwd": "1234", + "db_pwd": "5678", + "db_port": 3306, + "cpus": 4})) + + def test_csar_parsing_elk_url_based(self): + csar_archive = ('https://github.com/openstack/tosca-parser/raw/master/' + 'toscaparser/tests/data/CSAR/csar_elk.zip') + self.assertTrue(ToscaTemplate(csar_archive, a_file=False, + parsed_params={"my_cpus": 4})) + + def test_nested_imports_in_templates(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_instance_nested_imports.yaml") + tosca = ToscaTemplate(tosca_tpl) + expected_custom_types = ['tosca.nodes.WebApplication.WordPress', + 'test_namespace_prefix.Rsyslog', + 'Test2ndRsyslogType', + 'test_2nd_namespace_prefix.Rsyslog', + 'tosca.nodes.SoftwareComponent.Logstash', + 'tosca.nodes.SoftwareComponent.Rsyslog.' + 'TestRsyslogType'] + self.assertItemsEqual(tosca.topology_template.custom_defs.keys(), + expected_custom_types) + + def test_invalid_template_file(self): + template_file = 'invalid template file' + expected_msg = (_('"%s" is not a valid file.') % template_file) + self.assertRaises( + exception.ValidationError, + ToscaTemplate, template_file, None, False) + exception.ExceptionCollector.assertExceptionMessage(ValueError, + expected_msg) + + def test_multiple_validation_errors(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_multiple_validation_errors.yaml") + self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl, + None) + valid_versions = ', '.join(ToscaTemplate.VALID_TEMPLATE_VERSIONS) + err1_msg = (_('The template version "tosca_simple_yaml_1" is invalid. ' + 'Valid versions are "%s".') % valid_versions) + exception.ExceptionCollector.assertExceptionMessage( + exception.InvalidTemplateVersion, err1_msg) + + err2_msg = _('Import "custom_types/not_there.yaml" is not valid.') + exception.ExceptionCollector.assertExceptionMessage( + ImportError, err2_msg) + + err3_msg = _('Type "tosca.nodes.WebApplication.WordPress" is not a ' + 'valid type.') + exception.ExceptionCollector.assertExceptionMessage( + exception.InvalidTypeError, err3_msg) + + err4_msg = _('Node template "wordpress" contains unknown field ' + '"requirement". Refer to the definition to verify valid ' + 'values.') + exception.ExceptionCollector.assertExceptionMessage( + exception.UnknownFieldError, err4_msg) + + err5_msg = _('\'Property "passwords" was not found in node template ' + '"mysql_database".\'') + exception.ExceptionCollector.assertExceptionMessage( + KeyError, err5_msg) + + err6_msg = _('Template "mysql_dbms" is missing required field "type".') + exception.ExceptionCollector.assertExceptionMessage( + exception.MissingRequiredFieldError, err6_msg) + + err7_msg = _('Node template "mysql_dbms" contains unknown field ' + '"type1". Refer to the definition to verify valid ' + 'values.') + exception.ExceptionCollector.assertExceptionMessage( + exception.UnknownFieldError, err7_msg) + + err8_msg = _('\'Node template "server1" was not found in ' + '"webserver".\'') + exception.ExceptionCollector.assertExceptionMessage( + KeyError, err8_msg) + + err9_msg = _('"relationship" used in template "webserver" is missing ' + 'required field "type".') + exception.ExceptionCollector.assertExceptionMessage( + exception.MissingRequiredFieldError, err9_msg) + + err10_msg = _('Type "tosca.nodes.XYZ" is not a valid type.') + exception.ExceptionCollector.assertExceptionMessage( + exception.InvalidTypeError, err10_msg) + + def test_invalid_section_names(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_invalid_section_names.yaml") + self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl, + None) + err1_msg = _('Template contains unknown field ' + '"tosca_definitions_versions". Refer to the definition ' + 'to verify valid values.') + exception.ExceptionCollector.assertExceptionMessage( + exception.UnknownFieldError, err1_msg) + + err2_msg = _('Template contains unknown field "descriptions". ' + 'Refer to the definition to verify valid values.') + exception.ExceptionCollector.assertExceptionMessage( + exception.UnknownFieldError, err2_msg) + + err3_msg = _('Template contains unknown field "import". Refer to ' + 'the definition to verify valid values.') + exception.ExceptionCollector.assertExceptionMessage( + exception.UnknownFieldError, err3_msg) + + err4_msg = _('Template contains unknown field "topology_templates". ' + 'Refer to the definition to verify valid values.') + exception.ExceptionCollector.assertExceptionMessage( + exception.UnknownFieldError, err4_msg) + + def test_csar_with_alternate_extenstion(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/CSAR/csar_elk.csar") + tosca = ToscaTemplate(tosca_tpl, parsed_params={"my_cpus": 2}) + self.assertTrue(tosca.topology_template.custom_defs) + + def test_available_rel_tpls(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_available_rel_tpls.yaml") + tosca = ToscaTemplate(tosca_tpl) + for node in tosca.nodetemplates: + for relationship, target in node.relationships.items(): + try: + target.relationships + except TypeError as error: + self.fail(error) + + def test_no_input(self): + self.assertRaises(exception.ValidationError, ToscaTemplate, None, + None, False, None) + err_msg = (('No path or yaml_dict_tpl was provided. ' + 'There is nothing to parse.')) + exception.ExceptionCollector.assertExceptionMessage(ValueError, + err_msg) + + def test_path_and_yaml_dict_tpl_input(self): + test_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/tosca_helloworld.yaml") + + yaml_dict_tpl = toscaparser.utils.yamlparser.load_yaml(test_tpl) + + tosca = ToscaTemplate(test_tpl, yaml_dict_tpl=yaml_dict_tpl) + + self.assertEqual(tosca.version, "tosca_simple_yaml_1_0") + + def test_yaml_dict_tpl_input(self): + test_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/tosca_helloworld.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_0") + + def test_yaml_dict_tpl_with_params_and_url_import(self): + test_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/tosca_single_instance_wordpress_with_url_import.yaml") + + yaml_dict_tpl = toscaparser.utils.yamlparser.load_yaml(test_tpl) + + params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user', + 'db_root_pwd': 'mypasswd'} + + tosca = ToscaTemplate(parsed_params=params, + yaml_dict_tpl=yaml_dict_tpl) + + self.assertEqual(tosca.version, "tosca_simple_yaml_1_0") + + def test_yaml_dict_tpl_with_rel_import(self): + test_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/tosca_single_instance_wordpress.yaml") + + yaml_dict_tpl = toscaparser.utils.yamlparser.load_yaml(test_tpl) + params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user', + 'db_root_pwd': '12345678'} + self.assertRaises(exception.ValidationError, ToscaTemplate, None, + params, False, yaml_dict_tpl) + err_msg = (_('Relative file name "custom_types/wordpress.yaml" ' + 'cannot be used in a pre-parsed input template.')) + exception.ExceptionCollector.assertExceptionMessage(ImportError, + err_msg) + + def test_yaml_dict_tpl_with_fullpath_import(self): + test_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/tosca_single_instance_wordpress.yaml") + + yaml_dict_tpl = toscaparser.utils.yamlparser.load_yaml(test_tpl) + + yaml_dict_tpl['imports'] = [os.path.join(os.path.dirname( + os.path.abspath(__file__)), "data/custom_types/wordpress.yaml")] + + params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user', + 'db_root_pwd': 'mypasswd'} + + tosca = ToscaTemplate(parsed_params=params, + yaml_dict_tpl=yaml_dict_tpl) + + self.assertEqual(tosca.version, "tosca_simple_yaml_1_0") + + def test_policies_for_node_templates(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/policies/tosca_policy_template.yaml") + tosca = ToscaTemplate(tosca_tpl) + + for policy in tosca.topology_template.policies: + self.assertTrue( + policy.is_derived_from("tosca.policies.Root")) + if policy.name == 'my_compute_placement_policy': + self.assertEqual('tosca.policies.Placement', policy.type) + self.assertEqual(['my_server_1', 'my_server_2'], + policy.targets) + self.assertEqual('node_templates', policy.get_targets_type()) + for node in policy.targets_list: + if node.name == 'my_server_1': + '''Test property value''' + props = node.get_properties() + if props and 'mem_size' in props.keys(): + self.assertEqual(props['mem_size'].value, + '4096 MB') + + def test_policies_for_groups(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/policies/tosca_policy_template.yaml") + tosca = ToscaTemplate(tosca_tpl) + + for policy in tosca.topology_template.policies: + self.assertTrue( + policy.is_derived_from("tosca.policies.Root")) + if policy.name == 'my_groups_placement': + self.assertEqual('mycompany.mytypes.myScalingPolicy', + policy.type) + self.assertEqual(['webserver_group'], policy.targets) + self.assertEqual('groups', policy.get_targets_type()) + group = policy.get_targets_list()[0] + for node in group.get_member_nodes(): + if node.name == 'my_server_2': + '''Test property value''' + props = node.get_properties() + if props and 'mem_size' in props.keys(): + self.assertEqual(props['mem_size'].value, + '4096 MB') + + def test_node_filter(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/node_filter/test_node_filter.yaml") + ToscaTemplate(tosca_tpl) + + def test_attributes_inheritance(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_attributes_inheritance.yaml") + ToscaTemplate(tosca_tpl) + + def test_repositories_definition(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/repositories/test_repositories_definition.yaml") + ToscaTemplate(tosca_tpl) + + def test_custom_caps_def(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_custom_caps_def.yaml") + ToscaTemplate(tosca_tpl) + + def test_custom_rel_with_script(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_tosca_custom_rel_with_script.yaml") + tosca = ToscaTemplate(tosca_tpl) + rel = tosca.relationship_templates[0] + self.assertEqual(rel.type, "tosca.relationships.HostedOn") + self.assertTrue(rel.is_derived_from("tosca.relationships.Root")) + self.assertEqual(len(rel.interfaces), 1) + self.assertEqual(rel.interfaces[0].type, "Configure") + + def test_various_portspec_errors(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/datatypes/test_datatype_portspec_add_req.yaml") + self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl, + None) + + # TODO(TBD) find way to reuse error messages from constraints.py + msg = (_('The value "%(pvalue)s" of property "%(pname)s" is out of ' + 'range "(min:%(vmin)s, max:%(vmax)s)".') % + dict(pname=PortSpec.SOURCE, + pvalue='0', + vmin='1', + vmax='65535')) + exception.ExceptionCollector.assertExceptionMessage( + exception.ValidationError, msg) + + # Test value below range min. + msg = (_('The value "%(pvalue)s" of property "%(pname)s" is out of ' + 'range "(min:%(vmin)s, max:%(vmax)s)".') % + dict(pname=PortSpec.SOURCE, + pvalue='1', + vmin='2', + vmax='65534')) + exception.ExceptionCollector.assertExceptionMessage( + exception.RangeValueError, msg) + + # Test value above range max. + msg = (_('The value "%(pvalue)s" of property "%(pname)s" is out of ' + 'range "(min:%(vmin)s, max:%(vmax)s)".') % + dict(pname=PortSpec.SOURCE, + pvalue='65535', + vmin='2', + vmax='65534')) + exception.ExceptionCollector.assertExceptionMessage( + exception.RangeValueError, msg) + + def test_containers(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/containers/test_container_docker_mysql.yaml") + ToscaTemplate(tosca_tpl, parsed_params={"mysql_root_pwd": "12345678"}) + + def test_endpoint_on_compute(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_endpoint_on_compute.yaml") + ToscaTemplate(tosca_tpl) + + def test_nested_dsl_def(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/dsl_definitions/test_nested_dsl_def.yaml") + self.assertIsNotNone(ToscaTemplate(tosca_tpl)) + + def test_multiple_policies(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/policies/test_tosca_nfv_multiple_policies.yaml") + tosca = ToscaTemplate(tosca_tpl) + self.assertEqual( + ['ALRM1', 'SP1', 'SP2'], + sorted([policy.name for policy in tosca.policies])) diff --git a/nfvparser/toscaparser/tests/test_toscatplvalidation.py b/nfvparser/toscaparser/tests/test_toscatplvalidation.py new file mode 100644 index 0000000..911867f --- /dev/null +++ b/nfvparser/toscaparser/tests/test_toscatplvalidation.py @@ -0,0 +1,1784 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import os +import six + +from toscaparser.common import exception +from toscaparser.imports import ImportsLoader +from toscaparser.nodetemplate import NodeTemplate +from toscaparser.parameters import Input +from toscaparser.parameters import Output +from toscaparser.policy import Policy +from toscaparser.relationship_template import RelationshipTemplate +from toscaparser.repositories import Repository +from toscaparser.tests.base import TestCase +from toscaparser.topology_template import TopologyTemplate +from toscaparser.tosca_template import ToscaTemplate +from toscaparser.triggers import Triggers +from toscaparser.utils.gettextutils import _ +import toscaparser.utils.yamlparser + + +class ToscaTemplateValidationTest(TestCase): + + def test_well_defined_template(self): + tpl_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/tosca_single_instance_wordpress.yaml") + params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user', + 'db_root_pwd': '12345678'} + self.assertIsNotNone(ToscaTemplate(tpl_path, params)) + + def test_custom_interface_allowed(self): + tpl_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/interfaces/test_custom_interface_in_template.yaml") + self.assertIsNotNone(ToscaTemplate(tpl_path)) + + def test_custom_interface_invalid_operation(self): + tpl_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/interfaces/test_custom_interface_invalid_operation.yaml") + self.assertRaises(exception.ValidationError, + ToscaTemplate, tpl_path) + exception.ExceptionCollector.assertExceptionMessage( + exception.UnknownFieldError, + _('"interfaces" of template "customInterfaceTest" ' + 'contains unknown field "CustomOp4". ' + 'Refer to the definition to verify valid values.')) + + def test_first_level_sections(self): + tpl_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_tosca_top_level_error1.yaml") + self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path) + exception.ExceptionCollector.assertExceptionMessage( + exception.MissingRequiredFieldError, + _('Template is missing required field ' + '"tosca_definitions_version".')) + + tpl_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_tosca_top_level_error2.yaml") + self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path) + exception.ExceptionCollector.assertExceptionMessage( + exception.UnknownFieldError, + _('Template contains unknown field "node_template". Refer to the ' + 'definition to verify valid values.')) + + def test_template_with_imports_validation(self): + tpl_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/tosca_imports_validation.yaml") + self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path) + exception.ExceptionCollector.assertExceptionMessage( + exception.UnknownFieldError, + _('Template custom_types/imported_sample.yaml contains unknown ' + 'field "descriptions". Refer to the definition' + ' to verify valid values.')) + exception.ExceptionCollector.assertExceptionMessage( + exception.UnknownFieldError, + _('Template custom_types/imported_sample.yaml contains unknown ' + 'field "node_typess". Refer to the definition to ' + 'verify valid values.')) + exception.ExceptionCollector.assertExceptionMessage( + exception.UnknownFieldError, + _('Template custom_types/imported_sample.yaml contains unknown ' + 'field "tosca1_definitions_version". Refer to the definition' + ' to verify valid values.')) + exception.ExceptionCollector.assertExceptionMessage( + exception.InvalidTemplateVersion, + _('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_profile_for_nfv_1_0_0".')) + exception.ExceptionCollector.assertExceptionMessage( + exception.UnknownFieldError, + _('Template custom_types/imported_sample.yaml contains unknown ' + 'field "policy_types1". Refer to the definition to ' + 'verify valid values.')) + exception.ExceptionCollector.assertExceptionMessage( + exception.UnknownFieldError, + _('Nodetype"tosca.nodes.SoftwareComponent.Logstash" contains ' + 'unknown field "capabilities1". Refer to the definition ' + 'to verify valid values.')) + exception.ExceptionCollector.assertExceptionMessage( + exception.UnknownFieldError, + _('Policy "mycompany.mytypes.myScalingPolicy" contains unknown ' + 'field "derived1_from". Refer to the definition to ' + 'verify valid values.')) + exception.ExceptionCollector.assertExceptionMessage( + exception.UnknownFieldError, + _('Relationshiptype "test.relation.connects" contains unknown ' + 'field "derived_from4". Refer to the definition to ' + 'verify valid values.')) + + def test_getoperation_IncorrectValue(self): + # test case 1 + tpl_snippet = ''' + node_templates: + front_end: + type: tosca.nodes.Compute + interfaces: + Standard: + create: + implementation: scripts/frontend/create.sh + configure: + implementation: scripts/frontend/configure.sh + inputs: + data_dir: {get_operation_output: [front_end,Standard1, + create,data_dir]} + ''' + tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) + err = self.assertRaises(ValueError, + TopologyTemplate, tpl, None) + expectedmessage = _('Enter a valid interface name') + self.assertEqual(expectedmessage, err.__str__()) + # test case 2 + tpl_snippet2 = ''' + node_templates: + front_end: + type: tosca.nodes.Compute + interfaces: + Standard: + create: + implementation: scripts/frontend/create.sh + configure: + implementation: scripts/frontend/configure.sh + inputs: + data_dir: {get_operation_output: [front_end1,Standard, + create,data_dir]} + ''' + tpl2 = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet2)) + err2 = self.assertRaises(KeyError, + TopologyTemplate, tpl2, None) + expectedmessage2 = _('\'Node template "front_end1" was not found.\'') + self.assertEqual(expectedmessage2, err2.__str__()) + # test case 3 + tpl_snippet3 = ''' + node_templates: + front_end: + type: tosca.nodes.Compute + interfaces: + Standard: + create: + implementation: scripts/frontend/create.sh + configure: + implementation: scripts/frontend/configure.sh + inputs: + data_dir: {get_operation_output: [front_end,Standard, + get_target,data_dir]} + ''' + tpl3 = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet3)) + err3 = self.assertRaises(ValueError, + TopologyTemplate, tpl3, None) + expectedmessage3 = _('Enter an operation of Standard interface') + self.assertEqual(expectedmessage3, err3.__str__()) + # test case 4 + tpl_snippet4 = ''' + node_templates: + front_end: + type: tosca.nodes.Compute + interfaces: + Standard: + create: + implementation: scripts/frontend/create.sh + configure: + implementation: scripts/frontend/configure.sh + inputs: + data_dir: {get_operation_output: [front_end,Configure, + create,data_dir]} + ''' + tpl4 = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet4)) + err4 = self.assertRaises(ValueError, + TopologyTemplate, tpl4, None) + expectedmessage4 = _('Enter an operation of Configure interface') + self.assertEqual(expectedmessage4, err4.__str__()) + # test case 5 + tpl_snippet5 = ''' + node_templates: + front_end: + type: tosca.nodes.Compute + interfaces: + Standard: + create: + implementation: scripts/frontend/create.sh + configure: + implementation: scripts/frontend/configure.sh + inputs: + data_dir: {get_operation_output: [front_end,Standard, + create]} + ''' + tpl5 = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet5)) + err5 = self.assertRaises(ValueError, + TopologyTemplate, tpl5, None) + expectedmessage5 = _('Illegal arguments for function' + ' "get_operation_output".' + ' Expected arguments: "template_name",' + '"interface_name",' + '"operation_name","output_variable_name"') + self.assertEqual(expectedmessage5, err5.__str__()) + + def test_unsupported_type(self): + tpl_snippet = ''' + node_templates: + invalid_type: + type: tosca.test.invalidtype + properties: + size: { get_input: storage_size } + snapshot_id: { get_input: storage_snapshot_id } + ''' + tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) + err = self.assertRaises(exception.UnsupportedTypeError, + TopologyTemplate, tpl, None) + expectedmessage = _('Type "tosca.test.invalidtype" is valid' + ' TOSCA type but not supported at this time.') + self.assertEqual(expectedmessage, err.__str__()) + + def test_inputs(self): + tpl_snippet1 = ''' + inputs: + cpus: + type: integer + description: Number of CPUs for the server. + constraint: + - valid_values: [ 1, 2, 4 ] + required: yes + status: supported + ''' + tpl_snippet2 = ''' + inputs: + cpus: + type: integer + description: Number of CPUs for the server. + constraints: + - valid_values: [ 1, 2, 4 ] + required: yes + status: supported + ''' + tpl_snippet3 = ''' + inputs: + some_list: + type: list + description: List of items + entry_schema: + type: string + default: [] + ''' + inputs1 = (toscaparser.utils.yamlparser. + simple_parse(tpl_snippet1)['inputs']) + name1, attrs1 = list(inputs1.items())[0] + inputs2 = (toscaparser.utils.yamlparser. + simple_parse(tpl_snippet2)['inputs']) + name2, attrs2 = list(inputs2.items())[0] + try: + Input(name1, attrs1) + except Exception as err: + self.assertEqual(_('Input "cpus" contains unknown field ' + '"constraint". Refer to the definition to ' + 'verify valid values.'), + err.__str__()) + input2 = Input(name2, attrs2) + self.assertTrue(input2.required) + toscaparser.utils.yamlparser.simple_parse(tpl_snippet3)['inputs'] + + def _imports_content_test(self, tpl_snippet, path, custom_type_def): + imports = (toscaparser.utils.yamlparser. + simple_parse(tpl_snippet)['imports']) + loader = ImportsLoader(imports, path, custom_type_def) + return loader.get_custom_defs() + + def test_imports_without_templates(self): + tpl_snippet = ''' + imports: + # omitted here for brevity + ''' + path = 'toscaparser/tests/data/tosca_elk.yaml' + errormsg = _('"imports" keyname is defined without including ' + 'templates.') + err = self.assertRaises(exception.ValidationError, + self._imports_content_test, + tpl_snippet, + path, + "node_types") + self.assertEqual(errormsg, err.__str__()) + + def test_imports_with_name_without_templates(self): + tpl_snippet = ''' + imports: + - some_definitions: + ''' + path = 'toscaparser/tests/data/tosca_elk.yaml' + errormsg = _('A template file name is not provided with import ' + 'definition "some_definitions".') + err = self.assertRaises(exception.ValidationError, + self._imports_content_test, + tpl_snippet, path, None) + self.assertEqual(errormsg, err.__str__()) + + def test_imports_without_import_name(self): + tpl_snippet = ''' + imports: + - custom_types/paypalpizzastore_nodejs_app.yaml + - https://raw.githubusercontent.com/openstack/\ +tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml + ''' + path = 'toscaparser/tests/data/tosca_elk.yaml' + custom_defs = self._imports_content_test(tpl_snippet, + path, + "node_types") + self.assertTrue(custom_defs) + + def test_imports_wth_import_name(self): + tpl_snippet = ''' + imports: + - some_definitions: custom_types/paypalpizzastore_nodejs_app.yaml + - more_definitions: + file: 'https://raw.githubusercontent.com/openstack/tosca-parser\ +/master/toscaparser/tests/data/custom_types/wordpress.yaml' + namespace_prefix: single_instance_wordpress + ''' + path = 'toscaparser/tests/data/tosca_elk.yaml' + custom_defs = self._imports_content_test(tpl_snippet, + path, + "node_types") + self.assertTrue(custom_defs.get("single_instance_wordpress.tosca." + "nodes.WebApplication.WordPress")) + + def test_imports_wth_namespace_prefix(self): + tpl_snippet = ''' + imports: + - more_definitions: + file: custom_types/nested_rsyslog.yaml + namespace_prefix: testprefix + ''' + path = 'toscaparser/tests/data/tosca_elk.yaml' + custom_defs = self._imports_content_test(tpl_snippet, + path, + "node_types") + self.assertTrue(custom_defs.get("testprefix.Rsyslog")) + + def test_imports_with_no_main_template(self): + tpl_snippet = ''' + imports: + - some_definitions: https://raw.githubusercontent.com/openstack/\ +tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml + - some_definitions: + file: my_defns/my_typesdefs_n.yaml + ''' + errormsg = _('Input tosca template is not provided.') + err = self.assertRaises(exception.ValidationError, + self._imports_content_test, + tpl_snippet, None, None) + self.assertEqual(errormsg, err.__str__()) + + def test_imports_duplicate_name(self): + tpl_snippet = ''' + imports: + - some_definitions: https://raw.githubusercontent.com/openstack/\ +tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml + - some_definitions: + file: my_defns/my_typesdefs_n.yaml + ''' + errormsg = _('Duplicate import name "some_definitions" was found.') + path = 'toscaparser/tests/data/tosca_elk.yaml' + err = self.assertRaises(exception.ValidationError, + self._imports_content_test, + tpl_snippet, path, None) + self.assertEqual(errormsg, err.__str__()) + + def test_imports_missing_req_field_in_def(self): + tpl_snippet = ''' + imports: + - more_definitions: + file1: my_defns/my_typesdefs_n.yaml + repository: my_company_repo + namespace_uri: http://mycompany.com/ns/tosca/2.0 + namespace_prefix: mycompany + ''' + errormsg = _('Import of template "more_definitions" is missing ' + 'required field "file".') + path = 'toscaparser/tests/data/tosca_elk.yaml' + err = self.assertRaises(exception.MissingRequiredFieldError, + self._imports_content_test, + tpl_snippet, path, None) + self.assertEqual(errormsg, err.__str__()) + + def test_imports_file_with_uri(self): + tpl_snippet = ''' + imports: + - more_definitions: + file: https://raw.githubusercontent.com/openstack/\ +tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml + ''' + path = 'https://raw.githubusercontent.com/openstack/\ +tosca-parser/master/toscaparser/tests/data/\ +tosca_single_instance_wordpress_with_url_import.yaml' + custom_defs = self._imports_content_test(tpl_snippet, + path, + "node_types") + self.assertTrue(custom_defs.get("tosca.nodes." + "WebApplication.WordPress")) + + def test_imports_file_namespace_fields(self): + tpl_snippet = ''' + imports: + - more_definitions: + file: https://raw.githubusercontent.com/openstack/\ +heat-translator/master/translator/tests/data/custom_types/wordpress.yaml + namespace_prefix: mycompany + namespace_uri: http://docs.oasis-open.org/tosca/ns/simple/yaml/1.0 + ''' + path = 'toscaparser/tests/data/tosca_elk.yaml' + custom_defs = self._imports_content_test(tpl_snippet, + path, + "node_types") + self.assertTrue(custom_defs.get("mycompany.tosca.nodes." + "WebApplication.WordPress")) + + def test_import_error_file_uri(self): + tpl_snippet = ''' + imports: + - more_definitions: + file: mycompany.com/ns/tosca/2.0/toscaparser/tests/data\ +/tosca_elk.yaml + namespace_prefix: mycompany + namespace_uri: http://docs.oasis-open.org/tosca/ns/simple/yaml/1.0 + ''' + path = 'toscaparser/tests/data/tosca_elk.yaml' + self.assertRaises(ImportError, + self._imports_content_test, + tpl_snippet, path, None) + + def test_import_single_line_error(self): + tpl_snippet = ''' + imports: + - some_definitions: abc.com/tests/data/tosca_elk.yaml + ''' + errormsg = _('Import "abc.com/tests/data/tosca_elk.yaml" is not ' + 'valid.') + path = 'toscaparser/tests/data/tosca_elk.yaml' + err = self.assertRaises(ImportError, + self._imports_content_test, + tpl_snippet, path, None) + self.assertEqual(errormsg, err.__str__()) + + def test_outputs(self): + tpl_snippet = ''' + outputs: + server_address: + description: IP address of server instance. + values: { get_property: [server, private_address] } + ''' + outputs = (toscaparser.utils.yamlparser. + simple_parse(tpl_snippet)['outputs']) + name, attrs = list(outputs.items())[0] + output = Output(name, attrs) + try: + output.validate() + except Exception as err: + self.assertTrue( + isinstance(err, exception.MissingRequiredFieldError)) + self.assertEqual(_('Output "server_address" is missing required ' + 'field "value".'), err.__str__()) + + tpl_snippet = ''' + outputs: + server_address: + descriptions: IP address of server instance. + value: { get_property: [server, private_address] } + ''' + outputs = (toscaparser.utils.yamlparser. + simple_parse(tpl_snippet)['outputs']) + name, attrs = list(outputs.items())[0] + output = Output(name, attrs) + try: + output.validate() + except Exception as err: + self.assertIsInstance(err, exception.UnknownFieldError) + self.assertEqual(_('Output "server_address" contains unknown ' + 'field "descriptions". Refer to the definition ' + 'to verify valid values.'), + err.__str__()) + + def _repo_content(self, path): + repositories = path['repositories'] + reposit = [] + for name, val in repositories.items(): + reposits = Repository(name, val) + reposit.append(reposits) + return reposit + + def test_repositories(self): + tpl_snippet = ''' + repositories: + repo_code0: https://raw.githubusercontent.com/nandinivemula/intern + repo_code1: + description: My project's code Repository in github usercontent. + url: https://github.com/nandinivemula/intern + credential: + user: nandini + password: tcs@12345 + repo_code2: + description: My Project's code Repository in github. + url: https://github.com/nandinivemula/intern + credential: + user: xyzw + password: xyz@123 + ''' + tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) + repoobject = self._repo_content(tpl) + actualrepo_names = [] + for repo in repoobject: + repos = repo.name + actualrepo_names.append(repos) + reposname = list(tpl.values()) + reposnames = reposname[0] + expected_reponames = list(reposnames.keys()) + self.assertEqual(expected_reponames, actualrepo_names) + + def test_repositories_with_missing_required_field(self): + tpl_snippet = ''' + repositories: + repo_code0: https://raw.githubusercontent.com/nandinivemula/intern + repo_code1: + description: My project's code Repository in github usercontent. + credential: + user: nandini + password: tcs@12345 + repo_code2: + description: My Project's code Repository in github. + url: https://github.com/nandinivemula/intern + credential: + user: xyzw + password: xyz@123 + ''' + tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) + err = self.assertRaises(exception.MissingRequiredFieldError, + self._repo_content, tpl) + expectedmessage = _('Repository "repo_code1" is missing ' + 'required field "url".') + self.assertEqual(expectedmessage, err.__str__()) + + def test_repositories_with_unknown_field(self): + tpl_snippet = ''' + repositories: + repo_code0: https://raw.githubusercontent.com/nandinivemula/intern + repo_code1: + description: My project's code Repository in github usercontent. + url: https://github.com/nandinivemula/intern + credential: + user: nandini + password: tcs@12345 + repo_code2: + descripton: My Project's code Repository in github. + url: https://github.com/nandinivemula/intern + credential: + user: xyzw + password: xyz@123 + ''' + tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) + err = self.assertRaises(exception.UnknownFieldError, + self._repo_content, tpl) + expectedmessage = _('repositories "repo_code2" contains unknown field' + ' "descripton". Refer to the definition to verify' + ' valid values.') + self.assertEqual(expectedmessage, err.__str__()) + + def test_repositories_with_invalid_url(self): + tpl_snippet = ''' + repositories: + repo_code0: https://raw.githubusercontent.com/nandinivemula/intern + repo_code1: + description: My project's code Repository in github usercontent. + url: h + credential: + user: nandini + password: tcs@12345 + repo_code2: + description: My Project's code Repository in github. + url: https://github.com/nandinivemula/intern + credential: + user: xyzw + password: xyz@123 + ''' + tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) + err = self.assertRaises(exception.URLException, + self._repo_content, tpl) + expectedmessage = _('repsositories "repo_code1" Invalid Url') + self.assertEqual(expectedmessage, err.__str__()) + + def test_groups(self): + tpl_snippet = ''' + node_templates: + server: + type: tosca.nodes.Compute + requirements: + - log_endpoint: + capability: log_endpoint + + mysql_dbms: + type: tosca.nodes.DBMS + properties: + root_password: aaa + port: 3376 + + groups: + webserver_group: + type: tosca.groups.Root + members: [ server, mysql_dbms ] + ''' + tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) + TopologyTemplate(tpl, None) + + def test_groups_with_missing_required_field(self): + tpl_snippet = ''' + node_templates: + server: + type: tosca.nodes.Compute + requirements: + - log_endpoint: + capability: log_endpoint + + mysql_dbms: + type: tosca.nodes.DBMS + properties: + root_password: aaa + port: 3376 + + groups: + webserver_group: + members: ['server', 'mysql_dbms'] + ''' + tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) + err = self.assertRaises(exception.MissingRequiredFieldError, + TopologyTemplate, tpl, None) + expectedmessage = _('Template "webserver_group" is missing ' + 'required field "type".') + self.assertEqual(expectedmessage, err.__str__()) + + def test_groups_with_unknown_target(self): + tpl_snippet = ''' + node_templates: + server: + type: tosca.nodes.Compute + requirements: + - log_endpoint: + capability: log_endpoint + + mysql_dbms: + type: tosca.nodes.DBMS + properties: + root_password: aaa + port: 3376 + + groups: + webserver_group: + type: tosca.groups.Root + members: [ serv, mysql_dbms ] + ''' + tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) + expectedmessage = _('"Target member "serv" is not found in ' + 'node_templates"') + err = self.assertRaises(exception.InvalidGroupTargetException, + TopologyTemplate, tpl, None) + self.assertEqual(expectedmessage, err.__str__()) + + def test_groups_with_repeated_targets(self): + tpl_snippet = ''' + node_templates: + server: + type: tosca.nodes.Compute + requirements: + - log_endpoint: + capability: log_endpoint + + mysql_dbms: + type: tosca.nodes.DBMS + properties: + root_password: aaa + port: 3376 + + groups: + webserver_group: + type: tosca.groups.Root + members: [ server, server, mysql_dbms ] + ''' + tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) + expectedmessage = _('"Member nodes ' + '"[\'server\', \'server\', \'mysql_dbms\']" ' + 'should be >= 1 and not repeated"') + err = self.assertRaises(exception.InvalidGroupTargetException, + TopologyTemplate, tpl, None) + self.assertEqual(expectedmessage, err.__str__()) + + def test_groups_with_only_one_target(self): + tpl_snippet = ''' + node_templates: + server: + type: tosca.nodes.Compute + requirements: + - log_endpoint: + capability: log_endpoint + + mysql_dbms: + type: tosca.nodes.DBMS + properties: + root_password: aaa + port: 3376 + + groups: + webserver_group: + type: tosca.groups.Root + members: [] + ''' + tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) + expectedmessage = _('"Member nodes "[]" should be >= 1 ' + 'and not repeated"') + err = self.assertRaises(exception.InvalidGroupTargetException, + TopologyTemplate, tpl, None) + self.assertEqual(expectedmessage, err.__str__()) + + def _custom_types(self): + custom_types = {} + def_file = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/custom_types/wordpress.yaml") + custom_type = toscaparser.utils.yamlparser.load_yaml(def_file) + node_types = custom_type['node_types'] + for name in node_types: + defintion = node_types[name] + custom_types[name] = defintion + return custom_types + + def _single_node_template_content_test(self, tpl_snippet): + nodetemplates = (toscaparser.utils.yamlparser. + simple_ordered_parse(tpl_snippet))['node_templates'] + name = list(nodetemplates.keys())[0] + nodetemplate = NodeTemplate(name, nodetemplates, + self._custom_types()) + nodetemplate.validate() + nodetemplate.requirements + nodetemplate.get_capabilities_objects() + nodetemplate.get_properties_objects() + nodetemplate.interfaces + + def test_node_templates(self): + tpl_snippet = ''' + node_templates: + server: + capabilities: + host: + properties: + disk_size: 10 + num_cpus: 4 + mem_size: 4096 + os: + properties: + architecture: x86_64 + type: Linux + distribution: Fedora + version: 18.0 + ''' + expectedmessage = _('Template "server" is missing required field ' + '"type".') + err = self.assertRaises( + exception.MissingRequiredFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_node_template_with_wrong_properties_keyname(self): + """Node template keyname 'properties' given as 'propertiessss'.""" + tpl_snippet = ''' + node_templates: + mysql_dbms: + type: tosca.nodes.DBMS + propertiessss: + root_password: aaa + port: 3376 + ''' + expectedmessage = _('Node template "mysql_dbms" contains unknown ' + 'field "propertiessss". Refer to the definition ' + 'to verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_node_template_with_wrong_requirements_keyname(self): + """Node template keyname 'requirements' given as 'requirement'.""" + tpl_snippet = ''' + node_templates: + mysql_dbms: + type: tosca.nodes.DBMS + properties: + root_password: aaa + port: 3376 + requirement: + - host: server + ''' + expectedmessage = _('Node template "mysql_dbms" contains unknown ' + 'field "requirement". Refer to the definition to ' + 'verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_node_template_with_wrong_interfaces_keyname(self): + """Node template keyname 'interfaces' given as 'interfac'.""" + tpl_snippet = ''' + node_templates: + mysql_dbms: + type: tosca.nodes.DBMS + properties: + root_password: aaa + port: 3376 + requirements: + - host: server + interfac: + Standard: + configure: mysql_database_configure.sh + ''' + expectedmessage = _('Node template "mysql_dbms" contains unknown ' + 'field "interfac". Refer to the definition to ' + 'verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_node_template_with_wrong_capabilities_keyname(self): + """Node template keyname 'capabilities' given as 'capabilitiis'.""" + tpl_snippet = ''' + node_templates: + mysql_database: + type: tosca.nodes.Database + properties: + db_name: { get_input: db_name } + db_user: { get_input: db_user } + db_password: { get_input: db_pwd } + capabilitiis: + database_endpoint: + properties: + port: { get_input: db_port } + ''' + expectedmessage = _('Node template "mysql_database" contains unknown ' + 'field "capabilitiis". Refer to the definition to ' + 'verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_node_template_with_wrong_artifacts_keyname(self): + """Node template keyname 'artifacts' given as 'artifactsss'.""" + tpl_snippet = ''' + node_templates: + mysql_database: + type: tosca.nodes.Database + artifactsss: + db_content: + implementation: files/my_db_content.txt + type: tosca.artifacts.File + ''' + expectedmessage = _('Node template "mysql_database" contains unknown ' + 'field "artifactsss". Refer to the definition to ' + 'verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_node_template_with_multiple_wrong_keynames(self): + """Node templates given with multiple wrong keynames.""" + tpl_snippet = ''' + node_templates: + mysql_dbms: + type: tosca.nodes.DBMS + propertieees: + root_password: aaa + port: 3376 + requirements: + - host: server + interfacs: + Standard: + configure: mysql_database_configure.sh + ''' + expectedmessage = _('Node template "mysql_dbms" contains unknown ' + 'field "propertieees". Refer to the definition to ' + 'verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + tpl_snippet = ''' + node_templates: + mysql_database: + type: tosca.nodes.Database + properties: + name: { get_input: db_name } + user: { get_input: db_user } + password: { get_input: db_pwd } + capabilitiiiies: + database_endpoint: + properties: + port: { get_input: db_port } + requirementsss: + - host: + node: mysql_dbms + interfac: + Standard: + configure: mysql_database_configure.sh + + ''' + expectedmessage = _('Node template "mysql_database" contains unknown ' + 'field "capabilitiiiies". Refer to the definition ' + 'to verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_node_template_type(self): + tpl_snippet = ''' + node_templates: + mysql_database: + type: tosca.nodes.Databases + properties: + db_name: { get_input: db_name } + db_user: { get_input: db_user } + db_password: { get_input: db_pwd } + capabilities: + database_endpoint: + properties: + port: { get_input: db_port } + requirements: + - host: mysql_dbms + interfaces: + Standard: + configure: mysql_database_configure.sh + ''' + expectedmessage = _('Type "tosca.nodes.Databases" is not ' + 'a valid type.') + err = self.assertRaises( + exception.InvalidTypeError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_node_template_requirements(self): + tpl_snippet = ''' + node_templates: + webserver: + type: tosca.nodes.WebServer + requirements: + host: server + interfaces: + Standard: + create: webserver_install.sh + start: d.sh + ''' + expectedmessage = _('"requirements" of template "webserver" must be ' + 'of type "list".') + err = self.assertRaises( + exception.TypeMismatchError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + tpl_snippet = ''' + node_templates: + mysql_database: + type: tosca.nodes.Database + properties: + db_name: { get_input: db_name } + db_user: { get_input: db_user } + db_password: { get_input: db_pwd } + capabilities: + database_endpoint: + properties: + port: { get_input: db_port } + requirements: + - host: mysql_dbms + - database_endpoint: mysql_database + interfaces: + Standard: + configure: mysql_database_configure.sh + ''' + expectedmessage = _('"requirements" of template "mysql_database" ' + 'contains unknown field "database_endpoint". ' + 'Refer to the definition to verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_node_template_requirements_with_wrong_node_keyname(self): + """Node template requirements keyname 'node' given as 'nodes'.""" + tpl_snippet = ''' + node_templates: + mysql_database: + type: tosca.nodes.Database + requirements: + - host: + nodes: mysql_dbms + + ''' + expectedmessage = _('"requirements" of template "mysql_database" ' + 'contains unknown field "nodes". Refer to the ' + 'definition to verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_node_template_requirements_with_wrong_capability_keyname(self): + """Incorrect node template requirements keyname + + Node template requirements keyname 'capability' given as + 'capabilityy'. + """ + tpl_snippet = ''' + node_templates: + mysql_database: + type: tosca.nodes.Database + requirements: + - host: + node: mysql_dbms + - log_endpoint: + node: logstash + capabilityy: log_endpoint + relationship: + type: tosca.relationships.ConnectsTo + + ''' + expectedmessage = _('"requirements" of template "mysql_database" ' + 'contains unknown field "capabilityy". Refer to ' + 'the definition to verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_node_template_requirements_with_wrong_relationship_keyname(self): + """Incorrect node template requirements keyname + + Node template requirements keyname 'relationship' given as + 'relationshipppp'. + """ + tpl_snippet = ''' + node_templates: + mysql_database: + type: tosca.nodes.Database + requirements: + - host: + node: mysql_dbms + - log_endpoint: + node: logstash + capability: log_endpoint + relationshipppp: + type: tosca.relationships.ConnectsTo + + ''' + expectedmessage = _('"requirements" of template "mysql_database" ' + 'contains unknown field "relationshipppp". Refer ' + 'to the definition to verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_node_template_requirements_with_wrong_occurrences_keyname(self): + """Incorrect node template requirements keyname + + Node template requirements keyname 'occurrences' given as + 'occurences'. + """ + tpl_snippet = ''' + node_templates: + mysql_database: + type: tosca.nodes.Database + requirements: + - host: + node: mysql_dbms + - log_endpoint: + node: logstash + capability: log_endpoint + relationship: + type: tosca.relationships.ConnectsTo + occurences: [0, UNBOUNDED] + ''' + expectedmessage = _('"requirements" of template "mysql_database" ' + 'contains unknown field "occurences". Refer to ' + 'the definition to verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_node_template_requirements_with_multiple_wrong_keynames(self): + """Node templates given with multiple wrong requirements keynames.""" + tpl_snippet = ''' + node_templates: + mysql_database: + type: tosca.nodes.Database + requirements: + - host: + node: mysql_dbms + - log_endpoint: + nod: logstash + capabilit: log_endpoint + relationshipppp: + type: tosca.relationships.ConnectsTo + + ''' + expectedmessage = _('"requirements" of template "mysql_database" ' + 'contains unknown field "nod". Refer to the ' + 'definition to verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + tpl_snippet = ''' + node_templates: + mysql_database: + type: tosca.nodes.Database + requirements: + - host: + node: mysql_dbms + - log_endpoint: + node: logstash + capabilit: log_endpoint + relationshipppp: + type: tosca.relationships.ConnectsTo + + ''' + expectedmessage = _('"requirements" of template "mysql_database" ' + 'contains unknown field "capabilit". Refer to the ' + 'definition to verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_node_template_requirements_invalid_occurrences(self): + tpl_snippet = ''' + node_templates: + server: + type: tosca.nodes.Compute + requirements: + - log_endpoint: + capability: log_endpoint + occurrences: [0, -1] + ''' + expectedmessage = _('Value of property "[0, -1]" is invalid.') + err = self.assertRaises( + exception.InvalidPropertyValueError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + tpl_snippet = ''' + node_templates: + server: + type: tosca.nodes.Compute + requirements: + - log_endpoint: + capability: log_endpoint + occurrences: [a, w] + ''' + expectedmessage = _('"a" is not an integer.') + err = self.assertRaises( + ValueError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + tpl_snippet = ''' + node_templates: + server: + type: tosca.nodes.Compute + requirements: + - log_endpoint: + capability: log_endpoint + occurrences: -1 + ''' + expectedmessage = _('"-1" is not a list.') + err = self.assertRaises( + ValueError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + tpl_snippet = ''' + node_templates: + server: + type: tosca.nodes.Compute + requirements: + - log_endpoint: + capability: log_endpoint + occurrences: [5, 1] + ''' + expectedmessage = _('Value of property "[5, 1]" is invalid.') + err = self.assertRaises( + exception.InvalidPropertyValueError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + tpl_snippet = ''' + node_templates: + server: + type: tosca.nodes.Compute + requirements: + - log_endpoint: + capability: log_endpoint + occurrences: [0, 0] + ''' + expectedmessage = _('Value of property "[0, 0]" is invalid.') + err = self.assertRaises( + exception.InvalidPropertyValueError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_node_template_requirements_valid_occurrences(self): + tpl_snippet = ''' + node_templates: + server: + type: tosca.nodes.Compute + requirements: + - log_endpoint: + capability: log_endpoint + occurrences: [2, 2] + ''' + self._single_node_template_content_test(tpl_snippet) + + def test_node_template_capabilities(self): + tpl_snippet = ''' + node_templates: + mysql_database: + type: tosca.nodes.Database + properties: + db_name: { get_input: db_name } + db_user: { get_input: db_user } + db_password: { get_input: db_pwd } + capabilities: + http_endpoint: + properties: + port: { get_input: db_port } + requirements: + - host: mysql_dbms + interfaces: + Standard: + configure: mysql_database_configure.sh + ''' + expectedmessage = _('"capabilities" of template "mysql_database" ' + 'contains unknown field "http_endpoint". Refer to ' + 'the definition to verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_node_template_properties(self): + tpl_snippet = ''' + node_templates: + server: + type: tosca.nodes.Compute + properties: + os_image: F18_x86_64 + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Fedora + version: 18.0 + ''' + expectedmessage = _('"properties" of template "server" contains ' + 'unknown field "os_image". Refer to the ' + 'definition to verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_node_template_interfaces(self): + tpl_snippet = ''' + node_templates: + wordpress: + type: tosca.nodes.WebApplication.WordPress + requirements: + - host: webserver + - database_endpoint: mysql_database + interfaces: + Standards: + create: wordpress_install.sh + configure: + implementation: wordpress_configure.sh + inputs: + wp_db_name: { get_property: [ mysql_database, db_name ] } + wp_db_user: { get_property: [ mysql_database, db_user ] } + wp_db_password: { get_property: [ mysql_database, \ + db_password ] } + wp_db_port: { get_property: [ SELF, \ + database_endpoint, port ] } + ''' + expectedmessage = _('"interfaces" of template "wordpress" contains ' + 'unknown field "Standards". Refer to the ' + 'definition to verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + tpl_snippet = ''' + node_templates: + wordpress: + type: tosca.nodes.WebApplication.WordPress + requirements: + - host: webserver + - database_endpoint: mysql_database + interfaces: + Standard: + create: wordpress_install.sh + config: + implementation: wordpress_configure.sh + inputs: + wp_db_name: { get_property: [ mysql_database, db_name ] } + wp_db_user: { get_property: [ mysql_database, db_user ] } + wp_db_password: { get_property: [ mysql_database, \ + db_password ] } + wp_db_port: { get_property: [ SELF, \ + database_endpoint, port ] } + ''' + expectedmessage = _('"interfaces" of template "wordpress" contains ' + 'unknown field "config". Refer to the definition ' + 'to verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + tpl_snippet = ''' + node_templates: + wordpress: + type: tosca.nodes.WebApplication.WordPress + requirements: + - host: webserver + - database_endpoint: mysql_database + interfaces: + Standard: + create: wordpress_install.sh + configure: + implementation: wordpress_configure.sh + input: + wp_db_name: { get_property: [ mysql_database, db_name ] } + wp_db_user: { get_property: [ mysql_database, db_user ] } + wp_db_password: { get_property: [ mysql_database, \ + db_password ] } + wp_db_port: { get_ref_property: [ database_endpoint, \ + database_endpoint, port ] } + ''' + expectedmessage = _('"interfaces" of template "wordpress" contains ' + 'unknown field "input". Refer to the definition ' + 'to verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_relationship_template_properties(self): + tpl_snippet = ''' + relationship_templates: + storage_attachto: + type: AttachesTo + properties: + device: test_device + ''' + expectedmessage = _('"properties" of template "storage_attachto" is ' + 'missing required field "[\'location\']".') + rel_template = (toscaparser.utils.yamlparser. + simple_parse(tpl_snippet))['relationship_templates'] + name = list(rel_template.keys())[0] + rel_template = RelationshipTemplate(rel_template[name], name) + err = self.assertRaises(exception.MissingRequiredFieldError, + rel_template.validate) + self.assertEqual(expectedmessage, six.text_type(err)) + + def test_invalid_template_version(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_invalid_template_version.yaml") + self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl) + valid_versions = ', '.join(ToscaTemplate.VALID_TEMPLATE_VERSIONS) + exception.ExceptionCollector.assertExceptionMessage( + exception.InvalidTemplateVersion, + (_('The template version "tosca_xyz" is invalid. Valid versions ' + 'are "%s".') % valid_versions)) + + def test_node_template_capabilities_properties(self): + # validating capability property values + tpl_snippet = ''' + node_templates: + server: + type: tosca.nodes.WebServer + capabilities: + data_endpoint: + properties: + initiator: test + ''' + expectedmessage = _('The value "test" of property "initiator" is ' + 'not valid. Expected a value from "[source, ' + 'target, peer]".') + + err = self.assertRaises( + exception.ValidationError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + tpl_snippet = ''' + node_templates: + server: + type: tosca.nodes.Compute + capabilities: + host: + properties: + disk_size: 10 GB + num_cpus: { get_input: cpus } + mem_size: 4096 MB + os: + properties: + architecture: x86_64 + type: Linux + distribution: Fedora + version: 18.0 + scalable: + properties: + min_instances: 1 + max_instances: 3 + default_instances: 5 + ''' + expectedmessage = _('"properties" of template "server": ' + '"default_instances" value is not between ' + '"min_instances" and "max_instances".') + err = self.assertRaises( + exception.ValidationError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_node_template_objectstorage_without_required_property(self): + tpl_snippet = ''' + node_templates: + server: + type: tosca.nodes.ObjectStorage + properties: + maxsize: 1 GB + ''' + expectedmessage = _('"properties" of template "server" is missing ' + 'required field "[\'name\']".') + err = self.assertRaises( + exception.MissingRequiredFieldError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_node_template_objectstorage_with_invalid_scalar_unit(self): + tpl_snippet = ''' + node_templates: + server: + type: tosca.nodes.ObjectStorage + properties: + name: test + maxsize: -1 + ''' + expectedmessage = _('"-1" is not a valid scalar-unit.') + err = self.assertRaises( + ValueError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_node_template_objectstorage_with_invalid_scalar_type(self): + tpl_snippet = ''' + node_templates: + server: + type: tosca.nodes.ObjectStorage + properties: + name: test + maxsize: 1 XB + ''' + expectedmessage = _('"1 XB" is not a valid scalar-unit.') + err = self.assertRaises( + ValueError, + lambda: self._single_node_template_content_test(tpl_snippet)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_special_keywords(self): + """Test special keywords + + Test that special keywords, e.g. metadata, which are not part + of specification do not throw any validation error. + """ + tpl_snippet_metadata_map = ''' + node_templates: + server: + type: tosca.nodes.Compute + metadata: + name: server A + role: master + ''' + self._single_node_template_content_test(tpl_snippet_metadata_map) + + tpl_snippet_metadata_inline = ''' + node_templates: + server: + type: tosca.nodes.Compute + metadata: none + ''' + self._single_node_template_content_test(tpl_snippet_metadata_inline) + + def test_policy_valid_keynames(self): + tpl_snippet = ''' + policies: + - servers_placement: + type: tosca.policies.Placement + description: Apply placement policy to servers + metadata: { user1: 1001, user2: 1002 } + targets: [ serv1, serv2 ] + ''' + policies = (toscaparser.utils.yamlparser. + simple_parse(tpl_snippet))['policies'][0] + name = list(policies.keys())[0] + Policy(name, policies[name], None, None) + + def test_policy_invalid_keyname(self): + tpl_snippet = ''' + policies: + - servers_placement: + type: tosca.policies.Placement + testkey: testvalue + ''' + policies = (toscaparser.utils.yamlparser. + simple_parse(tpl_snippet))['policies'][0] + name = list(policies.keys())[0] + + expectedmessage = _('Policy "servers_placement" contains ' + 'unknown field "testkey". Refer to the ' + 'definition to verify valid values.') + err = self.assertRaises( + exception.UnknownFieldError, + lambda: Policy(name, policies[name], None, None)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_policy_trigger_valid_keyname(self): + tpl_snippet = ''' + triggers: + - resize_compute: + description: trigger + event_type: tosca.events.resource.utilization + schedule: + start_time: "2015-05-07T07:00:00Z" + end_time: "2015-06-07T07:00:00Z" + target_filter: + node: master-container + requirement: host + capability: Container + condition: + constraint: { greater_than: 50 } + period: 60 + evaluations: 1 + method : average + action: + resize: # Operation name + inputs: + strategy: LEAST_USED + implementation: Senlin.webhook() + ''' + 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(self): + tpl_snippet = ''' + triggers: + - resize_compute: + description: trigger + event_type: tosca.events.resource.utilization + schedule: + start_time: "2015-05-07T07:00:00Z" + end_time: "2015-06-07T07:00:00Z" + target_filter1: + node: master-container + requirement: host + capability: Container + condition: + constraint: utilization greater_than 50% + period1: 60 + evaluations: 1 + method: average + action: + resize: # Operation name + inputs: + strategy: LEAST_USED + implementation: Senlin.webhook() + ''' + triggers = (toscaparser.utils.yamlparser. + simple_parse(tpl_snippet))['triggers'][0] + name = list(triggers.keys())[0] + expectedmessage = _( + 'Triggers "resize_compute" contains unknown field ' + '"target_filter1". 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: + - servers_placement: + description: test description + ''' + policies = (toscaparser.utils.yamlparser. + simple_parse(tpl_snippet))['policies'][0] + name = list(policies.keys())[0] + + expectedmessage = _('Template "servers_placement" is missing ' + 'required field "type".') + err = self.assertRaises( + exception.MissingRequiredFieldError, + lambda: Policy(name, policies[name], None, None)) + self.assertEqual(expectedmessage, err.__str__()) + + def test_credential_datatype(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_credential_datatype.yaml") + self.assertIsNotNone(ToscaTemplate(tosca_tpl)) + + def test_invalid_default_value(self): + tpl_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_invalid_input_defaults.yaml") + self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path) + exception.ExceptionCollector.assertExceptionMessage( + ValueError, _('"two" is not an integer.')) + + def test_invalid_capability(self): + tpl_snippet = ''' + node_templates: + server: + type: tosca.nodes.Compute + capabilities: + oss: + properties: + architecture: x86_64 + ''' + tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet)) + err = self.assertRaises(exception.UnknownFieldError, + TopologyTemplate, tpl, None) + expectedmessage = _('"capabilities" of template "server" contains ' + 'unknown field "oss". Refer to the definition ' + 'to verify valid values.') + self.assertEqual(expectedmessage, err.__str__()) + + def test_qualified_name(self): + tpl_snippet_full_name = ''' + node_templates: + supported_type: + type: tosca.nodes.Compute + ''' + tpl = ( + toscaparser.utils.yamlparser.simple_parse( + tpl_snippet_full_name)) + TopologyTemplate(tpl, None) + + tpl_snippet_short_name = ''' + node_templates: + supported_type: + type: Compute + ''' + tpl = ( + toscaparser.utils.yamlparser.simple_parse( + tpl_snippet_short_name)) + TopologyTemplate(tpl, None) + + tpl_snippet_qualified_name = ''' + node_templates: + supported_type: + type: tosca:Compute + ''' + tpl = ( + toscaparser.utils.yamlparser.simple_parse( + tpl_snippet_qualified_name)) + TopologyTemplate(tpl, None) + + def test_requirements_as_list(self): + """Node template with requirements provided with or without list + + Node template requirements are required to be provided as list. + """ + + expectedmessage = _('"requirements" of template "my_webserver"' + ' must be of type "list".') + + # requirements provided as dictionary + tpl_snippet1 = ''' + node_templates: + my_webserver: + type: tosca.nodes.WebServer + requirements: + host: server + server: + type: tosca.nodes.Compute + ''' + err1 = self.assertRaises( + exception.TypeMismatchError, + lambda: self._single_node_template_content_test(tpl_snippet1)) + self.assertEqual(expectedmessage, err1.__str__()) + + # requirements provided as string + tpl_snippet2 = ''' + node_templates: + my_webserver: + type: tosca.nodes.WebServer + requirements: server + server: + type: tosca.nodes.Compute + ''' + err2 = self.assertRaises( + exception.TypeMismatchError, + lambda: self._single_node_template_content_test(tpl_snippet2)) + self.assertEqual(expectedmessage, err2.__str__()) + + # requirements provided as list + tpl_snippet3 = ''' + node_templates: + my_webserver: + type: tosca.nodes.WebServer + requirements: + - host: server + server: + type: tosca.nodes.Compute + ''' + self.assertIsNone( + self._single_node_template_content_test(tpl_snippet3)) + + def test_properties_override_with_flavor_and_image(self): + tpl_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_normative_type_properties_override.yaml") + self.assertIsNotNone(ToscaTemplate(tpl_path)) diff --git a/nfvparser/toscaparser/tests/test_utils.py b/nfvparser/toscaparser/tests/test_utils.py new file mode 100644 index 0000000..fca024d --- /dev/null +++ b/nfvparser/toscaparser/tests/test_utils.py @@ -0,0 +1,48 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from toscaparser.tests.base import TestCase +import toscaparser.utils.urlutils +import toscaparser.utils.yamlparser + +YAML_LOADER = toscaparser.utils.yamlparser.load_yaml + + +class UrlUtilsTest(TestCase): + + url_utils = toscaparser.utils.urlutils.UrlUtils + + def test_urlutils_validate_url(self): + self.assertTrue(self.url_utils.validate_url("http://www.github.com/")) + self.assertTrue( + self.url_utils.validate_url("https://github.com:81/a/2/a.b")) + self.assertTrue(self.url_utils.validate_url("ftp://github.com")) + self.assertFalse(self.url_utils.validate_url("github.com")) + self.assertFalse(self.url_utils.validate_url("123")) + self.assertFalse(self.url_utils.validate_url("a/b/c")) + self.assertTrue(self.url_utils.validate_url("file:///dir/file.ext")) + + def test_urlutils_join_url(self): + self.assertEqual( + self.url_utils.join_url("http://github.com/proj1", "proj2"), + "http://github.com/proj2") + self.assertEqual( + self.url_utils.join_url("http://github.com/proj1/scripts/a.js", + "b.js"), + "http://github.com/proj1/scripts/b.js") + self.assertEqual( + self.url_utils.join_url("http://github.com/proj1/scripts", "b.js"), + "http://github.com/proj1/b.js") + self.assertEqual( + self.url_utils.join_url("http://github.com/proj1/scripts", + "scripts/b.js"), + "http://github.com/proj1/scripts/b.js") diff --git a/nfvparser/toscaparser/tests/test_validate_tosca_version.py b/nfvparser/toscaparser/tests/test_validate_tosca_version.py new file mode 100644 index 0000000..e9a8ac2 --- /dev/null +++ b/nfvparser/toscaparser/tests/test_validate_tosca_version.py @@ -0,0 +1,132 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +from toscaparser.common.exception import ( + InvalidTOSCAVersionPropertyException) +from toscaparser.tests.base import TestCase +from toscaparser.utils.gettextutils import _ +from toscaparser.utils.validateutils import TOSCAVersionProperty + + +class TOSCAVersionPropertyTest(TestCase): + + def test_tosca_version_property(self): + version = '18.0.3.beta-1' + expected_output = '18.0.3.beta-1' + output = TOSCAVersionProperty(version).get_version() + self.assertEqual(output, expected_output) + + version = 18 + expected_output = '18.0' + output = TOSCAVersionProperty(version).get_version() + self.assertEqual(output, expected_output) + + version = 18.0 + expected_output = '18.0' + output = TOSCAVersionProperty(version).get_version() + self.assertEqual(output, expected_output) + + version = '18.0.3' + expected_output = '18.0.3' + output = TOSCAVersionProperty(version).get_version() + self.assertEqual(output, expected_output) + + version = 0 + expected_output = None + output = TOSCAVersionProperty(version).get_version() + self.assertEqual(output, expected_output) + + version = 00 + expected_output = None + output = TOSCAVersionProperty(version).get_version() + self.assertEqual(output, expected_output) + + version = 0.0 + expected_output = None + output = TOSCAVersionProperty(version).get_version() + self.assertEqual(output, expected_output) + + version = 00.00 + expected_output = None + output = TOSCAVersionProperty(version).get_version() + self.assertEqual(output, expected_output) + + version = '0.0.0' + expected_output = None + output = TOSCAVersionProperty(version).get_version() + self.assertEqual(output, expected_output) + + def test_tosca_version_property_invalid_major_version(self): + + version = 'x' + exp_msg = _('Value of TOSCA version property "x" is invalid.') + err = self.assertRaises(InvalidTOSCAVersionPropertyException, + TOSCAVersionProperty, version) + self.assertEqual(exp_msg, err.__str__()) + + def test_tosca_version_property_invalid_minor_version(self): + + version = '18.x' + exp_msg = _('Value of TOSCA version property "18.x" is invalid.') + err = self.assertRaises(InvalidTOSCAVersionPropertyException, + TOSCAVersionProperty, version) + self.assertEqual(exp_msg, err.__str__()) + + version = '18.x.y' + exp_msg = _('Value of TOSCA version property "18.x.y" is invalid.') + err = self.assertRaises(InvalidTOSCAVersionPropertyException, + TOSCAVersionProperty, version) + self.assertEqual(exp_msg, err.__str__()) + + version = '18-2' + exp_msg = _('Value of TOSCA version property "18-2" is invalid.') + err = self.assertRaises(InvalidTOSCAVersionPropertyException, + TOSCAVersionProperty, version) + self.assertEqual(exp_msg, err.__str__()) + + def test_tosca_version_property_invalid_fix_version(self): + + version = '18.0.a' + exp_msg = _('Value of TOSCA version property "18.0.a" is invalid.') + err = self.assertRaises(InvalidTOSCAVersionPropertyException, + TOSCAVersionProperty, version) + self.assertEqual(exp_msg, err.__str__()) + + def test_tosca_version_property_invalid_qualifier(self): + + version = '18.0.1-xyz' + exp_msg = _('Value of TOSCA version property "18.0.1-xyz" is invalid.') + err = self.assertRaises(InvalidTOSCAVersionPropertyException, + TOSCAVersionProperty, version) + self.assertEqual(exp_msg, err.__str__()) + + version = '0.0.0.abc' + exp_msg = _('Value of TOSCA version property "0.0.0.abc" is invalid.') + err = self.assertRaises(InvalidTOSCAVersionPropertyException, + TOSCAVersionProperty, version) + self.assertEqual(exp_msg, err.__str__()) + + def test_tosca_version_property_invalid_build_version(self): + + version = '18.0.1.abc-x' + exp_msg = _('Value of TOSCA version property ' + '"18.0.1.abc-x" is invalid.') + err = self.assertRaises(InvalidTOSCAVersionPropertyException, + TOSCAVersionProperty, version) + self.assertEqual(exp_msg, err.__str__()) + + version = '0.0.0.abc-x' + exp_msg = _('Value of TOSCA version property "0.0.0.abc-x" is ' + 'invalid.') + err = self.assertRaises(InvalidTOSCAVersionPropertyException, + TOSCAVersionProperty, version) + self.assertEqual(exp_msg, err.__str__()) diff --git a/nfvparser/toscaparser/topology_template.py b/nfvparser/toscaparser/topology_template.py new file mode 100644 index 0000000..4571fe7 --- /dev/null +++ b/nfvparser/toscaparser/topology_template.py @@ -0,0 +1,310 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + + +import logging + +from toscaparser.common import exception +from toscaparser.dataentity import DataEntity +from toscaparser import functions +from toscaparser.groups import Group +from toscaparser.nodetemplate import NodeTemplate +from toscaparser.parameters import Input +from toscaparser.parameters import Output +from toscaparser.policy import Policy +from toscaparser.relationship_template import RelationshipTemplate +from toscaparser.substitution_mappings import SubstitutionMappings +from toscaparser.tpl_relationship_graph import ToscaGraph +from toscaparser.utils.gettextutils import _ + + +# Topology template key names +SECTIONS = (DESCRIPTION, INPUTS, NODE_TEMPLATES, + RELATIONSHIP_TEMPLATES, OUTPUTS, GROUPS, + SUBSTITUION_MAPPINGS, POLICIES) = \ + ('description', 'inputs', 'node_templates', + 'relationship_templates', 'outputs', 'groups', + 'substitution_mappings', 'policies') + +log = logging.getLogger("tosca.model") + + +class TopologyTemplate(object): + + '''Load the template data.''' + def __init__(self, template, custom_defs, + rel_types=None, parsed_params=None, + sub_mapped_node_template=None): + self.tpl = template + self.sub_mapped_node_template = sub_mapped_node_template + if self.tpl: + self.custom_defs = custom_defs + self.rel_types = rel_types + self.parsed_params = parsed_params + self._validate_field() + self.description = self._tpl_description() + self.inputs = self._inputs() + self.relationship_templates = self._relationship_templates() + self.nodetemplates = self._nodetemplates() + self.outputs = self._outputs() + if hasattr(self, 'nodetemplates'): + self.graph = ToscaGraph(self.nodetemplates) + self.groups = self._groups() + self.policies = self._policies() + self._process_intrinsic_functions() + self.substitution_mappings = self._substitution_mappings() + + def _inputs(self): + inputs = [] + for name, attrs in self._tpl_inputs().items(): + input = Input(name, attrs) + if self.parsed_params and name in self.parsed_params: + input.validate(self.parsed_params[name]) + else: + default = input.default + if default: + input.validate(default) + if (self.parsed_params and input.name not in self.parsed_params + or self.parsed_params is None) and input.required \ + and input.default is None: + exception.ExceptionCollector.appendException( + exception.MissingRequiredParameterError( + what='Template', + input_name=input.name)) + + inputs.append(input) + return inputs + + def _nodetemplates(self): + nodetemplates = [] + tpls = self._tpl_nodetemplates() + if tpls: + for name in tpls: + tpl = NodeTemplate(name, tpls, self.custom_defs, + self.relationship_templates, + self.rel_types) + if (tpl.type_definition and + (tpl.type in tpl.type_definition.TOSCA_DEF or + (tpl.type not in tpl.type_definition.TOSCA_DEF and + bool(tpl.custom_def)))): + tpl.validate(self) + nodetemplates.append(tpl) + return nodetemplates + + def _relationship_templates(self): + rel_templates = [] + tpls = self._tpl_relationship_templates() + for name in tpls: + tpl = RelationshipTemplate(tpls[name], name, self.custom_defs) + rel_templates.append(tpl) + return rel_templates + + def _outputs(self): + outputs = [] + for name, attrs in self._tpl_outputs().items(): + output = Output(name, attrs) + output.validate() + outputs.append(output) + return outputs + + def _substitution_mappings(self): + tpl_substitution_mapping = self._tpl_substitution_mappings() + # if tpl_substitution_mapping and self.sub_mapped_node_template: + if tpl_substitution_mapping: + return SubstitutionMappings(tpl_substitution_mapping, + self.nodetemplates, + self.inputs, + self.outputs, + self.sub_mapped_node_template, + self.custom_defs) + + def _policies(self): + policies = [] + for policy in self._tpl_policies(): + for policy_name, policy_tpl in policy.items(): + target_list = policy_tpl.get('targets') + target_objects = [] + targets_type = "groups" + if target_list and len(target_list) >= 1: + target_objects = self._get_policy_groups(target_list) + if not target_objects: + targets_type = "node_templates" + target_objects = self._get_group_members(target_list) + policyObj = Policy(policy_name, policy_tpl, + target_objects, targets_type, + self.custom_defs) + policies.append(policyObj) + return policies + + def _groups(self): + groups = [] + member_nodes = None + for group_name, group_tpl in self._tpl_groups().items(): + member_names = group_tpl.get('members') + if member_names is not None: + DataEntity.validate_datatype('list', member_names) + if len(member_names) < 1 or \ + len(member_names) != len(set(member_names)): + exception.ExceptionCollector.appendException( + exception.InvalidGroupTargetException( + message=_('Member nodes "%s" should be >= 1 ' + 'and not repeated') % member_names)) + else: + member_nodes = self._get_group_members(member_names) + group = Group(group_name, group_tpl, + member_nodes, + self.custom_defs) + groups.append(group) + return groups + + def _get_group_members(self, member_names): + member_nodes = [] + self._validate_group_members(member_names) + for member in member_names: + for node in self.nodetemplates: + if node.name == member: + member_nodes.append(node) + return member_nodes + + def _get_policy_groups(self, member_names): + member_groups = [] + for member in member_names: + for group in self.groups: + if group.name == member: + member_groups.append(group) + return member_groups + + def _validate_group_members(self, members): + node_names = [] + for node in self.nodetemplates: + node_names.append(node.name) + for member in members: + if member not in node_names: + exception.ExceptionCollector.appendException( + exception.InvalidGroupTargetException( + message=_('Target member "%s" is not found in ' + 'node_templates') % member)) + + # topology template can act like node template + # it is exposed by substitution_mappings. + def nodetype(self): + return self.substitution_mappings.node_type \ + if self.substitution_mappings else None + + def capabilities(self): + return self.substitution_mappings.capabilities \ + if self.substitution_mappings else None + + def requirements(self): + return self.substitution_mappings.requirements \ + if self.substitution_mappings else None + + def _tpl_description(self): + description = self.tpl.get(DESCRIPTION) + if description: + return description.rstrip() + + def _tpl_inputs(self): + return self.tpl.get(INPUTS) or {} + + def _tpl_nodetemplates(self): + return self.tpl.get(NODE_TEMPLATES) + + def _tpl_relationship_templates(self): + return self.tpl.get(RELATIONSHIP_TEMPLATES) or {} + + def _tpl_outputs(self): + return self.tpl.get(OUTPUTS) or {} + + def _tpl_substitution_mappings(self): + return self.tpl.get(SUBSTITUION_MAPPINGS) or {} + + def _tpl_groups(self): + return self.tpl.get(GROUPS) or {} + + def _tpl_policies(self): + return self.tpl.get(POLICIES) or {} + + def _validate_field(self): + for name in self.tpl: + if name not in SECTIONS: + exception.ExceptionCollector.appendException( + exception.UnknownFieldError(what='Template', field=name)) + + def _process_intrinsic_functions(self): + """Process intrinsic functions + + Current implementation processes functions within node template + properties, requirements, interfaces inputs and template outputs. + """ + if hasattr(self, 'nodetemplates'): + for node_template in self.nodetemplates: + for prop in node_template.get_properties_objects(): + prop.value = functions.get_function(self, + node_template, + prop.value) + for interface in node_template.interfaces: + if interface.inputs: + for name, value in interface.inputs.items(): + interface.inputs[name] = functions.get_function( + self, + node_template, + value) + if node_template.requirements and \ + isinstance(node_template.requirements, list): + for req in node_template.requirements: + rel = req + for req_name, req_item in req.items(): + if isinstance(req_item, dict): + rel = req_item.get('relationship') + break + if rel and 'properties' in rel: + for key, value in rel['properties'].items(): + rel['properties'][key] = \ + functions.get_function(self, + req, + value) + if node_template.get_capabilities_objects(): + for cap in node_template.get_capabilities_objects(): + if cap.get_properties_objects(): + for prop in cap.get_properties_objects(): + propvalue = functions.get_function( + self, + node_template, + prop.value) + if isinstance(propvalue, functions.GetInput): + propvalue = propvalue.result() + for p, v in cap._properties.items(): + if p == prop.name: + cap._properties[p] = propvalue + for rel, node in node_template.relationships.items(): + rel_tpls = node.relationship_tpl + if rel_tpls: + for rel_tpl in rel_tpls: + for interface in rel_tpl.interfaces: + if interface.inputs: + for name, value in \ + interface.inputs.items(): + interface.inputs[name] = \ + functions.get_function(self, + rel_tpl, + value) + for output in self.outputs: + func = functions.get_function(self, self.outputs, output.value) + if isinstance(func, functions.GetAttribute): + output.attrs[output.VALUE] = func + + @classmethod + def get_sub_mapping_node_type(cls, topology_tpl): + if topology_tpl and isinstance(topology_tpl, dict): + submap_tpl = topology_tpl.get(SUBSTITUION_MAPPINGS) + return SubstitutionMappings.get_node_type(submap_tpl) diff --git a/nfvparser/toscaparser/tosca_template.py b/nfvparser/toscaparser/tosca_template.py new file mode 100644 index 0000000..f48078f --- /dev/null +++ b/nfvparser/toscaparser/tosca_template.py @@ -0,0 +1,344 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + + +import logging +import os + +from copy import deepcopy +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import InvalidTemplateVersion +from toscaparser.common.exception import MissingRequiredFieldError +from toscaparser.common.exception import UnknownFieldError +from toscaparser.common.exception import ValidationError +from toscaparser.elements.entity_type import update_definitions +from toscaparser.extensions.exttools import ExtTools +import toscaparser.imports +from toscaparser.prereq.csar import CSAR +from toscaparser.repositories import Repository +from toscaparser.topology_template import TopologyTemplate +from toscaparser.tpl_relationship_graph import ToscaGraph +from toscaparser.utils.gettextutils import _ +import toscaparser.utils.yamlparser + + +# TOSCA template key names +SECTIONS = (DEFINITION_VERSION, DEFAULT_NAMESPACE, TEMPLATE_NAME, + TOPOLOGY_TEMPLATE, TEMPLATE_AUTHOR, TEMPLATE_VERSION, + DESCRIPTION, IMPORTS, DSL_DEFINITIONS, NODE_TYPES, + RELATIONSHIP_TYPES, RELATIONSHIP_TEMPLATES, + CAPABILITY_TYPES, ARTIFACT_TYPES, DATA_TYPES, INTERFACE_TYPES, + POLICY_TYPES, GROUP_TYPES, REPOSITORIES) = \ + ('tosca_definitions_version', 'tosca_default_namespace', + 'template_name', 'topology_template', 'template_author', + 'template_version', 'description', 'imports', 'dsl_definitions', + 'node_types', 'relationship_types', 'relationship_templates', + 'capability_types', 'artifact_types', 'data_types', + 'interface_types', 'policy_types', 'group_types', 'repositories') +# Sections that are specific to individual template definitions +SPECIAL_SECTIONS = (METADATA) = ('metadata') + +log = logging.getLogger("tosca.model") + +YAML_LOADER = toscaparser.utils.yamlparser.load_yaml + + +class ToscaTemplate(object): + exttools = ExtTools() + + VALID_TEMPLATE_VERSIONS = ['tosca_simple_yaml_1_0'] + + VALID_TEMPLATE_VERSIONS.extend(exttools.get_versions()) + + ADDITIONAL_SECTIONS = {'tosca_simple_yaml_1_0': SPECIAL_SECTIONS} + + ADDITIONAL_SECTIONS.update(exttools.get_sections()) + + '''Load the template data.''' + def __init__(self, path=None, parsed_params=None, a_file=True, + yaml_dict_tpl=None, sub_mapped_node_template=None): + if sub_mapped_node_template is None: + ExceptionCollector.start() + self.a_file = a_file + self.input_path = None + self.path = None + self.tpl = None + self.sub_mapped_node_template = sub_mapped_node_template + self.nested_tosca_tpls_with_topology = {} + self.nested_tosca_templates_with_topology = [] + if path: + self.input_path = path + self.path = self._get_path(path) + if self.path: + self.tpl = YAML_LOADER(self.path, self.a_file) + if yaml_dict_tpl: + msg = (_('Both path and yaml_dict_tpl arguments were ' + 'provided. Using path and ignoring yaml_dict_tpl.')) + log.info(msg) + print(msg) + else: + if yaml_dict_tpl: + self.tpl = yaml_dict_tpl + else: + ExceptionCollector.appendException( + ValueError(_('No path or yaml_dict_tpl was provided. ' + 'There is nothing to parse.'))) + + if self.tpl: + self.parsed_params = parsed_params + self._validate_field() + self.version = self._tpl_version() + self.relationship_types = self._tpl_relationship_types() + self.description = self._tpl_description() + self.topology_template = self._topology_template() + self.repositories = self._tpl_repositories() + if self.topology_template.tpl: + self.inputs = self._inputs() + self.relationship_templates = self._relationship_templates() + self.nodetemplates = self._nodetemplates() + self.outputs = self._outputs() + self.policies = self._policies() + self._handle_nested_tosca_templates_with_topology() + self.graph = ToscaGraph(self.nodetemplates) + + if sub_mapped_node_template is None: + ExceptionCollector.stop() + self.verify_template() + + def _topology_template(self): + return TopologyTemplate(self._tpl_topology_template(), + self._get_all_custom_defs(), + self.relationship_types, + self.parsed_params, + self.sub_mapped_node_template) + + def _inputs(self): + return self.topology_template.inputs + + def _nodetemplates(self): + return self.topology_template.nodetemplates + + def _relationship_templates(self): + return self.topology_template.relationship_templates + + def _outputs(self): + return self.topology_template.outputs + + def _tpl_version(self): + return self.tpl.get(DEFINITION_VERSION) + + def _tpl_description(self): + desc = self.tpl.get(DESCRIPTION) + if desc: + return desc.rstrip() + + def _tpl_imports(self): + return self.tpl.get(IMPORTS) + + def _tpl_repositories(self): + repositories = self.tpl.get(REPOSITORIES) + reposit = [] + if repositories: + for name, val in repositories.items(): + reposits = Repository(name, val) + reposit.append(reposits) + return reposit + + def _tpl_relationship_types(self): + return self._get_custom_types(RELATIONSHIP_TYPES) + + def _tpl_relationship_templates(self): + topology_template = self._tpl_topology_template() + return topology_template.get(RELATIONSHIP_TEMPLATES) + + def _tpl_topology_template(self): + return self.tpl.get(TOPOLOGY_TEMPLATE) + + def _policies(self): + return self.topology_template.policies + + def _get_all_custom_defs(self, imports=None): + types = [IMPORTS, NODE_TYPES, CAPABILITY_TYPES, RELATIONSHIP_TYPES, + DATA_TYPES, INTERFACE_TYPES, POLICY_TYPES, GROUP_TYPES] + custom_defs_final = {} + custom_defs = self._get_custom_types(types, imports) + if custom_defs: + custom_defs_final.update(custom_defs) + if custom_defs.get(IMPORTS): + import_defs = self._get_all_custom_defs( + custom_defs.get(IMPORTS)) + custom_defs_final.update(import_defs) + + # As imports are not custom_types, removing from the dict + custom_defs_final.pop(IMPORTS, None) + return custom_defs_final + + def _get_custom_types(self, type_definitions, imports=None): + """Handle custom types defined in imported template files + + This method loads the custom type definitions referenced in "imports" + section of the TOSCA YAML template. + """ + + custom_defs = {} + type_defs = [] + if not isinstance(type_definitions, list): + type_defs.append(type_definitions) + else: + type_defs = type_definitions + + if not imports: + imports = self._tpl_imports() + + if imports: + custom_service = toscaparser.imports.\ + ImportsLoader(imports, self.path, + type_defs, self.tpl) + + nested_tosca_tpls = custom_service.get_nested_tosca_tpls() + self._update_nested_tosca_tpls_with_topology(nested_tosca_tpls) + + custom_defs = custom_service.get_custom_defs() + if not custom_defs: + return + + # Handle custom types defined in current template file + for type_def in type_defs: + if type_def != IMPORTS: + inner_custom_types = self.tpl.get(type_def) or {} + if inner_custom_types: + custom_defs.update(inner_custom_types) + return custom_defs + + def _update_nested_tosca_tpls_with_topology(self, nested_tosca_tpls): + for tpl in nested_tosca_tpls: + filename, tosca_tpl = list(tpl.items())[0] + if (tosca_tpl.get(TOPOLOGY_TEMPLATE) and + filename not in list( + self.nested_tosca_tpls_with_topology.keys())): + self.nested_tosca_tpls_with_topology.update(tpl) + + def _handle_nested_tosca_templates_with_topology(self): + for fname, tosca_tpl in self.nested_tosca_tpls_with_topology.items(): + for nodetemplate in self.nodetemplates: + if self._is_sub_mapped_node(nodetemplate, tosca_tpl): + parsed_params = self._get_params_for_nested_template( + nodetemplate) + nested_template = ToscaTemplate( + path=fname, parsed_params=parsed_params, + yaml_dict_tpl=tosca_tpl, + sub_mapped_node_template=nodetemplate) + if nested_template._has_substitution_mappings(): + # Record the nested templates in top level template + self.nested_tosca_templates_with_topology.\ + append(nested_template) + # Set the substitution toscatemplate for mapped node + nodetemplate.sub_mapping_tosca_template = \ + nested_template + + def _validate_field(self): + version = self._tpl_version() + if not version: + ExceptionCollector.appendException( + MissingRequiredFieldError(what='Template', + required=DEFINITION_VERSION)) + else: + self._validate_version(version) + self.version = version + + for name in self.tpl: + if (name not in SECTIONS and + name not in self.ADDITIONAL_SECTIONS.get(version, ())): + ExceptionCollector.appendException( + UnknownFieldError(what='Template', field=name)) + + def _validate_version(self, version): + if version not in self.VALID_TEMPLATE_VERSIONS: + ExceptionCollector.appendException( + InvalidTemplateVersion( + what=version, + valid_versions=', '. join(self.VALID_TEMPLATE_VERSIONS))) + else: + if version != 'tosca_simple_yaml_1_0': + update_definitions(version) + + def _get_path(self, path): + if path.lower().endswith('.yaml'): + return path + elif path.lower().endswith(('.zip', '.csar')): + # a CSAR archive + csar = CSAR(path, self.a_file) + if csar.validate(): + csar.decompress() + self.a_file = True # the file has been decompressed locally + return os.path.join(csar.temp_dir, csar.get_main_template()) + else: + ExceptionCollector.appendException( + ValueError(_('"%(path)s" is not a valid file.') + % {'path': path})) + + def verify_template(self): + if ExceptionCollector.exceptionsCaught(): + if self.input_path: + raise ValidationError( + message=(_('\nThe input "%(path)s" failed validation with ' + 'the following error(s): \n\n\t') + % {'path': self.input_path}) + + '\n\t'.join(ExceptionCollector.getExceptionsReport())) + else: + raise ValidationError( + message=_('\nThe pre-parsed input failed validation with ' + 'the following error(s): \n\n\t') + + '\n\t'.join(ExceptionCollector.getExceptionsReport())) + else: + if self.input_path: + msg = (_('The input "%(path)s" successfully passed ' + 'validation.') % {'path': self.input_path}) + else: + msg = _('The pre-parsed input successfully passed validation.') + + log.info(msg) + + def _is_sub_mapped_node(self, nodetemplate, tosca_tpl): + """Return True if the nodetemple is substituted.""" + if (nodetemplate and not nodetemplate.substitution_mapped and + self.get_sub_mapping_node_type(tosca_tpl) == nodetemplate.type + and len(nodetemplate.interfaces) < 1): + return True + else: + return False + + def _get_params_for_nested_template(self, nodetemplate): + """Return total params for nested_template.""" + parsed_params = deepcopy(self.parsed_params) \ + if self.parsed_params else {} + if nodetemplate: + for pname in nodetemplate.get_properties(): + parsed_params.update({pname: + nodetemplate.get_property_value(pname)}) + return parsed_params + + def get_sub_mapping_node_type(self, tosca_tpl): + """Return substitution mappings node type.""" + if tosca_tpl: + return TopologyTemplate.get_sub_mapping_node_type( + tosca_tpl.get(TOPOLOGY_TEMPLATE)) + + def _has_substitution_mappings(self): + """Return True if the template has valid substitution mappings.""" + return self.topology_template is not None and \ + self.topology_template.substitution_mappings is not None + + def has_nested_templates(self): + """Return True if the tosca template has nested templates.""" + return self.nested_tosca_templates_with_topology is not None and \ + len(self.nested_tosca_templates_with_topology) >= 1 diff --git a/nfvparser/toscaparser/tpl_relationship_graph.py b/nfvparser/toscaparser/tpl_relationship_graph.py new file mode 100644 index 0000000..1a5ea7b --- /dev/null +++ b/nfvparser/toscaparser/tpl_relationship_graph.py @@ -0,0 +1,46 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + + +class ToscaGraph(object): + '''Graph of Tosca Node Templates.''' + def __init__(self, nodetemplates): + self.nodetemplates = nodetemplates + self.vertices = {} + self._create() + + def _create_vertex(self, node): + if node not in self.vertices: + self.vertices[node.name] = node + + def _create_edge(self, node1, node2, relationship): + if node1 not in self.vertices: + self._create_vertex(node1) + self.vertices[node1.name]._add_next(node2, + relationship) + + def vertex(self, node): + if node in self.vertices: + return self.vertices[node] + + def __iter__(self): + return iter(self.vertices.values()) + + def _create(self): + for node in self.nodetemplates: + relation = node.relationships + if relation: + for rel, nodetpls in relation.items(): + for tpl in self.nodetemplates: + if tpl.name == nodetpls.name: + self._create_edge(node, tpl, rel) + self._create_vertex(node) diff --git a/nfvparser/toscaparser/triggers.py b/nfvparser/toscaparser/triggers.py new file mode 100644 index 0000000..9edeef4 --- /dev/null +++ b/nfvparser/toscaparser/triggers.py @@ -0,0 +1,68 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + + +import logging + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import UnknownFieldError +from toscaparser.entity_template import EntityTemplate + +SECTIONS = (DESCRIPTION, EVENT, SCHEDULE, TARGET_FILTER, CONDITION, ACTION) = \ + ('description', 'event_type', 'schedule', + 'target_filter', 'condition', 'action') +CONDITION_KEYNAMES = (CONTRAINT, PERIOD, EVALUATIONS, METHOD) = \ + ('constraint', 'period', 'evaluations', 'method') +log = logging.getLogger('tosca') + + +class Triggers(EntityTemplate): + + '''Triggers defined in policies of topology template''' + + def __init__(self, name, trigger_tpl): + self.name = name + self.trigger_tpl = trigger_tpl + self._validate_keys() + self._validate_condition() + + def get_description(self): + return self.trigger_tpl['description'] + + def get_event(self): + return self.trigger_tpl['event_type'] + + def get_schedule(self): + return self.trigger_tpl['schedule'] + + def get_target_filter(self): + return self.trigger_tpl['target_filter'] + + def get_condition(self): + return self.trigger_tpl['condition'] + + def get_action(self): + return self.trigger_tpl['action'] + + def _validate_keys(self): + for key in self.trigger_tpl.keys(): + if key not in SECTIONS: + ExceptionCollector.appendException( + UnknownFieldError(what='Triggers "%s"' % self.name, + field=key)) + + def _validate_condition(self): + for key in self.get_condition(): + if key not in CONDITION_KEYNAMES: + ExceptionCollector.appendException( + UnknownFieldError(what='Triggers "%s"' % self.name, + field=key)) diff --git a/nfvparser/toscaparser/unsupportedtype.py b/nfvparser/toscaparser/unsupportedtype.py new file mode 100644 index 0000000..a0c11f0 --- /dev/null +++ b/nfvparser/toscaparser/unsupportedtype.py @@ -0,0 +1,50 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. +import logging + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import UnsupportedTypeError +from toscaparser.utils.gettextutils import _ + +log = logging.getLogger('tosca') + + +class UnsupportedType(object): + + """Note: TOSCA spec version related + + The tosca.nodes.Storage.ObjectStorage and tosca.nodes.Storage.BlockStorage + used here as un_supported_types are part of the name changes in TOSCA spec + version 1.1. The original name as specified in version 1.0 are, + tosca.nodes.BlockStorage and tosca.nodes.ObjectStorage which are supported + by the tosca-parser. Since there are little overlapping in version support + currently in the tosca-parser, the names tosca.nodes.Storage.ObjectStorage + and tosca.nodes.Storage.BlockStorage are used here to demonstrate the usage + of un_supported_types. As tosca-parser move to provide support for version + 1.1 and higher, they will be removed. + """ + un_supported_types = ['tosca.test.invalidtype', + 'tosca.nodes.Storage.ObjectStorage', + 'tosca.nodes.Storage.BlockStorage'] + + def __init__(self): + pass + + @staticmethod + def validate_type(entitytype): + if entitytype in UnsupportedType.un_supported_types: + ExceptionCollector.appendException(UnsupportedTypeError( + what=_('%s') + % entitytype)) + return True + else: + return False diff --git a/nfvparser/toscaparser/utils/__init__.py b/nfvparser/toscaparser/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nfvparser/toscaparser/utils/gettextutils.py b/nfvparser/toscaparser/utils/gettextutils.py new file mode 100644 index 0000000..d631ac8 --- /dev/null +++ b/nfvparser/toscaparser/utils/gettextutils.py @@ -0,0 +1,23 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import gettext +import os + +_localedir = os.environ.get('tosca-parser'.upper() + '_LOCALEDIR') +_t = gettext.translation('tosca-parser', localedir=_localedir, + fallback=True) + + +def _(msg): + # type: (object) -> object + return _t.gettext(msg) diff --git a/nfvparser/toscaparser/utils/urlutils.py b/nfvparser/toscaparser/utils/urlutils.py new file mode 100644 index 0000000..546acca --- /dev/null +++ b/nfvparser/toscaparser/utils/urlutils.py @@ -0,0 +1,65 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + + +from six.moves.urllib.parse import urljoin +from six.moves.urllib.parse import urlparse +from toscaparser.common.exception import ExceptionCollector +from toscaparser.utils.gettextutils import _ + +try: + # Python 3.x + import urllib.request as urllib2 +except ImportError: + # Python 2.x + import urllib2 + + +class UrlUtils(object): + + @staticmethod + def validate_url(path): + """Validates whether the given path is a URL or not. + + If the given path includes a scheme (http, https, ftp, ...) and a net + location (a domain name such as www.github.com) it is validated as a + URL. + """ + parsed = urlparse(path) + if parsed.scheme == 'file': + # If the url uses the file scheme netloc will be "" + return True + else: + return bool(parsed.scheme) and bool(parsed.netloc) + + @staticmethod + def join_url(url, relative_path): + """Builds a new URL from the given URL and the relative path. + + Example: + url: http://www.githib.com/openstack/heat + relative_path: heat-translator + - joined: http://www.githib.com/openstack/heat-translator + """ + if not UrlUtils.validate_url(url): + ExceptionCollector.appendException( + ValueError(_('"%s" is not a valid URL.') % url)) + return urljoin(url, relative_path) + + @staticmethod + def url_accessible(url): + """Validates whether the given URL is accessible. + + Returns true if the get call returns a 200 response code. + Otherwise, returns false. + """ + return urllib2.urlopen(url).getcode() == 200 diff --git a/nfvparser/toscaparser/utils/validateutils.py b/nfvparser/toscaparser/utils/validateutils.py new file mode 100644 index 0000000..b280576 --- /dev/null +++ b/nfvparser/toscaparser/utils/validateutils.py @@ -0,0 +1,236 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import collections +import dateutil.parser +import logging +import numbers +import re +import six + +# from toscaparser.elements import constraints +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import InvalidTOSCAVersionPropertyException +from toscaparser.common.exception import RangeValueError +from toscaparser.utils.gettextutils import _ + +log = logging.getLogger('tosca') + +RANGE_UNBOUNDED = 'UNBOUNDED' + + +def str_to_num(value): + '''Convert a string representation of a number into a numeric type.''' + # TODO(TBD) we should not allow numeric values in, input should be str + if isinstance(value, numbers.Number): + return value + try: + return int(value) + except ValueError: + return float(value) + + +def validate_numeric(value): + if not isinstance(value, numbers.Number): + ExceptionCollector.appendException( + ValueError(_('"%s" is not a numeric.') % value)) + return value + + +def validate_integer(value): + if not isinstance(value, int): + try: + value = int(value) + except Exception: + ExceptionCollector.appendException( + ValueError(_('"%s" is not an integer.') % value)) + return value + + +def validate_float(value): + if not isinstance(value, float): + ExceptionCollector.appendException( + ValueError(_('"%s" is not a float.') % value)) + return value + + +def validate_string(value): + if not isinstance(value, six.string_types): + ExceptionCollector.appendException( + ValueError(_('"%s" is not a string.') % value)) + return value + + +def validate_list(value): + if not isinstance(value, list): + ExceptionCollector.appendException( + ValueError(_('"%s" is not a list.') % value)) + return value + + +def validate_range(range): + # list class check + validate_list(range) + # validate range list has a min and max + if len(range) != 2: + ExceptionCollector.appendException( + ValueError(_('"%s" is not a valid range.') % range)) + # validate min and max are numerics or the keyword UNBOUNDED + min_test = max_test = False + if not range[0] == RANGE_UNBOUNDED: + min = validate_numeric(range[0]) + else: + min_test = True + if not range[1] == RANGE_UNBOUNDED: + max = validate_numeric(range[1]) + else: + max_test = True + # validate the max > min (account for UNBOUNDED) + if not min_test and not max_test: + # Note: min == max is allowed + if min > max: + ExceptionCollector.appendException( + ValueError(_('"%s" is not a valid range.') % range)) + + return range + + +def validate_value_in_range(value, range, prop_name): + validate_numeric(value) + validate_range(range) + + # Note: value is valid if equal to min + if range[0] != RANGE_UNBOUNDED: + if value < range[0]: + ExceptionCollector.appendException( + RangeValueError(pname=prop_name, + pvalue=value, + vmin=range[0], + vmax=range[1])) + # Note: value is valid if equal to max + if range[1] != RANGE_UNBOUNDED: + if value > range[1]: + ExceptionCollector.appendException( + RangeValueError(pname=prop_name, + pvalue=value, + vmin=range[0], + vmax=range[1])) + return value + + +def validate_map(value): + if not isinstance(value, collections.Mapping): + ExceptionCollector.appendException( + ValueError(_('"%s" is not a map.') % value)) + return value + + +def validate_boolean(value): + if isinstance(value, bool): + return value + + if isinstance(value, str): + normalised = value.lower() + if normalised in ['true', 'false']: + return normalised == 'true' + + ExceptionCollector.appendException( + ValueError(_('"%s" is not a boolean.') % value)) + + +def validate_timestamp(value): + try: + # Note: we must return our own exception message + # as dateutil's parser returns different types / values on + # different systems. OSX, for example, returns a tuple + # containing a different error message than Linux + dateutil.parser.parse(value) + except Exception as e: + original_err_msg = str(e) + log.error(original_err_msg) + ExceptionCollector.appendException( + ValueError(_('"%(val)s" is not a valid timestamp. "%(msg)s"') % + {'val': value, 'msg': original_err_msg})) + return + + +class TOSCAVersionProperty(object): + + VERSION_RE = re.compile('^(?P([0-9][0-9]*))' + '(\.(?P([0-9][0-9]*)))?' + '(\.(?P([0-9][0-9]*)))?' + '(\.(?P([0-9A-Za-z]+)))?' + '(\-(?P[0-9])*)?$') + + def __init__(self, version): + self.version = str(version) + match = self.VERSION_RE.match(self.version) + if not match: + ExceptionCollector.appendException( + InvalidTOSCAVersionPropertyException(what=(self.version))) + return + ver = match.groupdict() + if self.version in ['0', '0.0', '0.0.0']: + log.warning(_('Version assumed as not provided')) + self.version = None + self.minor_version = ver['minor_version'] + self.major_version = ver['major_version'] + self.fix_version = ver['fix_version'] + self.qualifier = self._validate_qualifier(ver['qualifier']) + self.build_version = self._validate_build(ver['build_version']) + self._validate_major_version(self.major_version) + + def _validate_major_version(self, value): + """Validate major version + + Checks if only major version is provided and assumes + minor version as 0. + Eg: If version = 18, then it returns version = '18.0' + """ + + if self.minor_version is None and self.build_version is None and \ + value != '0': + log.warning(_('Minor version assumed "0".')) + self.version = '.'.join([value, '0']) + return value + + def _validate_qualifier(self, value): + """Validate qualifier + + TOSCA version is invalid if a qualifier is present without the + fix version or with all of major, minor and fix version 0s. + + For example, the following versions are invalid + 18.0.abc + 0.0.0.abc + """ + if (self.fix_version is None and value) or \ + (self.minor_version == self.major_version == + self.fix_version == '0' and value): + ExceptionCollector.appendException( + InvalidTOSCAVersionPropertyException(what=(self.version))) + return value + + def _validate_build(self, value): + """Validate build version + + TOSCA version is invalid if build version is present without the + qualifier. + Eg: version = 18.0.0-1 is invalid. + """ + if not self.qualifier and value: + ExceptionCollector.appendException( + InvalidTOSCAVersionPropertyException(what=(self.version))) + return value + + def get_version(self): + return self.version diff --git a/nfvparser/toscaparser/utils/yamlparser.py b/nfvparser/toscaparser/utils/yamlparser.py new file mode 100644 index 0000000..713650d --- /dev/null +++ b/nfvparser/toscaparser/utils/yamlparser.py @@ -0,0 +1,86 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file 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. + +import codecs +from collections import OrderedDict + +from six.moves import urllib +import yaml + +from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import URLException +from toscaparser.utils.gettextutils import _ + + +if hasattr(yaml, 'CSafeLoader'): + yaml_loader = yaml.CSafeLoader +else: + yaml_loader = yaml.SafeLoader + + +def load_yaml(path, a_file=True): + f = None + try: + f = codecs.open(path, encoding='utf-8', errors='strict') if a_file \ + else urllib.request.urlopen(path) + except urllib.error.URLError as e: + if hasattr(e, 'reason'): + msg = (_('Failed to reach server "%(path)s". Reason is: ' + '%(reason)s.') + % {'path': path, 'reason': e.reason}) + ExceptionCollector.appendException(URLException(what=msg)) + return + elif hasattr(e, 'code'): + msg = (_('The server "%(path)s" couldn\'t fulfill the request. ' + 'Error code: "%(code)s".') + % {'path': path, 'code': e.code}) + ExceptionCollector.appendException(URLException(what=msg)) + return + except Exception as e: + raise + return yaml.load(f.read(), Loader=yaml_loader) + + +def simple_parse(tmpl_str): + try: + tpl = yaml.load(tmpl_str, Loader=yaml_loader) + except yaml.YAMLError as yea: + ExceptionCollector.appendException(ValueError(yea)) + else: + if tpl is None: + tpl = {} + return tpl + + +def ordered_load(stream, Loader=yaml.Loader, object_pairs_hook=OrderedDict): + class OrderedLoader(Loader): + pass + + def construct_mapping(loader, node): + loader.flatten_mapping(node) + return object_pairs_hook(loader.construct_pairs(node)) + + OrderedLoader.add_constructor( + yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, + construct_mapping) + return yaml.load(stream, OrderedLoader) + + +def simple_ordered_parse(tmpl_str): + try: + tpl = ordered_load(tmpl_str) + except yaml.YAMLError as yea: + ExceptionCollector.appendException(ValueError(yea)) + else: + if tpl is None: + tpl = {} + return tpl diff --git a/nfvparser/tox.ini b/nfvparser/tox.ini new file mode 100644 index 0000000..8fc2a88 --- /dev/null +++ b/nfvparser/tox.ini @@ -0,0 +1,37 @@ +[tox] +minversion = 1.6 +envlist = py27,pep8 +skipsdist = True + +[testenv] +usedevelop = True +install_command = pip install -U {opts} {packages} +setenv = + VIRTUAL_ENV={envdir} +deps = -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt +commands = python setup.py testr --slowest --testr-args='{posargs}' + +[testenv:pep8] +commands = flake8 + +[testenv:venv] +commands = {posargs} + +[testenv:cover] +commands = python setup.py testr --coverage --coverage-package-name=toscaparser --testr-args='{posargs}' + +[testenv:docs] +commands = python setup.py build_sphinx + +[testenv:debug] +commands = oslo_debug_helper -t toscaparser/tests {posargs} + +[flake8] +# H803 skipped on purpose per list discussion. +# E123, E125 skipped as they are invalid PEP-8. + +show-source = True +ignore = E123,E125,H803 +builtins = _ +exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build -- cgit 1.2.3-korg