|
| 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 case for checking creation of two VM's with same name on VMWare""" |
| 19 | + |
| 20 | +from nose.plugins.attrib import attr |
| 21 | +from marvin.cloudstackTestCase import cloudstackTestCase |
| 22 | +from marvin.lib.utils import (cleanup_resources) |
| 23 | +from marvin.lib.base import (Account, |
| 24 | + ServiceOffering, |
| 25 | + VirtualMachine, |
| 26 | + Configurations |
| 27 | + ) |
| 28 | +from marvin.lib.common import (get_domain, |
| 29 | + get_zone, |
| 30 | + get_template, |
| 31 | + ) |
| 32 | + |
| 33 | +from marvin.sshClient import SshClient |
| 34 | +import time |
| 35 | + |
| 36 | + |
| 37 | +class TestSameVMName(cloudstackTestCase): |
| 38 | + |
| 39 | + @classmethod |
| 40 | + def setUpClass(cls): |
| 41 | + testClient = super(TestSameVMName, cls).getClsTestClient() |
| 42 | + cls.apiclient = testClient.getApiClient() |
| 43 | + cls.testdata = testClient.getParsedTestDataConfig() |
| 44 | + |
| 45 | + # Get Zone, Domain and templates |
| 46 | + cls.domain = get_domain(cls.apiclient) |
| 47 | + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) |
| 48 | + |
| 49 | + cls.template = get_template( |
| 50 | + cls.apiclient, |
| 51 | + cls.zone.id, |
| 52 | + cls.testdata["ostype"]) |
| 53 | + |
| 54 | + cls._cleanup = [] |
| 55 | + |
| 56 | + cls.mgtSvrDetails = cls.config.__dict__["mgtSvr"][0].__dict__ |
| 57 | + try: |
| 58 | + cls.skiptest = False |
| 59 | + |
| 60 | + if cls.hypervisor.lower() not in ['vmware']: |
| 61 | + cls.skiptest = True |
| 62 | + |
| 63 | + # Create an account |
| 64 | + cls.account_1 = Account.create( |
| 65 | + cls.apiclient, |
| 66 | + cls.testdata["account"], |
| 67 | + domainid=cls.domain.id |
| 68 | + ) |
| 69 | + cls.account_2 = Account.create( |
| 70 | + cls.apiclient, |
| 71 | + cls.testdata["account"], |
| 72 | + domainid=cls.domain.id |
| 73 | + ) |
| 74 | + |
| 75 | + # Create user api client of the account |
| 76 | + cls.userapiclient_1 = testClient.getUserApiClient( |
| 77 | + UserName=cls.account_1.name, |
| 78 | + DomainName=cls.account_1.domain |
| 79 | + ) |
| 80 | + |
| 81 | + cls.userapiclient_2 = testClient.getUserApiClient( |
| 82 | + UserName=cls.account_2.name, |
| 83 | + DomainName=cls.account_2.domain |
| 84 | + ) |
| 85 | + # Create Service offering |
| 86 | + cls.service_offering = ServiceOffering.create( |
| 87 | + cls.apiclient, |
| 88 | + cls.testdata["service_offering"], |
| 89 | + ) |
| 90 | + |
| 91 | + cls._cleanup = [ |
| 92 | + cls.account_1, |
| 93 | + cls.account_2, |
| 94 | + cls.service_offering, |
| 95 | + ] |
| 96 | + except Exception as e: |
| 97 | + cls.tearDownClass() |
| 98 | + raise e |
| 99 | + return |
| 100 | + |
| 101 | + @classmethod |
| 102 | + def RestartServer(cls): |
| 103 | + """Restart management server""" |
| 104 | + |
| 105 | + sshClient = SshClient( |
| 106 | + cls.mgtSvrDetails["mgtSvrIp"], |
| 107 | + 22, |
| 108 | + cls.mgtSvrDetails["user"], |
| 109 | + cls.mgtSvrDetails["passwd"] |
| 110 | + ) |
| 111 | + command = "service cloudstack-management restart" |
| 112 | + sshClient.execute(command) |
| 113 | + |
| 114 | + return |
| 115 | + |
| 116 | + @classmethod |
| 117 | + def tearDownClass(cls): |
| 118 | + try: |
| 119 | + cleanup_resources(cls.apiclient, cls._cleanup) |
| 120 | + except Exception as e: |
| 121 | + raise Exception("Warning: Exception during cleanup : %s" % e) |
| 122 | + |
| 123 | + def setUp(self): |
| 124 | + self.apiclient = self.testClient.getApiClient() |
| 125 | + self.dbclient = self.testClient.getDbConnection() |
| 126 | + self.cleanup = [] |
| 127 | + if self.skiptest: |
| 128 | + self.skipTest("This test is to be checked on VMWare only Hence, skip for %s" % self.hypervisor) |
| 129 | + |
| 130 | + def tearDown(self): |
| 131 | + try: |
| 132 | + cleanup_resources(self.apiclient, self.cleanup) |
| 133 | + except Exception as e: |
| 134 | + raise Exception("Warning: Exception during cleanup : %s" % e) |
| 135 | + return |
| 136 | + |
| 137 | + @attr(tags=["advanced", "basic"]) |
| 138 | + def test_vms_with_same_name(self): |
| 139 | + """ Test vm deployment with same name |
| 140 | +
|
| 141 | + # 1. Deploy a VM on with perticular name from account_1 |
| 142 | + # 2. Try to deploy another vm with same name from account_2 |
| 143 | + # 3. Verify that second VM deployment fails |
| 144 | +
|
| 145 | + """ |
| 146 | + # Step 1 |
| 147 | + # Create VM on cluster wide |
| 148 | + configs = Configurations.list( |
| 149 | + self.apiclient, |
| 150 | + name="vm.instancename.flag") |
| 151 | + orig_value = configs[0].value |
| 152 | + |
| 153 | + if orig_value == "false": |
| 154 | + Configurations.update(self.apiclient, |
| 155 | + name="vm.instancename.flag", |
| 156 | + value="true" |
| 157 | + ) |
| 158 | + |
| 159 | + # Restart management server |
| 160 | + self.RestartServer() |
| 161 | + time.sleep(120) |
| 162 | + |
| 163 | + self.testdata["small"]["displayname"]="TestName" |
| 164 | + self.testdata["small"]["name"]="TestName" |
| 165 | + VirtualMachine.create( |
| 166 | + self.userapiclient_1, |
| 167 | + self.testdata["small"], |
| 168 | + templateid=self.template.id, |
| 169 | + accountid=self.account_1.name, |
| 170 | + domainid=self.account_1.domainid, |
| 171 | + serviceofferingid=self.service_offering.id, |
| 172 | + zoneid=self.zone.id, |
| 173 | + ) |
| 174 | + |
| 175 | + with self.assertRaises(Exception): |
| 176 | + VirtualMachine.create( |
| 177 | + self.userapiclient_2, |
| 178 | + self.testdata["small"], |
| 179 | + templateid=self.template.id, |
| 180 | + accountid=self.account_2.name, |
| 181 | + domainid=self.account_2.domainid, |
| 182 | + serviceofferingid=self.service_offering.id, |
| 183 | + zoneid=self.zone.id, |
| 184 | + ) |
| 185 | + return |
0 commit comments