Beispiel #1
0
 def get(self, session, requires_id=True, error_message=None):
     stk = super(Stack, self).get(session, requires_id=requires_id,
                                  error_message=error_message)
     if stk and stk.status in ['DELETE_COMPLETE', 'ADOPT_COMPLETE']:
         raise exceptions.NotFoundException(
             "No stack found for %s" % stk.id)
     return stk
    def test_wait_for_delete(self):
        sess = mock.Mock()
        sot = FakeResource.new(**fake_data)
        sot.get = mock.MagicMock()
        sot.get.side_effect = [sot, exceptions.NotFoundException(mock.Mock())]

        self.assertEqual(sot, resource.wait_for_delete(sess, sot, 1, 2))
    def test_not_found_in_cache_active_introspection(self, mock_record):
        CONF.set_override('permit_active_introspection', True, 'processing')
        self.find_mock.side_effect = utils.NotFoundInCacheError('not found')
        self.cli.get_node.side_effect = os_exc.NotFoundException('boom')
        self.cache_fixture.mock.acquire_lock = mock.Mock()
        self.cache_fixture.mock.uuid = '1111'
        self.cache_fixture.mock.finished_at = None
        self.cache_fixture.mock.node = mock.Mock()
        mock_record.return_value = self.cache_fixture.mock
        res = process.process(self.data)

        self.assertEqual(self.fake_result_json, res)
        self.find_mock.assert_called_once_with(
            bmc_address=[self.bmc_address, self.bmc_v6address], mac=mock.ANY)
        actual_macs = self.find_mock.call_args[1]['mac']
        self.assertEqual(sorted(self.all_macs), sorted(actual_macs))
        mock_record.assert_called_once_with(bmc_addresses=[
            '1.2.3.4', '2001:1234:1234:1234:1234:1234:1234:1234/64'
        ],
                                            macs=mock.ANY)
        actual_macs = mock_record.call_args[1]['macs']
        self.assertEqual(sorted(self.all_macs), sorted(actual_macs))
        self.cli.get_node.assert_not_called()
        self.process_mock.assert_called_once_with(mock.ANY, mock.ANY,
                                                  self.data)
    def test_get_not_found(self):
        self.res.get.side_effect = exceptions.NotFoundException(
            message="test", http_status=404)

        # TODO(shade) The mock here does not mock the right things, so we're
        #             not testing the actual exception mechanism.
        self.assertRaisesRegex(exceptions.NotFoundException, "test",
                               self.sot._get, RetrieveableResource, self.res)
Beispiel #5
0
 def test_is_not_found(self):
     self.assertFalse(
         self.plugin.is_not_found(
             exceptions.HttpException(http_status=400)))
     self.assertFalse(self.plugin.is_not_found(Exception))
     self.assertTrue(
         self.plugin.is_not_found(
             exceptions.NotFoundException(http_status=404)))
Beispiel #6
0
    def test_get_not_found(self):
        self.res.get.side_effect = exceptions.NotFoundException(
            message="test", http_status=404)

        self.assertRaisesRegexp(
            exceptions.ResourceNotFound,
            "No %s found for %s" % (RetrieveableResource.__name__, self.res),
            self.sot._get, RetrieveableResource, self.res)
    def test_delete_ResourceNotFound(self):
        self.res.delete.side_effect = exceptions.NotFoundException(
            message="test", status_code=404)

        self.assertRaisesRegexp(
            exceptions.ResourceNotFound,
            "No %s found for %s" % (DeleteableResource.__name__, self.res),
            self.sot._delete, DeleteableResource, self.res,
            ignore_missing=False)
    def test_not_found_in_ironic(self):
        self.cli.get_node.side_effect = os_exc.NotFoundException()

        self.assertRaisesRegex(utils.Error,
                               'Node %s was not found' % self.uuid,
                               process.process, self.data)
        self.cli.get_node.assert_called_once_with(self.uuid)
        self.assertFalse(self.process_mock.called)
        self.node_info.finished.assert_called_once_with(istate.Events.error,
                                                        error=mock.ANY)
    def test_delete_NotFound(self):
        self.res.delete.side_effect = exceptions.NotFoundException(
            message="test", http_status=404)

        self.assertRaisesRegex(exceptions.NotFoundException,
                               "test",
                               self.sot._delete,
                               DeleteableResource,
                               self.res,
                               ignore_missing=False)
    def test_delete_NotFound(self):
        self.res.delete.side_effect = exceptions.NotFoundException(
            message="test", http_status=404)

        self.assertRaisesRegex(
            exceptions.NotFoundException,
            # TODO(shade) The mocks here are hiding the thing we want to test.
            "test",
            self.sot._delete,
            DeleteableResource,
            self.res,
            ignore_missing=False)
Beispiel #11
0
def handle_neutron_errors(method, *args, **kwargs):
    """Handle errors on openstacksdk router methods"""
    result = method(*args, **kwargs)
    if 'NeutronError' in result:
        error = result['NeutronError']
        if error['type'] in ('RouterNotFound',
                             'RouterInterfaceNotFoundForSubnet',
                             'SubnetNotFound'):
            raise os_exc.NotFoundException(message=error['message'])
        else:
            raise os_exc.SDKException(error['type'] + ": " + error['message'])

    return result
Beispiel #12
0
    def test_get(self, mock_get):
        sess = mock.Mock()
        sot = stack.Stack(**FAKE)
        deleted_stack = mock.Mock(id=FAKE_ID, status='DELETE_COMPLETE')
        normal_stack = mock.Mock(status='CREATE_COMPLETE')
        mock_get.side_effect = [
            normal_stack,
            exceptions.NotFoundException(message='oops'),
            deleted_stack,
        ]

        self.assertEqual(normal_stack, sot.get(sess))
        ex = self.assertRaises(exceptions.NotFoundException, sot.get, sess)
        self.assertEqual('oops', six.text_type(ex))
        ex = self.assertRaises(exceptions.NotFoundException, sot.get, sess)
        self.assertEqual('No stack found for %s' % FAKE_ID, six.text_type(ex))
    def test_failed_to_get_node(self, client_mock, start_mock):
        cli = client_mock.return_value
        cli.get_node.side_effect = os_exc.NotFoundException()
        self.assertRaisesRegex(utils.Error,
                               'Node %s was not found' % self.uuid,
                               introspect.introspect, self.uuid)

        cli.get_node.side_effect = os_exc.BadRequestException()
        self.assertRaisesRegex(utils.Error,
                               'Cannot get node %s: Error' % self.uuid,
                               introspect.introspect, self.uuid)

        self.assertEqual(0, self.node_info.ports.call_count)
        self.assertEqual(0, self.sync_filter_mock.call_count)
        self.assertEqual(0, cli.set_node_power_state.call_count)
        self.assertFalse(start_mock.called)
        self.assertFalse(self.node_info.acquire_lock.called)
Beispiel #14
0
 def map_exceptions_wrapper(*args, **kwargs):
     try:
         return func(*args, **kwargs)
     except _exceptions.HttpError as e:
         if e.http_status == 404:
             raise exceptions.NotFoundException(
                 message=e.message, details=e.details,
                 response=e.response, request_id=e.request_id,
                 url=e.url, method=e.method,
                 http_status=e.http_status, cause=e)
         else:
             raise exceptions.HttpException(
                 message=e.message, details=e.details,
                 response=e.response, request_id=e.request_id,
                 url=e.url, method=e.method,
                 http_status=e.http_status, cause=e)
     except _exceptions.ClientException as e:
         raise exceptions.SDKException(message=e.message, cause=e)
Beispiel #15
0
    def get_datastore_version(self, datastore, datastore_version):
        """Get the detail of a datastore version

        :param datastore: datastore name
        :param datastore_Version: id of the datastore version
        :returns: Detail of datastore version
        :rtype: :class:`~otcextensions.sdk.rds.v1.datastore.Datastore`
        """
        versions = self._list(
            _datastore.Datastore,
            paginated=False,
            # endpoint_override=self.get_rds_endpoint(),
            headers=self.get_os_headers(True),
            # project_id=self.session.get_project_id(),
            datastore_name=datastore)
        for ver in versions:
            if ver.id == datastore_version:
                return ver
        return exceptions.NotFoundException('Resource not found')
    def _translate_response(self, response, has_body=None, error_message=None):
        """Given a KSA response, inflate this instance with its data

        'DELETE' operations don't return a body, so only try to work
        with a body when has_body is True.

        This method updates attributes that correspond to headers
        and body on this instance and clears the dirty set.
        """
        if has_body is None:
            has_body = self.has_body
        # exceptions.raise_from_response(response, error_message=error_message)
        if has_body:
            body = response.json()

            errCode = body.get('errCode', None)
            if errCode and errCode == 'RDS.0041':
                if self.resource_key and self.resource_key in body:
                    body = body[self.resource_key]

                body = self._consume_body_attrs(body)
                self._body.attributes.update(body)
                self._body.clean()
            elif errCode and errCode == 'RDS.0028':
                raise exceptions.NotFoundException('Resource not found')
            elif errCode and errCode != 'RDS.0041':
                _logger.error('error during service invokation %s' % errCode)
                raise exceptions.SDKException(
                    body.get('externalMessage', body)
                )
            elif not errCode:
                if self.resource_key and self.resource_key in body:
                    body = body[self.resource_key]

                body = self._consume_body_attrs(body)
                self._body.attributes.update(body)
                self._body.clean()

        headers = self._consume_header_attrs(response.headers)
        self._header.attributes.update(headers)
        self._header.clean()
    def test_get_not_found(self):
        self.res.get.side_effect = exceptions.NotFoundException(
            message="test", http_status=404)

        self.assertRaisesRegex(exceptions.NotFoundException, "test",
                               self.sot._get, RetrieveableResource, self.res)
    def test_delete_ignore_missing(self):
        self.res.delete.side_effect = exceptions.NotFoundException(
            message="test", http_status=404)

        rv = self.sot._delete(DeleteableResource, self.fake_id)
        self.assertIsNone(rv)
 def test_store_find_node_error(self, hook_mock):
     self.cli.get_node.side_effect = os_exc.NotFoundException('boom')
     self.assertRaises(utils.Error, process.process, self.data)
     self._check_contents()
Beispiel #20
0
 def get(self, session, include_headers=False, args=None):
     stk = super(Stack, self).get(session, include_headers, args)
     if stk and stk.status in ['DELETE_COMPLETE', 'ADOPT_COMPLETE']:
         raise exceptions.NotFoundException("No stack found for %s" %
                                            stk.id)
     return stk
Beispiel #21
0
 def test_remove_not_found(self, mock_cli):
     mock_cli.return_value.remove_node_trait.side_effect = (
         os_exc.NotFoundException('trait not found'))
     self.act.apply(self.node_info, self.params)
     mock_cli.return_value.remove_node_trait.assert_called_once_with(
         self.uuid, 'CUSTOM_FOO')