Merge "rm invalid args when updating quotas with nova api"

This commit is contained in:
Jenkins 2013-03-18 00:12:46 +00:00 committed by Gerrit Code Review
commit a53d6491a9
4 changed files with 75 additions and 67 deletions

View File

@ -55,7 +55,8 @@ def cinderclient(request):
request.user.token.id,
project_id=request.user.tenant_id,
auth_url=cinder_url,
insecure=insecure)
insecure=insecure,
http_log_debug=settings.DEBUG)
c.client.auth_token = request.user.token.id
c.client.management_url = cinder_url
return c

View File

@ -26,7 +26,8 @@ from horizon import exceptions
from openstack_dashboard import api
from openstack_dashboard.test import helpers as test
from openstack_dashboard.usage import quotas
from .workflows import CreateProject, UpdateProject
from .workflows import CreateProject, UpdateProject, NOVA_QUOTA_FIELDS, \
CINDER_QUOTA_FIELDS
from .views import QUOTA_FIELDS
INDEX_URL = reverse('horizon:admin:projects:index')
@ -151,9 +152,16 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
user_id=user_id,
role_id=role.id)
nova_updated_quota = dict([(key, quota_data[key]) for key in
NOVA_QUOTA_FIELDS])
api.nova.tenant_quota_update(IsA(http.HttpRequest),
project.id,
**quota_data)
**nova_updated_quota)
cinder_updated_quota = dict([(key, quota_data[key]) for key in
CINDER_QUOTA_FIELDS])
api.cinder.tenant_quota_update(IsA(http.HttpRequest),
project.id,
**cinder_updated_quota)
self.mox.ReplayAll()
@ -274,9 +282,11 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
user_id=user_id,
role_id=role.id)
nova_updated_quota = dict([(key, quota_data[key]) for key in
NOVA_QUOTA_FIELDS])
api.nova.tenant_quota_update(IsA(http.HttpRequest),
project.id,
**quota_data) \
**nova_updated_quota) \
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()
@ -295,6 +305,7 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
'get_default_role',
'add_tenant_user_role'),
quotas: ('get_default_quota_data',),
api.cinder: ('tenant_quota_update',),
api.nova: ('tenant_quota_update',)})
def test_add_project_user_update_error(self):
project = self.tenants.first()
@ -336,9 +347,17 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
break
break
nova_updated_quota = dict([(key, quota_data[key]) for key in
NOVA_QUOTA_FIELDS])
api.nova.tenant_quota_update(IsA(http.HttpRequest),
project.id,
**quota_data)
**nova_updated_quota)
cinder_updated_quota = dict([(key, quota_data[key]) for key in
CINDER_QUOTA_FIELDS])
api.cinder.tenant_quota_update(IsA(http.HttpRequest),
project.id,
**cinder_updated_quota)
self.mox.ReplayAll()
@ -541,13 +560,17 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
user_id='3',
role_id='1')
nova_updated_quota = dict([(key, updated_quota[key]) for key in
NOVA_QUOTA_FIELDS])
api.nova.tenant_quota_update(IsA(http.HttpRequest),
project.id,
**updated_quota)
**nova_updated_quota)
cinder_updated_quota = dict([(key, updated_quota[key]) for key in
CINDER_QUOTA_FIELDS])
api.cinder.tenant_quota_update(IsA(http.HttpRequest),
project.id,
volumes=updated_quota['volumes'],
gigabytes=updated_quota['gigabytes'])
**cinder_updated_quota)
self.mox.ReplayAll()
# submit form data
@ -739,10 +762,12 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
user_id='3',
role_id='2')
nova_updated_quota = dict([(key, updated_quota[key]) for key in
NOVA_QUOTA_FIELDS])
api.nova.tenant_quota_update(IsA(http.HttpRequest),
project.id,
**updated_quota) \
.AndRaise(self.exceptions.nova)
**nova_updated_quota) \
.AndRaise(self.exceptions.nova)
self.mox.ReplayAll()

View File

