blob: 775eb5b883e6ffa0ea1f619536adb12939c5a92b [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 Ryzhenkin3ffa2b42017-10-05 16:38:44 +040024 def test_virtlet_create_delete_vm(self, show_step, config, k8s_deployed):
vrovachev99228d32017-06-08 19:46:10 +040025 """Test for deploying an mcp environment with virtlet
26
27 Scenario:
28 1. Start VM as a virtlet pod
29 2. Wait active state of VM
30 3. Delete VM and wait to delete pod
31
32 """
Victor Ryzhenkin42cfc312017-06-13 12:51:39 +040033
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040034 if not config.k8s_deploy.kubernetes_virtlet_enabled:
35 pytest.skip("Test requires Virtlet addon enabled")
36
37 k8s_deployed.git_clone('https://github.com/Mirantis/virtlet',
38 '~/virtlet')
39 k8s_deployed.install_jq()
40 show_step(1)
41 vm_name = k8s_deployed.run_vm()
42 show_step(2)
43 k8s_deployed.wait_active_state(vm_name)
44 show_step(3)
45 k8s_deployed.delete_vm(vm_name)
46
47 def test_vm_resource_quotas(self, show_step, config, k8s_deployed):
Victor Ryzhenkin42cfc312017-06-13 12:51:39 +040048 """Test for deploying a VM with specific quotas
49
50 Scenario:
51 1. Prepare VM's yaml
52 2. Start a VM
53 3. Check that VM resources is equal to provided in yaml
54 4. Destroy VM
55
56 """
57
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040058 if not config.k8s_deploy.kubernetes_virtlet_enabled:
59 pytest.skip("Test requires Virtlet addon enabled")
60
61 k8s_deployed.git_clone('https://github.com/Mirantis/virtlet',
62 '~/virtlet')
63 k8s_deployed.install_jq()
64 show_step(1)
Victor Ryzhenkin42cfc312017-06-13 12:51:39 +040065 target_cpu = 2 # Cores
66 target_memory = 256 # Size in MB
Dina Belovae6fdffb2017-09-19 13:58:34 -070067 target_memory_kb = target_memory * 1024
Victor Ryzhenkin42cfc312017-06-13 12:51:39 +040068 target_yaml = 'virtlet/examples/cirros-vm-exp.yaml'
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040069 k8s_deployed.adjust_cirros_resources(cpu=target_cpu,
Dennis Dmitriev9b02c8b2017-11-13 15:31:35 +020070 memory=target_memory,
71 target_yaml=target_yaml)
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040072 show_step(2)
73 vm_name = k8s_deployed.run_vm(target_yaml)
74 k8s_deployed.wait_active_state(vm_name)
75 show_step(3)
76 domain_name = k8s_deployed.get_domain_name(vm_name)
77 cpu = k8s_deployed.get_vm_cpu_count(domain_name)
78 mem = k8s_deployed.get_vm_memory_count(domain_name)
Victor Ryzhenkin42cfc312017-06-13 12:51:39 +040079 fail_msg = '{0} is not correct memory unit for VM. Correct is {1}'.\
80 format(mem, target_memory_kb)
81 assert target_memory_kb == mem, fail_msg
82 fail_msg = '{0} is not correct cpu cores count for VM. ' \
83 'Correct is {1}'.format(cpu, target_cpu)
84 assert target_cpu == cpu, fail_msg
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040085 show_step(4)
86 k8s_deployed.delete_vm(target_yaml)
Victor Ryzhenkin6609aaf2017-06-21 13:09:56 +040087
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +040088 @pytest.mark.skip(reason="No configuration with ceph and k8s")
89 def test_rbd_flexvolume_driver(self, show_step, config, k8s_deployed):
Victor Ryzhenkin6609aaf2017-06-21 13:09:56 +040090 """Test for deploying a VM with Ceph RBD volume using flexvolumeDriver
91
92 Scenario:
93 1. Start VM with prepared yaml from run-ceph.sh scripts
94 2. Check that RBD volume is listed in virsh domblklist for VM
95 3. Destroy VM
96
97 """
98 # From:
99 # https://github.com/Mirantis/virtlet/blob/master/tests/e2e/run_ceph.sh
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +0400100 if not config.k8s_deploy.kubernetes_virtlet_enabled:
101 pytest.skip("Test requires Virtlet addon enabled")
102
103 k8s_deployed.git_clone('https://github.com/Mirantis/virtlet',
104 '~/virtlet')
105 k8s_deployed.install_jq()
106
Victor Ryzhenkin6609aaf2017-06-21 13:09:56 +0400107 target_yaml = "virtlet/tests/e2e/cirros-vm-rbd-volume.yaml"
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +0400108 vm_name = k8s_deployed.run_vm(target_yaml)
109 k8s_deployed.wait_active_state(vm_name)
110 domain_name = k8s_deployed.get_domain_name(vm_name)
111 vm_volumes_list = k8s_deployed.list_vm_volumes(domain_name)
Victor Ryzhenkin6609aaf2017-06-21 13:09:56 +0400112 assert 'rbd' in vm_volumes_list
Victor Ryzhenkin3ffa2b42017-10-05 16:38:44 +0400113 k8s_deployed.delete_vm(target_yaml)