Skip to content

Commit

Permalink
Merge "Remove nova.db call from baremetal PXE driver"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Feb 9, 2013
2 parents b833c9e + 1eb3672 commit ba708ea
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
21 changes: 11 additions & 10 deletions nova/tests/baremetal/test_pxe.py
Expand Up @@ -69,7 +69,7 @@ def setUp(self):
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',
)
Expand Down Expand Up @@ -221,19 +221,20 @@ def test_get_default_deploy_ids(self):
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
# default "kinda.big" instance
sizes = pxe.get_partition_sizes(self.instance)
self.assertEqual(sizes[0], 10240)
self.assertEqual(sizes[1], 1)
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)

# 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']
sizes = pxe.get_partition_sizes(self.instance)
self.assertEqual(sizes[0], 40960)
self.assertEqual(sizes[1], 1024)
self.assertEqual(sizes[1], 1)

def test_get_tftp_image_info(self):
# Raises an exception when options are neither specified
Expand Down
29 changes: 21 additions & 8 deletions nova/tests/utils.py
Expand Up @@ -18,6 +18,9 @@

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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions nova/virt/baremetal/pxe.py
Expand Up @@ -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
Expand Down

0 comments on commit ba708ea

Please sign in to comment.