Exemplo n.º 1
0
    def test_power_on_syson_vios(self, mock_vios, mock_job_p, mock_run_job):
        """Validates a power on job when system is already on."""
        mock_vios.adapter = self.adpt
        mock_vios.rmc_state = pvm_bp.RMCState.ACTIVE
        for err_prefix in power._ALREADY_POWERED_ON_ERRS:
            mock_run_job.reset_mock()
            mock_run_job.side_effect = pexc.JobRequestFailed(
                error='PowerOn', operation_name=err_prefix)

            # Invoke the run the job, but succeed because it is already
            # powered on
            power._power_on_off(mock_vios, 'PowerOn', '1111')

            # This specific error should cause a retry.
            self.assertEqual(1, mock_run_job.call_count)
Exemplo n.º 2
0
    def test_power_on_off_vios(self, mock_vios, mock_job_p, mock_run_job):
        """Performs a simple set of Power On/Off Tests."""
        mock_vios.adapter = self.adpt
        power._power_on_off(mock_vios, 'PowerOn', '1111')
        self.assertEqual(1, mock_run_job.call_count)
        self.assertEqual(0, mock_job_p.call_count)
        mock_run_job.reset_mock()
        mock_job_p.reset_mock()
        self.adpt.reset_mock()

        # Try a power off
        power._power_on_off(mock_vios, 'PowerOff', '1111')
        self.assertEqual(1, mock_run_job.call_count)
        # Only the operation parameter is appended
        self.assertEqual(1, mock_job_p.call_count)
        mock_run_job.reset_mock()
        mock_job_p.reset_mock()

        # Try a power off when the RMC state is active
        mock_vios.rmc_state = pvm_bp.RMCState.ACTIVE
        power._power_on_off(mock_vios, 'PowerOff', '1111')
        self.assertEqual(1, mock_run_job.call_count)
        # The operation and immediate(no-delay) parameters are appended
        self.assertEqual(2, mock_job_p.call_count)
        mock_vios.reset_mock()
        mock_run_job.reset_mock()
        mock_job_p.reset_mock()

        # Try a more complex power off
        power._power_on_off(mock_vios,
                            'PowerOff',
                            '1111',
                            force_immediate=True,
                            restart=True,
                            timeout=100)
        self.assertEqual(1, mock_run_job.call_count)
        self.assertEqual(3, mock_job_p.call_count)
        mock_run_job.reset_mock()
        mock_job_p.reset_mock()

        # Try optional parameters
        power.power_on(mock_vios,
                       '1111',
                       add_parms={power.BootMode.KEY: power.BootMode.SMS})
        self.assertEqual(1, mock_run_job.call_count)
        self.assertEqual(1, mock_job_p.call_count)
        mock_job_p.assert_called_with(power.BootMode.KEY, power.BootMode.SMS)
Exemplo n.º 3
0
    def test_power_on_off(self, mock_lpar, mock_job_p, mock_run_job):
        """Performs a simple set of Power On/Off Tests."""
        def run_job_mock(**kwargs1):
            """Produce a run_job method that validates the given kwarg values.

            E.g. run_job_mock(foo='bar') will produce a mock run_job that
            asserts its foo argument is 'bar'.
            """
            def run_job(*args, **kwargs2):
                for key, val in kwargs1.items():
                    self.assertEqual(val, kwargs2[key])
            return run_job

        mock_lpar.adapter = self.adpt
        power._power_on_off(mock_lpar, 'PowerOn', '1111')
        self.assertEqual(1, mock_run_job.call_count)
        self.assertEqual(0, mock_job_p.call_count)
        self.assertEqual(1, self.adpt.invalidate_cache_elem.call_count)
        mock_run_job.reset_mock()
        mock_job_p.reset_mock()
        self.adpt.reset_mock()

        # Try a power off
        power._power_on_off(mock_lpar, 'PowerOff', '1111')
        self.assertEqual(1, mock_run_job.call_count)
        # Only the operation parameter is appended
        self.assertEqual(1, mock_job_p.call_count)
        mock_run_job.reset_mock()
        mock_job_p.reset_mock()

        # Try a power off when the RMC state is active
        mock_lpar.rmc_state = pvm_bp.RMCState.ACTIVE
        power._power_on_off(mock_lpar, 'PowerOff', '1111')
        self.assertEqual(1, mock_run_job.call_count)
        # The operation and immediate(no-delay) parameters are appended
        self.assertEqual(2, mock_job_p.call_count)
        mock_lpar.reset_mock()
        mock_run_job.reset_mock()
        mock_job_p.reset_mock()

        # Try a power off of IBMi
        mock_lpar.rmc_state = pvm_bp.RMCState.INACTIVE
        mock_lpar.env = pvm_bp.LPARType.OS400
        mock_lpar.ref_code = '00000000'
        power._power_on_off(mock_lpar, 'PowerOff', '1111')
        self.assertEqual(1, mock_run_job.call_count)
        # Only the operation parameter is appended
        self.assertEqual(1, mock_job_p.call_count)
        mock_job_p.assert_called_with('operation', 'osshutdown')
        mock_lpar.reset_mock()
        mock_run_job.reset_mock()
        mock_job_p.reset_mock()

        # Try a more complex power off
        power._power_on_off(mock_lpar, 'PowerOff', '1111',
                            force_immediate=True, restart=True, timeout=100)
        self.assertEqual(1, mock_run_job.call_count)
        self.assertEqual(3, mock_job_p.call_count)
        mock_run_job.reset_mock()
        mock_job_p.reset_mock()

        mock_run_job.side_effect = run_job_mock(synchronous=True)
        # Try optional parameters
        power.power_on(mock_lpar, '1111',
                       add_parms={power.BootMode.KEY: power.BootMode.SMS})
        self.assertEqual(1, mock_run_job.call_count)
        self.assertEqual(1, mock_job_p.call_count)
        mock_job_p.assert_called_with(power.BootMode.KEY, power.BootMode.SMS)
        mock_run_job.reset_mock()
        mock_job_p.reset_mock()

        power.power_on(mock_lpar, '1111', add_parms={
            pvm_lpar.IPLSrc.KEY: pvm_lpar.IPLSrc.A}, synchronous=True)
        self.assertEqual(1, mock_run_job.call_count)
        self.assertEqual(1, mock_job_p.call_count)
        mock_job_p.assert_called_with(pvm_lpar.IPLSrc.KEY, pvm_lpar.IPLSrc.A)
        mock_run_job.reset_mock()
        mock_job_p.reset_mock()

        mock_run_job.side_effect = run_job_mock(synchronous=False)
        power.power_on(mock_lpar, '1111', add_parms={
            power.KeylockPos.KEY: power.KeylockPos.MANUAL}, synchronous=False)
        self.assertEqual(1, mock_run_job.call_count)
        self.assertEqual(1, mock_job_p.call_count)
        mock_job_p.assert_called_with(power.KeylockPos.KEY,
                                      power.KeylockPos.MANUAL)