modify config_manager module method name: get_host_fullname

Change-Id: Ibf7780bb8b3baf8d5412fbbbb16733ee37c84440
This commit is contained in:
graceyu08 2014-08-08 13:51:34 -07:00
parent c03d4f849c
commit ebcf1cbd3f
11 changed files with 320 additions and 32 deletions

View File

@ -179,7 +179,7 @@ class BaseConfigManager(object):
return base_info
def get_host_name(self, host_id):
def get_host_fullname(self, host_id):
host_info = self._get_host_info(host_id)
if not host_info:
return None

View File

@ -127,13 +127,13 @@ class CobblerInstaller(OSInstaller):
hosts_deploy_config = {}
for host_id in clusterhost_ids:
fullname = self.config_manager.get_host_name(host_id)
hostname = self.config_manager.get_hostname(host_id)
vars_dict = self._get_host_tmpl_vars_dict(host_id,
global_vars_dict,
fullname=fullname,
hostname=hostname,
profile=profile)
self.update_host_config_to_cobbler(host_id, fullname, vars_dict)
self.update_host_config_to_cobbler(host_id, hostname, vars_dict)
# set host deploy config
temp = {}
@ -163,15 +163,15 @@ class CobblerInstaller(OSInstaller):
log_dir_prefix = compass_setting.INSTALLATION_LOGDIR[self.NAME]
for host_id in clusterhost_list:
fullname = self.config_manager.get_host_name(host_id)
self._clean_log(log_dir_prefix, fullname)
hostname = self.config_manager.get_hostname(host_id)
self._clean_log(log_dir_prefix, hostname)
def redeploy(self):
"""redeploy hosts."""
host_ids = self.config_manager.get_host_id_list()
for host_id in host_ids:
fullname = self.config_manager.get_host_name(host_id)
sys_id = self._get_system_id(fullname)
hostname = self.config_manager.get_hostname(host_id)
sys_id = self._get_system_id(hostname)
if sys_id:
self._netboot_enabled(sys_id)
@ -229,25 +229,25 @@ class CobblerInstaller(OSInstaller):
profile = result[0]
return profile
def _get_system_id(self, fullname):
def _get_system_id(self, hostname):
"""get system reference id for the host."""
sys_name = fullname
sys_name = hostname
sys_id = None
system_info = self.remote.find_system({"name": fullname})
system_info = self.remote.find_system({"name": hostname})
if not system_info:
# Create a new system
sys_id = self.remote.new_system(self.token)
self.remote.modify_system(sys_id, "name", fullname, self.token)
self.remote.modify_system(sys_id, "name", hostname, self.token)
logging.debug('create new system %s for %s', sys_id, sys_name)
else:
sys_id = self.remote.get_system_handle(sys_name, self.token)
return sys_id
def _clean_system(self, fullname):
def _clean_system(self, hostname):
"""clean system."""
sys_name = fullname
sys_name = hostname
try:
self.remote.remove_system(sys_name, self.token)
logging.debug('system %s is removed', sys_name)
@ -271,9 +271,9 @@ class CobblerInstaller(OSInstaller):
log_dir = os.path.join(log_dir_prefix, system_name)
shutil.rmtree(log_dir, True)
def update_host_config_to_cobbler(self, host_id, fullname, vars_dict):
def update_host_config_to_cobbler(self, host_id, hostname, vars_dict):
"""update host config and upload to cobbler server."""
sys_id = self._get_system_id(fullname)
sys_id = self._get_system_id(hostname)
system_config = self._get_system_config(host_id, vars_dict)
logging.debug('%s system config to update: %s', host_id, system_config)
@ -290,11 +290,11 @@ class CobblerInstaller(OSInstaller):
"""Delete the host from cobbler server and clean up the installation
progress.
"""
fullname = self.config_manager.get_host_name(host_id)
hostname = self.config_manager.get_hostname(host_id)
try:
log_dir_prefix = compass_setting.INSTALLATION_LOGDIR[self.NAME]
self._clean_system(fullname)
self._clean_log(log_dir_prefix, fullname)
self._clean_system(hostname)
self._clean_log(log_dir_prefix, hostname)
except Exception as ex:
logging.info("Deleting host got exception: %s", ex.message)
@ -313,7 +313,7 @@ class CobblerInstaller(OSInstaller):
profile = self._get_profile_from_server(os_version)
vars_dict[self.PROFILE] = profile
# Set fullname, MAC address and hostname, networks, dns and so on.
# Set hostname, MAC address and hostname, networks, dns and so on.
host_baseinfo = self.config_manager.get_host_baseinfo(host_id)
util.merge_dict(vars_dict, host_baseinfo)
@ -340,8 +340,8 @@ class CobblerInstaller(OSInstaller):
logging.info("System is None!")
return False
fullname = self.config_manager.get_host_name(host_id)
system = self.remote.get_system_as_rendered(fullname)
hostname = self.config_manager.get_hostname(host_id)
system = self.remote.get_system_as_rendered(hostname)
if system[self.POWER_TYPE] != 'ipmilan' or not system[self.POWER_USER]:
ipmi_info = self.config_manager.get_host_ipmi_info(host_id)
if not ipmi_info:
@ -360,8 +360,8 @@ class CobblerInstaller(OSInstaller):
return True
def poweron(self, host_id):
fullname = self.config_manager.get_host_name(host_id)
sys_id = self._get_system_id(fullname)
hostname = self.config_manager.get_hostname(host_id)
sys_id = self._get_system_id(hostname)
if not self._check_and_set_system_impi(sys_id):
return
@ -369,8 +369,8 @@ class CobblerInstaller(OSInstaller):
logging.info("Host with ID=%d starts to power on!" % host_id)
def poweroff(self, host_id):
fullname = self.config_manager.get_host_name(host_id)
sys_id = self._get_system_id(fullname)
hostname = self.config_manager.get_hostname(host_id)
sys_id = self._get_system_id(hostname)
if not self._check_and_set_system_impi(sys_id):
return
@ -378,8 +378,8 @@ class CobblerInstaller(OSInstaller):
logging.info("Host with ID=%d starts to power off!" % host_id)
def reset(self, host_id):
fullname = self.config_manager.get_host_name(host_id)
sys_id = self._get_system_id(fullname)
hostname = self.config_manager.get_hostname(host_id)
sys_id = self._get_system_id(hostname)
if not self._check_and_set_system_impi(sys_id):
return

