Service discovering
Support for next services was added: mysql, rabbitmq, nova-api, glance-api. Each service contains a list of nodes. Change-Id: Ief402887a0a95b0397892ac72d52e884c475d0da
This commit is contained in:
		@@ -43,13 +43,15 @@ def main():
 | 
				
			|||||||
    distractor.verify()
 | 
					    distractor.verify()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # os_failures library operate with 2 types of objects:
 | 
					    # os_failures library operate with 2 types of objects:
 | 
				
			||||||
    # service - is software that runs in the cloud, e.g. keystone
 | 
					    # service - is software that runs in the cloud, e.g. keystone, mysql,
 | 
				
			||||||
 | 
					    #           rabbitmq, nova-api, glance-api
 | 
				
			||||||
    # nodes   - nodes that host the cloud, e.g. hardware server with hostname
 | 
					    # nodes   - nodes that host the cloud, e.g. hardware server with hostname
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    logging.info('# Get a particular service in the cloud')
 | 
					    logging.info('# Get a particular service in the cloud')
 | 
				
			||||||
    service = distractor.get_service(name='keystone-api')
 | 
					    service = distractor.get_service(name='keystone')
 | 
				
			||||||
    logging.info('Keystone API Service: %s', service)
 | 
					    logging.info('Keystone API Service: %s', service)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Note: Only for Keystone!
 | 
				
			||||||
    logging.info('# Restart the service')
 | 
					    logging.info('# Restart the service')
 | 
				
			||||||
    service.restart()
 | 
					    service.restart()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -103,9 +103,17 @@ class FuelService(service.Service):
 | 
				
			|||||||
    def __repr__(self):
 | 
					    def __repr__(self):
 | 
				
			||||||
        return str(type(self))
 | 
					        return str(type(self))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _get_nodes(self, role):
 | 
					    def get_nodes(self):
 | 
				
			||||||
        nodes = self.cloud_management.get_nodes()
 | 
					        nodes = self.cloud_management.get_nodes()
 | 
				
			||||||
        return nodes.filter(role=role)
 | 
					        ips = [n['ip'] for n in nodes.hosts]
 | 
				
			||||||
 | 
					        results = self.cloud_management.execute_on_cloud(
 | 
				
			||||||
 | 
					            ips, {'command': self.GET_NODES_CMD}, False)
 | 
				
			||||||
 | 
					        success_ips = [r.host for r in results
 | 
				
			||||||
 | 
					                       if r.status == executor.STATUS_OK]
 | 
				
			||||||
 | 
					        hosts = [h for h in nodes.hosts if h['ip'] in success_ips]
 | 
				
			||||||
 | 
					        return FuelNodeCollection(cloud_management=self.cloud_management,
 | 
				
			||||||
 | 
					                                  power_management=self.power_management,
 | 
				
			||||||
 | 
					                                  hosts=hosts)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
    def get_nodes_ips(nodes):
 | 
					    def get_nodes_ips(nodes):
 | 
				
			||||||
@@ -113,8 +121,7 @@ class FuelService(service.Service):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class KeystoneService(FuelService):
 | 
					class KeystoneService(FuelService):
 | 
				
			||||||
    def get_nodes(self):
 | 
					    GET_NODES_CMD = 'bash -c "ps ax | grep \'keystone-main\'"'
 | 
				
			||||||
        return self._get_nodes(role='controller')
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def restart(self, nodes=None):
 | 
					    def restart(self, nodes=None):
 | 
				
			||||||
        nodes = nodes or self._get_nodes(role='controller')
 | 
					        nodes = nodes or self._get_nodes(role='controller')
 | 
				
			||||||
@@ -127,8 +134,28 @@ class KeystoneService(FuelService):
 | 
				
			|||||||
        logging.info('Restart the service, result: %s', exec_res)
 | 
					        logging.info('Restart the service, result: %s', exec_res)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class MySQLService(FuelService):
 | 
				
			||||||
 | 
					    GET_NODES_CMD = 'bash -c "netstat -tap | grep \'.*LISTEN.*mysqld\'"'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class RabbitMQService(FuelService):
 | 
				
			||||||
 | 
					    GET_NODES_CMD = 'bash -c "rabbitmqctl status | grep \'pid,\'"'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class NovaAPIService(FuelService):
 | 
				
			||||||
 | 
					    GET_NODES_CMD = 'bash -c "ps ax | grep \'nova-api\'"'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class GlanceAPIService(FuelService):
 | 
				
			||||||
 | 
					    GET_NODES_CMD = 'bash -c "ps ax | grep \'glance-api\'"'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SERVICE_NAME_TO_CLASS = {
 | 
					SERVICE_NAME_TO_CLASS = {
 | 
				
			||||||
    'keystone-api': KeystoneService,
 | 
					    'keystone': KeystoneService,
 | 
				
			||||||
 | 
					    'mysql': MySQLService,
 | 
				
			||||||
 | 
					    'rabbitmq': RabbitMQService,
 | 
				
			||||||
 | 
					    'nova-api': NovaAPIService,
 | 
				
			||||||
 | 
					    'glance-api': GlanceAPIService,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -178,14 +205,17 @@ class FuelManagement(cloud_management.CloudManagement):
 | 
				
			|||||||
        return self.master_node_executor.execute(
 | 
					        return self.master_node_executor.execute(
 | 
				
			||||||
            [self.master_node_address], task)
 | 
					            [self.master_node_address], task)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def execute_on_cloud(self, hosts, task):
 | 
					    def execute_on_cloud(self, hosts, task, raise_on_error=True):
 | 
				
			||||||
        """Execute task on specified hosts within the cloud.
 | 
					        """Execute task on specified hosts within the cloud.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        :param hosts: List of host FQDNs
 | 
					        :param hosts: List of host FQDNs
 | 
				
			||||||
        :param task: Ansible task
 | 
					        :param task: Ansible task
 | 
				
			||||||
        :return: Ansible execution result (list of records)
 | 
					        :return: Ansible execution result (list of records)
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
 | 
					        if raise_on_error:
 | 
				
			||||||
            return self.cloud_executor.execute(hosts, task)
 | 
					            return self.cloud_executor.execute(hosts, task)
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            return self.cloud_executor.execute(hosts, task, [])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _retrieve_hosts_fqdn(self):
 | 
					    def _retrieve_hosts_fqdn(self):
 | 
				
			||||||
        for host in self._get_cloud_hosts():
 | 
					        for host in self._get_cloud_hosts():
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user