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

test_00_environment_clear()   A

Complexity

Conditions 1

Size

Total Lines 24
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nop 0
dl 0
loc 24
rs 9.85
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
import warnings
38
39
# TODO: The numbering is here because pytest-dependency is missing dependency test
40
#  sorting. Remove when the PR ( https://github.com/RKrahl/pytest-dependency/pull/44 )
41
#  has been integrated
42
@pytest.mark.dependency()
43
def test_00_environment_clear():
44
45
    """Creates a new default instances and clears it without archiving"""
46
    pytest.reset_base()
47
48
    _ = pytest.run_cli(isotool, ['instance', 'create'], full_log=True)
49
50
    assert os.path.exists('/tmp/isomer-test/etc/isomer/instances/' +
51
                          pytest.INSTANCENAME + '.conf')
52
    assert not os.path.exists('/tmp/isomer-test/var/lib/isomer/' +
53
                              pytest.INSTANCENAME + '/green')
54
55
    result = pytest.run_cli(isotool, ['environment', 'clear', '--no-archive'])
56
57
    warnings.warn(print.output)
58
59
    # assert os.path.exists('/tmp/isomer-test/var/lib/isomer/' +
60
    #                       pytest.INSTANCENAME + '/green')
61
    # assert os.path.exists('/tmp/isomer-test/var/cache/isomer/' +
62
    #                       pytest.INSTANCENAME + '/green')
63
    # assert os.path.exists('/tmp/isomer-test/var/local/isomer/' +
64
    #                       pytest.INSTANCENAME + '/green')
65
    assert result.exit_code == 0
66
67
68
@pytest.mark.dependency(depends=["test_00_environment_clear"])
69
def test_01_install():
70
    """Creates a new default instances and clears it without archiving"""
71
    pytest.reset_base(unset_instance=True)
72
    import os
73
    import pwd
74
75
    def get_username():
76
        """Return current username"""
77
        return pwd.getpwuid(os.getuid())[0]
78
79
    _ = pytest.run_cli(isotool, ['instance', 'create'], full_log=True)
80
    _ = pytest.run_cli(isotool, ['instance', 'set', 'user', get_username()],
81
                       full_log=True)
82
    _ = pytest.run_cli(isotool, ['environment', 'clear', '--no-archive'], full_log=True)
83
84
    # assert os.path.exists('/tmp/isomer-test/etc/isomer/instances/' +
85
    #                       pytest.INSTANCENAME + '.conf')
86
    # assert os.path.exists('/tmp/isomer-test/var/lib/isomer/' +
87
    #                       pytest.INSTANCENAME + '/green')
88
89
    repo_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))
90
91
    result = pytest.run_cli(
92
        isotool,
93
        ['environment', 'install', '--no-sudo', '--source', 'copy',
94
         '--url', repo_path, '--skip-provisions', '--skip-frontend'],
95
        full_log=True
96
    )
97
98
    assert result.exit_code == 0
99
100
    # assert os.path.exists('/tmp/isomer-test/var/lib/isomer/' +
101
    #                       pytest.INSTANCENAME + '/green')
102
    # assert os.path.exists('/tmp/isomer-test/var/cache/isomer/' +
103
    #                       pytest.INSTANCENAME + '/green')
104
    # assert os.path.exists('/tmp/isomer-test/var/local/isomer/' +
105
    #                       pytest.INSTANCENAME + '/green')
106
    # assert os.path.exists(
107
    #     '/tmp/isomer-test/var/lib/isomer/' +
108
    #     pytest.INSTANCENAME + '/green/venv/bin/python3')
109
    # assert os.path.exists('/tmp/isomer-test/var/lib/isomer/' +
110
    #                       pytest.INSTANCENAME + '/green/venv/bin/iso')
111
    # assert os.path.exists('/tmp/isomer-test/var/lib/isomer/' +
112
    #                       pytest.INSTANCENAME + '/green/repository')
113
    # assert os.path.exists(
114
    #     '/tmp/isomer-test/var/lib/isomer/' +
115
    #     pytest.INSTANCENAME + '/green/repository/frontend')
116
117
    instance_configuration = load_instance(pytest.INSTANCENAME)
118
    environment = instance_configuration['environments']['green']
119
120
    assert environment['installed'] is True
121
    assert environment['provisioned'] is False
122
    assert environment['migrated'] is True
123
    assert environment['frontend'] is False
124
    assert environment['tested'] is False
125
    assert environment['database'] == pytest.INSTANCENAME + '_green'
126
127
    if result.exit_code != 0:
128
        print(result.output)
129
        print("For more information on possibly failed subtasks, "
130
              "consult /tmp/isomer_test_run_cli_logfile")
131