1 ##############################################################################
2 # Copyright (c) 2018 ZTE Corporation and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from os.path import isfile
11 from doctor_tests.common.utils import SSHClient
12 from doctor_tests.installer.base import BaseInstaller
15 class McpInstaller(BaseInstaller):
16 node_user_name = 'ubuntu'
17 cm_set_script = 'set_ceilometer.py'
18 cm_restore_script = 'restore_ceilometer.py'
20 def __init__(self, conf, log):
21 super(McpInstaller, self).__init__(conf, log)
22 self.key_file = self.get_ssh_key_from_installer()
23 self.client = SSHClient(self.conf.installer.ip,
25 key_filename=self.key_file,
27 self.controllers = list()
28 self.controller_clients = list()
31 self.log.info('Setup MCP installer start......')
33 self.controllers = self.get_controller_ips()
35 self.set_apply_patches()
39 self.restore_apply_patches()
40 for server in self.servers:
43 def get_ssh_key_from_installer(self):
44 self.log.info('Get SSH keys from MCP......')
46 # Assuming mcp.rsa is already mapped to functest container
47 # if not, only the test runs on jumphost can get the ssh_key
48 # default in path /var/lib/opnfv/mcp.rsa
49 ssh_key = '/root/.ssh/id_rsa'
50 mcp_key = '/var/lib/opnfv/mcp.rsa'
51 return ssh_key if isfile(ssh_key) else mcp_key
53 def get_controller_ips(self):
54 self.log.info('Get controller ips from Mcp installer......')
56 command = "sudo salt --out yaml 'ctl*' " \
57 "pillar.get _param:openstack_control_address |" \
59 controllers = self._run_cmd_remote(self.client, command)
60 self.log.info('Get controller_ips:%s from Mcp installer'
64 def get_host_ip_from_hostname(self, hostname):
65 command = "sudo salt --out yaml '%s*' " \
66 "pillar.get _param:single_address |" \
67 "awk '{print $2}'" % hostname
68 host_ips = self._run_cmd_remote(self.client, command)
71 def set_apply_patches(self):
72 self.log.info('Set apply patches start......')
74 restart_cm_cmd = 'sudo service ceilometer-agent-notification restart'
75 for node_ip in self.controllers:
76 client = SSHClient(node_ip, self.node_user_name,
77 key_filename=self.key_file)
78 self.controller_clients.append(client)
79 self._run_apply_patches(client,
83 def restore_apply_patches(self):
84 self.log.info('restore apply patches start......')
86 restart_cm_cmd = 'sudo service ceilometer-agent-notification restart'
87 for client in self.controller_clients:
88 self._run_apply_patches(client,
90 [self.cm_restore_script])