Add Proliant Hardware Manager for IPA

This commit adds a IPA hardware manager for
exposing functions specific to Proliant hardware
in Ironic Python Agent.

Co-Authored-By: Ramakrishnan G <rameshg87@gmail.com>
Implements: blueprint ipa-hardware-manager
Change-Id: I286fcc4e88934b4a425e57f5b676d6cbd64690c4
This commit is contained in:
Anusha Ramineni 2015-02-19 19:42:43 +05:30
parent 36b3f22dc2
commit 91062d458f
6 changed files with 139 additions and 1 deletions

View File

View File

@ -0,0 +1,46 @@
# Copyright 2015 Hewlett-Packard Development Company, L.P.
#
# 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 ironic_python_agent import hardware
from oslo.concurrency import processutils
from proliantutils.hpssa import manager as hpssa_manager
class ProliantHardwareManager(hardware.GenericHardwareManager):
HARDWARE_MANAGER_VERSION = "3"
def get_clean_steps(self):
pass
def evaluate_hardware_support(cls):
return hardware.HardwareSupport.SERVICE_PROVIDER
def erase_block_device(self, block_device):
npass = 3
cmd = ('shred', '--force', '--zero', '--verbose',
'--iterations', npass, block_device.name)
processutils.execute(*cmd)
def erase_devices(self):
block_devices = self.list_block_devices()
for block_device in block_devices:
self.erase_block_device(block_device)
def create_raid_configuration(self, raid_config):
return hpssa_manager.create_configuration(raid_config=raid_config)
def delete_raid_configuration(self):
hpssa_manager.delete_configuration()

View File

@ -0,0 +1,28 @@
# Copyright 2015 Hewlett-Packard Development Company, L.P.
#
# 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 sys
import mock
from oslo.utils import importutils
ironic_python_agent = importutils.try_import('ironic_python_agent')
if not ironic_python_agent:
ipa_mock = mock.MagicMock()
sys.modules['ironic_python_agent'] = ipa_mock
sys.modules['ironic_python_agent.errors'] = ipa_mock.errors
sys.modules['ironic_python_agent.hardware'] = ipa_mock.hardware
ipa_mock.hardware.GenericHardwareManager = mock.MagicMock
if 'proliantutils.ipa_hw_manager' in sys.modules:
reload(sys.modules['proliantutils.ipa_hw_manager'])

View File

@ -0,0 +1,60 @@
# Copyright 2015 Hewlett-Packard Development Company, L.P.
#
# 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 oslo.concurrency import processutils
import testtools
from proliantutils.hpssa import manager as hpssa_manager
from proliantutils.ipa_hw_manager import hardware_manager
class ProliantHardwareManagerTestCase(testtools.TestCase):
def setUp(self):
self.hardware_manager = hardware_manager.ProliantHardwareManager()
super(ProliantHardwareManagerTestCase, self).setUp()
@mock.patch.object(processutils, 'execute')
def test_erase_block_device(self, processutils_mock):
device = mock.MagicMock()
p = mock.PropertyMock(return_value='/dev/sda')
type(device).name = p
cmd_expected = ('shred', '--force', '--zero', '--verbose',
'--iterations', 3, '/dev/sda')
self.hardware_manager.erase_block_device(device)
processutils_mock.assert_called_once_with(*cmd_expected)
@mock.patch.object(hardware_manager.ProliantHardwareManager,
'erase_block_device')
def test_erase_devices(self, erase_block_device_mock):
disks = ['/dev/sda', '/dev/sdb']
self.hardware_manager.list_block_devices.return_value = disks
self.hardware_manager.erase_devices()
self.hardware_manager.list_block_devices.assert_called_once_with()
erase_block_device_mock.assert_any_call('/dev/sda')
erase_block_device_mock.assert_any_call('/dev/sdb')
@mock.patch.object(hpssa_manager, 'create_configuration')
def test_create_raid_configuration(self, create_mock):
create_mock.return_value = 'current-config'
manager = self.hardware_manager
ret = manager.create_raid_configuration(raid_config='target')
create_mock.assert_called_once_with(raid_config='target')
self.assertEqual('current-config', ret)
@mock.patch.object(hpssa_manager, 'delete_configuration')
def test_delete_raid_configuration(self, delete_mock):
self.hardware_manager.delete_raid_configuration()
delete_mock.assert_called_once_with()

View File

@ -1,3 +1,4 @@
six>=1.9.0
oslo.concurrency>=1.4.1 # Apache-2.0
oslo.utils>=1.2.0
jsonschema>=2.4.0

View File

@ -1,6 +1,6 @@
[metadata]
name = proliantutils
summary = Client Library for interfacing with various
summary = Client Library for interfacing with various
devices in HP Proliant Servers.
description-file =
README.rst
@ -22,3 +22,6 @@ classifier =
packages =
proliantutils
[entry_points]
ironic_python_agent.hardware_managers =
hp-proliant = proliantutils.ipa_hw_manager.hardware_manager:ProliantHardwareManager