Debian Codegraph @

config_tempest/services/orchestration.py

raw
1 # Copyright 2019 Red Hat, Inc.
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16 from six.moves import configparser
17
18 from config_tempest.constants import LOG
19 from config_tempest.services.base import Service
20 from config_tempest.users import Users
21
22
23 class OrchestrationService(Service):
24
25 @staticmethod
26 def get_service_type():
27 return ['orchestration']
28
29 @staticmethod
30 def get_codename():
31 return 'heat'
32
33 def set_default_tempest_options(self, conf):
34 try:
35 sec = 'heat_plugin'
36
37 conf.set(sec, 'username', conf.get('identity', 'username'))
38 conf.set(sec, 'password', conf.get('identity', 'password'))
39 conf.set(sec, 'admin_username', conf.get('auth', 'admin_username'))
40 conf.set(sec, 'admin_password', conf.get('auth', 'admin_password'))
41 conf.set(sec, 'project_name', conf.get('identity', 'project_name'))
42 admin_project_name = conf.get('auth', 'admin_project_name')
43 conf.set(sec, 'admin_project_name', admin_project_name)
44 conf.set(sec, 'region', conf.get('identity', 'region'))
45
46 v = '3' if conf.get('identity', 'auth_version') == 'v3' else '2'
47 if v == '3':
48 conf.set(sec, 'auth_url', conf.get('identity', 'uri_v3'))
49 else:
50 conf.set(sec, 'auth_url', conf.get('identity', 'uri'))
51 conf.set(sec, 'auth_version', v)
52
53 domain_name = conf.get('auth', 'admin_domain_name')
54 conf.set(sec, 'project_domain_name', domain_name)
55 conf.set(sec, 'user_domain_name', domain_name)
56 except configparser.NoOptionError:
57 LOG.warning("Be aware that an option required for "
58 "heat_tempest_plugin cannot be set!")
59
60 networks_client = self.client['networks']
61 subnets_client = self.client['subnets']
62 projects_client = self.client['projects']
63 roles_client = self.client['roles']
64 users_client = self.client['users']
65
66 heat_network_name = "heat_tempestconf_network"
67 heat_subnet_name = "heat_tempestconf_subnet"
68 project = conf.get('identity', 'project_name')
69
70 try:
71 network_list = networks_client.list_networks()
72 heat_network = [network for network in network_list['networks']
73 if network['name'] == heat_network_name]
74
75 if not heat_network:
76 project_id = projects_client.get_project_by_name(project)['id']
77 heat_network = networks_client.create_network(
78 name=heat_network_name,
79 project_id=project_id)
80 heat_network_id = heat_network['network']['id']
81 subnets_client.create_subnet(
82 network_id=heat_network_id,
83 ip_version=4,
84 cidr="192.168.199.0/24",
85 name=heat_subnet_name)
86
87 conf.set(sec, 'fixed_network_name', heat_network_name)
88 except Exception:
89 LOG.warning("Could not create network within the %s project "
90 "needed by heat tempest plugin!", project)
91
92 try:
93 users = Users(projects_client, roles_client, users_client, conf)
94 username = conf.get('identity', 'username')
95 users.give_role_to_user(username, "member")
96 except Exception:
97 LOG.warning("Could not assign role 'member' to user '%s'!",
98 username)
99
100 def post_configuration(self, conf, is_service):
101 conf.set('heat_plugin', 'disable_ssl_certificate_validation',
102 str(self.disable_ssl_validation))
103 if self.ca_certs:
104 conf.set('heat_plugin', 'ca_file', self.ca_certs)
105 if conf.has_section('compute'):
106 compute_options = conf.options('compute')
107 if 'flavor_ref' in compute_options:
108 conf.set('heat_plugin', 'minimal_instance_type',
109 conf.get('compute', 'flavor_ref'))
110 if 'flavor_ref_alt' in compute_options:
111 conf.set('heat_plugin', 'instance_type',
112 conf.get('compute', 'flavor_ref_alt'))
113 if 'image_ref' in compute_options:
114 conf.set('heat_plugin', 'minimal_image_ref',
115 conf.get('compute', 'image_ref'))
116 if 'image_ref_alt' in compute_options:
117 conf.set('heat_plugin', 'image_ref',
118 conf.get('compute', 'image_ref_alt'))
119 if conf.has_section('network'):
120 try:
121 network = conf.get('network', 'floating_network_name')
122 conf.set('heat_plugin', 'network_for_ssh', network)
123 conf.set('heat_plugin', 'floating_network_name', network)
124 except configparser.NoOptionError:
125 LOG.info("heat_plugin.network_for_ssh and heat_plugin."
126 "floating_network_name are not set because there "
127 "is no floating network")