File: s390_test.py

package info (click to toggle)
libblockdev 3.3.0-2.1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 4,272 kB
  • sloc: ansic: 25,314; python: 13,388; makefile: 663; sh: 503; xml: 146
file content (113 lines) | stat: -rw-r--r-- 4,557 bytes parent folder | download
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import unittest
import os
import overrides_hack

from utils import fake_path, TestTags, tag_test, required_plugins

import gi
gi.require_version('GLib', '2.0')
gi.require_version('BlockDev', '3.0')
from gi.repository import GLib, BlockDev

@unittest.skipUnless(os.uname()[4].startswith('s390'), "s390x architecture required")
@required_plugins(("s390",))
class S390TestCase(unittest.TestCase):

    requested_plugins = BlockDev.plugin_specs_from_names(("s390",))

    @classmethod
    def setUpClass(cls):

        if not BlockDev.is_initialized():
            BlockDev.init(cls.requested_plugins, None)
        else:
            BlockDev.reinit(cls.requested_plugins, True, None)

    @tag_test(TestTags.NOSTORAGE)
    def test_plugin_version(self):
       self.assertEqual(BlockDev.get_plugin_soname(BlockDev.Plugin.S390), "libbd_s390.so.3")

    @tag_test(TestTags.EXTRADEPS, TestTags.NOSTORAGE)
    def test_device_input(self):
        """Verify that s390_sanitize_dev_input works as expected"""
        dev = "1234"
        self.assertEqual(BlockDev.s390_sanitize_dev_input(dev), '0.0.' + dev)

        dev = "123456"
        self.assertEqual(BlockDev.s390_sanitize_dev_input(dev), '0.0.' + dev)

        # the device number is padded on the left with 0s up to 4 digits
        dev = "123.abc"
        self.assertEqual(BlockDev.s390_sanitize_dev_input(dev), "0.0.0abc")
        dev = "abc"
        self.assertEqual(BlockDev.s390_sanitize_dev_input(dev), "0.0.0abc")
        dev = ".abc"
        self.assertEqual(BlockDev.s390_sanitize_dev_input(dev), "0.0.0abc")

        # a complete number is unchanged
        dev = "0.0.abcd"
        self.assertEqual(BlockDev.s390_sanitize_dev_input(dev), dev)

        # a too long number doesn't mean a crash no matter if it makes sense
        dev = "0.0.abcdefgh"
        self.assertEqual(BlockDev.s390_sanitize_dev_input(dev), dev)

    @tag_test(TestTags.EXTRADEPS, TestTags.NOSTORAGE)
    def test_wwpn_input(self):
        """Verify that s390_zfcp_sanitize_wwpn_input works as expected"""
        # missing "0x" from beginning of wwpn; this should be added by fx
        wwpn = "01234567abcdefab"
        self.assertEqual(BlockDev.s390_zfcp_sanitize_wwpn_input(wwpn), "0x01234567abcdefab")
        # this should be fine as-is
        wwpn = "0x01234567abcdefab"
        self.assertEqual(BlockDev.s390_zfcp_sanitize_wwpn_input(wwpn), wwpn)

        # too short
        wwpn = "a"
        with self.assertRaises(GLib.GError):
            BlockDev.s390_zfcp_sanitize_wwpn_input(wwpn)

    @tag_test(TestTags.EXTRADEPS, TestTags.NOSTORAGE)
    def test_lun_input(self):
        """Verify that s390_zfcp_sanitize_lun_input works as expected"""
        # user does not prepend lun with "0x"; this should get added
        lun = "01234567abcdefab"
        self.assertEqual(BlockDev.s390_zfcp_sanitize_lun_input(lun), "0x01234567abcdefab")
        # a user enters a lun that is between 0 and 16 chars long (non-inclusive); 0 padding should be added to expand to 16
        lun = "0x123"
        self.assertEqual(BlockDev.s390_zfcp_sanitize_lun_input(lun), "0x0123000000000000")
        lun = "0x12345"
        self.assertEqual(BlockDev.s390_zfcp_sanitize_lun_input(lun), "0x1234500000000000")
        lun = "0x123456"
        self.assertEqual(BlockDev.s390_zfcp_sanitize_lun_input(lun), "0x1234560000000000")
        # this should be fine as-is
        lun = "0x1234567800000000"
        self.assertEqual(BlockDev.s390_zfcp_sanitize_lun_input(lun), lun)

        # too long
        lun = "12345678901234567890"
        with self.assertRaises(GLib.GError):
            BlockDev.s390_zfcp_sanitize_lun_input(lun)


@unittest.skipUnless(os.uname()[4].startswith('s390'), "s390x architecture required")
class S390DepsTest(unittest.TestCase):

    requested_plugins = BlockDev.plugin_specs_from_names(("s390",))

    @classmethod
    def setUpClass(cls):

        if not BlockDev.is_initialized():
            BlockDev.init(cls.requested_plugins, None)
        else:
            BlockDev.reinit(cls.requested_plugins, True, None)

    @tag_test(TestTags.EXTRADEPS, TestTags.NOSTORAGE)
    def test_missing_dependencies(self):
        """Verify that checking for technology support works as expected"""

        with fake_path(all_but="dasdfmt"):
            # dasdfmt is not available, so the s390 plugin should fail to load
            with self.assertRaisesRegex(GLib.GError, "The 'dasdfmt' utility is not available"):
                BlockDev.s390_is_tech_avail(BlockDev.S390Tech.DASD, BlockDev.S390TechMode.MODIFY)