Пример #1
0
    def test_write_to_conf(self, mock_write):
        """
        Unittest to write smt val to zipl file.
        """
        data = """
        [defaultboot]
default=linux
target=/boot
[linux]
        image=/boot/vmlinuz-4.4.0-25.44.el7_2.kvmibm1_1_3.1.s390x
        ramdisk=/boot/initramfs-4.4.0-25.44.el7_2.kvmibm1_1_3.1.s390x.img
        parameters="vconsole.keymap=us elevator=deadline pci=on zfcp.
        allow_lun_scan=0 root=/dev/mapper/zkvm-root rd.lvm.lv=zkvm/root
        crashkernel=128M rd.zfcp=0.0.9200,0x50050763071046a6,
        0x4013400f00000000 LANG=en_US.UTF-8 rd.zfcp=0.0.9200,
        0x50050763070386a6,0x4013400f00000000 vconsole.font=latarcyrhe smt=2"
       """
        name = "dummy"
        smt_val = 2
        open_mock = mock.mock_open(read_data=data)
        with mock.patch('wok.plugins.ginger.model.utils.open',
                        open_mock, create=True):
            smtmodel = SmtModel()
            smtmodel.write_zipl_file(name, smt_val)
            mock_write.return_value = {}
            smtmodel.write_zipl_file(name, smt_val)
Пример #2
0
 def test_get_smt_status_notsupported(self, mock_smt_suport):
     """
     Unittest to fetch smt status when smt not supported.
     """
     mock_smt_suport.return_value = False
     with self.assertRaisesRegexp(OperationFailed, 'GINSMT0006E'):
         smtmodel = SmtModel()
         smtmodel.get_smt_status_s390x()
         mock_smt_suport.assert_called_with()
Пример #3
0
 def test_get_smt_status_notsupported(self, mock_smt_suport):
     """
     Unittest to fetch smt status when smt not supported.
     """
     mock_smt_suport.return_value = False
     with self.assertRaisesRegexp(OperationFailed, 'GINSMT0006E'):
         smtmodel = SmtModel()
         smtmodel.get_smt_status_s390x()
         mock_smt_suport.assert_called_with()
Пример #4
0
 def test_load_smt_s390x(self, mock_run):
     """
     Unittest to load SMT.
     """
     backup = "dfdf"
     mock_run.return_value = ["", "", 0]
     command = ['zipl']
     smtmodel = SmtModel()
     smtmodel.load_smt_s390x(backup)
     mock_run.assert_called_once_with(command)
Пример #5
0
 def test_load_smt_s390x(self, mock_run):
     """
     Unittest to load SMT.
     """
     backup = "dfdf"
     mock_run.return_value = ["", "", 0]
     command = ['zipl']
     smtmodel = SmtModel()
     smtmodel.load_smt_s390x(backup)
     mock_run.assert_called_once_with(command)
Пример #6
0
 def test_enable_s390x_success(self, mock_load, mock_write, mock_is_file,
                               mock_shutil):
     """
     Unittest to enable SMT success scenario.
     """
     smt_val = '1'
     name = "dummy"
     mock_is_file.return_value = True
     mock_shutil.return_value = {}
     mock_write.return_value = {}
     mock_load.return_value = {}
     smtmodel = SmtModel()
     smtmodel.enable_smt_s390x(name, smt_val)
Пример #7
0
 def test_enable_s390x_success(self, mock_load, mock_write,
                               mock_is_file, mock_shutil):
     """
     Unittest to enable SMT success scenario.
     """
     smt_val = '1'
     name = "dummy"
     mock_is_file.return_value = True
     mock_shutil.return_value = {}
     mock_write.return_value = {}
     mock_load.return_value = {}
     smtmodel = SmtModel()
     smtmodel.enable_smt_s390x(name, smt_val)
Пример #8
0
 def test_get_smt_status_supported(self, mock_current,
                                   mock_persistent, mock_smt_suport):
     """
     Unittest to fetch smt status
     """
     current_info = {"status": "enabled", "smt": "2"}
     perisistent_info = {"status": "enabled", "smt": "2"}
     mock_smt_suport.return_value = True
     mock_current.return_value = current_info
     mock_persistent.return_value = perisistent_info
     smtmodel = SmtModel()
     out = smtmodel.get_smt_status_s390x()
     mock_smt_suport.assert_called_with()
     self.assertEqual(len(out), 2)
