blob: 0af33e336075550d19050ae410d88cf55cb6fdca [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,
29 k8s_deployed, k8s_actions, sl_deployed):
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)
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030062 res = netchecker.get_metric(k8sclient, netchecker_pod_port=netchecker_port,
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030063 namespace='netchecker')
64
65 assert res.status_code == 200, 'Unexpected response code {}'.format(res)
66 metrics = ['ncagent_error_count_total', 'ncagent_http_probe_code',
67 'ncagent_http_probe_connect_time_ms',
68 'ncagent_http_probe_connection_result',
69 'ncagent_http_probe_content_transfer_time_ms',
70 'ncagent_http_probe_dns_lookup_time_ms',
71 'ncagent_http_probe_server_processing_time_ms',
72 'ncagent_http_probe_tcp_connection_time_ms',
73 'ncagent_http_probe_total_time_ms',
74 'ncagent_report_count_tota']
75 for metric in metrics:
76 assert metric in res.text.strip(), \
77 'Mandotory metric {0} is missing in {1}'.format(
78 metric, res.text)
Tatyana Leontovich09b7b012017-07-10 12:53:45 +030079
80 prometheus_client = sl_deployed.api
81 current_targets = prometheus_client.get_targets()
82 #todo (tleontovich) add assertion that k8s targets here
83 LOG.debug('Current targets after install {0}'.format(current_targets))
84
85 for metric in metrics:
86 res = prometheus_client.get_query(metric)
87 for entry in res:
88 assert entry["metric"]["job"] == 'kubernetes-service-endpoints'
89 LOG.debug('Metric {} exists'.format(res))
90 # todo (tleontovich) add asserts here and extend the tests with acceptance criteria
Tatyana Leontovichf00b2342017-07-04 18:26:25 +030091
Tatyana Leontovich1c568f92017-07-03 15:16:27 +030092 if config.k8s.k8s_conformance_run:
vrovacheva9d08332017-06-22 20:01:59 +040093 k8s_actions.run_conformance()
Tatyana Leontovichb7404592017-04-07 11:52:28 +030094 LOG.info("*************** DONE **************")
vrovachev0a2f6352017-06-09 12:48:59 +040095
Artem Panchenko0594cd72017-06-12 13:25:26 +030096 @pytest.mark.fail_snapshot
vrovacheva9d08332017-06-22 20:01:59 +040097 def test_only_k8s_install(self, config, k8s_deployed, k8s_actions):
Artem Panchenko0594cd72017-06-12 13:25:26 +030098 """Test for deploying MCP environment with k8s and check it
vrovachev0a2f6352017-06-09 12:48:59 +040099
100 Scenario:
101 1. Prepare salt on hosts
102 2. Setup controller nodes
103 3. Setup compute nodes
Artem Panchenko0594cd72017-06-12 13:25:26 +0300104 4. Setup Kubernetes cluster
vrovacheva9d08332017-06-22 20:01:59 +0400105 5. Run conformance if need
vrovachev0a2f6352017-06-09 12:48:59 +0400106
107 """
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()
vrovachev0a2f6352017-06-09 12:48:59 +0400110 LOG.info("*************** DONE **************")