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 |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 28 | def test_virtlet_create_delete_vm(self, show_step, config, k8s_deployed): |
vrovachev | 99228d3 | 2017-06-08 19:46:10 +0400 | [diff] [blame] | 29 | """Test for deploying an mcp environment with virtlet |
| 30 | |
| 31 | Scenario: |
| 32 | 1. Start VM as a virtlet pod |
| 33 | 2. Wait active state of VM |
| 34 | 3. Delete VM and wait to delete pod |
| 35 | |
| 36 | """ |
Victor Ryzhenkin | 42cfc31 | 2017-06-13 12:51:39 +0400 | [diff] [blame] | 37 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 38 | if not config.k8s_deploy.kubernetes_virtlet_enabled: |
| 39 | pytest.skip("Test requires Virtlet addon enabled") |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 40 | data_dir = os.path.join(os.path.dirname(__file__), 'testdata/k8s') |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 41 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 42 | show_step(1) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 43 | vm_pod = k8s_deployed.api.pods.create( |
| 44 | body=read_yaml_file(data_dir, 'cirros-vm.yaml')) |
| 45 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 46 | show_step(2) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 47 | vm_pod.wait_running(timeout=600) |
| 48 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 49 | show_step(3) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 50 | vm_pod.delete() |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 51 | |
Victor Ryzhenkin | 1bdb4aa | 2018-01-12 17:36:56 +0400 | [diff] [blame] | 52 | @pytest.mark.grab_versions |
| 53 | @pytest.mark.fail_snapshot |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 54 | def test_vm_resource_quotas(self, show_step, config, k8s_deployed): |
Victor Ryzhenkin | 42cfc31 | 2017-06-13 12:51:39 +0400 | [diff] [blame] | 55 | """Test for deploying a VM with specific quotas |
| 56 | |
| 57 | Scenario: |
| 58 | 1. Prepare VM's yaml |
| 59 | 2. Start a VM |
| 60 | 3. Check that VM resources is equal to provided in yaml |
| 61 | 4. Destroy VM |
| 62 | |
| 63 | """ |
| 64 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 65 | if not config.k8s_deploy.kubernetes_virtlet_enabled: |
| 66 | pytest.skip("Test requires Virtlet addon enabled") |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 67 | data_dir = os.path.join(os.path.dirname(__file__), 'testdata/k8s') |
| 68 | cpu = 2 |
| 69 | memory_mb = 512 |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 70 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 71 | show_step(1) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 72 | pod_body = read_yaml_file(data_dir, 'cirros-vm.yaml') |
| 73 | pod_body['metadata']['annotations']['VirtletVCPUCount'] = str(cpu) |
| 74 | pod_body['spec']['containers'][0]['resources']['limits']['memory'] = \ |
| 75 | '{}Mi'.format(memory_mb) |
| 76 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 77 | show_step(2) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 78 | vm_pod = k8s_deployed.api.pods.create(body=pod_body) |
| 79 | vm_pod.wait_running(timeout=600) |
| 80 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 81 | show_step(3) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 82 | stats = k8s_deployed.virtlet.virsh_domstats(vm_pod) |
| 83 | assert int(stats['vcpu.current']) == cpu |
| 84 | assert int(stats['balloon.maximum'])/1024 == memory_mb |
| 85 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 86 | show_step(4) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 87 | vm_pod.delete() |
Victor Ryzhenkin | 6609aaf | 2017-06-21 13:09:56 +0400 | [diff] [blame] | 88 | |
Victor Ryzhenkin | 8ff3c3f | 2018-01-17 19:37:05 +0400 | [diff] [blame] | 89 | @pytest.mark.grab_versions |
Victor Ryzhenkin | cf26c93 | 2018-03-29 20:08:21 +0400 | [diff] [blame] | 90 | @pytest.mark.grab_k8s_results(name=['virtlet_conformance.log', |
| 91 | 'report.xml']) |
Victor Ryzhenkin | 8ff3c3f | 2018-01-17 19:37:05 +0400 | [diff] [blame] | 92 | @pytest.mark.fail_snapshot |
Victor Ryzhenkin | 62123da | 2018-01-25 18:24:34 +0400 | [diff] [blame] | 93 | def test_virtlet_conformance(self, show_step, config, k8s_deployed, |
Victor Ryzhenkin | cf26c93 | 2018-03-29 20:08:21 +0400 | [diff] [blame] | 94 | k8s_logs): |
Victor Ryzhenkin | 8ff3c3f | 2018-01-17 19:37:05 +0400 | [diff] [blame] | 95 | """Test run of virtlet conformance tests |
| 96 | |
| 97 | Scenario: |
| 98 | 1. Perform virtlet conformance |
| 99 | |
| 100 | """ |
| 101 | |
| 102 | show_step(1) |
| 103 | k8s_deployed.run_virtlet_conformance() |