File: prepare_db.sh

package info (click to toggle)
mistral 21.0.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,140 kB
  • sloc: python: 54,052; sh: 701; makefile: 58
file content (65 lines) | stat: -rw-r--r-- 1,612 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash

set -eu

db_type=$1

function setup_db {
    case ${db_type} in
        sqlite )
            rm -f tests.sqlite
            ;;
        postgresql | mysql )
            dbname="openstack_citest"
            username="openstack_citest"
            password="openstack_citest"
            ;;
    esac
}

function setup_db_pylib {
    case ${db_type} in
        postgresql )
            echo "Installing python library for PostgreSQL."
            pip install psycopg2==2.8.3
            ;;
        mysql )
            echo "Installing python library for MySQL"
            pip install PyMySQL
            ;;
    esac
}

function setup_db_cfg {
    case ${db_type} in
        sqlite )
            rm -f .mistral.conf
            ;;
        postgresql )
            oslo-config-generator --config-file \
                ./tools/config/config-generator.mistral.conf \
                --output-file .mistral.conf
            sed -i "s/#connection = <None>/connection = postgresql:\/\/$username:$password@localhost\/$dbname/g" .mistral.conf
            ;;
        mysql )
            oslo-config-generator --config-file \
                ./tools/config/config-generator.mistral.conf \
                --output-file .mistral.conf
            sed -i "s/#connection = <None>/connection = mysql+pymysql:\/\/$username:$password@localhost\/$dbname/g" .mistral.conf
            ;;
    esac
}

function upgrade_db {
    case ${db_type} in
        postgresql | mysql )
            mistral-db-manage --config-file .mistral.conf upgrade head
            ;;
    esac
}


setup_db
setup_db_pylib
setup_db_cfg
upgrade_db