Example #1
0
class TestYMLTranformer(TestCase):
    @classmethod
    def setUpClass(self):
        file = 'data/tests/test_groups.yml'
        importer = YMLImporter()
        self.microtosca = importer.Import(file)
        self.exporter = YMLExporter()

    def test_export_team1(self):
        t1 = self.microtosca.get_group("team1")
        dteam = self.exporter._transform_group(t1)
        self.assertEqual(dteam["type"], MICROTOSCA_GROUPS_TEAM)
        self.assertEqual(dteam["members"], ["s1", "mb1"])

    def test_export_team2(self):
        t2 = self.microtosca.get_group("team2")
        dteam = self.exporter._transform_group(t2)
        self.assertEqual(dteam["type"], MICROTOSCA_GROUPS_TEAM)
        self.assertEqual(dteam["members"], ["s2", "mr2", "db2"])

    def test_export_team3(self):
        t3 = self.microtosca.get_group("team3")
        dteam = self.exporter._transform_group(t3)
        self.assertEqual(dteam["type"], MICROTOSCA_GROUPS_TEAM)
        self.assertEqual(dteam["members"], ["s3", "db3"])

    def test_export_edge(self):
        edge = self.microtosca.get_group("edgenodes")
        dedge = self.exporter._transform_group(edge)
        self.assertEqual(dedge["type"], MICROTOSCA_GROUPS_EDGE)
        self.assertEqual(dedge["members"], ["s1", "mr2", "s3"])
Example #2
0
class TestYMLTranformer(TestCase):
    @classmethod
    def setUpClass(self):
        file = 'data/tests/test_nodes.yml'
        loader = YMLImporter()
        self.microtosca = loader.Import(file)
        self.tranformer = YMLExporter()

    def test_transform_service(self):
        service = self.microtosca["my_service"]
        dict_service = self.tranformer._transform_node_template(service)
        self.assertEqual(dict_service["type"], MICROTOSCA_NODES_SERVICE)

    def test_transform_database(self):
        db = self.microtosca['my_datastore']
        dict_db = self.tranformer._transform_node_template(db)
        self.assertEqual(dict_db["type"], MICROTOSCA_NODES_DATABASE)

    def test_transform_messagebroker(self):
        mb = self.microtosca['my_messagebroker']
        dict_mb = self.tranformer._transform_node_template(mb)
        self.assertEqual(dict_mb["type"], MICROTOSCA_NODES_MESSAGE_BROKER)

    def test_transform_router(self):
        mr = self.microtosca['my_messagerouter']
        dict_mr = self.tranformer._transform_node_template(mr)
        self.assertEqual(dict_mr["type"], MICROTOSCA_NODES_MESSAGE_ROUTER)
