[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).
If this becomes really expensive (e.g. many calls to fetchFile), you could cache the result in a field of SparkConf (or just make this into a private instance method of SparkConf).  I could make those changes now, or we could wait to see if this is an actual performance problem.

I guess the correct YARN logic is "if this process is running inside of a YARN container, then use the YARN directories".  If so, I need a way to determine `isRunningInYarnContainer.`  Is `SPARK_YARN_MODE` the right way to do this, or should I be using some other signal (or does SPARK_YARN_MODE need to be set differently so that it's not set on the driver when running in client mode)?