move out broken tests (#5495)

Co-authored-by: Daan Hoogland <dahn@onecht.net>
This commit is contained in:
dahn 2021-09-22 11:17:18 +02:00 committed by GitHub
parent 7444bc6cd5
commit 3208929a97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 0 additions and 836 deletions

View File

@ -1,16 +0,0 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

View File

@ -1,257 +0,0 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#Test from the Marvin - Testing in Python wiki
#All tests inherit from cloudstackTestCase
from marvin.cloudstackTestCase import cloudstackTestCase
#Import Integration Libraries
from marvin.codes import FAILED
#base - contains all resources as entities and defines create, delete, list operations on them
from marvin.lib.base import Account, VirtualMachine, ServiceOffering, SimulatorMock
#utils - utility classes for common cleanup, external library wrappers etc
from marvin.lib.utils import cleanup_resources
#common - commonly used methods for all tests are listed here
from marvin.lib.common import get_zone, get_domain, get_template
from nose.plugins.attrib import attr
class TestDeployVMVolumeCreationFailure(cloudstackTestCase):
"""Test VM deploy into user account with volume creation failure
"""
def setUp(self):
self.testdata = self.testClient.getParsedTestDataConfig()
self.apiclient = self.testClient.getApiClient()
# Get Zone, Domain and Default Built-in template
self.domain = get_domain(self.apiclient)
self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())
self.testdata["mode"] = self.zone.networktype
self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"])
#create a user account
self.account = Account.create(
self.apiclient,
self.testdata["account"],
domainid=self.domain.id
)
#create a service offering
self.service_offering = ServiceOffering.create(
self.apiclient,
self.testdata["service_offerings"]["small"]
)
#create first VM
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.testdata["virtual_machine"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
templateid=self.template.id)
#mock to simulate volume creation failure
self.mock_volume_failure = SimulatorMock.create(
apiclient=self.apiclient,
command="CopyCommand",
count=6)
#build cleanup list
self.cleanup = [
self.service_offering,
self.account,
self.mock_volume_failure
]
@attr(tags = ['advanced'], required_hardware="simulator only")
def test_deploy_vm_volume_creation_failure(self):
"""Test Deploy Virtual Machine - volume creation failure and retry
# Validate the following:
# 1. 1st VM creation failed
# 2. Check there were 4 failed volume creation retries (mock count = (6-4) = 2)
# 3. 2nd VM creation succeeded
# 4. Check there were 2 failed volume creation retries (mock count = (2-2) = 0)
# 5. ListVM returns accurate information
"""
self.virtual_machine = None
with self.assertRaises(Exception):
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.testdata["virtual_machine2"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
templateid=self.template.id)
self.mock_volume_failure = self.mock_volume_failure.query(self.apiclient)
self.assertEqual(
self.mock_volume_failure.count,
2,
msg="Volume failure mock not executed")
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.testdata["virtual_machine3"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
templateid=self.template.id)
list_vms = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id)
self.assertTrue(isinstance(list_vms, list) and len(list_vms) > 0, msg="List VM response empty")
vm = list_vms[0]
self.assertEqual(
vm.id,
self.virtual_machine.id,
"VM ids do not match")
self.assertEqual(
vm.name,
self.virtual_machine.name,
"VM names do not match")
self.assertEqual(
vm.state,
"Running",
msg="VM is not in Running state")
self.mock_volume_failure = self.mock_volume_failure.query(self.apiclient)
self.assertEqual(
self.mock_volume_failure.count,
0,
msg="Volume failure mock not executed")
def tearDown(self):
try:
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
class TestDeployVMStartFailure(cloudstackTestCase):
"""Test VM deploy into user account with start operation failure
"""
def setUp(self):
self.testdata = self.testClient.getParsedTestDataConfig()
self.apiclient = self.testClient.getApiClient()
# Get Zone, Domain and Default Built-in template
self.domain = get_domain(self.apiclient)
self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())
self.testdata["mode"] = self.zone.networktype
self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"])
#create a user account
self.account = Account.create(
self.apiclient,
self.testdata["account"],
domainid=self.domain.id
)
#create a service offering
self.service_offering = ServiceOffering.create(
self.apiclient,
self.testdata["service_offerings"]["small"]
)
#create first VM
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.testdata["virtual_machine"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
templateid=self.template.id)
#mock to simulate vm start failure
self.mock_start_failure = SimulatorMock.create(
apiclient=self.apiclient,
command="StartCommand",
count=6)
#build cleanup list
self.cleanup = [
self.service_offering,
self.account,
self.mock_start_failure
]
@attr(tags = ['advanced'], required_hardware="simulator only")
def test_deploy_vm_start_failure(self):
"""Test Deploy Virtual Machine - start operation failure and retry
# Validate the following:
# 1. 1st VM creation failed
# 2. Check there were 4 failed start operation retries (mock count = (6-4) = 2)
# 3. 2nd VM creation succeeded
# 4. Check there were 2 failed start operation retries (mock count = (2-2) = 0)
# 5. ListVM returns accurate information
"""
self.virtual_machine = None
with self.assertRaises(Exception):
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.testdata["virtual_machine2"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
templateid=self.template.id)
self.mock_start_failure = self.mock_start_failure.query(self.apiclient)
self.assertEqual(
self.mock_start_failure.count,
2,
msg="Start failure mock not executed")
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.testdata["virtual_machine3"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
templateid=self.template.id)
list_vms = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id)
self.assertTrue(isinstance(list_vms, list) and len(list_vms) > 0, msg="List VM response empty")
vm = list_vms[0]
self.assertEqual(
vm.id,
self.virtual_machine.id,
"VM ids do not match")
self.assertEqual(
vm.name,
self.virtual_machine.name,
"VM names do not match")
self.assertEqual(
vm.state,
"Running",
msg="VM is not in Running state")
self.mock_start_failure = self.mock_start_failure.query(self.apiclient)
self.assertEqual(
self.mock_start_failure.count,
0,
msg="Start failure mock not executed")
def tearDown(self):
try:
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)

