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 |
| 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 Leontovich | b740459 | 2017-04-07 11:52:28 +0300 | [diff] [blame] | 34 | |
| 35 | Scenario: |
| 36 | 1. Prepare salt on hosts |
| 37 | 2. Setup controller nodes |
| 38 | 3. Setup compute nodes |
Tatyana Leontovich | 5acc82a | 2017-05-23 15:41:35 +0300 | [diff] [blame] | 39 | 4. Setup stack light nodes |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 40 | 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 Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 45 | 10. Run LMA component tests |
| 46 | 11. Optionally run k8s e2e tests |
Tatyana Leontovich | b740459 | 2017-04-07 11:52:28 +0300 | [diff] [blame] | 47 | |
| 48 | """ |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 49 | # 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 Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 53 | netchecker_port = netchecker.get_service_port(k8sclient) |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 54 | 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 Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 65 | netchecker_pod_port=netchecker_port) |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 66 | show_step(9) |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 67 | res = netchecker.get_metric(k8sclient, |
| 68 | netchecker_pod_port=netchecker_port, |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 69 | namespace='netchecker') |
| 70 | |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 71 | assert res.status_code == 200, 'Unexpected response code {}'\ |
| 72 | .format(res) |
Tatyana Leontovich | f00b234 | 2017-07-04 18:26:25 +0300 | [diff] [blame] | 73 | 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 Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 86 | |
| 87 | prometheus_client = sl_deployed.api |
Tatyana Leontovich | b57ec13 | 2017-07-27 17:16:42 +0300 | [diff] [blame] | 88 | try: |
| 89 | current_targets = prometheus_client.get_targets() |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 90 | LOG.debug('Current targets after install {0}' |
| 91 | .format(current_targets)) |
Tatyana Leontovich | b57ec13 | 2017-07-27 17:16:42 +0300 | [diff] [blame] | 92 | 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 Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 101 | LOG.debug('Current targets after install {0}' |
| 102 | .format(current_targets)) |
Tatyana Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 103 | |
Dina Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 104 | # todo (tleontovich) add assertion that k8s targets here |
Tatyana Leontovich | 09b7b01 | 2017-07-10 12:53:45 +0300 | [diff] [blame] | 105 | 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 Belova | e6fdffb | 2017-09-19 13:58:34 -0700 | [diff] [blame] | 110 | # todo (tleontovich) add asserts here and extend the tests |
| 111 | # with acceptance criteria |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 112 | 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 Belova | 9e9141d | 2017-09-19 14:16:34 -0700 | [diff] [blame] | 124 | |
Tatyana Leontovich | 1c568f9 | 2017-07-03 15:16:27 +0300 | [diff] [blame] | 125 | if config.k8s.k8s_conformance_run: |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 126 | show_step(11) |
| 127 | k8s_actions.run_conformance() |
| 128 | LOG.info("*************** DONE **************") |
| 129 | |
Tatyana Leontovich | c411ec3 | 2017-10-09 14:48:00 +0300 | [diff] [blame^] | 130 | @pytest.mark.grab_versions |
Tatyana Leontovich | 9bd9c10 | 2017-09-28 12:49:38 +0300 | [diff] [blame] | 131 | @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) |
vrovachev | a9d0833 | 2017-06-22 20:01:59 +0400 | [diff] [blame] | 188 | k8s_actions.run_conformance() |
Tatyana Leontovich | b740459 | 2017-04-07 11:52:28 +0300 | [diff] [blame] | 189 | LOG.info("*************** DONE **************") |
vrovachev | 0a2f635 | 2017-06-09 12:48:59 +0400 | [diff] [blame] | 190 | |
Tatyana Leontovich | c411ec3 | 2017-10-09 14:48:00 +0300 | [diff] [blame^] | 191 | @pytest.mark.grab_versions |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 192 | @pytest.mark.fail_snapshot |
vrovachev | a9d0833 | 2017-06-22 20:01:59 +0400 | [diff] [blame] | 193 | def test_only_k8s_install(self, config, k8s_deployed, k8s_actions): |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 194 | """Test for deploying MCP environment with k8s and check it |
vrovachev | 0a2f635 | 2017-06-09 12:48:59 +0400 | [diff] [blame] | 195 | |
| 196 | Scenario: |
| 197 | 1. Prepare salt on hosts |
| 198 | 2. Setup controller nodes |
| 199 | 3. Setup compute nodes |
Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 200 | 4. Setup Kubernetes cluster |
vrovachev | a9d0833 | 2017-06-22 20:01:59 +0400 | [diff] [blame] | 201 | 5. Run conformance if need |
vrovachev | 0a2f635 | 2017-06-09 12:48:59 +0400 | [diff] [blame] | 202 | |
| 203 | """ |
Tatyana Leontovich | 1c568f9 | 2017-07-03 15:16:27 +0300 | [diff] [blame] | 204 | if config.k8s.k8s_conformance_run: |
vrovachev | a9d0833 | 2017-06-22 20:01:59 +0400 | [diff] [blame] | 205 | k8s_actions.run_conformance() |
Dina Belova | 9e9141d | 2017-09-19 14:16:34 -0700 | [diff] [blame] | 206 | LOG.info("*************** DONE **************") |