1 ##############################################################################
2 # Copyright (c) 2018 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 ##############################################################################
9 from doctor_tests.common.utils import get_doctor_test_root_dir
10 from doctor_tests.identity_auth import get_identity_auth
11 from doctor_tests.identity_auth import get_session
12 from doctor_tests.os_clients import keystone_client
13 from doctor_tests.os_clients import neutron_client
14 from doctor_tests.os_clients import nova_client
15 from doctor_tests.stack import Stack
18 class Maintenance(object):
20 def __init__(self, conf, log):
23 self.keystone = keystone_client(
24 self.conf.keystone_version, get_session())
25 self.nova = nova_client(conf.nova_version, get_session())
26 auth = get_identity_auth(project=self.conf.doctor_project)
27 self.neutron = neutron_client(get_session(auth=auth))
28 self.stack = Stack(self.conf, self.log)
30 def get_external_network(self):
32 networks = self.neutron.list_networks()['networks']
33 for network in networks:
34 if network['router:external']:
35 ext_net = network['name']
38 raise Exception("externl network not defined")
41 def setup_maintenance(self, user):
42 # each hypervisor needs to have same amount of vcpus and they
43 # need to be free before test
44 hvisors = self.nova.hypervisors.list(detailed=True)
47 self.log.info('checking hypervisors.......')
48 for hvisor in hvisors:
49 vcpus = hvisor.__getattr__("vcpus")
50 vcpus_used = hvisor.__getattr__("vcpus_used")
51 hostname = hvisor.__getattr__("hypervisor_hostname")
53 raise Exception('not enough vcpus on %s' % hostname)
55 raise Exception('%d vcpus used on %s'
56 % (vcpus_used, hostname))
57 if prev_vcpus != 0 and prev_vcpus != vcpus:
58 raise Exception('%d vcpus on %s does not match to'
61 prev_vcpus, prev_hostname))
63 prev_hostname = hostname
65 # maintenance flavor made so that 2 instances take whole node
66 flavor_vcpus = int(vcpus / 2)
67 compute_nodes = len(hvisors)
68 amount_actstdby_instances = 2
69 amount_noredundancy_instances = 2 * compute_nodes - 2
70 self.log.info('testing %d computes with %d vcpus each'
71 % (compute_nodes, vcpus))
72 self.log.info('testing %d actstdby and %d noredundancy instances'
73 % (amount_actstdby_instances,
74 amount_noredundancy_instances))
75 max_instances = (amount_actstdby_instances +
76 amount_noredundancy_instances)
77 max_cores = compute_nodes * vcpus
79 user.update_quota(max_instances, max_cores)
81 test_dir = get_doctor_test_root_dir()
82 template_file = '{0}/{1}'.format(test_dir, 'maintenance_hot_tpl.yaml')
83 files, template = self.stack.get_hot_tpl(template_file)
85 ext_net = self.get_external_network()
87 parameters = {'ext_net': ext_net,
88 'flavor_vcpus': flavor_vcpus,
89 'maint_image': self.conf.image_name,
90 'nonha_intances': amount_noredundancy_instances,
91 'ha_intances': amount_actstdby_instances}
93 self.log.info('creating maintenance stack.......')
94 self.log.info('parameters: %s' % parameters)
96 self.stack.create('doctor_test_maintenance',
98 parameters=parameters,
101 def cleanup_maintenance(self):
102 self.log.info('stack delete start.......')