@ -33,22 +33,12 @@ from openstack_dashboard.usage import quotas
from openstack_dashboard.dashboards.admin.users.views import CreateView
from .forms import CreateUser
from .tables import TenantsTable, TenantUsersTable, AddUsersTable
from .workflows import CreateProject, UpdateProject
from .workflows import CreateProject, UpdateProject, NOVA_QUOTA_FIELDS, \
CINDER_QUOTA_FIELDS
LOG = logging.getLogger(__name__)
QUOTA_FIELDS = ("metadata_items",
"cores",
"instances",
"injected_files",
"injected_file_content_bytes",
"volumes",
"gigabytes",
"ram",
"floating_ips",
"security_groups",
"security_group_rules")
QUOTA_FIELDS = NOVA_QUOTA_FIELDS + CINDER_QUOTA_FIELDS
PROJECT_INFO_FIELDS = ("name",
"description",
@ -183,8 +173,8 @@ class UpdateProjectView(workflows.WorkflowView):
initial[field] = quota_data.get(field).limit
except:
exceptions.handle(self.request,
_('Unable to retrieve project details.'),
redirect=reverse(INDEX_URL))
_('Unable to retrieve project details.'),
redirect=reverse(INDEX_URL))
return initial

View File

@ -32,10 +32,22 @@ from openstack_dashboard import api
from openstack_dashboard.api import cinder, nova
from openstack_dashboard.api.base import is_service_enabled
INDEX_URL = "horizon:admin:projects:index"
ADD_USER_URL = "horizon:admin:projects:create_user"
NOVA_QUOTA_FIELDS = ("metadata_items",
"cores",
"instances",
"injected_files",
"injected_file_content_bytes",
"ram",
"floating_ips",
"security_groups",
"security_group_rules",)
CINDER_QUOTA_FIELDS = ("volumes",
"gigabytes",)
class UpdateProjectQuotaAction(workflows.Action):
ifcb_label = _("Injected File Content Bytes")
@ -81,10 +93,9 @@ class UpdateProjectQuota(workflows.Step):
class CreateProjectInfoAction(workflows.Action):
name = forms.CharField(label=_("Name"))
description = forms.CharField(
widget=forms.widgets.Textarea(),
label=_("Description"),
required=False)
description = forms.CharField(widget=forms.widgets.Textarea(),
label=_("Description"),
required=False)
enabled = forms.BooleanField(label=_("Enabled"),
required=False,
initial=True)
@ -187,7 +198,7 @@ class UpdateProjectMembers(workflows.UpdateMembersStep):
roles = api.keystone.role_list(self.workflow.request)
except:
exceptions.handle(self.workflow.request,
_('Unable to retrieve user list.'))
_('Unable to retrieve user list.'))
post = self.workflow.request.POST
for role in roles:
@ -249,23 +260,17 @@ class CreateProject(workflows.Workflow):
'and set project quotas.'
% users_to_add))
# update the project quota
ifcb = data['injected_file_content_bytes']
# Update the project quota.
nova_data = dict([(key, data[key]) for key in NOVA_QUOTA_FIELDS])
try:
api.nova.tenant_quota_update(
request,
project_id,
metadata_items=data['metadata_items'],
injected_file_content_bytes=ifcb,
volumes=data['volumes'],
gigabytes=data['gigabytes'],
ram=data['ram'],
floating_ips=data['floating_ips'],
instances=data['instances'],
injected_files=data['injected_files'],
cores=data['cores'],
security_groups=data['security_groups'],
security_group_rules=data['security_group_rules'])
nova.tenant_quota_update(request, project_id, **nova_data)
if is_service_enabled(request, 'volume'):
cinder_data = dict([(key, data[key]) for key in
CINDER_QUOTA_FIELDS])
cinder.tenant_quota_update(request,
project_id,
**cinder_data)
except:
exceptions.handle(request, _('Unable to set project quotas.'))
return True
@ -384,31 +389,18 @@ class UpdateProject(workflows.Workflow):
return True
# update the project quota
ifcb = data['injected_file_content_bytes']
nova_data = dict([(key, data[key]) for key in NOVA_QUOTA_FIELDS])
try:
# TODO(gabriel): Once nova-volume is fully deprecated the
# "volumes" and "gigabytes" quotas should no longer be sent to
# the nova API to be updated anymore.
nova.tenant_quota_update(
request,
project_id,
metadata_items=data['metadata_items'],
injected_file_content_bytes=ifcb,
volumes=data['volumes'],
gigabytes=data['gigabytes'],
ram=data['ram'],
floating_ips=data['floating_ips'],
instances=data['instances'],
injected_files=data['injected_files'],
cores=data['cores'],
security_groups=data['security_groups'],
security_group_rules=data['security_group_rules'])
nova.tenant_quota_update(request,
project_id,
**nova_data)
if is_service_enabled(request, 'volume'):
cinder_data = dict([(key, data[key]) for key in
CINDER_QUOTA_FIELDS])
cinder.tenant_quota_update(request,
project_id,
volumes=data['volumes'],
gigabytes=data['gigabytes'])
**cinder_data)
return True
except:
exceptions.handle(request, _('Modified project information and '