blob: 6c926d8c3e83bd8bf1b2cea0bbc31bfc7aecdf56 [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
Artem Panchenko0594cd72017-06-12 13:25:26 +030027 @pytest.mark.fail_snapshot
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +030028 @pytest.mark.cz8116
29 def test_k8s_install_calico(self, config, show_step,
30 k8s_deployed, k8s_actions,
31 sl_deployed, sl_actions):
32 """Test for deploying MCP with k8s+stacklight_calico and check it
Tatyana Leontovichb7404592017-04-07 11:52:28 +030033
34 Scenario:
35 1. Prepare salt on hosts
36 2. Setup controller nodes
37 3. Setup compute nodes
Tatyana Leontovich5acc82a2017-05-23 15:41:35 +030038 4. Setup stack light nodes
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030039 5. Setup Kubernetes cluster and check it nodes
40 6. Check netchecker server is running
41 7. Check netchecker agent is running
42 8. Check connectivity
43 9. Get metrics from netchecker
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +030044 10. Run LMA component tests
45 11. Optionally run k8s e2e tests
Tatyana Leontovichb7404592017-04-07 11:52:28 +030046
47 """
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030048 # STEP #5
49 show_step(5)
50 k8sclient = k8s_deployed.api
51 assert k8sclient.nodes.list() is not None, "Can not get nodes list"
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030052 netchecker_port = netchecker.get_service_port(k8sclient)
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030053 show_step(6)
54 netchecker.get_netchecker_pod_status(k8s=k8s_deployed,
55 namespace='netchecker')
56
57 show_step(7)
58 netchecker.get_netchecker_pod_status(k8s=k8s_deployed,
59 pod_name='netchecker-agent',
60 namespace='netchecker')
61
62 # show_step(8)
63 netchecker.wait_check_network(k8sclient, namespace='netchecker',
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030064 netchecker_pod_port=netchecker_port)
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030065 show_step(9)
Dina Belovae6fdffb2017-09-19 13:58:34 -070066 res = netchecker.get_metric(k8sclient,
67 netchecker_pod_port=netchecker_port,
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030068 namespace='netchecker')
69
Dina Belovae6fdffb2017-09-19 13:58:34 -070070 assert res.status_code == 200, 'Unexpected response code {}'\
71 .format(res)
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030072 metrics = ['ncagent_error_count_total', 'ncagent_http_probe_code',
73 'ncagent_http_probe_connect_time_ms',
74 'ncagent_http_probe_connection_result',
75 'ncagent_http_probe_content_transfer_time_ms',
76 'ncagent_http_probe_dns_lookup_time_ms',
77 'ncagent_http_probe_server_processing_time_ms',
78 'ncagent_http_probe_tcp_connection_time_ms',
79 'ncagent_http_probe_total_time_ms',
80 'ncagent_report_count_tota']
81 for metric in metrics:
82 assert metric in res.text.strip(), \
83 'Mandotory metric {0} is missing in {1}'.format(
84 metric, res.text)
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030085
86 prometheus_client = sl_deployed.api
Tatyana Leontovichb57ec132017-07-27 17:16:42 +030087 try:
88 current_targets = prometheus_client.get_targets()
Dina Belovae6fdffb2017-09-19 13:58:34 -070089 LOG.debug('Current targets after install {0}'
90 .format(current_targets))
Tatyana Leontovichb57ec132017-07-27 17:16:42 +030091 except:
92 LOG.warning('Restarting keepalived service on mon nodes...')
93 sl_actions._salt.local(tgt='mon*', fun='cmd.run',
94 args='systemctl restart keepalived')
95 LOG.warning(
96 'Ip states after forset restart {0}'.format(
97 sl_actions._salt.local(tgt='mon*',
98 fun='cmd.run', args='ip a')))
99 current_targets = prometheus_client.get_targets()
Dina Belovae6fdffb2017-09-19 13:58:34 -0700100 LOG.debug('Current targets after install {0}'
101 .format(current_targets))
Tatyana Leontovich09b7b012017-07-10 12:53:45 +0300102
Dina Belovae6fdffb2017-09-19 13:58:34 -0700103 # todo (tleontovich) add assertion that k8s targets here
Tatyana Leontovich09b7b012017-07-10 12:53:45 +0300104 for metric in metrics:
105 res = prometheus_client.get_query(metric)
106 for entry in res:
107 assert entry["metric"]["job"] == 'kubernetes-service-endpoints'
108 LOG.debug('Metric {} exists'.format(res))
Dina Belovae6fdffb2017-09-19 13:58:34 -0700109 # todo (tleontovich) add asserts here and extend the tests
110 # with acceptance criteria
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300111 show_step(10)
112 # Run SL component tests
113 sl_deployed.run_sl_functional_tests(
114 'cfg01',
115 '/root/stacklight-pytest/stacklight_tests/',
116 'tests/prometheus',
117 'test_alerts.py')
118
119 # Download report
120 sl_deployed.download_sl_test_report(
121 'cfg01',
122 '/root/stacklight-pytest/stacklight_tests/report.xml')
Dina Belova9e9141d2017-09-19 14:16:34 -0700123
Tatyana Leontovich1c568f92017-07-03 15:16:27 +0300124 if config.k8s.k8s_conformance_run:
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300125 show_step(11)
126 k8s_actions.run_conformance()
127 LOG.info("*************** DONE **************")
128
129 @pytest.mark.fail_snapshot
130 @pytest.mark.cz8115
131 def test_k8s_install_contrail(self, config, show_step,
132 k8s_deployed, k8s_actions,
133 sl_deployed, sl_actions):
134 """Test for deploying MCP with k8s+stacklight+contrail and check it
135
136 Scenario:
137 1. Prepare salt on hosts
138 2. Setup controller nodes
139 3. Setup compute nodes
140 4. Setup stack light nodes
141 5. Setup Kubernetes cluster and check it nodes
142 6. Run LMA2.0 component tests
143 7. Optionally run k8s e2e conformance
144
145 """
146 # STEP #5
147 show_step(5)
148 k8sclient = k8s_deployed.api
149 assert k8sclient.nodes.list() is not None, "Can not get nodes list"
150
151 prometheus_client = sl_deployed.api
152 try:
153 current_targets = prometheus_client.get_targets()
154 LOG.debug('Current targets after install {0}'
155 .format(current_targets))
156 except:
157 LOG.warning('Restarting keepalived service on mon nodes...')
158 sl_actions._salt.local(tgt='mon*', fun='cmd.run',
159 args='systemctl restart keepalived')
160 LOG.warning(
161 'Ip states after forset restart {0}'.format(
162 sl_actions._salt.local(tgt='mon*',
163 fun='cmd.run', args='ip a')))
164 current_targets = prometheus_client.get_targets()
165 LOG.debug('Current targets after install {0}'
166 .format(current_targets))
167 mon_nodes = sl_deployed.get_monitoring_nodes()
168 LOG.debug('Mon nodes list {0}'.format(mon_nodes))
169
170 sl_deployed.check_prometheus_targets(mon_nodes)
171 show_step(6)
172 # Run SL component tests
173 sl_deployed.run_sl_functional_tests(
174 'cfg01',
175 '/root/stacklight-pytest/stacklight_tests/',
176 'tests/prometheus',
177 'test_alerts.py')
178
179 # Download report
180 sl_deployed.download_sl_test_report(
181 'cfg01',
182 '/root/stacklight-pytest/stacklight_tests/report.xml')
183
184 if config.k8s.k8s_conformance_run:
185 show_step(7)
vrovacheva9d08332017-06-22 20:01:59 +0400186 k8s_actions.run_conformance()
Tatyana Leontovichb7404592017-04-07 11:52:28 +0300187 LOG.info("*************** DONE **************")
vrovachev0a2f6352017-06-09 12:48:59 +0400188
Artem Panchenko0594cd72017-06-12 13:25:26 +0300189 @pytest.mark.fail_snapshot
vrovacheva9d08332017-06-22 20:01:59 +0400190 def test_only_k8s_install(self, config, k8s_deployed, k8s_actions):
Artem Panchenko0594cd72017-06-12 13:25:26 +0300191 """Test for deploying MCP environment with k8s and check it
vrovachev0a2f6352017-06-09 12:48:59 +0400192
193 Scenario:
194 1. Prepare salt on hosts
195 2. Setup controller nodes
196 3. Setup compute nodes
Artem Panchenko0594cd72017-06-12 13:25:26 +0300197 4. Setup Kubernetes cluster
vrovacheva9d08332017-06-22 20:01:59 +0400198 5. Run conformance if need
vrovachev0a2f6352017-06-09 12:48:59 +0400199
200 """
Tatyana Leontovich1c568f92017-07-03 15:16:27 +0300201 if config.k8s.k8s_conformance_run:
vrovacheva9d08332017-06-22 20:01:59 +0400202 k8s_actions.run_conformance()
Dina Belova9e9141d2017-09-19 14:16:34 -0700203 LOG.info("*************** DONE **************")