[v2,2/3] Default dev settings, set host to empty (unix socket) on postgresql

Message ID 20180806065639.23094-2-daniel@linux.ibm.com
State New
Headers show
Series
  • [v2,1/3] travis: test against postgresql 10 and 11
Related show

Commit Message

Daniel Black Aug. 6, 2018, 6:56 a.m.
An empty environment variable resulted in localhost, meaning
posgresql connecting to domain sockets wasn't available.

Signed-off-by: Daniel Black <daniel@linux.ibm.com>
---
 .travis.yml               | 3 +++
 patchwork/settings/dev.py | 1 +
 2 files changed, 4 insertions(+)

Comments

Daniel Axtens Aug. 9, 2018, 3:08 p.m. | #1
Daniel Black <daniel@linux.ibm.com> writes:

> An empty environment variable resulted in localhost, meaning
> posgresql connecting to domain sockets wasn't available.

It took me a long time to understand how this works (e.g. that PGPORT is
still required to be set for psql to find the correct domain socket.)
But I think I'm now a bit clearer.

> Signed-off-by: Daniel Black <daniel@linux.ibm.com>
> ---
>  .travis.yml               | 3 +++
>  patchwork/settings/dev.py | 1 +
>  2 files changed, 4 insertions(+)
>
> diff --git a/.travis.yml b/.travis.yml
> index 58e0b08..0c6e79d 100644
> --- a/.travis.yml
> +++ b/.travis.yml
> @@ -22,6 +22,7 @@ env:
>      - PW_TEST_DB_TYPE=mysql PW_TEST_DB_USER=root
>    global:
>      - PW_TEST_DB_PASS=""
> +    - PW_TEST_DB_HOST="localhost"

I tried setting this to "" globally and it seemed to work; is there any
reason to treat postgres 10 and 11 specially?

More fundamentally, is there any reason we particuarly want to do things
this way on Travis?

Regards,
Daniel
Daniel Black Aug. 9, 2018, 10:29 p.m. | #2
On Fri, 10 Aug 2018 01:08:48 +1000
Daniel Axtens <dja@axtens.net> wrote:

> Daniel Black <daniel@linux.ibm.com> writes:
> 
> > An empty environment variable resulted in localhost, meaning
> > posgresql connecting to domain sockets wasn't available.  
> 
> It took me a long time to understand how this works (e.g. that PGPORT
> is still required to be set for psql to find the correct domain
> socket.) But I think I'm now a bit clearer.
> 
> > Signed-off-by: Daniel Black <daniel@linux.ibm.com>
> > ---
> >  .travis.yml               | 3 +++
> >  patchwork/settings/dev.py | 1 +
> >  2 files changed, 4 insertions(+)
> >
> > diff --git a/.travis.yml b/.travis.yml
> > index 58e0b08..0c6e79d 100644
> > --- a/.travis.yml
> > +++ b/.travis.yml
> > @@ -22,6 +22,7 @@ env:
> >      - PW_TEST_DB_TYPE=mysql PW_TEST_DB_USER=root
> >    global:
> >      - PW_TEST_DB_PASS=""
> > +    - PW_TEST_DB_HOST="localhost"  
> 
> I tried setting this
> to "" globally and it seemed to work; is there
> any reason to treat postgres 10 and 11 specially?

I was preserving PW_TEST_DB_HOST=localhost so the previous 9.6 test was
run the same way as it did previously.

> More fundamentally, is there any reason we particuarly want to do
> things this way on Travis?

No idea which "things" you're exactly referring to.

> 
> Regards,
> Daniel
>
Daniel Axtens Aug. 10, 2018, 5:44 p.m. | #3
Daniel Black <daniel@linux.ibm.com> writes:

