def test_create_failed(self):
        self.mockclient.create_metering_label_rule.side_effect = (
            exceptions.NeutronClientException())

        snippet = template_format.parse(metering_template)
        stack = utils.parse_stack(snippet)
        self.patchobject(stack['label'], 'FnGetRefId',
                         return_value='1234')
        resource_defns = stack.t.resource_definitions(stack)
        rsrc = metering.MeteringRule(
            'rule', resource_defns['rule'], stack)
        error = self.assertRaises(exception.ResourceFailure,
                                  scheduler.TaskRunner(rsrc.create))
        self.assertEqual(
            'NeutronClientException: resources.rule: '
            'An unknown exception occurred.',
            str(error))
        self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)

        self.mockclient.create_metering_label_rule.assert_called_once_with({
            'metering_label_rule': {
                'metering_label_id': '1234',
                'remote_ip_prefix': '10.0.3.0/24',
                'direction': 'ingress',
                'excluded': False
            }
        })
    def create_metering_label_rule(self):
        self.mockclient.create_metering_label_rule.return_value = {
            'metering_label_rule': {'id': '5678'}
        }

        snippet = template_format.parse(metering_template)
        self.stack = utils.parse_stack(snippet)
        self.patchobject(self.stack['label'], 'FnGetRefId',
                         return_value='1234')
        resource_defns = self.stack.t.resource_definitions(self.stack)
        return metering.MeteringRule(
            'rule', resource_defns['rule'], self.stack)
    def create_metering_label_rule(self):
        neutronclient.Client.create_metering_label_rule({
            'metering_label_rule': {
                'metering_label_id': 'None',
                'remote_ip_prefix': '10.0.3.0/24',
                'direction': 'ingress',
                'excluded': False}
        }).AndReturn({'metering_label_rule': {'id': '5678'}})

        snippet = template_format.parse(metering_template)
        self.stack = utils.parse_stack(snippet)
        resource_defns = self.stack.t.resource_definitions(self.stack)
        return metering.MeteringRule(
            'rule', resource_defns['rule'], self.stack)
示例#4
0
    def test_create_failed(self):
        neutronclient.Client.create_metering_label_rule({
            'metering_label_rule': {
                'metering_label_id': 'None',
                'remote_ip_prefix': '10.0.3.0/24',
                'direction': 'ingress',
                'excluded': False}
        }).AndRaise(exceptions.NeutronClientException())
        self.m.ReplayAll()

        snippet = template_format.parse(metering_template)
        stack = utils.parse_stack(snippet)
        resource_defns = stack.t.resource_definitions(stack)
        rsrc = metering.MeteringRule(
            'rule', resource_defns['rule'], stack)
        error = self.assertRaises(exception.ResourceFailure,
                                  scheduler.TaskRunner(rsrc.create))
        self.assertEqual(
            'NeutronClientException: An unknown exception occurred.',
            six.text_type(error))
        self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state)
        self.m.VerifyAll()