Testcase refactor and updates for vhba_vnic

Change-Id: I72e5dcc60b1bdebb9fc1c30ffa95e38d25453de8
This commit is contained in:
preethipy
2016-12-30 12:59:32 +05:30
committed by Prabhat Ranjan
parent 982977b862
commit c0f2c1c610
8 changed files with 405 additions and 106 deletions

View File

@@ -1,62 +0,0 @@
# Copyright 2016 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 zhmcclient._logging import _log_call
from zhmcclient._resource import BaseResource
def getFakeCPC(cpcmanager):
cpc_props = dict()
cpc_props['object-uri'] = "/api/cpc/dummy"
cpc_props['name'] = "fakecpc"
cpc_props['storage-customer'] = 100
cpc_props['processor-count-pending-ifl'] = 6
cpc_props['processor-count-ifl'] = 12
cpc_props['storage-customer-available'] = 500
cpc = Cpc(cpcmanager, cpc_props['object-uri'], cpc_props)
return cpc
def getFakeCPCconf():
conf = {'cpcsubset_name': "S12subset",
'cpc_uuid': "1232132",
'max_processors': 10,
'max_memory_mb': 200,
'max_partitions': 10
}
return conf
def getFakeCPCwithProp(cpcmanager, cpc_props):
cpc = Cpc(cpcmanager, cpc_props['object-uri'], cpc_props)
return cpc
class Cpc(BaseResource):
def __init__(self, manager, uri, properties):
super(Cpc, self).__init__(manager, uri, properties,
uri_prop='object-uri',
name_prop='name')
@property
@_log_call
def dpm_enabled(self):
return True
def pull_full_properties(self):
self._pull_full_properties = True

View File

@@ -0,0 +1,41 @@
# Copyright 2016 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.
def getFakeCPCconf():
conf = {'cpcsubset_name': "S12subset",
'cpc_uuid': "1232132",
'max_processors': 10,
'max_memory_mb': 200,
'max_partitions': 10
}
return conf
def getFakeInstance():
props = {'hostname': 'DummyPartition'}
instance = Instance(props)
return instance
class Instance(object):
hostname = None
def __init__(self, properties):
global hostname
hostname = properties['hostname']
def save(self):
return

View File

