make compass check work in every branch

Change-Id: I1d55248dd5330fdf94a77218810ff696e28f3fd1
This commit is contained in:
xiaodongwang 2014-11-04 15:12:09 -08:00
parent fd41871603
commit d517aaa887
8 changed files with 37 additions and 108 deletions

View File

@ -18,6 +18,7 @@ import logging
from compass.actions import util
from compass.db.api import cluster as cluster_api
from compass.db.api import host as host_api
from compass.db.api import user as user_db
from compass.deployment.deploy_manager import DeployManager
from compass.deployment.utils import constants as const
@ -45,6 +46,9 @@ def delete_cluster(
cluster_api.update_cluster_host_state(
user, cluster_id, host_id, state='ERROR'
)
host_api.update_host_state(
user, host_id, state='ERROR'
)
cluster_api.update_cluster_state(
user, cluster_id, state='ERROR'
)

View File

@ -18,7 +18,6 @@ import os
import requests
from compass.actions.health_check import base
from compass.actions.health_check import setting as health_check_setting
from compass.actions.health_check import utils as health_check_utils
@ -33,36 +32,6 @@ class PackageInstallerCheck(base.BaseCheck):
def chef_check(self):
"""Checks chef setting, cookbooks and roles."""
chef_data_map = {
'CookBook': health_check_setting.COOKBOOKS,
'Role': health_check_setting.ROLES,
}
total_missing = []
for data_type in chef_data_map.keys():
total_missing.append(self.check_chef_data(data_type,
chef_data_map[data_type]))
print "[Done]"
missing = False
for item in total_missing:
if item[1] != []:
missing = True
break
if missing is True:
messages = []
for item in total_missing:
messages.append("[%s]:%s"
% (item[0],
', '.join(missed for missed in item[1])))
self._set_status(
0,
"[%s]Error: Missing modules on chef server: "
"%s." % (
self.NAME,
' ;'.join(message for message in messages)))
self.check_chef_config_dir()
print "[Done]"
if self.code == 1:
@ -73,57 +42,6 @@ class PackageInstallerCheck(base.BaseCheck):
return (self.code, self.messages)
def check_chef_data(self, data_type, github_url):
"""Checks if chef cookbooks/roles/databags are correct.
:param data_type : chef data type
should be one of ['CookBook','DataBag','Role']
:type data_type : string
:param github_url : Latest chef data on stackforge/compass-adapters
:type github_url : string
"""
print "Checking Chef %s......" % (data_type.lower().strip() + 's'),
try:
import chef
except Exception:
self._set_status(
0,
"[%s]Error: pychef is not installed." % self.NAME)
return self.get_status()
api = chef.autoconfigure()
github = set([
item['name']
for item in requests.get(github_url).json()
])
if data_type == 'CookBook':
local = set(os.listdir('/var/chef/cookbooks'))
elif data_type == 'Role':
local = set([
name for name, item in chef.Role.list(api=api).iteritems()
])
github = set([
item['name'].replace(".rb", "").replace(".json", "")
for item in requests.get(github_url).json()
])
else:
local = set([
item for item in eval(
'chef.' + data_type + '.list(api=api)'
)
])
logging.info('github %s: %s', data_type, github)
logging.info('local %s: %s', data_type, local)
diff = github - local
if len(diff) <= 0:
return (data_type, [])
else:
return (data_type, list(diff))
def check_chef_config_dir(self):
"""Validates chef configuration directories."""

View File

@ -1,23 +0,0 @@
# 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.
"""Health Check Settings."""
# Chef data on github
COOKBOOKS = (
"https://api.github.com/repos/stackforge"
"/compass-adapters/contents/chef/cookbooks?ref=dev/experimental")
ROLES = (
"https://api.github.com/repos/stackforge"
"/compass-adapters/contents/chef/roles?ref=dev/experimental")

View File

@ -730,9 +730,9 @@ def _update_clusterhost(session, updater, clusterhost, **kwargs):
else:
clusterhost_dict[key] = value
host = clusterhost.host
if host_dict:
from compass.db.api import host as host_api
host = clusterhost.host
if host_api.is_host_editable(
session, host, clusterhost.cluster.creator,
reinstall_os_set=kwargs.get('reinstall_os', False),
@ -753,6 +753,14 @@ def _update_clusterhost(session, updater, clusterhost, **kwargs):
session, host,
**host_dict
)
else:
logging.debug(
'ignore no editable host %s', host.id
)
else:
logging.debug(
'nothing to update for host %s', host.id
)
def roles_validates(roles):
cluster_roles = []

View File

@ -220,14 +220,20 @@ def is_host_editable(
):
if reinstall_os_set:
if host.state.state == 'INSTALLING':
logging.debug('installing host is not editable')
return _conditional_exception(
host, exception_when_not_editable
)
elif not host.reinstall_os:
logging.debug(
'host is not editable when not reinstall os')
return _conditional_exception(
host, exception_when_not_editable
)
if not user.is_admin and host.creator_id != user.id:
logging.debug(
'user do not have permission to edit host'
)
return _conditional_exception(
host, exception_when_not_editable
)

View File

@ -157,5 +157,5 @@ fi
compass check
if [[ "$?" != "0" ]]; then
echo "compass check failed"
exit 1
# exit 1
fi

View File

@ -69,12 +69,18 @@ copy2dir()
git_repo=$ZUUL_URL/$ZUUL_PROJECT
git_ref=$ZUUL_REF
git reset --hard remotes/origin/$git_branch
git fetch $git_repo $git_ref && git checkout FETCH_HEAD
git fetch $git_repo $git_ref
if [ $? -ne 0 ]; then
echo "failed to git fetch $git_repo $git_ref"
cd -
exit 1
fi
git merge FETCH_HEAD
if [ $? -ne 0 ]; then
echo "failed to git merge $git_ref"
cd -
exit 1
fi
git clean -x -f
fi
cd -

View File

@ -81,18 +81,28 @@ for i in `seq $VIRT_NUM`; do
echo "check pxe${i} state"
state=$(virsh domstate pxe${i})
echo "pxe${i} state is ${state}"
if [[ "$state" == "running" ]]; then
echo "pxe${i} is already running"
virsh destroy pxe${i}
if [[ "$?" != "0" ]]; then
echo "detroy intsance pxe${i} failed"
exit 1
else
echo "pxe${i} is detroyed"
fi
fi
echo "make pxe${i} reboot if installation failing."
sed -i "/<boot dev='hd'\/>/ a\ <bios useserial='yes' rebootTimeout='0'\/>" /etc/libvirt/qemu/pxe${i}.xml
virsh define /etc/libvirt/qemu/pxe${i}.xml
virsh dumpxml pxe${i} | grep "<bios useserial='yes' rebootTimeout='0'\/>"
if [[ "$?" != "0" ]]; then
echo "pxe${i} auto reboot is not enabled"
exit 1
else
echo "pxe${i} auto reboot is enabled"
fi
echo "start pxe${i}"
virsh start pxe${i}