def test_dump_cluster(self): """ Dump cluster to json """ storage = self.get_cluster_storage() configurator = Configurator(Configuration().get_config(self.path)) nodes = {"compute": 2, "frontend": 1} cluster = Cluster("mycluster", "cluster_name", "hobbes", MagicMock(), MagicMock(), nodes, configurator) instance_id = "test-id" ip_public = "127.0.0.1" ip_private = "127.0.0.2" for node in cluster.get_all_nodes(): node.instance_id = instance_id node.ip_public = ip_public node.ip_private = ip_private storage.dump_cluster(cluster) dump = os.path.join(self.storage_path, "cluster_name.json") f = open(dump, "r") content = f.read() expected = """ {"compute_nodes": 2, "nodes": [{"instance_id": "test-id", "ip_public": "127.0.0.1", "type": "compute", "name": "compute001", "ip_private": "127.0.0.2"}, {"instance_id": "test-id", "ip_public": "127.0.0.1", "type": "compute", "name": "compute002", "ip_private": "127.0.0.2"}, {"instance_id": "test-id", "ip_public": "127.0.0.1", "type": "frontend", "name": "frontend001", "ip_private": "127.0.0.2"}], "frontend_nodes": 1, "name": "cluster_name", "template": "mycluster"}""" self.assertEqual(json.loads(content), json.loads(expected)) os.unlink(dump)