Tatyana Leontovich | b740459 | 2017-04-07 11:52:28 +0300 | [diff] [blame] | 1 | # 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 Leontovich | b740459 | 2017-04-07 11:52:28 +0300 | [diff] [blame] | 14 | |
| 15 | import pytest |
| 16 | |
Tatyana Leontovich | b740459 | 2017-04-07 11:52:28 +0300 | [diff] [blame] | 17 | from tcp_tests import logger |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 18 | from tcp_tests.helpers import netchecker |
Tatyana Leontovich | b740459 | 2017-04-07 11:52:28 +0300 | [diff] [blame] | 19 | |
| 20 | LOG = logger.logger |
| 21 | |
| 22 | |
| 23 | @pytest.mark.deploy |
| 24 | class Testk8sInstall(object): |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 25 | """Test class for testing Kubernetes deploy""" |
Tatyana Leontovich | b740459 | 2017-04-07 11:52:28 +0300 | [diff] [blame] | 26 | |
Tatyana Leontovich | c411ec3 | 2017-10-09 14:48:00 +0300 | [diff] [blame] | 27 | @pytest.mark.grab_versions |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 28 | @pytest.mark.fail_snapshot |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 29 | @pytest.mark.cz8116 |
Dennis Dmitriev | 0f624a8 | 2018-06-11 12:57:13 +0300 | [diff] [blame] | 30 | @pytest.mark.k8s_calico_sl |
Tatyana Leontovich | 071ce6a | 2017-10-24 18:08:10 +0300 | [diff] [blame] | 31 | def test_k8s_install_calico_lma(self, config, show_step, |
Dmitry Tyzhnenko | 34595f8 | 2018-06-12 19:03:12 +0300 | [diff] [blame] | 32 | k8s_deployed, |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 33 | stacklight_deployed): |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 34 | """Test for deploying MCP with k8s+stacklight_calico and check it |
Tatyana Leontovich | b740459 | 2017-04-07 11:52:28 +0300 | [diff] [blame] | 35 | |
| 36 | Scenario: |
| 37 | 1. Prepare salt on hosts |
| 38 | 2. Setup controller nodes |
| 39 | 3. Setup compute nodes |
Tatyana Leontovich | 5acc82a | 2017-05-23 15:41:35 +0300 | [diff] [blame] | 40 | 4. Setup stack light nodes |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 41 | 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 Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 46 | 10. Run LMA component tests |
| 47 | 11. Optionally run k8s e2e tests |
Tatyana Leontovich | b740459 | 2017-04-07 11:52:28 +0300 | [diff] [blame] | 48 | |
| 49 | """ |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 50 | |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 51 | show_step(5) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 52 | sl_actions = stacklight_deployed |
| 53 | nch = netchecker.Netchecker(k8s_deployed.api) |
| 54 | |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 55 | show_step(6) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 56 | nch.wait_netchecker_pods_running(netchecker.NETCHECKER_SERVER_PREFIX) |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 57 | |
| 58 | show_step(7) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 59 | nch.wait_netchecker_pods_running(netchecker.NETCHECKER_AGENT_PREFIX) |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 60 | |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 61 | show_step(8) |
| 62 | nch.wait_check_network(works=True) |
| 63 | |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 64 | show_step(9) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 65 | res = nch.get_metric() |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 66 | |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 67 | assert res.status_code == 200, 'Unexpected response code {}'\ |
| 68 | .format(res) |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 69 | 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 Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 82 | |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 83 | prometheus_client = stacklight_deployed.api |
Tatyana Leontovich | b57ec13 | 2017-07-27 17:16:42 +0300 | [diff] [blame] | 84 | try: |
| 85 | current_targets = prometheus_client.get_targets() |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 86 | LOG.debug('Current targets after install {0}' |
| 87 | .format(current_targets)) |
Dennis Dmitriev | 9b02c8b | 2017-11-13 15:31:35 +0200 | [diff] [blame] | 88 | except Exception: |
Tatyana Leontovich | b57ec13 | 2017-07-27 17:16:42 +0300 | [diff] [blame] | 89 | 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 Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 97 | LOG.debug('Current targets after install {0}' |
| 98 | .format(current_targets)) |
Tatyana Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 99 | |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 100 | # todo (tleontovich) add assertion that k8s targets here |
Tatyana Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 101 | 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 Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 106 | # todo (tleontovich) add asserts here and extend the tests |
| 107 | # with acceptance criteria |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 108 | show_step(10) |
Dennis Dmitriev | 66650fc | 2018-11-02 11:04:37 +0200 | [diff] [blame] | 109 | |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 110 | # Run SL component tests |
Dennis Dmitriev | 66650fc | 2018-11-02 11:04:37 +0200 | [diff] [blame] | 111 | stacklight_deployed.setup_sl_functional_tests( |
| 112 | 'cfg01', |
| 113 | ) |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 114 | stacklight_deployed.run_sl_functional_tests( |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 115 | 'cfg01', |
| 116 | '/root/stacklight-pytest/stacklight_tests/', |
vitalygusev | 0e57ef6 | 2018-11-30 12:13:56 +0400 | [diff] [blame] | 117 | 'tests', |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 118 | 'test_alerts.py') |
| 119 | |
| 120 | # Download report |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 121 | stacklight_deployed.download_sl_test_report( |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 122 | 'cfg01', |
| 123 | '/root/stacklight-pytest/stacklight_tests/report.xml') |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 124 | LOG.info("*************** DONE **************") |
| 125 | |
Tatyana Leontovich | c411ec3 | 2017-10-09 14:48:00 +0300 | [diff] [blame] | 126 | @pytest.mark.grab_versions |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 127 | @pytest.mark.fail_snapshot |
| 128 | @pytest.mark.cz8115 |
Tatyana Leontovich | 071ce6a | 2017-10-24 18:08:10 +0300 | [diff] [blame] | 129 | def test_k8s_install_contrail_lma(self, config, show_step, |
Dmitry Tyzhnenko | 34595f8 | 2018-06-12 19:03:12 +0300 | [diff] [blame] | 130 | k8s_deployed, |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 131 | stacklight_deployed): |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 132 | """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 Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 144 | |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 145 | show_step(5) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 146 | sl_actions = stacklight_deployed |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 147 | |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 148 | prometheus_client = stacklight_deployed.api |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 149 | try: |
| 150 | current_targets = prometheus_client.get_targets() |
| 151 | LOG.debug('Current targets after install {0}' |
| 152 | .format(current_targets)) |
Dennis Dmitriev | 9b02c8b | 2017-11-13 15:31:35 +0200 | [diff] [blame] | 153 | except Exception: |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 154 | 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 Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 164 | mon_nodes = stacklight_deployed.get_monitoring_nodes() |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 165 | LOG.debug('Mon nodes list {0}'.format(mon_nodes)) |
| 166 | |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 167 | stacklight_deployed.check_prometheus_targets(mon_nodes) |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 168 | show_step(6) |
| 169 | # Run SL component tests |
Dennis Dmitriev | 66650fc | 2018-11-02 11:04:37 +0200 | [diff] [blame] | 170 | stacklight_deployed.setup_sl_functional_tests( |
| 171 | 'cfg01', |
| 172 | ) |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 173 | stacklight_deployed.run_sl_functional_tests( |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 174 | 'cfg01', |
| 175 | '/root/stacklight-pytest/stacklight_tests/', |
vitalygusev | 0e57ef6 | 2018-11-30 12:13:56 +0400 | [diff] [blame] | 176 | 'tests', |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 177 | 'test_alerts.py') |
| 178 | |
| 179 | # Download report |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 180 | stacklight_deployed.download_sl_test_report( |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 181 | 'cfg01', |
| 182 | '/root/stacklight-pytest/stacklight_tests/report.xml') |
| 183 | |
| 184 | if config.k8s.k8s_conformance_run: |
| 185 | show_step(7) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 186 | k8s_deployed.run_conformance() |
Tatyana Leontovich | b740459 | 2017-04-07 11:52:28 +0300 | [diff] [blame] | 187 | LOG.info("*************** DONE **************") |
vrovachev | 0a2f635 | 2017-06-09 12:48:59 +0400 | [diff] [blame] | 188 | |
Victor Ryzhenkin | e784bbf | 2018-12-21 03:58:00 +0400 | [diff] [blame^] | 189 | @pytest.mark.prepare_log(filepath='/tmp/conformance/conformance.log') |
| 190 | @pytest.mark.merge_xunit(path='/tmp/conformance', |
Victor Ryzhenkin | cf26c93 | 2018-03-29 20:08:21 +0400 | [diff] [blame] | 191 | output='/root/conformance_result.xml') |
Victor Ryzhenkin | e784bbf | 2018-12-21 03:58:00 +0400 | [diff] [blame^] | 192 | @pytest.mark.download(name=['conformance.log', |
| 193 | 'conformance_result.xml']) |
Tatyana Leontovich | c411ec3 | 2017-10-09 14:48:00 +0300 | [diff] [blame] | 194 | @pytest.mark.grab_versions |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 195 | @pytest.mark.fail_snapshot |
Tatyana Leontovich | 071ce6a | 2017-10-24 18:08:10 +0300 | [diff] [blame] | 196 | @pytest.mark.cz8116 |
Dennis Dmitriev | 0f624a8 | 2018-06-11 12:57:13 +0300 | [diff] [blame] | 197 | @pytest.mark.k8s_calico |
Victor Ryzhenkin | cf26c93 | 2018-03-29 20:08:21 +0400 | [diff] [blame] | 198 | def test_only_k8s_install(self, config, show_step, |
Victor Ryzhenkin | e784bbf | 2018-12-21 03:58:00 +0400 | [diff] [blame^] | 199 | k8s_deployed, conformance_helper): |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 200 | """Test for deploying MCP environment with k8s and check it |
vrovachev | 0a2f635 | 2017-06-09 12:48:59 +0400 | [diff] [blame] | 201 | |
| 202 | Scenario: |
| 203 | 1. Prepare salt on hosts |
| 204 | 2. Setup controller nodes |
| 205 | 3. Setup compute nodes |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 206 | 4. Setup Kubernetes cluster |
vrovachev | a9d0833 | 2017-06-22 20:01:59 +0400 | [diff] [blame] | 207 | 5. Run conformance if need |
vrovachev | 0a2f635 | 2017-06-09 12:48:59 +0400 | [diff] [blame] | 208 | |
| 209 | """ |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 210 | |
Tatyana Leontovich | 1c568f9 | 2017-07-03 15:16:27 +0300 | [diff] [blame] | 211 | if config.k8s.k8s_conformance_run: |
Victor Ryzhenkin | cf26c93 | 2018-03-29 20:08:21 +0400 | [diff] [blame] | 212 | show_step(5) |
Victor Ryzhenkin | e784bbf | 2018-12-21 03:58:00 +0400 | [diff] [blame^] | 213 | k8s_deployed.start_conformance_inside_pod() |
Dina Belova | 9e9141d | 2017-09-19 14:16:34 -0700 | [diff] [blame] | 214 | LOG.info("*************** DONE **************") |