Esempio n. 1
0
    def test_instance_usage_exception(self):
        now = self.override_times()

        exception = api_exceptions.ApiException('apiException',
                                                message='apiException')
        self.mox.StubOutWithMock(api, 'usage_get')
        api.usage_get(
            IsA(http.HttpRequest), self.TEST_TENANT,
            datetime.datetime(now.year, now.month, 1, now.hour, now.minute,
                              now.second), now).AndRaise(exception)

        self.mox.StubOutWithMock(messages, 'error')
        messages.error(IsA(http.HttpRequest), IsA(basestring))

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('steer:engine:instances_and_volumes:instances:usage'))

        self.assertTemplateUsed(
            res, 'engine/instances_and_volumes/instances/usage.html')

        self.assertEqual(res.context['usage'], {})

        self.reset_times()
Esempio n. 2
0
    def test_instance_usage_exception(self):
        now = self.override_times()

        exception = api_exceptions.ApiException('apiException',
                                                message='apiException')
        self.mox.StubOutWithMock(api, 'usage_get')
        api.usage_get(IsA(http.HttpRequest), self.TEST_TENANT,
                      datetime.datetime(now.year, now.month, 1,
                                        now.hour, now.minute, now.second),
                      now).AndRaise(exception)

        self.mox.StubOutWithMock(messages, 'error')
        messages.error(IsA(http.HttpRequest), IsA(basestring))

        self.mox.ReplayAll()

        res = self.client.get(
                reverse('steer:engine:instances_and_volumes:instances:usage'))

        self.assertTemplateUsed(res,
                'engine/instances_and_volumes/instances/usage.html')

        self.assertEqual(res.context['usage'], {})

        self.reset_times()
Esempio n. 3
0
    def test_instance_usage_default_tenant(self):
        TEST_RETURN = 'testReturn'

        now = self.override_times()

        self.mox.StubOutWithMock(api, 'usage_get')
        api.usage_get(IsA(http.HttpRequest), self.TEST_TENANT,
                      datetime.datetime(now.year, now.month, 1,
                                        now.hour, now.minute, now.second),
                      now).AndReturn(TEST_RETURN)

        self.mox.ReplayAll()

        res = self.client.get(
                reverse('steer:engine:instances_and_volumes:instances:usage'))

        self.assertTemplateUsed(res,
                'engine/instances_and_volumes/instances/usage.html')

        self.assertEqual(res.context['usage'], TEST_RETURN)

        self.reset_times()
Esempio n. 4
0
    def test_instance_usage_default_tenant(self):
        TEST_RETURN = 'testReturn'

        now = self.override_times()

        self.mox.StubOutWithMock(api, 'usage_get')
        api.usage_get(
            IsA(http.HttpRequest), self.TEST_TENANT,
            datetime.datetime(now.year, now.month, 1, now.hour, now.minute,
                              now.second), now).AndReturn(TEST_RETURN)

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('steer:engine:instances_and_volumes:instances:usage'))

        self.assertTemplateUsed(
            res, 'engine/instances_and_volumes/instances/usage.html')

        self.assertEqual(res.context['usage'], TEST_RETURN)

        self.reset_times()
Esempio n. 5
0
def usage(request, tenant_id=None):
    tenant_id = tenant_id or request.user.tenant_id
    today = test.today()
    date_start = datetime.date(today.year, today.month, 1)
    datetime_start = datetime.datetime.combine(date_start, test.time())
    datetime_end = test.utcnow()

    show_terminated = request.GET.get('show_terminated', False)

    usage = {}
    if not tenant_id:
        tenant_id = request.user.tenant_id

    try:
        usage = api.usage_get(request, tenant_id, datetime_start, datetime_end)
    except api_exceptions.ApiException, e:
        LOG.exception(_('ApiException in instance usage'))

        messages.error(request, _('Unable to get usage info: %s') % e.message)
Esempio n. 6
0
def usage(request, tenant_id=None):
    tenant_id = tenant_id or request.user.tenant_id
    today = test.today()
    date_start = datetime.date(today.year, today.month, 1)
    datetime_start = datetime.datetime.combine(date_start, test.time())
    datetime_end = test.utcnow()

    show_terminated = request.GET.get('show_terminated', False)

    usage = {}
    if not tenant_id:
        tenant_id = request.user.tenant_id

    try:
        usage = api.usage_get(request, tenant_id, datetime_start, datetime_end)
    except api_exceptions.ApiException, e:
        LOG.exception(_('ApiException in instance usage'))

        messages.error(request, _('Unable to get usage info: %s') % e.message)
Esempio n. 7
0
def tenant_usage(request):
    tenant_id = request.user.tenant
    (date_start, date_end, datetime_start, datetime_end) = \
            _get_start_and_end_date(request)
    if date_start > _current_month():
        messages.error(request, _('No data for the selected period'))
        date_end = date_start
        datetime_end = datetime_start

    dateform = forms.DateForm()
    dateform['date'].field.initial = date_start

    usage = {}
    try:
        usage = api.usage_get(request, tenant_id, datetime_start, datetime_end)
    except api_exceptions.ApiException, e:
        LOG.exception('ApiException getting usage info for tenant "%s"'
                      ' on date range "%s to %s"' %
                      (tenant_id, datetime_start, datetime_end))
        messages.error(request, _('Unable to get usage info: %s') % e.message)
Esempio n. 8
0
def tenant_usage(request):
    tenant_id = request.user.tenant
    (date_start, date_end, datetime_start, datetime_end) = \
            _get_start_and_end_date(request)
    if date_start > _current_month():
        messages.error(request, _('No data for the selected period'))
        date_end = date_start
        datetime_end = datetime_start

    dateform = forms.DateForm()
    dateform['date'].field.initial = date_start

    usage = {}
    try:
        usage = api.usage_get(request, tenant_id, datetime_start, datetime_end)
    except api_exceptions.ApiException, e:
        LOG.exception('ApiException getting usage info for tenant "%s"'
                  ' on date range "%s to %s"' % (tenant_id,
                                                 datetime_start,
                                                 datetime_end))
        messages.error(request, _('Unable to get usage info: %s') % e.message)