diff --git a/compass/actions/deploy.py b/compass/actions/deploy.py index 49ef5d61..7983a1a5 100644 --- a/compass/actions/deploy.py +++ b/compass/actions/deploy.py @@ -33,7 +33,7 @@ def deploy(cluster_id, hosts_id_list, username=None): .. note:: The function should be called out of database session. """ - with util.lock('serialized_action') as lock: + with util.lock('serialized_action', timeout=1000) as lock: if not lock: raise Exception('failed to acquire lock to deploy') diff --git a/compass/actions/update_progress.py b/compass/actions/update_progress.py index ed3cc736..0f721983 100644 --- a/compass/actions/update_progress.py +++ b/compass/actions/update_progress.py @@ -90,9 +90,15 @@ def update_progress(cluster_hosts): adapter = cluster.adapter os_installer = adapter.adapter_os_installer - os_installer_name = os_installer.instance_name + if os_installer: + os_installer_name = os_installer.name + else: + os_installer_name = None package_installer = adapter.adapter_package_installer - package_installer_name = package_installer.instance_name + if package_installer: + package_installer_name = package_installer.name + else: + package_installer_name = None distributed_system_name = cluster.distributed_system_name os_name = cluster.os_name @@ -103,6 +109,19 @@ def update_progress(cluster_hosts): hostids = [clusterhost.host.id for clusterhost in clusterhosts] cluster_hosts.update({clusterid: hostids}) + logging.info( + 'update progress for ' + 'os_installer_name %s,' + 'os_names %s,' + 'package_installer_name %s,' + 'distributed_systems %s,' + 'cluster_hosts %s', + os_installer_name, + os_names, + package_installer_name, + distributed_systems, + cluster_hosts + ) progress_calculator.update_progress( os_installer_name, os_names, diff --git a/compass/actions/util.py b/compass/actions/util.py index 29c2a44e..f989d16a 100644 --- a/compass/actions/util.py +++ b/compass/actions/util.py @@ -29,9 +29,11 @@ from compass.db import models def lock(lock_name, blocking=True, timeout=10): redis_instance = redis.Redis() instance_lock = redis_instance.lock(lock_name, timeout=timeout) + owned = False try: locked = instance_lock.acquire(blocking=blocking) if locked: + owned = True logging.debug('acquired lock %s', lock_name) yield instance_lock else: @@ -45,9 +47,13 @@ def lock(lock_name, blocking=True, timeout=10): yield None finally: - instance_lock.acquired_until = 0 - instance_lock.release() - logging.debug('released lock %s', lock_name) + if owned: + instance_lock.acquired_until = 0 + instance_lock.release() + logging.debug('released lock %s', lock_name) + else: + logging.debug('nothing to release %s', lock_name) + """ def update_cluster_hosts(cluster_hosts, diff --git a/compass/db/api/network.py b/compass/db/api/network.py index a8f94ffa..381df144 100644 --- a/compass/db/api/network.py +++ b/compass/db/api/network.py @@ -88,8 +88,8 @@ def get_subnet( ) @utils.wrap_to_dict(RESP_FIELDS) def add_subnet( - session, creator, subnet, - exception_when_existing=True, **kwargs + session, creator, exception_when_existing=True, + subnet=None, **kwargs ): """Create a subnet.""" return utils.add_db_object( diff --git a/compass/db/models.py b/compass/db/models.py index f6b0affb..0adf7812 100644 --- a/compass/db/models.py +++ b/compass/db/models.py @@ -586,7 +586,8 @@ class ClusterHost(BASE, TimestampMixin, HelperMixin): host.state.state != 'SUCCESSFUL' ): return host.state_dict() - return self.state.to_dict() + else: + return self.state.to_dict() def to_dict(self): dict_info = self.host.to_dict() @@ -598,9 +599,11 @@ class ClusterHost(BASE, TimestampMixin, HelperMixin): 'owner': self.owner, 'clustername': self.clustername, 'hostname': self.hostname, - 'name': self.name, - 'roles': [role.to_dict() for role in self.roles] + 'name': self.name }) + roles = self.roles + if roles: + dict_info['roles'] = [role.to_dict() for role in roles] return dict_info diff --git a/compass/log_analyzor/adapter_matcher.py b/compass/log_analyzor/adapter_matcher.py index 1960ec62..02dac125 100644 --- a/compass/log_analyzor/adapter_matcher.py +++ b/compass/log_analyzor/adapter_matcher.py @@ -89,9 +89,13 @@ class OSMatcher(object): def match(self, os_installer_name, os_name): """Check if the os matcher is acceptable.""" - return all([ - self.name_ == os_installer_name, - self.os_regex_.match(os_name)]) + if os_name is None: + return False + else: + return all([ + self.name_ == os_installer_name, + self.os_regex_.match(os_name) + ]) def update_progress(self, fullname, progress): """Update progress.""" @@ -123,9 +127,13 @@ class PackageMatcher(object): def match(self, package_installer_name, target_system): """Check if the package matcher is acceptable.""" - return all([ - self.name_.match(package_installer_name), - self.target_system_ == target_system]) + if package_installer_name is None: + return False + else: + return all([ + self.name_.match(package_installer_name), + self.target_system_ == target_system + ]) def update_progress(self, fullname, progress): """Update progress.""" diff --git a/templates/cobbler/CentOS-6.5-x86_64/system.tmpl b/templates/cobbler/CentOS-6.5-x86_64/system.tmpl index 2df3d3fe..ce4ca4cc 100644 --- a/templates/cobbler/CentOS-6.5-x86_64/system.tmpl +++ b/templates/cobbler/CentOS-6.5-x86_64/system.tmpl @@ -1,5 +1,5 @@ { - "name": "$host.name", + "name": "$host.hostname", "hostname": "$host.hostname", "profile": "$host.profile", "gateway": "$host.gateway", diff --git a/templates/cobbler/Ubuntu-12.04-x86_64/system.tmpl b/templates/cobbler/Ubuntu-12.04-x86_64/system.tmpl index 2df3d3fe..ce4ca4cc 100644 --- a/templates/cobbler/Ubuntu-12.04-x86_64/system.tmpl +++ b/templates/cobbler/Ubuntu-12.04-x86_64/system.tmpl @@ -1,5 +1,5 @@ { - "name": "$host.name", + "name": "$host.hostname", "hostname": "$host.hostname", "profile": "$host.profile", "gateway": "$host.gateway",