def create_metering_label(self):
     self.mockclient.create_metering_label.return_value = {
         'metering_label': {'id': '1234'}
     }
     snippet = template_format.parse(metering_template)
     self.stack = utils.parse_stack(snippet)
     resource_defns = self.stack.t.resource_definitions(self.stack)
     return metering.MeteringLabel(
         'label', resource_defns['label'], self.stack)
    def create_metering_label(self):
        neutronclient.Client.create_metering_label({
            'metering_label': {
                'name': 'TestLabel',
                'description': 'Description of TestLabel',
                'shared': True}
        }).AndReturn({'metering_label': {'id': '1234'}})

        snippet = template_format.parse(metering_template)
        self.stack = utils.parse_stack(snippet)
        resource_defns = self.stack.t.resource_definitions(self.stack)
        return metering.MeteringLabel(
            'label', resource_defns['label'], self.stack)
Beispiel #3
0
    def test_create_failed(self):
        neutronclient.Client.create_metering_label({
            'metering_label': {
                'name': 'TestLabel',
                'description': 'Description of TestLabel',
                'shared': True}
        }).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.MeteringLabel(
            'label', resource_defns['label'], 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()
    def test_create_failed(self):
        self.mockclient.create_metering_label.side_effect = (
            exceptions.NeutronClientException())

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

        self.mockclient.create_metering_label.assert_called_once_with({
            'metering_label': {
                'name': 'TestLabel',
                'description': 'Description of TestLabel',
                'shared': True
            }
        })