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 |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 29 | def test_virtlet_create_delete_vm(self, show_step, config, k8s_deployed): |
vrovachev | 99228d3 | 2017-06-08 19:46:10 +0400 | [diff] [blame] | 30 | """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 Ryzhenkin | 42cfc31 | 2017-06-13 12:51:39 +0400 | [diff] [blame] | 38 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 39 | if not config.k8s_deploy.kubernetes_virtlet_enabled: |
| 40 | pytest.skip("Test requires Virtlet addon enabled") |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 41 | data_dir = os.path.join(os.path.dirname(__file__), 'testdata/k8s') |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 42 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 43 | show_step(1) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 44 | vm_pod = k8s_deployed.api.pods.create( |
| 45 | body=read_yaml_file(data_dir, 'cirros-vm.yaml')) |
| 46 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 47 | show_step(2) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 48 | vm_pod.wait_running(timeout=600) |
| 49 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 50 | show_step(3) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 51 | vm_pod.delete() |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 52 | |
Victor Ryzhenkin | 1bdb4aa | 2018-01-12 17:36:56 +0400 | [diff] [blame] | 53 | @pytest.mark.grab_versions |
| 54 | @pytest.mark.fail_snapshot |
Dennis Dmitriev | 716d7d2 | 2018-11-15 18:01:45 +0200 | [diff] [blame] | 55 | @pytest.mark.k8s_virtlet |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 56 | def test_vm_resource_quotas(self, show_step, config, k8s_deployed): |
Victor Ryzhenkin | 42cfc31 | 2017-06-13 12:51:39 +0400 | [diff] [blame] | 57 | """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 Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 67 | if not config.k8s_deploy.kubernetes_virtlet_enabled: |
| 68 | pytest.skip("Test requires Virtlet addon enabled") |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 69 | data_dir = os.path.join(os.path.dirname(__file__), 'testdata/k8s') |
| 70 | cpu = 2 |
| 71 | memory_mb = 512 |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 72 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 73 | show_step(1) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 74 | 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 Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 79 | show_step(2) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 80 | vm_pod = k8s_deployed.api.pods.create(body=pod_body) |
| 81 | vm_pod.wait_running(timeout=600) |
| 82 | |
Victor Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 83 | show_step(3) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 84 | 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 Ryzhenkin | 3ffa2b4 | 2017-10-05 16:38:44 +0400 | [diff] [blame] | 88 | show_step(4) |
Vladimir Jigulin | 4ad52a8 | 2018-08-12 05:51:30 +0400 | [diff] [blame] | 89 | vm_pod.delete() |
Victor Ryzhenkin | 6609aaf | 2017-06-21 13:09:56 +0400 | [diff] [blame] | 90 | |
Victor Ryzhenkin | 8ff3c3f | 2018-01-17 19:37:05 +0400 | [diff] [blame] | 91 | @pytest.mark.grab_versions |
Victor Ryzhenkin | cf26c93 | 2018-03-29 20:08:21 +0400 | [diff] [blame] | 92 | @pytest.mark.grab_k8s_results(name=['virtlet_conformance.log', |
| 93 | 'report.xml']) |
Victor Ryzhenkin | 8ff3c3f | 2018-01-17 19:37:05 +0400 | [diff] [blame] | 94 | @pytest.mark.fail_snapshot |
Victor Ryzhenkin | 62123da | 2018-01-25 18:24:34 +0400 | [diff] [blame] | 95 | def test_virtlet_conformance(self, show_step, config, k8s_deployed, |
Victor Ryzhenkin | cf26c93 | 2018-03-29 20:08:21 +0400 | [diff] [blame] | 96 | k8s_logs): |
Victor Ryzhenkin | 8ff3c3f | 2018-01-17 19:37:05 +0400 | [diff] [blame] | 97 | """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() |