This is an automated email from the ASF dual-hosted git repository.

ocket8888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 476513d  todb-tests GitHub action does not run the Traffic Ops DB 
tests (#5701)
476513d is described below

commit 476513da4f09164b4adb360b23cbd90c407d3649
Author: Srijeet Chatterjee <[email protected]>
AuthorDate: Tue Apr 6 13:09:29 2021 -0600

    todb-tests GitHub action does not run the Traffic Ops DB tests (#5701)
    
    * wip
    
    * add traffic_ops.rpm
    
    * wip
    
    * adding rpm to workflow
    
    * dont add the src rpm
    
    * fix typo
    
    * remove alpine docker images
    
    * test if the script quits
    
    * wip
    
    * check return code
    
    * catch return code
    
    * wip
    
    * cleanup
    
    * remove unneeded change
    
    * delete unneeded file
    
    * test
    
    * test again
    
    * fix script
    
    * cleanup
    
    * changelog entry
    
    * code review
---
 .github/workflows/traffic.ops.database.yml | 15 ++++++---------
 CHANGELOG.md                               |  1 +
 traffic_ops/app/db/admin.go                |  6 ++++--
 traffic_ops_db/test/docker/run-db-test.sh  | 12 +++++++++---
 4 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/.github/workflows/traffic.ops.database.yml 
b/.github/workflows/traffic.ops.database.yml
index 58b1cb7..c537e0a 100644
--- a/.github/workflows/traffic.ops.database.yml
+++ b/.github/workflows/traffic.ops.database.yml
@@ -28,12 +28,14 @@ on:
       - traffic_ops/app/db/**
       - .github/actions/todb-tests/**
       - .github/workflows/traffic.ops.database.yml
+      - traffic_ops_db/test/**
   pull_request:
     types: [opened, reopened, ready_for_review, synchronize]
     paths:
       - traffic_ops/app/db/**
       - .github/actions/todb-tests/**
       - .github/workflows/traffic.ops.database.yml
+      - traffic_ops_db/test/**
 
 jobs:
   tests:
@@ -44,14 +46,9 @@ jobs:
         with:
           fetch-depth: 0
         uses: actions/checkout@master
-      - name: Cache Alpine Docker image
-        uses: actions/cache@v2
-        with:
-          path: ${{ github.workspace }}/docker-images
-          key: docker-images/alpine@${{ env.ALPINE_VERSION }}.tar.gz
-      - name: Import cached Alpine Docker image
-        run: .github/actions/save-alpine-tar/entrypoint.sh load ${{ 
env.ALPINE_VERSION }}
       - name: Run Traffic Ops Database Tests
         run: ./.github/actions/todb-tests/entrypoint.sh
-      - name: Save Alpine Docker image
-        run: .github/actions/save-alpine-tar/entrypoint.sh save ${{ 
env.ALPINE_VERSION }}
+      - name: Build And Copy Traffic Ops RPM
+        run: ./pkg traffic_ops_build && cp ./dist/traffic_ops-*.x86_64.rpm 
traffic_ops_db/test/docker/traffic_ops.rpm
+      - name: Run Traffic Ops Database Docker Tests
+        run: cd traffic_ops_db/test/docker/ && docker-compose up 
--exit-code-from trafficops-db-admin
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dbb73ea..8a3639d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@ The format is based on [Keep a 
Changelog](http://keepachangelog.com/en/1.0.0/).
 
 ## [unreleased]
 ### Added
+- [#5449](https://github.com/apache/trafficcontrol/issues/5449) The 
`todb-tests` GitHub action now runs the Traffic Ops DB tests
 - Python client: [#5611](https://github.com/apache/trafficcontrol/pull/5611) 
Added server_detail endpoint
 - Ported the Postinstall script to Python. The Perl version has been moved to 
`install/bin/_postinstall.pl` and has been deprecated, pending removal in a 
future release.
 - CDN-in-a-Box: Generate config files using the Postinstall script
diff --git a/traffic_ops/app/db/admin.go b/traffic_ops/app/db/admin.go
index 67e2518..035dbf2 100644
--- a/traffic_ops/app/db/admin.go
+++ b/traffic_ops/app/db/admin.go
@@ -176,8 +176,9 @@ func createDB() {
        stderr := bytes.Buffer{}
        dbExistsCmd.Stderr = &stderr
        out, err := dbExistsCmd.Output()
+       // An error is returned if the database could not be found, which is to 
be expected. Don't exit on this error.
        if err != nil {
-               die("unable to check if DB already exists: " + err.Error() + ", 
stderr: " + stderr.String())
+               fmt.Println("unable to check if DB already exists: " + 
err.Error() + ", stderr: " + stderr.String())
        }
        if len(out) > 0 {
                fmt.Println("Database " + DBName + " already exists")
@@ -207,8 +208,9 @@ func createUser() {
        stderr := bytes.Buffer{}
        userExistsCmd.Stderr = &stderr
        out, err := userExistsCmd.Output()
+       // An error is returned if the user could not be found, which is to be 
expected. Don't exit on this error.
        if err != nil {
-               die("unable to check if user already exists: " + err.Error() + 
", stderr: " + stderr.String())
+               fmt.Println("unable to check if user already exists: " + 
err.Error() + ", stderr: " + stderr.String())
        }
        if len(out) > 0 {
                fmt.Println("User " + DBUser + " already exists")
diff --git a/traffic_ops_db/test/docker/run-db-test.sh 
b/traffic_ops_db/test/docker/run-db-test.sh
index db7ae2b..d0f6ba9 100755
--- a/traffic_ops_db/test/docker/run-db-test.sh
+++ b/traffic_ops_db/test/docker/run-db-test.sh
@@ -75,15 +75,21 @@ get_db_dumps() {
     find /db_dumps -name '*.dump'
 }
 
+db_is_empty=true
+
 for d in $(get_db_dumps); do
+    db_is_empty=false
     echo "checking integrity of DB dump: $d"
     pg_restore -l "$d" > /dev/null || { echo "invalid DB dump: $d. Unable to 
list contents"; exit 1; }
 done
 
 cd "$TO_DIR"
-db_is_empty=false
-old_db_version=$(get_current_db_version)
-[[ "$old_db_version" =~ ^failed ]] && { echo "get_current_db_version failed: 
$old_db_version"; exit 1; }
+old_db_version=0
+
+if [[ "$db_is_empty" = false ]]; then
+  old_db_version=$(get_current_db_version)
+  [[ "$old_db_version" =~ ^failed ]] && { echo "get_current_db_version failed: 
$old_db_version"; exit 1; }
+fi
 
 # reset the DB if it is empty (i.e. no db.dump was provided)
 if [[ "$old_db_version" -eq 0 ]]; then

Reply via email to