blob: 71094973201df5e35eb62a1bfe83a8c1de17a49a [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
30 def test_k8s_install_calico(self, config, show_step,
31 k8s_deployed, k8s_actions,
32 sl_deployed, sl_actions):
33 """Test for deploying MCP with k8s+stacklight_calico and check it
Tatyana Leontovichb7404592017-04-07 11:52:28 +030034
35 Scenario:
36 1. Prepare salt on hosts
37 2. Setup controller nodes
38 3. Setup compute nodes
Tatyana Leontovich5acc82a2017-05-23 15:41:35 +030039 4. Setup stack light nodes
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030040 5. Setup Kubernetes cluster and check it nodes
41 6. Check netchecker server is running
42 7. Check netchecker agent is running
43 8. Check connectivity
44 9. Get metrics from netchecker
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +030045 10. Run LMA component tests
46 11. Optionally run k8s e2e tests
Tatyana Leontovichb7404592017-04-07 11:52:28 +030047
48 """
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030049 # STEP #5
50 show_step(5)
51 k8sclient = k8s_deployed.api
52 assert k8sclient.nodes.list() is not None, "Can not get nodes list"
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030053 netchecker_port = netchecker.get_service_port(k8sclient)
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030054 show_step(6)
55 netchecker.get_netchecker_pod_status(k8s=k8s_deployed,
56 namespace='netchecker')
57
58 show_step(7)
59 netchecker.get_netchecker_pod_status(k8s=k8s_deployed,
60 pod_name='netchecker-agent',
61 namespace='netchecker')
62
63 # show_step(8)
64 netchecker.wait_check_network(k8sclient, namespace='netchecker',
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030065 netchecker_pod_port=netchecker_port)
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030066 show_step(9)
Dina Belovae6fdffb2017-09-19 13:58:34 -070067 res = netchecker.get_metric(k8sclient,
68 netchecker_pod_port=netchecker_port,
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030069 namespace='netchecker')
70
Dina Belovae6fdffb2017-09-19 13:58:34 -070071 assert res.status_code == 200, 'Unexpected response code {}'\
72 .format(res)
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030073 metrics = ['ncagent_error_count_total', 'ncagent_http_probe_code',
74 'ncagent_http_probe_connect_time_ms',
75 'ncagent_http_probe_connection_result',
76 'ncagent_http_probe_content_transfer_time_ms',
77 'ncagent_http_probe_dns_lookup_time_ms',
78 'ncagent_http_probe_server_processing_time_ms',
79 'ncagent_http_probe_tcp_connection_time_ms',
80 'ncagent_http_probe_total_time_ms',
81 'ncagent_report_count_tota']
82 for metric in metrics:
83 assert metric in res.text.strip(), \
84 'Mandotory metric {0} is missing in {1}'.format(
85 metric, res.text)
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030086
87 prometheus_client = sl_deployed.api
Tatyana Leontovichb57ec132017-07-27 17:16:42 +030088 try:
89 current_targets = prometheus_client.get_targets()
Dina Belovae6fdffb2017-09-19 13:58:34 -070090 LOG.debug('Current targets after install {0}'
91 .format(current_targets))
Tatyana Leontovichb57ec132017-07-27 17:16:42 +030092 except:
93 LOG.warning('Restarting keepalived service on mon nodes...')
94 sl_actions._salt.local(tgt='mon*', fun='cmd.run',
95 args='systemctl restart keepalived')
96 LOG.warning(
97 'Ip states after forset restart {0}'.format(
98 sl_actions._salt.local(tgt='mon*',
99 fun='cmd.run', args='ip a')))
100 current_targets = prometheus_client.get_targets()
Dina Belovae6fdffb2017-09-19 13:58:34 -0700101 LOG.debug('Current targets after install {0}'
102 .format(current_targets))
Tatyana Leontovich09b7b012017-07-10 12:53:45 +0300103
Dina Belovae6fdffb2017-09-19 13:58:34 -0700104 # todo (tleontovich) add assertion that k8s targets here
Tatyana Leontovich09b7b012017-07-10 12:53:45 +0300105 for metric in metrics:
106 res = prometheus_client.get_query(metric)
107 for entry in res:
108 assert entry["metric"]["job"] == 'kubernetes-service-endpoints'
109 LOG.debug('Metric {} exists'.format(res))
Dina Belovae6fdffb2017-09-19 13:58:34 -0700110 # todo (tleontovich) add asserts here and extend the tests
111 # with acceptance criteria
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300112 show_step(10)
113 # Run SL component tests
114 sl_deployed.run_sl_functional_tests(
115 'cfg01',
116 '/root/stacklight-pytest/stacklight_tests/',
117 'tests/prometheus',
118 'test_alerts.py')
119
120 # Download report
121 sl_deployed.download_sl_test_report(
122 'cfg01',
123 '/root/stacklight-pytest/stacklight_tests/report.xml')
Dina Belova9e9141d2017-09-19 14:16:34 -0700124
Tatyana Leontovich1c568f92017-07-03 15:16:27 +0300125 if config.k8s.k8s_conformance_run:
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300126 show_step(11)
127 k8s_actions.run_conformance()
128 LOG.info("*************** DONE **************")
129
Tatyana Leontovichc411ec32017-10-09 14:48:00 +0300130 @pytest.mark.grab_versions
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300131 @pytest.mark.fail_snapshot
132 @pytest.mark.cz8115
133 def test_k8s_install_contrail(self, config, show_step,
134 k8s_deployed, k8s_actions,
135 sl_deployed, sl_actions):
136 """Test for deploying MCP with k8s+stacklight+contrail and check it
137
138 Scenario:
139 1. Prepare salt on hosts
140 2. Setup controller nodes
141 3. Setup compute nodes
142 4. Setup stack light nodes
143 5. Setup Kubernetes cluster and check it nodes
144 6. Run LMA2.0 component tests
145 7. Optionally run k8s e2e conformance
146
147 """
148 # STEP #5
149 show_step(5)
150 k8sclient = k8s_deployed.api
151 assert k8sclient.nodes.list() is not None, "Can not get nodes list"
152
153 prometheus_client = sl_deployed.api
154 try:
155 current_targets = prometheus_client.get_targets()
156 LOG.debug('Current targets after install {0}'
157 .format(current_targets))
158 except:
159 LOG.warning('Restarting keepalived service on mon nodes...')
160 sl_actions._salt.local(tgt='mon*', fun='cmd.run',
161 args='systemctl restart keepalived')
162 LOG.warning(
163 'Ip states after forset restart {0}'.format(
164 sl_actions._salt.local(tgt='mon*',
165 fun='cmd.run', args='ip a')))
166 current_targets = prometheus_client.get_targets()
167 LOG.debug('Current targets after install {0}'
168 .format(current_targets))
169 mon_nodes = sl_deployed.get_monitoring_nodes()
170 LOG.debug('Mon nodes list {0}'.format(mon_nodes))
171
172 sl_deployed.check_prometheus_targets(mon_nodes)
173 show_step(6)
174 # Run SL component tests
175 sl_deployed.run_sl_functional_tests(
176 'cfg01',
177 '/root/stacklight-pytest/stacklight_tests/',
178 'tests/prometheus',
179 'test_alerts.py')
180
181 # Download report
182 sl_deployed.download_sl_test_report(
183 'cfg01',
184 '/root/stacklight-pytest/stacklight_tests/report.xml')
185
186 if config.k8s.k8s_conformance_run:
187 show_step(7)
vrovacheva9d08332017-06-22 20:01:59 +0400188 k8s_actions.run_conformance()
Tatyana Leontovichb7404592017-04-07 11:52:28 +0300189 LOG.info("*************** DONE **************")
vrovachev0a2f6352017-06-09 12:48:59 +0400190
Tatyana Leontovichc411ec32017-10-09 14:48:00 +0300191 @pytest.mark.grab_versions
Artem Panchenko0594cd72017-06-12 13:25:26 +0300192 @pytest.mark.fail_snapshot
vrovacheva9d08332017-06-22 20:01:59 +0400193 def test_only_k8s_install(self, config, k8s_deployed, k8s_actions):
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 """
Tatyana Leontovich1c568f92017-07-03 15:16:27 +0300204 if config.k8s.k8s_conformance_run:
vrovacheva9d08332017-06-22 20:01:59 +0400205 k8s_actions.run_conformance()
Dina Belova9e9141d2017-09-19 14:16:34 -0700206 LOG.info("*************** DONE **************")