Пример #1
0
 def test_update_inventory_conflict_exception(self):
     inventory = mock.ANY
     self.placement_fixture.mock_put.side_effect = ks_exc.Conflict()
     self.assertRaises(n_exc.PlacementInventoryUpdateConflict,
                       self.placement_api_client.update_inventory,
                       RESOURCE_PROVIDER_UUID, inventory,
                       RESOURCE_CLASS_NAME)
Пример #2
0
 def test_update_resource_inventory_inventory_conflict_exception(self):
     self.placement_fixture.mock_put.side_effect = ks_exc.Conflict()
     self.assertRaises(
         n_exc.PlacementInventoryUpdateConflict,
         self.placement_api_client.update_resource_provider_inventory,
         RESOURCE_PROVIDER_UUID,
         INVENTORY,
         RESOURCE_CLASS_NAME,
         resource_provider_generation=1)
Пример #3
0
def get_rule_id_from_name(client, parsed_args):
    results = client.list_policy_rules(parsed_args.policy_name)['results']
    rule_id = None
    for result in results:
        if result.get('name') == parsed_args.rule_id:
            if rule_id is None:
                rule_id = result.get('id')
            else:
                raise exceptions.Conflict(
                    "[Multiple rules with same name: %s]" %
                    parsed_args.rule_id)
    if rule_id is None:
        raise exceptions.NotFound("[No rule found with name: %s]" %
                                  parsed_args.rule_id)
    return rule_id
Пример #4
0
 def test_update_rp_inventories_raise_other_conflict(self):
     mock_resp = mock.Mock()
     mock_resp.text = ''
     mock_resp.json = lambda: {'errors': [{'code': 'some_other_code'}]}
     self.placement_fixture.mock_put.side_effect = [
         ks_exc.Conflict(response=mock_resp),
         mock.Mock(),
     ]
     self.assertRaises(
         n_exc.PlacementClientError,
         self.placement_api_client.update_resource_provider_inventories,
         resource_provider_uuid='resource provider uuid',
         inventories={},
         resource_provider_generation=None,
     )
     self.assertEqual(1, self.placement_fixture.mock_put.call_count)
Пример #5
0
    def test_group_create_or_show(self):
        self.groups_mock.create.side_effect = ks_exc.Conflict()
        arglist = [
            '--or-show',
            self.group.name,
        ]
        verifylist = [
            ('or_show', True),
            ('name', self.group.name),
        ]
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        columns, data = self.cmd.take_action(parsed_args)
        self.groups_mock.get.assert_called_once_with(self.group.name)
        self.assertEqual(self.columns, columns)
        self.assertEqual(self.data, data)
Пример #6
0
 def test_update_rp_inventories_callee_handles_generation_conflict(self):
     mock_resp = mock.Mock()
     mock_resp.text = ''
     mock_resp.json = lambda: {
         'errors': [{
             'code': 'placement.concurrent_update'
         }]
     }
     self.placement_fixture.mock_put.side_effect = [
         ks_exc.Conflict(response=mock_resp),
         mock.Mock(),
     ]
     self.placement_api_client.update_resource_provider_inventories(
         resource_provider_uuid='resource provider uuid',
         inventories={},
         resource_provider_generation=None,
     )
     self.assertEqual(2, self.placement_fixture.mock_put.call_count)
Пример #7
0
 def test_update_rp_inventories_caller_handles_generation_conflict(self):
     mock_resp = mock.Mock()
     mock_resp.text = ''
     mock_resp.json = lambda: {
         'errors': [{
             'code': 'placement.concurrent_update'
         }]
     }
     self.placement_fixture.mock_put.side_effect = ks_exc.Conflict(
         response=mock_resp)
     self.assertRaises(
         n_exc.PlacementResourceProviderGenerationConflict,
         self.placement_api_client.update_resource_provider_inventories,
         resource_provider_uuid='resource provider uuid',
         inventories={},
         resource_provider_generation=3,
     )
     self.placement_fixture.mock_put.assert_called_once()
