Add rxtx factor to flavors.

Adds rxtx factor to create and update flavor.
Adds rxtx factor column to flavor table.
Update tests.

Change-Id: I0b6c0a8faff5ae32339c41ec95258b5ac3da5148
Closes-Bug: 1481425
This commit is contained in:
Itxaka 2015-11-19 17:22:32 +01:00
parent 4b5886d276
commit 90b3276e60
6 changed files with 48 additions and 6 deletions

View File

@ -485,11 +485,13 @@ def server_serial_console(request, instance_id, console_type='serial'):
def flavor_create(request, name, memory, vcpu, disk, flavorid='auto', def flavor_create(request, name, memory, vcpu, disk, flavorid='auto',
ephemeral=0, swap=0, metadata=None, is_public=True): ephemeral=0, swap=0, metadata=None, is_public=True,
rxtx_factor=1):
flavor = novaclient(request).flavors.create(name, memory, vcpu, disk, flavor = novaclient(request).flavors.create(name, memory, vcpu, disk,
flavorid=flavorid, flavorid=flavorid,
ephemeral=ephemeral, ephemeral=ephemeral,
swap=swap, is_public=is_public) swap=swap, is_public=is_public,
rxtx_factor=rxtx_factor)
if (metadata): if (metadata):
flavor_extra_set(request, flavor.id, metadata) flavor_extra_set(request, flavor.id, metadata)
return flavor return flavor

View File

