Create module for management LPAR utilities

Create new module nova_powervm.virt.powervm.mgmt containing utilities
around the PowerVM management partition.

Moved vm.get_mgmt_partition into the new module.

Change-Id: I67d88148c78a5c966e16ddb4b490a398250b2120
This commit is contained in:
Eric Fried 2015-05-29 15:08:29 -05:00
parent d0bf3dbd2b
commit 797755c029
9 changed files with 90 additions and 23 deletions

View File

@ -301,7 +301,7 @@ class TestLocalDisk(test.TestCase):
mock_rm_vdisk_map.assert_called_with(local.adapter, 'vios_uuid',
'mp_id', disk_names=['disk_name'])
@mock.patch('nova_powervm.virt.powervm.vm.get_mgmt_partition')
@mock.patch('nova_powervm.virt.powervm.mgmt.get_mgmt_partition')
@mock.patch('nova_powervm.virt.powervm.disk.localdisk.LocalStorage.'
'instance_disk_iter')
@mock.patch('pypowervm.tasks.scsi_mapper.add_vscsi_mapping')

View File

@ -584,7 +584,7 @@ class TestSSPDiskAdapter(test.TestCase):
mock_rm_lu_map.assert_called_with(ssp_stor.adapter, 'vios_uuid',
'mp_id', disk_names=['disk_name'])
@mock.patch('nova_powervm.virt.powervm.vm.get_mgmt_partition')
@mock.patch('nova_powervm.virt.powervm.mgmt.get_mgmt_partition')
@mock.patch('nova_powervm.virt.powervm.disk.ssp.SSPDiskAdapter.'
'instance_disk_iter')
@mock.patch('pypowervm.tasks.scsi_mapper.add_vscsi_mapping')

View File

@ -0,0 +1,44 @@
# Copyright 2015 IBM Corp.
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from nova import test
from pypowervm.tests.wrappers.util import pvmhttp
from pypowervm.wrappers import logical_partition as pvm_lpar
from nova_powervm.tests.virt.powervm import fixtures as fx
from nova_powervm.virt.powervm import mgmt
LPAR_HTTPRESP_FILE = "lpar.txt"
class TestVM(test.TestCase):
def setUp(self):
super(TestVM, self).setUp()
self.pypvm = self.useFixture(fx.PyPowerVM())
self.apt = self.pypvm.apt
lpar_http = pvmhttp.load_pvm_resp(LPAR_HTTPRESP_FILE, adapter=self.apt)
self.assertNotEqual(lpar_http, None,
"Could not load %s " %
LPAR_HTTPRESP_FILE)
self.resp = lpar_http.response
def test_get_mgmt_partition(self):
self.apt.read.return_value = self.resp
mp_wrap = mgmt.get_mgmt_partition(self.apt)
self.assertIsInstance(mp_wrap, pvm_lpar.LPAR)
self.assertTrue(mp_wrap.is_mgmt_partition)

View File

@ -334,12 +334,6 @@ class TestVM(test.TestCase):
self.assertRaises(pvm_exc.Error, vm.get_vm_qp, self.apt,
'lpar_uuid')
def test_get_mgmt_partition(self):
self.apt.read.return_value = self.resp
mp_wrap = vm.get_mgmt_partition(self.apt)
self.assertIsInstance(mp_wrap, pvm_lpar.LPAR)
self.assertTrue(mp_wrap.is_mgmt_partition)
def test_norm_mac(self):
EXPECTED = "12:34:56:78:90:ab"
self.assertEqual(EXPECTED, vm.norm_mac("12:34:56:78:90:ab"))

View File

