1 ##############################################################################
2 # Copyright (c) 2019 Nokia 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 ##############################################################################
13 from doctor_tests.common.utils import SSHClient
14 from doctor_tests.common.utils import LocalSSH
15 from doctor_tests.identity_auth import get_session
16 from doctor_tests.installer.base import BaseInstaller
17 from doctor_tests.os_clients import nova_client
20 class DevstackInstaller(BaseInstaller):
22 cm_set_script = 'set_config.py'
23 nc_set_compute_script = 'set_compute_config.py'
24 cm_restore_script = 'restore_config.py'
25 nc_restore_compute_script = 'restore_compute_config.py'
26 ac_restart_script = 'restart_aodh.py'
27 ac_restore_script = 'restore_aodh.py'
30 def __init__(self, conf, log):
31 super(DevstackInstaller, self).__init__(conf, log)
32 # Run Doctor under users home. sudo hides other env param to be used
33 home, self.node_user_name = (iter(os.environ.get('VIRTUAL_ENV')
35 # Migration needs to work so ssh should have proper key defined
36 self.key_file = '/%s/%s/.ssh/id_rsa' % (home, self.node_user_name)
37 self.log.info('ssh uses: %s and %s' % (self.node_user_name,
39 self.controllers = ([ip for ip in
40 socket.gethostbyname_ex(socket.gethostname())[2]
41 if not ip.startswith('127.')] or
42 [[(s.connect(('8.8.8.8', 53)),
43 s.getsockname()[0], s.close())
44 for s in [socket.socket(socket.AF_INET,
45 socket.SOCK_DGRAM)]][0][1]])
46 conf.admin_tool.ip = self.controllers[0]
47 self.computes = list()
48 self.nova = nova_client(conf.nova_version, get_session())
51 self.log.info('Setup Devstack installer start......')
52 self._get_devstack_conf()
54 self.set_apply_patches()
57 self.restore_apply_patches()
59 def get_ssh_key_from_installer(self):
62 def get_transport_url(self):
63 client = LocalSSH(self.log)
64 cmd = 'sudo grep -m1 "^transport_url" /etc/nova/nova.conf'
65 ret, url = client.ssh(cmd)
66 url = url.split("= ", 1)[1][:-1]
67 self.log.info('get_transport_url %s' % url)
70 def get_host_ip_from_hostname(self, hostname):
71 return [hvisor.__getattr__('host_ip') for hvisor in self.hvisors
72 if hvisor.__getattr__('hypervisor_hostname') == hostname][0]
74 def _get_devstack_conf(self):
75 self.log.info('Get devstack config details for Devstack installer'
77 self.hvisors = self.nova.hypervisors.list(detailed=True)
78 self.log.info('checking hypervisors.......')
79 self.computes = [hvisor.__getattr__('host_ip') for hvisor in
81 self.use_containers = False
82 self.log.info('controller_ips:%s' % self.controllers)
83 self.log.info('compute_ips:%s' % self.computes)
84 self.log.info('use_containers:%s' % self.use_containers)
86 def _set_docker_restart_cmd(self, service):
87 # There can be multiple instances running so need to restart all
88 cmd = "for container in `sudo docker ps | grep "
90 cmd += " | awk '{print $1}'`; do sudo docker restart $container; \
94 def set_apply_patches(self):
95 self.log.info('Set apply patches start......')
97 set_scripts = [self.cm_set_script]
99 restart_cmd = 'sudo systemctl restart' \
100 ' devstack@ceilometer-anotification.service'
102 client = LocalSSH(self.log)
103 self._run_apply_patches(client,
109 self.log.info('Set apply patches start......')
111 if self.conf.test_case != 'fault_management':
112 restart_cmd = 'sudo systemctl restart' \
113 ' devstack@n-cpu.service'
114 for node_ip in self.computes:
115 client = SSHClient(node_ip, self.node_user_name,
116 key_filename=self.key_file)
117 self._run_apply_patches(client,
119 [self.nc_set_compute_script],
123 def restore_apply_patches(self):
124 self.log.info('restore apply patches start......')
126 restore_scripts = [self.cm_restore_script]
128 restart_cmd = 'sudo systemctl restart' \
129 ' devstack@ceilometer-anotification.service'
131 if self.conf.test_case != 'fault_management':
132 restart_cmd += ' devstack@n-sch.service'
133 restore_scripts.append(self.nc_restore_compute_script)
135 client = LocalSSH(self.log)
136 self._run_apply_patches(client,
141 if self.conf.test_case != 'fault_management':
143 restart_cmd = 'sudo systemctl restart' \
144 ' devstack@n-cpu.service'
145 for node_ip in self.computes:
146 client = SSHClient(node_ip, self.node_user_name,
147 key_filename=self.key_file)
148 self._run_apply_patches(
150 [self.nc_restore_compute_script],