fuel-plugin-nsx-t/plugin_test/tests/base_plugin_test.py

99 lines
3.5 KiB
Python

"""Copyright 2016 Mirantis, Inc.
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
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 os
from proboscis.asserts import assert_true
from fuelweb_test import logger
from fuelweb_test.helpers import utils
from fuelweb_test.helpers.utils import pretty_log
from fuelweb_test.tests.base_test_case import TestBasic
from helpers import settings
class TestNSXtBase(TestBasic):
"""Base class for NSX-T plugin tests"""
def __init__(self):
super(TestNSXtBase, self).__init__()
self.default = settings
def install_nsxt_plugin(self):
"""Download and install NSX-T plugin on master node.
:return: None
"""
master_ip = self.ssh_manager.admin_ip
utils.upload_tarball(ip=master_ip,
tar_path=self.default.NSXT_PLUGIN_PATH,
tar_target='/var')
utils.install_plugin_check_code(
ip=master_ip,
plugin=os.path.basename(self.default.NSXT_PLUGIN_PATH))
def enable_plugin(self, cluster_id, settings=None):
"""Enable NSX-T plugin on cluster.
:param cluster_id: cluster id
:param settings: settings in dict format
:return: None
"""
msg = "Plugin couldn't be enabled. Check plugin version. Test aborted"
settings = settings if settings else {}
checker = self.fuel_web.check_plugin_exists(cluster_id,
self.default.PLUGIN_NAME)
assert_true(checker, msg)
logger.info('Configure cluster with '
'following parameters: \n{}'.format(pretty_log(settings)))
self.fuel_web.update_plugin_settings(
cluster_id,
self.default.PLUGIN_NAME,
self.default.NSXT_PLUGIN_VERSION,
dict(self.default.plugin_configuration, **settings))
def reconfigure_cluster_interfaces(self, cluster_id):
# clear network mapping enp0s6 for all deployed nodes
nodes = self.fuel_web.client.list_cluster_nodes(cluster_id)
for node in nodes:
self.fuel_web.update_node_networks(node['id'],
settings.assigned_networks)
def delete_nsxt_plugin(self, failover=False):
"""Delete NSX-T plugin
:param failover: True if we expect that plugin won't be deleted
:return:
"""
plugin_name = self.default.PLUGIN_NAME
plugin_vers = self.default.NSXT_PLUGIN_VERSION
tmp = "Plugin '{0}' {1} removed"
msg = tmp.format(plugin_name, 'was' if failover else "wasn't")
cmd = 'fuel plugins --remove {0}=={1}'.format(plugin_name, plugin_vers)
self.ssh_manager.check_call(
ip=self.ssh_manager.admin_ip,
command=cmd,
expected=[1 if failover else 0],
raise_on_err=not failover
)
output = self.ssh_manager.check_call(
ip=self.ssh_manager.admin_ip,
command='fuel2 plugins list -f value -c name'
).stdout[-1].split(' ')
assert_true(plugin_name in output != failover, msg)