> On Fri, 10 Aug 2018 01:08:48 +1000
> Daniel Axtens <dja@axtens.net> wrote:
>
>> Daniel Black <daniel@linux.ibm.com> writes:
>> 
>> > An empty environment variable resulted in localhost, meaning
>> > posgresql connecting to domain sockets wasn't available.  
>> 
>> It took me a long time to understand how this works (e.g. that PGPORT
>> is still required to be set for psql to find the correct domain
>> socket.) But I think I'm now a bit clearer.
>> 
>> > Signed-off-by: Daniel Black <daniel@linux.ibm.com>
>> > ---
>> >  .travis.yml               | 3 +++
>> >  patchwork/settings/dev.py | 1 +
>> >  2 files changed, 4 insertions(+)
>> >
>> > diff --git a/.travis.yml b/.travis.yml
>> > index 58e0b08..0c6e79d 100644
>> > --- a/.travis.yml
>> > +++ b/.travis.yml
>> > @@ -22,6 +22,7 @@ env:
>> >      - PW_TEST_DB_TYPE=mysql PW_TEST_DB_USER=root
>> >    global:
>> >      - PW_TEST_DB_PASS=""
>> > +    - PW_TEST_DB_HOST="localhost"  
>> 
>> I tried setting this
>> to "" globally and it seemed to work; is there
>> any reason to treat postgres 10 and 11 specially?
>
> I was preserving PW_TEST_DB_HOST=localhost so the previous 9.6 test was
> run the same way as it did previously.
>
>> More fundamentally, is there any reason we particuarly want to do
>> things this way on Travis?
>
> No idea which "things" you're exactly referring to.

Sorry, I wasn't clear.

Why should we test with local domain sockets rather than with localhost?

Regards,
Daniel

>
>> 
>> Regards,
>> Daniel
>>
Daniel Black Aug. 12, 2018, 5:19 a.m. | #4
> >> > diff --git a/.travis.yml b/.travis.yml
> >> > index 58e0b08..0c6e79d 100644
> >> > --- a/.travis.yml
> >> > +++ b/.travis.yml
> >> > @@ -22,6 +22,7 @@ env:
> >> >      - PW_TEST_DB_TYPE=mysql PW_TEST_DB_USER=root
> >> >    global:
> >> >      - PW_TEST_DB_PASS=""
> >> > +    - PW_TEST_DB_HOST="localhost"    
> >> 
> >> I tried setting this
> >> to "" globally and it seemed to work; is there
> >> any reason to treat postgres 10 and 11 specially?  
> >
> > I was preserving PW_TEST_DB_HOST=localhost so the previous 9.6 test
> > was run the same way as it did previously.
> >  
> >> More fundamentally, is there any reason we particuarly want to do
> >> things this way on Travis?  
> >
> > No idea which "things" you're exactly referring to.  
> 
> Sorry, I wasn't clear.
> 
> Why should we test with local domain sockets rather than with
> localhost?

You should test both connection types are possible in patchwork.
Obviously the end result is the same however.

Patch

diff --git a/.travis.yml b/.travis.yml
index 58e0b08..0c6e79d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -22,6 +22,7 @@  env:
     - PW_TEST_DB_TYPE=mysql PW_TEST_DB_USER=root
   global:
     - PW_TEST_DB_PASS=""
+    - PW_TEST_DB_HOST="localhost"
 
 matrix:
   include:
@@ -33,6 +34,7 @@  matrix:
           - postgresql-client-10
       env:
         - PGPORT=5433
+        - PW_TEST_DB_HOST=""
         - PW_TEST_DB_PORT=5433
         - PW_TEST_DB_TYPE=postgres
         - PW_TEST_DB_USER=travis
@@ -43,6 +45,7 @@  matrix:
         - sudo -u postgres psql -c "grant ALL on DATABASE postgres to travis WITH GRANT OPTION;"
     - env:
         - PGPORT=5433
+        - PW_TEST_DB_HOST=""
         - PW_TEST_DB_PORT=5433
         - PW_TEST_DB_TYPE=postgres
         - PW_TEST_DB_USER=travis
diff --git a/patchwork/settings/dev.py b/patchwork/settings/dev.py
index 7bdfdff..0f79b61 100644
--- a/patchwork/settings/dev.py
+++ b/patchwork/settings/dev.py
@@ -41,6 +41,7 @@  DATABASES = {
 
 if os.getenv('PW_TEST_DB_TYPE', None) == 'postgres':
     DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
+    DATABASES['default']['HOST'] = os.getenv('PW_TEST_DB_HOST', '')
 
 EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'