blob: 1cf4beef9fc8ec719f6a6e609926ce51259ec89d [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
vrovachev99228d32017-06-08 19:46:10 +040015
vrovachev99228d32017-06-08 19:46:10 +040016from tcp_tests import logger
17
18LOG = logger.logger
19
20
21class TestVirtletActions(object):
22 """Test class for testing Virtlet actions"""
23
Victor Ryzhenkin1bdb4aa2018-01-12 17:36:56 +040024 @pytest.mark.grab_versions
25 @pytest.mark.fail_snapshot
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040026 def test_virtlet_create_delete_vm(self, show_step, config, k8s_deployed):
vrovachev99228d32017-06-08 19:46:10 +040027 """Test for deploying an mcp environment with virtlet
28
29 Scenario:
30 1. Start VM as a virtlet pod
31 2. Wait active state of VM
32 3. Delete VM and wait to delete pod
33
34 """
Victor Ryzhenkin42cfc312017-06-13 12:51:39 +040035
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040036 if not config.k8s_deploy.kubernetes_virtlet_enabled:
37 pytest.skip("Test requires Virtlet addon enabled")
38
39 k8s_deployed.git_clone('https://github.com/Mirantis/virtlet',
40 '~/virtlet')
41 k8s_deployed.install_jq()
42 show_step(1)
43 vm_name = k8s_deployed.run_vm()
44 show_step(2)
Victor Ryzhenkin26b5aaa2018-01-16 17:58:58 +040045 k8s_deployed.wait_active_state(vm_name, timeout=360)
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040046 show_step(3)
47 k8s_deployed.delete_vm(vm_name)
48
Victor Ryzhenkin1bdb4aa2018-01-12 17:36:56 +040049 @pytest.mark.grab_versions
50 @pytest.mark.fail_snapshot
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040051 def test_vm_resource_quotas(self, show_step, config, k8s_deployed):
Victor Ryzhenkin42cfc312017-06-13 12:51:39 +040052 """Test for deploying a VM with specific quotas
53
54 Scenario:
55 1. Prepare VM's yaml
56 2. Start a VM
57 3. Check that VM resources is equal to provided in yaml
58 4. Destroy VM
59
60 """
61
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040062 if not config.k8s_deploy.kubernetes_virtlet_enabled:
63 pytest.skip("Test requires Virtlet addon enabled")
64
65 k8s_deployed.git_clone('https://github.com/Mirantis/virtlet',
66 '~/virtlet')
67 k8s_deployed.install_jq()
68 show_step(1)
Victor Ryzhenkin42cfc312017-06-13 12:51:39 +040069 target_cpu = 2 # Cores
70 target_memory = 256 # Size in MB
Dina Belovae6fdffb2017-09-19 13:58:34 -070071 target_memory_kb = target_memory * 1024
Victor Ryzhenkin42cfc312017-06-13 12:51:39 +040072 target_yaml = 'virtlet/examples/cirros-vm-exp.yaml'
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040073 k8s_deployed.adjust_cirros_resources(cpu=target_cpu,
Dennis Dmitriev9b02c8b2017-11-13 15:31:35 +020074 memory=target_memory,
75 target_yaml=target_yaml)
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040076 show_step(2)
77 vm_name = k8s_deployed.run_vm(target_yaml)
Victor Ryzhenkin26b5aaa2018-01-16 17:58:58 +040078 k8s_deployed.wait_active_state(vm_name, timeout=360)
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040079 show_step(3)
80 domain_name = k8s_deployed.get_domain_name(vm_name)
81 cpu = k8s_deployed.get_vm_cpu_count(domain_name)
82 mem = k8s_deployed.get_vm_memory_count(domain_name)
Victor Ryzhenkin42cfc312017-06-13 12:51:39 +040083 fail_msg = '{0} is not correct memory unit for VM. Correct is {1}'.\
84 format(mem, target_memory_kb)
85 assert target_memory_kb == mem, fail_msg
86 fail_msg = '{0} is not correct cpu cores count for VM. ' \
87 'Correct is {1}'.format(cpu, target_cpu)
88 assert target_cpu == cpu, fail_msg
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040089 show_step(4)
90 k8s_deployed.delete_vm(target_yaml)
Victor Ryzhenkin6609aaf2017-06-21 13:09:56 +040091
Victor Ryzhenkin8ff3c3f2018-01-17 19:37:05 +040092 @pytest.mark.grab_versions
Victor Ryzhenkincf26c932018-03-29 20:08:21 +040093 @pytest.mark.grab_k8s_results(name=['virtlet_conformance.log',
94 'report.xml'])
Victor Ryzhenkin8ff3c3f2018-01-17 19:37:05 +040095 @pytest.mark.fail_snapshot
Victor Ryzhenkin62123da2018-01-25 18:24:34 +040096 def test_virtlet_conformance(self, show_step, config, k8s_deployed,
Victor Ryzhenkincf26c932018-03-29 20:08:21 +040097 k8s_logs):
Victor Ryzhenkin8ff3c3f2018-01-17 19:37:05 +040098 """Test run of virtlet conformance tests
99
100 Scenario:
101 1. Perform virtlet conformance
102
103 """
104
105 show_step(1)
106 k8s_deployed.run_virtlet_conformance()
107
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +0400108 @pytest.mark.skip(reason="No configuration with ceph and k8s")
109 def test_rbd_flexvolume_driver(self, show_step, config, k8s_deployed):
Victor Ryzhenkin6609aaf2017-06-21 13:09:56 +0400110 """Test for deploying a VM with Ceph RBD volume using flexvolumeDriver
111
112 Scenario:
113 1. Start VM with prepared yaml from run-ceph.sh scripts
114 2. Check that RBD volume is listed in virsh domblklist for VM
115 3. Destroy VM
116
117 """
118 # From:
119 # https://github.com/Mirantis/virtlet/blob/master/tests/e2e/run_ceph.sh
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +0400120 if not config.k8s_deploy.kubernetes_virtlet_enabled:
121 pytest.skip("Test requires Virtlet addon enabled")
122
123 k8s_deployed.git_clone('https://github.com/Mirantis/virtlet',
124 '~/virtlet')
125 k8s_deployed.install_jq()
126
Victor Ryzhenkin6609aaf2017-06-21 13:09:56 +0400127 target_yaml = "virtlet/tests/e2e/cirros-vm-rbd-volume.yaml"
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +0400128 vm_name = k8s_deployed.run_vm(target_yaml)
129 k8s_deployed.wait_active_state(vm_name)
130 domain_name = k8s_deployed.get_domain_name(vm_name)
131 vm_volumes_list = k8s_deployed.list_vm_volumes(domain_name)
Victor Ryzhenkin6609aaf2017-06-21 13:09:56 +0400132 assert 'rbd' in vm_volumes_list
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +0400133 k8s_deployed.delete_vm(target_yaml)