[SPARK-2974] [SPARK-2975] Fix two bugs related to spark.local.dirs

This PR fixes two bugs related to `spark.local.dirs` and `SPARK_LOCAL_DIRS`, one where `Utils.getLocalDir()` might return an invalid directory (SPARK-2974) and another where the `SPARK_LOCAL_DIRS` override didn't affect the driver, which could cause problems when running tasks in local mode (SPARK-2975).

This patch fixes both issues: the new `Utils.getOrCreateLocalRootDirs(conf: SparkConf)` utility method manages the creation of local directories and handles the precedence among the different configuration options, so we should see the same behavior whether we're running in local mode or on a worker.

It's kind of a pain to mock out environment variables in tests (no easy way to mock System.getenv), so I added a `private[spark]` method to SparkConf for accessing environment variables (by default, it just delegates to System.getenv).  By subclassing SparkConf and overriding this method, we can mock out SPARK_LOCAL_DIRS in tests.

I also fixed a typo in PySpark where we used `SPARK_LOCAL_DIR` instead of `SPARK_LOCAL_DIRS` (I think this was technically innocuous, but it seemed worth fixing).
Sorry actually there is a problem with this in yarn client mode.  In yarn client mode the spark driver is on the launcher/gateway box (not in yarn cluster) and with these changes the driver tries to look up yarn directories even though its not on yarn.  

14/08/18 16:21:59 INFO SparkEnv: Registering BlockManagerMaster
14/08/18 16:21:59 DEBUG BlockManagerMasterActor: [actor] received message ExpireDeadHosts from Actor[akka://spark/user/BlockManagerMaster#-836784892]
14/08/18 16:21:59 DEBUG BlockManagerMasterActor: [actor] handled message (2.386093 ms) ExpireDeadHosts from Actor[akka://spark/user/BlockManagerMaster#-836784892]
Exception in thread "main" java.lang.Exception: Yarn Local dirs can't be empty
        at org.apache.spark.util.Utils$.getYarnLocalDirs(Utils.scala:501)
        at org.apache.spark.util.Utils$.getOrCreateLocalRootDirs(Utils.scala:471)
        at org.apache.spark.storage.DiskBlockManager.createLocalDirs(DiskBlockManager.scala:137)