@@ -11,9 +11,10 @@
# 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_dpm.tests.unit.virt.dpm import fakecpcs
from zhmcclient._cpc import Cpc
from zhmcclient._logging import _log_call
from zhmcclient._manager import BaseManager
from zhmcclient._resource import BaseResource
import zhmcclient
@@ -45,6 +46,98 @@ def getzhmclientCpcmgr(ipaddress, username, password):
return cpcmgr
def getFakeCPC(cpcmanager=None):
cpc_props = dict()
cpc_props['object-uri'] = "/api/cpc/dummy"
cpc_props['name'] = "fakecpc"
cpc_props['storage-customer'] = 100
cpc_props['processor-count-pending-ifl'] = 6
cpc_props['processor-count-ifl'] = 12
cpc_props['storage-customer-available'] = 500
if not cpcmanager:
cpcmanager = getdummyCpcmgr()
cpc = Cpc(cpcmanager, cpc_props['object-uri'], cpc_props)
return cpc
def getFakeCPCconf():
conf = {'cpcsubset_name': "S12subset",
'cpc_uuid': "1232132",
'max_processors': 10,
'max_memory_mb': 200,
'max_partitions': 10
}
return conf
def getFakeCPCwithProp(cpcmanager, cpc_props):
cpc = Cpc(cpcmanager, cpc_props['object-uri'], cpc_props)
return cpc
def getFakePartition():
partition_props = dict()
partition_props['name'] = "DummyPartition"
partition_props['object-uri'] = "/api/partitions/" \
"00000000-aaaa-bbbb-cccc-abcdabcdabcd"
partition = Partition(getdummyCpcmgr(), partition_props['object-uri'],
partition_props)
return partition
def getFakeNicManager():
nics = NicManager(getFakePartition())
return nics
def getFakeNic(properties=None):
if not properties:
properties = {}
properties['element-uri'] = "/api/partitions/" \
"00000000-aaaa-bbbb-cccc-abcdabcdabcd" \
"/nics/00000000-nics-bbbb-cccc-abcdabcdabcd"
nic = Nic(getFakeNicManager(), properties['element-uri'],
properties)
return nic
def getFakeHbaManager():
hbas = HbaManager(getFakePartition())
return hbas
def getFakeHba(properties=None):
if not properties:
properties = {}
properties['element-uri'] = "/api/partitions/" \
"00000000-aaaa-bbbb-cccc-abcdabcdabcd" \
"/hbas/00000000-nics-bbbb-cccc-abcdabcdabcd"
hba = Hba(getFakeHbaManager(), properties['element-uri'],
properties)
return hba
def getFakeAdapterManager():
adapters = AdapterManager(getFakeCPC())
return adapters
def getFakeAdapter(properties=None):
if not properties:
properties = {}
properties['object-uri'] = "/api/adapters/" \
"9b926334-8e01-11e5-b1a4-9abe94228ee1"
properties['type'] = "fcp"
adapter = Adapter(getFakeAdapterManager(), properties['object-uri'],
properties)
return adapter
class CpcManager(BaseManager):
"""fake cpcmanager"""
@@ -58,11 +151,157 @@ class CpcManager(BaseManager):
def list(self, full_properties=False):
cpc_list = []
cpc_list.append(fakecpcs.getFakeCPC(getdummyCpcmgr()))
cpc_list.append(getFakeCPC(getdummyCpcmgr()))
return cpc_list
def find(self, **kwargs):
return fakecpcs.getFakeCPC(getdummyCpcmgr())
return getFakeCPC(getdummyCpcmgr())
class Cpc(BaseResource):
def __init__(self, manager, uri, properties):
super(Cpc, self).__init__(manager, uri, properties,
uri_prop='object-uri',
name_prop='name')
@property
@_log_call
def dpm_enabled(self):
return True
def pull_full_properties(self):
self._pull_full_properties = True
@property
@_log_call
def adapters(self):
return getFakeAdapterManager()
class PartitionManager(BaseManager):
"""fake cpcmanager"""
def __init__(self, cpc):
# This function should not go into the docs.
# Parameters:
# cpc (:class:`~zhmcclient.Cpc`):
# CPC defining the scope for this manager.
super(PartitionManager, self).__init__(cpc)
def list(self, full_properties=False):
partition_list = []
partition_list.append(getFakePartition())
return partition_list
def find(self, **kwargs):
return getFakePartition()
class Partition(BaseResource):
def __init__(self, manager, uri, properties):
super(Partition, self).__init__(
manager, uri, properties,
uri_prop='object-uri', name_prop='name')
def pull_full_properties(self):
self._pull_full_properties = True
class NicManager(BaseManager):
"""fake cpcmanager"""
def __init__(self, partition):
# This function should not go into the docs.
# Parameters:
# partition (:class:`~zhmcclient.Partition`):
# Partition defining the scope for this manager.
super(NicManager, self).__init__(partition)
def list(self, full_properties=False):
nic_list = []
nic_list.append(getFakeNic())
return nic_list
def create(self, properties):
return getFakeNic(properties)
def find(self, **kwargs):
return getFakeNic()
class Nic(BaseResource):
def __init__(self, manager, uri, properties):
super(Nic, self).__init__(manager, uri, properties,
uri_prop='object-uri',
name_prop='name')
def pull_full_properties(self):
self._pull_full_properties = True
class HbaManager(BaseManager):
"""fake cpcmanager"""
def __init__(self, partition):
# This function should not go into the docs.
# Parameters:
# partition (:class:`~zhmcclient.Partition`):
# Partition defining the scope for this manager.
super(HbaManager, self).__init__(partition)
def list(self, full_properties=False):
hba_list = []
hba_list.append(getFakeHba())
return hba_list
def create(self, properties):
return getFakeHba(properties)
def find(self, **kwargs):
return getFakeHba()
class Hba(BaseResource):
def __init__(self, manager, uri, properties):
super(Hba, self).__init__(manager, uri, properties,
uri_prop='object-uri',
name_prop='name')
def pull_full_properties(self):
self._pull_full_properties = True
class AdapterManager(BaseManager):
"""fake cpcmanager"""
def __init__(self, partition):
# This function should not go into the docs.
# Parameters:
# partition (:class:`~zhmcclient.Partition`):
# Partition defining the scope for this manager.
super(AdapterManager, self).__init__(partition)
def list(self, full_properties=False):
adapter_list = []
adapter_list.append(getFakeAdapter())
return adapter_list
def create(self, properties):
return getFakeAdapter(properties)
def find(self, **kwargs):
return getFakeAdapter()
class Adapter(BaseResource):
def __init__(self, manager, uri, properties):
super(Adapter, self).__init__(manager, uri, properties,
uri_prop='object-uri',
name_prop='name')
def pull_full_properties(self):
self._pull_full_properties = True
class Session(object):

View File

