blob: b9621ab5ce8d43d8523c87b1536f9b90d6d83954 [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)
Dennis Dmitriev66650fc2018-11-02 11:04:37 +0200109
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300110 # Run SL component tests
Dennis Dmitriev66650fc2018-11-02 11:04:37 +0200111 stacklight_deployed.setup_sl_functional_tests(
112 'cfg01',
113 )
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300114 stacklight_deployed.run_sl_functional_tests(
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300115 'cfg01',
116 '/root/stacklight-pytest/stacklight_tests/',
vitalygusev0e57ef62018-11-30 12:13:56 +0400117 'tests',
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300118 'test_alerts.py')
119
120 # Download report
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300121 stacklight_deployed.download_sl_test_report(
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300122 'cfg01',
123 '/root/stacklight-pytest/stacklight_tests/report.xml')
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300124 LOG.info("*************** DONE **************")
125
Tatyana Leontovichc411ec32017-10-09 14:48:00 +0300126 @pytest.mark.grab_versions
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300127 @pytest.mark.fail_snapshot
128 @pytest.mark.cz8115
Tatyana Leontovich071ce6a2017-10-24 18:08:10 +0300129 def test_k8s_install_contrail_lma(self, config, show_step,
Dmitry Tyzhnenko34595f82018-06-12 19:03:12 +0300130 k8s_deployed,
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300131 stacklight_deployed):
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300132 """Test for deploying MCP with k8s+stacklight+contrail and check it
133
134 Scenario:
135 1. Prepare salt on hosts
136 2. Setup controller nodes
137 3. Setup compute nodes
138 4. Setup stack light nodes
139 5. Setup Kubernetes cluster and check it nodes
140 6. Run LMA2.0 component tests
141 7. Optionally run k8s e2e conformance
142
143 """
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +0400144
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300145 show_step(5)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +0400146 sl_actions = stacklight_deployed
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300147
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300148 prometheus_client = stacklight_deployed.api
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300149 try:
150 current_targets = prometheus_client.get_targets()
151 LOG.debug('Current targets after install {0}'
152 .format(current_targets))
Dennis Dmitriev9b02c8b2017-11-13 15:31:35 +0200153 except Exception:
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300154 LOG.warning('Restarting keepalived service on mon nodes...')
155 sl_actions._salt.local(tgt='mon*', fun='cmd.run',
156 args='systemctl restart keepalived')
157 LOG.warning(
158 'Ip states after forset restart {0}'.format(
159 sl_actions._salt.local(tgt='mon*',
160 fun='cmd.run', args='ip a')))
161 current_targets = prometheus_client.get_targets()
162 LOG.debug('Current targets after install {0}'
163 .format(current_targets))
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300164 mon_nodes = stacklight_deployed.get_monitoring_nodes()
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300165 LOG.debug('Mon nodes list {0}'.format(mon_nodes))
166
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300167 stacklight_deployed.check_prometheus_targets(mon_nodes)
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300168 show_step(6)
169 # Run SL component tests
Dennis Dmitriev66650fc2018-11-02 11:04:37 +0200170 stacklight_deployed.setup_sl_functional_tests(
171 'cfg01',
172 )
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300173 stacklight_deployed.run_sl_functional_tests(
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300174 'cfg01',
175 '/root/stacklight-pytest/stacklight_tests/',
vitalygusev0e57ef62018-11-30 12:13:56 +0400176 'tests',
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300177 'test_alerts.py')
178
179 # Download report
Dennis Dmitrievea48cf52018-07-18 18:04:39 +0300180 stacklight_deployed.download_sl_test_report(
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300181 'cfg01',
182 '/root/stacklight-pytest/stacklight_tests/report.xml')
183
184 if config.k8s.k8s_conformance_run:
185 show_step(7)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +0400186 k8s_deployed.run_conformance()
Tatyana Leontovichb7404592017-04-07 11:52:28 +0300187 LOG.info("*************** DONE **************")
vrovachev0a2f6352017-06-09 12:48:59 +0400188
Victor Ryzhenkine784bbf2018-12-21 03:58:00 +0400189 @pytest.mark.prepare_log(filepath='/tmp/conformance/conformance.log')
190 @pytest.mark.merge_xunit(path='/tmp/conformance',
Victor Ryzhenkincf26c932018-03-29 20:08:21 +0400191 output='/root/conformance_result.xml')
Victor Ryzhenkine784bbf2018-12-21 03:58:00 +0400192 @pytest.mark.download(name=['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 Leontovichae47eb42019-01-08 12:40:15 +0200196 @pytest.mark.k8s_calico_only_k8s
Victor Ryzhenkincf26c932018-03-29 20:08:21 +0400197 def test_only_k8s_install(self, config, show_step,
Victor Ryzhenkine784bbf2018-12-21 03:58:00 +0400198 k8s_deployed, conformance_helper):
Artem Panchenko0594cd72017-06-12 13:25:26 +0300199 """Test for deploying MCP environment with k8s and check it
vrovachev0a2f6352017-06-09 12:48:59 +0400200
201 Scenario:
202 1. Prepare salt on hosts
203 2. Setup controller nodes
204 3. Setup compute nodes
Artem Panchenko0594cd72017-06-12 13:25:26 +0300205 4. Setup Kubernetes cluster
vrovacheva9d08332017-06-22 20:01:59 +0400206 5. Run conformance if need
vrovachev0a2f6352017-06-09 12:48:59 +0400207
208 """
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +0400209
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)
Victor Ryzhenkine784bbf2018-12-21 03:58:00 +0400212 k8s_deployed.start_conformance_inside_pod()
Dina Belova9e9141d2017-09-19 14:16:34 -0700213 LOG.info("*************** DONE **************")