blob: 018f561b9ea57f0a6f5d36c485bddf91cd5e4627 [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
Tatyana Leontovich071ce6a2017-10-24 18:08:10 +030030 def test_k8s_install_calico_lma(self, config, show_step,
31 k8s_deployed, k8s_actions,
32 sl_deployed, sl_actions):
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +030033 """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))
Dennis Dmitriev9b02c8b2017-11-13 15:31:35 +020092 except Exception:
Tatyana Leontovichb57ec132017-07-27 17:16:42 +030093 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')
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,
130 k8s_deployed, k8s_actions,
131 sl_deployed, sl_actions):
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 """
144 # STEP #5
145 show_step(5)
146 k8sclient = k8s_deployed.api
147 assert k8sclient.nodes.list() is not None, "Can not get nodes list"
148
149 prometheus_client = sl_deployed.api
150 try:
151 current_targets = prometheus_client.get_targets()
152 LOG.debug('Current targets after install {0}'
153 .format(current_targets))
Dennis Dmitriev9b02c8b2017-11-13 15:31:35 +0200154 except Exception:
Tatyana Leontovich9bd9c102017-09-28 12:49:38 +0300155 LOG.warning('Restarting keepalived service on mon nodes...')
156 sl_actions._salt.local(tgt='mon*', fun='cmd.run',
157 args='systemctl restart keepalived')
158 LOG.warning(
159 'Ip states after forset restart {0}'.format(
160 sl_actions._salt.local(tgt='mon*',
161 fun='cmd.run', args='ip a')))
162 current_targets = prometheus_client.get_targets()
163 LOG.debug('Current targets after install {0}'
164 .format(current_targets))
165 mon_nodes = sl_deployed.get_monitoring_nodes()
166 LOG.debug('Mon nodes list {0}'.format(mon_nodes))
167
168 sl_deployed.check_prometheus_targets(mon_nodes)
169 show_step(6)
170 # Run SL component tests
171 sl_deployed.run_sl_functional_tests(
172 'cfg01',
173 '/root/stacklight-pytest/stacklight_tests/',
174 'tests/prometheus',
175 'test_alerts.py')
176
177 # Download report
178 sl_deployed.download_sl_test_report(
179 'cfg01',
180 '/root/stacklight-pytest/stacklight_tests/report.xml')
181
182 if config.k8s.k8s_conformance_run:
183 show_step(7)
vrovacheva9d08332017-06-22 20:01:59 +0400184 k8s_actions.run_conformance()
Tatyana Leontovichb7404592017-04-07 11:52:28 +0300185 LOG.info("*************** DONE **************")
vrovachev0a2f6352017-06-09 12:48:59 +0400186
Tatyana Leontovichc411ec32017-10-09 14:48:00 +0300187 @pytest.mark.grab_versions
Artem Panchenko0594cd72017-06-12 13:25:26 +0300188 @pytest.mark.fail_snapshot
Tatyana Leontovich071ce6a2017-10-24 18:08:10 +0300189 @pytest.mark.cz8116
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 **************")