@@ -16,7 +16,7 @@ import json
import mock
from nova.test import TestCase
from nova_dpm.tests.unit.virt.dpm import fakecpcs
from nova_dpm.tests.unit.virt.dpm import fakeutils
from nova_dpm.tests.unit.virt.dpm import fakezhmcclient
from nova_dpm.virt.dpm import host
@@ -27,13 +27,12 @@ cpcsubset unit testcase
def fakeHost():
session = fakezhmcclient.Session("dummy", "dummy",
"dummy")
client = fakezhmcclient.Client(session)
session = fakezhmcclient.Session("hostip", "dummyhost", "dummyhost")
client = fakezhmcclient.Client(session)
cpcmanager = fakezhmcclient.getCpcmgrForClient(client)
cpc = fakecpcs.getFakeCPC(cpcmanager)
conf = fakecpcs.getFakeCPCconf()
cpc = fakezhmcclient.getFakeCPC(cpcmanager)
conf = fakezhmcclient.getFakeCPCconf()
host1 = host.Host(conf, cpc, client)
return host1
@@ -66,17 +65,14 @@ class HostTestCase(TestCase):
super(HostTestCase, self).setUp()
self._session = fakezhmcclient.Session(
"dummy", "dummy", "dummy")
self._client = fakezhmcclient.Client(self._session)
self._cpcmanager = fakezhmcclient.getCpcmgrForClient(self._client)
self._cpc = fakezhmcclient.getFakeCPC(self._cpcmanager)
self._conf = fakeutils.getFakeCPCconf()
@mock.patch.object(host.LOG, 'debug')
def test_host(self, mock_warning):
client = fakezhmcclient.Client(self._session)
cpcmanager = fakezhmcclient.getCpcmgrForClient(client)
cpc = fakecpcs.getFakeCPC(cpcmanager)
conf = fakecpcs.getFakeCPCconf()
host.Host(conf, cpc, client)
host.Host(self._conf, self._cpc, self._client)
expected_arg = "Host initializing done"
assertlogs = False
@@ -93,8 +89,8 @@ class HostTestCase(TestCase):
client = fakezhmcclient.Client(self._session)
cpcmanager = fakezhmcclient.getCpcmgrForClient(client)
cpc = fakecpcs.getFakeCPC(cpcmanager)
conf = fakecpcs.getFakeCPCconf()
cpc = fakezhmcclient.getFakeCPC(cpcmanager)
conf = fakeutils.getFakeCPCconf()
host1 = host.Host(conf, cpc, client)
host_properties = host1.properties

View File

@@ -0,0 +1,84 @@
# Copyright 2016 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.
import mock
from nova.compute import manager as compute_manager
from nova.test import TestCase
from nova_dpm.tests.unit.virt.dpm import fakeutils
from nova_dpm.tests.unit.virt.dpm import fakezhmcclient
from nova_dpm.virt.dpm import vm
from nova_dpm.virt.dpm.vm import Instance
"""
vm unit testcase
"""
vm.zhmcclient = fakezhmcclient
session = fakezhmcclient.Session("hostip", "dummyhost", "dummyhost")
client = fakezhmcclient.Client(session)
cpc = fakezhmcclient.getFakeCPC()
conf = fakeutils.getFakeCPCconf()
inst = Instance(fakeutils.getFakeInstance(), cpc, client)
inst.partition = fakezhmcclient.getFakePartition()
class VmNicTestCase(TestCase):
def setUp(self):
super(VmNicTestCase, self).setUp()
inst.partition.nics = fakezhmcclient.getFakeNicManager()
@mock.patch.object(vm.LOG, 'debug')
def test_attach_nic(self, mock_debug):
vif1 = {'id': 1234, 'type': 'dpm_vswitch',
'address': "12-34-56-78-9A-BC",
'details':
{'object-id': '00000000-aaaa-bbbb-cccc-abcdabcdabcd'}}
network_info = [vif1]
nic_interface = inst.attach_nic(conf, network_info)
self.assertEqual(nic_interface.properties['name'],
"OpenStack_Port_1234")
self.assertEqual(nic_interface.properties['object-uri'],
"/api/partitions/00000000-aaaa-bbbb-"
"cccc-abcdabcdabcd/nics/00000000-nics-"
"bbbb-cccc-abcdabcdabcd")
class VmHBATestCase(TestCase):
def setUp(self):
super(VmHBATestCase, self).setUp()
conf['physical_storage_adapter_mappings'] = \
["aaaaaaaa-bbbb-cccc-1123-567890abcdef:1"]
inst.partition.hbas = fakezhmcclient.getFakeHbaManager()
@mock.patch.object(vm.LOG, 'debug')
@mock.patch.object(compute_manager.ComputeManager, '_prep_block_device',
return_value="blockdeviceinfo")
def test_build_resources(self, mock_prep_block_dev, mock_debug):
context = None
novainstance = fakeutils.getFakeInstance()
block_device_mapping = None
resources = inst._build_resources(
context, novainstance, block_device_mapping)
self.assertEqual(resources['block_device_info'],
"blockdeviceinfo")
@mock.patch.object(vm.LOG, 'debug')
def test_attach_hba(self, mock_debug):
inst.attachHba(conf)