[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).
SPARK_YARN_USER_ENV is optional.  We could make sure some other env variable is always set when we launch a container in yarn though.  

I was looking for something else we could use that would be reliable.  For instance, you could use the LOCAL_DIRS or YARN_LOCAL_DIRS as an indicator since YARN always set those.  But LOCAL_DIRS is generic enough I guess a user could have it set for something else. There are other variables that YARN sets for you.  I think what might be a good idea is to check to see if either CONTAINER_ID or NM_HOST are set.  The reason to check for both is hadoop 2.x sets CONTAINER_ID which I prefer to use but hadoop 0.23 doesn't and NM_HOST is set on both.