def test_transac_container_properties(self): SessionService.open_session("test_transac_container_properties") container = Container(name="test_transac_container_properties", gate_uri="ssh://my_host/docker/test_transac_container_properties", primary_admin_gate_name="container name space (pid)", company="Docker", product="Docker", c_type="container") container.save() SessionService.commit() container2 = ContainerService.find_container(cid=container.id) self.assertEqual(container2.properties.__len__(), 0) container.add_property(('int_prop', 10), sync=False) container.add_property(('long_prop', 10000000), sync=False) container.add_property(('double_prop', 3.1414), sync=False) container.add_property(('boolean_prop', True), sync=False) container.add_property(('string_prop', "value"), sync=False) datacenter = {"dc": "Sagittarius", "gpsLng": 2.251088, "address": "2 rue Baudin", "gpsLat": 48.895345, "town": "Courbevoie", "country": "France"} container.add_property(('map_prop_datacenter', datacenter), sync=False) container.add_property(('array_prop', [1, 2, 3, 4, 5]), sync=False) self.assertEqual(container.properties.__len__(), 0) container.save() SessionService.commit() container2 = ContainerService.find_container(cid=container.id) self.assertTrue('boolean_prop' in container2.properties) self.assertTrue('double_prop' in container2.properties) self.assertTrue('int_prop' in container2.properties) self.assertTrue('long_prop' in container2.properties) self.assertTrue('map_prop_datacenter' in container2.properties) self.assertTrue('string_prop' in container2.properties) self.assertTrue('array_prop' in container2.properties) container.remove() SessionService.commit() SessionService.close_session()
def test_transac_replace_container_gate_1(self): SessionService.open_session("test_transac_replace_container_gate_1") container2 = Container(name="test_transac_replace_container_gate_1", gate_uri="ssh://my_host/docker/test_transac_replace_container_gate_1_container2", primary_admin_gate_name="container name space (pid)", company="Docker", product="Docker", c_type="container") container2.save() gate = Gate(name="sshd", url="ssh://test_transac_replace_container_gate_1_ugly_docker_admin_endpoint", is_primary_admin=False, container=container2) prim_adm_ep = EndpointService.find_endpoint( url="ssh://my_host/docker/test_transac_replace_container_gate_1_container2" ) previous_prim_gate = GateService.find_gate( nid=prim_adm_ep.parent_node_id ) gate.save() SessionService.commit() self.assertIsNotNone(gate.id) self.assertNotEqual(container2.primary_admin_gate_id, gate.id) self.assertTrue(gate.id in container2.nodes_id) self.assertTrue(gate.id in container2.gates_id) gate.url = "ssh://my_host/docker/test_transac_replace_container_gate_1_container2" gate.is_primary_admin = True gate.save() previous_prim_gate.remove() SessionService.commit() self.assertEqual(container2.primary_admin_gate_id, gate.id) self.assertEqual(container2.gate_uri, gate.url) container2.remove() SessionService.commit() SessionService.close_session()
def stop(self): if self.ready: if InjectorCachedGearService.get_gears_cache_size() == 0 and \ InjectorCachedComponentService.get_components_cache_size() == 0: self.injector_ui_procos_entity.remove() self.injector_service.stop() SessionService.close_session() self.ready = False
def test_session(self): args = {'type': 'REST', 'base_url': 'http://localhost:6969/ariane/', 'user': '******', 'password': '******'} MappingService(args) session_id = SessionService.open_session("test") thread_id = threading.current_thread().ident self.assertIn(thread_id, SessionService.session_registry) self.assertEqual(SessionService.session_registry[thread_id], session_id) SessionService.close_session() self.assertNotIn(thread_id, SessionService.session_registry)
def test_transac_get_transports(self): SessionService.open_session("test") transport = Transport(name="test_transac_get_transports") transport.save() SessionService.commit() self.assertTrue(transport in TransportService.get_transports()) transport.remove() SessionService.commit() self.assertFalse(transport in TransportService.get_transports()) SessionService.commit() SessionService.close_session()
def test_transac_get_links(self): SessionService.open_session("test_transac_get_links") link = Link(source_endpoint_id=self.endpoint1.id, target_endpoint_id=self.endpoint2.id, transport_id=self.transport.id) link.save() SessionService.commit() self.assertTrue(link in LinkService.get_links()) link.remove() SessionService.commit() self.assertFalse(link in LinkService.get_links()) SessionService.commit() SessionService.close_session()
def test_transac_node_properties(self): SessionService.open_session("test_transac_node_properties") gate = Gate(name="sshd", url="ssh://test_transac_node_properties_ugly_docker_admin_endpoint", is_primary_admin=False, container=self.container1) gate.add_property(('int_prop', 10), sync=False) gate.add_property(('long_prop', 10000000), sync=False) gate.add_property(('double_prop', 3.1414), sync=False) gate.add_property(('boolean_prop', True), sync=False) gate.add_property(('string_prop', "value"), sync=False) datacenter = {"dc": "Sagittarius", "gpsLng": 2.251088, "address": "2 rue Baudin", "gpsLat": 48.895345, "town": "Courbevoie", "country": "France"} gate.add_property(('map_prop_datacenter', datacenter), sync=False) gate.add_property(('array_prop', [1, 2, 3, 4, 5]), sync=False) self.assertIsNone(gate.properties) gate.save() SessionService.commit() self.assertTrue('boolean_prop' in gate.properties) self.assertTrue('double_prop' in gate.properties) self.assertTrue('int_prop' in gate.properties) self.assertTrue('long_prop' in gate.properties) self.assertTrue('map_prop_datacenter' in gate.properties) self.assertTrue('string_prop' in gate.properties) self.assertTrue('array_prop' in gate.properties) gate.del_property('int_prop', sync=False) gate.del_property('long_prop', sync=False) gate.del_property('double_prop', sync=False) gate.del_property('boolean_prop', sync=False) gate.del_property('string_prop', sync=False) gate.del_property('map_prop_datacenter', sync=False) gate.del_property('array_prop', sync=False) self.assertTrue('boolean_prop' in gate.properties) self.assertTrue('double_prop' in gate.properties) self.assertTrue('int_prop' in gate.properties) self.assertTrue('long_prop' in gate.properties) self.assertTrue('map_prop_datacenter' in gate.properties) self.assertTrue('string_prop' in gate.properties) self.assertTrue('array_prop' in gate.properties) gate.save() SessionService.commit() self.assertFalse(gate.properties is not None and 'boolean_prop' in gate.properties) self.assertFalse(gate.properties is not None and 'double_prop' in gate.properties) self.assertFalse(gate.properties is not None and 'int_prop' in gate.properties) self.assertFalse(gate.properties is not None and 'long_prop' in gate.properties) self.assertFalse(gate.properties is not None and 'map_prop_datacenter' in gate.properties) self.assertFalse(gate.properties is not None and 'string_prop' in gate.properties) self.assertFalse(gate.properties is not None and 'array_prop' in gate.properties) gate.remove() SessionService.commit() SessionService.close_session()
def test_transac_create_remove_node_basic(self): SessionService.open_session("test_transac_create_remove_node_basic") node = Node(name="mysqld", container_id=self.container1.id) node.save() SessionService.commit() self.assertIsNotNone(node.id) self.container1.sync() self.assertTrue(node.id in self.container1.nodes_id) self.assertIsNone(node.remove()) self.container1.sync() SessionService.commit() self.assertFalse(node.id in self.container1.nodes_id) SessionService.commit() SessionService.close_session()
def test_transac_get_endpoints(self): SessionService.open_session("test_transac_get_endpoints") endpoint = Endpoint(url="mysql://test_transac_get_endpoints_container1:4385", parent_node_id=self.node1.id) endpoint.save() self.assertTrue(endpoint in EndpointService.find_endpoint(selector="endpointURL =~ 'mysql:.*'")) self.assertTrue(endpoint in EndpointService.find_endpoint(selector="endpointURL =~ 'mysql:.*'", cid=self.container1.id)) self.assertTrue(endpoint in EndpointService.find_endpoint(selector="endpointURL =~ 'mysql:.*'", nid=self.node1.id)) self.assertTrue(endpoint in EndpointService.get_endpoints()) SessionService.commit() self.assertTrue(endpoint in EndpointService.find_endpoint(selector="endpointURL =~ 'mysql:.*'")) self.assertTrue(endpoint in EndpointService.find_endpoint(selector="endpointURL =~ 'mysql:.*'", cid=self.container1.id)) self.assertTrue(endpoint in EndpointService.find_endpoint(selector="endpointURL =~ 'mysql:.*'", nid=self.node1.id)) self.assertTrue(endpoint in EndpointService.get_endpoints()) endpoint.remove() self.assertFalse(EndpointService.find_endpoint(selector="endpointURL =~ 'mysql:.*'") is not None and endpoint in EndpointService.find_endpoint(selector="endpointURL =~ 'mysql:.*'")) self.assertFalse(EndpointService.find_endpoint(selector="endpointURL =~ 'mysql:.*'") is not None and endpoint in EndpointService.find_endpoint(selector="endpointURL =~ 'mysql:.*'", cid=self.container1.id)) self.assertFalse(EndpointService.find_endpoint(selector="endpointURL =~ 'mysql:.*'") is not None and endpoint in EndpointService.find_endpoint(selector="endpointURL =~ 'mysql:.*'", nid=self.node1.id)) self.assertFalse(endpoint in EndpointService.get_endpoints()) SessionService.commit() self.assertFalse(endpoint in EndpointService.get_endpoints()) SessionService.close_session()
def test_transac_endpoint_properties(self): SessionService.open_session("test_transac_endpoint_properties") endpoint = Endpoint(url="mysql://test_transac_endpoint_properties_container1:4385", parent_node_id=self.node1.id) endpoint.add_property(('int_prop', 10), sync=False) endpoint.add_property(('long_prop', 10000000), sync=False) endpoint.add_property(('double_prop', 3.1414), sync=False) endpoint.add_property(('boolean_prop', True), sync=False) endpoint.add_property(('string_prop', "value"), sync=False) datacenter = {"dc": "Sagittarius", "gpsLng": 2.251088, "address": "2 rue Baudin", "gpsLat": 48.895345, "town": "Courbevoie", "country": "France"} endpoint.add_property(('map_prop_datacenter', datacenter), sync=False) endpoint.add_property(('array_prop', [1, 2, 3, 4, 5]), sync=False) self.assertIsNone(endpoint.properties) endpoint.save() SessionService.commit() self.assertTrue('boolean_prop' in endpoint.properties) self.assertTrue('double_prop' in endpoint.properties) self.assertTrue('int_prop' in endpoint.properties) self.assertTrue('long_prop' in endpoint.properties) self.assertTrue('map_prop_datacenter' in endpoint.properties) self.assertTrue('string_prop' in endpoint.properties) self.assertTrue('array_prop' in endpoint.properties) endpoint.del_property('int_prop', sync=False) endpoint.del_property('long_prop', sync=False) endpoint.del_property('double_prop', sync=False) endpoint.del_property('boolean_prop', sync=False) endpoint.del_property('string_prop', sync=False) endpoint.del_property('map_prop_datacenter', sync=False) endpoint.del_property('array_prop', sync=False) self.assertTrue('boolean_prop' in endpoint.properties) self.assertTrue('double_prop' in endpoint.properties) self.assertTrue('int_prop' in endpoint.properties) self.assertTrue('long_prop' in endpoint.properties) self.assertTrue('map_prop_datacenter' in endpoint.properties) self.assertTrue('string_prop' in endpoint.properties) self.assertTrue('array_prop' in endpoint.properties) endpoint.save() SessionService.commit() self.assertFalse(endpoint.properties is not None and 'boolean_prop' in endpoint.properties) self.assertFalse(endpoint.properties is not None and 'double_prop' in endpoint.properties) self.assertFalse(endpoint.properties is not None and 'int_prop' in endpoint.properties) self.assertFalse(endpoint.properties is not None and 'long_prop' in endpoint.properties) self.assertFalse(endpoint.properties is not None and 'map_prop_datacenter' in endpoint.properties) self.assertFalse(endpoint.properties is not None and 'string_prop' in endpoint.properties) self.assertFalse(endpoint.properties is not None and 'array_prop' in endpoint.properties) endpoint.remove() SessionService.commit() SessionService.close_session()
def test_transac_node_properties(self): SessionService.open_session("test_transac_node_properties") node = Node(name="mysqld1", container=self.container1) node.add_property(('int_prop', 10), sync=False) node.add_property(('long_prop', 10000000), sync=False) node.add_property(('double_prop', 3.1414), sync=False) node.add_property(('boolean_prop', True), sync=False) node.add_property(('string_prop', "value"), sync=False) datacenter = {"dc": "Sagittarius", "gpsLng": 2.251088, "address": "2 rue Baudin", "gpsLat": 48.895345, "town": "Courbevoie", "country": "France"} node.add_property(('map_prop_datacenter', datacenter), sync=False) node.add_property(('array_prop', [1, 2, 3, 4, 5]), sync=False) self.assertIsNone(node.properties) node.save() SessionService.commit() self.assertTrue('boolean_prop' in node.properties) self.assertTrue('double_prop' in node.properties) self.assertTrue('int_prop' in node.properties) self.assertTrue('long_prop' in node.properties) self.assertTrue('map_prop_datacenter' in node.properties) self.assertTrue('string_prop' in node.properties) self.assertTrue('array_prop' in node.properties) node.del_property('int_prop', sync=False) node.del_property('long_prop', sync=False) node.del_property('double_prop', sync=False) node.del_property('boolean_prop', sync=False) node.del_property('string_prop', sync=False) node.del_property('map_prop_datacenter', sync=False) node.del_property('array_prop', sync=False) self.assertTrue('boolean_prop' in node.properties) self.assertTrue('double_prop' in node.properties) self.assertTrue('int_prop' in node.properties) self.assertTrue('long_prop' in node.properties) self.assertTrue('map_prop_datacenter' in node.properties) self.assertTrue('string_prop' in node.properties) self.assertTrue('array_prop' in node.properties) node.save() SessionService.commit() self.assertFalse(node.properties is not None and 'boolean_prop' in node.properties) self.assertFalse(node.properties is not None and 'double_prop' in node.properties) self.assertFalse(node.properties is not None and 'int_prop' in node.properties) self.assertFalse(node.properties is not None and 'long_prop' in node.properties) self.assertFalse(node.properties is not None and 'map_prop_datacenter' in node.properties) self.assertFalse(node.properties is not None and 'string_prop' in node.properties) self.assertFalse(node.properties is not None and 'array_prop' in node.properties) node.remove() SessionService.commit() SessionService.close_session()
def test_transac_create_remove_transport(self): SessionService.open_session("test") transport = Transport(name="test_transac_create_remove_transport") transport.save() SessionService.commit() self.assertIsNotNone(transport.id) self.assertIsNone(transport.remove()) SessionService.commit() SessionService.close_session()
def test_session_rollback(self): args = {'type': 'REST', 'base_url': 'http://localhost:6969/ariane/', 'user': '******', 'password': '******'} MappingService(args) session_id = SessionService.open_session("test") thread_id = threading.current_thread().ident self.assertIn(thread_id, SessionService.session_registry) self.assertEqual(SessionService.session_registry[thread_id], session_id) init_cluster_count = ClusterService.get_clusters().__len__() new_cluster = Cluster(name="test_cluster") new_cluster.save() SessionService.rollback() SessionService.close_session() self.assertNotIn(thread_id, SessionService.session_registry) self.assertEqual(ClusterService.get_clusters().__len__(), init_cluster_count)
def test_transac_create_remove_link_basic(self): SessionService.open_session("test_transac_create_remove_link_basic") link = Link(source_endpoint_id=self.endpoint1.id, target_endpoint_id=self.endpoint2.id, transport_id=self.transport.id) link.save() SessionService.commit() self.assertIsNotNone(link.id) self.assertIsNone(link.remove()) SessionService.commit() SessionService.close_session()
def test_transac_get_clusters(self): SessionService.open_session("test_transac_get_clusters") new_cluster = Cluster(name="test_transac_get_clusters") new_cluster.save() self.assertTrue(new_cluster in ClusterService.get_clusters()) SessionService.commit() self.assertTrue(new_cluster in ClusterService.get_clusters()) new_cluster.remove() self.assertTrue(new_cluster not in ClusterService.get_clusters()) SessionService.commit() self.assertTrue(new_cluster not in ClusterService.get_clusters()) SessionService.close_session()
def test_transac_create_remove_endpoint_parent_node(self): SessionService.open_session("test_transac_create_remove_endpoint_parent_node") container2 = Container(name="test_transac_create_remove_endpoint_parent_node_container2", gate_uri="ssh://my_host/docker/test_container2", primary_admin_gate_name="container name space (pid)", company="Docker", product="Docker", c_type="container") node2 = Node(name="mysqld", container=container2) node2.save() SessionService.commit() endpoint2 = Endpoint(url="mysql://test_transac_create_remove_endpoint_parent_node_container1:4385", parent_node=node2) endpoint2.save() SessionService.commit() self.assertIsNotNone(endpoint2.id) self.assertTrue(endpoint2.id in node2.endpoints_id) self.assertIsNone(endpoint2.remove()) self.assertFalse(endpoint2.id in node2.endpoints_id) node2.remove() container2.remove() SessionService.commit() SessionService.close_session()
def test_transac_create_remove_node_parent_node(self): SessionService.open_session("test_transac_create_remove_node_parent_node") container2 = Container(name="test_transac_create_remove_node_parent_node_container2", gate_uri="ssh://my_host/docker/test_transac_create_remove_node_parent_node_container2", primary_admin_gate_name="container name space (pid)", company="Docker", product="Docker", c_type="container") node_mysql = Node(name="mysqld", container=container2) node_db = Node(name="my_db", container=container2, parent_node=node_mysql) node_db.save() SessionService.commit() self.assertIsNotNone(node_db.id) self.assertIsNotNone(node_mysql.id) self.assertTrue(node_db.id in node_mysql.child_nodes_id) self.assertTrue(node_db.parent_node_id == node_mysql.id) node_db.remove() SessionService.commit() self.assertFalse(node_db.id in node_mysql.child_nodes_id) node_mysql.remove() container2.remove() SessionService.commit() SessionService.close_session()
def test_transac_create_remove_endpoint_basic(self): SessionService.open_session("test_transac_create_remove_endpoint_basic") endpoint = Endpoint(url="mysql://test_transac_create_remove_endpoint_basic_container1:4385", parent_node_id=self.node1.id) endpoint.save() SessionService.commit() self.assertIsNotNone(endpoint.id) self.node1.sync() self.assertTrue(endpoint.id in self.node1.endpoints_id) self.assertIsNone(endpoint.remove()) self.node1.sync() self.assertFalse(endpoint.id in self.node1.endpoints_id) SessionService.commit() SessionService.close_session()
def test_transac_create_remove_node_parent_container_2(self): SessionService.open_session("test_transac_create_remove_node_parent_container_2") container2 = Container(name="test_transac_create_remove_node_parent_container_2_container2", gate_uri="ssh://my_host/docker/test_transac_create_remove_node_parent_container_2_container2", primary_admin_gate_name="container name space (pid)", company="Docker", product="Docker", c_type="container") container2.save() SessionService.commit() gate = Gate(name="sshd", url="ssh://test_transac_create_remove_node_parent_container_2_ugly_docker_admin_endpoint2", is_primary_admin=False, container=container2) gate.save() SessionService.commit() self.assertIsNotNone(gate.id) self.assertTrue(gate.id in container2.nodes_id) self.assertTrue(gate.id in container2.gates_id) self.assertIsNone(gate.remove()) self.assertFalse(gate.id in container2.nodes_id) self.assertFalse(gate.id in container2.gates_id) container2.remove() SessionService.commit() SessionService.close_session()
def test_transac_get_clusters(self): args = {'type': DriverFactory.DRIVER_REST, 'base_url': 'http://localhost:6969/ariane/', 'user': '******', 'password': '******'} MappingService(args) SessionService.open_session("test") new_cluster = Cluster(name="test_transac_get_clusters") new_cluster.save() self.assertTrue(new_cluster in ClusterService.get_clusters()) SessionService.commit() self.assertTrue(new_cluster in ClusterService.get_clusters()) new_cluster.remove() self.assertTrue(new_cluster not in ClusterService.get_clusters()) SessionService.commit() self.assertTrue(new_cluster not in ClusterService.get_clusters()) SessionService.close_session()
def test_transac_get_containers(self): SessionService.open_session("test_transac_get_containers") new_container = Container(name="test_transac_get_containers", gate_uri="ssh://my_host/docker/test_transac_get_containers", primary_admin_gate_name="container name space (pid)", company="Docker", product="Docker", c_type="container") new_container.save() self.assertTrue(new_container in ContainerService.get_containers()) SessionService.commit() self.assertTrue(new_container in ContainerService.get_containers()) new_container.remove() self.assertFalse(new_container in ContainerService.get_containers()) SessionService.commit() self.assertFalse(new_container in ContainerService.get_containers()) SessionService.close_session()
def test_transac_create_remove_gate_basic(self): SessionService.open_session("test") gate = Gate(name="sshd", url="ssh://test_transac_create_remove_gate_basic_ugly_docker_admin_endpoint", is_primary_admin=True, container_id=self.container1.id) gate.save() SessionService.commit() self.assertIsNotNone(gate.id) self.container1.sync() self.assertTrue(gate.id in self.container1.nodes_id) self.assertTrue(gate.id in self.container1.gates_id) self.assertIsNotNone(gate.remove()) self.container1.sync() self.assertTrue(gate.id in self.container1.nodes_id) self.assertTrue(gate.id in self.container1.gates_id) SessionService.commit() SessionService.close_session()
def test_transac_change_container_gate_3(self): SessionService.open_session("test_transac_change_container_gate_3") container2 = Container(name="test_transac_change_container_gate_3", gate_uri="ssh://my_host/docker/test_transac_change_container_gate_3_container2", primary_admin_gate_name="container name space (pid)", company="Docker", product="Docker", c_type="container") gate = Gate(name="sshd", url="ssh://test_transac_change_container_gate_3_ugly_docker_admin_endpoint", is_primary_admin=False, container=container2) gate.save() SessionService.commit() self.assertIsNotNone(gate.id) self.assertNotEqual(container2.primary_admin_gate_id, gate.id) self.assertTrue(gate.id in container2.nodes_id) self.assertTrue(gate.id in container2.gates_id) gate.url = "ssh://test_transac_change_container_gate_3_another_ugly_docker_admin_endpoint" gate.is_primary_admin = True gate.save() SessionService.commit() self.assertEqual(container2.primary_admin_gate_id, gate.id) self.assertEqual(container2.gate_uri, gate.url) container2.remove() SessionService.commit() SessionService.close_session()
def test_transac_get_containers(self): args = {'type': 'REST', 'base_url': 'http://localhost:6969/ariane/', 'user': '******', 'password': '******'} MappingService(args) SessionService.open_session("test") new_container = Container(name="test_transac_get_containers", gate_uri="ssh://my_host/docker/test_transac_get_containers", primary_admin_gate_name="container name space (pid)", company="Docker", product="Docker", c_type="container") new_container.save() self.assertTrue(new_container in ContainerService.get_containers()) SessionService.commit() self.assertTrue(new_container in ContainerService.get_containers()) new_container.remove() self.assertFalse(new_container in ContainerService.get_containers()) SessionService.commit() self.assertFalse(new_container in ContainerService.get_containers()) SessionService.close_session()
def test_transac_cluster_link_to_container(self): SessionService.open_session("test_transac_cluster_link_to_container") cluster = Cluster(name="test_transac_cluster_link_to_container") container = Container(name="test_transac_cluster_link_to_container_container", gate_uri="ssh://my_host/docker/test_transac_cluster_link_to_container_container", primary_admin_gate_name="container name space (pid)", company="Docker", product="Docker", c_type="container") cluster.add_container(container, False) self.assertTrue(container in cluster.containers_2_add) self.assertIsNone(cluster.containers_id) self.assertIsNone(container.cluster_id) cluster.save() self.assertTrue(cluster in ClusterService.get_clusters()) self.assertTrue(container in ContainerService.get_containers()) SessionService.commit() self.assertTrue(cluster in ClusterService.get_clusters()) self.assertTrue(container in ContainerService.get_containers()) self.assertFalse(container in cluster.containers_2_add) self.assertTrue(container.id in cluster.containers_id) self.assertTrue(container.cluster_id == cluster.id) cluster.del_container(container, False) self.assertTrue(container in cluster.containers_2_rm) self.assertTrue(container.id in cluster.containers_id) self.assertTrue(container.cluster_id == cluster.id) cluster.save() SessionService.commit() self.assertFalse(container in cluster.containers_2_rm) self.assertTrue(cluster.containers_id.__len__() == 0) self.assertIsNone(container.cluster_id) cluster.add_container(container) SessionService.commit() self.assertTrue(container.id in cluster.containers_id) self.assertTrue(container.cluster_id == cluster.id) cluster.del_container(container) SessionService.commit() self.assertTrue(cluster.containers_id.__len__() == 0) self.assertIsNone(container.cluster_id) container.remove() cluster.remove() self.assertFalse(cluster in ClusterService.get_clusters()) self.assertFalse(container in ContainerService.get_containers()) SessionService.commit() self.assertFalse(cluster in ClusterService.get_clusters()) self.assertFalse(container in ContainerService.get_containers()) SessionService.close_session()
def __init__(self, docker_config): self.ready = False rest_args = { 'type': 'REST', 'base_url': docker_config.rest_base_url, 'user': docker_config.rest_user, 'password': docker_config.rest_password } client_properties = { 'product': 'Ariane', 'information': 'Ariane Plugin Docker - Map your Docker containers interaction and more ...', 'ariane.pgurl': 'ssh://' + socket.gethostname() + "/$[/usr/local/bin/adocker {start|stop}]", 'ariane.osi': socket.gethostname(), 'ariane.otm': 'AROps', 'ariane.app': 'Ariane Plugin Docker', 'ariane.cmp': 'echinopsii', 'ariane.pid': os.getpid() } nats_args = { 'type': DriverFactory.DRIVER_NATS, 'user': docker_config.nats_user, 'password': docker_config.nats_password, 'host': docker_config.nats_host, 'port': docker_config.nats_port, 'client_properties': client_properties } rbmq_args = { 'type': 'RBMQ', 'user': docker_config.rbmq_user, 'password': docker_config.rbmq_password, 'host': docker_config.rbmq_host, 'port': docker_config.rbmq_port, 'vhost': docker_config.rbmq_vhost, 'client_properties': client_properties } self.gears_registry_cache_id = 'ariane.community.plugin.docker.gears.cache' docker_gears_registry_conf = { 'registry.name': 'Ariane Docker plugin gears registry', 'registry.cache.id': self.gears_registry_cache_id, 'registry.cache.name': 'Ariane Docker plugin gears cache', 'cache.mgr.name': 'ARIANE_PLUGIN_DOCKER_GEARS_CACHE_MGR' } self.components_registry_cache_id = 'ariane.community.plugin.docker.components.cache' docker_components_registry_conf = { 'registry.name': 'Ariane Docker plugin components registry', 'registry.cache.id': self.components_registry_cache_id, 'registry.cache.name': 'Ariane Docker plugin components cache', 'cache.mgr.name': 'ARIANE_PLUGIN_DOCKER_COMPONENTS_CACHE_MGR' } no_error = True DirectoryService(rest_args) # Test Directory Service try: LocationService.get_locations() except Exception as e: LOGGER.error("Problem while initializing Ariane directory service.") LOGGER.error(e.__str__()) no_error = False if no_error: if docker_config.mapping_driver_type == DriverFactory.DRIVER_RBMQ: LOGGER.info("Starting Mapping Service through RabbitMQ") MappingService(rbmq_args) elif docker_config.mapping_driver_type == DriverFactory.DRIVER_NATS: LOGGER.info("Starting Mapping Service through NATS") MappingService(nats_args) else: LOGGER.info("Starting Mapping Service through REST") MappingService(rest_args) # Open session and Test Mapping Service try: SessionService.open_session("ArianeDocker_test" + socket.gethostname()) SessionService.close_session() except Exception as e: LOGGER.error("Problem while initializing Ariane mapping service.") LOGGER.error(e.__str__()) no_error = False if no_error: try: if docker_config.injector_driver_type == DriverFactory.DRIVER_RBMQ: LOGGER.info("Starting Injector Service through RabbitMQ") self.injector_service = InjectorService( driver_args=rbmq_args, gears_registry_args=docker_gears_registry_conf, components_registry_args=docker_components_registry_conf ) elif docker_config.injector_driver_type == DriverFactory.DRIVER_NATS: LOGGER.info("Starting Injector Service through NATS") self.injector_service = InjectorService( driver_args=nats_args, gears_registry_args=docker_gears_registry_conf, components_registry_args=docker_components_registry_conf ) except Exception as e: LOGGER.error("Problem while initializing Ariane injector service.") LOGGER.error(e.__str__()) no_error = False if no_error: # Register UI entity if needed (and so test) self.injector_ui_mapping_entity = InjectorUITreeService.find_ui_tree_entity('mappingDir') if self.injector_ui_mapping_entity is None: self.injector_ui_mapping_entity = InjectorUITreeEntity(uitid="mappingDir", value="Mapping", uitype=InjectorUITreeEntity.entity_dir_type) self.injector_ui_mapping_entity.save() self.injector_ui_system_entity = InjectorUITreeEntity(uitid="systemDir", value="System", uitype=InjectorUITreeEntity.entity_dir_type, context_address="", description="", parent_id=self.injector_ui_mapping_entity.id, display_roles=["sysreviewer"], display_permissions=["injMapSysDocker:display"]) self.injector_ui_system_entity.save() self.injector_ui_procos_entity = InjectorUITreeEntity(uitid="docker", value="Docker", uitype=InjectorUITreeEntity.entity_leaf_type, context_address= "/ariane/views/injectors/external.jsf?id=docker", description="Docker injector", icon="icon-docker-injector", parent_id=self.injector_ui_system_entity.id, display_roles=["sysadmin", "sysreviewer"], display_permissions=["injMapSysDocker:display"], other_actions_roles={"action": ["sysadmin"]}, other_actions_perms={"action": ["injMapSysDocker:action"]}, remote_injector_tree_entity_gears_cache_id= self.gears_registry_cache_id, remote_injector_tree_entity_components_cache_id= self.components_registry_cache_id) self.injector_ui_procos_entity.save() self.ready = True
def test_transac_twin_nodes_link(self): SessionService.open_session("test_transac_twin_nodes_link") container2 = Container(name="test_transac_twin_nodes_link_container2", gate_uri="ssh://my_host/docker/test_transac_twin_nodes_link_container2", primary_admin_gate_name="container name space (pid)", company="Docker", product="Docker", c_type="container") node_mysql1 = Node(name="mysqld1", container=self.container1) node_mysql2 = Node(name="mysqld2", container=container2) node_mysql1.add_twin_node(node_mysql2, sync=False) self.assertTrue(node_mysql2 in node_mysql1.twin_nodes_2_add) node_mysql1.save() SessionService.commit() self.assertFalse(node_mysql2 in node_mysql1.twin_nodes_2_add) self.assertTrue(node_mysql2.id in node_mysql1.twin_nodes_id) self.assertTrue(node_mysql1.id in node_mysql2.twin_nodes_id) node_mysql2.del_twin_node(node_mysql1, sync=False) SessionService.commit() self.assertTrue(node_mysql1 in node_mysql2.twin_nodes_2_rm) self.assertTrue(node_mysql2.id in node_mysql1.twin_nodes_id) self.assertTrue(node_mysql1.id in node_mysql2.twin_nodes_id) node_mysql2.save() SessionService.commit() self.assertFalse(node_mysql1 in node_mysql2.twin_nodes_2_rm) self.assertFalse(node_mysql2.id in node_mysql1.twin_nodes_id) self.assertFalse(node_mysql1.id in node_mysql2.twin_nodes_id) node_mysql1.add_twin_node(node_mysql2) SessionService.commit() self.assertTrue(node_mysql2.id in node_mysql1.twin_nodes_id) self.assertTrue(node_mysql1.id in node_mysql2.twin_nodes_id) node_mysql2.del_twin_node(node_mysql1) SessionService.commit() self.assertFalse(node_mysql2.id in node_mysql1.twin_nodes_id) self.assertFalse(node_mysql1.id in node_mysql2.twin_nodes_id) node_mysql1.remove() node_mysql2.remove() container2.remove() SessionService.commit() SessionService.close_session()
def test_transac_twin_nodes_link(self): SessionService.open_session("test_transac_twin_nodes_link") container2 = Container(name="test_transac_twin_nodes_link_container2", gate_uri="ssh://my_host/docker/test_transac_twin_nodes_link_container2", primary_admin_gate_name="container name space (pid)", company="Docker", product="Docker", c_type="container") gate1 = Gate(name="sshd", url="ssh://test_transac_twin_nodes_link_ugly_docker_admin_endpoint", is_primary_admin=False, container=self.container1) gate2 = Gate(name="sshd", url="ssh://test_transac_twin_nodes_link_ugly_docker_admin_endpoint2", is_primary_admin=False, container=container2) gate1.add_twin_node(gate2, sync=False) self.assertTrue(gate2 in gate1.twin_nodes_2_add) gate1.save() SessionService.commit() self.assertFalse(gate2 in gate1.twin_nodes_2_add) self.assertTrue(gate2.id in gate1.twin_nodes_id) self.assertTrue(gate1.id in gate2.twin_nodes_id) gate2.del_twin_node(gate1, sync=False) self.assertTrue(gate1 in gate2.twin_nodes_2_rm) self.assertTrue(gate2.id in gate1.twin_nodes_id) self.assertTrue(gate1.id in gate2.twin_nodes_id) gate2.save() SessionService.commit() self.assertFalse(gate1 in gate2.twin_nodes_2_rm) self.assertFalse(gate2.id in gate1.twin_nodes_id) self.assertFalse(gate1.id in gate2.twin_nodes_id) gate1.add_twin_node(gate2) SessionService.commit() self.assertTrue(gate2.id in gate1.twin_nodes_id) self.assertTrue(gate1.id in gate2.twin_nodes_id) gate2.del_twin_node(gate1) SessionService.commit() self.assertFalse(gate2.id in gate1.twin_nodes_id) self.assertFalse(gate1.id in gate2.twin_nodes_id) gate1.remove() gate2.remove() container2.remove() SessionService.commit() SessionService.close_session()
def test_transac_child_containers(self): SessionService.open_session("test_transac_child_containers") container = Container(name="test_transac_child_containers", gate_uri="ssh://my_host/docker/test_transac_child_containers", primary_admin_gate_name="container name space (pid)", company="Docker", product="Docker", c_type="container") container.save() SessionService.commit() container2 = ContainerService.find_container(cid=container.id) self.assertTrue(container2.child_containers_id.__len__() == 0) child_container = Container(name="containerized_mysql", gate_uri="mysql://container_ip:mysql_port", primary_admin_gate_name="mysql cli sock", company="Oracle", product="MySQL", c_type="MySQL server") container.add_child_container(child_container, sync=False) self.assertTrue(child_container in container.child_containers_2_add) self.assertTrue(container.child_containers_id.__len__() == 0) self.assertIsNone(child_container.parent_container_id) container.save() container2 = ContainerService.find_container(cid=container.id) self.assertTrue(container2.child_containers_id.__len__() == 1) SessionService.commit() self.assertFalse(child_container in container.child_containers_2_add) self.assertTrue(child_container.id in container.child_containers_id) self.assertTrue(child_container.parent_container_id == container.id) container.del_child_container(child_container, sync=False) self.assertTrue(child_container in container.child_containers_2_rm) self.assertTrue(child_container.id in container.child_containers_id) self.assertTrue(child_container.parent_container_id == container.id) container.save() SessionService.commit() self.assertFalse(child_container in container.child_containers_2_rm) self.assertFalse(child_container.id in container.child_containers_id) self.assertIsNone(child_container.parent_container_id) child_container.remove() container.remove() SessionService.commit() SessionService.close_session()
def test_transac_twin_endpoints_link(self): SessionService.open_session("test_transac_twin_endpoints_link") container2 = Container(name="test_transac_twin_endpoints_link_container2", gate_uri="ssh://my_host/docker/test_transac_twin_endpoints_link_container2", primary_admin_gate_name="container name space (pid)", company="Docker", product="Docker", c_type="container") node2 = Node(name="mysqld2", container=container2) endpoint1 = Endpoint(url="mysql://test_transac_twin_endpoints_link_container1:4385", parent_node_id=self.node1.id) endpoint2 = Endpoint(url="mysql://test_transac_twin_endpoints_link_container2:4385", parent_node=node2) endpoint1.add_twin_endpoint(endpoint2, sync=False) self.assertTrue(endpoint2 in endpoint1.twin_endpoints_2_add) endpoint1.save() SessionService.commit() self.assertFalse(endpoint2 in endpoint1.twin_endpoints_2_add) self.assertTrue(endpoint2.id in endpoint1.twin_endpoints_id) self.assertTrue(endpoint1.id in endpoint2.twin_endpoints_id) endpoint2.del_twin_endpoint(endpoint1, sync=False) self.assertTrue(endpoint1 in endpoint2.twin_endpoints_2_rm) self.assertTrue(endpoint2.id in endpoint1.twin_endpoints_id) self.assertTrue(endpoint1.id in endpoint2.twin_endpoints_id) endpoint2.save() SessionService.commit() self.assertFalse(endpoint1 in endpoint2.twin_endpoints_2_rm) self.assertFalse(endpoint2.id in endpoint1.twin_endpoints_id) self.assertFalse(endpoint1.id in endpoint2.twin_endpoints_id) endpoint1.add_twin_endpoint(endpoint2) SessionService.commit() self.assertTrue(endpoint2.id in endpoint1.twin_endpoints_id) self.assertTrue(endpoint1.id in endpoint2.twin_endpoints_id) endpoint2.del_twin_endpoint(endpoint1) SessionService.commit() self.assertFalse(endpoint2.id in endpoint1.twin_endpoints_id) self.assertFalse(endpoint1.id in endpoint2.twin_endpoints_id) endpoint1.remove() endpoint2.remove() node2.remove() container2.remove() SessionService.commit() SessionService.close_session()