View File

@ -1,211 +0,0 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#Test from the Marvin - Testing in Python wiki
#All tests inherit from cloudstackTestCase
from marvin.cloudstackTestCase import cloudstackTestCase
#Import Integration Libraries
#base - contains all resources as entities and defines create, delete, list operations on them
from marvin.lib.base import (
Account,
VirtualMachine,
Volume,
ServiceOffering,
Configurations,
DiskOffering,
Template)
#utils - utility classes for common cleanup, external library wrappers etc
from marvin.lib.utils import cleanup_resources, validateList
#common - commonly used methods for all tests are listed here
from marvin.lib.common import get_zone, get_domain, get_template
from marvin.codes import PASS
from nose.plugins.attrib import attr
import time
class TestTemplates(cloudstackTestCase):
@classmethod
def setUpClass(cls):
try:
cls._cleanup = []
cls.testClient = super(TestTemplates, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient()
cls.services = cls.testClient.getParsedTestDataConfig()
# Get Domain, Zone, Template
cls.domain = get_domain(cls.api_client)
cls.zone = get_zone(
cls.api_client,
cls.testClient.getZoneForTests())
cls.template = get_template(
cls.api_client,
cls.zone.id,
cls.services["ostype"]
)
cls.services["template"]["ostypeid"] = cls.template.ostypeid
cls.services["template"]["isextractable"] = 'True'
if cls.zone.localstorageenabled:
cls.storagetype = 'local'
cls.services["service_offerings"][
"tiny"]["storagetype"] = 'local'
cls.services["disk_offering"]["storagetype"] = 'local'
else:
cls.storagetype = 'shared'
cls.services["service_offerings"][
"tiny"]["storagetype"] = 'shared'
cls.services["disk_offering"]["storagetype"] = 'shared'
cls.services['mode'] = cls.zone.networktype
cls.services["virtual_machine"][
"hypervisor"] = cls.testClient.getHypervisorInfo()
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls.services["virtual_machine"]["template"] = cls.template.id
cls.services["custom_volume"]["zoneid"] = cls.zone.id
# Creating Disk offering, Service Offering and Account
cls.disk_offering = DiskOffering.create(
cls.api_client,
cls.services["disk_offering"]
)
cls.service_offering = ServiceOffering.create(
cls.api_client,
cls.services["service_offerings"]["tiny"]
)
cls.account = Account.create(
cls.api_client,
cls.services["account"],
domainid=cls.domain.id
)
# Getting authentication for user in newly created Account
cls.user = cls.account.user[0]
cls.userapiclient = cls.testClient.getUserApiClient(cls.user.username, cls.domain.name)
cls._cleanup.append(cls.disk_offering)
cls._cleanup.append(cls.service_offering)
cls._cleanup.append(cls.account)
except Exception as e:
cls.tearDownClass()
raise Exception("Warning: Exception in setup : %s" % e)
return
@classmethod
def tearDownClass(cls):
try:
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
def setUp(self):
self.apiClient = self.testClient.getApiClient()
self.cleanup = []
return
def tearDown(self):
#Clean up, terminate the created volumes
cleanup_resources(self.apiClient, self.cleanup)
return
@attr(tags=["advanced", "advancedsg", "sg"], required_hardware='true')
def test01_template_download_URL_expire(self):
"""
@Desc:Template files are deleted from secondary storage after download URL expires
Step1:Deploy vm with default cent os template
Step2:Stop the vm
Step3:Create template from the vm's root volume
Step4:Extract Template and wait for the download url to expire
Step5:Deploy another vm with the template created at Step3
Step6:Verify that vm deployment succeeds
"""
params = ['extract.url.expiration.interval', 'extract.url.cleanup.interval']
wait_time = 0
for param in params:
config = Configurations.list(
self.apiClient,
name=param,
)
self.assertEqual(validateList(config)[0], PASS, "Config list returned invalid response")
wait_time = wait_time+int(config[0].value)
self.debug("Total wait time for url expiry: %s" % wait_time)
# Creating Virtual Machine
self.virtual_machine = VirtualMachine.create(
self.userapiclient,
self.services["virtual_machine"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
)
self.assertIsNotNone(self.virtual_machine, "Virtual Machine creation failed")
self.cleanup.append(self.virtual_machine)
#Stop virtual machine
self.virtual_machine.stop(self.userapiclient)
list_volume = Volume.list(
self.userapiclient,
virtualmachineid=self.virtual_machine.id,
type='ROOT',
listall=True
)
self.assertEqual(validateList(list_volume)[0],
PASS,
"list volumes with type ROOT returned invalid list"
)
self.volume = list_volume[0]
self.create_template = Template.create(
self.userapiclient,
self.services["template"],
volumeid=self.volume.id,
account=self.account.name,
domainid=self.account.domainid
)
self.assertIsNotNone(self.create_template, "Failed to create template from root volume")
self.cleanup.append(self.create_template)
"""
Extract template
"""
try:
Template.extract(
self.userapiclient,
self.create_template.id,
'HTTP_DOWNLOAD',
self.zone.id
)
except Exception as e:
self.fail("Extract template failed with error %s" % e)
self.debug("Waiting for %s seconds for url to expire" % repr(wait_time+20))
time.sleep(wait_time+20)
self.debug("Waited for %s seconds for url to expire" % repr(wait_time+20))
"""
Deploy vm with the template created from the volume. After url expiration interval only
url should be deleted not the template. To validate this deploy vm with the template
"""
try:
self.vm = VirtualMachine.create(
self.userapiclient,
self.services["virtual_machine"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
templateid=self.create_template.id
)
self.cleanup.append(self.vm)
except Exception as e:
self.fail("Template is automatically deleted after URL expired.\
So vm deployment failed with error: %s" % e)
return

View File

@ -1,201 +0,0 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#Test from the Marvin - Testing in Python wiki
import time
#All tests inherit from cloudstackTestCase
from marvin.cloudstackTestCase import cloudstackTestCase
#Import Integration Libraries
#base - contains all resources as entities and defines create, delete, list operations on them
from marvin.lib.base import Account, VirtualMachine, Cluster, Host, ServiceOffering, Configurations, SimulatorMock
#utils - utility classes for common cleanup, external library wrappers etc
from marvin.lib.utils import cleanup_resources, validateList
#common - commonly used methods for all tests are listed here
from marvin.lib.common import get_zone, get_domain, get_template
from marvin.codes import PASS
from nose.plugins.attrib import attr
class TestDeployVMHA(cloudstackTestCase):
"""Test VM HA
"""
def setUp(self):
self.testdata = self.testClient.getParsedTestDataConfig()
self.apiclient = self.testClient.getApiClient()
# Get Zone, Domain and Default Built-in template
self.domain = get_domain(self.apiclient)
self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())
self.testdata["mode"] = self.zone.networktype
self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"])
self.hosts = []
suitablecluster = None
clusters = Cluster.list(self.apiclient)
self.assertTrue(isinstance(clusters, list) and len(clusters) > 0, msg = "No clusters found")
for cluster in clusters:
self.hosts = Host.list(self.apiclient, clusterid=cluster.id, type='Routing')
if isinstance(self.hosts, list) and len(self.hosts) >= 2:
suitablecluster = cluster
break
self.assertEqual(validateList(self.hosts)[0], PASS, "hosts list validation failed")
if len(self.hosts) < 2:
self.skipTest("Atleast 2 hosts required in cluster for VM HA test")
#update host tags
for host in self.hosts:
Host.update(self.apiclient, id=host.id, hosttags=self.testdata["service_offerings"]["hasmall"]["hosttags"])
#create a user account
self.account = Account.create(
self.apiclient,
self.testdata["account"],
domainid=self.domain.id
)
#create a service offering
self.service_offering = ServiceOffering.create(
self.apiclient,
self.testdata["service_offerings"]["hasmall"]
)
#deploy ha vm
self.virtual_machine = VirtualMachine.create(
self.apiclient,
self.testdata["virtual_machine"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
templateid=self.template.id
)
list_vms = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id)
self.debug(
"Verify listVirtualMachines response for virtual machine: %s"\
% self.virtual_machine.id
)
self.assertTrue(isinstance(list_vms, list) and len(list_vms) == 1, msg = "List VM response was empty")
self.virtual_machine = list_vms[0]
self.mock_checkhealth = SimulatorMock.create(
apiclient=self.apiclient,
command="CheckHealthCommand",
zoneid=suitablecluster.zoneid,
podid=suitablecluster.podid,
clusterid=suitablecluster.id,
hostid=self.virtual_machine.hostid,
value="result:fail")
self.mock_ping = SimulatorMock.create(
apiclient=self.apiclient,
command="PingCommand",
zoneid=suitablecluster.zoneid,
podid=suitablecluster.podid,
clusterid=suitablecluster.id,
hostid=self.virtual_machine.hostid,
value="result:fail")
self.mock_checkvirtualmachine = SimulatorMock.create(
apiclient=self.apiclient,
command="CheckVirtualMachineCommand",
zoneid=suitablecluster.zoneid,
podid=suitablecluster.podid,
clusterid=suitablecluster.id,
hostid=self.virtual_machine.hostid,
value="result:fail")
self.mock_pingtest = SimulatorMock.create(
apiclient=self.apiclient,
command="PingTestCommand",
zoneid=suitablecluster.zoneid,
podid=suitablecluster.podid,
value="result:fail")
self.mock_checkonhost_list = []
for host in self.hosts:
if host.id != self.virtual_machine.hostid:
self.mock_checkonhost_list.append(SimulatorMock.create(
apiclient=self.apiclient,
command="CheckOnHostCommand",
zoneid=suitablecluster.zoneid,
podid=suitablecluster.podid,
clusterid=suitablecluster.id,
hostid=host.id,
value="result:fail"))
#build cleanup list
self.cleanup = [
self.service_offering,
self.account,
self.mock_checkhealth,
self.mock_ping,
self.mock_checkvirtualmachine,
self.mock_pingtest
]
self.cleanup = self.cleanup + self.mock_checkonhost_list
@attr(tags = ['advanced'], required_hardware="simulator only")
def test_vm_ha(self):
"""Test VM HA
# Validate the following:
# VM started on other host in cluster
"""
#wait for VM to HA
ping_timeout = Configurations.list(self.apiclient, name="ping.timeout")
ping_interval = Configurations.list(self.apiclient, name="ping.interval")
total_duration = int(float(ping_timeout[0].value) * float(ping_interval[0].value))
time.sleep(total_duration)
duration = 0
vm = None
while duration < total_duration:
list_vms = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id)
self.assertTrue(isinstance(list_vms, list) and len(list_vms) == 1, msg = "List VM response was empty")
vm = list_vms[0]
if vm.hostid != self.virtual_machine.hostid and vm.state == "Running":
break
else:
time.sleep(10)
duration = duration + 10
self.assertEqual(
vm.id,
self.virtual_machine.id,
"VM ids do not match")
self.assertEqual(
vm.name,
self.virtual_machine.name,
"VM names do not match")
self.assertEqual(
vm.state,
"Running",
msg="VM is not in Running state")
self.assertNotEqual(
vm.hostid,
self.virtual_machine.hostid,
msg="VM is not started on another host as part of HA")
def tearDown(self):
try:
for host in self.hosts:
Host.update(self.apiclient, id=host.id, hosttags="")
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)

