vrovachev | 99228d3 | 2017-06-08 19:46:10 +0400 | [diff] [blame] | 1 | # 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 Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 14 | import pytest |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 15 | import os |
vrovachev | 99228d3 | 2017-06-08 19:46:10 +0400 | [diff] [blame] | 16 | |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 17 | from tcp_tests.managers.k8s import read_yaml_file |
vrovachev | 99228d3 | 2017-06-08 19:46:10 +0400 | [diff] [blame] | 18 | from tcp_tests import logger |
| 19 | |
| 20 | LOG = logger.logger |
| 21 | |
| 22 | |
| 23 | class TestVirtletActions(object): |
| 24 | """Test class for testing Virtlet actions""" |
| 25 | |
Victor Ryzhenkin | 1bdb4aa | 2018-01-12 17:36:56 +0400 | [diff] [blame] | 26 | @pytest.mark.grab_versions |
| 27 | @pytest.mark.fail_snapshot |
Dennis Dmitriev | 716d7d2 | 2018-11-15 18:01:45 +0200 | [diff] [blame] | 28 | @pytest.mark.k8s_virtlet |
Vladimir Jigulin | eb8b813 | 2019-03-19 15:34:02 +0400 | [diff] [blame] | 29 | @pytest.mark.k8s_system |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 30 | def test_virtlet_create_delete_vm(self, show_step, config, k8s_deployed): |
vrovachev | 99228d3 | 2017-06-08 19:46:10 +0400 | [diff] [blame] | 31 | """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 Ryzhenkin | 42cfc31 | 2017-06-13 12:51:39 +0400 | [diff] [blame] | 39 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 40 | if not config.k8s_deploy.kubernetes_virtlet_enabled: |
| 41 | pytest.skip("Test requires Virtlet addon enabled") |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 42 | data_dir = os.path.join(os.path.dirname(__file__), 'testdata/k8s') |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 43 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 44 | show_step(1) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 45 | vm_pod = k8s_deployed.api.pods.create( |
| 46 | body=read_yaml_file(data_dir, 'cirros-vm.yaml')) |
| 47 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 48 | show_step(2) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 49 | vm_pod.wait_running(timeout=600) |
| 50 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 51 | show_step(3) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 52 | vm_pod.delete() |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 53 | |
Victor Ryzhenkin | 1bdb4aa | 2018-01-12 17:36:56 +0400 | [diff] [blame] | 54 | @pytest.mark.grab_versions |
| 55 | @pytest.mark.fail_snapshot |
Dennis Dmitriev | 716d7d2 | 2018-11-15 18:01:45 +0200 | [diff] [blame] | 56 | @pytest.mark.k8s_virtlet |
Vladimir Jigulin | eb8b813 | 2019-03-19 15:34:02 +0400 | [diff] [blame] | 57 | @pytest.mark.k8s_system |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 58 | def test_vm_resource_quotas(self, show_step, config, k8s_deployed): |
Victor Ryzhenkin | 42cfc31 | 2017-06-13 12:51:39 +0400 | [diff] [blame] | 59 | """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 Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 69 | if not config.k8s_deploy.kubernetes_virtlet_enabled: |
| 70 | pytest.skip("Test requires Virtlet addon enabled") |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 71 | data_dir = os.path.join(os.path.dirname(__file__), 'testdata/k8s') |
| 72 | cpu = 2 |
| 73 | memory_mb = 512 |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 74 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 75 | show_step(1) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 76 | 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 Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 81 | show_step(2) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 82 | vm_pod = k8s_deployed.api.pods.create(body=pod_body) |
| 83 | vm_pod.wait_running(timeout=600) |
| 84 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 85 | show_step(3) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 86 | 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 Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 90 | show_step(4) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 91 | vm_pod.delete() |
Victor Ryzhenkin | 6609aaf | 2017-06-21 13:09:56 +0400 | [diff] [blame] | 92 | |
Victor Ryzhenkin | e784bbf | 2018-12-21 03:58:00 +0400 | [diff] [blame] | 93 | @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 Ryzhenkin | 8ff3c3f | 2018-01-17 19:37:05 +0400 | [diff] [blame] | 99 | @pytest.mark.grab_versions |
Victor Ryzhenkin | 8ff3c3f | 2018-01-17 19:37:05 +0400 | [diff] [blame] | 100 | @pytest.mark.fail_snapshot |
Victor Ryzhenkin | 62123da | 2018-01-25 18:24:34 +0400 | [diff] [blame] | 101 | def test_virtlet_conformance(self, show_step, config, k8s_deployed, |
Victor Ryzhenkin | e784bbf | 2018-12-21 03:58:00 +0400 | [diff] [blame] | 102 | conformance_helper): |
Victor Ryzhenkin | 8ff3c3f | 2018-01-17 19:37:05 +0400 | [diff] [blame] | 103 | """Test run of virtlet conformance tests |
| 104 | |
| 105 | Scenario: |
| 106 | 1. Perform virtlet conformance |
| 107 | |
| 108 | """ |
| 109 | |
| 110 | show_step(1) |
Victor Ryzhenkin | e784bbf | 2018-12-21 03:58:00 +0400 | [diff] [blame] | 111 | k8s_deployed.start_conformance_inside_pod(cnf_type='virtlet') |