View File

@ -117,7 +117,7 @@ class ChefInstaller(PKInstaller):
self.delete_node(host_id)
def delete_node(self, host_id):
fullname = self.config_manager.get_host_name(host_id)
fullname = self.config_manager.get_host_fullname(host_id)
node = self.get_node(fullname)
self._delete_node(node)
@ -343,7 +343,7 @@ class ChefInstaller(PKInstaller):
hosts_deployed_configs = {}
for host_id in host_list:
node_name = self.config_manager.get_host_name(host_id)
node_name = self.config_manager.get_host_fullname(host_id)
roles = self.config_manager.get_host_roles(host_id)
node = self.get_node(node_name, env_name)
@ -386,7 +386,7 @@ class ChefInstaller(PKInstaller):
host_ids = self.config_manager.get_host_id_list()
os_installer_configs = {}
for host_id in host_ids:
fullname = self.config_manager.get_host_name(host_id)
fullname = self.config_manager.get_host_fullname(host_id)
temp = {
"tool": "chef",
"chef_url": self.installer_url
@ -402,7 +402,7 @@ class ChefInstaller(PKInstaller):
log_dir_prefix = compass_setting.INSTALLATION_LOGDIR[self.NAME]
hosts_list = self.config_manager.get_host_id_list()
for host_id in hosts_list:
fullname = self.config_manager.get_host_name()
fullname = self.config_manager.get_host_fullname()
self._clean_log(log_dir_prefix, fullname)
def _clean_log(self, log_dir_prefix, node_name):

View File

@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA2aiAT//LE2EIB4n/Y0MM8eiwcExy6xO0HEdwUMHuCHXM9g01
U4T9KWRHJ4kGDS8yUwgRXrz4BIVVYuHqs05t4TsU4VzsoQvtat0u6N7Ccs0GoyvQ
DkcVFWaAetnHGGEG7Yw3Epc553pwDhfajFKjziX2SW28XLFZhzxigciSPDccB0lS
IhbsdEZbAX9/ByPZ79HHnwexO0aSAIYhsXkKMSJ8ZlkcbXAY69UGTN+Hr9ScUDZg
W7VYn+MgQXDj+lv2pwbG7wI1GwywQCzCC07OZeiMCTVLSUOU+V8+i92R7b+Zdrtj
iBra6AR8k514CbSJmGWvHUCqPm2xY3pZzCTnUQIDAQABAoIBAQCYe+TQptpFTFAM
wA/MIZg7DZI2SkikCdy/hwjXetVg1e5uXliCl4OocNksiGFV8T+nTdqlbWuv9x0X
tj/vuD1gcjyxmaEpPirpF+WaPR0qwhopTDNpHUFXCcVuy40gtjDdUMLwYkOtuGgy
Z2Gztt2NOakuThONOK4JATPdyn8wcPyF9/z96fKSysqu2v2syD5Ql4XaXwLv47vR
bd/jgFZ3Fh8TbhWU8ss5qOKZMy9jK2VuLQRbheMGKaBA4YrTQHFmWWZpTrqW1ixR
eEPuMvD1q7P+8ynnNWsFJnUIB8l1RTuw8TKGPeXvzb2YbvOqwHwTSoA/Qwx9XIuf
ZdBSEErxAoGBAPAWsI9fO6C6uBrPW47Yui8OaDcXd+knF/DpJx8Xc243LDe/g/FA
eLczpw8dy2DOnMhWi7DGlzQL6GpBUuHTxpJmdiYxUbA7kYQucfZpdS9z6dGjkaOH
+RelZxLtifJSccKwPw3L8LsC8zzaXEPGA/gSrbMal1hr5aByy4cO6zf9AoGBAOgV
QpT+75EJ4MlABTDEQZroKPHPeoT7DGa6l5da9t9rIUXrfeK2fYzibS6fjHOFsAQN
R5+3aEZx6GXXKKd3uHcQ5K8RFd7I2bbDRRVRpLkFDJ6DuxRz1KfbVF1XJFO+FPGw
RcBL6qB2X6F6Gb5x0p7fOSNtQdcl0nJqfRPrprrlAoGBAN/7CvR2T9Z+20qHsE7v
eaJ0ulzLFB77TaZ+nPSwmAt2hVXs4VasYvHmyi+cCCRkHHf55ZAhdOYlRcn67yum
ulXSKN8wm5jhubuq6L6NW7nNVZEyG6iILaYVtLc/y7W5nE+YxPpGDGsrMWjP/cts
bD9+jXXNlOv0nOC2t5FkJaSxAoGAUwKvsv1QkO8YkMMuWBgKYy7g3kTYzNHCyMe6
yu9FV/pIh2rItxuQ4qBmbwOwR+2sXHanhLAkQvYhKrP/nY7L0wKe2SNiUDJE9QL5
JbvzEB6HOfdiJdmcWYGwtkYh/zYA5cWn3TUKMeTFJcu3g4/QxvSOymYc46hqknQW
Uta55yUCgYA7oJXdFyYkk68EWcleGC0EvB29Z0bnPg+SF4rWVI7sZRY2SihMTxkC
nYQtcEkNdxMP3HbrPmr8+VAMayzm2NdIp0zyhQx0z/bQ0UjsGXLFDg7xwc7fL22r
zUCV2oB+T/43vyM/jNaiRO1JDNdEZM97CS/SjmdA1CB1dEWSQTITrw==
-----END RSA PRIVATE KEY-----

View File

@ -19,6 +19,7 @@ import os
curr_dir = os.path.dirname(os.path.realpath(__file__))
test_tmpl_dir = os.path.join(curr_dir, 'templates')
test_client_key = os.path.join(curr_dir, 'client.pem')
adapter_test_config = {

View File

@ -0,0 +1,13 @@
# Copyright 2014 Huawei Technologies Co. Ltd
#
# 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.

View File

@ -0,0 +1,13 @@
# Copyright 2014 Huawei Technologies Co. Ltd
#
# 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.

View File

@ -0,0 +1,13 @@
# Copyright 2014 Huawei Technologies Co. Ltd
#
# 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.

View File

@ -0,0 +1,13 @@
# Copyright 2014 Huawei Technologies Co. Ltd
#
# 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.

View File

@ -0,0 +1,13 @@
# Copyright 2014 Huawei Technologies Co. Ltd
#
# 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.

View File

@ -0,0 +1,195 @@
#!/usr/bin/python
#
# Copyright 2014 Huawei Technologies Co. Ltd
#
# 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.
__author__ = "Grace Yu (grace.yu@huawei.com)"
"""Test Chef installer functionalities regarding to chef server side.
"""
from copy import deepcopy
from mock import Mock
import os
import unittest2
os.environ['COMPASS_IGNORE_SETTING'] = 'true'
from compass.tests.deployment.test_data import config_data
from compass.utils import setting_wrapper as compass_setting
reload(compass_setting)
from compass.deployment.installers.pk_installers.chef_installer.chef_installer\
import ChefInstaller
class TestChefInstaller(unittest2.TestCase):
"""Test installer functionality."""
def setUp(self):
super(TestChefInstaller, self).setUp()
self.test_chef = self._get_chef_installer()
def tearDown(self):
super(TestChefInstaller, self).tearDown()
del self.test_chef
def _get_testchefapi(self):
import chef
url = 'https://api.opscode.com/organizations/compasscheftest'
return chef.ChefAPI(url, config_data.test_client_key, 'graceyu')
def _get_chef_installer(self):
adapter_info = deepcopy(config_data.adapter_test_config)
cluster_info = deepcopy(config_data.cluster_test_config)
hosts_info = deepcopy(config_data.hosts_test_config)
ChefInstaller.get_tmpl_path = Mock()
test_tmpl_dir = os.path.join(os.path.join(config_data.test_tmpl_dir,
'chef_installer'),
'openstack_icehouse')
ChefInstaller.get_tmpl_path.return_value = test_tmpl_dir
ChefInstaller._get_chef_api = Mock()
ChefInstaller._get_chef_api.return_value = self._get_testchefapi()
chef_installer = ChefInstaller(adapter_info, cluster_info, hosts_info)
return chef_installer
def test_get_tmpl_vars(self):
pass
"""
def test_get_node_attributes(self):
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": {
"endpoints": {
"compute-vnc-bind": {
"host": "12.234.32.101"
}
}
}
}
output = self.test_chef._get_node_attributes(['os-compute'], vars_dict)
self.maxDiff = None
self.assertDictEqual(expected_node_attr, output)
def test_get_env_attributes(self):
expected_env = {
"name": "testing",
"description": "Environment",
"cookbook_versions": {
},
"json_class": "Chef::Environment",
"chef_type": "environment",
"default_attributes": {
},
"override_attributes": {
"compute": {
"syslog": {
"use": False
},
"libvirt": {
"bind_interface": "eth0"
},
"novnc_proxy": {
"bind_interface": "vnet0"
},
"xvpvnc_proxy": {
"bind_interface": "eth0"
}
},
"db": {
"bind_interface": "vnet0",
"compute": {
"host": "12.234.32.100"
},
"identity": {
"host": "12.234.32.100"
}
},
"mq": {
"user": "guest",
"password": "test",
"vhost": "/nova",
"network": {
"service_type": "rabbitmq"
}
}
}
}
vars_dict = self.test_chef._get_cluster_tmpl_vars()
output = self.test_chef._get_env_attributes(vars_dict)
self.maxDiff = None
self.assertDictEqual(expected_env, output)
def test_get_databagitem_attributes(self):
vars_dict = {
"cluster": {
"deployed_package_config": {
"service_credentials": {
"nova": {
"username": "nova",
"password": "compute"
}
},
"users_credentials": {
"ksadmin": {
"username": "ksadmin",
"password": "ksadmin"
},
"demo": {
"username": "demo",
"password": "demo"
}
}
}
}
}
expected_output = {
"user_passwords": {
"admin": {
"admin": "admin",
},
"ksadmin": {
"ksadmin": "ksadmin"
},
"demo": {
"demo": "demo"
}
},
"db_passwords": {
"nova": {
"nova": "compute",
},
"horizon": {
"horizon": "horizon"
},
"keystone": {
"keystone": "keystone"
}
}
}
databag_dir = os.path.join(self.test_chef.get_tmpl_path(), 'databags')
databags = self.test_chef.config_manager.get_chef_databag_names()
for bag in databags:
tmpl_path = os.path.join(databag_dir, '.'.join((bag, 'tmpl')))
output = self.test_chef._get_databagitem_attributes(tmpl_path,
vars_dict)
self.maxDiff = None
self.assertDictEqual(expected_output[bag], output)
"""