add more unit tests for deployment
Change-Id: I1807b0891cb09f91a14a9f0ef86eb0da07cfc486
This commit is contained in:
parent
8849903875
commit
c80a75a3ed
@ -154,7 +154,7 @@ class ActionHelper(object):
|
||||
"""
|
||||
adapter_info = adapter_db.get_adapter(user, adapter_id)
|
||||
metadata = cluster_db.get_cluster_metadata(user, cluster_id)
|
||||
adapter_info.update(metadata)
|
||||
adapter_info.update({const.METADATA: metadata})
|
||||
|
||||
for flavor_info in adapter_info[const.FLAVORS]:
|
||||
roles = flavor_info[const.ROLES]
|
||||
|
@ -81,6 +81,7 @@ class BaseInstaller(object):
|
||||
mapping_to = metadata['_self']['mapping_to']
|
||||
except Exception:
|
||||
mapping_to = None
|
||||
|
||||
return mapping_to
|
||||
|
||||
def _get_submeta_by_key(self, metadata, key):
|
||||
@ -138,6 +139,7 @@ class BaseInstaller(object):
|
||||
tmpl = Template(file=tmpl_dir, searchList=searchList)
|
||||
config = json.loads(tmpl.respond(), encoding='utf-8')
|
||||
config = json.loads(json.dumps(config), encoding='utf-8')
|
||||
|
||||
return config
|
||||
|
||||
@classmethod
|
||||
|
@ -202,6 +202,15 @@ class CobblerInstaller(OSInstaller):
|
||||
logging.debug("Failed to sync cobbler server! Error: %s" % ex)
|
||||
raise ex
|
||||
|
||||
def dump_system_info(self, host_id):
|
||||
|
||||
hostname = self.config_manager.get_hostname(host_id)
|
||||
if self.remote is None or not hostname:
|
||||
logging.info("[dump_system_info]Remote or hostname is None.")
|
||||
return {}
|
||||
|
||||
return self.remote.get_system_as_rendered(hostname)
|
||||
|
||||
def _generate_system_config(self, host_id, host_vars_dict):
|
||||
"""Generate updated system config from the template.
|
||||
|
||||
@ -349,9 +358,9 @@ class CobblerInstaller(OSInstaller):
|
||||
logging.info("System is None!")
|
||||
return False
|
||||
|
||||
hostname = self.config_manager.get_hostname(host_id)
|
||||
system = self.remote.get_system_as_rendered(hostname)
|
||||
system = self.dump_system_info(host_id)
|
||||
if system[self.POWER_TYPE] != 'ipmilan' or not system[self.POWER_USER]:
|
||||
# Set sytem power type to ipmilan if needs and set IPMI info
|
||||
ipmi_info = self.config_manager.get_host_ipmi_info(host_id)
|
||||
if not ipmi_info:
|
||||
logging.info('No IPMI information found! Failed power on.')
|
||||
|
@ -159,7 +159,7 @@ class ChefInstaller(PKInstaller):
|
||||
node_name,
|
||||
error)
|
||||
|
||||
def _add_roles(self, node, roles):
|
||||
def add_roles(self, node, roles):
|
||||
"""Add roles to the node.
|
||||
:param object node: The node object.
|
||||
:param list roles: The list of roles for this node.
|
||||
@ -206,7 +206,7 @@ class ChefInstaller(PKInstaller):
|
||||
|
||||
return node_attr
|
||||
|
||||
def update_node(self, node, roles, host_vars_dict):
|
||||
def update_node_attributes_by_roles(self, node, roles, host_vars_dict):
|
||||
"""Update node attributes to chef server."""
|
||||
if node is None:
|
||||
raise Exception("Node is None!")
|
||||
@ -215,16 +215,14 @@ class ChefInstaller(PKInstaller):
|
||||
logging.info("The list of roles is None.")
|
||||
return
|
||||
|
||||
# Add roles to node Rolelist on chef server.
|
||||
self._add_roles(node, roles)
|
||||
|
||||
# Update node attributes.
|
||||
node_config = self._generate_node_attributes(roles, host_vars_dict)
|
||||
available_attrs = ['default', 'normal', 'override']
|
||||
for attr in node_config:
|
||||
if attr in available_attrs:
|
||||
# print node_config[attr]
|
||||
setattr(node, attr, node_config[attr])
|
||||
node_attributes = getattr(node, attr).to_dict()
|
||||
util.merge_dict(node_attributes, node_config[attr])
|
||||
setattr(node, attr, node_attributes)
|
||||
|
||||
node.save()
|
||||
|
||||
@ -407,8 +405,8 @@ class ChefInstaller(PKInstaller):
|
||||
roles = self.config_manager.get_host_roles(host_id)
|
||||
|
||||
node = self.get_create_node(node_name, env_name)
|
||||
self.add_roles(node, roles)
|
||||
vars_dict = self._get_host_tmpl_vars(host_id, global_vars_dict)
|
||||
self.update_node(node, roles, vars_dict)
|
||||
|
||||
# set each host deployed config
|
||||
host_config = {}
|
||||
|
@ -96,8 +96,10 @@ class TestDeployAction(unittest2.TestCase):
|
||||
"url": "http://127.0.0.1"
|
||||
}
|
||||
},
|
||||
"os_config": {},
|
||||
"package_config": {}
|
||||
"metadata": {
|
||||
"os_config": {},
|
||||
"package_config": {}
|
||||
}
|
||||
}
|
||||
output = deploy.ActionHelper.get_adapter_info(1, 1, None)
|
||||
self.maxDiff = None
|
||||
|
@ -130,7 +130,7 @@ class TestCobblerInstaller(unittest2.TestCase):
|
||||
self.maxDiff = None
|
||||
self.assertDictEqual(self.expected_host_vars_dict, output)
|
||||
|
||||
def test_get_system_config(self):
|
||||
def test_generate_system_config(self):
|
||||
expected_system_config = {
|
||||
"name": "server01.test",
|
||||
"hostname": "server01",
|
||||
@ -279,3 +279,15 @@ class TestCobblerInstaller(unittest2.TestCase):
|
||||
output = self.test_cobbler.deploy()
|
||||
self.maxDiff = None
|
||||
self.assertDictEqual(expected_output, output)
|
||||
|
||||
def test_check_and_set_system_impi(self):
|
||||
self.test_cobbler._update_system_config = Mock()
|
||||
self.test_cobbler.dump_system_info = Mock()
|
||||
self.test_cobbler.dump_system_info.return_value = {
|
||||
'power_type': 'ipmilan',
|
||||
'power_address': '',
|
||||
'power_user': '',
|
||||
'power_pass': ''
|
||||
}
|
||||
output = self.test_cobbler._check_and_set_system_impi(3, "test_sys_id")
|
||||
self.assertTrue(output)
|
||||
|
@ -73,7 +73,7 @@ class TestChefInstaller(unittest2.TestCase):
|
||||
cluster_dict = self.test_chef._get_cluster_tmpl_vars()
|
||||
vars_dict = self.test_chef._get_host_tmpl_vars(2, cluster_dict)
|
||||
expected_node_attr = {
|
||||
"override_attributes": {
|
||||
"override": {
|
||||
"openstack": {
|
||||
"endpoints": {
|
||||
"compute-vnc-bind": {
|
||||
@ -408,7 +408,7 @@ class TestChefInstaller(unittest2.TestCase):
|
||||
self.test_chef.update_environment = Mock()
|
||||
self.test_chef.update_databags = Mock()
|
||||
self.test_chef.get_create_node = Mock()
|
||||
self.test_chef.update_node = Mock()
|
||||
self.test_chef.add_roles = Mock()
|
||||
|
||||
output = self.test_chef.deploy()
|
||||
self.maxDiff = None
|
||||
|
@ -20,6 +20,7 @@ import unittest2
|
||||
os.environ['COMPASS_IGNORE_SETTING'] = 'true'
|
||||
|
||||
from compass.deployment.installers.config_manager import BaseConfigManager
|
||||
from compass.deployment.utils import constants as const
|
||||
from compass.tests.deployment.test_data import config_data
|
||||
from compass.utils import setting_wrapper as compass_setting
|
||||
reload(compass_setting)
|
||||
@ -29,17 +30,37 @@ class TestConfigManager(unittest2.TestCase):
|
||||
"""Test ConfigManager methods."""
|
||||
def setUp(self):
|
||||
super(TestConfigManager, self).setUp()
|
||||
adapter_test_info = config_data.adapter_test_config
|
||||
cluster_test_info = config_data.cluster_test_config
|
||||
hosts_test_info = config_data.hosts_test_config
|
||||
self.test_config_manager = BaseConfigManager(adapter_test_info,
|
||||
cluster_test_info,
|
||||
hosts_test_info)
|
||||
self.adapter_test_info = config_data.adapter_test_config
|
||||
self.cluster_test_info = config_data.cluster_test_config
|
||||
self.hosts_test_info = config_data.hosts_test_config
|
||||
self.test_config_manager = BaseConfigManager(self.adapter_test_info,
|
||||
self.cluster_test_info,
|
||||
self.hosts_test_info)
|
||||
|
||||
def tearDown(self):
|
||||
super(TestConfigManager, self).tearDown()
|
||||
del self.test_config_manager
|
||||
|
||||
def test_get_cluster_baseinfo(self):
|
||||
expected_output = {
|
||||
"id": 1,
|
||||
"name": "test",
|
||||
"os_name": "Ubuntu-12.04-x86_64"
|
||||
}
|
||||
output = self.test_config_manager.get_cluster_baseinfo()
|
||||
self.maxDiff = None
|
||||
self.assertDictEqual(expected_output, output)
|
||||
|
||||
def test_get_host_id_list(self):
|
||||
expected_output = [1, 2, 3]
|
||||
output = self.test_config_manager.get_host_id_list()
|
||||
self.assertEqual(expected_output, output)
|
||||
|
||||
def test_get_cluster_flavor_info(self):
|
||||
expected_output = self.cluster_test_info[const.FLAVOR]
|
||||
output = self.test_config_manager.get_cluster_flavor_info()
|
||||
self.assertDictEqual(expected_output, output)
|
||||
|
||||
def test_get_cluster_roles_mapping(self):
|
||||
expected_output = {
|
||||
"os_controller": {
|
||||
|
@ -42,8 +42,9 @@ class TestBaseInstaller(unittest2.TestCase):
|
||||
config = case["config"]
|
||||
expected_output = case["expected_output"]
|
||||
|
||||
output = self.test_installer.get_tmpl_vars_from_metadata(metadata,
|
||||
config)
|
||||
output = self.test_installer.get_tmpl_vars_from_metadata(
|
||||
metadata, config
|
||||
)
|
||||
|
||||
self.maxDiff = None
|
||||
self.assertDictEqual(expected_output, output)
|
||||
|
@ -350,6 +350,11 @@ hosts_test_config = {
|
||||
"subnet": "10.0.0.0/24"
|
||||
}
|
||||
},
|
||||
"ipmi_credentials": {
|
||||
"ip": "172.16.100.104",
|
||||
"username": "admin",
|
||||
"password": "admin"
|
||||
},
|
||||
"os_config": {
|
||||
"general": {
|
||||
"language": "EN",
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"override_attributes": {
|
||||
"override": {
|
||||
"openstack": {
|
||||
"endpoints": {
|
||||
"compute-vnc-bind": {
|
||||
|
@ -101,26 +101,27 @@ class TestChefInstaller(unittest2.TestCase):
|
||||
env_name = self.test_chef.get_env_name(self.dist_sys_name,
|
||||
cluster_name)
|
||||
|
||||
test_node = self.test_chef.get_node(node_name, env_name)
|
||||
test_node = self.test_chef.get_create_node(node_name, env_name)
|
||||
self.assertIsNotNone(test_node)
|
||||
self._register(test_node)
|
||||
|
||||
cluster_dict = self.test_chef._get_cluster_tmpl_vars()
|
||||
vars_dict = self.test_chef._get_host_tmpl_vars(host_id, cluster_dict)
|
||||
|
||||
self.test_chef.update_node(test_node, roles, vars_dict)
|
||||
self.test_chef.update_node_attributes_by_roles(
|
||||
test_node, roles, vars_dict
|
||||
)
|
||||
self.test_chef.add_roles(test_node, roles)
|
||||
|
||||
result_node = chef.Node(node_name, self.chef_test_api)
|
||||
|
||||
self.assertListEqual(result_node.run_list, ['role[os-compute]'])
|
||||
self.assertEqual(result_node.chef_environment, env_name)
|
||||
expected_node_attr = {
|
||||
"override_attributes": {
|
||||
"openstack": {
|
||||
"endpoints": {
|
||||
"compute-vnc-bind": {
|
||||
"host": "12.234.32.101"
|
||||
}
|
||||
"openstack": {
|
||||
"endpoints": {
|
||||
"compute-vnc-bind": {
|
||||
"host": "12.234.32.101"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -135,8 +136,8 @@ class TestChefInstaller(unittest2.TestCase):
|
||||
env_name = self.test_chef.get_env_name(self.dist_sys_name,
|
||||
cluster_name)
|
||||
vars_dict = self.test_chef._get_cluster_tmpl_vars()
|
||||
env_attrs = self.test_chef._get_env_attributes(vars_dict)
|
||||
test_env = self.test_chef.get_environment(env_name)
|
||||
env_attrs = self.test_chef._generate_env_attributes(vars_dict)
|
||||
test_env = self.test_chef.get_create_environment(env_name)
|
||||
self.assertIsNotNone(test_env)
|
||||
self._register(test_env)
|
||||
|
||||
@ -254,7 +255,7 @@ class TestChefInstaller(unittest2.TestCase):
|
||||
self._register(test_node)
|
||||
|
||||
input_roles = ['test_role_1', 'test_role_2', 'test_role_a']
|
||||
self.test_chef._add_roles(test_node, input_roles)
|
||||
self.test_chef.add_roles(test_node, input_roles)
|
||||
|
||||
expected_roles = [('role[%s]' % role) for role in input_roles]
|
||||
self.assertSetEqual(set(expected_roles), set(test_node.run_list))
|
||||
|
@ -6,5 +6,6 @@
|
||||
"horizon": "horizon"
|
||||
},
|
||||
"keystone": {
|
||||
"identity": "identity"
|
||||
}
|
||||
}
|
||||
|
@ -151,6 +151,9 @@
|
||||
"compute-novnc-bind": {
|
||||
"bind_interface": "$os_controller.management.interface"
|
||||
},
|
||||
"compute-vnc-bind": {
|
||||
"bind_interface" : "$os_compute_worker.management.interface"
|
||||
},
|
||||
"vnc_bind": {
|
||||
"bind_interface": "$os_controller.management.interface"
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user