def test_add_edge(self): edge = Edge("myedge") edge.add_member(Service("first-edge")) edge.add_member(Service("second-edge")) self.microtosca.add_group(edge) self.assertEqual(len(edge.members), 2) self.assertIsInstance(self.microtosca.get_group("myedge"), Edge)
def test_get_subgraph_from_nodes(self): first = self.microtosca.add_node(Service("one")) second = self.microtosca.add_node(Service("two")) third = self.microtosca.add_node(Service("third")) team_name = "prova-subgraph" team = Team(team_name) team.add_member(first) self.microtosca.add_group(team) first = self.microtosca.add_node(first) second = self.microtosca.add_node(second) third = self.microtosca.add_node(third) first_to_second = first.add_interaction(second) third_to_second = third.add_interaction(second) subgraph = self.microtosca.get_subgraph([first, second, third]) self.assertEqual(len(list(subgraph.nodes)), 3) self.assertCountEqual(list(subgraph.nodes), [first, second, third]) self.assertIn(first_to_second, subgraph['one'].interactions) self.assertIn(first_to_second, subgraph['two'].incoming_interactions) self.assertEqual(2, len(subgraph['two'].incoming_interactions)) self.assertIn(first, subgraph.get_group(team_name).members) self.assertEqual(len(list(subgraph.get_group(team_name).members)), 1)
def test_add_get_team(self): team_name = "prova-team-add" first = self.microtosca.add_node(Service("first-team-add")) second = self.microtosca.add_node(Service("second-team-add")) team = Team(team_name) team.add_member(first) team.add_member(second) self.microtosca.add_group(team) self.assertIsInstance(self.microtosca.get_group(team_name), Team) self.assertEqual(self.microtosca.get_group(team_name), team)
def test_create_team(self): first = self.microtosca.add_node(Service("first-team")) second = self.microtosca.add_node(Service("second-team")) team = Team("prova-team") team.add_member(first) team.add_member(second) self.assertIn(first, team) self.assertIn(second, team) self.assertEqual(len(team.members), 2) self.assertEqual(team[first.name], first)
def test_remove_member(self): first = self.microtosca.add_node(Service("fteam")) second = self.microtosca.add_node(Service("steam")) team = Team("pteam") team.add_member(first) team.add_member(second) self.assertEqual(len(team.members), 2) team.remove_member(first) self.assertIn(first, self.microtosca.nodes) self.assertEqual(len(team.members), 1) self.assertNotIn(first, team.members) self.assertIn(second, team.members)
def test_delete_node_remove_interactions(self): first = self.microtosca.add_node(Service("first")) second = self.microtosca.add_node(Service("second")) third = self.microtosca.add_node(Service("third")) first_second = first.add_interaction(second) second_third = second.add_interaction(third) first_third = first.add_interaction(third) self.microtosca.delete_node(second) self.assertNotIn(second, self.microtosca.nodes) self.assertNotIn(first_second, second.incoming_interactions) self.assertNotIn(second_third, third.incoming_interactions) self.assertIn(first_third, third.incoming_interactions) self.assertIn(first_third, first.interactions)
def test_change_properties(self): s = self.microtosca.add_node(Service("s")) t = self.microtosca.add_node(Service("t")) link = self.microtosca.add_interaction(s, t) self.assertFalse(link.timeout) self.assertFalse(link.circuit_breaker) self.assertFalse(link.dynamic_discovery) link.set_timeout(True) link.set_circuit_breaker(True) link.set_dynamic_discovery(True) self.assertTrue(link.timeout) self.assertTrue(link.circuit_breaker) self.assertTrue(link.dynamic_discovery)
def test_add_service_node(self): s = Service(self.service_name) self.microtosca.add_node(s) self.assertTrue(s in self.microtosca) self.assertEqual(s, self.microtosca[self.service_name]) self.assertIsInstance(self.microtosca[self.service_name], Service) self.assertIn(s, self.microtosca.services)
def test_relink_incoming(self): s1 = self.microtosca.add_node(Service("s1")) s2 = self.microtosca.add_node(Service("s2")) s3 = self.microtosca.add_node(Service("s3")) current = self.microtosca.add_node(Service("current")) new = self.microtosca.add_node(Service("new_node")) s1.add_interaction(current) s2.add_interaction(current) s3.add_interaction(current) self.assertEqual(len(list(current.incoming_interactions)), 3) self.microtosca.relink_incoming(current, new) self.assertEqual(len(list(current.incoming_interactions)), 0) self.assertEqual(len(list(new.incoming_interactions)), 3) self.assertCountEqual( [rel.source for rel in new.incoming_interactions], [s1, s2, s3])
def setUpClass(self): self.name = "prova-model" self.microtosca = MicroToscaModel(self.name) self.service_name = "s1" self.database_name = "db1" self.messagerouter_name = "mr1" self.messagebroker_name = "mb1" self.microtosca.add_node(Service(self.service_name)) self.microtosca.add_node(Datastore(self.database_name)) self.microtosca.add_node(MessageBroker(self.messagebroker_name)) self.microtosca.add_node(MessageRouter(self.messagerouter_name))
def test_relink_incoming_with_discard(self): s1 = self.microtosca.add_node(Service("s1")) s2 = self.microtosca.add_node(Service("s2")) s3 = self.microtosca.add_node(Service("s3")) discard = self.microtosca.add_node(Service("discard")) current = self.microtosca.add_node(Service("cuurent")) new = self.microtosca.add_node(Service("new_node")) s1.add_interaction(current) s2.add_interaction(current) s3.add_interaction(current) discard.add_interaction(current) self.assertEqual(len(list(current.incoming_interactions)), 4) self.microtosca.relink_incoming(current, new, [discard]) self.assertEqual(len(list(new.incoming_interactions)), 3) self.assertCountEqual( [rel.source for rel in new.incoming_interactions], [s1, s2, s3]) self.assertNotIn(discard, [rel.source for rel in new.incoming_interactions]) self.assertEqual(len(list(current.incoming_interactions)), 1) self.assertCountEqual( [rel.source for rel in current.incoming_interactions], [discard]) self.assertNotIn(s1, [rel.source for rel in current.incoming_interactions]) self.assertNotIn(s2, [rel.source for rel in current.incoming_interactions]) self.assertNotIn(s3, [rel.source for rel in current.incoming_interactions])
def _add_relationship(self, source_name, target_name): s = self.microtosca.add_node(Service(source_name)) t = self.microtosca.add_node(Service(target_name)) return s.add_interaction(t)
def test_add_interaction(self): nodo1 = self.microtosca.add_node(Service("inter1")) nodo2 = self.microtosca.add_node(Service("inter2")) rel = self.microtosca.add_interaction(nodo1, nodo2) self.assertIn(rel, nodo1.interactions) self.assertIn(rel, nodo2.incoming_interactions)
def test_delete_node(self): nodo = self.microtosca.add_node(Service("prova")) self.assertIn(nodo, self.microtosca.services) self.microtosca.delete_node(nodo) self.assertNotIn(nodo, self.microtosca.services)