#1350 Allow to run tests with PostgreSQL inside Vagrant machine
Merged 4 years ago by cqi. Opened 4 years ago by cqi.

file modified
+41
@@ -80,6 +80,46 @@ 

    fi

  DEVENV

  

+ $config_pgsql = <<PGSQL

+ dnf install -y postgresql postgresql-server python2-psycopg2

+ 

+ pg_hba_conf=/var/lib/pgsql/data/pg_hba.conf

+ 

+ if [[ ! -e "$pg_hba_conf" ]]; then

+   postgresql-setup --initdb

+ fi

+ 

+ systemctl start postgresql

+ systemctl enable postgresql

+ 

+ cp "$pg_hba_conf" "${pg_hba_conf}.orig"

+ 

+ # Allow to connect to PostgreSQL without password

+ if ! grep "host all all 127.0.0.1/32 trust" "$pg_hba_conf" >/dev/null; then

+   echo "host all all 127.0.0.1/32 trust" > "$pg_hba_conf"

+ fi

+ 

+ # Avoid SQL query statement being truncated in pg_stat_activity, which is

+ # convenient for debugging.

+ pg_conf=/var/lib/pgsql/data/postgresql.conf

+ if ! grep "track_activity_query_size = 4096" "$pg_conf" >/dev/null; then

+   echo "track_activity_query_size = 4096" >> "$pg_conf"

+ fi

+ 

+ # Restart to apply configuration changes

+ systemctl restart postgresql

+ 

+ psql -U postgres -h 127.0.0.1 -c "DROP DATABASE IF EXISTS mbstest"

+ psql -U postgres -h 127.0.0.1 -c "CREATE DATABASE mbstest"

+ 

+ bashrc=/home/vagrant/.bashrc

+ 

+ echo "******** Run Tests with PostgreSQL ********"

+ echo "Set this environment variable to test with PostgreSQL"

+ echo "export DATABASE_URI=postgresql+psycopg2://postgres:@127.0.0.1/mbstest"

+ echo

+ PGSQL

+ 

  $script_services = <<SCRIPT_SERVICES

      bin_dir=~/devenv/bin

      cd /opt/module_build_service
@@ -98,6 +138,7 @@ 

    config.vm.network "forwarded_port", guest_ip: "0.0.0.0", guest: 13747, host: 13747

    config.vm.provision "shell", inline: $script

    config.vm.provision "shell", inline: "usermod -a -G mock vagrant"

+   config.vm.provision "shell", inline: $config_pgsql

    config.vm.provision "shell", inline: $make_devenv, privileged: false

    config.vm.provision "shell", inline: $script_services, privileged: false, run: "always"

    config.vm.provider "libvirt" do |v, override|

file modified
+15
@@ -1,6 +1,9 @@ 

  Running Tests

  =============

  

+ Inside Container

+ ----------------

+ 

  Since MBS requires Python dependencies that aren't available using PyPi (e.g.

  libsolv bindings), there are container images (based on CentOS and Fedora) that

  can be used to run the code analysis and unit tests.
@@ -38,6 +41,18 @@ 

          /src/tests/test_mmd_resolver.py \

          /src/tests/test_builder/test_koji.py::TestKojiBuilder::test_tag_to_repo

  

+ Inside Vagrant machine

+ ----------------------

+ 

+ You can run tests with either SQLite or PostgreSQL as well. The former is default.

+ 

+ To start to run tests with SQLite, you could simply run ``py.test`` or ``tox``.

+ 

+ To start to run tests with PostgreSQL, set environment variable

+ ``DATABASE_URI`` before running ``py.test`` or ``tox``::

+ 

+     export DATABASE_URI=postgresql+psycopg2://postgres:@127.0.0.1/mbstest

+ 

  Style Guide

  ===========

  

Signed-off-by: Chenxiong Qi cqi@redhat.com

I used this to debug tests locally. Hopefully, this would be helpful for other developers as well.

+1, but I will wait for US to wake up to check this in case they want to :).

You don't want to append to the file instead?

is not truncated => being truncated

debug => debugging

What does this do?

It's the final part of:

$config_pgsql = <<PGSQL

You don't want to append to the file instead?

Yeah, only one auth meth is enough for running tests or even running mbs in this dev env.

rebased onto 8505830dde77c7587000be1a09fcb66e26155db7

4 years ago

@mprahl Spelling issues are fixed.

Build #282 failed (commit: 8505830dde77c7587000be1a09fcb66e26155db7).
Rebase or make new commits to rebuild.

pretty please pagure-ci rebuild

4 years ago

rebased onto 68fe2b6

4 years ago

rebased onto 68fe2b6

4 years ago

Pull-Request has been merged by cqi

4 years ago

Build #286 failed (commit: 68fe2b6).
Rebase or make new commits to rebuild.