Example #3
0
def export_yml(request, model_name):
    model = model_storage.get_model(model_name)
    try:
        yml_exporter = YMLExporter()
        ymodel = yml_exporter.Export(model)
        return Response(ymodel, status=status.HTTP_200_OK)
    except MicroFreshenerError as e:
        return Response(str(e), status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Example #4
0
def jsontoyml(jsonfile, ymlfile):
    """
    Transform a JSON file into microTosca YML file
    """

    model = JSONImporter().Import(jsonfile)
    ymlString = YMLExporter().Export(model)
    click.echo(ymlString)
    with open(ymlfile, 'w') as outfile:
        outfile.write(ymlString)
Example #5
0
 def setUpClass(self):
     file = 'data/tests/test_groups.yml'
     importer = YMLImporter()
     self.microtosca = importer.Import(file)
     self.exporter = YMLExporter()
Example #6
0
import os
import json

from microfreshener.core.analyser import MicroToscaAnalyser
from microfreshener.core.analyser import MicroToscaAnalyserBuilder
from microfreshener.core.importer import JSONImporter, YMLImporter
from microfreshener.core.exporter import JSONExporter, YMLExporter
from microfreshener.core.model import MicroToscaModel
from microfreshener.core.model import Service, Datastore, CommunicationPattern
from microfreshener.core.errors import ImporterError, MicroFreshenerError
from microfreshener.core.refiner import KubernetesRefiner, IstioRefiner

json_importer = JSONImporter()
yml_importer = YMLImporter()
json_exporter = JSONExporter()
yml_exporter = YMLExporter()

file_name = "default.json"
model_file_path = os.path.join(settings.MEDIA_ROOT, file_name)
examples_path = os.path.join(settings.MEDIA_ROOT, "examples")
uploads_path = os.path.join(settings.MEDIA_ROOT, "uploads")
file_uploads_path = os.path.join(uploads_path, "upload.yml")
file_refine_path = os.path.join(uploads_path, "refinekubernetes.yml")
file_refine_istio_path = os.path.join(uploads_path, "refine_istio.yml")


@api_view(['GET'])
def graph_analysis(request):
    """
    get:
    Run the analysis and return the smells (with their refactorings)
class TestYmlExporterRelationships(TestCase):

    @classmethod
    def setUpClass(self):
        file = 'data/tests/test_relationships_properties.yml'
        importer = YMLImporter()
        self.microtosca = importer.Import(file)
        self.exporter = YMLExporter()

    def test_relationship(self):
        rel_dict = self._transform_relationship_from_source_to_target("source", "target")
        self.assertEqual(rel_dict[YML_INTERACTION], "target")

    def test_relationship_t(self):
        rel_dict = self._transform_relationship_from_source_to_target("source", "target_t")
        self.assertEqual(rel_dict[YML_INTERACTION]['node'], "target_t")
        self.assertEqual(rel_dict[YML_INTERACTION]["relationship"], "t")
    
    def test_relationship_c(self):
        rel_dict = self._transform_relationship_from_source_to_target("source", "target_c")
        self.assertEqual(rel_dict[YML_INTERACTION]['node'], "target_c")
        self.assertEqual(rel_dict[YML_INTERACTION]["relationship"], "c")
    
    def test_relationship_d(self):
        rel_dict = self._transform_relationship_from_source_to_target("source", "target_d")
        self.assertEqual(rel_dict[YML_INTERACTION]['node'], "target_d")
        self.assertEqual(rel_dict[YML_INTERACTION]["relationship"], "d")
    
    def test_relationship_tc(self):
        rel_dict = self._transform_relationship_from_source_to_target("source", "target_tc")
        self.assertEqual(rel_dict[YML_INTERACTION]['node'], "target_tc")
        self.assertEqual(rel_dict[YML_INTERACTION]["relationship"], "tc")
    
    def test_relationship_td(self):
        rel_dict = self._transform_relationship_from_source_to_target("source", "target_td")
        self.assertEqual(rel_dict[YML_INTERACTION]['node'], "target_td")
        self.assertEqual(rel_dict[YML_INTERACTION]["relationship"], "td")
    
    def test_relationship_cd(self):
        rel_dict = self._transform_relationship_from_source_to_target("source", "target_cd")
        self.assertEqual(rel_dict[YML_INTERACTION]['node'], "target_cd")
        self.assertEqual(rel_dict[YML_INTERACTION]["relationship"], "cd")
    
    def test_relationship_tcd(self):
        rel_dict = self._transform_relationship_from_source_to_target("source", "target_tcd")
        self.assertEqual(rel_dict[YML_INTERACTION]['node'], "target_tcd")
        self.assertEqual(rel_dict[YML_INTERACTION]["relationship"], "tcd")
    
    def _transform_relationship_from_source_to_target(self, source_name, target_name):
        source = self.microtosca[source_name]
        target = self.microtosca[target_name]
        link_to_target = [
            link for link in source.interactions if link.target == target]
        self.assertEqual(len(link_to_target), 1)
        rel_dict = self.exporter._transform_relationship(link_to_target[0])
        return rel_dict
    


    def test_build_relationship_templates_t(self):
        rel = self.exporter.build_relationship_templates()
        self.assertDictEqual(rel[YML_RELATIONSHIP_T], {"type": MICROTOSCA_RELATIONSHIPS_INTERACT_WITH, "properties": {MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_TIMEOUT_PROPERTY: True}})
        self.assertTrue(MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_CIRCUIT_BREAKER_PROPERTY not in rel[YML_RELATIONSHIP_T])
        self.assertTrue(MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_DYNAMIC_DISCOVEY_PROPERTY not in rel[YML_RELATIONSHIP_T])

    def test_build_relationship_templates_d(self):
        rel = self.exporter.build_relationship_templates()
        self.assertDictEqual(rel[YML_RELATIONSHIP_D], {"type": MICROTOSCA_RELATIONSHIPS_INTERACT_WITH, "properties": {MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_DYNAMIC_DISCOVEY_PROPERTY: True}})
        self.assertTrue(MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_CIRCUIT_BREAKER_PROPERTY not in rel[YML_RELATIONSHIP_T])
        self.assertTrue(MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_TIMEOUT_PROPERTY not in rel[YML_RELATIONSHIP_T])

    def test_build_relationship_templates_c(self):
        rel = self.exporter.build_relationship_templates()
        self.assertDictEqual(rel[YML_RELATIONSHIP_C], {"type": MICROTOSCA_RELATIONSHIPS_INTERACT_WITH, "properties": {MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_CIRCUIT_BREAKER_PROPERTY: True}})
        self.assertTrue(MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_TIMEOUT_PROPERTY not in rel[YML_RELATIONSHIP_T])
        self.assertTrue(MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_DYNAMIC_DISCOVEY_PROPERTY not in rel[YML_RELATIONSHIP_T])

    def test_build_relationship_templates_tc(self):
        rel = self.exporter.build_relationship_templates()
        self.assertDictEqual(rel[YML_RELATIONSHIP_TC], {"type": MICROTOSCA_RELATIONSHIPS_INTERACT_WITH, "properties": {MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_TIMEOUT_PROPERTY: True, MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_CIRCUIT_BREAKER_PROPERTY: True}})
        self.assertTrue(MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_DYNAMIC_DISCOVEY_PROPERTY not in rel[YML_RELATIONSHIP_T])
    
    def test_build_relationship_templates_td(self):
        rel = self.exporter.build_relationship_templates()
        self.assertDictEqual(rel[YML_RELATIONSHIP_TD], {"type": MICROTOSCA_RELATIONSHIPS_INTERACT_WITH, "properties": {MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_TIMEOUT_PROPERTY: True, MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_DYNAMIC_DISCOVEY_PROPERTY: True}})
        self.assertTrue(MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_CIRCUIT_BREAKER_PROPERTY not in rel[YML_RELATIONSHIP_T])
        
    def test_build_relationship_templates_cd(self):
        rel = self.exporter.build_relationship_templates()
        self.assertDictEqual(rel[YML_RELATIONSHIP_CD], {"type": MICROTOSCA_RELATIONSHIPS_INTERACT_WITH, "properties": {MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_CIRCUIT_BREAKER_PROPERTY: True, MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_DYNAMIC_DISCOVEY_PROPERTY: True}})
        self.assertTrue(MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_TIMEOUT_PROPERTY not in rel[YML_RELATIONSHIP_T])
    
    def test_build_relationship_templates_tcd(self):
        rel = self.exporter.build_relationship_templates()
        self.assertDictEqual(rel[YML_RELATIONSHIP_TCD], {"type": MICROTOSCA_RELATIONSHIPS_INTERACT_WITH, "properties": {MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_TIMEOUT_PROPERTY: True,MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_CIRCUIT_BREAKER_PROPERTY: True, MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_DYNAMIC_DISCOVEY_PROPERTY: True}})
 def setUpClass(self):
     file = 'data/tests/test_relationships_properties.yml'
     importer = YMLImporter()
     self.microtosca = importer.Import(file)
     self.exporter = YMLExporter()
Example #9
0
 def setUpClass(self):
     file = 'data/tests/test_nodes.yml'
     loader = YMLImporter()
     self.microtosca = loader.Import(file)
     self.tranformer = YMLExporter()