def test_load_from_storage(self):
     cloud_provider = MagicMock()
     cloud_provider.is_instance_running.return_value = True
     cloud_provider.get_ips.return_value = ('127.0.0.1', '127.0.0.1')
     setup_provider = MagicMock()
     storage = MagicMock()
     
     cluster = Cluster(config_cluster_name, config_cloud_name, cloud_provider, setup_provider, 1, 2, Configurator())
     cluster._storage = storage
     cluster.load_from_storage()
     
     storage.load_cluster.assert_called_once_with(cluster)
    def test_start(self):
        cloud_provider = MagicMock()
        cloud_provider.start_instance.return_value = u'test-id'
        cloud_provider.get_ips.return_value = ('127.0.0.1', '127.0.0.1')
        running_states = [True, True, True, True, True, False, False, False, False, False]
        def side_effect_is_instance_running(id):
            return running_states.pop()
        cloud_provider.is_instance_running.side_effect = side_effect_is_instance_running
        setup_provider = MagicMock()
        setup_provider.setup_cluster.return_value = True
        
        cluster = Cluster(config_cluster_name, config_cloud_name, cloud_provider, setup_provider, 1, 2, Configurator())
        cluster._storage = MagicMock()

        cluster.start()
        
        cluster._storage.dump_cluster.assert_called_once_with(cluster)

        for node in cluster.frontend_nodes + cluster.compute_nodes:
            assert node.instance_id == u'test-id'
            assert node.ip_public == '127.0.0.1'
            assert node.ip_private == '127.0.0.1'