The simulator changes makes it easy to write tests for various scenarios that was not possible earlier, especially negative/fault scenarios. Earlier Now it was not is possible to write end-to-end tests for VM deployment retry logic, HA, migration etc. This document takes some of the these scenarios mentioned above and shows how to write effectives teststo explain the simulator changes.
...
Now in order to simulate host failure where HA VM is running, following mocks needs to be created. The above call says that create a mock for the agent command 'PingCommand' to return failure (result:fail) for the agent/resource identified by zoneid, podid, clusterid, hostid. Possible values for 'result' can be fail/fault. To create a mock with generic scope don't specify anything for hostid, clusterid, podid, zoneid in that specific order. For e.g. to create mock for all hosts in a cluster specify clusterid, podid and zoneid only. All these mock are persisted in the mock configuration table in simulator DB.
self.mock_ping = SimulatorMock.create(
...
self.mock_pingtest = SimulatorMock.create(
apiclient=self.apiclient,
command="PingTestCommand",
zoneid=suitablecluster.zoneid,
podid=suitablecluster.podid,
value="result:fail")
In the actual test there is a wait for HA to happen. Then there is a validation to see that the HA VM has moved to another host in the cluster.
In this case while creating the mocks, count parameter is not used. This is used to make sure that the mock is active only for 'count' times. Every time a mock successfully executes count is decremented by 1. This parameter can be used to make sure that the mock actually got executed as expected and that the test failure is due to the mock and due to some other issues. For an e.g. take a look at test/integration/smoke/test_deploy_vm.py where there are tests for VM deployment retry logic.
As part of cleanup, clear all the mocks created during setup so that subsequent tests are not impacted by them. The mocks are cleaned up by simply updating the 'removed' field.