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, |
| 33 | sl_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 | """ |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 50 | # STEP #5 |
Dmitry Tyzhnenko | 34595f8 | 2018-06-12 19:03:12 +0300 | [diff] [blame^] | 51 | # k8s_actions = k8s_deployed |
| 52 | sl_actions = sl_deployed |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 53 | show_step(5) |
| 54 | k8sclient = k8s_deployed.api |
| 55 | assert k8sclient.nodes.list() is not None, "Can not get nodes list" |
Tatyana Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 56 | netchecker_port = netchecker.get_service_port(k8sclient) |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 57 | show_step(6) |
| 58 | netchecker.get_netchecker_pod_status(k8s=k8s_deployed, |
| 59 | namespace='netchecker') |
| 60 | |
| 61 | show_step(7) |
| 62 | netchecker.get_netchecker_pod_status(k8s=k8s_deployed, |
| 63 | pod_name='netchecker-agent', |
| 64 | namespace='netchecker') |
| 65 | |
| 66 | # show_step(8) |
| 67 | netchecker.wait_check_network(k8sclient, namespace='netchecker', |
Tatyana Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 68 | netchecker_pod_port=netchecker_port) |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 69 | show_step(9) |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 70 | res = netchecker.get_metric(k8sclient, |
| 71 | netchecker_pod_port=netchecker_port, |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 72 | namespace='netchecker') |
| 73 | |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 74 | assert res.status_code == 200, 'Unexpected response code {}'\ |
| 75 | .format(res) |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 76 | metrics = ['ncagent_error_count_total', 'ncagent_http_probe_code', |
| 77 | 'ncagent_http_probe_connect_time_ms', |
| 78 | 'ncagent_http_probe_connection_result', |
| 79 | 'ncagent_http_probe_content_transfer_time_ms', |
| 80 | 'ncagent_http_probe_dns_lookup_time_ms', |
| 81 | 'ncagent_http_probe_server_processing_time_ms', |
| 82 | 'ncagent_http_probe_tcp_connection_time_ms', |
| 83 | 'ncagent_http_probe_total_time_ms', |
| 84 | 'ncagent_report_count_tota'] |
| 85 | for metric in metrics: |
| 86 | assert metric in res.text.strip(), \ |
| 87 | 'Mandotory metric {0} is missing in {1}'.format( |
| 88 | metric, res.text) |
Tatyana Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 89 | |
| 90 | prometheus_client = sl_deployed.api |
Tatyana Leontovich | b57ec13 | 2017-07-27 17:16:42 +0300 | [diff] [blame] | 91 | try: |
| 92 | current_targets = prometheus_client.get_targets() |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 93 | LOG.debug('Current targets after install {0}' |
| 94 | .format(current_targets)) |
Dennis Dmitriev | 9b02c8b | 2017-11-13 15:31:35 +0200 | [diff] [blame] | 95 | except Exception: |
Tatyana Leontovich | b57ec13 | 2017-07-27 17:16:42 +0300 | [diff] [blame] | 96 | LOG.warning('Restarting keepalived service on mon nodes...') |
| 97 | sl_actions._salt.local(tgt='mon*', fun='cmd.run', |
| 98 | args='systemctl restart keepalived') |
| 99 | LOG.warning( |
| 100 | 'Ip states after forset restart {0}'.format( |
| 101 | sl_actions._salt.local(tgt='mon*', |
| 102 | fun='cmd.run', args='ip a'))) |
| 103 | current_targets = prometheus_client.get_targets() |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 104 | LOG.debug('Current targets after install {0}' |
| 105 | .format(current_targets)) |
Tatyana Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 106 | |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 107 | # todo (tleontovich) add assertion that k8s targets here |
Tatyana Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 108 | for metric in metrics: |
| 109 | res = prometheus_client.get_query(metric) |
| 110 | for entry in res: |
| 111 | assert entry["metric"]["job"] == 'kubernetes-service-endpoints' |
| 112 | LOG.debug('Metric {} exists'.format(res)) |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 113 | # todo (tleontovich) add asserts here and extend the tests |
| 114 | # with acceptance criteria |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 115 | show_step(10) |
| 116 | # Run SL component tests |
| 117 | sl_deployed.run_sl_functional_tests( |
| 118 | 'cfg01', |
| 119 | '/root/stacklight-pytest/stacklight_tests/', |
| 120 | 'tests/prometheus', |
| 121 | 'test_alerts.py') |
| 122 | |
| 123 | # Download report |
| 124 | sl_deployed.download_sl_test_report( |
| 125 | 'cfg01', |
| 126 | '/root/stacklight-pytest/stacklight_tests/report.xml') |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 127 | LOG.info("*************** DONE **************") |
| 128 | |
Tatyana Leontovich | c411ec3 | 2017-10-09 14:48:00 +0300 | [diff] [blame] | 129 | @pytest.mark.grab_versions |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 130 | @pytest.mark.fail_snapshot |
| 131 | @pytest.mark.cz8115 |
Tatyana Leontovich | 071ce6a | 2017-10-24 18:08:10 +0300 | [diff] [blame] | 132 | def test_k8s_install_contrail_lma(self, config, show_step, |
Dmitry Tyzhnenko | 34595f8 | 2018-06-12 19:03:12 +0300 | [diff] [blame^] | 133 | k8s_deployed, |
| 134 | sl_deployed): |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 135 | """Test for deploying MCP with k8s+stacklight+contrail and check it |
| 136 | |
| 137 | Scenario: |
| 138 | 1. Prepare salt on hosts |
| 139 | 2. Setup controller nodes |
| 140 | 3. Setup compute nodes |
| 141 | 4. Setup stack light nodes |
| 142 | 5. Setup Kubernetes cluster and check it nodes |
| 143 | 6. Run LMA2.0 component tests |
| 144 | 7. Optionally run k8s e2e conformance |
| 145 | |
| 146 | """ |
Dmitry Tyzhnenko | 34595f8 | 2018-06-12 19:03:12 +0300 | [diff] [blame^] | 147 | k8s_actions = k8s_deployed |
| 148 | sl_actions = sl_deployed |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 149 | # STEP #5 |
| 150 | show_step(5) |
| 151 | k8sclient = k8s_deployed.api |
| 152 | assert k8sclient.nodes.list() is not None, "Can not get nodes list" |
| 153 | |
| 154 | prometheus_client = sl_deployed.api |
| 155 | try: |
| 156 | current_targets = prometheus_client.get_targets() |
| 157 | LOG.debug('Current targets after install {0}' |
| 158 | .format(current_targets)) |
Dennis Dmitriev | 9b02c8b | 2017-11-13 15:31:35 +0200 | [diff] [blame] | 159 | except Exception: |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 160 | LOG.warning('Restarting keepalived service on mon nodes...') |
| 161 | sl_actions._salt.local(tgt='mon*', fun='cmd.run', |
| 162 | args='systemctl restart keepalived') |
| 163 | LOG.warning( |
| 164 | 'Ip states after forset restart {0}'.format( |
| 165 | sl_actions._salt.local(tgt='mon*', |
| 166 | fun='cmd.run', args='ip a'))) |
| 167 | current_targets = prometheus_client.get_targets() |
| 168 | LOG.debug('Current targets after install {0}' |
| 169 | .format(current_targets)) |
| 170 | mon_nodes = sl_deployed.get_monitoring_nodes() |
| 171 | LOG.debug('Mon nodes list {0}'.format(mon_nodes)) |
| 172 | |
| 173 | sl_deployed.check_prometheus_targets(mon_nodes) |
| 174 | show_step(6) |
| 175 | # Run SL component tests |
| 176 | sl_deployed.run_sl_functional_tests( |
| 177 | 'cfg01', |
| 178 | '/root/stacklight-pytest/stacklight_tests/', |
| 179 | 'tests/prometheus', |
| 180 | 'test_alerts.py') |
| 181 | |
| 182 | # Download report |
| 183 | sl_deployed.download_sl_test_report( |
| 184 | 'cfg01', |
| 185 | '/root/stacklight-pytest/stacklight_tests/report.xml') |
| 186 | |
| 187 | if config.k8s.k8s_conformance_run: |
| 188 | show_step(7) |
vrovachev | a9d0833 | 2017-06-22 20:01:59 +0400 | [diff] [blame] | 189 | k8s_actions.run_conformance() |
Tatyana Leontovich | b740459 | 2017-04-07 11:52:28 +0300 | [diff] [blame] | 190 | LOG.info("*************** DONE **************") |
vrovachev | 0a2f635 | 2017-06-09 12:48:59 +0400 | [diff] [blame] | 191 | |
Victor Ryzhenkin | cf26c93 | 2018-03-29 20:08:21 +0400 | [diff] [blame] | 192 | @pytest.mark.extract(container_system='docker', extract_from='conformance', |
| 193 | files_to_extract=['report']) |
| 194 | @pytest.mark.merge_xunit(path='/root/report', |
| 195 | output='/root/conformance_result.xml') |
| 196 | @pytest.mark.grab_k8s_results(name=['k8s_conformance.log', |
| 197 | 'conformance_result.xml']) |
Tatyana Leontovich | c411ec3 | 2017-10-09 14:48:00 +0300 | [diff] [blame] | 198 | @pytest.mark.grab_versions |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 199 | @pytest.mark.fail_snapshot |
Tatyana Leontovich | 071ce6a | 2017-10-24 18:08:10 +0300 | [diff] [blame] | 200 | @pytest.mark.cz8116 |
Dennis Dmitriev | 0f624a8 | 2018-06-11 12:57:13 +0300 | [diff] [blame] | 201 | @pytest.mark.k8s_calico |
Victor Ryzhenkin | cf26c93 | 2018-03-29 20:08:21 +0400 | [diff] [blame] | 202 | def test_only_k8s_install(self, config, show_step, |
Dmitry Tyzhnenko | 34595f8 | 2018-06-12 19:03:12 +0300 | [diff] [blame^] | 203 | k8s_deployed, k8s_logs): |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 204 | """Test for deploying MCP environment with k8s and check it |
vrovachev | 0a2f635 | 2017-06-09 12:48:59 +0400 | [diff] [blame] | 205 | |
| 206 | Scenario: |
| 207 | 1. Prepare salt on hosts |
| 208 | 2. Setup controller nodes |
| 209 | 3. Setup compute nodes |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 210 | 4. Setup Kubernetes cluster |
vrovachev | a9d0833 | 2017-06-22 20:01:59 +0400 | [diff] [blame] | 211 | 5. Run conformance if need |
vrovachev | 0a2f635 | 2017-06-09 12:48:59 +0400 | [diff] [blame] | 212 | |
| 213 | """ |
Dmitry Tyzhnenko | 34595f8 | 2018-06-12 19:03:12 +0300 | [diff] [blame^] | 214 | k8s_actions = k8s_deployed |
Tatyana Leontovich | 1c568f9 | 2017-07-03 15:16:27 +0300 | [diff] [blame] | 215 | if config.k8s.k8s_conformance_run: |
Victor Ryzhenkin | cf26c93 | 2018-03-29 20:08:21 +0400 | [diff] [blame] | 216 | show_step(5) |
vrovachev | a9d0833 | 2017-06-22 20:01:59 +0400 | [diff] [blame] | 217 | k8s_actions.run_conformance() |
Dina Belova | 9e9141d | 2017-09-19 14:16:34 -0700 | [diff] [blame] | 218 | LOG.info("*************** DONE **************") |