Пример #8
0
 def test_update_qos_minbwallocation_generation_conflict_solved(self):
     mock_rsp_get = self._get_allocation_response({'c': 3})
     self.placement_fixture.mock_get.side_effect = 2 * [mock_rsp_get]
     mock_rsp_put = mock.Mock()
     mock_rsp_put.json = lambda: {
         'errors': [{
             'code': 'placement.concurrent_update'
         }]
     }
     self.placement_fixture.mock_put.side_effect = [
         ks_exc.Conflict(response=mock_rsp_put),
         mock.Mock()
     ]
     self.placement_api_client.update_qos_minbw_allocation(
         consumer_uuid=CONSUMER_UUID,
         minbw_alloc_diff={},
         rp_uuid=RESOURCE_PROVIDER_UUID)
     self.assertEqual(2, self.placement_fixture.mock_put.call_count)
Пример #9
0
 def test_update_rp_inventories_reached_max_tries(self):
     mock_resp = mock.Mock()
     mock_resp.text = ''
     mock_resp.json = lambda: {
         'errors': [{
             'code': 'placement.concurrent_update'
         }]
     }
     self.placement_fixture.mock_put.side_effect = 10 * [
         ks_exc.Conflict(response=mock_resp),
     ]
     self.assertRaises(
         n_exc.PlacementResourceProviderGenerationConflict,
         self.placement_api_client.update_resource_provider_inventories,
         resource_provider_uuid='resource provider uuid',
         inventories={},
         resource_provider_generation=None,
     )
     self.assertEqual(10, self.placement_fixture.mock_put.call_count)
Пример #10
0
 def test_update_qos_minbw_allocation_max_retries(self):
     mock_rsp_get = self._get_allocation_response({'c': 3})
     self.placement_fixture.mock_get.side_effect = 10 * [mock_rsp_get]
     mock_rsp_put = mock.Mock()
     mock_rsp_put.json = lambda: {
         'errors': [{
             'code': 'placement.concurrent_update'
         }]
     }
     self.placement_fixture.mock_put.side_effect = ks_exc.Conflict(
         response=mock_rsp_put)
     self.assertRaises(
         n_exc.PlacementAllocationGenerationConflict,
         self.placement_api_client.update_qos_minbw_allocation,
         consumer_uuid=CONSUMER_UUID,
         minbw_alloc_diff={},
         rp_uuid=RESOURCE_PROVIDER_UUID,
     )
     self.assertEqual(10, self.placement_fixture.mock_put.call_count)
Пример #11
0
 def test_update_qos_minbw_allocation_other_conflict(self):
     mock_rsp_get = self._get_allocation_response({'c': 3})
     self.placement_fixture.mock_get.side_effect = 10 * [mock_rsp_get]
     mock_rsp_put = mock.Mock()
     mock_rsp_put.text = ''
     mock_rsp_put.json = lambda: {
         'errors': [{
             'code': 'some other error code'
         }]
     }
     self.placement_fixture.mock_put.side_effect = ks_exc.Conflict(
         response=mock_rsp_put)
     self.assertRaises(
         ks_exc.Conflict,
         self.placement_api_client.update_qos_minbw_allocation,
         consumer_uuid=CONSUMER_UUID,
         minbw_alloc_diff={},
         rp_uuid=RESOURCE_PROVIDER_UUID,
     )
     self.placement_fixture.mock_put.assert_called_once()
Пример #12
0
 def _raise_conflict(*args, **kwargs):
     raise ks_exc.Conflict(None)
