blob: 83fd33a5e2a3cd9ac860888c212a467c495ae5a5 [file] [log] [blame]
vrovachev99228d32017-06-08 19:46:10 +04001# 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.
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040014import pytest
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040015import os
vrovachev99228d32017-06-08 19:46:10 +040016
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040017from tcp_tests.managers.k8s import read_yaml_file
vrovachev99228d32017-06-08 19:46:10 +040018from tcp_tests import logger
19
20LOG = logger.logger
21
22
23class TestVirtletActions(object):
24 """Test class for testing Virtlet actions"""
25
Victor Ryzhenkin1bdb4aa2018-01-12 17:36:56 +040026 @pytest.mark.grab_versions
27 @pytest.mark.fail_snapshot
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040028 def test_virtlet_create_delete_vm(self, show_step, config, k8s_deployed):
vrovachev99228d32017-06-08 19:46:10 +040029 """Test for deploying an mcp environment with virtlet
30
31 Scenario:
32 1. Start VM as a virtlet pod
33 2. Wait active state of VM
34 3. Delete VM and wait to delete pod
35
36 """
Victor Ryzhenkin42cfc312017-06-13 12:51:39 +040037
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040038 if not config.k8s_deploy.kubernetes_virtlet_enabled:
39 pytest.skip("Test requires Virtlet addon enabled")
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040040 data_dir = os.path.join(os.path.dirname(__file__), 'testdata/k8s')
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040041
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040042 show_step(1)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040043 vm_pod = k8s_deployed.api.pods.create(
44 body=read_yaml_file(data_dir, 'cirros-vm.yaml'))
45
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040046 show_step(2)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040047 vm_pod.wait_running(timeout=600)
48
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040049 show_step(3)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040050 vm_pod.delete()
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040051
Victor Ryzhenkin1bdb4aa2018-01-12 17:36:56 +040052 @pytest.mark.grab_versions
53 @pytest.mark.fail_snapshot
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040054 def test_vm_resource_quotas(self, show_step, config, k8s_deployed):
Victor Ryzhenkin42cfc312017-06-13 12:51:39 +040055 """Test for deploying a VM with specific quotas
56
57 Scenario:
58 1. Prepare VM's yaml
59 2. Start a VM
60 3. Check that VM resources is equal to provided in yaml
61 4. Destroy VM
62
63 """
64
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040065 if not config.k8s_deploy.kubernetes_virtlet_enabled:
66 pytest.skip("Test requires Virtlet addon enabled")
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040067 data_dir = os.path.join(os.path.dirname(__file__), 'testdata/k8s')
68 cpu = 2
69 memory_mb = 512
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040070
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040071 show_step(1)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040072 pod_body = read_yaml_file(data_dir, 'cirros-vm.yaml')
73 pod_body['metadata']['annotations']['VirtletVCPUCount'] = str(cpu)
74 pod_body['spec']['containers'][0]['resources']['limits']['memory'] = \
75 '{}Mi'.format(memory_mb)
76
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040077 show_step(2)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040078 vm_pod = k8s_deployed.api.pods.create(body=pod_body)
79 vm_pod.wait_running(timeout=600)
80
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040081 show_step(3)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040082 stats = k8s_deployed.virtlet.virsh_domstats(vm_pod)
83 assert int(stats['vcpu.current']) == cpu
84 assert int(stats['balloon.maximum'])/1024 == memory_mb
85
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040086 show_step(4)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040087 vm_pod.delete()
Victor Ryzhenkin6609aaf2017-06-21 13:09:56 +040088
Victor Ryzhenkin8ff3c3f2018-01-17 19:37:05 +040089 @pytest.mark.grab_versions
Victor Ryzhenkincf26c932018-03-29 20:08:21 +040090 @pytest.mark.grab_k8s_results(name=['virtlet_conformance.log',
91 'report.xml'])
Victor Ryzhenkin8ff3c3f2018-01-17 19:37:05 +040092 @pytest.mark.fail_snapshot
Victor Ryzhenkin62123da2018-01-25 18:24:34 +040093 def test_virtlet_conformance(self, show_step, config, k8s_deployed,
Victor Ryzhenkincf26c932018-03-29 20:08:21 +040094 k8s_logs):
Victor Ryzhenkin8ff3c3f2018-01-17 19:37:05 +040095 """Test run of virtlet conformance tests
96
97 Scenario:
98 1. Perform virtlet conformance
99
100 """
101
102 show_step(1)
103 k8s_deployed.run_virtlet_conformance()