Commit e47b687c authored by Spiros Koulouzis's avatar Spiros Koulouzis

added check is service is up

parent d79834d8
...@@ -16,6 +16,8 @@ import os ...@@ -16,6 +16,8 @@ import os
import unittest import unittest
from io import BytesIO from io import BytesIO
import urllib3
import sure_tosca_client import sure_tosca_client
from sure_tosca_client import Configuration, ApiClient from sure_tosca_client import Configuration, ApiClient
from sure_tosca_client.api.default_api import DefaultApi # noqa: E501 from sure_tosca_client.api.default_api import DefaultApi # noqa: E501
...@@ -28,9 +30,13 @@ class TestDefaultApi(unittest.TestCase): ...@@ -28,9 +30,13 @@ class TestDefaultApi(unittest.TestCase):
def setUp(self): def setUp(self):
configuration = Configuration() configuration = Configuration()
configuration.host = 'http://localhost:8081/tosca-sure/1.0.0' #Make sure we don't have '/' on the end of url configuration.host = 'http://localhost:8081/tosca-sure/1.0.0' #Make sure we don't have '/' on the end of url
configuration.verify_ssl = False if self.service_is_up(configuration.host):
api_client = ApiClient(configuration=configuration) configuration.verify_ssl = False
self.api = sure_tosca_client.api.default_api.DefaultApi(api_client=api_client) # noqa: E501 api_client = ApiClient(configuration=configuration)
self.api = sure_tosca_client.api.default_api.DefaultApi(api_client=api_client) # noqa: E501
self.service_is_up = True
else:
self.service_is_up = False
def tearDown(self): def tearDown(self):
pass pass
...@@ -94,10 +100,11 @@ class TestDefaultApi(unittest.TestCase): ...@@ -94,10 +100,11 @@ class TestDefaultApi(unittest.TestCase):
"""Test case for get_node_templates """Test case for get_node_templates
""" """
file_id = self.upload_tosca_template('application_example_provisioned.yaml') if self.service_is_up:
node_templates = self.api.get_node_templates(file_id) file_id = self.upload_tosca_template('application_example_provisioned.yaml')
self.assertIsNotNone(node_templates) node_templates = self.api.get_node_templates(file_id)
nodes_to_deploy = self.api.get_node_templates(file_id,type_name = 'tosca.nodes.ARTICONF.Application') self.assertIsNotNone(node_templates)
nodes_to_deploy = self.api.get_node_templates(file_id,type_name = 'tosca.nodes.ARTICONF.Application')
...@@ -162,8 +169,9 @@ class TestDefaultApi(unittest.TestCase): ...@@ -162,8 +169,9 @@ class TestDefaultApi(unittest.TestCase):
upload a tosca template description file # noqa: E501 upload a tosca template description file # noqa: E501
""" """
file_id = self.upload_tosca_template('application_example_provisioned.yaml') if self.service_is_up:
self.assertIsNotNone(file_id) file_id = self.upload_tosca_template('application_example_provisioned.yaml')
self.assertIsNotNone(file_id)
def get_tosca_file(self, file_name): def get_tosca_file(self, file_name):
tosca_path = "../../TOSCA/" tosca_path = "../../TOSCA/"
...@@ -178,10 +186,21 @@ class TestDefaultApi(unittest.TestCase): ...@@ -178,10 +186,21 @@ class TestDefaultApi(unittest.TestCase):
return input_tosca_file_path return input_tosca_file_path
def upload_tosca_template(self, file_name): def upload_tosca_template(self, file_name):
file = self.get_tosca_file(file_name) if self.service_is_up:
file_id = self.api.upload_tosca_template(file) file = self.get_tosca_file(file_name)
return file_id file_id = self.api.upload_tosca_template(file)
return file_id
def service_is_up(self, url):
code = None
try:
http = urllib3.PoolManager()
r = http.request('HEAD', url)
except Exception as e:
return False
return True
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment