本文整理汇总了Python中openstack.exceptions.BadRequestException方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.BadRequestException方法的具体用法?Python exceptions.BadRequestException怎么用?Python exceptions.BadRequestException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openstack.exceptions
的用法示例。
在下文中一共展示了exceptions.BadRequestException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ensure_listener_bad_request_exception
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import BadRequestException [as 别名]
def test_ensure_listener_bad_request_exception(self):
cls = d_lbaasv2.LBaaSv2Driver
m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
name = 'TEST_NAME'
project_id = 'TEST_PROJECT'
subnet_id = 'D3FA400A-F543-4B91-9CD3-047AF0CE42D1'
ip = '1.2.3.4'
loadbalancer_id = '00EE9E11-91C2-41CF-8FD4-7970579E5C4C'
port = 1234
protocol = 'TCP'
provider = 'amphora'
loadbalancer = obj_lbaas.LBaaSLoadBalancer(
id=loadbalancer_id, name=name, project_id=project_id,
subnet_id=subnet_id, ip=ip, provider=provider)
m_driver._ensure_provisioned.side_effect = os_exc.BadRequestException
resp = cls.ensure_listener(m_driver, loadbalancer,
protocol, port)
self.assertIsNone(resp)
示例2: test_create_pool_conflict
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import BadRequestException [as 别名]
def test_create_pool_conflict(self):
cls = d_lbaasv2.LBaaSv2Driver
m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
lb_algorithm = 'ROUND_ROBIN'
pool = obj_lbaas.LBaaSPool(
name='TEST_NAME', project_id='TEST_PROJECT', protocol='TCP',
listener_id='A57B7771-6050-4CA8-A63C-443493EC98AB',
loadbalancer_id='00EE9E11-91C2-41CF-8FD4-7970579E5C4C')
req = {
'name': pool.name,
'project_id': pool.project_id,
'listener_id': pool.listener_id,
'loadbalancer_id': pool.loadbalancer_id,
'protocol': pool.protocol,
'lb_algorithm': lb_algorithm}
lbaas.create_pool.side_effect = os_exc.BadRequestException
self.assertRaises(os_exc.BadRequestException, cls._create_pool,
m_driver, pool)
lbaas.create_pool.assert_called_once_with(**req)
示例3: test_add_subnet_to_router_already_connected
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import BadRequestException [as 别名]
def test_add_subnet_to_router_already_connected(self):
cls = subnet_drv.NamespacePodSubnetDriver
m_driver = mock.MagicMock(spec=cls)
subnet_id = mock.sentinel.subnet_id
os_net = self.useFixture(k_fix.MockNetworkClient()).client
os_net.add_interface_to_router.side_effect = (
os_exc.BadRequestException)
router_id = 'router1'
oslo_cfg.CONF.set_override('pod_router',
router_id,
group='namespace_subnet')
router_id_resp = cls.add_subnet_to_router(m_driver, subnet_id)
self.assertEqual(router_id_resp, router_id)
os_net.add_interface_to_router.assert_called_once()
示例4: test_delete_metadata_error
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import BadRequestException [as 别名]
def test_delete_metadata_error(self):
sess = mock.Mock()
response = mock.Mock()
response.status_code = 400
response.content = None
sess.delete.return_value = response
sot = server.Server(id=IDENTIFIER)
key = "hey"
self.assertRaises(
exceptions.BadRequestException,
sot.delete_metadata,
sess,
[key])
示例5: test_set_metadata_error
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import BadRequestException [as 别名]
def test_set_metadata_error(self):
sess = mock.Mock()
response = mock.Mock()
response.status_code = 400
response.content = None
sess.post.return_value = response
sot = server.Server(id=IDENTIFIER)
set_meta = {"lol": "rofl"}
self.assertRaises(
exceptions.BadRequestException,
sot.set_metadata,
sess,
**set_meta)
示例6: test_raise_bad_request_exception
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import BadRequestException [as 别名]
def test_raise_bad_request_exception(self):
response = mock.Mock()
response.status_code = 400
response.headers = {
'content-type': 'application/json',
'x-openstack-request-id': uuid.uuid4().hex,
}
exc = self.assertRaises(exceptions.BadRequestException,
self._do_raise, response,
error_message=self.message)
self.assertEqual(self.message, exc.message)
self.assertEqual(response.status_code, exc.status_code)
self.assertEqual(
response.headers.get('x-openstack-request-id'),
exc.request_id
)
示例7: get_node
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import BadRequestException [as 别名]
def get_node(node_id, ironic=None, **kwargs):
"""Get a node from Ironic.
:param node_id: node UUID or name.
:param ironic: ironic client instance.
:param kwargs: arguments to pass to Ironic client.
:raises: Error on failure
"""
ironic = ironic if ironic is not None else get_client()
try:
node = ironic.get_node(node_id, **kwargs)
node.uuid = node.id
except os_exc.ResourceNotFound:
raise NotFound(node_id)
except os_exc.BadRequestException as exc:
raise utils.Error(_("Cannot get node %(node)s: %(exc)s") %
{'node': node_id, 'exc': exc})
return node
示例8: test_power_failure
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import BadRequestException [as 别名]
def test_power_failure(self, client_mock, start_mock):
cli = self._prepare(client_mock)
cli.set_node_power_state.side_effect = os_exc.BadRequestException()
start_mock.return_value = self.node_info
self.async_exc = (utils.Error, 'Failed to power on')
introspect.introspect(self.node.uuid)
cli.get_node.assert_called_once_with(self.uuid)
start_mock.assert_called_once_with(self.uuid,
bmc_address=[self.bmc_address],
manage_boot=True,
ironic=cli)
cli.set_node_boot_device.assert_called_once_with(self.uuid,
'pxe',
persistent=False)
cli.set_node_power_state.assert_called_once_with(self.uuid,
'rebooting')
start_mock.return_value.finished.assert_called_once_with(
introspect.istate.Events.error, error=mock.ANY)
self.node_info.acquire_lock.assert_called_once_with()
self.node_info.release_lock.assert_called_once_with()
示例9: test_set_boot_device_failure
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import BadRequestException [as 别名]
def test_set_boot_device_failure(self, client_mock, start_mock):
cli = self._prepare(client_mock)
cli.set_node_boot_device.side_effect = os_exc.BadRequestException()
start_mock.return_value = self.node_info
self.async_exc = (utils.Error, 'Failed to set boot device')
introspect.introspect(self.node.uuid)
cli.get_node.assert_called_once_with(self.uuid)
start_mock.assert_called_once_with(self.uuid,
bmc_address=[self.bmc_address],
manage_boot=True,
ironic=cli)
cli.set_node_boot_device.assert_called_once_with(self.uuid,
'pxe',
persistent=False)
cli.set_node_power_state.assert_not_called()
start_mock.return_value.finished.assert_called_once_with(
introspect.istate.Events.error, error=mock.ANY)
self.node_info.acquire_lock.assert_called_once_with()
self.node_info.release_lock.assert_called_once_with()
示例10: _ensure_provisioned
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import BadRequestException [as 别名]
def _ensure_provisioned(self, loadbalancer, obj, create, find,
interval=_LB_STS_POLL_FAST_INTERVAL):
for remaining in self._provisioning_timer(_ACTIVATION_TIMEOUT,
interval):
self._wait_for_provisioning(loadbalancer, remaining, interval)
try:
result = self._ensure(create, find, obj, loadbalancer)
if result:
return result
except os_exc.BadRequestException:
raise
except os_exc.SDKException:
pass
raise k_exc.ResourceNotReady(obj)
示例11: _release
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import BadRequestException [as 别名]
def _release(self, loadbalancer, obj, delete, *args, **kwargs):
for remaining in self._provisioning_timer(_ACTIVATION_TIMEOUT):
try:
try:
delete(*args, **kwargs)
return
except (os_exc.ConflictException, os_exc.BadRequestException):
self._wait_for_provisioning(loadbalancer, remaining)
except os_exc.NotFoundException:
return
raise k_exc.ResourceNotReady(obj)
示例12: add_subnet_to_router
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import BadRequestException [as 别名]
def add_subnet_to_router(self, subnet_id):
os_net = clients.get_network_client()
router_id = oslo_cfg.CONF.namespace_subnet.pod_router
try:
# connect the subnet to the router
os_net.add_interface_to_router(router_id, subnet_id=subnet_id)
except os_exc.BadRequestException:
LOG.debug("Subnet %s already connected to the router", subnet_id)
except os_exc.SDKException:
LOG.exception("Error attaching the subnet %s to the router",
subnet_id)
raise
return router_id
示例13: test_release_with_wait
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import BadRequestException [as 别名]
def test_release_with_wait(self):
cls = d_lbaasv2.LBaaSv2Driver
m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
loadbalancer = mock.sentinel.loadbalancer
obj = mock.sentinel.obj
m_delete = mock.Mock()
timer = [mock.sentinel.t0, mock.sentinel.t1]
m_driver._provisioning_timer.return_value = timer
m_delete.side_effect = [os_exc.BadRequestException, None]
cls._release(m_driver, loadbalancer, obj, m_delete)
m_driver._wait_for_provisioning.assert_called_once_with(loadbalancer,
mock.ANY)
self.assertEqual(2, m_delete.call_count)
示例14: get
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import BadRequestException [as 别名]
def get(self, dns_zone_id):
try:
return OpenStackDnsZone(
self.provider,
self.provider.os_conn.dns.get_zone(dns_zone_id))
except (ResourceNotFound, NotFoundException, BadRequestException):
log.debug("Dns Zone %s not found.", dns_zone_id)
return None
示例15: test_create_firewall_rule_bad_protocol
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import BadRequestException [as 别名]
def test_create_firewall_rule_bad_protocol(self):
bad_rule = self._mock_firewall_rule_attrs.copy()
del bad_rule['id'] # id not allowed
bad_rule['ip_version'] = 5
self.register_uris([
# no validate due to added location key
dict(method='POST',
uri=self._make_mock_url('firewall_rules'),
status_code=400,
json={})
])
self.assertRaises(exceptions.BadRequestException,
self.cloud.create_firewall_rule, **bad_rule)
self.assert_calls()