Пример #9
0
 def test_get_smt_status_supported(self, mock_current, mock_persistent,
                                   mock_smt_suport):
     """
     Unittest to fetch smt status
     """
     current_info = {"status": "enabled", "smt": "2"}
     perisistent_info = {"status": "enabled", "smt": "2"}
     mock_smt_suport.return_value = True
     mock_current.return_value = current_info
     mock_persistent.return_value = perisistent_info
     smtmodel = SmtModel()
     out = smtmodel.get_smt_status_s390x()
     mock_smt_suport.assert_called_with()
     self.assertEqual(len(out), 2)
Пример #10
0
 def test_get_current_smt_s390x(self, mock_run, mock_threads):
     """
     Unittest to get the current SMT setting from /proc/cmdline
     """
     output = "elevator=deadline crashkernel=196M " \
              "zfcp.no_auto_port_rescan=1 zfcp." \
              "allow_lun_scan=0 cmma=on pci=on " \
              "root=/dev/disk/by-path/ccw-0.0.518e-part1 " \
              "rd_DASD=0.0.518e BOOT_IMAGE=0 smt=1"
     mock_threads.return_value = 1
     mock_run.return_value = [output, "", 0]
     smtmodel = SmtModel()
     out = smtmodel.get_current_settings_s390x()
     self.assertEqual(out['smt'], 1)
     self.assertEqual(out['status'], 'enabled')
Пример #11
0
 def test_get_current_smt_s390x(self, mock_run, mock_threads):
     """
     Unittest to get the current SMT setting from /proc/cmdline
     """
     output = "elevator=deadline crashkernel=196M " \
              "zfcp.no_auto_port_rescan=1 zfcp." \
              "allow_lun_scan=0 cmma=on pci=on " \
              "root=/dev/disk/by-path/ccw-0.0.518e-part1 " \
              "rd_DASD=0.0.518e BOOT_IMAGE=0 smt=1"
     mock_threads.return_value = 1
     mock_run.return_value = [output, "", 0]
     smtmodel = SmtModel()
     out = smtmodel.get_current_settings_s390x()
     self.assertEqual(out['smt'], 1)
     self.assertEqual(out['status'], 'enabled')
Пример #12
0
    def test_disable_s390x_invalid(self, mock_load, mock_get, mock_is_file):

        """
        Unittest to disable SMT invalid scenario.
        """
        info = {
            "persisted_smt_settings": {"status": "enabled", "smt": "2"},
            "current_smt_settings": {"status": "disabled", "smt": "nosmt"}
        }
        name = "dummy"

        with self.assertRaisesRegexp(InvalidOperation, 'GINSMT0005E'):
            mock_get.return_value = info
            mock_is_file.return_value = True
            mock_load.return_value = {}
            smtmodel = SmtModel()
            smtmodel.disable_smt_s390x(name)
Пример #13
0
    def test_disable_success(self, mock_load, mock_get, mock_is_file,
                             mock_shutil, mock_fileinput):

        """
        Unittest for disabling SMT success scenario.
        """
        info = {
            "persisted_smt_settings": {"status": "enabled", "smt": "2"},
            "current_smt_settings": {"status": "enabled", "smt": "nosmt"}
        }
        name = "dummy"
        mock_get.return_value = info
        mock_is_file.return_value = True
        mock_shutil.return_value = {}
        mock_fileinput.return_value = {}
        mock_load.return_value = {}
        smtmodel = SmtModel()
        smtmodel.disable_smt_s390x(name)
Пример #14
0
 def test_enable_s390x_invalid(self, mock_load, mock_write):
     """
     Unittest to enable SMT for invalid parameter.
     """
     name = "dummy"
     smt_val = "sdsd"
     mock_write.return_value = {}
     mock_load.return_value = {}
     smtmodel = SmtModel()
     self.assertRaises(InvalidParameter, smtmodel.enable_smt_s390x, smt_val,
                       name)
