def analyse(ymlfile): """ Analyse a microTOSCA YML """ importer = YMLImporter() model = importer.Import(ymlfile) builder = MicroToscaAnalyserBuilder(model) analyser = builder.add_all_sniffers().build() res = analyser.run() click.echo(res)
def ymltojson(ymlfile, jsonfile): """ Transform a microTOSCA YML file to JSON """ yml_importer = YMLImporter() json_exporter = JSONExporter() mmodel = yml_importer.Import(ymlfile) jsonString = json_exporter.Export(mmodel) with open(jsonfile, 'w') as outfile: json.dump(jsonString, outfile, indent=4)
class TestYMLImporterGroups(TestCase): @classmethod def setUpClass(self): file = 'data/tests/test_groups.yml' self.importer = YMLImporter() self.microtosca = self.importer.Import(file) def test_team1(self): t1 = self.microtosca.get_group("team1") self.assertEqual(len(t1.members),2) self.assertIsInstance(t1, Team) def test_team2(self): t2 = self.microtosca.get_group("team2") self.assertEqual(len(t2.members),3) self.assertIsInstance(t2, Team) def test_team3(self): t3 = self.microtosca.get_group("team3") self.assertEqual(len(t3.members),2) self.assertIsInstance(t3, Team) def test_edge(self): edge = self.microtosca.get_group("edgenodes") self.assertEqual(len(edge.members), 3) # Datastore node cannot be into an Edge group self.assertIsInstance(edge, Edge)
class TestYMLImporterNodes(TestCase): @classmethod def setUpClass(self): file = 'data/tests/test_nodes.yml' self.importer = YMLImporter() self.microtosca = self.importer.Import(file) def test_service(self): s1 = self.microtosca['my_service'] self.assertIsInstance(s1, Service) self.assertEqual(s1.name, "my_service") def test_database(self): db = self.microtosca['my_datastore'] self.assertIsInstance(db, Datastore) self.assertEqual(db.name, "my_datastore") def test_messagebroker(self): mb = self.microtosca['my_messagebroker'] self.assertIsInstance(mb, MessageBroker) self.assertEqual(mb.name, "my_messagebroker") def test_messagerouter(self): mr = self.microtosca['my_messagerouter'] self.assertIsInstance(mr, MessageRouter) self.assertEqual(mr.name, "my_messagerouter") self.assertEqual(mr.label, "MR") def test_kservice(self): mr = self.microtosca['my_kservice'] self.assertIsInstance(mr, KService) self.assertEqual(mr.name, "my_kservice") def test_kproxy(self): mr = self.microtosca['my_kproxy'] self.assertIsInstance(mr, KProxy) self.assertEqual(mr.name, "my_kproxy") def test_kingress(self): mr = self.microtosca['my_kingress'] self.assertIsInstance(mr, KIngress) self.assertEqual(mr.name, "my_kingress")
class TestYMLImporterRelationshipProperties(TestCase): @classmethod def setUpClass(self): file = 'data/tests/test_relationships_properties.yml' self.importer = YMLImporter() self.microtosca = self.importer.Import(file) def test_relationship_empty(self): link = self._load_relationship_from_source_to_target( "source", "target") self.assertFalse(link.timeout) self.assertFalse(link.circuit_breaker) self.assertFalse(link.dynamic_discovery) def test_relationship_t(self): link = self._load_relationship_from_source_to_target( "source", "target_t") self.assertTrue(link.timeout) self.assertFalse(link.circuit_breaker) self.assertFalse(link.dynamic_discovery) def test_relationship_c(self): link = self._load_relationship_from_source_to_target( "source", "target_c") self.assertFalse(link.timeout) self.assertTrue(link.circuit_breaker) self.assertFalse(link.dynamic_discovery) def test_relationship_d(self): link = self._load_relationship_from_source_to_target( "source", "target_d") self.assertFalse(link.timeout) self.assertFalse(link.circuit_breaker) self.assertTrue(link.dynamic_discovery) def test_relationship_tc(self): link = self._load_relationship_from_source_to_target( "source", "target_tc") self.assertTrue(link.timeout) self.assertTrue(link.circuit_breaker) self.assertFalse(link.dynamic_discovery) def test_relationship_td(self): link = self._load_relationship_from_source_to_target( "source", "target_td") self.assertTrue(link.timeout) self.assertFalse(link.circuit_breaker) self.assertTrue(link.dynamic_discovery) def test_relationship_cd(self): link = self._load_relationship_from_source_to_target( "source", "target_cd") self.assertFalse(link.timeout) self.assertTrue(link.circuit_breaker) self.assertTrue(link.dynamic_discovery) def test_relationship_tcd(self): link = self._load_relationship_from_source_to_target( "source", "target_tcd") self.assertTrue(link.timeout) self.assertTrue(link.circuit_breaker) self.assertTrue(link.dynamic_discovery) def test_multiple_relatsionship(self): source = self.microtosca["source_same"] target = self.microtosca["target_same"] links_to_target = [ link for link in source.interactions if link.target == target ] self.assertEqual(len(links_to_target), 8) self.assertFalse(links_to_target[0] == links_to_target[1]) self.assertTrue(links_to_target[0] == links_to_target[0]) def test_get_relationship_template_t(self): rel = self.importer._get_relationship_template_by_name( YML_RELATIONSHIP_T) self.assertDictEqual( rel, { "type": MICROTOSCA_RELATIONSHIPS_INTERACT_WITH, "properties": { MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_TIMEOUT_PROPERTY: True } }) def test_get_relationship_template_c(self): rel = self.importer._get_relationship_template_by_name( YML_RELATIONSHIP_C) self.assertDictEqual( rel, { "type": MICROTOSCA_RELATIONSHIPS_INTERACT_WITH, "properties": { MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_CIRCUIT_BREAKER_PROPERTY: True } }) def test_get_relationship_template_d(self): rel = self.importer._get_relationship_template_by_name( YML_RELATIONSHIP_D) self.assertDictEqual( rel, { "type": MICROTOSCA_RELATIONSHIPS_INTERACT_WITH, "properties": { MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_DYNAMIC_DISCOVEY_PROPERTY: True } }) def test_get_relationship_template_tc(self): rel = self.importer._get_relationship_template_by_name( YML_RELATIONSHIP_TC) self.assertDictEqual( rel, { "type": MICROTOSCA_RELATIONSHIPS_INTERACT_WITH, "properties": { MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_TIMEOUT_PROPERTY: True, MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_CIRCUIT_BREAKER_PROPERTY: True } }) def test_get_relationship_template_td(self): rel = self.importer._get_relationship_template_by_name( YML_RELATIONSHIP_TD) self.assertDictEqual( rel, { "type": MICROTOSCA_RELATIONSHIPS_INTERACT_WITH, "properties": { MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_TIMEOUT_PROPERTY: True, MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_DYNAMIC_DISCOVEY_PROPERTY: True } }) def test_get_relationship_template_cd(self): rel = self.importer._get_relationship_template_by_name( YML_RELATIONSHIP_CD) self.assertDictEqual( rel, { "type": MICROTOSCA_RELATIONSHIPS_INTERACT_WITH, "properties": { MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_CIRCUIT_BREAKER_PROPERTY: True, MICROTOSCA_RELATIONSHIPS_INTERACT_WITH_DYNAMIC_DISCOVEY_PROPERTY: True } }) def test_get_relationship_template_tcd(self): rel = self.importer._get_relationship_template_by_name( YML_RELATIONSHIP_TCD) self.assertDictEqual( rel, { "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 test_get_relationship_template_raise(self): with self.assertRaises(ImporterError): self.importer._get_relationship_template_by_name("notexist") def _load_relationship_from_source_to_target(self, source_name, target_name): source = self.microtosca[source_name] target = self.microtosca[target_name] links_to_target = [ link for link in source.interactions if link.target == target ] self.assertEqual(len(links_to_target), 1) return links_to_target[0]
def setUpClass(self): file = 'data/tests/test_relationships_properties.yml' self.importer = YMLImporter() self.microtosca = self.importer.Import(file)
def setUpClass(self): file = 'data/tests/test_sniffer_ctdm.yml' loader = YMLImporter() self.micro_model = loader.Import(file) self.ctdmSniffer = CrossTeamDataManagementSmellSniffer( self.micro_model)
def setUpClass(self): file = 'data/examples/hello-world/helloworld.yml' loader = YMLImporter() self.micro_object = loader.Import(file)
def setUpClass(self): self.microtosca = YMLImporter().Import( 'data/examples/sockshop/sockshop.yml') self.refiner = KubernetesRefiner( 'data/examples/sockshop/ksockshop.yml') self.kmicrotosca = self.refiner.Refine(self.microtosca)
def setUpClass(self): file = 'data/tests/test_groups.yml' importer = YMLImporter() self.microtosca = importer.Import(file) self.exporter = YMLExporter()
from django.views.decorators.csrf import csrf_exempt from rest_framework.response import Response 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): """
def setUpClass(self): file = 'data/tests/test_nodes.yml' self.importer = YMLImporter() self.microtosca = self.importer.Import(file)
def setUpClass(self): file = 'data/tests/test_sniffer_shpr.yml' loader = YMLImporter() self.micro_model = loader.Import(file) self.shprSniffer = SharedPersistencySmellSniffer()
class TestYMLImporter(TestCase): @classmethod def setUpClass(self): file = 'data/examples/hello-world/helloworld.yml' self.importer = YMLImporter() self.microtosca = self.importer.Import(file) def test_number_nodes(self): self.assertEqual(len(list(self.microtosca.nodes)), 5) def test_get_node_by_name(self): self.assertEqual(self.microtosca['shipping'].name, "shipping") def test_get_services(self): self.assertEqual(len(list(self.microtosca.services)), 2) def test_database(self): db = self.microtosca['shipping'] self.assertIsInstance(db, Service) def test_shipping_interactions(self): shipping = self.microtosca["shipping"] rels = [link.target.name for link in shipping.interactions] self.assertCountEqual(rels, ['rabbitmq', 'order_db']) def test_order_interactions(self): order = self.microtosca["order"] rels = [link.target.name for link in order.interactions] self.assertCountEqual(rels, ['shipping', 'order_db', 'rabbitmq', 'shipping']) def test_gateway_interactions(self): order = self.microtosca["gateway"] rels = [link.target.name for link in order.interactions] self.assertCountEqual(rels, ['shipping']) def test_shipping_incoming_interactions(self): shipping = self.microtosca["shipping"] rels = [link.source.name for link in shipping.incoming_interactions] self.assertCountEqual(rels, ['order', 'order', 'gateway']) def test_order_incoming_interactions(self): order = self.microtosca["order"] rels = [link.source.name for link in order.incoming_interactions] self.assertCountEqual(rels, []) def test_rabbitmq_incoming_interactions(self): rabbitmq = self.microtosca["rabbitmq"] rels = [link.source.name for link in rabbitmq.incoming_interactions] self.assertCountEqual(rels, ['shipping', 'order']) def test_orderdb_incoming_interactions(self): order_db = self.microtosca["order_db"] rels = [link.source.name for link in order_db.incoming_interactions] self.assertCountEqual(rels, ['shipping', 'order']) def test_timedout_relationship(self): order = self.microtosca["order"] shipping = self.microtosca["shipping"] link_to_shipping = [ link for link in order.interactions if link.target == shipping ] self.assertTrue(link_to_shipping[0].timeout) def test_edge_group(self): group = self.microtosca.get_group('edgenodes') self.assertEqual(group.name, "edgenodes") self.assertEqual(self.microtosca['shipping'] in group, True) self.assertEqual('shipping' in group, True) self.assertEqual(self.microtosca['rabbitmq'] in group, False) self.assertEqual('rabbitmq' in group, False) members = [m.name for m in group.members] self.assertCountEqual(members, ['shipping', 'order', 'gateway']) def test_squad_group(self): squad = self.microtosca.get_group('team1') self.assertEqual(squad.name, "team1") self.assertEqual(self.microtosca['shipping'] in squad, True) self.assertEqual('shipping' in squad, True) self.assertEqual(self.microtosca['rabbitmq'] in squad, True) self.assertEqual('rabbitmq' in squad, True) self.assertEqual(self.microtosca['order'] in squad, False) self.assertEqual('order' in squad, False) self.assertCountEqual([m.name for m in squad.members], ['shipping', 'rabbitmq']) squad = self.microtosca.get_group('team2') self.assertEqual(squad.name, "team2") self.assertCountEqual([m.name for m in squad.members], ['order', 'order_db'])
def setUpClass(self): file = 'data/tests/test_sniffer_ebsi.yml' loader = YMLImporter() self.micro_model = loader.Import(file) self.ebsiSniffer = EndpointBasedServiceInteractionSmellSniffer()
def setUpClass(self): file = 'data/examples/hello-world/helloworld.yml' self.importer = YMLImporter() self.microtosca = self.importer.Import(file)
path_to_json= os.path.join(os.path.dirname(os.path.realpath(__file__)), json_ex ) #********************************** # VALIDATOR: Open stack # ********************************* tosca = ToscaTemplate(path_to_yml, None) if tosca.version: print("\nversion: " + tosca.version) #******************************** # LOADER: yml, json #******************************* # Yml loader loader = YMLImporter() micro_model = loader.Import(path_to_yml) #JSON loader # loader = JSONImporter() # micro_model = loader.Import(path_to_json) #******************************** # MICRO MODEL #******************************* # add node # s = Service(name="new") # s.add_deployment_time(micro_model["order"]) # s.add_run_time(micro_model["order_db"]) # micro_model.add_node(s)
def setUpClass(self): file = 'data/tests/test_sniffer_wbsi.yml' loader = YMLImporter() self.micro_model = loader.Import(file) self.wbsiSniffer = WobblyServiceInteractionSmellSniffer()
def setUpClass(self): file = 'data/tests/test_nodes.yml' loader = YMLImporter() self.microtosca = loader.Import(file) self.tranformer = YMLExporter()