View File

@ -1,151 +0,0 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#Test from the Marvin - Testing in Python wiki
import time
#All tests inherit from cloudstackTestCase
from marvin.cloudstackTestCase import cloudstackTestCase
#Import Integration Libraries
#base - contains all resources as entities and defines create, delete, list operations on them
from marvin.lib.base import Account, VirtualMachine, Cluster, Host, ServiceOffering, Configurations, SimulatorMock
#utils - utility classes for common cleanup, external library wrappers etc
from marvin.lib.utils import cleanup_resources
#common - commonly used methods for all tests are listed here
from marvin.lib.common import get_zone, get_domain, get_template
from nose.plugins.attrib import attr
class TestDeployVMSync(cloudstackTestCase):
"""Test VM Sync
"""
def setUp(self):
self.testdata = self.testClient.getParsedTestDataConfig()
self.apiclient = self.testClient.getApiClient()
# Get Zone, Domain and Default Built-in template
self.domain = get_domain(self.apiclient)
self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())
self.testdata["mode"] = self.zone.networktype
self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"])
hosts = Host.list(self.apiclient, type='Routing')
self.assertTrue(isinstance(hosts, list) and len(hosts) > 0, msg = "No hosts found")
self.host = hosts[0]
#update host tags
Host.update(self.apiclient, id=self.host.id, hosttags=self.testdata["service_offerings"]["taggedsmall"]["hosttags"])
#create a user account
self.account = Account.create(
self.apiclient,
self.testdata["account"],
domainid=self.domain.id
)
#create a service offering
self.service_offering = ServiceOffering.create(
self.apiclient,
self.testdata["service_offerings"]["taggedsmall"]
)
#deploy vms
self.vm1 = VirtualMachine.create(
self.apiclient,
self.testdata["small"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
templateid=self.template.id
)
self.vm2 = VirtualMachine.create(
self.apiclient,
self.testdata["small"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
templateid=self.template.id
)
self.vm3 = VirtualMachine.create(
self.apiclient,
self.testdata["small"],
accountid=self.account.name,
zoneid=self.zone.id,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
templateid=self.template.id
)
list_vms = VirtualMachine.list(self.apiclient, ids=[self.vm1.id, self.vm2.id, self.vm3.id], listAll=True)
self.assertTrue(isinstance(list_vms, list) and len(list_vms) == 3, msg = "List VM response is empty")
clusters = Cluster.list(self.apiclient, id=self.host.clusterid)
self.assertTrue(isinstance(clusters, list) and len(clusters) > 0, msg = "Cluster not found")
json_response = '{"com.cloud.agent.api.PingRoutingWithNwGroupsCommand":{"newGroupStates":{},"newStates":{},"_hostVmStateReport":{"%s":{"state":"PowerOn","host":"%s"},"%s":{"state":"PowerOff","host":"%s"}},"_gatewayAccessible":true,"_vnetAccessible":true,"hostType":"Routing","hostId":0,"contextMap":{},"wait":0}}'
json_response = json_response%(self.vm1.instancename, self.host.name, self.vm2.instancename, self.host.name)
#create a mock to simulate vm1 as power-on, vm2 as power-off and vm3 as missing
self.mock_ping = SimulatorMock.create(
apiclient=self.apiclient,
command="PingRoutingWithNwGroupsCommand",
zoneid=self.zone.id,
podid=clusters[0].podid,
clusterid=clusters[0].id,
hostid=self.host.id,
value='',
jsonresponse=json_response,
method='POST')
#build cleanup list
self.cleanup = [
self.service_offering,
self.account,
self.mock_ping
]
@attr(tags = ['advanced'], required_hardware="simulator only")
def test_vm_sync(self):
"""Test VM Sync
# Validate the following:
# vm1 should be running, vm2 should be stopped as power report says PowerOff, vm3 should be stopped as missing from power report
"""
#wait for vmsync to happen
ping_interval = Configurations.list(self.apiclient, name="ping.interval")
total_duration = int(float(ping_interval[0].value) * 3.2)
time.sleep(total_duration)
list_vms = VirtualMachine.list(self.apiclient, ids=[self.vm1.id, self.vm2.id, self.vm3.id], listAll=True)
self.assertTrue(isinstance(list_vms, list) and len(list_vms) == 3, msg = "List VM response is empty")
for vm in list_vms:
if vm.id == self.vm1.id:
self.assertTrue(vm.state == "Running", msg = "VM {0} is expected to be in running state".format(vm.name))
elif vm.id == self.vm2.id or vm.id == self.vm3.id:
self.assertTrue(vm.state == "Stopped", msg = "VM {0} is expected to be in stopped state".format(vm.name))
def tearDown(self):
try:
Host.update(self.apiclient, id=self.host.id, hosttags="")
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
self.debug("Warning! Exception in tearDown: %s" % e)