Пример #13
0
class TestIsNotFound(common.HeatTestCase):

    scenarios = [
        ('aodh_not_found',
         dict(
             is_not_found=True,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=False,
             plugin='aodh',
             exception=lambda: aodh_exc.NotFound('not found'),
         )),
        ('aodh_overlimit',
         dict(
             is_not_found=False,
             is_over_limit=True,
             is_client_exception=True,
             is_conflict=False,
             plugin='aodh',
             exception=lambda: aodh_exc.OverLimit('over'),
         )),
        ('aodh_conflict',
         dict(
             is_not_found=False,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=True,
             plugin='aodh',
             exception=lambda: aodh_exc.Conflict('conflict'),
         )),
        ('cinder_not_found',
         dict(
             is_not_found=True,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=False,
             plugin='cinder',
             exception=lambda: cinder_exc.NotFound(code=404),
         )),
        ('cinder_exception',
         dict(is_not_found=False,
              is_over_limit=False,
              is_client_exception=False,
              is_conflict=False,
              plugin='cinder',
              exception=lambda: Exception())),
        ('cinder_overlimit',
         dict(
             is_not_found=False,
             is_over_limit=True,
             is_client_exception=True,
             is_conflict=False,
             plugin='cinder',
             exception=lambda: cinder_exc.OverLimit(code=413),
         )),
        ('cinder_conflict',
         dict(
             is_not_found=False,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=True,
             plugin='cinder',
             exception=lambda: cinder_exc.ClientException(code=409,
                                                          message='conflict'),
         )),
        ('glance_not_found_1',
         dict(
             is_not_found=True,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=False,
             plugin='glance',
             exception=lambda: client_exception.EntityMatchNotFound(),
         )),
        ('glance_not_found_2',
         dict(
             is_not_found=True,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=False,
             plugin='glance',
             exception=lambda: glance_exc.HTTPNotFound(),
         )),
        ('glance_exception',
         dict(is_not_found=False,
              is_over_limit=False,
              is_client_exception=False,
              is_conflict=False,
              plugin='glance',
              exception=lambda: Exception())),
        ('glance_overlimit',
         dict(
             is_not_found=False,
             is_over_limit=True,
             is_client_exception=True,
             is_conflict=False,
             plugin='glance',
             exception=lambda: glance_exc.HTTPOverLimit(details='over'),
         )),
        ('glance_conflict_1',
         dict(
             is_not_found=False,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=True,
             plugin='glance',
             exception=lambda: glance_exc.Conflict(),
         )),
        ('heat_not_found',
         dict(
             is_not_found=True,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=False,
             plugin='heat',
             exception=lambda: heat_exc.HTTPNotFound(message='gone'),
         )),
        ('heat_exception',
         dict(is_not_found=False,
              is_over_limit=False,
              is_client_exception=False,
              is_conflict=False,
              plugin='heat',
              exception=lambda: Exception())),
        ('heat_overlimit',
         dict(
             is_not_found=False,
             is_over_limit=True,
             is_client_exception=True,
             is_conflict=False,
             plugin='heat',
             exception=lambda: heat_exc.HTTPOverLimit(message='over'),
         )),
        ('heat_conflict',
         dict(
             is_not_found=False,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=True,
             plugin='heat',
             exception=lambda: heat_exc.HTTPConflict(),
         )),
        ('keystone_not_found',
         dict(
             is_not_found=True,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=False,
             plugin='keystone',
             exception=lambda: keystone_exc.NotFound(details='gone'),
         )),
        ('keystone_entity_not_found',
         dict(
             is_not_found=True,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=False,
             plugin='keystone',
             exception=lambda: exception.EntityNotFound(),
         )),
        ('keystone_exception',
         dict(is_not_found=False,
              is_over_limit=False,
              is_client_exception=False,
              is_conflict=False,
              plugin='keystone',
              exception=lambda: Exception())),
        ('keystone_overlimit',
         dict(
             is_not_found=False,
             is_over_limit=True,
             is_client_exception=True,
             is_conflict=False,
             plugin='keystone',
             exception=lambda: keystone_exc.RequestEntityTooLarge(details=
                                                                  'over'),
         )),
        ('keystone_conflict',
         dict(
             is_not_found=False,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=True,
             plugin='keystone',
             exception=lambda: keystone_exc.Conflict(message='Conflict'),
         )),
        ('neutron_not_found',
         dict(
             is_not_found=True,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=False,
             plugin='neutron',
             exception=lambda: neutron_exc.NotFound,
         )),
        ('neutron_network_not_found',
         dict(
             is_not_found=True,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=False,
             plugin='neutron',
             exception=lambda: neutron_exc.NetworkNotFoundClient(),
         )),
        ('neutron_port_not_found',
         dict(
             is_not_found=True,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=False,
             plugin='neutron',
             exception=lambda: neutron_exc.PortNotFoundClient(),
         )),
        ('neutron_status_not_found',
         dict(
             is_not_found=True,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=False,
             plugin='neutron',
             exception=lambda: neutron_exc.NeutronClientException(status_code=
                                                                  404),
         )),
        ('neutron_exception',
         dict(is_not_found=False,
              is_over_limit=False,
              is_client_exception=False,
              is_conflict=False,
              plugin='neutron',
              exception=lambda: Exception())),
        ('neutron_overlimit',
         dict(
             is_not_found=False,
             is_over_limit=True,
             is_client_exception=True,
             is_conflict=False,
             plugin='neutron',
             exception=lambda: neutron_exc.NeutronClientException(status_code=
                                                                  413),
         )),
        ('neutron_conflict',
         dict(
             is_not_found=False,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=True,
             plugin='neutron',
             exception=lambda: neutron_exc.Conflict(),
         )),
        ('nova_not_found',
         dict(
             is_not_found=True,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=False,
             is_unprocessable_entity=False,
             plugin='nova',
             exception=lambda: fakes_nova.fake_exception(),
         )),
        ('nova_exception',
         dict(is_not_found=False,
              is_over_limit=False,
              is_client_exception=False,
              is_conflict=False,
              is_unprocessable_entity=False,
              plugin='nova',
              exception=lambda: Exception())),
        ('nova_overlimit',
         dict(
             is_not_found=False,
             is_over_limit=True,
             is_client_exception=True,
             is_conflict=False,
             is_unprocessable_entity=False,
             plugin='nova',
             exception=lambda: fakes_nova.fake_exception(413),
         )),
        ('nova_unprocessable_entity',
         dict(
             is_not_found=False,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=False,
             is_unprocessable_entity=True,
             plugin='nova',
             exception=lambda: fakes_nova.fake_exception(422),
         )),
        ('nova_conflict',
         dict(
             is_not_found=False,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=True,
             is_unprocessable_entity=False,
             plugin='nova',
             exception=lambda: fakes_nova.fake_exception(409),
         )),
        ('openstack_not_found',
         dict(
             is_not_found=True,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=False,
             is_unprocessable_entity=False,
             plugin='openstack',
             exception=lambda: exceptions.ResourceNotFound,
         )),
        ('swift_not_found',
         dict(
             is_not_found=True,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=False,
             plugin='swift',
             exception=lambda: swift_exc.ClientException(msg='gone',
                                                         http_status=404),
         )),
        ('swift_exception',
         dict(is_not_found=False,
              is_over_limit=False,
              is_client_exception=False,
              is_conflict=False,
              plugin='swift',
              exception=lambda: Exception())),
        ('swift_overlimit',
         dict(
             is_not_found=False,
             is_over_limit=True,
             is_client_exception=True,
             is_conflict=False,
             plugin='swift',
             exception=lambda: swift_exc.ClientException(msg='ouch',
                                                         http_status=413),
         )),
        ('swift_conflict',
         dict(
             is_not_found=False,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=True,
             plugin='swift',
             exception=lambda: swift_exc.ClientException(msg='conflict',
                                                         http_status=409),
         )),
        ('trove_not_found',
         dict(
             is_not_found=True,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=False,
             plugin='trove',
             exception=lambda: troveclient.exceptions.NotFound(message='gone'),
         )),
        ('trove_exception',
         dict(is_not_found=False,
              is_over_limit=False,
              is_client_exception=False,
              is_conflict=False,
              plugin='trove',
              exception=lambda: Exception())),
        ('trove_overlimit',
         dict(
             is_not_found=False,
             is_over_limit=True,
             is_client_exception=True,
             is_conflict=False,
             plugin='trove',
             exception=lambda: troveclient.exceptions.RequestEntityTooLarge(
                 message='over'),
         )),
        ('trove_conflict',
         dict(
             is_not_found=False,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=True,
             plugin='trove',
             exception=lambda: troveclient.exceptions.Conflict(message=
                                                               'Conflict'),
         )),
        ('sahara_not_found',
         dict(
             is_not_found=True,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=False,
             plugin='sahara',
             exception=lambda: sahara_base.APIException(error_message='gone1',
                                                        error_code=404),
         )),
        ('sahara_exception',
         dict(is_not_found=False,
              is_over_limit=False,
              is_client_exception=False,
              is_conflict=False,
              plugin='sahara',
              exception=lambda: Exception())),
        ('sahara_overlimit',
         dict(
             is_not_found=False,
             is_over_limit=True,
             is_client_exception=True,
             is_conflict=False,
             plugin='sahara',
             exception=lambda: sahara_base.APIException(error_message='over1',
                                                        error_code=413),
         )),
        ('sahara_conflict',
         dict(
             is_not_found=False,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=True,
             plugin='sahara',
             exception=lambda: sahara_base.APIException(
                 error_message='conflict1', error_code=409),
         )),
        ('zaqar_not_found',
         dict(
             is_not_found=True,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=False,
             plugin='zaqar',
             exception=lambda: zaqar_exc.ResourceNotFound(),
         )),
        ('manila_not_found',
         dict(
             is_not_found=True,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=False,
             plugin='manila',
             exception=lambda: manila_exc.NotFound(),
         )),
        ('manila_exception',
         dict(is_not_found=False,
              is_over_limit=False,
              is_client_exception=False,
              is_conflict=False,
              plugin='manila',
              exception=lambda: Exception())),
        ('manila_overlimit',
         dict(
             is_not_found=False,
             is_over_limit=True,
             is_client_exception=True,
             is_conflict=False,
             plugin='manila',
             exception=lambda: manila_exc.RequestEntityTooLarge(),
         )),
        ('manila_conflict',
         dict(
             is_not_found=False,
             is_over_limit=False,
             is_client_exception=True,
             is_conflict=True,
             plugin='manila',
             exception=lambda: manila_exc.Conflict(),
         )),
        ('mistral_not_found1',
         dict(
             is_not_found=True,
             is_over_limit=False,
             is_client_exception=False,
             is_conflict=False,
             plugin='mistral',
             exception=lambda: mistral_base.APIException(404),
         )),
        ('mistral_not_found2',
         dict(
             is_not_found=True,
             is_over_limit=False,
             is_client_exception=False,
             is_conflict=False,
             plugin='mistral',
             exception=lambda: keystone_exc.NotFound(),
         )),
    ]

    def test_is_not_found(self):
        con = mock.Mock()
        c = clients.Clients(con)
        client_plugin = c.client_plugin(self.plugin)
        try:
            raise self.exception()
        except Exception as e:
            if self.is_not_found != client_plugin.is_not_found(e):
                raise

    def test_ignore_not_found(self):
        con = mock.Mock()
        c = clients.Clients(con)
        client_plugin = c.client_plugin(self.plugin)
        try:
            exp = self.exception()
            exp_class = exp.__class__
            raise exp
        except Exception as e:
            if self.is_not_found:
                client_plugin.ignore_not_found(e)
            else:
                self.assertRaises(exp_class, client_plugin.ignore_not_found, e)

    def test_ignore_not_found_context_manager(self):
        con = mock.Mock()
        c = clients.Clients(con)
        client_plugin = c.client_plugin(self.plugin)

        exp = self.exception()
        exp_class = exp.__class__

        def try_raise():
            with client_plugin.ignore_not_found:
                raise exp

        if self.is_not_found:
            try_raise()
        else:
            self.assertRaises(exp_class, try_raise)

    def test_ignore_conflict_and_not_found(self):
        con = mock.Mock()
        c = clients.Clients(con)
        client_plugin = c.client_plugin(self.plugin)
        try:
            exp = self.exception()
            exp_class = exp.__class__
            raise exp
        except Exception as e:
            if self.is_conflict or self.is_not_found:
                client_plugin.ignore_conflict_and_not_found(e)
            else:
                self.assertRaises(exp_class,
                                  client_plugin.ignore_conflict_and_not_found,
                                  e)

    def test_ignore_conflict_and_not_found_context_manager(self):
        con = mock.Mock()
        c = clients.Clients(con)
        client_plugin = c.client_plugin(self.plugin)

        exp = self.exception()
        exp_class = exp.__class__

        def try_raise():
            with client_plugin.ignore_conflict_and_not_found:
                raise exp

        if self.is_conflict or self.is_not_found:
            try_raise()
        else:
            self.assertRaises(exp_class, try_raise)

    def test_is_over_limit(self):
        con = mock.Mock()
        c = clients.Clients(con)
        client_plugin = c.client_plugin(self.plugin)
        try:
            raise self.exception()
        except Exception as e:
            if self.is_over_limit != client_plugin.is_over_limit(e):
                raise

    def test_is_client_exception(self):
        con = mock.Mock()
        c = clients.Clients(con)
        client_plugin = c.client_plugin(self.plugin)
        try:
            raise self.exception()
        except Exception as e:
            ice = self.is_client_exception
            actual = client_plugin.is_client_exception(e)
            if ice != actual:
                raise

    def test_is_conflict(self):
        con = mock.Mock()
        c = clients.Clients(con)
        client_plugin = c.client_plugin(self.plugin)
        try:
            raise self.exception()
        except Exception as e:
            if self.is_conflict != client_plugin.is_conflict(e):
                raise

    def test_is_unprocessable_entity(self):
        con = mock.Mock()
        c = clients.Clients(con)
        # only 'nova' client plugin need to check this exception
        if self.plugin == 'nova':
            client_plugin = c.client_plugin(self.plugin)
            try:
                raise self.exception()
            except Exception as e:
                iue = self.is_unprocessable_entity
                if iue != client_plugin.is_unprocessable_entity(e):
                    raise