Exemplo n.º 1
0
def raise_axapi_ex(response, method, api_url):
    if 'response' in response and 'err' in response['response']:
        code = response['response']['err']['code']

        # Check if this is a known error code that we want to map.
        if code in RESPONSE_CODES:
            ex_dict = RESPONSE_CODES[code]
            ex = None

            # Now match against specific HTTP method exceptions
            if method in ex_dict:
                x = ex_dict[method]
            else:
                x = ex_dict['*']

            # Now try to find specific API method exceptions
            matched = False
            for k in x.keys():
                if k != '*' and re.match('^' + k, api_url):
                    matched = True
                    ex = x[k]

            # If we get here, try for a fallback exception for this code
            if not matched and not ex and '*' in x:
                ex = x['*']

            # Alright, time to actually do something
            if ex:
                raise ex(code, response['response']['err']['msg'])
            else:
                return

        raise ae.ACOSException(code, response['response']['err']['msg'])

    raise ae.ACOSException()
Exemplo n.º 2
0
def raise_axapi_ex(response, action=None):
    if 'response' in response and 'err' in response['response']:
        code = response['response']['err']['code']

        if code in RESPONSE_CODES:
            ex_dict = RESPONSE_CODES[code]

            if action is not None and action in ex_dict:
                ex = ex_dict[action]
            else:
                ex = ex_dict.get('*')

            if ex is not None:
                raise ex(code, response['response']['err']['msg'])
            else:
                return

        raise ae.ACOSException(code, response['response']['err']['msg'])
    raise ae.ACOSException()
Exemplo n.º 3
0
 def test_HandleACOSPartitionChange_execute_create_partition_fail(
         self, mock_utils):
     mock_client = mock.Mock()
     mock_client.system.partition.get.side_effect = acos_errors.NotFound()
     mock_client.system.action.write_memory.side_effect = acos_errors.ACOSException(
     )
     mock_utils.get_axapi_client.return_value = mock_client
     mock_thunder = copy.deepcopy(VTHUNDER)
     mock_thunder.partition_name = "PartitionA"
     expected_error = acos_errors.ACOSException
     task_function = task.HandleACOSPartitionChange().execute
     self.assertRaises(expected_error, task_function, mock_thunder)