Esempio n. 1
0
    def test_dlt_lpar(self, mock_vterm):
        """Performs a delete LPAR test."""
        vm.delete_lpar(self.apt, 'inst')
        self.get_pvm_uuid.assert_called_once_with('inst')
        self.apt.delete.assert_called_once_with(
            pvm_lpar.LPAR.schema_type, root_id=self.get_pvm_uuid.return_value)
        self.assertEqual(1, mock_vterm.call_count)

        # Test Failure Path
        # build a mock response body with the expected HSCL msg
        resp = mock.Mock()
        resp.body = 'error msg: HSCL151B more text'
        self.apt.delete.side_effect = pvm_exc.Error(
            'Mock Error Message', response=resp)

        # Reset counters
        self.apt.reset_mock()
        mock_vterm.reset_mock()

        self.assertRaises(pvm_exc.Error, vm.delete_lpar, self.apt, 'inst')
        self.assertEqual(1, mock_vterm.call_count)
        self.assertEqual(1, self.apt.delete.call_count)

        self.apt.reset_mock()
        mock_vterm.reset_mock()

        # Test HttpError 404
        resp.status = 404
        self.apt.delete.side_effect = pvm_exc.HttpError(resp=resp)
        vm.delete_lpar(self.apt, 'inst')
        self.assertEqual(1, mock_vterm.call_count)
        self.assertEqual(1, self.apt.delete.call_count)

        self.apt.reset_mock()
        mock_vterm.reset_mock()

        # Test Other HttpError
        resp.status = 111
        self.apt.delete.side_effect = pvm_exc.HttpError(resp=resp)
        self.assertRaises(pvm_exc.HttpError, vm.delete_lpar, self.apt, 'inst')
        self.assertEqual(1, mock_vterm.call_count)
        self.assertEqual(1, self.apt.delete.call_count)

        self.apt.reset_mock()
        mock_vterm.reset_mock()

        # Test HttpError 404 closing vterm
        resp.status = 404
        mock_vterm.side_effect = pvm_exc.HttpError(resp=resp)
        vm.delete_lpar(self.apt, 'inst')
        self.assertEqual(1, mock_vterm.call_count)
        self.assertEqual(0, self.apt.delete.call_count)

        self.apt.reset_mock()
        mock_vterm.reset_mock()

        # Test Other HttpError closing vterm
        resp.status = 111
        mock_vterm.side_effect = pvm_exc.HttpError(resp=resp)
        self.assertRaises(pvm_exc.HttpError, vm.delete_lpar, self.apt, 'inst')
        self.assertEqual(1, mock_vterm.call_count)
        self.assertEqual(0, self.apt.delete.call_count)
Esempio n. 2
0
 def execute(self):
     vm.delete_lpar(self.adapter, self.instance)
Esempio n. 3
0
    def test_dlt_lpar(self, mock_vterm):
        """Performs a delete LPAR test."""
        vm.delete_lpar(self.apt, 'inst')
        self.get_pvm_uuid.assert_called_once_with('inst')
        self.apt.delete.assert_called_once_with(
            pvm_lpar.LPAR.schema_type, root_id=self.get_pvm_uuid.return_value)
        self.assertEqual(1, mock_vterm.call_count)

        # Test Failure Path
        # build a mock response body with the expected HSCL msg
        resp = mock.Mock()
        resp.body = 'error msg: HSCL151B more text'
        self.apt.delete.side_effect = pvm_exc.Error('Mock Error Message',
                                                    response=resp)

        # Reset counters
        self.apt.reset_mock()
        mock_vterm.reset_mock()

        self.assertRaises(pvm_exc.Error, vm.delete_lpar, self.apt, 'inst')
        self.assertEqual(1, mock_vterm.call_count)
        self.assertEqual(1, self.apt.delete.call_count)

        self.apt.reset_mock()
        mock_vterm.reset_mock()

        # Test HttpError 404
        resp.status = 404
        self.apt.delete.side_effect = pvm_exc.HttpError(resp=resp)
        vm.delete_lpar(self.apt, 'inst')
        self.assertEqual(1, mock_vterm.call_count)
        self.assertEqual(1, self.apt.delete.call_count)

        self.apt.reset_mock()
        mock_vterm.reset_mock()

        # Test Other HttpError
        resp.status = 111
        self.apt.delete.side_effect = pvm_exc.HttpError(resp=resp)
        self.assertRaises(pvm_exc.HttpError, vm.delete_lpar, self.apt, 'inst')
        self.assertEqual(1, mock_vterm.call_count)
        self.assertEqual(1, self.apt.delete.call_count)

        self.apt.reset_mock()
        mock_vterm.reset_mock()

        # Test HttpError 404 closing vterm
        resp.status = 404
        mock_vterm.side_effect = pvm_exc.HttpError(resp=resp)
        vm.delete_lpar(self.apt, 'inst')
        self.assertEqual(1, mock_vterm.call_count)
        self.assertEqual(0, self.apt.delete.call_count)

        self.apt.reset_mock()
        mock_vterm.reset_mock()

        # Test Other HttpError closing vterm
        resp.status = 111
        mock_vterm.side_effect = pvm_exc.HttpError(resp=resp)
        self.assertRaises(pvm_exc.HttpError, vm.delete_lpar, self.apt, 'inst')
        self.assertEqual(1, mock_vterm.call_count)
        self.assertEqual(0, self.apt.delete.call_count)
Esempio n. 4
0
File: vm.py Progetto: Juniper/nova
 def execute(self):
     vm.delete_lpar(self.adapter, self.instance)