Merge "Remove nova.db call from baremetal PXE driver"
This commit is contained in:
@@ -69,7 +69,7 @@ class BareMetalPXETestCase(bm_db_base.BMDBTestCase):
|
||||
self.node_info = bm_db_utils.new_bm_node(
|
||||
id=123,
|
||||
service_host='test_host',
|
||||
cpus=2,
|
||||
cpus=4,
|
||||
memory_mb=2048,
|
||||
prov_mac_address='11:11:11:11:11:11',
|
||||
)
|
||||
@@ -221,20 +221,21 @@ class PXEClassMethodsTestCase(BareMetalPXETestCase):
|
||||
pxe.get_deploy_ari_id(self.instance), 'bbbb')
|
||||
|
||||
def test_get_partition_sizes(self):
|
||||
# m1.tiny: 10GB root, 0GB swap
|
||||
self.instance['instance_type_id'] = 1
|
||||
sizes = pxe.get_partition_sizes(self.instance)
|
||||
self.assertEqual(sizes[0], 10240)
|
||||
self.assertEqual(sizes[1], 1)
|
||||
|
||||
# kinda.big: 40GB root, 1GB swap
|
||||
ref = utils.get_test_instance_type()
|
||||
self.instance['instance_type_id'] = ref['id']
|
||||
self.instance['root_gb'] = ref['root_gb']
|
||||
# default "kinda.big" instance
|
||||
sizes = pxe.get_partition_sizes(self.instance)
|
||||
self.assertEqual(sizes[0], 40960)
|
||||
self.assertEqual(sizes[1], 1024)
|
||||
|
||||
def test_swap_not_zero(self):
|
||||
# override swap to 0
|
||||
instance_type = utils.get_test_instance_type(self.context)
|
||||
instance_type['swap'] = 0
|
||||
self.instance = utils.get_test_instance(self.context, instance_type)
|
||||
|
||||
sizes = pxe.get_partition_sizes(self.instance)
|
||||
self.assertEqual(sizes[0], 40960)
|
||||
self.assertEqual(sizes[1], 1)
|
||||
|
||||
def test_get_tftp_image_info(self):
|
||||
# Raises an exception when options are neither specified
|
||||
# on the instance nor in configuration file
|
||||
|
||||
@@ -18,6 +18,9 @@ import platform
|
||||
|
||||
import nova.context
|
||||
import nova.db
|
||||
|
||||
from nova.compute import instance_types
|
||||
from nova import exception
|
||||
from nova.image import glance
|
||||
from nova.network import minidns
|
||||
from nova.network import model as network_model
|
||||
@@ -52,25 +55,35 @@ def get_test_instance_type(context=None):
|
||||
'root_gb': 40,
|
||||
'ephemeral_gb': 80,
|
||||
'swap': 1024}
|
||||
|
||||
instance_type_ref = nova.db.instance_type_create(context,
|
||||
test_instance_type)
|
||||
try:
|
||||
instance_type_ref = nova.db.instance_type_create(context,
|
||||
test_instance_type)
|
||||
except exception.InstanceTypeExists:
|
||||
instance_type_ref = nova.db.instance_type_get_by_name(context,
|
||||
'kinda.big')
|
||||
return instance_type_ref
|
||||
|
||||
|
||||
def get_test_instance(context=None):
|
||||
def get_test_instance(context=None, instance_type=None):
|
||||
if not context:
|
||||
context = get_test_admin_context()
|
||||
|
||||
test_instance = {'memory_kb': '1024000',
|
||||
if not instance_type:
|
||||
instance_type = get_test_instance_type(context)
|
||||
|
||||
metadata = {}
|
||||
instance_types.save_instance_type_info(metadata, instance_type, '')
|
||||
|
||||
test_instance = {'memory_kb': '2048000',
|
||||
'basepath': '/some/path',
|
||||
'bridge_name': 'br100',
|
||||
'vcpus': 2,
|
||||
'root_gb': 10,
|
||||
'vcpus': 4,
|
||||
'root_gb': 40,
|
||||
'project_id': 'fake',
|
||||
'bridge': 'br101',
|
||||
'image_ref': 'cedef40a-ed67-4d10-800e-17455edce175',
|
||||
'instance_type_id': '5'} # m1.small
|
||||
'instance_type_id': '5',
|
||||
'system_metadata': metadata}
|
||||
|
||||
instance_ref = nova.db.instance_create(context, test_instance)
|
||||
return instance_ref
|
||||
|
||||
@@ -167,11 +167,9 @@ def get_pxe_config_file_path(instance):
|
||||
|
||||
|
||||
def get_partition_sizes(instance):
|
||||
type_id = instance['instance_type_id']
|
||||
root_mb = instance['root_gb'] * 1024
|
||||
|
||||
# NOTE(deva): is there a way to get swap_mb directly from instance?
|
||||
swap_mb = instance_types.get_instance_type(type_id)['swap']
|
||||
instance_type = instance_types.extract_instance_type(instance)
|
||||
root_mb = instance_type['root_gb'] * 1024
|
||||
swap_mb = instance_type['swap']
|
||||
|
||||
# NOTE(deva): For simpler code paths on the deployment side,
|
||||
# we always create a swap partition. If the flavor
|
||||
|
||||
Reference in New Issue
Block a user