diff --git a/bin/delete_clusters.py b/bin/delete_clusters.py index c822a4f1..fef0a9d8 100755 --- a/bin/delete_clusters.py +++ b/bin/delete_clusters.py @@ -67,6 +67,11 @@ def delete_clusters(): cluster_id = cluster['id'] hosts = cluster_api.list_cluster_hosts(user, cluster_id) host_id_list = [host['id'] for host in hosts] + logging.info( + 'delete cluster %s and cluster hosts %s', + cluster_id, host_id_list + ) + logging.info('delete underlying host? %s', delete_underlying_host) if flags.OPTIONS.async: celery.send_task( 'compass.tasks.delete_cluster', diff --git a/compass/actions/delete.py b/compass/actions/delete.py index fdd31685..1c1b13bc 100644 --- a/compass/actions/delete.py +++ b/compass/actions/delete.py @@ -17,6 +17,7 @@ import logging from compass.actions import util +from compass.db.api import cluster as cluster_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 @@ -40,6 +41,22 @@ def delete_cluster( user = user_db.get_user_object(username) + for host_id in host_id_list: + cluster_api.update_cluster_host_state( + user, cluster_id, host_id, state='ERROR' + ) + cluster_api.update_cluster_state( + user, cluster_id, state='ERROR' + ) + + cluster_api.update_cluster( + user, cluster_id, reinstall_distributed_system=True + ) + for host_id in host_id_list: + cluster_api.update_cluster_host( + user, cluster_id, host_id, reinstall_os=True + ) + cluster_info = util.ActionHelper.get_cluster_info(cluster_id, user) adapter_id = cluster_info[const.ADAPTER_ID] @@ -48,9 +65,10 @@ def delete_cluster( hosts_info = util.ActionHelper.get_hosts_info( cluster_id, host_id_list, user) + logging.debug('adapter info: %s', adapter_info) + logging.debug('cluster info: %s', cluster_info) + logging.debug('hosts info: %s', hosts_info) deploy_manager = DeployManager(adapter_info, cluster_info, hosts_info) - logging.debug('Created deploy manager with %s %s %s' - % (adapter_info, cluster_info, hosts_info)) deploy_manager.remove_hosts( package_only=not delete_underlying_host, diff --git a/compass/db/api/cluster.py b/compass/db/api/cluster.py index 1528601b..20074780 100644 --- a/compass/db/api/cluster.py +++ b/compass/db/api/cluster.py @@ -549,10 +549,13 @@ def add_clusterhost_internal( session, models.Host, False, id=machine_id ) if host: - if host_api.is_host_editable( - session, host, cluster.creator, - reinstall_os_set=kwargs.get('reinstall_os', False), - exception_when_not_editable=False + if ( + host_dict and + host_api.is_host_editable( + session, host, cluster.creator, + reinstall_os_set=kwargs.get('reinstall_os', False), + exception_when_not_editable=False + ) ): if 'name' in host_dict: hostname = host_dict['name'] @@ -719,6 +722,38 @@ def add_cluster_host( ) @utils.wrap_to_dict(RESP_CLUSTERHOST_FIELDS) def _update_clusterhost(session, updater, clusterhost, **kwargs): + clusterhost_dict = {} + host_dict = {} + for key, value in kwargs.items(): + if key in UPDATED_HOST_FIELDS: + host_dict[key] = value + else: + clusterhost_dict[key] = value + + 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), + exception_when_not_editable=False + ): + if 'name' in host_dict: + hostname = host_dict['name'] + host_by_name = utils.get_db_object( + session, models.Host, False, name=hostname + ) + if host_by_name and host_by_name.id != host.id: + raise exception.InvalidParameter( + 'host name %s exists in host %s' % ( + hostname, host_by_name.id + ) + ) + utils.update_db_object( + session, host, + **host_dict + ) + def roles_validates(roles): cluster_roles = [] cluster = clusterhost.cluster @@ -759,7 +794,7 @@ def _update_clusterhost(session, updater, clusterhost, **kwargs): @utils.supported_filters( - optional_support_keys=UPDATED_CLUSTERHOST_FIELDS, + optional_support_keys=(UPDATED_HOST_FIELDS + UPDATED_CLUSTERHOST_FIELDS), ignore_support_keys=IGNORE_FIELDS ) @database.run_in_session() @@ -775,7 +810,7 @@ def update_cluster_host( @utils.supported_filters( - optional_support_keys=UPDATED_CLUSTERHOST_FIELDS, + optional_support_keys=(UPDATED_HOST_FIELDS + UPDATED_CLUSTERHOST_FIELDS), ignore_support_keys=IGNORE_FIELDS ) @database.run_in_session() diff --git a/compass/deployment/installers/os_installers/cobbler/cobbler.py b/compass/deployment/installers/os_installers/cobbler/cobbler.py index 5ae589ae..7406b813 100644 --- a/compass/deployment/installers/os_installers/cobbler/cobbler.py +++ b/compass/deployment/installers/os_installers/cobbler/cobbler.py @@ -302,8 +302,10 @@ class CobblerInstaller(OSInstaller): def delete_hosts(self): hosts_id_list = self.config_manager.get_host_id_list() + logging.debug('delete hosts %s', hosts_id_list) for host_id in hosts_id_list: self.delete_single_host(host_id) + self._sync() def delete_single_host(self, host_id): """Delete the host from cobbler server and clean up the installation @@ -311,11 +313,12 @@ class CobblerInstaller(OSInstaller): """ hostname = self.config_manager.get_hostname(host_id) try: - log_dir_prefix = compass_setting.INSTALLATION_LOGDIR[self.NAME] + log_dir_prefix = compass_setting.INSTALLATION_LOGDIR[NAME] self._clean_system(hostname) self._clean_log(log_dir_prefix, hostname) except Exception as ex: - logging.info("Deleting host got exception: %s", ex.message) + logging.error("Deleting host got exception: %s", ex) + logging.exception(ex) def _get_host_tmpl_vars_dict(self, host_id, global_vars_dict, **kwargs): """Generate template variables dictionary. diff --git a/compass/deployment/installers/pk_installers/chef_installer/chef_installer.py b/compass/deployment/installers/pk_installers/chef_installer/chef_installer.py index c9cd372e..d234be9b 100644 --- a/compass/deployment/installers/pk_installers/chef_installer/chef_installer.py +++ b/compass/deployment/installers/pk_installers/chef_installer/chef_installer.py @@ -549,7 +549,7 @@ class ChefInstaller(PKInstaller): def _clean_log(self, log_dir_prefix, node_name): log_dir = os.path.join(log_dir_prefix, node_name) - shutil.rmtree(log_dir, False) + shutil.rmtree(log_dir, True) def get_supported_dist_systems(self): """get target systems from chef. All target_systems for compass will diff --git a/install/compass.sh b/install/compass.sh index 6805ee0e..077b70f2 100755 --- a/install/compass.sh +++ b/install/compass.sh @@ -87,6 +87,7 @@ sudo mkdir -p /var/lib/redis/ sudo chown -R redis:root /var/lib/redis sudo mkdir -p /var/run/redis sudo chown -R redis:root /var/run/redis +killall -9 redis-server sudo service redis restart echo "Checking if redis is running" sudo service redis status @@ -153,8 +154,8 @@ else echo "compass-progress-updated has already started" fi -#compass check -#if [[ "$?" != "0" ]]; then -# echo "compass check failed" -# exit 1 -#fi +compass check +if [[ "$?" != "0" ]]; then + echo "compass check failed" + exit 1 +fi diff --git a/install/compass_web.sh b/install/compass_web.sh index 9afc85a8..5dbe84a1 100755 --- a/install/compass_web.sh +++ b/install/compass_web.sh @@ -22,7 +22,7 @@ sudo cp -rf $WEB_HOME/v2 /var/www/compass_web/ if [[ $LOCAL_REPO = "y" ]]; then echo "setting up local repo" mkdir -p /tmp/repo - download -f https://s3-us-west-1.amazonaws.com/compass-local-repo/local_repo.tar.gz local_repo.tar.gz unzip /tmp/repo || exit $? + download https://s3-us-west-1.amazonaws.com/compass-local-repo/local_repo.tar.gz local_repo.tar.gz unzip /tmp/repo || exit $? mv -f /tmp/repo/local_repo/* /var/www/compass_web/v2/ if [[ "$?" != "0" ]]; then echo "failed to setup local repo" diff --git a/install/prepare.sh b/install/prepare.sh index 8526bd45..a86a5432 100755 --- a/install/prepare.sh +++ b/install/prepare.sh @@ -174,6 +174,7 @@ if [ "$tempest" == "true" ]; then mkvirtualenv tempest fi workon tempest + rm -rf ${WORKON_HOME}/tempest/build cd /tmp/tempest pip install -e . pip install sqlalchemy @@ -193,6 +194,7 @@ if ! lsvirtualenv |grep compass-core>/dev/null; then fi cd $COMPASSDIR workon compass-core +rm -rf ${WORKON_HOME}/compass-core/build echo "install compass requirements" pip install -U -r requirements.txt if [[ "$?" != "0" ]]; then @@ -256,7 +258,7 @@ fi # download local repo if [[ $LOCAL_REPO = "y" ]]; then - download -f https://s3-us-west-1.amazonaws.com/compass-local-repo/local_repo.tar.gz local_repo.tar.gz || exit $? + download https://s3-us-west-1.amazonaws.com/compass-local-repo/local_repo.tar.gz local_repo.tar.gz || exit $? fi # Install net-snmp