@ -151,6 +151,7 @@ class FlavorsTable(tables.DataTable):
swap = tables.Column(get_swap_size, swap = tables.Column(get_swap_size,
verbose_name=_('Swap Disk'), verbose_name=_('Swap Disk'),
attrs={'data-type': 'size'}) attrs={'data-type': 'size'})
rxtx_factor = tables.Column('rxtx_factor', verbose_name=_("RX/TX factor"))
flavor_id = tables.Column('id', verbose_name=_('ID')) flavor_id = tables.Column('id', verbose_name=_('ID'))
public = tables.Column("is_public", public = tables.Column("is_public",
verbose_name=_("Public"), verbose_name=_("Public"),

View File

@ -45,6 +45,7 @@ class BaseFlavorWorkflowTests(test.BaseAdminViewTests):
"memory": flavor.ram, "memory": flavor.ram,
"disk": flavor.disk, "disk": flavor.disk,
"swap": flavor.swap, "swap": flavor.swap,
"rxtx_factor": flavor.rxtx_factor,
"ephemeral": eph, "ephemeral": eph,
"is_public": flavor.is_public} "is_public": flavor.is_public}
if id: if id:
@ -58,6 +59,7 @@ class BaseFlavorWorkflowTests(test.BaseAdminViewTests):
"memory_mb": flavor.ram, "memory_mb": flavor.ram,
"disk_gb": flavor.disk, "disk_gb": flavor.disk,
"swap_mb": flavor.swap, "swap_mb": flavor.swap,
"rxtx_factor": flavor.rxtx_factor,
"eph_gb": eph} "eph_gb": eph}
if access: if access:
access_field_name = 'update_flavor_access_role_member' access_field_name = 'update_flavor_access_role_member'
@ -325,6 +327,8 @@ class UpdateFlavorWorkflowTests(BaseFlavorWorkflowTests):
self.assertEqual(step.action.initial['memory_mb'], flavor.ram) self.assertEqual(step.action.initial['memory_mb'], flavor.ram)
self.assertEqual(step.action.initial['disk_gb'], flavor.disk) self.assertEqual(step.action.initial['disk_gb'], flavor.disk)
self.assertEqual(step.action.initial['swap_mb'], flavor.swap) self.assertEqual(step.action.initial['swap_mb'], flavor.swap)
self.assertEqual(step.action.initial['rxtx_factor'],
flavor.rxtx_factor)
self.assertEqual(step.action.initial['eph_gb'], eph) self.assertEqual(step.action.initial['eph_gb'], eph)
step = workflow.get_step("update_flavor_access") step = workflow.get_step("update_flavor_access")
@ -365,6 +369,7 @@ class UpdateFlavorWorkflowTests(BaseFlavorWorkflowTests):
'vcpus': flavor.vcpus + 1, 'vcpus': flavor.vcpus + 1,
'disk': flavor.disk, 'disk': flavor.disk,
'ram': flavor.ram, 'ram': flavor.ram,
'rxtx_factor': flavor.rxtx_factor,
'swap': 0, 'swap': 0,
'OS-FLV-EXT-DATA:ephemeral': eph, 'OS-FLV-EXT-DATA:ephemeral': eph,
'extra_specs': extra_specs}) 'extra_specs': extra_specs})
@ -388,6 +393,7 @@ class UpdateFlavorWorkflowTests(BaseFlavorWorkflowTests):
new_flavor.vcpus, new_flavor.vcpus,
new_flavor.disk, new_flavor.disk,
swap=new_flavor.swap, swap=new_flavor.swap,
rxtx_factor=new_flavor.rxtx_factor,
ephemeral=eph, ephemeral=eph,
is_public=True).AndReturn(new_flavor) is_public=True).AndReturn(new_flavor)
@ -407,6 +413,7 @@ class UpdateFlavorWorkflowTests(BaseFlavorWorkflowTests):
'memory_mb': new_flavor.ram, 'memory_mb': new_flavor.ram,
'disk_gb': new_flavor.disk, 'disk_gb': new_flavor.disk,
'swap_mb': new_flavor.swap, 'swap_mb': new_flavor.swap,
'rxtx_factor': flavor.rxtx_factor,
'eph_gb': eph, 'eph_gb': eph,
'is_public': True} 'is_public': True}
resp = self.client.post(url, workflow_data) resp = self.client.post(url, workflow_data)
@ -436,6 +443,7 @@ class UpdateFlavorWorkflowTests(BaseFlavorWorkflowTests):
'disk': flavor.disk, 'disk': flavor.disk,
'ram': flavor.ram, 'ram': flavor.ram,
'swap': flavor.swap, 'swap': flavor.swap,
'rxtx_factor': flavor.rxtx_factor,
'OS-FLV-EXT-DATA:ephemeral': eph, 'OS-FLV-EXT-DATA:ephemeral': eph,
'extra_specs': extra_specs}) 'extra_specs': extra_specs})
@ -458,6 +466,7 @@ class UpdateFlavorWorkflowTests(BaseFlavorWorkflowTests):
new_flavor.vcpus, new_flavor.vcpus,
new_flavor.disk, new_flavor.disk,
swap=new_flavor.swap, swap=new_flavor.swap,
rxtx_factor=new_flavor.rxtx_factor,
ephemeral=eph, ephemeral=eph,
is_public=True).AndReturn(new_flavor) is_public=True).AndReturn(new_flavor)
api.nova.flavor_extra_set(IsA(http.HttpRequest), api.nova.flavor_extra_set(IsA(http.HttpRequest),
@ -478,6 +487,7 @@ class UpdateFlavorWorkflowTests(BaseFlavorWorkflowTests):
'memory_mb': new_flavor.ram, 'memory_mb': new_flavor.ram,
'disk_gb': new_flavor.disk, 'disk_gb': new_flavor.disk,
'swap_mb': new_flavor.swap, 'swap_mb': new_flavor.swap,
'rxtx_factor': flavor.rxtx_factor,
'eph_gb': eph, 'eph_gb': eph,
'is_public': True} 'is_public': True}
resp = self.client.post(url, workflow_data) resp = self.client.post(url, workflow_data)
@ -505,6 +515,7 @@ class UpdateFlavorWorkflowTests(BaseFlavorWorkflowTests):
'vcpus': flavor.vcpus + 1, 'vcpus': flavor.vcpus + 1,
'disk': flavor.disk, 'disk': flavor.disk,
'ram': flavor.ram, 'ram': flavor.ram,
'rxtx_factor': flavor.rxtx_factor,
'swap': 0, 'swap': 0,
'OS-FLV-EXT-DATA:ephemeral': eph, 'OS-FLV-EXT-DATA:ephemeral': eph,
'extra_specs': extra_specs}) 'extra_specs': extra_specs})
@ -530,6 +541,7 @@ class UpdateFlavorWorkflowTests(BaseFlavorWorkflowTests):
new_flavor.vcpus, new_flavor.vcpus,
new_flavor.disk, new_flavor.disk,
swap=new_flavor.swap, swap=new_flavor.swap,
rxtx_factor=new_flavor.rxtx_factor,
ephemeral=eph, ephemeral=eph,
is_public=True)\ is_public=True)\
.AndRaise(self.exceptions.nova) .AndRaise(self.exceptions.nova)
@ -550,6 +562,7 @@ class UpdateFlavorWorkflowTests(BaseFlavorWorkflowTests):
'memory_mb': new_flavor.ram, 'memory_mb': new_flavor.ram,
'disk_gb': new_flavor.disk, 'disk_gb': new_flavor.disk,
'swap_mb': new_flavor.swap, 'swap_mb': new_flavor.swap,
'rxtx_factor': flavor.rxtx_factor,
'eph_gb': eph, 'eph_gb': eph,
'is_public': True} 'is_public': True}
resp = self.client.post(url, workflow_data) resp = self.client.post(url, workflow_data)
@ -582,6 +595,7 @@ class UpdateFlavorWorkflowTests(BaseFlavorWorkflowTests):
'disk': flavor.disk, 'disk': flavor.disk,
'ram': flavor.ram, 'ram': flavor.ram,
'swap': 0, 'swap': 0,
'rxtx_factor': flavor.rxtx_factor,
'OS-FLV-EXT-DATA:ephemeral': eph, 'OS-FLV-EXT-DATA:ephemeral': eph,
'os-flavor-access:is_public': False, 'os-flavor-access:is_public': False,
'extra_specs': extra_specs}) 'extra_specs': extra_specs})
@ -606,6 +620,7 @@ class UpdateFlavorWorkflowTests(BaseFlavorWorkflowTests):
new_flavor.vcpus, new_flavor.vcpus,
new_flavor.disk, new_flavor.disk,
swap=new_flavor.swap, swap=new_flavor.swap,
rxtx_factor=new_flavor.rxtx_factor,
ephemeral=eph, ephemeral=eph,
is_public=new_flavor.is_public) \ is_public=new_flavor.is_public) \
.AndReturn(new_flavor) .AndReturn(new_flavor)
@ -667,6 +682,7 @@ class UpdateFlavorWorkflowTests(BaseFlavorWorkflowTests):
'memory_mb': flavor.ram, 'memory_mb': flavor.ram,
'disk_gb': flavor.disk, 'disk_gb': flavor.disk,
'swap_mb': flavor.swap, 'swap_mb': flavor.swap,
'rxtx_factor': flavor.rxtx_factor,
'eph_gb': eph, 'eph_gb': eph,
'is_public': True} 'is_public': True}
resp = self.client.post(url, workflow_data) resp = self.client.post(url, workflow_data)
@ -689,6 +705,7 @@ class UpdateFlavorWorkflowTests(BaseFlavorWorkflowTests):
'disk': flavor_a.disk, 'disk': flavor_a.disk,
'ram': flavor_a.ram, 'ram': flavor_a.ram,
'swap': flavor_a.swap, 'swap': flavor_a.swap,
'rxtx_factor': flavor_a.rxtx_factor,
'OS-FLV-EXT-DATA:ephemeral': eph, 'OS-FLV-EXT-DATA:ephemeral': eph,
'extra_specs': extra_specs}) 'extra_specs': extra_specs})
@ -716,6 +733,7 @@ class UpdateFlavorWorkflowTests(BaseFlavorWorkflowTests):
'memory_mb': new_flavor.ram, 'memory_mb': new_flavor.ram,
'disk_gb': new_flavor.disk, 'disk_gb': new_flavor.disk,
'swap_mb': new_flavor.swap, 'swap_mb': new_flavor.swap,
'rxtx_factor': new_flavor.rxtx_factor,
'eph_gb': eph, 'eph_gb': eph,
'is_public': True} 'is_public': True}
resp = self.client.post(url, data) resp = self.client.post(url, data)
@ -753,6 +771,7 @@ class UpdateFlavorWorkflowTests(BaseFlavorWorkflowTests):
'memory_mb': flavor.ram, 'memory_mb': flavor.ram,
'disk_gb': flavor.disk, 'disk_gb': flavor.disk,
'swap_mb': flavor.swap, 'swap_mb': flavor.swap,
'rxtx_factor': flavor.rxtx_factor,
'eph_gb': eph, 'eph_gb': eph,
'is_public': True} 'is_public': True}
workflow_data.update(override_data) workflow_data.update(override_data)
@ -788,3 +807,9 @@ class UpdateFlavorWorkflowTests(BaseFlavorWorkflowTests):
data = {'eph_gb': -1} data = {'eph_gb': -1}
self.generic_update_flavor_invalid_data_form_fails(override_data=data, self.generic_update_flavor_invalid_data_form_fails(override_data=data,
error_msg=error) error_msg=error)
def test_update_flavor_invalid_rxtx_factor_fails(self):
error = 'Ensure this value is greater than or equal to 1.'
data = {'rxtx_factor': 0}
self.generic_update_flavor_invalid_data_form_fails(override_data=data,
error_msg=error)

