File: test_suseSetupProduct.py

package info (click to toggle)
kiwi 10.2.36-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 7,664 kB
  • sloc: python: 69,179; sh: 4,228; xml: 3,383; ansic: 391; makefile: 353
file content (99 lines) | stat: -rw-r--r-- 3,051 bytes parent folder | download | duplicates (2)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import pytest

from .conftest import (
    LEAP_15_5,
    TUMBLEWEED,
)


CONTAINER_IMAGES = [TUMBLEWEED]


def test_does_nothing_when_product_correct(auto_container_per_test):
    previous_contents = auto_container_per_test.connection.file(
        "/etc/products.d"
    ).listdir()
    auto_container_per_test.connection.run_expect(
        [0], ". /bin/functions.sh && suseSetupProduct"
    )
    assert auto_container_per_test.connection.file("/etc/products.d").listdir() == previous_contents


@pytest.mark.parametrize(
    "container_per_test,product_name",
    (
        (TUMBLEWEED, "openSUSE.prod"),
        (LEAP_15_5, "Leap.prod"),
    ),
    indirect=["container_per_test"],
)
def test_sets_baseproduct_from_etc_os_release(container_per_test, product_name):
    assert not container_per_test.connection.file("/etc/SuSE-brand").exists

    container_per_test.connection.run_expect([0], "rm /etc/products.d/baseproduct")
    container_per_test.connection.run_expect(
        [0], ". /bin/functions.sh && suseSetupProduct"
    )

    assert container_per_test.connection.file("/etc/products.d/baseproduct").exists
    assert container_per_test.connection.file("/etc/products.d/baseproduct").is_symlink
    assert container_per_test.connection.file("/etc/products.d/baseproduct").linked_to == "/etc/products.d/" + product_name


def test_sets_baseproduct_with_weird_os_release(auto_container_per_test):
    assert not auto_container_per_test.connection.file(
        "/etc/SuSE-brand"
    ).exists
    auto_container_per_test.connection.run_expect(
        [0], "rm /etc/products.d/baseproduct"
    )
    auto_container_per_test.connection.run_expect(
        [0],
        """cat <<EOF > /etc/os-release
NAME=openSUSE Tumbleweed
ID="opensuse-tumbleweed"
ID_LIKE="opensuse suse"
EOF
""",
    )

    auto_container_per_test.connection.run_expect(
        [0], ". /bin/functions.sh && suseSetupProduct"
    )
    assert auto_container_per_test.connection.file(
        "/etc/products.d/baseproduct"
    ).exists
    assert auto_container_per_test.connection.file(
        "/etc/products.d/baseproduct"
    ).is_symlink
    assert (
        auto_container_per_test.connection.file(
            "/etc/products.d/baseproduct"
        ).linked_to == "/etc/products.d/openSUSE.prod"
    )


def test_sets_baseproduct_from_prod_files(auto_container_per_test):
    auto_container_per_test.connection.run_expect(
        [0],
        """rm /etc/products.d/baseproduct
rm /etc/products.d/openSUSE.prod
touch /etc/products.d/10.prod
touch /etc/products.d/20.prod
""",
    )

    auto_container_per_test.connection.run_expect(
        [0], ". /bin/functions.sh && suseSetupProduct"
    )
    assert auto_container_per_test.connection.file(
        "/etc/products.d/baseproduct"
    ).exists
    assert auto_container_per_test.connection.file(
        "/etc/products.d/baseproduct"
    ).is_symlink
    assert (
        auto_container_per_test.connection.file(
            "/etc/products.d/baseproduct"
        ).linked_to == "/etc/products.d/20.prod"
    )