blob: fff3100c8fdce609b61d9e5b190d0c37197ecad1 [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
Artem Panchenko0594cd72017-06-12 13:25:26 +030027 @pytest.mark.fail_snapshot
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030028 def test_k8s_install(self, config, show_step,
Tatyana Leontovichb57ec132017-07-27 17:16:42 +030029 k8s_deployed, k8s_actions, sl_deployed, sl_actions):
Artem Panchenko0594cd72017-06-12 13:25:26 +030030 """Test for deploying MCP environment with k8s+stacklight and check it
Tatyana Leontovichb7404592017-04-07 11:52:28 +030031
32 Scenario:
33 1. Prepare salt on hosts
34 2. Setup controller nodes
35 3. Setup compute nodes
Tatyana Leontovich5acc82a2017-05-23 15:41:35 +030036 4. Setup stack light nodes
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030037 5. Setup Kubernetes cluster and check it nodes
38 6. Check netchecker server is running
39 7. Check netchecker agent is running
40 8. Check connectivity
41 9. Get metrics from netchecker
Tatyana Leontovichb7404592017-04-07 11:52:28 +030042
43 """
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030044 # STEP #5
45 show_step(5)
46 k8sclient = k8s_deployed.api
47 assert k8sclient.nodes.list() is not None, "Can not get nodes list"
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030048 netchecker_port = netchecker.get_service_port(k8sclient)
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030049 show_step(6)
50 netchecker.get_netchecker_pod_status(k8s=k8s_deployed,
51 namespace='netchecker')
52
53 show_step(7)
54 netchecker.get_netchecker_pod_status(k8s=k8s_deployed,
55 pod_name='netchecker-agent',
56 namespace='netchecker')
57
58 # show_step(8)
59 netchecker.wait_check_network(k8sclient, namespace='netchecker',
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030060 netchecker_pod_port=netchecker_port)
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030061 show_step(9)
Dina Belovae6fdffb2017-09-19 13:58:34 -070062 res = netchecker.get_metric(k8sclient,
63 netchecker_pod_port=netchecker_port,
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030064 namespace='netchecker')
65
Dina Belovae6fdffb2017-09-19 13:58:34 -070066 assert res.status_code == 200, 'Unexpected response code {}'\
67 .format(res)
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030068 metrics = ['ncagent_error_count_total', 'ncagent_http_probe_code',
69 'ncagent_http_probe_connect_time_ms',
70 'ncagent_http_probe_connection_result',
71 'ncagent_http_probe_content_transfer_time_ms',
72 'ncagent_http_probe_dns_lookup_time_ms',
73 'ncagent_http_probe_server_processing_time_ms',
74 'ncagent_http_probe_tcp_connection_time_ms',
75 'ncagent_http_probe_total_time_ms',
76 'ncagent_report_count_tota']
77 for metric in metrics:
78 assert metric in res.text.strip(), \
79 'Mandotory metric {0} is missing in {1}'.format(
80 metric, res.text)
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030081
82 prometheus_client = sl_deployed.api
Tatyana Leontovichb57ec132017-07-27 17:16:42 +030083 try:
84 current_targets = prometheus_client.get_targets()
Dina Belovae6fdffb2017-09-19 13:58:34 -070085 LOG.debug('Current targets after install {0}'
86 .format(current_targets))
Tatyana Leontovichb57ec132017-07-27 17:16:42 +030087 except:
88 LOG.warning('Restarting keepalived service on mon nodes...')
89 sl_actions._salt.local(tgt='mon*', fun='cmd.run',
90 args='systemctl restart keepalived')
91 LOG.warning(
92 'Ip states after forset restart {0}'.format(
93 sl_actions._salt.local(tgt='mon*',
94 fun='cmd.run', args='ip a')))
95 current_targets = prometheus_client.get_targets()
Dina Belovae6fdffb2017-09-19 13:58:34 -070096 LOG.debug('Current targets after install {0}'
97 .format(current_targets))
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030098
Dina Belovae6fdffb2017-09-19 13:58:34 -070099 # todo (tleontovich) add assertion that k8s targets here
Tatyana Leontovich09b7b012017-07-10 12:53:45 +0300100 for metric in metrics:
101 res = prometheus_client.get_query(metric)
102 for entry in res:
103 assert entry["metric"]["job"] == 'kubernetes-service-endpoints'
104 LOG.debug('Metric {} exists'.format(res))
Dina Belovae6fdffb2017-09-19 13:58:34 -0700105 # todo (tleontovich) add asserts here and extend the tests
106 # with acceptance criteria
Dina Belova9e9141d2017-09-19 14:16:34 -0700107
Tatyana Leontovich1c568f92017-07-03 15:16:27 +0300108 if config.k8s.k8s_conformance_run:
vrovacheva9d08332017-06-22 20:01:59 +0400109 k8s_actions.run_conformance()
Tatyana Leontovichb7404592017-04-07 11:52:28 +0300110 LOG.info("*************** DONE **************")
vrovachev0a2f6352017-06-09 12:48:59 +0400111
Artem Panchenko0594cd72017-06-12 13:25:26 +0300112 @pytest.mark.fail_snapshot
vrovacheva9d08332017-06-22 20:01:59 +0400113 def test_only_k8s_install(self, config, k8s_deployed, k8s_actions):
Artem Panchenko0594cd72017-06-12 13:25:26 +0300114 """Test for deploying MCP environment with k8s and check it
vrovachev0a2f6352017-06-09 12:48:59 +0400115
116 Scenario:
117 1. Prepare salt on hosts
118 2. Setup controller nodes
119 3. Setup compute nodes
Artem Panchenko0594cd72017-06-12 13:25:26 +0300120 4. Setup Kubernetes cluster
vrovacheva9d08332017-06-22 20:01:59 +0400121 5. Run conformance if need
vrovachev0a2f6352017-06-09 12:48:59 +0400122
123 """
Tatyana Leontovich1c568f92017-07-03 15:16:27 +0300124 if config.k8s.k8s_conformance_run:
vrovacheva9d08332017-06-22 20:01:59 +0400125 k8s_actions.run_conformance()
Dina Belova9e9141d2017-09-19 14:16:34 -0700126 LOG.info("*************** DONE **************")