View File

@ -80,4 +80,5 @@ class UpdateView(workflows.WorkflowView):
'memory_mb': flavor.ram, 'memory_mb': flavor.ram,
'disk_gb': flavor.disk, 'disk_gb': flavor.disk,
'swap_mb': flavor.swap or 0, 'swap_mb': flavor.swap or 0,
'rxtx_factor': flavor.rxtx_factor or 1,
'eph_gb': getattr(flavor, 'OS-FLV-EXT-DATA:ephemeral', None)} 'eph_gb': getattr(flavor, 'OS-FLV-EXT-DATA:ephemeral', None)}

View File

@ -57,6 +57,10 @@ class CreateFlavorInfoAction(workflows.Action):
required=False, required=False,
initial=0, initial=0,
min_value=0) min_value=0)
rxtx_factor = forms.FloatField(label=_("RX/TX Factor"),
required=False,
initial=1,
min_value=1)
class Meta(object): class Meta(object):
name = _("Flavor Information") name = _("Flavor Information")
@ -99,7 +103,8 @@ class CreateFlavorInfo(workflows.Step):
"memory_mb", "memory_mb",
"disk_gb", "disk_gb",
"eph_gb", "eph_gb",
"swap_mb") "swap_mb",
"rxtx_factor")
class UpdateFlavorAccessAction(workflows.MembershipAction): class UpdateFlavorAccessAction(workflows.MembershipAction):
@ -196,6 +201,7 @@ class CreateFlavor(workflows.Workflow):
ephemeral = data.get('eph_gb') or 0 ephemeral = data.get('eph_gb') or 0
flavor_access = data['flavor_access'] flavor_access = data['flavor_access']
is_public = not flavor_access is_public = not flavor_access
rxtx_factor = data.get('rxtx_factor') or 1
# Create the flavor # Create the flavor
try: try:
@ -207,7 +213,8 @@ class CreateFlavor(workflows.Workflow):
ephemeral=ephemeral, ephemeral=ephemeral,
swap=swap, swap=swap,
flavorid=flavor_id, flavorid=flavor_id,
is_public=is_public) is_public=is_public,
rxtx_factor=rxtx_factor)
except Exception: except Exception:
exceptions.handle(request, _('Unable to create flavor.')) exceptions.handle(request, _('Unable to create flavor.'))
return False return False
@ -264,7 +271,8 @@ class UpdateFlavorInfo(workflows.Step):
"memory_mb", "memory_mb",
"disk_gb", "disk_gb",
"eph_gb", "eph_gb",
"swap_mb") "swap_mb",
"rxtx_factor")
class UpdateFlavor(workflows.Workflow): class UpdateFlavor(workflows.Workflow):
@ -305,7 +313,8 @@ class UpdateFlavor(workflows.Workflow):
data['disk_gb'], data['disk_gb'],
ephemeral=data['eph_gb'], ephemeral=data['eph_gb'],
swap=data['swap_mb'], swap=data['swap_mb'],
is_public=is_public) is_public=is_public,
rxtx_factor=data['rxtx_factor'])
if (extras_dict): if (extras_dict):
api.nova.flavor_extra_set(request, flavor.id, extras_dict) api.nova.flavor_extra_set(request, flavor.id, extras_dict)
except Exception: except Exception:

