blob: d3b6c2719065b08b189c2d03a6141a01b049acf1 [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
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040029 def test_virtlet_create_delete_vm(self, show_step, config, k8s_deployed):
vrovachev99228d32017-06-08 19:46:10 +040030 """Test for deploying an mcp environment with virtlet
31
32 Scenario:
33 1. Start VM as a virtlet pod
34 2. Wait active state of VM
35 3. Delete VM and wait to delete pod
36
37 """
Victor Ryzhenkin42cfc312017-06-13 12:51:39 +040038
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040039 if not config.k8s_deploy.kubernetes_virtlet_enabled:
40 pytest.skip("Test requires Virtlet addon enabled")
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040041 data_dir = os.path.join(os.path.dirname(__file__), 'testdata/k8s')
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040042
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040043 show_step(1)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040044 vm_pod = k8s_deployed.api.pods.create(
45 body=read_yaml_file(data_dir, 'cirros-vm.yaml'))
46
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040047 show_step(2)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040048 vm_pod.wait_running(timeout=600)
49
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040050 show_step(3)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040051 vm_pod.delete()
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040052
Victor Ryzhenkin1bdb4aa2018-01-12 17:36:56 +040053 @pytest.mark.grab_versions
54 @pytest.mark.fail_snapshot
Dennis Dmitriev716d7d22018-11-15 18:01:45 +020055 @pytest.mark.k8s_virtlet
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040056 def test_vm_resource_quotas(self, show_step, config, k8s_deployed):
Victor Ryzhenkin42cfc312017-06-13 12:51:39 +040057 """Test for deploying a VM with specific quotas
58
59 Scenario:
60 1. Prepare VM's yaml
61 2. Start a VM
62 3. Check that VM resources is equal to provided in yaml
63 4. Destroy VM
64
65 """
66
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040067 if not config.k8s_deploy.kubernetes_virtlet_enabled:
68 pytest.skip("Test requires Virtlet addon enabled")
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040069 data_dir = os.path.join(os.path.dirname(__file__), 'testdata/k8s')
70 cpu = 2
71 memory_mb = 512
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040072
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040073 show_step(1)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040074 pod_body = read_yaml_file(data_dir, 'cirros-vm.yaml')
75 pod_body['metadata']['annotations']['VirtletVCPUCount'] = str(cpu)
76 pod_body['spec']['containers'][0]['resources']['limits']['memory'] = \
77 '{}Mi'.format(memory_mb)
78
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040079 show_step(2)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040080 vm_pod = k8s_deployed.api.pods.create(body=pod_body)
81 vm_pod.wait_running(timeout=600)
82
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040083 show_step(3)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040084 stats = k8s_deployed.virtlet.virsh_domstats(vm_pod)
85 assert int(stats['vcpu.current']) == cpu
86 assert int(stats['balloon.maximum'])/1024 == memory_mb
87
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040088 show_step(4)
Vladimir Jigulin4ad52a82018-08-12 05:51:30 +040089 vm_pod.delete()
Victor Ryzhenkin6609aaf2017-06-21 13:09:56 +040090
Victor Ryzhenkin8ff3c3f2018-01-17 19:37:05 +040091 @pytest.mark.grab_versions
Victor Ryzhenkincf26c932018-03-29 20:08:21 +040092 @pytest.mark.grab_k8s_results(name=['virtlet_conformance.log',
93 'report.xml'])
Victor Ryzhenkin8ff3c3f2018-01-17 19:37:05 +040094 @pytest.mark.fail_snapshot
Victor Ryzhenkin62123da2018-01-25 18:24:34 +040095 def test_virtlet_conformance(self, show_step, config, k8s_deployed,
Victor Ryzhenkincf26c932018-03-29 20:08:21 +040096 k8s_logs):
Victor Ryzhenkin8ff3c3f2018-01-17 19:37:05 +040097 """Test run of virtlet conformance tests
98
99 Scenario:
100 1. Perform virtlet conformance
101
102 """
103
104 show_step(1)
105 k8s_deployed.run_virtlet_conformance()