[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).
There's also some code in the Yarn ApplicationMaster and ExecutorLauncher classes that sets the `spark.local.dir` property, too:

```
    // Setup the directories so things go to yarn approved directories rather
    // then user specified and /tmp.
    System.setProperty("spark.local.dir", getLocalDirs())
```

The getLocalDirs() code is duplicated in several places now, too:

```
[joshrosen Spark (master)]$ git grep -A4 "def getLocalDirs"
yarn/alpha/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala:  private def getLocalDirs(): String = {
yarn/alpha/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala-    // Hadoop 0.23 and 2.x have different Environment variable names for the
yarn/alpha/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala-    // local dirs, so lets check both. We assume one of the 2 is set.
yarn/alpha/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala-    // LOCAL_DIRS => 2.X, YARN_LOCAL_DIRS => 0.23.X
yarn/alpha/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala-    val localDirs = Option(System.getenv("YARN_LOCAL_DIRS"))
--
yarn/alpha/src/main/scala/org/apache/spark/deploy/yarn/ExecutorLauncher.scala:  private def getLocalDirs(): String = {
yarn/alpha/src/main/scala/org/apache/spark/deploy/yarn/ExecutorLauncher.scala-    // Hadoop 0.23 and 2.x have different Environment variable names for the
yarn/alpha/src/main/scala/org/apache/spark/deploy/yarn/ExecutorLauncher.scala-    // local dirs, so lets check both. We assume one of the 2 is set.
yarn/alpha/src/main/scala/org/apache/spark/deploy/yarn/ExecutorLauncher.scala-    // LOCAL_DIRS => 2.X, YARN_LOCAL_DIRS => 0.23.X
yarn/alpha/src/main/scala/org/apache/spark/deploy/yarn/ExecutorLauncher.scala-    val localDirs = Option(System.getenv("YARN_LOCAL_DIRS"))
--
yarn/stable/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala:  private def getLocalDirs(): String = {
yarn/stable/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala-    // Hadoop 0.23 and 2.x have different Environment variable names for the
yarn/stable/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala-    // local dirs, so lets check both. We assume one of the 2 is set.
yarn/stable/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala-    // LOCAL_DIRS => 2.X, YARN_LOCAL_DIRS => 0.23.X
yarn/stable/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala-    val localDirs = Option(System.getenv("YARN_LOCAL_DIRS"))
--
yarn/stable/src/main/scala/org/apache/spark/deploy/yarn/ExecutorLauncher.scala:  private def getLocalDirs(): String = {
yarn/stable/src/main/scala/org/apache/spark/deploy/yarn/ExecutorLauncher.scala-    // Hadoop 0.23 and 2.x have different Environment variable names for the
yarn/stable/src/main/scala/org/apache/spark/deploy/yarn/ExecutorLauncher.scala-    // local dirs, so lets check both. We assume one of the 2 is set.
yarn/stable/src/main/scala/org/apache/spark/deploy/yarn/ExecutorLauncher.scala-    // LOCAL_DIRS => 2.X, YARN_LOCAL_DIRS => 0.23.X
yarn/stable/src/main/scala/org/apache/spark/deploy/yarn/ExecutorLauncher.scala-    val localDirs = Option(System.getenv("YARN_LOCAL_DIRS"))
```

I'm not sure whether this code actually affects anything, since it sets the `spark.local.dir` system property _after_ the SparkConf has already been created, and `spark.local.dir` is only consumed through SparkConf, not through directly reading the system property.