From 0f53d73f25ba458902a293b1174fad06eeff706d Mon Sep 17 00:00:00 2001 From: Valyavskiy Viacheslav Date: Tue, 22 Sep 2015 23:52:52 +0300 Subject: [PATCH] Disable iscsi actions for clusters without emc plugins Change-Id: I2588c6e86a3dc65fc3e6269d8e3927f28d47b0f7 --- octane/handlers/upgrade/compute.py | 5 +++ octane/tests/test_plugin.py | 56 ++++++++++++++++++++++++++++++ octane/util/plugin.py | 25 +++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 octane/tests/test_plugin.py create mode 100644 octane/util/plugin.py diff --git a/octane/handlers/upgrade/compute.py b/octane/handlers/upgrade/compute.py index f0edf9fb..633e8d71 100644 --- a/octane/handlers/upgrade/compute.py +++ b/octane/handlers/upgrade/compute.py @@ -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 " diff --git a/octane/tests/test_plugin.py b/octane/tests/test_plugin.py new file mode 100644 index 00000000..4d246b8e --- /dev/null +++ b/octane/tests/test_plugin.py @@ -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' + } +} diff --git a/octane/util/plugin.py b/octane/util/plugin.py new file mode 100644 index 00000000..0068cc47 --- /dev/null +++ b/octane/util/plugin.py @@ -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']