Пример #15
0
    def test_write_to_conf(self, mock_write):
        """
        Unittest to write smt val to zipl file.
        """
        data = """
        [defaultboot]
default=linux
target=/boot
[linux]
        image=/boot/vmlinuz-4.4.0-25.44.el7_2.kvmibm1_1_3.1.s390x
        ramdisk=/boot/initramfs-4.4.0-25.44.el7_2.kvmibm1_1_3.1.s390x.img
        parameters="vconsole.keymap=us elevator=deadline pci=on zfcp.
        allow_lun_scan=0 root=/dev/mapper/zkvm-root rd.lvm.lv=zkvm/root
        crashkernel=128M rd.zfcp=0.0.9200,0x50050763071046a6,
        0x4013400f00000000 LANG=en_US.UTF-8 rd.zfcp=0.0.9200,
        0x50050763070386a6,0x4013400f00000000 vconsole.font=latarcyrhe smt=2"
       """
        name = "dummy"
        smt_val = 2
        open_mock = mock.mock_open(read_data=data)
        with mock.patch('wok.plugins.ginger.model.utils.open',
                        open_mock,
                        create=True):
            smtmodel = SmtModel()
            smtmodel.write_zipl_file(name, smt_val)
            mock_write.return_value = {}
            smtmodel.write_zipl_file(name, smt_val)
Пример #16
0
    def test_disable_s390x_invalid(self, mock_load, mock_get, mock_is_file):
        """
        Unittest to disable SMT invalid scenario.
        """
        info = {
            'persisted_smt_settings': {
                'status': 'enabled',
                'smt': '2'
            },
            'current_smt_settings': {
                'status': 'disabled',
                'smt': 'nosmt'
            }
        }
        name = 'dummy'

        with self.assertRaisesRegexp(InvalidOperation, 'GINSMT0005E'):
            mock_get.return_value = info
            mock_is_file.return_value = True
            mock_load.return_value = {}
            smtmodel = SmtModel()
            smtmodel.disable_smt_s390x(name)
Пример #17
0
    def test_disable_s390x_invalid(self, mock_load, mock_get, mock_is_file):
        """
        Unittest to disable SMT invalid scenario.
        """
        info = {
            "persisted_smt_settings": {
                "status": "enabled",
                "smt": "2"
            },
            "current_smt_settings": {
                "status": "disabled",
                "smt": "nosmt"
            }
        }
        name = "dummy"

        with self.assertRaisesRegexp(InvalidOperation, 'GINSMT0005E'):
            mock_get.return_value = info
            mock_is_file.return_value = True
            mock_load.return_value = {}
            smtmodel = SmtModel()
            smtmodel.disable_smt_s390x(name)
Пример #18
0
 def test_disable_success(self, mock_load, mock_get, mock_is_file,
                          mock_shutil, mock_fileinput):
     """
     Unittest for disabling SMT success scenario.
     """
     info = {
         "persisted_smt_settings": {
             "status": "enabled",
             "smt": "2"
         },
         "current_smt_settings": {
             "status": "enabled",
             "smt": "nosmt"
         }
     }
     name = "dummy"
     mock_get.return_value = info
     mock_is_file.return_value = True
     mock_shutil.return_value = {}
     mock_fileinput.return_value = {}
     mock_load.return_value = {}
     smtmodel = SmtModel()
     smtmodel.disable_smt_s390x(name)
Пример #19
0
 def test_disable_success(self, mock_load, mock_get, mock_is_file,
                          mock_shutil, mock_fileinput):
     """
     Unittest for disabling SMT success scenario.
     """
     info = {
         'persisted_smt_settings': {
             'status': 'enabled',
             'smt': '2'
         },
         'current_smt_settings': {
             'status': 'enabled',
             'smt': 'nosmt'
         }
     }
     name = 'dummy'
     mock_get.return_value = info
     mock_is_file.return_value = True
     mock_shutil.return_value = {}
     mock_fileinput.return_value = {}
     mock_load.return_value = {}
     smtmodel = SmtModel()
     smtmodel.disable_smt_s390x(name)
Пример #20
0
 def has_smt(self):
     if ARCH.startswith('s390x') and SmtModel().check_smt_support():
         return True
     else:
         return False