Disable iscsi actions for clusters without emc plugins

Change-Id: I2588c6e86a3dc65fc3e6269d8e3927f28d47b0f7
This commit is contained in:
Valyavskiy Viacheslav 2015-09-22 23:52:52 +03:00
parent 1b3ac1c506
commit 0f53d73f25
3 changed files with 86 additions and 0 deletions

View File

@ -18,6 +18,7 @@ from octane.helpers import disk
from octane import magic_consts
from octane.util import env as env_util
from octane.util import node as node_util
from octane.util import plugin
from octane.util import ssh
@ -79,6 +80,8 @@ class ComputeUpgrade(upgrade.UpgradeHandler):
disk.create_partition(disks[0]['name'], size, self.node)
def backup_iscsi_initiator_info(self):
if not plugin.is_enabled(self.env, 'emc_vnx'):
return
bup_file_path = get_iscsi_bup_file_path(self.node)
file_dir = os.path.dirname(bup_file_path)
if not os.path.exists(file_dir):
@ -86,6 +89,8 @@ class ComputeUpgrade(upgrade.UpgradeHandler):
ssh.sftp(self.node).get(magic_consts.ISCSI_CONFIG_PATH, bup_file_path)
def restore_iscsi_initiator_info(self):
if not plugin.is_enabled(self.env, 'emc_vnx'):
return
bup_file_path = get_iscsi_bup_file_path(self.node)
if not os.path.exists(bup_file_path):
raise Exception("Backup iscsi configuration is not present for "

View File

@ -0,0 +1,56 @@
# 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
import pytest
from octane.util import plugin
@pytest.mark.parametrize("installed,enabled", [
(False, False),
(True, False),
(True, True),
])
def test_check_plugin(installed, enabled):
settings = {'editable': {}}
if installed:
settings['editable']['emc_vnx'] = EMC_VNX_SETTINGS
settings['editable']['emc_vnx']['metadata']['enabled'] = enabled
env = mock.Mock(spec_set=['get_settings_data'])
env.get_settings_data.return_value = settings
assert plugin.is_installed(env, 'emc_vnx') is installed
assert plugin.is_enabled(env, 'emc_vnx') is enabled
EMC_VNX_SETTINGS = {
'emc_username': {
'value': 'username',
},
'emc_pool_name': {
'value': '',
},
'emc_sp_a_ip': {
'value': '192.168.200.30',
},
'emc_sp_b_ip': {
'value': '192.168.200.31',
},
'emc_password': {
'value': 'password',
},
'metadata': {
'enabled': 'false'
}
}

25
octane/util/plugin.py Normal file
View File

@ -0,0 +1,25 @@
# 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 is_installed(env, plugin_name):
settings = env.get_settings_data()
if plugin_name in settings['editable']:
return True
return False
def is_enabled(env, plugin_name):
settings = env.get_settings_data()
if plugin_name not in settings['editable']:
return False
return settings['editable'][plugin_name]['metadata']['enabled']