Completed
Push — master ( 38bdd8...8e8835 )
by
unknown
01:57
created

configure_splunk_forwarder()   A

Complexity

Conditions 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 3
dl 0
loc 12
rs 9.4286
1
# coding: utf8
2
3
"""
4
This software is licensed under the Apache 2 license, quoted below.
5
6
Copyright 2014 Crystalnix Limited
7
8
Licensed under the Apache License, Version 2.0 (the "License"); you may not
9
use this file except in compliance with the License. You may obtain a copy of
10
the License at
11
12
    http://www.apache.org/licenses/LICENSE-2.0
13
14
Unless required by applicable law or agreed to in writing, software
15
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
License for the specific language governing permissions and limitations under
18
the License.
19
"""
20
21
import os
22
23
from raven import Client
24
from paver.easy import task, needs
25
from paver.easy import sh
26
27
28
client = Client(os.environ.get('RAVEN_DNS'))
29
30
31
@task
32
def test():
33
    sh('./manage.py test --settings=omaha_server.settings_test', cwd='omaha_server')
34
35
36
@task
37
def test_tox():
38
    path_to_test = os.getenv("PATH_TO_TEST", '')
39
    settings = os.getenv("DJANGO_SETTINGS_MODULE", 'omaha_server.settings_test')
40
    sh('./manage.py test %s --settings=%s' % (path_to_test, settings), cwd='omaha_server')
41
42
43
@task
44
def test_postgres():
45
    sh('./manage.py test --settings=omaha_server.settings_test_postgres', cwd='omaha_server')
46
47
48
@task
49
@needs('test', 'test_postgres')
50
def test_all():
51
    pass
52
53
54
@task
55
def up_local_dev_server():
56
    """
57
    Requirements:
58
59
    - [docker](docker.com) or [boot2docker](https://github.com/boot2docker/boot2docker) for OS X or Windows
60
    - [docker-compose](https://docs.docker.com/compose/install/)
61
62
    """
63
    sh('docker-compose -f docker-compose.dev.yml -p dev up -d db')
64
    sh('docker-compose -f docker-compose.dev.yml -p dev up -d web')
65
    print("""Open http://{DOCKER_HOST}:9090/admin/\n username: admin\n password: admin""")
66
67
68
@task
69
def deploy_dev():
70
    sh('ebs-deploy deploy -e omaha-server-dev', cwd='omaha_server')
71
72
73
@task
74
def collectstatic():
75
    sh('./manage.py collectstatic --noinput', cwd='omaha_server')
76
77
78
@task
79
def loaddata():
80
    sh('./manage.py loaddata fixtures/initial_data.json', cwd='omaha_server')
81
82
83
@task
84
def migrate():
85
    sh('./manage.py migrate auth --noinput', cwd='omaha_server')
86
    sh('./manage.py migrate --noinput', cwd='omaha_server')
87
88
89
@task
90
def create_admin():
91
    sh('./createadmin.py', cwd='omaha_server')
92
93
94
@task
95
def configure_nginx():
96
    splunk_host = os.environ.get('SPLUNK_HOST')
97
    splunk_port = os.environ.get('SPLUNK_PORT', '')
98
    if splunk_host and splunk_port.isdigit():
99
        sh("sed -i 's/access_log.*;/access_log syslog:server=%s:%s main;/g' /etc/nginx/nginx.conf" % (splunk_host, splunk_port))
100
        sh("sed -i 's/error_log.*;/error_log syslog:server=%s:%s;/g' /etc/nginx/nginx.conf" % (splunk_host, splunk_port))
101
    else:
102
        sh("sed -i 's#access_log.*;#access_log /var/log/nginx/access.log main;#g' /etc/nginx/nginx.conf")
103
        sh("sed -i 's#error_log.*;#error_log /var/log/nginx/error.log;#g' /etc/nginx/nginx.conf")
104
    server_name = os.environ.get('HOST_NAME', '_')
105
    sh("sed -i 's/server_name.*;/server_name %s;/g' /etc/nginx/sites-enabled/nginx-app.conf" % (server_name))
106
107
108
@task
109
def docker_run():
110
    try:
111
        is_private = True if os.environ.get('OMAHA_SERVER_PRIVATE', '').title() == 'True' else False
112
113
        if is_private:
114
            migrate()
115
            loaddata()
116
            create_admin()
117
            collectstatic()
118
119
        configure_nginx()
120
        sh('/usr/bin/supervisord')
121
    except:
122
        client.captureException()
123
        raise
124
125
126
@task
127
def docker_run_test():
128
    sh('apt-get install -y python-dev libxslt-dev libpq-dev')
129
    sh('pip install -r requirements/test.txt --use-mirrors')
130
    test()
131
    test_postgres()
132
133
134
@task
135
def run_test_in_docker():
136
    try:
137
        sh('docker-compose -f docker-compose.test.yml -p omaha_testing run --rm web paver docker_run_test')
138
    except:
139
        pass
140
    sh('docker-compose -f docker-compose.test.yml -p omaha_testing stop')
141
    sh('docker-compose -f docker-compose.test.yml -p omaha_testing rm --force')
142