|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +# Test from the Marvin - Testing in Python wiki |
| 19 | + |
| 20 | +# All tests inherit from cloudstackTestCase |
| 21 | +from marvin.cloudstackTestCase import cloudstackTestCase |
| 22 | + |
| 23 | +# Import Integration Libraries |
| 24 | + |
| 25 | +# base - contains all resources as entities and defines create, delete, |
| 26 | +# list operations on them |
| 27 | +from marvin.lib.base import (Account, |
| 28 | + VirtualMachine, |
| 29 | + ServiceOffering, |
| 30 | + NetworkOffering, |
| 31 | + Network, |
| 32 | + Template, |
| 33 | + DiskOffering, |
| 34 | + StoragePool, |
| 35 | + Volume) |
| 36 | + |
| 37 | +# utils - utility classes for common cleanup, external library wrappers etc |
| 38 | +from marvin.lib.utils import cleanup_resources, get_hypervisor_type, validateList |
| 39 | + |
| 40 | +# common - commonly used methods for all tests are listed here |
| 41 | +from marvin.lib.common import get_zone, get_domain, get_template, list_hosts, get_pod |
| 42 | + |
| 43 | +from marvin.sshClient import SshClient |
| 44 | + |
| 45 | +from marvin.codes import FAILED, PASS |
| 46 | + |
| 47 | +from nose.plugins.attrib import attr |
| 48 | + |
| 49 | +import xml.etree.ElementTree as ET |
| 50 | + |
| 51 | +class Templates: |
| 52 | + """Test data for templates |
| 53 | + """ |
| 54 | + |
| 55 | + def __init__(self): |
| 56 | + self.templates = { |
| 57 | + "kvmvirtioscsi": { |
| 58 | + "kvm": { |
| 59 | + "name": "tiny-kvm-scsi", |
| 60 | + "displaytext": "virtio-scsi kvm", |
| 61 | + "format": "qcow2", |
| 62 | + "hypervisor": "kvm", |
| 63 | + "ostype": "Other PV Virtio-SCSI (64-bit)", |
| 64 | + "url": "http://dl.openvm.eu/cloudstack/ubuntu/vanilla/16.04/x86_64/ubuntu-16.04-server-cloudimg-amd64-disk1-kvm.qcow2.bz2", |
| 65 | + "requireshvm": "True", |
| 66 | + "ispublic": "True", |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | +class TestDeployVirtioSCSIVM(cloudstackTestCase): |
| 72 | + |
| 73 | + """ |
| 74 | + Test deploy a vGPU enabled VM into a user account |
| 75 | + """ |
| 76 | + @classmethod |
| 77 | + def setUpClass(cls): |
| 78 | + testClient = super(TestDeployVirtioSCSIVM, cls).getClsTestClient() |
| 79 | + cls.apiclient = testClient.getApiClient() |
| 80 | + cls.services = cls.testClient.getParsedTestDataConfig() |
| 81 | + cls.hostConfig = cls.config.__dict__["zones"][0].__dict__["pods"][0].__dict__["clusters"][0].__dict__["hosts"][0].__dict__ |
| 82 | + cls.hypervisorNotSupported = False |
| 83 | + cls.hypervisor = testClient.getHypervisorInfo() |
| 84 | + |
| 85 | + # Get Zone, Domain and templates |
| 86 | + cls.domain = get_domain(cls.apiclient) |
| 87 | + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) |
| 88 | + cls.pod = get_pod(cls.apiclient, cls.zone.id) |
| 89 | + cls.services['mode'] = cls.zone.networktype |
| 90 | + if cls.hypervisor.lower() not in ['kvm']: |
| 91 | + cls.hypervisorNotSupported = True |
| 92 | + |
| 93 | + cls._cleanup = [] |
| 94 | + if not cls.hypervisorNotSupported: |
| 95 | + kvmvirtioscsi = Templates().templates["kvmvirtioscsi"] |
| 96 | + cls.template = Template.register(cls.apiclient, kvmvirtioscsi[cls.hypervisor.lower()], |
| 97 | + cls.zone.id, hypervisor=cls.hypervisor.lower(), domainid=cls.domain.id) |
| 98 | + cls.template.download(cls.apiclient) |
| 99 | + |
| 100 | + if cls.template == FAILED: |
| 101 | + assert False, "get_template() failed to return template" |
| 102 | + |
| 103 | + # Create VMs, NAT Rules etc |
| 104 | + cls.account = Account.create( |
| 105 | + cls.apiclient, |
| 106 | + cls.services["account"], |
| 107 | + domainid=cls.domain.id |
| 108 | + ) |
| 109 | + cls.service_offering = ServiceOffering.create( |
| 110 | + cls.apiclient, |
| 111 | + cls.services["service_offerings"]["tiny"] |
| 112 | + ) |
| 113 | + cls.virtual_machine = VirtualMachine.create( |
| 114 | + cls.apiclient, |
| 115 | + cls.services["small"], |
| 116 | + templateid=cls.template.id, |
| 117 | + accountid=cls.account.name, |
| 118 | + domainid=cls.account.domainid, |
| 119 | + zoneid=cls.zone.id, |
| 120 | + serviceofferingid=cls.service_offering.id, |
| 121 | + mode=cls.services["mode"] |
| 122 | + ) |
| 123 | + |
| 124 | + cls.sparse_disk_offering = DiskOffering.create( |
| 125 | + cls.apiclient, |
| 126 | + cls.services["sparse_disk_offering"] |
| 127 | + ) |
| 128 | + |
| 129 | + cls.volume = Volume.create( |
| 130 | + cls.apiclient, |
| 131 | + cls.services, |
| 132 | + zoneid=cls.zone.id, |
| 133 | + account=cls.account.name, |
| 134 | + domainid=cls.account.domainid, |
| 135 | + diskofferingid=cls.sparse_disk_offering.id |
| 136 | + ) |
| 137 | + |
| 138 | + cls.virtual_machine.attach_volume( |
| 139 | + cls.apiclient, |
| 140 | + cls.volume |
| 141 | + ) |
| 142 | + |
| 143 | + cls._cleanup.append(cls.template) |
| 144 | + cls._cleanup.append(cls.service_offering) |
| 145 | + cls._cleanup.append(cls.sparse_disk_offering) |
| 146 | + cls._cleanup.append(cls.account) |
| 147 | + |
| 148 | + host = cls.virtual_machine.hostname |
| 149 | + instancename = cls.virtual_machine.instancename |
| 150 | + |
| 151 | + sshClient = SshClient( |
| 152 | + host=host, |
| 153 | + port=cls.services['configurableData']['host']["publicport"], |
| 154 | + user=cls.hostConfig['username'], |
| 155 | + passwd=cls.hostConfig['password']) |
| 156 | + cls.virshxml = "\n".join(sshClient.execute("virsh dumpxml "+ instancename)) |
| 157 | + |
| 158 | + @classmethod |
| 159 | + def tearDownClass(cls): |
| 160 | + try: |
| 161 | + # Cleanup resources used |
| 162 | + cleanup_resources(cls.apiclient, cls._cleanup) |
| 163 | + except Exception as e: |
| 164 | + raise Exception("Warning: Exception during cleanup : %s" % e) |
| 165 | + return |
| 166 | + |
| 167 | + def setUp(self): |
| 168 | + self.apiclient = self.testClient.getApiClient() |
| 169 | + self.dbclient = self.testClient.getDbConnection() |
| 170 | + self.cleanup = [] |
| 171 | + return |
| 172 | + |
| 173 | + def tearDown(self): |
| 174 | + try: |
| 175 | + # Clean up, terminate the created instance, volumes and snapshots |
| 176 | + cleanup_resources(self.apiclient, self.cleanup) |
| 177 | + except Exception as e: |
| 178 | + raise Exception("Warning: Exception during cleanup : %s" % e) |
| 179 | + return |
| 180 | + |
| 181 | + |
| 182 | + |
| 183 | + @attr(tags=["advanced", "advancedns", "smoke"], required_hardware="true") |
| 184 | + def test_01_verify_libvirt(self): |
| 185 | + """Test that libvirt properly created domain with scsi controller |
| 186 | + """ |
| 187 | + |
| 188 | + # Validate virsh dumpxml |
| 189 | + if self.hypervisorNotSupported: |
| 190 | + self.skipTest |
| 191 | + |
| 192 | + root = ET.fromstring(self.virshxml) |
| 193 | + |
| 194 | + scsis = root.findall("./devices/controller[@type='scsi']/alias[@name='scsi0']/..") |
| 195 | + |
| 196 | + self.assertEqual(len(scsis), 1, "SCSI controller not found") |
| 197 | + |
| 198 | + scsiindex = scsis[0].get('index') |
| 199 | + self.assertNotEqual(scsiindex, None, "Could not find index of SCSI controller") |
| 200 | + |
| 201 | + # find all scsi disks |
| 202 | + disks = root.findall("./devices/disk[@device='disk']/target[@bus='scsi']/..") |
| 203 | + |
| 204 | + self.assertEqual(len(disks), 2, "Could not find two disks") |
| 205 | + |
| 206 | + for disk in disks: |
| 207 | + for child in disk: |
| 208 | + if child.tag.lower() == "target": |
| 209 | + dev = child.get("dev") |
| 210 | + self.assert_(dev != None and dev.startswith("sd"), "disk dev is invalid") |
| 211 | + elif child.tag.lower() == "address": |
| 212 | + con = child.get("controller") |
| 213 | + self.assertEqual(con, scsiindex, "disk controller not equal to SCSI " \ |
| 214 | + "controller index") |
| 215 | + |
| 216 | + |
0 commit comments