File: test_http_error.py

package info (click to toggle)
python-pypowervm 1.1.24%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 7,400 kB
  • sloc: python: 29,780; xml: 174; makefile: 14
file content (77 lines) | stat: -rw-r--r-- 3,150 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
# Copyright 2015, 2016 IBM Corp.
#
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import unittest

import mock

from pypowervm.tests.test_utils import pvmhttp
import pypowervm.wrappers.http_error as he

HTTPRESP_FILE = "fake_httperror.txt"

MSG = ('Unexpected error occurred while fetching Cluster/SSP '
       'information : 9999-99Z*2125D4A/1 : Unable to send com'
       'mand to VIOS at this moment. VIOS 1*9999-99Z*2125D4A '
       'is busy processing some other request. Please retry t'
       'he operation after sometime.')
MSG2 = ('Error occurred while querying for Adapter from VIOS vios1 with ID 2 '
        'in System 9119-MHE*1085B07 -  The system is currently too busy to '
        'complete the specified request. Please retry the operation at a '
        'later time. If the operation continues to fail, check the error log '
        'to see if the filesystem is full.')
REASON_CODE = 'Unknown internal error.'


class TestHttpError(unittest.TestCase):

    def setUp(self):
        super(TestHttpError, self).setUp()

        self.http_error = pvmhttp.load_pvm_resp(HTTPRESP_FILE)
        self.assertIsNotNone(self.http_error,
                             "Could not load %s " %
                             HTTPRESP_FILE)

    def test_wrap(self):
        wrap = he.HttpError.wrap(self.http_error.response.entry)
        self.assertEqual(wrap.message, MSG)
        self.assertEqual(wrap.status, 500)
        self.assertEqual(wrap.reason_code, REASON_CODE)

        self.assertTrue(wrap.is_vios_busy())
        # Ensure it's checking for 500 only.
        with mock.patch.object(wrap, '_get_val_int', return_value=555):
            self.assertFalse(wrap.is_vios_busy())
        # Ensure it's checking for 'VIOS' string.
        with mock.patch.object(wrap, '_get_val_str', return_value='other'):
            self.assertFalse(wrap.is_vios_busy())
        # Ensure it finds 'VIOS' but not the other string.
        with mock.patch.object(wrap, '_get_val_str', return_value='VIOS xxx'):
            self.assertFalse(wrap.is_vios_busy())

        # Ensure it finds 'HSCL' return code.
        msg_string = 'msg HSCL3205 msg'
        with mock.patch.object(wrap, '_get_val_str', return_value=msg_string):
            self.assertTrue(wrap.is_vios_busy())

        msg_string = 'msg VIOS0014 msg'
        with mock.patch.object(wrap, '_get_val_str', return_value=msg_string):
            self.assertTrue(wrap.is_vios_busy())

        # Ensure we find the new message
        with mock.patch.object(wrap, '_get_val_str', return_value=MSG2):
            self.assertTrue(wrap.is_vios_busy())