add update state to deploy action
Change-Id: I6216c4ed99255cc6428ebe1aa870291082ba1131
This commit is contained in:
parent
20b53b88e1
commit
eadf609096
@ -52,6 +52,7 @@ def deploy(cluster_id, hosts_id_list, username=None):
|
||||
deployed_config = deploy_manager.deploy()
|
||||
|
||||
ActionHelper.save_deployed_config(deployed_config, user)
|
||||
ActionHelper.update_state(cluster_id, hosts_id_list, user)
|
||||
|
||||
|
||||
def redeploy(cluster_id, hosts_id_list, username=None):
|
||||
@ -78,6 +79,7 @@ def redeploy(cluster_id, hosts_id_list, username=None):
|
||||
deploy_manager = DeployManager(adapter_info, cluster_info, hosts_info)
|
||||
#deploy_manager.prepare_for_deploy()
|
||||
deploy_manager.redeploy()
|
||||
ActionHelper.update_state(cluster_id, hosts_id_list, user)
|
||||
|
||||
|
||||
def poweron(host_id):
|
||||
@ -192,13 +194,8 @@ class ActionHelper(object):
|
||||
hosts_info = {}
|
||||
for clusterhost_id in hosts_id_list:
|
||||
info = cluster_db.get_clusterhost(user, clusterhost_id)
|
||||
host_id = info[const.HOST_ID]
|
||||
temp = host_db.get_host(user, host_id)
|
||||
config = cluster_db.get_cluster_host_config(user, cluster_id,
|
||||
host_id)
|
||||
config = cluster_db.get_clusterhost_config(user, clusterhost_id)
|
||||
# Delete 'id' from temp
|
||||
del temp['id']
|
||||
info.update(temp)
|
||||
info.update(config)
|
||||
|
||||
networks = info[const.NETWORKS]
|
||||
@ -238,3 +235,13 @@ class ActionHelper(object):
|
||||
cluster_db.update_clusterhost_deployed_config(user,
|
||||
clusterhost_id,
|
||||
**config)
|
||||
|
||||
@staticmethod
|
||||
def update_state(cluster_id, clusterhost_id_list, user):
|
||||
# update cluster state
|
||||
cluster_db.update_cluster_state(user, cluster_id, state='INSTALLING')
|
||||
|
||||
# update all clusterhosts state
|
||||
for clusterhost_id in clusterhost_id_list:
|
||||
cluster_db.update_clusterhost_state(user, clusterhost_id,
|
||||
state='INSTALLING')
|
||||
|
@ -118,9 +118,9 @@ class BaseInstaller(object):
|
||||
|
||||
def get_config_from_template(self, tmpl_dir, vars_dict):
|
||||
if not os.path.exists(tmpl_dir) or not vars_dict:
|
||||
logging.info("Template or variables dict is not specified!")
|
||||
logging.info("Template dir or vars_dict is None!")
|
||||
logging.debug("template dir is %s", tmpl_dir)
|
||||
logging.debug("template vars dict is %s", vars_dict)
|
||||
logging.debug("vars_dict is %s", vars_dict)
|
||||
return {}
|
||||
|
||||
tmpl = Template(file=tmpl_dir, searchList=[vars_dict])
|
||||
|
@ -81,10 +81,6 @@ class ChefInstaller(PKInstaller):
|
||||
"""Generate environment name."""
|
||||
return "-".join((dist_sys_name, cluster_name))
|
||||
|
||||
def get_databag_name(self):
|
||||
"""Get databag name."""
|
||||
return self.config_manager.get_dist_system_name()
|
||||
|
||||
def get_databag(self, databag_name):
|
||||
"""Get databag object from chef server. Creating the databag if its
|
||||
doesnot exist.
|
||||
@ -94,7 +90,7 @@ class ChefInstaller(PKInstaller):
|
||||
bag.save()
|
||||
return bag
|
||||
|
||||
def get_node(self, node_name, env_name=None):
|
||||
def get_node(self, node_name, env_name):
|
||||
"""Get chef node if existing, otherwise create one and set its
|
||||
environment.
|
||||
|
||||
@ -253,11 +249,15 @@ class ChefInstaller(PKInstaller):
|
||||
import chef
|
||||
databags_dir = os.path.join(self.tmpl_dir, self.DATABAG_TMPL_DIR)
|
||||
for databag_name in databag_names:
|
||||
databag = self.get_databag(databag_name)
|
||||
databag_tmpl = os.paht.join(databags_dir, databag_name)
|
||||
databagitem_attri = self._get_databagitem_attributes(databag_tmpl,
|
||||
vars_dict)
|
||||
if not databagitem_attri:
|
||||
logging.info("Databag template not found or vars_dict is None")
|
||||
logging.info("databag template is %s", databag_tmpl)
|
||||
continue
|
||||
|
||||
databag = self.get_databag(databag_name)
|
||||
for item, item_values in databagitem_attri.iteritems():
|
||||
databagitem = chef.DataBagItem(databag, item,
|
||||
api=self.chef_api)
|
||||
@ -351,7 +351,9 @@ class ChefInstaller(PKInstaller):
|
||||
# set each host deployed config
|
||||
tmp = self.config_manager.get_host_deployed_package_config(host_id)
|
||||
tmp[const.TMPL_VARS_DICT] = vars_dict
|
||||
hosts_deployed_configs[host_id][const.DEPLOYED_PK_CONFIG] = tmp
|
||||
host_config = {}
|
||||
host_config[const.DEPLOYED_PK_CONFIG] = tmp
|
||||
hosts_deployed_configs[host_id] = host_config
|
||||
|
||||
# set cluster deployed config
|
||||
cl_config = self.config_manager.get_cluster_deployed_package_config()
|
||||
|
@ -93,18 +93,20 @@ class TestDeployAction(unittest2.TestCase):
|
||||
self.maxDiff = None
|
||||
self.assertDictEqual(expected_output, output)
|
||||
|
||||
@patch('compass.db.api.cluster.get_cluster_host_config')
|
||||
@patch('compass.db.api.host.get_host')
|
||||
@patch('compass.db.api.cluster.get_clusterhost_config')
|
||||
@patch('compass.db.api.cluster.get_clusterhost')
|
||||
def test_get_hosts_info(self, mock_get_clusterhost, mock_get_host,
|
||||
mock_get_cluster_host_config):
|
||||
def test_get_hosts_info(self, mock_get_clusterhost,
|
||||
mock_get_clusterhost_config):
|
||||
mock_get_clusterhost_config.return_value = {
|
||||
"os_config": {},
|
||||
"package_config": {},
|
||||
"deployed_os_config": {},
|
||||
"deployed_package_config": {}
|
||||
}
|
||||
mock_get_clusterhost.return_value = {
|
||||
"id": 1,
|
||||
"host_id": 10,
|
||||
"name": "test"
|
||||
}
|
||||
mock_get_host.return_value = {
|
||||
"id": 10,
|
||||
"name": "test",
|
||||
"mac": "00:89:23:a1:e9:10",
|
||||
"hostname": "server01",
|
||||
"networks": [
|
||||
@ -114,16 +116,10 @@ class TestDeployAction(unittest2.TestCase):
|
||||
"netmask": "255.255.255.0",
|
||||
"is_mgmt": True,
|
||||
"subnet": "127.0.0.0/24",
|
||||
"is_promiscuous": False
|
||||
"is_promiscuous": False,
|
||||
}
|
||||
]
|
||||
}
|
||||
mock_get_cluster_host_config.return_value = {
|
||||
"os_config": {},
|
||||
"package_config": {},
|
||||
"deployed_os_config": {},
|
||||
"deployed_package_config": {}
|
||||
}
|
||||
expected_output = {
|
||||
1: {
|
||||
"id": 1,
|
||||
|
@ -129,3 +129,59 @@ class TestChefInstaller(unittest2.TestCase):
|
||||
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)
|
||||
|
@ -41,8 +41,7 @@ adapter_test_config = {
|
||||
"chef_url": "https://127.0.0.1",
|
||||
"key_dir": "xxx",
|
||||
"client_name": "xxx",
|
||||
"databags": ["user_passwords", "db_passwords", "service_passwords",
|
||||
"secrets"]
|
||||
"databags": ["user_passwords", "db_passwords"]
|
||||
}
|
||||
},
|
||||
"metadata": {
|
||||
|
@ -1,21 +1,20 @@
|
||||
#set aval_services = ['nova', 'horizon', 'keystone', 'glance', 'ceilometer', 'neutron', 'cinder', 'heat', 'dash']
|
||||
#set aval_services = ['nova', 'horizon', 'keystone']
|
||||
#set config = $cluster.deployed_package_config
|
||||
#set service_config = {}
|
||||
#if "service_credentials" in $config:
|
||||
#set service_config = $cluster.deployed_package_config.service_credentials
|
||||
#end if
|
||||
#set databagitems = {}
|
||||
#for $service in $aval_services:
|
||||
#set databagitems[$service] = {$service: $service}
|
||||
#end for
|
||||
|
||||
#if service_config:
|
||||
#for $service, $value in $service_config.iteritems():
|
||||
#if $service in $aval_services:
|
||||
#set databagitems[$service] = {$value.username: $value.password}
|
||||
#set databagitems[$service] = {$service: $value.password}
|
||||
#end if
|
||||
#end for
|
||||
|
||||
#else:
|
||||
#for $service in $aval_services:
|
||||
#set databagitems[$service] = {$service: $service}
|
||||
#end for
|
||||
#end if
|
||||
#import simplejson as json
|
||||
#set output = json.dumps($databagitems, encoding='utf-8')
|
||||
|
@ -4,17 +4,21 @@
|
||||
#if "services_credentials" in $config:
|
||||
#set services_config = $cluster.deployed_package_config.services_credentials
|
||||
#end if
|
||||
|
||||
#set databagitems = {}
|
||||
#for $service in $required_services:
|
||||
#if $service not in $databagitems:
|
||||
#set databagitems[$service] = {$service: $service}
|
||||
#end if
|
||||
#end for
|
||||
|
||||
#if services_config:
|
||||
#for $service, $value in $services_config.iteritems():
|
||||
#set databagitems[$service] = {$value.username: $value.password}
|
||||
#if $service in $required_services:
|
||||
#set databagitems[$service] = {$service: $value.password}
|
||||
#end if
|
||||
#end for
|
||||
#end if
|
||||
#for $service in $required_services:
|
||||
#if $service not in $databagitems:
|
||||
#set databagitems[$service] = {$service: $service}
|
||||
#end if
|
||||
#end for
|
||||
#import simplejson as json
|
||||
#set output = json.dumps($databagitems, encoding='utf-8')
|
||||
$output
|
||||
|
3
setup.py
3
setup.py
@ -83,9 +83,6 @@ setup(
|
||||
install_requires=REQUIREMENTS,
|
||||
packages=find_packages(exclude=['compass.tests']),
|
||||
include_package_data=True,
|
||||
#TODO login UI will be replaced by compass's own templates later
|
||||
package_data={'compass': ['templates/*.jinja', 'static/js/*.js',
|
||||
'static/css/*.css', 'static/img/*.png']},
|
||||
classifiers=[
|
||||
'Development Status :: 5 - Production/Stable',
|
||||
'Environment :: Console',
|
||||
|
@ -3,19 +3,19 @@
|
||||
#set service_config = {}
|
||||
#if "service_credentials" in $config:
|
||||
#set service_config = $cluster.deployed_package_config.service_credentials
|
||||
#end if
|
||||
#end if
|
||||
#set databagitems = {}
|
||||
|
||||
#for $service in $aval_services:
|
||||
#set databagitems[$service] = {$service: $service}
|
||||
#end for
|
||||
|
||||
#if service_config:
|
||||
#for $service, $value in $service_config.iteritems():
|
||||
#if $service in $aval_services:
|
||||
#set databagitems[$service] = {$value.username: $value.password}
|
||||
#set databagitems[$service] = {$service: $value.password}
|
||||
#end if
|
||||
#end for
|
||||
|
||||
#else:
|
||||
#for $service in $aval_services:
|
||||
#set databagitems[$service] = {$service: $service}
|
||||
#end for
|
||||
#end if
|
||||
#import simplejson as json
|
||||
#set output = json.dumps($databagitems, encoding='utf-8')
|
||||
|
@ -4,17 +4,21 @@
|
||||
#if "services_credentials" in $config:
|
||||
#set services_config = $cluster.deployed_package_config.services_credentials
|
||||
#end if
|
||||
|
||||
#set databagitems = {}
|
||||
#for $service in $required_services:
|
||||
#if $service not in $databagitems:
|
||||
#set databagitems[$service] = {$service: $service}
|
||||
#end if
|
||||
#end for
|
||||
|
||||
#if services_config:
|
||||
#for $service, $value in $services_config.iteritems():
|
||||
#set databagitems[$service] = {$value.username: $value.password}
|
||||
#if $service in $required_services:
|
||||
#set databagitems[$service] = {$service: $value.password}
|
||||
#end if
|
||||
#end for
|
||||
#end if
|
||||
#for $service in $required_services:
|
||||
#if $service not in $databagitems:
|
||||
#set databagitems[$service] = {$service: $service}
|
||||
#end if
|
||||
#end for
|
||||
#import simplejson as json
|
||||
#set output = json.dumps($databagitems, encoding='utf-8')
|
||||
$output
|
||||
|
Loading…
Reference in New Issue
Block a user