blob: 8066cd974faa961da6a4521818b52b95dae9df2e [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 """
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040050
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030051 show_step(5)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040052 sl_actions = stacklight_deployed
53 nch = netchecker.Netchecker(k8s_deployed.api)
54
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030055 show_step(6)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040056 nch.wait_netchecker_pods_running(netchecker.NETCHECKER_SERVER_PREFIX)
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030057
58 show_step(7)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040059 nch.wait_netchecker_pods_running(netchecker.NETCHECKER_AGENT_PREFIX)
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030060
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040061 show_step(8)
62 nch.wait_check_network(works=True)
63
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030064 show_step(9)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040065 res = nch.get_metric()
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030066
Dina Belovae6fdffb2017-09-19 13:58:34 -070067 assert res.status_code == 200, 'Unexpected response code {}'\
68 .format(res)
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030069 metrics = ['ncagent_error_count_total', 'ncagent_http_probe_code',
70 'ncagent_http_probe_connect_time_ms',
71 'ncagent_http_probe_connection_result',
72 'ncagent_http_probe_content_transfer_time_ms',
73 'ncagent_http_probe_dns_lookup_time_ms',
74 'ncagent_http_probe_server_processing_time_ms',
75 'ncagent_http_probe_tcp_connection_time_ms',
76 'ncagent_http_probe_total_time_ms',
77 'ncagent_report_count_tota']
78 for metric in metrics:
79 assert metric in res.text.strip(), \
80 'Mandotory metric {0} is missing in {1}'.format(
81 metric, res.text)
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030082
Dennis Dmitrievea48cf52018-07-18 18:04:39 +030083 prometheus_client = stacklight_deployed.api
Tatyana Leontovichb57ec132017-07-27 17:16:42 +030084 try:
85 current_targets = prometheus_client.get_targets()
Dina Belovae6fdffb2017-09-19 13:58:34 -070086 LOG.debug('Current targets after install {0}'
87 .format(current_targets))
Dennis Dmitriev9b02c8b2017-11-13 15:31:35 +020088 except Exception:
Tatyana Leontovichb57ec132017-07-27 17:16:42 +030089 LOG.warning('Restarting keepalived service on mon nodes...')
90 sl_actions._salt.local(tgt='mon*', fun='cmd.run',
91 args='systemctl restart keepalived')
92 LOG.warning(
93 'Ip states after forset restart {0}'.format(
94 sl_actions._salt.local(tgt='mon*',
95 fun='cmd.run', args='ip a')))
96 current_targets = prometheus_client.get_targets()
Dina Belovae6fdffb2017-09-19 13:58:34 -070097 LOG.debug('Current targets after install {0}'
98 .format(current_targets))
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030099
Dina Belovae6fdffb2017-09-19 13:58:34 -0700100 # todo (tleontovich) add assertion that k8s targets here
Tatyana Leontovich09b7b012017-07-10 12:53:45 +0300101 for metric in metrics:
102 res = prometheus_client.get_query(metric)
103 for entry in res:
104 assert entry["metric"]["job"] == 'kubernetes-service-endpoints'
105 LOG.debug('Metric {} exists'.format(res))
Dina Belovae6fdffb2017-09-19 13:58:34 -0700106 # todo (tleontovich) add asserts here and extend the tests
107 # with acceptance criteria
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300108 show_step(10)
109 # Run SL component tests
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300110 stacklight_deployed.run_sl_functional_tests(
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300111 'cfg01',
112 '/root/stacklight-pytest/stacklight_tests/',
113 'tests/prometheus',
114 'test_alerts.py')
115
116 # Download report
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300117 stacklight_deployed.download_sl_test_report(
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300118 'cfg01',
119 '/root/stacklight-pytest/stacklight_tests/report.xml')
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300120 LOG.info("*************** DONE **************")
121
Tatyana Leontovichc411ec32017-10-09 14:48:00 +0300122 @pytest.mark.grab_versions
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300123 @pytest.mark.fail_snapshot
124 @pytest.mark.cz8115
Tatyana Leontovich071ce6a2017-10-24 18:08:10 +0300125 def test_k8s_install_contrail_lma(self, config, show_step,
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +0300126 k8s_deployed,
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300127 stacklight_deployed):
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300128 """Test for deploying MCP with k8s+stacklight+contrail and check it
129
130 Scenario:
131 1. Prepare salt on hosts
132 2. Setup controller nodes
133 3. Setup compute nodes
134 4. Setup stack light nodes
135 5. Setup Kubernetes cluster and check it nodes
136 6. Run LMA2.0 component tests
137 7. Optionally run k8s e2e conformance
138
139 """
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +0400140
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300141 show_step(5)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +0400142 sl_actions = stacklight_deployed
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300143
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300144 prometheus_client = stacklight_deployed.api
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300145 try:
146 current_targets = prometheus_client.get_targets()
147 LOG.debug('Current targets after install {0}'
148 .format(current_targets))
Dennis Dmitriev9b02c8b2017-11-13 15:31:35 +0200149 except Exception:
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300150 LOG.warning('Restarting keepalived service on mon nodes...')
151 sl_actions._salt.local(tgt='mon*', fun='cmd.run',
152 args='systemctl restart keepalived')
153 LOG.warning(
154 'Ip states after forset restart {0}'.format(
155 sl_actions._salt.local(tgt='mon*',
156 fun='cmd.run', args='ip a')))
157 current_targets = prometheus_client.get_targets()
158 LOG.debug('Current targets after install {0}'
159 .format(current_targets))
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300160 mon_nodes = stacklight_deployed.get_monitoring_nodes()
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300161 LOG.debug('Mon nodes list {0}'.format(mon_nodes))
162
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300163 stacklight_deployed.check_prometheus_targets(mon_nodes)
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300164 show_step(6)
165 # Run SL component tests
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300166 stacklight_deployed.run_sl_functional_tests(
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300167 'cfg01',
168 '/root/stacklight-pytest/stacklight_tests/',
169 'tests/prometheus',
170 'test_alerts.py')
171
172 # Download report
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300173 stacklight_deployed.download_sl_test_report(
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300174 'cfg01',
175 '/root/stacklight-pytest/stacklight_tests/report.xml')
176
177 if config.k8s.k8s_conformance_run:
178 show_step(7)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +0400179 k8s_deployed.run_conformance()
Tatyana Leontovichb7404592017-04-07 11:52:28 +0300180 LOG.info("*************** DONE **************")
vrovachev0a2f6352017-06-09 12:48:59 +0400181
Victor Ryzhenkincf26c932018-03-29 20:08:21 +0400182 @pytest.mark.extract(container_system='docker', extract_from='conformance',
183 files_to_extract=['report'])
184 @pytest.mark.merge_xunit(path='/root/report',
185 output='/root/conformance_result.xml')
186 @pytest.mark.grab_k8s_results(name=['k8s_conformance.log',
187 'conformance_result.xml'])
Tatyana Leontovichc411ec32017-10-09 14:48:00 +0300188 @pytest.mark.grab_versions
Artem Panchenko0594cd72017-06-12 13:25:26 +0300189 @pytest.mark.fail_snapshot
Tatyana Leontovich071ce6a2017-10-24 18:08:10 +0300190 @pytest.mark.cz8116
Dennis Dmitriev0f624a82018-06-11 12:57:13 +0300191 @pytest.mark.k8s_calico
Victor Ryzhenkincf26c932018-03-29 20:08:21 +0400192 def test_only_k8s_install(self, config, show_step,
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +0300193 k8s_deployed, k8s_logs):
Artem Panchenko0594cd72017-06-12 13:25:26 +0300194 """Test for deploying MCP environment with k8s and check it
vrovachev0a2f6352017-06-09 12:48:59 +0400195
196 Scenario:
197 1. Prepare salt on hosts
198 2. Setup controller nodes
199 3. Setup compute nodes
Artem Panchenko0594cd72017-06-12 13:25:26 +0300200 4. Setup Kubernetes cluster
vrovacheva9d08332017-06-22 20:01:59 +0400201 5. Run conformance if need
vrovachev0a2f6352017-06-09 12:48:59 +0400202
203 """
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +0400204
Tatyana Leontovich1c568f92017-07-03 15:16:27 +0300205 if config.k8s.k8s_conformance_run:
Victor Ryzhenkincf26c932018-03-29 20:08:21 +0400206 show_step(5)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +0400207 k8s_deployed.run_conformance()
Dina Belova9e9141d2017-09-19 14:16:34 -0700208 LOG.info("*************** DONE **************")