blob: 9b7c366826b153ef988339b3d48632ea6feba4fb [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
Dennis Dmitriev716d7d22018-11-15 18:01:45 +020028 @pytest.mark.k8s_virtlet
Vladimir Jigulineb8b8132019-03-19 15:34:02 +040029 @pytest.mark.k8s_system
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040030 def test_virtlet_create_delete_vm(self, show_step, config, k8s_deployed):
vrovachev99228d32017-06-08 19:46:10 +040031 """Test for deploying an mcp environment with virtlet
32
33 Scenario:
34 1. Start VM as a virtlet pod
35 2. Wait active state of VM
36 3. Delete VM and wait to delete pod
37
38 """
Victor Ryzhenkin42cfc312017-06-13 12:51:39 +040039
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040040 if not config.k8s_deploy.kubernetes_virtlet_enabled:
41 pytest.skip("Test requires Virtlet addon enabled")
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040042 data_dir = os.path.join(os.path.dirname(__file__), 'testdata/k8s')
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040043
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040044 show_step(1)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040045 vm_pod = k8s_deployed.api.pods.create(
46 body=read_yaml_file(data_dir, 'cirros-vm.yaml'))
47
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040048 show_step(2)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040049 vm_pod.wait_running(timeout=600)
50
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040051 show_step(3)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040052 vm_pod.delete()
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040053
Victor Ryzhenkin1bdb4aa2018-01-12 17:36:56 +040054 @pytest.mark.grab_versions
55 @pytest.mark.fail_snapshot
Dennis Dmitriev716d7d22018-11-15 18:01:45 +020056 @pytest.mark.k8s_virtlet
Vladimir Jigulineb8b8132019-03-19 15:34:02 +040057 @pytest.mark.k8s_system
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040058 def test_vm_resource_quotas(self, show_step, config, k8s_deployed):
Victor Ryzhenkin42cfc312017-06-13 12:51:39 +040059 """Test for deploying a VM with specific quotas
60
61 Scenario:
62 1. Prepare VM's yaml
63 2. Start a VM
64 3. Check that VM resources is equal to provided in yaml
65 4. Destroy VM
66
67 """
68
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040069 if not config.k8s_deploy.kubernetes_virtlet_enabled:
70 pytest.skip("Test requires Virtlet addon enabled")
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040071 data_dir = os.path.join(os.path.dirname(__file__), 'testdata/k8s')
72 cpu = 2
73 memory_mb = 512
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040074
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040075 show_step(1)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040076 pod_body = read_yaml_file(data_dir, 'cirros-vm.yaml')
77 pod_body['metadata']['annotations']['VirtletVCPUCount'] = str(cpu)
78 pod_body['spec']['containers'][0]['resources']['limits']['memory'] = \
79 '{}Mi'.format(memory_mb)
80
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040081 show_step(2)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040082 vm_pod = k8s_deployed.api.pods.create(body=pod_body)
83 vm_pod.wait_running(timeout=600)
84
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040085 show_step(3)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040086 stats = k8s_deployed.virtlet.virsh_domstats(vm_pod)
87 assert int(stats['vcpu.current']) == cpu
88 assert int(stats['balloon.maximum'])/1024 == memory_mb
89
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040090 show_step(4)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040091 vm_pod.delete()
Victor Ryzhenkin6609aaf2017-06-21 13:09:56 +040092
Victor Ryzhenkine784bbf2018-12-21 03:58:00 +040093 @pytest.mark.prepare_log(filepath='/tmp/virtlet-conformance/'
94 'virtlet_conformance.log')
95 @pytest.mark.merge_xunit(path='/tmp/virtlet-conformance',
96 output='/root/report.xml')
97 @pytest.mark.download(name=['virtlet_conformance.log',
98 'report.xml'])
Victor Ryzhenkin8ff3c3f2018-01-17 19:37:05 +040099 @pytest.mark.grab_versions
Victor Ryzhenkin8ff3c3f2018-01-17 19:37:05 +0400100 @pytest.mark.fail_snapshot
Victor Ryzhenkin62123da2018-01-25 18:24:34 +0400101 def test_virtlet_conformance(self, show_step, config, k8s_deployed,
Victor Ryzhenkine784bbf2018-12-21 03:58:00 +0400102 conformance_helper):
Victor Ryzhenkin8ff3c3f2018-01-17 19:37:05 +0400103 """Test run of virtlet conformance tests
104
105 Scenario:
106 1. Perform virtlet conformance
107
108 """
109
110 show_step(1)
Victor Ryzhenkine784bbf2018-12-21 03:58:00 +0400111 k8s_deployed.start_conformance_inside_pod(cnf_type='virtlet')