Test Failed
Push — master ( c17ee3...e147d3 )
by Heiko 'riot'
01:59
created

test_00_environment_clear()   A

Complexity

Conditions 1

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 16
nop 0
dl 0
loc 22
rs 9.6
c 0
b 0
f 0
1
#!/usr/bin/env python
2
# -*- coding: UTF-8 -*-
3
4
# Isomer - The distributed application framework
5
# ==============================================
6
# Copyright (C) 2011-2020 Heiko 'riot' Weinen <[email protected]> and others.
7
#
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU Affero General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
12
#
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
# GNU Affero General Public License for more details.
17
#
18
# You should have received a copy of the GNU Affero General Public License
19
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21
"""
22
Isomer - Backend
23
24
Test Isomer Environment Management
25
==================================
26
27
28
29
"""
30
31
import os
32
import pytest
33
34
from isomer.tool.etc import load_instance
35
from isomer.tool.tool import isotool
36
37
38
# TODO: The numbering is here because pytest-dependency is missing dependency test
39
#  sorting. Remove when the PR ( https://github.com/RKrahl/pytest-dependency/pull/44 )
40
#  has been integrated
41
@pytest.mark.dependency()
42
def test_00_environment_clear():
43
44
    """Creates a new default instances and clears it without archiving"""
45
    pytest.reset_base()
46
47
    _ = pytest.run_cli(isotool, ['instance', 'create'], full_log=True)
48
49
    assert os.path.exists('/tmp/isomer-test/etc/isomer/instances/' +
50
                          pytest.INSTANCENAME + '.conf')
51
    assert not os.path.exists('/tmp/isomer-test/var/lib/isomer/' +
52
                              pytest.INSTANCENAME + '/green')
53
54
    result = pytest.run_cli(isotool, ['environment', 'clear', '--no-archive'])
55
56
    assert os.path.exists('/tmp/isomer-test/var/lib/isomer/' +
57
                          pytest.INSTANCENAME + '/green')
58
    assert os.path.exists('/tmp/isomer-test/var/cache/isomer/' +
59
                          pytest.INSTANCENAME + '/green')
60
    assert os.path.exists('/tmp/isomer-test/var/local/isomer/' +
61
                          pytest.INSTANCENAME + '/green')
62
    assert result.exit_code == 0
63
64
65
@pytest.mark.dependency(depends=["test_00_environment_clear"])
66
def test_01_install():
67
    """Creates a new default instances and clears it without archiving"""
68
    pytest.reset_base(unset_instance=True)
69
    import os
70
    import pwd
71
72
    def get_username():
73
        """Return current username"""
74
        return pwd.getpwuid(os.getuid())[0]
75
76
    _ = pytest.run_cli(isotool, ['instance', 'create'], full_log=True)
77
    _ = pytest.run_cli(isotool, ['instance', 'set', 'user', get_username()],
78
                       full_log=True)
79
    _ = pytest.run_cli(isotool, ['environment', 'clear', '--no-archive'], full_log=True)
80
81
    assert os.path.exists('/tmp/isomer-test/etc/isomer/instances/' +
82
                          pytest.INSTANCENAME + '.conf')
83
    assert os.path.exists('/tmp/isomer-test/var/lib/isomer/' +
84
                          pytest.INSTANCENAME + '/green')
85
86
    repo_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))
87
88
    result = pytest.run_cli(
89
        isotool,
90
        ['environment', 'install', '--no-sudo', '--source', 'copy',
91
         '--url', repo_path, '--skip-provisions', '--skip-frontend'],
92
        full_log=True
93
    )
94
95
    assert result.exit_code == 0
96
97
    assert os.path.exists('/tmp/isomer-test/var/lib/isomer/' +
98
                          pytest.INSTANCENAME + '/green')
99
    assert os.path.exists('/tmp/isomer-test/var/cache/isomer/' +
100
                          pytest.INSTANCENAME + '/green')
101
    assert os.path.exists('/tmp/isomer-test/var/local/isomer/' +
102
                          pytest.INSTANCENAME + '/green')
103
    assert os.path.exists(
104
        '/tmp/isomer-test/var/lib/isomer/' +
105
        pytest.INSTANCENAME + '/green/venv/bin/python3')
106
    assert os.path.exists('/tmp/isomer-test/var/lib/isomer/' +
107
                          pytest.INSTANCENAME + '/green/venv/bin/iso')
108
    assert os.path.exists('/tmp/isomer-test/var/lib/isomer/' +
109
                          pytest.INSTANCENAME + '/green/repository')
110
    assert os.path.exists(
111
        '/tmp/isomer-test/var/lib/isomer/' +
112
        pytest.INSTANCENAME + '/green/repository/frontend')
113
114
    instance_configuration = load_instance(pytest.INSTANCENAME)
115
    environment = instance_configuration['environments']['green']
116
117
    assert environment['installed'] is True
118
    assert environment['provisioned'] is False
119
    assert environment['migrated'] is True
120
    assert environment['frontend'] is False
121
    assert environment['tested'] is False
122
    assert environment['database'] == pytest.INSTANCENAME + '_green'
123
124
    if result.exit_code != 0:
125
        print(result.output)
126
        print("For more information on possibly failed subtasks, "
127
              "consult /tmp/isomer_test_run_cli_logfile")
128