Improve server faking in osc unit test framework.
There are mainly two problems in the current osc unit framework when it is faking a server:
1. It uses class FakeResource to fake a server, which is a subclass of Object.
That means, if we fake a server like this:
server = FakeResource(
we cannnot do this kind of call:
server.start(), server.stop(), server.pause(), ......
This is because it is not a Mock instance. This is also the reason why there is no such test cases in the current osc. So in order to test the methods of a server itself, we need an instance of class Mock to fake the server, instead of class Object.
The solution is make FakeResource inherit from Mock.
One related patch is: https:/
(Review in progress, and more similar test cases will be posted as this BP moving on.)
2. It cannot fake and pass more than one servers to the unit test case.
Currently, most of the server commands only take one server as parameter. We have had a BP [1] to improve them to take multiple servers at one time. After this, we need unit tests to test multiple server parameters.
But . For example, in class DeleteServer, it uses a loop to operate on each server:
def take_action(self, parsed_args):
......
for server in parsed_args.server:
......
And in class TestServerDelete, it uses class FakeResource to fake the return value for utils.find_
# This is the return value for utils.find_
None,
)
This can fake only one server. If we enter the loop, we can get two same servers.
We can use side_effect in class Mock to solve this problem.
The BP [1] will continuously improve the commands, and this BP will improve the test framework, and continuously add test cases.
[1] https:/
Whiteboard
Gerrit topic: https:/
Addressed by: https:/
Enable FakeResource to fake methods.
Addressed by: https:/
Introduce random server faking mechanism.
Addressed by: https:/
Add unit tests for "server pause" command.
Addressed by: https:/
Use class FakeServer in TestServerCreate.
Addressed by: https:/
Use class FakeServer in TestServerDelete.
Addressed by: https:/
Use class FakeServer in TestServerImage
Addressed by: https:/
Use class FakeServer in TestServerResize.
Addressed by: https:/
Remove the old fake server data.
Addressed by: https:/
Move setup_servers_
Addressed by: https:/
Use setup_servers_
Addressed by: https:/
Add multiple servers test case to TestServerDelete.
Addressed by: https:/
Add unit tests for "server unpause" command.
Addressed by: https:/
Add unit tests for "server lock" command.
Addressed by: https:/
Add unit tests for "server unlock" command.
Addressed by: https:/
Add unit tests for "server suspend" command.
Addressed by: https:/
Add unit tests for "server resume" command.
Addressed by: https:/
Add unit tests for "server start" command.
Addressed by: https:/
Add unit tests for "server stop" command.
Addressed by: https:/
Abstract a helper function for server.xxx() tests.
Addressed by: https:/
Enable setup_servers_
Addressed by: https:/
Add class TestServerList to provide basic unit test for "server list" command.
Addressed by: https:/
TestServerG
Gerrit topic: https:/
Addressed by: https:/
TestServerG
Addressed by: https:/
TestServerG
Addressed by: https:/
Add unit test for TestServerList to test --long option.