blob: ec90863b979700eec0ff713bd34de95a3c9c9a2a [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,
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +030032 k8s_deployed,
Dennis Dmitrievea48cf52018-07-18 18:04:39 +030033 stacklight_deployed):
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
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +030051 # k8s_actions = k8s_deployed
Dennis Dmitrievea48cf52018-07-18 18:04:39 +030052 sl_actions = stacklight_deployed
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030053 show_step(5)
54 k8sclient = k8s_deployed.api
55 assert k8sclient.nodes.list() is not None, "Can not get nodes list"
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030056 netchecker_port = netchecker.get_service_port(k8sclient)
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030057 show_step(6)
58 netchecker.get_netchecker_pod_status(k8s=k8s_deployed,
59 namespace='netchecker')
60
61 show_step(7)
62 netchecker.get_netchecker_pod_status(k8s=k8s_deployed,
63 pod_name='netchecker-agent',
64 namespace='netchecker')
65
66 # show_step(8)
67 netchecker.wait_check_network(k8sclient, namespace='netchecker',
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030068 netchecker_pod_port=netchecker_port)
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030069 show_step(9)
Dina Belovae6fdffb2017-09-19 13:58:34 -070070 res = netchecker.get_metric(k8sclient,
71 netchecker_pod_port=netchecker_port,
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030072 namespace='netchecker')
73
Dina Belovae6fdffb2017-09-19 13:58:34 -070074 assert res.status_code == 200, 'Unexpected response code {}'\
75 .format(res)
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030076 metrics = ['ncagent_error_count_total', 'ncagent_http_probe_code',
77 'ncagent_http_probe_connect_time_ms',
78 'ncagent_http_probe_connection_result',
79 'ncagent_http_probe_content_transfer_time_ms',
80 'ncagent_http_probe_dns_lookup_time_ms',
81 'ncagent_http_probe_server_processing_time_ms',
82 'ncagent_http_probe_tcp_connection_time_ms',
83 'ncagent_http_probe_total_time_ms',
84 'ncagent_report_count_tota']
85 for metric in metrics:
86 assert metric in res.text.strip(), \
87 'Mandotory metric {0} is missing in {1}'.format(
88 metric, res.text)
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030089
Dennis Dmitrievea48cf52018-07-18 18:04:39 +030090 prometheus_client = stacklight_deployed.api
Tatyana Leontovichb57ec132017-07-27 17:16:42 +030091 try:
92 current_targets = prometheus_client.get_targets()
Dina Belovae6fdffb2017-09-19 13:58:34 -070093 LOG.debug('Current targets after install {0}'
94 .format(current_targets))
Dennis Dmitriev9b02c8b2017-11-13 15:31:35 +020095 except Exception:
Tatyana Leontovichb57ec132017-07-27 17:16:42 +030096 LOG.warning('Restarting keepalived service on mon nodes...')
97 sl_actions._salt.local(tgt='mon*', fun='cmd.run',
98 args='systemctl restart keepalived')
99 LOG.warning(
100 'Ip states after forset restart {0}'.format(
101 sl_actions._salt.local(tgt='mon*',
102 fun='cmd.run', args='ip a')))
103 current_targets = prometheus_client.get_targets()
Dina Belovae6fdffb2017-09-19 13:58:34 -0700104 LOG.debug('Current targets after install {0}'
105 .format(current_targets))
Tatyana Leontovich09b7b012017-07-10 12:53:45 +0300106
Dina Belovae6fdffb2017-09-19 13:58:34 -0700107 # todo (tleontovich) add assertion that k8s targets here
Tatyana Leontovich09b7b012017-07-10 12:53:45 +0300108 for metric in metrics:
109 res = prometheus_client.get_query(metric)
110 for entry in res:
111 assert entry["metric"]["job"] == 'kubernetes-service-endpoints'
112 LOG.debug('Metric {} exists'.format(res))
Dina Belovae6fdffb2017-09-19 13:58:34 -0700113 # todo (tleontovich) add asserts here and extend the tests
114 # with acceptance criteria
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300115 show_step(10)
116 # Run SL component tests
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300117 stacklight_deployed.run_sl_functional_tests(
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300118 'cfg01',
119 '/root/stacklight-pytest/stacklight_tests/',
120 'tests/prometheus',
121 'test_alerts.py')
122
123 # Download report
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300124 stacklight_deployed.download_sl_test_report(
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300125 'cfg01',
126 '/root/stacklight-pytest/stacklight_tests/report.xml')
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300127 LOG.info("*************** DONE **************")
128
Tatyana Leontovichc411ec32017-10-09 14:48:00 +0300129 @pytest.mark.grab_versions
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300130 @pytest.mark.fail_snapshot
131 @pytest.mark.cz8115
Tatyana Leontovich071ce6a2017-10-24 18:08:10 +0300132 def test_k8s_install_contrail_lma(self, config, show_step,
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +0300133 k8s_deployed,
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300134 stacklight_deployed):
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300135 """Test for deploying MCP with k8s+stacklight+contrail and check it
136
137 Scenario:
138 1. Prepare salt on hosts
139 2. Setup controller nodes
140 3. Setup compute nodes
141 4. Setup stack light nodes
142 5. Setup Kubernetes cluster and check it nodes
143 6. Run LMA2.0 component tests
144 7. Optionally run k8s e2e conformance
145
146 """
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +0300147 k8s_actions = k8s_deployed
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300148 sl_actions = stacklight_deployed
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300149 # STEP #5
150 show_step(5)
151 k8sclient = k8s_deployed.api
152 assert k8sclient.nodes.list() is not None, "Can not get nodes list"
153
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300154 prometheus_client = stacklight_deployed.api
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300155 try:
156 current_targets = prometheus_client.get_targets()
157 LOG.debug('Current targets after install {0}'
158 .format(current_targets))
Dennis Dmitriev9b02c8b2017-11-13 15:31:35 +0200159 except Exception:
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300160 LOG.warning('Restarting keepalived service on mon nodes...')
161 sl_actions._salt.local(tgt='mon*', fun='cmd.run',
162 args='systemctl restart keepalived')
163 LOG.warning(
164 'Ip states after forset restart {0}'.format(
165 sl_actions._salt.local(tgt='mon*',
166 fun='cmd.run', args='ip a')))
167 current_targets = prometheus_client.get_targets()
168 LOG.debug('Current targets after install {0}'
169 .format(current_targets))
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300170 mon_nodes = stacklight_deployed.get_monitoring_nodes()
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300171 LOG.debug('Mon nodes list {0}'.format(mon_nodes))
172
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300173 stacklight_deployed.check_prometheus_targets(mon_nodes)
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300174 show_step(6)
175 # Run SL component tests
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300176 stacklight_deployed.run_sl_functional_tests(
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300177 'cfg01',
178 '/root/stacklight-pytest/stacklight_tests/',
179 'tests/prometheus',
180 'test_alerts.py')
181
182 # Download report
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300183 stacklight_deployed.download_sl_test_report(
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300184 'cfg01',
185 '/root/stacklight-pytest/stacklight_tests/report.xml')
186
187 if config.k8s.k8s_conformance_run:
188 show_step(7)
vrovacheva9d08332017-06-22 20:01:59 +0400189 k8s_actions.run_conformance()
Tatyana Leontovichb7404592017-04-07 11:52:28 +0300190 LOG.info("*************** DONE **************")
vrovachev0a2f6352017-06-09 12:48:59 +0400191
Victor Ryzhenkincf26c932018-03-29 20:08:21 +0400192 @pytest.mark.extract(container_system='docker', extract_from='conformance',
193 files_to_extract=['report'])
194 @pytest.mark.merge_xunit(path='/root/report',
195 output='/root/conformance_result.xml')
196 @pytest.mark.grab_k8s_results(name=['k8s_conformance.log',
197 'conformance_result.xml'])
Tatyana Leontovichc411ec32017-10-09 14:48:00 +0300198 @pytest.mark.grab_versions
Artem Panchenko0594cd72017-06-12 13:25:26 +0300199 @pytest.mark.fail_snapshot
Tatyana Leontovich071ce6a2017-10-24 18:08:10 +0300200 @pytest.mark.cz8116
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300201 @pytest.mark.k8s_calico
Victor Ryzhenkincf26c932018-03-29 20:08:21 +0400202 def test_only_k8s_install(self, config, show_step,
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +0300203 k8s_deployed, k8s_logs):
Artem Panchenko0594cd72017-06-12 13:25:26 +0300204 """Test for deploying MCP environment with k8s and check it
vrovachev0a2f6352017-06-09 12:48:59 +0400205
206 Scenario:
207 1. Prepare salt on hosts
208 2. Setup controller nodes
209 3. Setup compute nodes
Artem Panchenko0594cd72017-06-12 13:25:26 +0300210 4. Setup Kubernetes cluster
vrovacheva9d08332017-06-22 20:01:59 +0400211 5. Run conformance if need
vrovachev0a2f6352017-06-09 12:48:59 +0400212
213 """
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +0300214 k8s_actions = k8s_deployed
Tatyana Leontovich1c568f92017-07-03 15:16:27 +0300215 if config.k8s.k8s_conformance_run:
Victor Ryzhenkincf26c932018-03-29 20:08:21 +0400216 show_step(5)
vrovacheva9d08332017-06-22 20:01:59 +0400217 k8s_actions.run_conformance()
Dina Belova9e9141d2017-09-19 14:16:34 -0700218 LOG.info("*************** DONE **************")