blob: ac4d1d16aa6f4acd5481efb6e72fccf4e959a499 [file] [log] [blame]
Tatyana Leontovichb7404592017-04-07 11:52:28 +03001# Copyright 2017 Mirantis, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
Tatyana Leontovichb7404592017-04-07 11:52:28 +030014
15import pytest
16
Tatyana Leontovichb7404592017-04-07 11:52:28 +030017from tcp_tests import logger
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030018from tcp_tests.helpers import netchecker
Tatyana Leontovichb7404592017-04-07 11:52:28 +030019
20LOG = logger.logger
21
22
23@pytest.mark.deploy
24class Testk8sInstall(object):
Artem Panchenko0594cd72017-06-12 13:25:26 +030025 """Test class for testing Kubernetes deploy"""
Tatyana Leontovichb7404592017-04-07 11:52:28 +030026
Tatyana Leontovichc411ec32017-10-09 14:48:00 +030027 @pytest.mark.grab_versions
Artem Panchenko0594cd72017-06-12 13:25:26 +030028 @pytest.mark.fail_snapshot
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +030029 @pytest.mark.cz8116
Dennis Dmitriev0f624a82018-06-11 12:57:13 +030030 @pytest.mark.k8s_calico_sl
Tatyana Leontovich071ce6a2017-10-24 18:08:10 +030031 def test_k8s_install_calico_lma(self, config, show_step,
32 k8s_deployed, k8s_actions,
33 sl_deployed, sl_actions):
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +030034 """Test for deploying MCP with k8s+stacklight_calico and check it
Tatyana Leontovichb7404592017-04-07 11:52:28 +030035
36 Scenario:
37 1. Prepare salt on hosts
38 2. Setup controller nodes
39 3. Setup compute nodes
Tatyana Leontovich5acc82a2017-05-23 15:41:35 +030040 4. Setup stack light nodes
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030041 5. Setup Kubernetes cluster and check it nodes
42 6. Check netchecker server is running
43 7. Check netchecker agent is running
44 8. Check connectivity
45 9. Get metrics from netchecker
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +030046 10. Run LMA component tests
47 11. Optionally run k8s e2e tests
Tatyana Leontovichb7404592017-04-07 11:52:28 +030048
49 """
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030050 # STEP #5
51 show_step(5)
52 k8sclient = k8s_deployed.api
53 assert k8sclient.nodes.list() is not None, "Can not get nodes list"
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030054 netchecker_port = netchecker.get_service_port(k8sclient)
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030055 show_step(6)
56 netchecker.get_netchecker_pod_status(k8s=k8s_deployed,
57 namespace='netchecker')
58
59 show_step(7)
60 netchecker.get_netchecker_pod_status(k8s=k8s_deployed,
61 pod_name='netchecker-agent',
62 namespace='netchecker')
63
64 # show_step(8)
65 netchecker.wait_check_network(k8sclient, namespace='netchecker',
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030066 netchecker_pod_port=netchecker_port)
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030067 show_step(9)
Dina Belovae6fdffb2017-09-19 13:58:34 -070068 res = netchecker.get_metric(k8sclient,
69 netchecker_pod_port=netchecker_port,
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030070 namespace='netchecker')
71
Dina Belovae6fdffb2017-09-19 13:58:34 -070072 assert res.status_code == 200, 'Unexpected response code {}'\
73 .format(res)
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030074 metrics = ['ncagent_error_count_total', 'ncagent_http_probe_code',
75 'ncagent_http_probe_connect_time_ms',
76 'ncagent_http_probe_connection_result',
77 'ncagent_http_probe_content_transfer_time_ms',
78 'ncagent_http_probe_dns_lookup_time_ms',
79 'ncagent_http_probe_server_processing_time_ms',
80 'ncagent_http_probe_tcp_connection_time_ms',
81 'ncagent_http_probe_total_time_ms',
82 'ncagent_report_count_tota']
83 for metric in metrics:
84 assert metric in res.text.strip(), \
85 'Mandotory metric {0} is missing in {1}'.format(
86 metric, res.text)
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030087
88 prometheus_client = sl_deployed.api
Tatyana Leontovichb57ec132017-07-27 17:16:42 +030089 try:
90 current_targets = prometheus_client.get_targets()
Dina Belovae6fdffb2017-09-19 13:58:34 -070091 LOG.debug('Current targets after install {0}'
92 .format(current_targets))
Dennis Dmitriev9b02c8b2017-11-13 15:31:35 +020093 except Exception:
Tatyana Leontovichb57ec132017-07-27 17:16:42 +030094 LOG.warning('Restarting keepalived service on mon nodes...')
95 sl_actions._salt.local(tgt='mon*', fun='cmd.run',
96 args='systemctl restart keepalived')
97 LOG.warning(
98 'Ip states after forset restart {0}'.format(
99 sl_actions._salt.local(tgt='mon*',
100 fun='cmd.run', args='ip a')))
101 current_targets = prometheus_client.get_targets()
Dina Belovae6fdffb2017-09-19 13:58:34 -0700102 LOG.debug('Current targets after install {0}'
103 .format(current_targets))
Tatyana Leontovich09b7b012017-07-10 12:53:45 +0300104
Dina Belovae6fdffb2017-09-19 13:58:34 -0700105 # todo (tleontovich) add assertion that k8s targets here
Tatyana Leontovich09b7b012017-07-10 12:53:45 +0300106 for metric in metrics:
107 res = prometheus_client.get_query(metric)
108 for entry in res:
109 assert entry["metric"]["job"] == 'kubernetes-service-endpoints'
110 LOG.debug('Metric {} exists'.format(res))
Dina Belovae6fdffb2017-09-19 13:58:34 -0700111 # todo (tleontovich) add asserts here and extend the tests
112 # with acceptance criteria
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300113 show_step(10)
114 # Run SL component tests
115 sl_deployed.run_sl_functional_tests(
116 'cfg01',
117 '/root/stacklight-pytest/stacklight_tests/',
118 'tests/prometheus',
119 'test_alerts.py')
120
121 # Download report
122 sl_deployed.download_sl_test_report(
123 'cfg01',
124 '/root/stacklight-pytest/stacklight_tests/report.xml')
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300125 LOG.info("*************** DONE **************")
126
Tatyana Leontovichc411ec32017-10-09 14:48:00 +0300127 @pytest.mark.grab_versions
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300128 @pytest.mark.fail_snapshot
129 @pytest.mark.cz8115
Tatyana Leontovich071ce6a2017-10-24 18:08:10 +0300130 def test_k8s_install_contrail_lma(self, config, show_step,
131 k8s_deployed, k8s_actions,
132 sl_deployed, sl_actions):
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300133 """Test for deploying MCP with k8s+stacklight+contrail and check it
134
135 Scenario:
136 1. Prepare salt on hosts
137 2. Setup controller nodes
138 3. Setup compute nodes
139 4. Setup stack light nodes
140 5. Setup Kubernetes cluster and check it nodes
141 6. Run LMA2.0 component tests
142 7. Optionally run k8s e2e conformance
143
144 """
145 # STEP #5
146 show_step(5)
147 k8sclient = k8s_deployed.api
148 assert k8sclient.nodes.list() is not None, "Can not get nodes list"
149
150 prometheus_client = sl_deployed.api
151 try:
152 current_targets = prometheus_client.get_targets()
153 LOG.debug('Current targets after install {0}'
154 .format(current_targets))
Dennis Dmitriev9b02c8b2017-11-13 15:31:35 +0200155 except Exception:
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300156 LOG.warning('Restarting keepalived service on mon nodes...')
157 sl_actions._salt.local(tgt='mon*', fun='cmd.run',
158 args='systemctl restart keepalived')
159 LOG.warning(
160 'Ip states after forset restart {0}'.format(
161 sl_actions._salt.local(tgt='mon*',
162 fun='cmd.run', args='ip a')))
163 current_targets = prometheus_client.get_targets()
164 LOG.debug('Current targets after install {0}'
165 .format(current_targets))
166 mon_nodes = sl_deployed.get_monitoring_nodes()
167 LOG.debug('Mon nodes list {0}'.format(mon_nodes))
168
169 sl_deployed.check_prometheus_targets(mon_nodes)
170 show_step(6)
171 # Run SL component tests
172 sl_deployed.run_sl_functional_tests(
173 'cfg01',
174 '/root/stacklight-pytest/stacklight_tests/',
175 'tests/prometheus',
176 'test_alerts.py')
177
178 # Download report
179 sl_deployed.download_sl_test_report(
180 'cfg01',
181 '/root/stacklight-pytest/stacklight_tests/report.xml')
182
183 if config.k8s.k8s_conformance_run:
184 show_step(7)
vrovacheva9d08332017-06-22 20:01:59 +0400185 k8s_actions.run_conformance()
Tatyana Leontovichb7404592017-04-07 11:52:28 +0300186 LOG.info("*************** DONE **************")
vrovachev0a2f6352017-06-09 12:48:59 +0400187
Victor Ryzhenkincf26c932018-03-29 20:08:21 +0400188 @pytest.mark.extract(container_system='docker', extract_from='conformance',
189 files_to_extract=['report'])
190 @pytest.mark.merge_xunit(path='/root/report',
191 output='/root/conformance_result.xml')
192 @pytest.mark.grab_k8s_results(name=['k8s_conformance.log',
193 'conformance_result.xml'])
Tatyana Leontovichc411ec32017-10-09 14:48:00 +0300194 @pytest.mark.grab_versions
Artem Panchenko0594cd72017-06-12 13:25:26 +0300195 @pytest.mark.fail_snapshot
Tatyana Leontovich071ce6a2017-10-24 18:08:10 +0300196 @pytest.mark.cz8116
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300197 @pytest.mark.k8s_calico
Victor Ryzhenkincf26c932018-03-29 20:08:21 +0400198 def test_only_k8s_install(self, config, show_step,
199 k8s_deployed, k8s_actions, k8s_logs):
Artem Panchenko0594cd72017-06-12 13:25:26 +0300200 """Test for deploying MCP environment with k8s and check it
vrovachev0a2f6352017-06-09 12:48:59 +0400201
202 Scenario:
203 1. Prepare salt on hosts
204 2. Setup controller nodes
205 3. Setup compute nodes
Artem Panchenko0594cd72017-06-12 13:25:26 +0300206 4. Setup Kubernetes cluster
vrovacheva9d08332017-06-22 20:01:59 +0400207 5. Run conformance if need
vrovachev0a2f6352017-06-09 12:48:59 +0400208
209 """
Tatyana Leontovich1c568f92017-07-03 15:16:27 +0300210 if config.k8s.k8s_conformance_run:
Victor Ryzhenkincf26c932018-03-29 20:08:21 +0400211 show_step(5)
vrovacheva9d08332017-06-22 20:01:59 +0400212 k8s_actions.run_conformance()
Dina Belova9e9141d2017-09-19 14:16:34 -0700213 LOG.info("*************** DONE **************")