View File

@ -263,6 +263,7 @@ def data(TEST):
'disk': 0, 'disk': 0,
'ram': 512, 'ram': 512,
'swap': 0, 'swap': 0,
'rxtx_factor': 1,
'extra_specs': {}, 'extra_specs': {},
'os-flavor-access:is_public': True, 'os-flavor-access:is_public': True,
'OS-FLV-EXT-DATA:ephemeral': 0}) 'OS-FLV-EXT-DATA:ephemeral': 0})
@ -273,6 +274,7 @@ def data(TEST):
'disk': 1024, 'disk': 1024,
'ram': 10000, 'ram': 10000,
'swap': 0, 'swap': 0,
'rxtx_factor': 1,
'extra_specs': {'Trusted': True, 'foo': 'bar'}, 'extra_specs': {'Trusted': True, 'foo': 'bar'},
'os-flavor-access:is_public': True, 'os-flavor-access:is_public': True,
'OS-FLV-EXT-DATA:ephemeral': 2048}) 'OS-FLV-EXT-DATA:ephemeral': 2048})
@ -283,6 +285,7 @@ def data(TEST):
'disk': 1024, 'disk': 1024,
'ram': 10000, 'ram': 10000,
'swap': 0, 'swap': 0,
'rxtx_factor': 1,
'extra_specs': {}, 'extra_specs': {},
'os-flavor-access:is_public': False, 'os-flavor-access:is_public': False,
'OS-FLV-EXT-DATA:ephemeral': 2048}) 'OS-FLV-EXT-DATA:ephemeral': 2048})
@ -293,6 +296,7 @@ def data(TEST):
'disk': 1024, 'disk': 1024,
'ram': 10000, 'ram': 10000,
'swap': 0, 'swap': 0,
'rxtx_factor': 1,
'extra_specs': FlavorExtraSpecs( 'extra_specs': FlavorExtraSpecs(
{'key': 'key_mock', {'key': 'key_mock',
'value': 'value_mock'}), 'value': 'value_mock'}),