This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
test_cli.py
293 lines (247 loc) · 11.9 KB
/
test_cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# Copyright 2015 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from proboscis import test
from proboscis.asserts import assert_equal
from proboscis.asserts import assert_false
from proboscis.asserts import assert_true
from devops.error import TimeoutError
from devops.helpers.helpers import wait
from fuelweb_test.helpers.checkers import check_cluster_presence
from fuelweb_test.helpers.checkers import check_cobbler_node_exists
from fuelweb_test.helpers.decorators import log_snapshot_after_test
from fuelweb_test.helpers.utils import run_on_remote
from fuelweb_test.settings import DEPLOYMENT_MODE
from fuelweb_test.settings import NEUTRON_ENABLE
from fuelweb_test.settings import NEUTRON_SEGMENT_TYPE
from fuelweb_test.settings import OPENSTACK_RELEASE
from fuelweb_test.tests.base_test_case import SetupEnvironment
from fuelweb_test.tests.base_test_case import TestBasic
from fuelweb_test.tests import test_cli_base
from fuelweb_test import logger
@test(groups=["command_line_minimal"])
class CommandLineMinimal(TestBasic):
"""CommandLineMinimal.""" # TODO documentation
@test(depends_on=[SetupEnvironment.setup_with_custom_manifests],
groups=["hiera_deploy"])
@log_snapshot_after_test
def hiera_deploy(self):
"""Deploy cluster with controller node only
Scenario:
1. Start installation of master
2. Enter "fuelmenu"
3. Upload custom manifests
4. Kill "fuelmenu" pid
5. Deploy hiera manifest
Duration 20m
"""
self.env.revert_snapshot("empty_custom_manifests")
self.env.bootstrap_nodes(
self.env.d_env.nodes().slaves[:1])
cluster_id = self.fuel_web.create_cluster(
name=self.__class__.__name__,
mode=DEPLOYMENT_MODE
)
self.fuel_web.update_nodes(
cluster_id,
{'slave-01': ['controller']}
)
with self.env.d_env.get_admin_remote() as remote:
node_id = self.fuel_web.get_nailgun_node_by_devops_node(
self.env.d_env.nodes().slaves[0])['id']
remote.execute('fuel node --node {0} --provision --env {1}'.format
(node_id, cluster_id))
self.fuel_web.provisioning_cluster_wait(cluster_id)
remote.execute('fuel node --node {0} --end hiera --env {1}'.format
(node_id, cluster_id))
try:
wait(lambda: int(
remote.execute(
'fuel task | grep deployment | awk \'{print $9}\'')
['stdout'][0].rstrip()) == 100, timeout=120)
except TimeoutError:
raise TimeoutError("hiera manifest was not applyed")
role = remote.execute('ssh -q node-{0} "hiera role"'
.format(node_id))['stdout'][0].rstrip()
assert_equal(role, 'primary-controller', "node with deployed hiera "
"was not found")
@test(groups=["command_line"])
class CommandLineTest(test_cli_base.CommandLine):
"""CommandLine.""" # TODO documentation
@test(depends_on=[SetupEnvironment.prepare_slaves_3],
groups=["cli_selected_nodes_deploy"])
@log_snapshot_after_test
def cli_selected_nodes_deploy(self):
"""Create and deploy environment using Fuel CLI
Scenario:
1. Revert snapshot "ready_with_3_slaves"
2. Create a cluster using Fuel CLI
3. Provision a controller node using Fuel CLI
4. Provision two compute+cinder nodes using Fuel CLI
5. Deploy the controller node using Fuel CLI
6. Deploy the compute+cinder nodes usin Fuel CLI
7. Run OSTF
8. Make snapshot "cli_selected_nodes_deploy"
Duration 50m
"""
self.env.revert_snapshot("ready_with_3_slaves")
node_ids = [self.fuel_web.get_nailgun_node_by_devops_node(
self.env.d_env.nodes().slaves[slave_id])['id']
for slave_id in range(3)]
release_id = self.fuel_web.get_releases_list_for_os(
release_name=OPENSTACK_RELEASE)[0]
# Choose network type
if NEUTRON_ENABLE:
net = 'neutron --nst={nst}'.format(nst=NEUTRON_SEGMENT_TYPE)
else:
net = 'nova'
with self.env.d_env.get_admin_remote() as remote:
# Create an environment
cmd = ('fuel env create --name={0} --release={1} --mode=ha '
'--net={2} --json'.format(self.__class__.__name__,
release_id, net))
env_result = run_on_remote(remote, cmd, jsonify=True)
cluster_id = env_result['id']
# Update network parameters
self.update_cli_network_configuration(cluster_id, remote)
# Update SSL configuration
self.update_ssl_configuration(cluster_id, remote)
# Add and provision a controller node
logger.info("Add to the cluster and start provisioning "
"a controller node [{0}]".format(node_ids[0]))
cmd = ('fuel --env-id={0} node set --node {1} --role=controller'
.format(cluster_id, node_ids[0]))
remote.execute(cmd)
cmd = ('fuel --env-id={0} node --provision --node={1} --json'
.format(cluster_id, node_ids[0]))
task = run_on_remote(remote, cmd, jsonify=True)
self.assert_cli_task_success(task, remote, timeout=30 * 60)
# Add and provision 2 compute+cinder
logger.info("Add to the cluster and start provisioning two "
"compute+cinder nodes [{0},{1}]".format(node_ids[1],
node_ids[2]))
cmd = ('fuel --env-id={0} node set --node {1},{2} '
'--role=compute,cinder'.format(cluster_id,
node_ids[1], node_ids[2]))
remote.execute(cmd)
cmd = ('fuel --env-id={0} node --provision --node={1},{2} --json'
.format(cluster_id, node_ids[1], node_ids[2]))
task = run_on_remote(remote, cmd, jsonify=True)
self.assert_cli_task_success(task, remote, timeout=10 * 60)
# Deploy the controller node
cmd = ('fuel --env-id={0} node --deploy --node {1} --json'
.format(cluster_id, node_ids[0]))
task = run_on_remote(remote, cmd, jsonify=True)
self.assert_cli_task_success(task, remote, timeout=60 * 60)
# Deploy the compute nodes
cmd = ('fuel --env-id={0} node --deploy --node {1},{2} --json'
.format(cluster_id, node_ids[1], node_ids[2]))
task = run_on_remote(remote, cmd, jsonify=True)
self.assert_cli_task_success(task, remote, timeout=30 * 60)
self.fuel_web.run_ostf(
cluster_id=cluster_id,
test_sets=['ha', 'smoke', 'sanity'])
self.env.make_snapshot("cli_selected_nodes_deploy", is_make=True)
@test(depends_on_groups=['cli_selected_nodes_deploy'],
groups=["cli_node_deletion_check"])
@log_snapshot_after_test
def cli_node_deletion_check(self):
"""Destroy node and remove it from Nailgun using Fuel CLI
Scenario:
1. Revert snapshot 'cli_selected_nodes_deploy'
2. Check 'slave-03' is present
3. Destroy 'slave-03'
4. Wait until 'slave-03' become offline
5. Delete offline 'slave-03' from db
6. Check presence of 'slave-03'
Duration 30m
"""
self.env.revert_snapshot("cli_selected_nodes_deploy")
with self.env.d_env.get_admin_remote() as remote:
node_id = self.fuel_web.get_nailgun_node_by_devops_node(
self.env.d_env.nodes().slaves[2])['id']
assert_true(check_cobbler_node_exists(remote, node_id),
"node-{0} is not found".format(node_id))
self.env.d_env.nodes().slaves[2].destroy()
try:
wait(
lambda: not self.fuel_web.get_nailgun_node_by_devops_node(
self.env.d_env.nodes().
slaves[2])['online'], timeout=60 * 6)
except TimeoutError:
raise
with self.env.d_env.get_admin_remote() as remote:
res = remote.execute('fuel node --node-id {0} --delete-from-db'
.format(node_id))
assert_true(
res['exit_code'] == 0,
"Offline node-{0} was not"
"deleted from database".format(node_id))
with self.env.d_env.get_admin_remote() as remote:
try:
wait(
lambda: not remote.execute(
"fuel node | awk '{{print $1}}' | grep -w '{0}'".
format(node_id))['exit_code'] == 0, timeout=60 * 4)
except TimeoutError:
raise TimeoutError(
"After deletion node-{0} is found in fuel list".
format(node_id))
with self.env.d_env.get_admin_remote() as remote:
is_cobler_node_exists = check_cobbler_node_exists(remote, node_id)
assert_false(is_cobler_node_exists,
"After deletion node-{0} is found in cobbler list".
format(node_id))
with self.env.d_env.get_admin_remote() as remote:
cluster_id = ''.join(remote.execute(
"fuel env | tail -n 1 | awk {'print $1'}")['stdout']).rstrip()
self.fuel_web.verify_network(cluster_id)
self.fuel_web.run_ostf(
cluster_id=cluster_id, test_sets=['ha', 'smoke', 'sanity'],
should_fail=1)
@test(depends_on_groups=['cli_selected_nodes_deploy'],
groups=["cli_cluster_deletion"])
@log_snapshot_after_test
def cli_cluster_deletion(self):
"""Delete a cluster using Fuel CLI
Scenario:
1. Revert snapshot 'cli_selected_nodes_deploy'
2. Delete cluster via cli
3. Check cluster absence in the list
Duration 25m
"""
self.env.revert_snapshot("cli_selected_nodes_deploy")
cluster_id = self.fuel_web.get_last_created_cluster()
nodes = self.fuel_web.client.list_cluster_nodes(cluster_id)
online_nodes = [node for node in nodes if node['online']]
if nodes != online_nodes:
logger.error(
'Some slaves do not become online after revert!!'
' Expected {0} Actual {1}'.format(nodes, online_nodes))
with self.env.d_env.get_admin_remote() as remote:
res = remote.execute('fuel --env {0} env delete'
.format(cluster_id))
assert_true(
res['exit_code'] == 0)
with self.env.d_env.get_admin_remote() as remote:
try:
wait(lambda:
remote.execute("fuel env | awk '{print $1}'"
" | tail -n 1 | grep '^.$'")
['exit_code'] == 1, timeout=60 * 10)
except TimeoutError:
raise TimeoutError(
"cluster {0} was not deleted".format(cluster_id))
assert_false(
check_cluster_presence(cluster_id, self.env.postgres_actions),
"cluster {0} is found".format(cluster_id))