@ -28,6 +28,7 @@ import pypowervm.util as pvm_util
import pypowervm.wrappers.virtual_io_server as pvm_vios
from nova_powervm.virt.powervm import disk
from nova_powervm.virt.powervm import mgmt
from nova_powervm.virt.powervm import vm
LOG = logging.getLogger(__name__)
@ -147,7 +148,7 @@ class DiskAdapter(object):
:raise InstanceDiskMappingFailed: If the mapping could not be done.
"""
if mp_wrap is None:
mp_wrap = vm.get_mgmt_partition(self.adapter)
mp_wrap = mgmt.get_mgmt_partition(self.adapter)
msg_args = {'instance_name': instance.name,
'mp_name': mp_wrap.name}
for stg_elem, vios in self.instance_disk_iter(instance):

View File

@ -30,6 +30,7 @@ from pypowervm.wrappers import virtual_io_server as pvm_vios
import nova_powervm.virt.powervm.disk as disk
from nova_powervm.virt.powervm.disk import driver as disk_dvr
from nova_powervm.virt.powervm import mgmt
from nova_powervm.virt.powervm import vm
localdisk_opts = [
@ -171,7 +172,7 @@ class LocalStorage(disk_dvr.DiskAdapter):
looked up.
"""
if mp_wrap is None:
mp_wrap = vm.get_mgmt_partition(self.adapter)
mp_wrap = mgmt.get_mgmt_partition(self.adapter)
tsk_map.remove_vdisk_mapping(self.adapter, vios_uuid, mp_wrap.id,
disk_names=[disk_name])
LOG.info(_LI(

View File

@ -23,6 +23,7 @@ from nova import image
from nova.i18n import _, _LI, _LE
import nova_powervm.virt.powervm.disk as disk
from nova_powervm.virt.powervm.disk import driver as disk_drv
from nova_powervm.virt.powervm import mgmt
from nova_powervm.virt.powervm import vm
from pypowervm.tasks import scsi_mapper as tsk_map
@ -140,7 +141,7 @@ class SSPDiskAdapter(disk_drv.DiskAdapter):
looked up.
"""
if mp_wrap is None:
mp_wrap = vm.get_mgmt_partition(self.adapter)
mp_wrap = mgmt.get_mgmt_partition(self.adapter)
tsk_map.remove_lu_mapping(self.adapter, vios_uuid, mp_wrap.id,
disk_names=[disk_name])
LOG.info(_LI(

View File

@ -0,0 +1,37 @@
# Copyright 2015 IBM Corp.
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Utilities related to the PowerVM management partition.
The management partition is a special LPAR that runs the PowerVM REST API
service. It itself appears through the REST API as a LogicalPartition of type
aixlinux, but with the is_mgmt_partition property set to True.
The PowerVM Nova Compute service runs on the management partition.
"""
from nova.i18n import _
from pypowervm.wrappers import logical_partition as pvm_lpar
def get_mgmt_partition(adapter):
"""Get the LPAR wrapper for this host's management partition.
:param adapter: The adapter for the pypowervm API.
"""
wraps = pvm_lpar.LPAR.search(adapter, is_mgmt_partition=True)
if len(wraps) != 1:
raise Exception(_("Unable to find a single management partition."))
return wraps[0]

View File

@ -21,7 +21,7 @@ from oslo_log import log as logging
from nova.compute import power_state
from nova import exception
from nova.i18n import _, _LI, _LE
from nova.i18n import _LI, _LE
from nova.virt import hardware
from pypowervm import exceptions as pvm_exc
from pypowervm.tasks import cna
@ -216,17 +216,6 @@ def get_instance_wrapper(adapter, instance, host_uuid):
return pvm_lpar.LPAR.wrap(resp)
def get_mgmt_partition(adapter):
"""Get the LPAR wrapper for this host's management partition.
:param adapter: The adapter for the pypowervm API.
"""
wraps = pvm_lpar.LPAR.search(adapter, is_mgmt_partition=True)
if len(wraps) != 1:
raise Exception(_("Unable to find a single management partition."))
return wraps[0]
def _build_attrs(instance, flavor):
"""Builds LPAR attributes that are used by the LPAR builder.