diff --git a/translator/tests/data/csar_elk.zip b/translator/tests/data/csar_elk.zip new file mode 100644 index 00000000..5fae801a Binary files /dev/null and b/translator/tests/data/csar_elk.zip differ diff --git a/translator/tests/data/csar_hello_world.zip b/translator/tests/data/csar_hello_world.zip new file mode 100644 index 00000000..43ffbbc8 Binary files /dev/null and b/translator/tests/data/csar_hello_world.zip differ diff --git a/translator/tests/data/csar_metadata_not_yaml.zip b/translator/tests/data/csar_metadata_not_yaml.zip new file mode 100644 index 00000000..3e6120bb Binary files /dev/null and b/translator/tests/data/csar_metadata_not_yaml.zip differ diff --git a/translator/tests/data/csar_not_zip.zip b/translator/tests/data/csar_not_zip.zip new file mode 100644 index 00000000..43b7f5f5 --- /dev/null +++ b/translator/tests/data/csar_not_zip.zip @@ -0,0 +1 @@ +This is an invalid CSAR file. \ No newline at end of file diff --git a/translator/tests/data/csar_single_instance_wordpress.zip b/translator/tests/data/csar_single_instance_wordpress.zip new file mode 100644 index 00000000..5df7b483 Binary files /dev/null and b/translator/tests/data/csar_single_instance_wordpress.zip differ diff --git a/translator/tests/data/csar_wordpress_invalid_import_path.zip b/translator/tests/data/csar_wordpress_invalid_import_path.zip new file mode 100644 index 00000000..d6442594 Binary files /dev/null and b/translator/tests/data/csar_wordpress_invalid_import_path.zip differ diff --git a/translator/tests/data/csar_wordpress_invalid_script_url.zip b/translator/tests/data/csar_wordpress_invalid_script_url.zip new file mode 100644 index 00000000..6014f923 Binary files /dev/null and b/translator/tests/data/csar_wordpress_invalid_script_url.zip differ diff --git a/translator/tests/data/csar_wrong_metadata_file.zip b/translator/tests/data/csar_wrong_metadata_file.zip new file mode 100644 index 00000000..85d660a0 Binary files /dev/null and b/translator/tests/data/csar_wrong_metadata_file.zip differ diff --git a/translator/tests/data/hot_output/hot_elk_from_csar.yaml b/translator/tests/data/hot_output/hot_elk_from_csar.yaml new file mode 100644 index 00000000..27427bab --- /dev/null +++ b/translator/tests/data/hot_output/hot_elk_from_csar.yaml @@ -0,0 +1,555 @@ +heat_template_version: 2013-05-23 + +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. + +parameters: + github_url: + type: string + description: The URL to download nodejs. + default: http://github.com/paypal/rest-api-sample-app-nodejs.git + + my_cpus: + type: number + description: Number of CPUs for the server. + default: 4 + constraints: + - allowed_values: + - 1 + - 2 + - 4 + - 8 + +resources: + + nodejs_create_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: nodejs_create_config + server: + get_resource: app_server + + nodejs_create_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/nodejs/create.sh + group: script + + paypal_pizzastore_configure_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: paypal_pizzastore_configure_config + input_values: + github_url: http://github.com/paypal/rest-api-sample-app-nodejs.git + mongodb_ip: + get_attr: + - mongo_server + - networks + - private + - 0 + server: + get_resource: app_server + depends_on: + - nodejs_create_deploy + - mongo_db_create_deploy + + paypal_pizzastore_configure_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/nodejs/config.sh + group: script + + paypal_pizzastore_start_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: paypal_pizzastore_start_config + server: + get_resource: app_server + depends_on: + - paypal_pizzastore_configure_deploy + + paypal_pizzastore_start_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/nodejs/start.sh + group: script + + + mongo_dbms_create_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: mongo_dbms_create_config + server: + get_resource: mongo_server + + mongo_dbms_create_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/mongodb/create.sh + group: script + + mongo_dbms_configure_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: mongo_dbms_configure_config + input_values: + mongodb_ip: + get_attr: + - mongo_server + - networks + - private + - 0 + server: + get_resource: mongo_server + depends_on: + - mongo_dbms_create_deploy + + mongo_dbms_configure_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/mongodb/config.sh + group: script + + mongo_dbms_start_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: mongo_dbms_start_config + server: + get_resource: mongo_server + depends_on: + - mongo_dbms_configure_deploy + + mongo_dbms_start_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/mongodb/start.sh + group: script + + mongo_db_create_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: mongo_db_create_config + server: + get_resource: mongo_server + depends_on: + - mongo_dbms_start_deploy + + mongo_db_create_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/mongodb/create_database.sh + group: script + + + app_collectd_create_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: app_collectd_create_config + server: + get_resource: app_server + depends_on: + - logstash_start_deploy + + app_collectd_create_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/collectd/create.sh + group: script + + app_collectd_configure_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: app_collectd_configure_config + input_values: + logstash_ip: + get_attr: + - logstash_server + - networks + - private + - 0 + server: + get_resource: app_server + depends_on: + - app_collectd_create_deploy + + app_collectd_configure_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Python/collectd/config.py + group: script + + app_collectd_start_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: app_collectd_start_config + server: + get_resource: app_server + depends_on: + - app_collectd_configure_deploy + + app_collectd_start_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/collectd/start.sh + group: script + + app_collectd_logstash_connect_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: app_collectd_logstash_connect_config + server: + get_resource: logstash_server + depends_on: + - logstash_create_deploy + + app_collectd_logstash_connect_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Python/logstash/configure_collectd.py + group: script + + + app_rsyslog_create_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: app_rsyslog_create_config + server: + get_resource: app_server + depends_on: + - logstash_start_deploy + + app_rsyslog_create_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/rsyslog/create.sh + group: script + + app_rsyslog_start_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: app_rsyslog_start_config + server: + get_resource: app_server + depends_on: + - app_rsyslog_configure_deploy + + app_rsyslog_start_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/rsyslog/start.sh + group: script + + app_rsyslog_configure_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: app_rsyslog_configure_config + input_values: + logstash_ip: + get_attr: + - logstash_server + - networks + - private + - 0 + server: + get_resource: app_server + depends_on: + - app_rsyslog_create_deploy + + app_rsyslog_configure_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/rsyslog/config.sh + group: script + + app_rsyslog_logstash_connect_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: app_rsyslog_logstash_connect_config + server: + get_resource: logstash_server + depends_on: + - logstash_create_deploy + + app_rsyslog_logstash_connect_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Python/logstash/configure_rsyslog.py + group: script + + + logstash_create_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: logstash_create_config + server: + get_resource: logstash_server + depends_on: + - elasticsearch_start_deploy + + logstash_create_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/logstash/create.sh + group: script + + logstash_start_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: logstash_start_config + server: + get_resource: logstash_server + depends_on: + - logstash_create_deploy + + logstash_start_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/logstash/start.sh + group: script + + logstash_elasticsearch_connect_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: logstash_elasticsearch_connect_config + input_values: + elasticsearch_ip: + get_attr: + - elasticsearch_server + - networks + - private + - 0 + server: + get_resource: logstash_server + depends_on: + - logstash_create_deploy + + logstash_elasticsearch_connect_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Python/logstash/configure_elasticsearch.py + group: script + + + elasticsearch_create_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: elasticsearch_create_config + server: + get_resource: elasticsearch_server + + elasticsearch_create_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/elasticsearch/create.sh + group: script + + elasticsearch_start_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: elasticsearch_start_config + server: + get_resource: elasticsearch_server + depends_on: + - elasticsearch_create_deploy + + elasticsearch_start_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/elasticsearch/start.sh + group: script + + + kibana_create_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: kibana_create_config + server: + get_resource: kibana_server + depends_on: + - elasticsearch_start_deploy + + kibana_create_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/kibana/create.sh + group: script + + kibana_configure_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: kibana_configure_config + input_values: + elasticsearch_ip: + get_attr: + - elasticsearch_server + - networks + - private + - 0 + kibana_ip: + get_attr: + - kibana_server + - networks + - private + - 0 + server: + get_resource: kibana_server + depends_on: + - kibana_create_deploy + + kibana_configure_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/kibana/config.sh + group: script + + kibana_start_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: kibana_start_config + server: + get_resource: kibana_server + depends_on: + - kibana_configure_deploy + + kibana_start_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/kibana/start.sh + group: script + + + app_server: + type: OS::Nova::Server + properties: + flavor: m1.large + image: ubuntu-software-config-os-init + key_name: userkey + user_data_format: SOFTWARE_CONFIG + + mongo_server: + type: OS::Nova::Server + properties: + flavor: m1.large + image: ubuntu-software-config-os-init + key_name: userkey + user_data_format: SOFTWARE_CONFIG + + logstash_server: + type: OS::Nova::Server + properties: + flavor: m1.large + image: ubuntu-software-config-os-init + key_name: userkey + user_data_format: SOFTWARE_CONFIG + + elasticsearch_server: + type: OS::Nova::Server + properties: + flavor: m1.large + image: ubuntu-software-config-os-init + key_name: userkey + user_data_format: SOFTWARE_CONFIG + + kibana_server: + type: OS::Nova::Server + properties: + flavor: m1.large + image: ubuntu-software-config-os-init + key_name: userkey + user_data_format: SOFTWARE_CONFIG + +outputs: + nodejs_url: + description: URL for the nodejs server, http://:3000 + value: + get_attr: + - app_server + - networks + - private + - 0 + + mongodb_url: + description: URL for the mongodb server. + value: + get_attr: + - mongo_server + - networks + - private + - 0 + + logstash_url: + description: URL for the logstash server. + value: + get_attr: + - logstash_server + - networks + - private + - 0 + + elasticsearch_url: + description: URL for the elasticsearch server. + value: + get_attr: + - elasticsearch_server + - networks + - private + - 0 + + kibana_url: + description: URL for the kibana server. + value: + get_attr: + - kibana_server + - networks + - private + - 0 + diff --git a/translator/tests/data/hot_output/hot_tosca_helloworld.yaml b/translator/tests/data/hot_output/hot_hello_world.yaml similarity index 100% rename from translator/tests/data/hot_output/hot_tosca_helloworld.yaml rename to translator/tests/data/hot_output/hot_hello_world.yaml diff --git a/translator/tests/data/hot_output/hot_single_instance_wordpress_from_csar.yaml b/translator/tests/data/hot_output/hot_single_instance_wordpress_from_csar.yaml new file mode 100644 index 00000000..60b043b9 --- /dev/null +++ b/translator/tests/data/hot_output/hot_single_instance_wordpress_from_csar.yaml @@ -0,0 +1,200 @@ +heat_template_version: 2013-05-23 + +description: > + TOSCA simple profile with wordpress, web server and mysql on the same server. + +parameters: + 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 + cpus: + type: number + description: Number of CPUs for the server. + default: 8 + constraints: + - allowed_values: + - 1 + - 2 + - 4 + - 8 + db_root_pwd: + type: string + description: Root password for MySQL. + default: passw0rd + db_port: + type: number + description: Port for the MySQL database. + default: 3366 + +resources: + + mysql_dbms_create_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/MYSQLDBMS/install.sh + group: script + + mysql_dbms_create_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: mysql_dbms_create_config + server: + get_resource: server + + mysql_dbms_start_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/MYSQLDBMS/start.sh + group: script + + mysql_dbms_start_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: mysql_dbms_start_config + server: + get_resource: server + depends_on: + - mysql_dbms_configure_deploy + + mysql_dbms_configure_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/MYSQLDBMS/configure.sh + group: script + + mysql_dbms_configure_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: mysql_dbms_configure_config + input_values: + root_password: passw0rd + server: + get_resource: server + depends_on: + - mysql_dbms_create_deploy + + mysql_database_configure_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/MYSQLDatabase/configure.sh + group: script + + mysql_database_configure_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: mysql_database_configure_config + input_values: + db_name: wordpress + db_password: wp_pass + db_root_password: passw0rd + db_user: wp_user + server: + get_resource: server + depends_on: + - mysql_dbms_start_deploy + + webserver_create_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/WebServer/install.sh + group: script + + webserver_create_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: webserver_create_config + server: + get_resource: server + + webserver_start_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/WebServer/start.sh + group: script + + webserver_start_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: webserver_start_config + server: + get_resource: server + depends_on: + - webserver_create_deploy + + wordpress_create_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/WordPress/install.sh + group: script + + wordpress_create_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: wordpress_create_config + server: + get_resource: server + depends_on: + - webserver_start_deploy + - mysql_database_configure_deploy + + wordpress_configure_config: + type: OS::Heat::SoftwareConfig + properties: + config: + get_file: ../Scripts/WordPress/configure.sh + group: script + + wordpress_configure_deploy: + type: OS::Heat::SoftwareDeployment + properties: + config: + get_resource: wordpress_configure_config + input_values: + wp_db_name: wordpress + wp_db_password: wp_pass + wp_db_user: wp_user + server: + get_resource: server + depends_on: + - wordpress_create_deploy + + server: + type: OS::Nova::Server + properties: + flavor: m1.xlarge + image: fedora-amd64-heat-config + key_name: userkey + user_data_format: SOFTWARE_CONFIG + +outputs: + website_url: + description: IP address for Wordpress wiki. + value: + get_attr: + - server + - networks + - private + - 0 diff --git a/translator/tests/test_tosca_hot_translation.py b/translator/tests/test_tosca_hot_translation.py index 294937c8..3b3d8908 100644 --- a/translator/tests/test_tosca_hot_translation.py +++ b/translator/tests/test_tosca_hot_translation.py @@ -11,6 +11,9 @@ # under the License. import json + +from toscaparser.common.exception import URLException +from toscaparser.common.exception import ValidationError from translator.common.utils import TranslationUtils from translator.tests.base import TestCase @@ -18,8 +21,7 @@ from translator.tests.base import TestCase class ToscaHotTranslationTest(TestCase): def test_hot_translate_single_server(self): - tosca_file = \ - '../tests/data/tosca_single_server.yaml' + tosca_file = '../tests/data/tosca_single_server.yaml' hot_file = '../tests/data/hot_output/hot_single_server.yaml' params = {'cpus': 1} diff = TranslationUtils.compare_tosca_translation_with_hot(tosca_file, @@ -49,8 +51,7 @@ class ToscaHotTranslationTest(TestCase): json.dumps(diff2, indent=4, separators=(', ', ': '))) def test_hot_translate_wordpress_single_instance(self): - tosca_file = \ - '../tests/data/tosca_single_instance_wordpress.yaml' + tosca_file = '../tests/data/tosca_single_instance_wordpress.yaml' hot_file = '../tests/data/hot_output/' \ 'hot_single_instance_wordpress.yaml' params = {'db_name': 'wordpress', @@ -66,10 +67,8 @@ class ToscaHotTranslationTest(TestCase): json.dumps(diff, indent=4, separators=(', ', ': '))) def test_hot_translate_helloworld(self): - tosca_file = \ - '../tests/data/tosca_helloworld.yaml' - hot_file = '../tests/data/hot_output/' \ - 'hot_tosca_helloworld.yaml' + tosca_file = '../tests/data/tosca_helloworld.yaml' + hot_file = '../tests/data/hot_output/hot_hello_world.yaml' diff = TranslationUtils.compare_tosca_translation_with_hot(tosca_file, hot_file, {}) @@ -77,10 +76,8 @@ class ToscaHotTranslationTest(TestCase): json.dumps(diff, indent=4, separators=(', ', ': '))) def test_hot_translate_host_assignment(self): - tosca_file = \ - '../tests/data/test_host_assignment.yaml' - hot_file = '../tests/data/hot_output/' \ - 'hot_host_assignment.yaml' + tosca_file = '../tests/data/test_host_assignment.yaml' + hot_file = '../tests/data/hot_output/hot_host_assignment.yaml' diff = TranslationUtils.compare_tosca_translation_with_hot(tosca_file, hot_file, {}) @@ -88,8 +85,7 @@ class ToscaHotTranslationTest(TestCase): json.dumps(diff, indent=4, separators=(', ', ': '))) def test_hot_translate_elk(self): - tosca_file = \ - '../tests/data/tosca_elk.yaml' + tosca_file = '../tests/data/tosca_elk.yaml' hot_file = '../tests/data/hot_output/hot_elk.yaml' params = {'github_url': 'http://github.com/paypal/rest-api-sample-app-nodejs.git', @@ -101,8 +97,7 @@ class ToscaHotTranslationTest(TestCase): json.dumps(diff, indent=4, separators=(', ', ': '))) def test_hot_translate_nodejs_mongodb_two_instances(self): - tosca_file = \ - '../tests/data/tosca_nodejs_mongodb_two_instances.yaml' + tosca_file = '../tests/data/tosca_nodejs_mongodb_two_instances.yaml' hot_file = '../tests/data/hot_output/' \ 'hot_nodejs_mongodb_two_instances.yaml' params = {'github_url': @@ -115,9 +110,8 @@ class ToscaHotTranslationTest(TestCase): json.dumps(diff, indent=4, separators=(', ', ': '))) def test_hot_translate_blockstorage_with_attachment(self): - tosca_file = \ - '../tests/data/storage/' \ - 'tosca_blockstorage_with_attachment.yaml' + tosca_file = '../tests/data/storage/' \ + 'tosca_blockstorage_with_attachment.yaml' hot_file = '../tests/data/hot_output/storage/' \ 'hot_blockstorage_with_attachment.yaml' params = {'cpus': 1, @@ -131,9 +125,8 @@ class ToscaHotTranslationTest(TestCase): json.dumps(diff, indent=4, separators=(', ', ': '))) def test_hot_translate_blockstorage_with_custom_relationship_type(self): - tosca_file = \ - '../tests/data/storage/' \ - 'tosca_blockstorage_with_custom_relationship_type.yaml' + tosca_file = '../tests/data/storage/' \ + 'tosca_blockstorage_with_custom_relationship_type.yaml' hot_file = '../tests/data/hot_output/storage/' \ 'hot_blockstorage_with_custom_relationship_type.yaml' params = {'cpus': 1, @@ -147,9 +140,8 @@ class ToscaHotTranslationTest(TestCase): json.dumps(diff, indent=4, separators=(', ', ': '))) def test_hot_translate_blockstorage_with_relationship_template(self): - tosca_file = \ - '../tests/data/storage/' \ - 'tosca_blockstorage_with_relationship_template.yaml' + tosca_file = '../tests/data/storage/' \ + 'tosca_blockstorage_with_relationship_template.yaml' hot_file = '../tests/data/hot_output/storage/' \ 'hot_blockstorage_with_relationship_template.yaml' params = {'cpus': 1, @@ -162,9 +154,8 @@ class ToscaHotTranslationTest(TestCase): json.dumps(diff, indent=4, separators=(', ', ': '))) def test_hot_translate_blockstorage_with_attachment_notation1(self): - tosca_file = \ - '../tests/data/storage/' \ - 'tosca_blockstorage_with_attachment_notation1.yaml' + tosca_file = '../tests/data/storage/' \ + 'tosca_blockstorage_with_attachment_notation1.yaml' hot_file1 = '../tests/data/hot_output/storage/' \ 'hot_blockstorage_with_attachment_notation1_alt1.yaml' hot_file2 = '../tests/data/hot_output/storage/' \ @@ -188,9 +179,8 @@ class ToscaHotTranslationTest(TestCase): separators=(', ', ': '))) def test_hot_translate_blockstorage_with_attachment_notation2(self): - tosca_file = \ - '../tests/data/storage/' \ - 'tosca_blockstorage_with_attachment_notation2.yaml' + tosca_file = '../tests/data/storage/' \ + 'tosca_blockstorage_with_attachment_notation2.yaml' hot_file1 = '../tests/data/hot_output/storage/' \ 'hot_blockstorage_with_attachment_notation2_alt1.yaml' hot_file2 = '../tests/data/hot_output/storage/' \ @@ -214,9 +204,8 @@ class ToscaHotTranslationTest(TestCase): separators=(', ', ': '))) def test_hot_translate_multiple_blockstorage_with_attachment(self): - tosca_file = \ - '../tests/data/storage/' \ - 'tosca_multiple_blockstorage_with_attachment.yaml' + tosca_file = '../tests/data/storage/' \ + 'tosca_multiple_blockstorage_with_attachment.yaml' hot_file1 = '../tests/data/hot_output/storage/' \ 'hot_multiple_blockstorage_with_attachment_alt1.yaml' hot_file2 = '../tests/data/hot_output/storage/' \ @@ -240,10 +229,8 @@ class ToscaHotTranslationTest(TestCase): separators=(', ', ': '))) def test_hot_translate_single_object_store(self): - tosca_file = \ - '../tests/data/storage/tosca_single_object_store.yaml' - hot_file = '../tests/data/hot_output/' \ - 'hot_single_object_store.yaml' + tosca_file = '../tests/data/storage/tosca_single_object_store.yaml' + hot_file = '../tests/data/hot_output/hot_single_object_store.yaml' params = {'objectstore_name': 'myobjstore'} diff = TranslationUtils.compare_tosca_translation_with_hot(tosca_file, hot_file, @@ -252,8 +239,7 @@ class ToscaHotTranslationTest(TestCase): json.dumps(diff, indent=4, separators=(', ', ': '))) def test_hot_translate_one_server_one_network(self): - tosca_file = \ - '../tests/data/network/tosca_one_server_one_network.yaml' + tosca_file = '../tests/data/network/tosca_one_server_one_network.yaml' hot_file = '../tests/data/hot_output/network/' \ 'hot_one_server_one_network.yaml' params = {'network_name': 'private_net'} @@ -276,8 +262,7 @@ class ToscaHotTranslationTest(TestCase): json.dumps(diff, indent=4, separators=(', ', ': '))) def test_hot_translate_two_servers_one_network(self): - tosca_file = \ - '../tests/data/network/tosca_two_servers_one_network.yaml' + tosca_file = '../tests/data/network/tosca_two_servers_one_network.yaml' hot_file = '../tests/data/hot_output/network/' \ 'hot_two_servers_one_network.yaml' params = {'network_name': 'my_private_net', @@ -304,8 +289,7 @@ class ToscaHotTranslationTest(TestCase): def test_hot_translate_software_component(self): tosca_file = '../tests/data/tosca_software_component.yaml' - hot_file = '../tests/data/hot_output/' \ - 'hot_software_component.yaml' + hot_file = '../tests/data/hot_output/hot_software_component.yaml' params = {'cpus': '1', 'download_url': 'http://www.software.com/download'} diff = TranslationUtils.compare_tosca_translation_with_hot(tosca_file, @@ -370,19 +354,16 @@ class ToscaHotTranslationTest(TestCase): 'db_root_pwd': 'passw0rd', 'db_port': 3366, 'cpus': 8} - try: - TranslationUtils.compare_tosca_translation_with_hot( - tosca_file, hot_file, params) - except Exception as err: - self.assertTrue(isinstance(err, ImportError)) - self.assertEqual( - 'Absolute file name /tmp/wordpress.yaml cannot be used for a ' - 'URL-based input https://ibm.box.com/shared/static/' - 'lrgdktp9vw3991y2hlogmghwwvnok3lu.yaml template.', - err.__str__()) - else: - raise Exception( - 'The unit test that was expected to fail did not fail.') + + err = self.assertRaises( + ImportError, + TranslationUtils.compare_tosca_translation_with_hot, + tosca_file, hot_file, params) + self.assertEqual( + 'Absolute file name /tmp/wordpress.yaml cannot be used for a ' + 'URL-based input https://ibm.box.com/shared/static/' + 'lrgdktp9vw3991y2hlogmghwwvnok3lu.yaml template.', + err.__str__()) def test_hot_translate_template_by_url_with_url_import(self): tosca_url = 'https://ibm.box.com/shared/static/' \ @@ -400,3 +381,122 @@ class ToscaHotTranslationTest(TestCase): params) self.assertEqual({}, diff, ' : ' + json.dumps(diff, indent=4, separators=(', ', ': '))) + + def test_translate_hello_world_csar(self): + tosca_file = '../tests/data/csar_hello_world.zip' + hot_file = '../tests/data/hot_output/hot_hello_world.yaml' + diff = TranslationUtils.compare_tosca_translation_with_hot(tosca_file, + hot_file, + {}) + self.assertEqual({}, diff, ' : ' + + json.dumps(diff, indent=4, separators=(', ', ': '))) + + def test_translate_single_instance_wordpress_csar(self): + tosca_file = '../tests/data/csar_single_instance_wordpress.zip' + hot_file = '../tests/data/hot_output/' \ + 'hot_single_instance_wordpress_from_csar.yaml' + params = {'db_name': 'wordpress', + 'db_user': 'wp_user', + 'db_pwd': 'wp_pass', + 'db_root_pwd': 'passw0rd', + 'db_port': 3366, + 'cpus': 8} + diff = TranslationUtils.compare_tosca_translation_with_hot(tosca_file, + hot_file, + params) + self.assertEqual({}, diff, ' : ' + + json.dumps(diff, indent=4, separators=(', ', ': '))) + + def test_translate_elk_csar_from_url(self): + tosca_file = 'https://ibm.box.com/shared/static/' \ + 'k9vtus4jes1epl7vfojbcscgsd80inzv.zip' + hot_file = '../tests/data/hot_output/hot_elk_from_csar.yaml' + params = {'github_url': + 'http://github.com/paypal/rest-api-sample-app-nodejs.git', + 'my_cpus': 4} + diff = TranslationUtils.compare_tosca_translation_with_hot(tosca_file, + hot_file, + params) + self.assertEqual({}, diff, ' : ' + + json.dumps(diff, indent=4, separators=(', ', ': '))) + + def test_translate_csar_not_zip(self): + tosca_file = '../tests/data/csar_not_zip.zip' + hot_file = '' + params = {} + + err = self.assertRaises( + ValidationError, + TranslationUtils.compare_tosca_translation_with_hot, + tosca_file, hot_file, params) + + err_msg = err.__str__() + self.assertIs(True, + err_msg.startswith('The file ') and + err_msg.endswith('../tests/data/csar_not_zip.zip is not ' + 'a valid zip file.')) + + def test_translate_csar_metadata_not_yaml(self): + tosca_file = '../tests/data/csar_metadata_not_yaml.zip' + hot_file = '' + params = {} + + err = self.assertRaises( + ValidationError, + TranslationUtils.compare_tosca_translation_with_hot, + tosca_file, hot_file, params) + + err_msg = err.__str__() + self.assertIs(True, + err_msg.startswith('The file ' + '"TOSCA-Metadata/TOSCA.meta" in ') + and + err_msg.endswith('../tests/data/csar_metadata_not_yaml' + '.zip does not contain valid YAML ' + 'content.')) + + def test_translate_csar_wrong_metadata_file(self): + tosca_file = '../tests/data/csar_wrong_metadata_file.zip' + hot_file = '' + params = {} + + err = self.assertRaises( + ValidationError, + TranslationUtils.compare_tosca_translation_with_hot, + tosca_file, hot_file, params) + + err_msg = err.__str__() + self.assertIs(True, + err_msg.startswith('The file ') and + err_msg.endswith('../tests/data/csar_wrong_metadata_file' + '.zip is not a valid CSAR as it does ' + 'not contain the required file ' + '"TOSCA.meta" in the folder ' + '"TOSCA-Metadata".')) + + def test_translate_csar_wordpress_invalid_import_path(self): + tosca_file = '../tests/data/csar_wordpress_invalid_import_path.zip' + hot_file = '' + params = {} + + err = self.assertRaises( + ImportError, + TranslationUtils.compare_tosca_translation_with_hot, + tosca_file, hot_file, params) + self.assertEqual('Import Definitions/wordpress.yaml is not valid', + err.__str__()) + + def test_translate_csar_wordpress_invalid_script_url(self): + tosca_file = '../tests/data/csar_wordpress_invalid_script_url.zip' + hot_file = '' + params = {} + + err = self.assertRaises( + URLException, + TranslationUtils.compare_tosca_translation_with_hot, + tosca_file, hot_file, params) + self.assertEqual('URLException "The resource at ' + 'https://raw.githubusercontent.com/openstack/' + 'heat-translator/master/translator/tests/data/' + 'custom_types/wordpress1.yaml cannot be accessed".', + err.__str__())